/* Math Hub styles.
 * Layout: a colour band (the course's colour) with breadcrumbs and actions,
 * then cards on a pale page. Problems and worked examples keep the look of
 * the original Unit 2 practice page. Dark mode follows the device setting.
 */
@font-face {
  font-family: "Public Sans"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(../fonts/public-sans-latin-wght-normal.woff2) format("woff2");
}
@font-face {
  font-family: "Source Serif 4"; font-style: normal; font-display: swap; font-weight: 200 900;
  src: url(../fonts/source-serif-4-latin-wght-normal.woff2) format("woff2");
}

:root {
  --accent: #3f4a75;               /* set per course by the app */
  --bg: #f3f4f8; --surface: #ffffff; --ink: #1c2240; --muted: #5a6280; --line: #d6d9e4; --line-strong: #9aa1b8;
  --head: var(--accent); --on-band: #ffffff; --band-muted: rgba(255,255,255,.78);
  --yellow: #fff200; --on-yellow: #1c2240; --butter: #fff2be; --mist: #ecedf1;
  --btn-bg: #054279; --btn-ink: #ffffff;
  --grid: #e6e9f1; --tile: #cdebfb; --tile-edge: #054279; --pt: #054279;
  --good: #1b6e40; --good-bg: #e1f3e8; --good-fill: #1f8a4c; --good-ink: #ffffff; --bad: #a8251d; --bad-bg: #fbe6e3;
  --dot: #d6d9e4;
  --c-diff: #c2410c; --c-zero: #6d3fc0;
  --font-display: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-body: "Public Sans", "Segoe UI", system-ui, sans-serif;
  --scrim: rgba(28,34,64,.45);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151d; --surface: #1b1f2b; --ink: #e7e9f1; --muted: #a2a8bd; --line: #2e3445; --line-strong: #4a5268;
    --head: color-mix(in srgb, var(--accent) 40%, #ffffff);
    --butter: #3a3417; --mist: #262b3a;
    --btn-bg: #8fb8ec; --btn-ink: #0d1626;
    --grid: #2a3042; --tile: #1d3a57; --tile-edge: #8fc3ec; --pt: #8fc3ec;
    --good: #84d4a5; --good-bg: #173224; --good-fill: #2b8a54; --bad: #f2a29a; --bad-bg: #3a1d1b;
    --dot: #3a4155;
    --c-diff: #f59a5c; --c-zero: #b9a0f2;
    --scrim: rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; }
.wrap { width: 100%; max-width: 1060px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--head); }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---------- Header band ---------- */
.band { background: var(--accent); color: var(--on-band); }
.band-in { padding-top: 22px; padding-bottom: 24px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 20px; }
.band-text { min-width: 0; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; font-size: 13px; font-weight: 600; letter-spacing: .04em; }
.crumbs a { color: var(--band-muted); text-decoration: none; }
.crumbs a:hover { color: var(--on-band); text-decoration: underline; }
.crumbs .sep { color: var(--band-muted); }
h1 { font-family: var(--font-display); font-weight: 650; font-size: clamp(26px, 4vw, 34px); line-height: 1.15; margin: 2px 0 0; text-wrap: balance; }
.band-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.band .chip-btn { background: none; border-color: rgba(255,255,255,.6); color: var(--on-band); }
.band .chip-btn:hover { background: rgba(255,255,255,.14); }
.band .chip-btn[aria-pressed="true"] { background: var(--yellow); border-color: var(--yellow); color: var(--on-yellow); }
.chip-btn { display: inline-block; border: 1.5px solid var(--line-strong); background: var(--surface); color: var(--head); border-radius: 999px; padding: 6px 16px; font-weight: 600; font-size: 14px; text-decoration: none; }

main.wrap { flex: 1; padding-top: 24px; padding-bottom: 48px; }
.view { display: flex; flex-direction: column; gap: 20px; }
.lede { margin: 0; color: var(--muted); font-size: 17px; max-width: 62ch; }
.foot { color: var(--muted); font-size: 13px; }
.foot p { margin: 0 auto; padding-top: 14px; padding-bottom: 22px; background: linear-gradient(var(--line), var(--line)) no-repeat 16px 0 / calc(100% - 32px) 1px; }
.foot a { color: inherit; }

/* ---------- Progress bits ---------- */
.bar { display: inline-block; width: 90px; height: 8px; border-radius: 99px; background: var(--dot); overflow: hidden; vertical-align: middle; flex: none; }
.bar i { display: block; height: 100%; background: var(--good-fill); border-radius: 99px; }
.dots { display: inline-flex; gap: 5px; }
.dots i { width: 11px; height: 11px; border-radius: 50%; background: var(--dot); }
.dots i.on { background: var(--btn-bg); }
.dots.all i { background: var(--good-fill); }

/* ---------- Home: courses ---------- */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 14px; }
.course-card { display: flex; flex-direction: column; gap: 4px; padding: 20px 20px 18px; background: var(--surface); border: 1px solid var(--line); border-top: 6px solid var(--cc); border-radius: 12px; text-decoration: none; color: var(--ink); transition: box-shadow .15s ease, border-color .15s ease; }
.course-card:hover { box-shadow: 0 8px 22px -14px var(--cc); border-color: var(--cc); }
.cc-name { font-family: var(--font-display); font-weight: 650; font-size: 22px; line-height: 1.2; }
.cc-meta { color: var(--muted); font-size: 14px; }
.course-card.quiet .cc-name { color: var(--muted); }

/* ---------- Course: units ---------- */
.unit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 14px; }
.unit-tile { display: flex; flex-direction: column; gap: 4px; min-height: 120px; padding: 18px 20px; background: var(--surface); border: 1.5px solid var(--line-strong); border-radius: 12px; color: var(--ink); text-decoration: none; transition: box-shadow .15s ease, border-color .15s ease; }
a.unit-tile:hover { border-color: var(--accent); box-shadow: 0 8px 22px -14px var(--accent); }
.u-num { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.u-title { font-family: var(--font-display); font-weight: 650; font-size: 21px; line-height: 1.2; color: var(--head); }
.u-meta { margin-top: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.unit-tile.soon { background: transparent; border-style: dashed; border-color: var(--line); color: var(--muted); }
.unit-tile.soon .u-num, .unit-tile.soon .u-title { color: var(--muted); opacity: .8; }

/* ---------- Unit: skills ---------- */
.unit-sum { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; color: var(--muted); font-size: 15px; }
.unit-sum strong { color: var(--ink); }
.unit-sum .bar { width: 140px; }
.skill-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.skill-card { background: var(--surface); border: 1.5px solid var(--line-strong); border-radius: 14px; padding: 28px 24px 24px; display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.skill-card h3 { font-family: var(--font-display); font-size: 26px; line-height: 1.2; margin: 0; color: var(--head); text-align: center; text-wrap: balance; }
.lv-cols { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 16px; justify-items: center; align-items: start; }
.lv-col { display: flex; flex-direction: column; gap: 10px; align-items: center; min-width: 0; }
.lv { border: 2px solid var(--head); background: var(--surface); color: var(--head); border-radius: 999px; padding: 8px 22px; font-weight: 700; font-size: 16px; white-space: nowrap; text-decoration: none; }
.lv:hover { background: var(--mist); }
.lv.done { background: var(--good-fill); border-color: var(--good-fill); color: var(--good-ink); }
.lv.done:hover { filter: brightness(1.08); }
.opts { display: flex; flex-direction: column; gap: 6px; padding-left: 4px; margin-top: 2px; }
.opts label { display: flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.opts input, .tick input, .check input { width: 17px; height: 17px; accent-color: var(--head); margin: 0; }
.lv-note { margin: 2px 0 0; font-size: 14px; color: var(--muted); text-align: center; }

/* ---------- Practice ---------- */
.q-status { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.pill { border: 1.5px solid var(--head); color: var(--head); border-radius: 999px; padding: 3px 14px; font-weight: 700; font-size: 14px; }
.meter { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--muted); }
.meter strong { color: var(--ink); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.lead { font-family: var(--font-display); font-size: 20px; line-height: 1.45; margin: 0; max-width: 62ch; }
.question { font-family: var(--font-display); font-size: 20px; font-weight: 700; margin: 0; max-width: 62ch; }
.stage { border-radius: 10px; padding: 18px; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); }
.expr { font-size: clamp(20px, 3.4vw, 28px); font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .01em; display: inline-block; padding: 2px 8px; border-radius: 6px; }
.dia { display: block; max-width: 100%; height: auto; }
.dia text { fill: var(--ink); font-family: var(--font-body); }
.dia .lbl { fill: var(--muted); font-weight: 600; }
.dia .tile { fill: var(--tile); stroke: var(--tile-edge); stroke-width: 1.25; }
.dia .cell { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1; }
.dia .th { fill: var(--mist); stroke: var(--line-strong); stroke-width: 1; }
.dia .grid { stroke: var(--grid); stroke-width: 1; }
.dia .axis { stroke: var(--ink); stroke-width: 1.5; }
.dia .pt { fill: var(--pt); }
.dia .bold { font-weight: 700; }

form.answer { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.prefix { font-size: 22px; font-weight: 600; }
.answer input { font-size: 20px; padding: 8px 12px; border: 1.5px solid var(--line-strong); border-radius: 10px; background: var(--surface); width: 240px; max-width: 100%; font-variant-numeric: tabular-nums; }
.answer input:disabled { opacity: .75; }
.btn { display: inline-block; background: var(--btn-bg); color: var(--btn-ink); border: 0; border-radius: 10px; padding: 10px 20px; font-weight: 700; text-decoration: none; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: none; color: var(--head); border: 1.5px solid var(--line-strong); }
.hint { font-size: 14px; color: var(--muted); margin: 0; }
.after { display: flex; flex-direction: column; gap: 14px; }
.after:empty { display: none; }
.fb-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.fb { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; padding: 8px 14px; border-radius: 10px; }
.fb.ok { background: var(--good-bg); color: var(--good); }
.fb.no { background: var(--bad-bg); color: var(--bad); }
.reveal { font-size: 18px; }
.reveal strong { font-variant-numeric: tabular-nums; }
.after-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Worked examples (notebook layout, shared by units) ---------- */
.wx { display: flex; flex-direction: column; gap: 26px; margin-top: 6px; max-width: 760px; }
.wx-row { display: grid; grid-template-columns: 36px minmax(0,1fr) minmax(0,1fr); gap: 10px 18px; align-items: center; }
.wx-two { align-items: start; }
.wx-num { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--head); color: var(--head); font-weight: 700; display: grid; place-items: center; font-size: 15px; }
.wx-label { font-weight: 600; font-size: 17px; }
.wx-label sup, .wx-cd sup { font-size: .65em; }
.wx-n { font-weight: 600; margin-left: 14px; font-variant-numeric: tabular-nums; }
.wx-col { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; min-width: 0; }
.wx-math { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.5; }
.vsub { display: inline-grid; justify-items: end; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.35; margin-left: 24px; }
.vsub i { font-style: normal; margin-right: 6px; }
.vsub .res { border-top: 2px solid var(--ink); padding-top: 4px; margin-top: 2px; min-width: 100%; text-align: right; }
.circ { display: inline-block; border: 2px solid var(--head); border-radius: 999px; padding: 0 12px; line-height: 1.35; }
.wx-rule { border: 0; border-top: 2px solid var(--line-strong); margin: 0; }
.wx-head .wx-label { grid-column: 2 / -1; }
.wx-sub { margin-top: -10px; }
.wx-sub .wx-label { font-weight: 500; }
.wx-sub .wx-math { font-size: 20px; }
.wx-arrows { min-width: 0; overflow-x: auto; }
.nb-arrows { display: block; max-width: 100%; height: auto; }
.nb-arrows text { font-family: var(--font-body); font-size: 26px; font-weight: 600; fill: var(--ink); }
.nb-arrows .nb-zero { fill: var(--c-zero); }
.nb-arrows .arc-d { fill: none; stroke: var(--c-diff); stroke-width: 2; }
.nb-arrows .arc-z { fill: none; stroke: var(--c-zero); stroke-width: 2; }
.nb-arrows .arc-d-t { fill: var(--c-diff); font-size: 15px; }
.nb-arrows .arc-z-t { fill: var(--c-zero); font-size: 15px; }
.nb-arrows .ah-d { fill: var(--c-diff); }
.nb-arrows .ah-z { fill: var(--c-zero); }
.wx-cd { font-size: 18px; font-weight: 500; display: flex; flex-direction: column; gap: 4px; }
.c-diff { color: var(--c-diff); font-size: 22px; }
.c-zero { color: var(--c-zero); font-size: 22px; }
.pairline { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 36px; }
.brk { display: inline-flex; flex-direction: column; align-items: center; }
.brk-b { width: 100%; height: 9px; border: 2px solid var(--ink); border-top: 0; margin-top: 2px; }
.brk-v { font-size: 18px; margin-top: 2px; }
.pairline .vsub { margin-left: 0; font-size: 20px; }
.wx-plain { font-weight: 500; font-size: 17px; }
.wx-top { align-items: start; }
.varlist { font-size: 18px; font-weight: 600; line-height: 1.7; font-variant-numeric: tabular-nums; padding-top: 4px; }
.sumf { display: grid; grid-template-columns: auto auto; justify-content: start; column-gap: 8px; row-gap: 6px; align-items: center; font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; font-size: .9em; line-height: 1.1; margin: 0 3px; }
.frac > span:first-child { border-bottom: 2px solid currentColor; padding: 0 3px; }
#exampleCard .after-actions { margin-top: 8px; }

/* ---------- Worksheets ---------- */
details.panel { padding: 0; gap: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; }
details.panel summary { cursor: pointer; list-style: none; padding: 16px 20px; font-family: var(--font-display); font-size: 20px; font-weight: 600; color: var(--head); display: flex; align-items: center; gap: 10px; }
details.panel summary::-webkit-details-marker { display: none; }
details.panel summary::before { content: "▸"; font-size: 14px; transition: transform .15s; }
details.panel[open] summary::before { transform: rotate(90deg); }
.panel-body { padding: 14px 20px 20px; display: flex; flex-direction: column; gap: 20px; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.ws-title { max-width: 420px; }
.text-in { padding: 8px 10px; border: 1.5px solid var(--line-strong); border-radius: 8px; background: var(--surface); }
.ws-rows { display: flex; flex-direction: column; }
.ws-row { display: grid; grid-template-columns: minmax(0, 15em) auto minmax(0, 1fr); align-items: center; gap: 8px 18px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ws-row:last-child { border-bottom: 0; }
.ws-name { font-weight: 600; font-size: 15px; }
.ws-opts { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.tick, .check { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; cursor: pointer; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.stepper button { border: 0; background: var(--mist); width: 32px; height: 32px; font-weight: 700; }
.stepper output { width: 36px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.status { font-size: 14px; color: var(--muted); margin: 0; min-height: 1.5em; }
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 28px; min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.sheet-h { display: flex; flex-direction: column; gap: 6px; border-bottom: 2px solid var(--head); padding-bottom: 12px; }
.sheet-h h2 { font-family: var(--font-display); margin: 0; font-size: 24px; color: var(--head); }
.sheet-h .nameline { font-size: 14px; color: var(--muted); word-spacing: 2px; }
.sec-h { font-weight: 700; color: var(--head); font-size: 15px; margin: 6px 0 0; }
.wp { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 8px; padding-bottom: 16px; border-bottom: 1px dashed var(--line); }
.wp .num { font-weight: 700; font-variant-numeric: tabular-nums; }
.wp .body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.wp .lead, .wp .question { font-size: 16px; }
.wp .expr { font-size: 18px; padding: 0; }
.wp .dia-box { overflow-x: auto; }
.wp .ans { font-size: 14px; background: var(--butter); padding: 2px 8px; border-radius: 6px; align-self: flex-start; font-weight: 600; }
.empty { color: var(--muted); font-size: 15px; }
.work, .ansline, .print-key { display: none; }

/* ---------- Mastery popup ---------- */
.modal { position: fixed; inset: 0; z-index: 20; background: var(--scrim); display: grid; place-items: center; padding: 24px 16px; }
.modal-box { background: var(--surface); border-radius: 16px; padding: 32px 28px; max-width: 440px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; box-shadow: 0 20px 50px rgba(20,24,50,.25); }
.m-badge { width: 64px; height: 64px; border-radius: 50%; background: var(--good-fill); color: var(--good-ink); font-size: 34px; font-weight: 700; display: grid; place-items: center; }
.modal-box h2 { font-family: var(--font-display); font-size: 26px; margin: 0; color: var(--head); text-wrap: balance; }
.m-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ---------- Small screens ---------- */
@media (max-width: 820px) {
  .skill-grid { grid-template-columns: minmax(0, 1fr); }
  .ws-row { grid-template-columns: minmax(0, 1fr) auto; }
  .ws-opts { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .wx-head .wx-label { grid-column: 2; }
  .wx-row { grid-template-columns: 32px minmax(0, 1fr); }
  .wx-row .wx-math { grid-column: 2; }
  .wx-two { grid-template-columns: 32px minmax(0, 1fr) minmax(0, 1fr); }
  .wx-top .varlist, .wx-top .sumf { grid-column: 2; }
  .sumf { font-size: 19px; overflow-x: auto; }
  .sumf > span { white-space: nowrap; }
}
@media (max-width: 480px) {
  .card, .sheet { padding: 18px; }
  .skill-card { padding: 22px 16px 20px; }
  .lead, .question { font-size: 18px; }
}
@media (prefers-reduced-motion: no-preference) {
  .fb { animation: pop .18s ease-out; }
  @keyframes pop { from { transform: scale(.94); opacity: .4; } to { transform: none; opacity: 1; } }
}
@media (prefers-reduced-motion: reduce) {
  .course-card, .unit-tile, details.panel summary::before { transition: none; }
}

/* ---------- Print: only the worksheet, always in light colours ---------- */
@media print {
  @page { margin: 0.55in; }
  :root { --bg: #fff; --surface: #fff; --ink: #1c2240; --muted: #555; --line: #bbb; --line-strong: #888; --head: #3f4a75; --butter: #fff2be; --mist: #ecedf1; --grid: #e6e9f1; --tile: #cdebfb; --tile-edge: #054279; --pt: #054279; color-scheme: light; }
  body { background: #fff; display: block; }
  .band, .foot, .ws-settings, .modal { display: none !important; }
  main.wrap { padding: 0; max-width: none; }
  .view { gap: 0; }
  .sheet { border: 0; padding: 0; border-radius: 0; gap: 14px; }
  .sec-h { break-after: avoid; margin-top: 10px; }
  .wp { break-inside: avoid; border-bottom: 1px solid #bbb; padding-bottom: 10px; }
  .work { display: block; }
  .work.s { height: .75in; } .work.m { height: 1.05in; } .work.l { height: 1.35in; }
  .ansline { display: flex; justify-content: flex-end; align-items: flex-end; gap: 8px; font-weight: 600; font-size: 15px; }
  .ansline span { display: inline-block; width: 2.6in; border-bottom: 1.5px solid #333; }
  .print-key { display: block; break-before: page; }
  .print-key h2 { font-family: var(--font-display); color: var(--head); margin: 0 0 4px; font-size: 22px; }
  .print-key .sub { color: #555; font-size: 13px; margin-bottom: 14px; }
  .print-key .keylist { columns: 2; column-gap: 36px; font-size: 14px; line-height: 2; }
  .print-key .keylist div { break-inside: avoid; }
}
