/* ==========================================================================
   Study Hub — app.css: the one design system for every page and course.
   1 tokens · 2 base · 3 shell (top bar, sidebar, main) · 4 banners · 5 cards & dashboard
   6 lesson components · 7 figures · 8 question cards · 9 tools (lab, quiz, review, reference) · 10 print
   Each course sets --course (its accent) on <html>; components use --acc.
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  color-scheme: light;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px; --radius-sm: 8px; --radius-lg: 16px;
  --topbar-h: 56px; --sidebar-w: 280px; --content-max: 780px; --wide-max: 1080px; --gutter: 16px;
  --bg: #f6f7f9; --bg-elev: #ffffff; --bg-sunken: #eef1f5;
  --ink: #18212b; --ink-muted: #556270; --ink-faint: #66727f;
  --line: #dde2e8; --line-strong: #c3cbd4; --line-input: #8a95a1;
  --accent: #0b6b86; --accent-soft: #e3f2f6; --accent-ink: #fff;
  --course: var(--accent);
  --acc: var(--course);
  --acc-soft: color-mix(in srgb, var(--acc) 12%, var(--bg-elev));
  --c-good: #23793a; --c-good-soft: #e6f4ea; --c-bad: #c92a2a; --c-bad-soft: #fdecec;
  --c-warn: #9a5100; --c-warn-soft: #fff4e5; --c-info: #1769bd; --c-info-soft: #e8f1fb;
  --c-axis: #3a4450; --c-grid: #dbe1e7; --c-curve: #1769bd; --c-curve2: #c2410c; --c-curve3: #6d44e0;
  --c-vec1: #23793a; --c-vec2: #c92a2a; --c-fill: rgba(23, 105, 189, 0.16); --c-fill2: rgba(194, 65, 12, 0.16);
  --viz-bg: #fbfcfd; --viz-ui-bg: rgba(255, 255, 255, 0.88);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 6px 18px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 14px 36px rgba(16, 24, 40, 0.18);
  --scrim: rgba(14, 19, 24, 0.45); --track: #d3dae2; --row-alt: rgba(16, 24, 40, 0.025);
  --paper-line: rgba(11, 107, 134, 0.07);
  --ex-c1: #1769bd; --ex-c2: #c2410c; --ex-c3: #6d44e0; --ex-c4: #0f766e; --ex-c5: #a21caf; --ex-c6: #8a5a00;   /* Motion explorer: colour of each row */
}
@media screen {
  html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0e1318; --bg-elev: #161c23; --bg-sunken: #1d242c;
    --ink: #e5eaf0; --ink-muted: #9ba7b4; --ink-faint: #85919e;
    --line: #2a333d; --line-strong: #3b4652; --line-input: #66717e;
    --accent: #4fc0dc; --accent-soft: #15303a; --accent-ink: #062530;
    --acc: color-mix(in srgb, var(--course) 55%, #ffffff);
    --acc-soft: color-mix(in srgb, var(--course) 22%, var(--bg-elev));
    --c-good: #5cc26f; --c-good-soft: #142b1b; --c-bad: #ff6b6b; --c-bad-soft: #321718;
    --c-warn: #ffb454; --c-warn-soft: #2e2413; --c-info: #5eaaff; --c-info-soft: #13243a;
    --c-axis: #b3bdc8; --c-grid: #2c3641; --c-curve: #5eaaff; --c-curve2: #ff8a4c; --c-curve3: #a98bff;
    --c-vec1: #5cc26f; --c-vec2: #ff6b6b; --c-fill: rgba(94, 170, 255, 0.2); --c-fill2: rgba(255, 138, 76, 0.2);
    --viz-bg: #11171d; --viz-ui-bg: rgba(22, 28, 35, 0.88);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
    --scrim: rgba(0, 0, 0, 0.6); --track: #35404c; --row-alt: rgba(255,255,255,.025);
    --paper-line: rgba(79, 192, 220, 0.05);
    --ex-c1: #5eaaff; --ex-c2: #ff8a4c; --ex-c3: #a98bff; --ex-c4: #2dd4bf; --ex-c5: #f0abfc; --ex-c6: #fbbf24;
  }
}

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-family: var(--font-sans); font-size: 1rem; line-height: 1.6; overflow-wrap: break-word; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.sa-nocss { display: none !important; }
a { color: var(--acc); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.01em; margin: 0 0 0.55em; text-wrap: balance; }
h1 { font-size: clamp(1.7rem, 1.2rem + 2vw, 2.35rem); line-height: 1.15; letter-spacing: -0.02em; }
h2 { font-size: 1.36em; margin-top: 2.2em; }
h3 { font-size: 1.12em; margin-top: 1.6em; }
p, ul, ol, dl, figure, table, pre { margin: 0 0 0.85em; }
ul, ol { padding-left: 1.4em; }
li { margin: 0.3em 0; }
code, pre, kbd { font-family: var(--font-mono); font-size: 0.92em; }
code { padding: 0.08em 0.3em; border-radius: 5px; background: var(--bg-sunken); }
pre { padding: 12px 14px; overflow-x: auto; border-radius: var(--radius-sm); background: var(--bg-sunken); line-height: 1.45; }
pre code { padding: 0; background: none; }
strong { font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
input[type="text"], input[type="search"], input[type="date"], input[type="number"], textarea, select {
  max-width: 100%; padding: 7px 10px; border: 1px solid var(--line-input); border-radius: var(--radius-sm); background: var(--bg-elev); color: var(--ink);
}
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.katex { font-size: 1.07em; }
.katex-display { max-width: 100%; margin: 0.9em 0; padding: 2px 0 4px; overflow-x: auto; overflow-y: hidden; }
.muted { color: var(--ink-muted); }
.nowrap { white-space: nowrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 7px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg-elev); color: var(--ink); font-weight: 600; font-size: 0.93rem; text-decoration: none; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--acc); color: var(--acc); }
.btn.primary { border-color: var(--acc); background: var(--acc); color: #fff; }
html[data-theme="dark"] .btn.primary { color: #0b1015; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); color: #fff; }
html[data-theme="dark"] .btn.primary:hover:not(:disabled) { color: #0b1015; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: 0.85rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0.6em 0 1em; }
button.mini { min-width: 30px; min-height: 30px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg-elev); cursor: pointer; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 12px; border: 1px solid var(--line-strong); border-radius: 99px; background: var(--bg-elev); font-size: 0.88rem; font-weight: 600; cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--acc); background: var(--acc-soft); color: var(--acc); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; background: var(--bg-sunken); color: var(--ink-muted); font-size: 0.78rem; font-weight: 650; }
.pill.acc { background: var(--acc-soft); color: var(--acc); }
.pill.good { background: var(--c-good-soft); color: var(--c-good); }
.pill.warn { background: var(--c-warn-soft); color: var(--c-warn); }
.pill.bad { background: var(--c-bad-soft); color: var(--c-bad); }
.ic { width: 20px; height: 20px; flex: none; }

/* 3. Shell ----------------------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 6px; height: var(--topbar-h); padding: 0 12px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg-elev) 92%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.tb-brand { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; color: var(--ink); font-weight: 750; text-decoration: none; }
.tb-course { display: inline-flex; align-items: center; gap: 7px; min-width: 0; padding: 5px 10px; border-radius: 99px; background: var(--acc-soft); color: var(--acc); font-weight: 700; font-size: 0.9rem; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--acc); flex: none; }
.tb-course-title { font-weight: 600; }
.tb-spacer { flex: 1; }
.tb-btn { position: relative; display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--ink-muted); cursor: pointer; }
.tb-btn:hover { background: var(--bg-sunken); color: var(--ink); }
.tb-badge { position: absolute; top: 3px; right: 1px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--c-bad); color: #fff; font-size: 0.68rem; font-weight: 800; line-height: 18px; text-align: center; }
.tb-menu { display: none; }
@media (max-width: 639.98px) { .tb-course-title, .tb-brand span { display: none; } }
.sidebar { position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 30; width: var(--sidebar-w); padding: 14px 10px 30px; overflow-y: auto; border-right: 1px solid var(--line); background: var(--bg-elev); }
.sb-head { margin: 14px 10px 6px; color: var(--ink-faint); font-size: 0.72rem; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
.sb-list { list-style: none; margin: 0; padding: 0; }
.sb-list li { margin: 1px 0; }
.sb-link { display: flex; gap: 9px; align-items: baseline; padding: 6px 10px; border-radius: 8px; color: var(--ink); font-size: 0.9rem; line-height: 1.35; text-decoration: none; }
.sb-link:hover { background: var(--bg-sunken); }
.sb-link.is-active { background: var(--acc-soft); color: var(--acc); font-weight: 650; }
.sb-num { flex: none; min-width: 1.6em; color: var(--ink-faint); font-variant-numeric: tabular-nums; font-size: 0.82rem; font-weight: 700; }
.sb-link.is-done .sb-num { color: var(--c-good); }
.sb-link.is-done .sb-num::after { content: " ✓"; }
.scrim { position: fixed; inset: var(--topbar-h) 0 0; z-index: 25; background: var(--scrim); }
main { display: block; width: 100%; max-width: calc(var(--content-max) + 2 * var(--gutter)); margin: 0 auto; padding: 22px var(--gutter) 40px; }
main.wide { max-width: calc(var(--wide-max) + 2 * var(--gutter)); }
body.has-course main { margin-left: auto; }
@media (min-width: 1100px) {
  body.has-course main { margin-left: max(calc(var(--sidebar-w) + 20px), calc((100vw - var(--content-max)) / 2)); margin-right: auto; }
  body.has-course main.wide { margin-left: calc(var(--sidebar-w) + 20px); max-width: min(calc(100vw - var(--sidebar-w) - 40px), calc(var(--wide-max) + 2 * var(--gutter))); }
}
@media (max-width: 1099.98px) {
  .tb-menu { display: inline-grid; }
  .sidebar { transform: translateX(-102%); transition: transform 0.2s; box-shadow: var(--shadow-lg); }
  body.sb-open .sidebar { transform: none; }
}
.foot { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--ink-faint); font-size: 0.84rem; }
.eyebrow { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 8px; color: var(--acc); font-size: 0.8rem; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; }
.lede { color: var(--ink-muted); font-size: 1.1rem; }
.page-head { margin-bottom: 1.6rem; }

/* 4. Banners --------------------------------------------------------------- */
.banner { margin: 0 0 18px; padding: 12px 16px; border: 1px solid var(--line-strong); border-left-width: 4px; border-radius: var(--radius-sm); background: var(--bg-elev); }
.banner.warn { border-color: var(--c-warn); background: var(--c-warn-soft); }
.banner.bad { border-color: var(--c-bad); background: var(--c-bad-soft); }
.banner.good { border-color: var(--c-good); background: var(--c-good-soft); }
.banner.info { border-color: var(--c-info); background: var(--c-info-soft); }

/* 5. Cards & dashboard ------------------------------------------------------- */
.card { display: block; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); color: var(--ink); text-decoration: none; box-shadow: var(--shadow-sm); }
a.card:hover { border-color: var(--acc); box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); margin: 0; padding: 0; list-style: none; }
.grid > li { display: flex; margin: 0; }
.grid > li > * { flex: 1; }
.course-card { position: relative; display: flex; flex-direction: column; gap: 8px; border-top: 5px solid var(--cc, var(--acc)); }
.course-card h3 { margin: 0; font-size: 1.1rem; }
.course-card h3 a { color: var(--ink); text-decoration: none; }
.course-card h3 a:hover { color: var(--cc, var(--acc)); text-decoration: underline; }
.course-card .cc-code { color: var(--cc, var(--acc)); font-size: 0.8rem; font-weight: 800; letter-spacing: 0.06em; }
html[data-theme="dark"] .course-card .cc-code { color: color-mix(in srgb, var(--cc) 55%, #fff); }
.cc-exam { font-size: 0.9rem; }
.cc-exam strong { font-variant-numeric: tabular-nums; }
.cc-weak { margin: 0; color: var(--ink-muted); font-size: 0.86rem; }
.cc-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 6px; }
.bar { height: 7px; overflow: hidden; border-radius: 99px; background: var(--track); }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--cc, var(--acc)); }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 0.86rem; color: var(--ink-muted); }
.bar-row .bar { flex: 1; }
.hero { position: relative; padding: 6px 0 20px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.search-box { display: flex; gap: 8px; margin: 10px 0; }
.search-box input { flex: 1; min-height: 44px; font-size: 1.02rem; }
.search-results { margin: 0; padding: 0; list-style: none; }
.search-results li { margin: 0; border-bottom: 1px solid var(--line); }
.search-results a { display: block; padding: 9px 4px; color: var(--ink); text-decoration: none; }
.search-results a:hover { background: var(--bg-sunken); }
.sr-kind { margin-right: 8px; }
.sr-snip { display: block; color: var(--ink-muted); font-size: 0.87rem; }
.stat-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 16px; }
.stat { min-width: 120px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-elev); }
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--ink-muted); font-size: 0.8rem; }
.lesson-list { margin: 0; padding: 0; list-style: none; counter-reset: none; }
.lesson-list li { margin: 0 0 8px; }
.lesson-item { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 2px 12px; align-items: start; padding: 12px 14px; }
.li-num { grid-row: 1 / span 2; display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: var(--bg-sunken); color: var(--ink-muted); font-weight: 750; font-size: 0.85rem; }
.lesson-item.is-done .li-num { border-color: color-mix(in srgb, var(--c-good) 45%, transparent); background: var(--c-good-soft); color: var(--c-good); }
.li-title { margin: 0; font-size: 1rem; font-weight: 650; }
.li-meta { grid-column: 2; margin: 0; color: var(--ink-muted); font-size: 0.84rem; }
.li-side { grid-row: 1 / span 2; grid-column: 3; color: var(--ink-faint); font-size: 0.82rem; white-space: nowrap; }
.group-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin: 1.8em 0 0.6em; }
.group-head h3 { margin: 0; }

/* 6. Lesson components ------------------------------------------------------- */
.lesson-header { position: relative; isolation: isolate; margin-bottom: 1.4rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.lesson-header::before { content: ""; position: absolute; z-index: -1; inset: -22px calc(-1 * min(20px, var(--gutter))) 0; background-image: linear-gradient(var(--paper-line) 1px, transparent 1px), linear-gradient(90deg, var(--paper-line) 1px, transparent 1px); background-size: 22px 22px; -webkit-mask-image: radial-gradient(120% 95% at 0% 0%, #000 25%, transparent 72%); mask-image: radial-gradient(120% 95% at 0% 0%, #000 25%, transparent 72%); pointer-events: none; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0 0; color: var(--ink-muted); font-size: 0.86rem; }
.objectives, .takeaways, .prereq { margin: 1.2rem 0; padding: 14px 18px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
.objectives h2, .takeaways h2, .prereq h2 { margin: 0 0 8px; font-size: 1.02rem; }
.objectives { border-left: 4px solid var(--acc); }
.takeaways { background: var(--acc-soft); border-color: color-mix(in srgb, var(--acc) 30%, transparent); }
.hook { margin: 1rem 0 1.4rem; font-size: 1.05rem; }
.key-result { margin: 1.2em 0; padding: 12px 18px 6px; border: 1px solid color-mix(in srgb, var(--acc) 40%, transparent); border-radius: var(--radius); background: var(--acc-soft); }
.key-title { margin: 0 0 2px; color: var(--acc); font-size: 0.8rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.callout { margin: 1.2em 0; padding: 12px 16px 6px; border: 1px solid var(--line); border-left: 4px solid var(--c-info); border-radius: var(--radius-sm); background: var(--bg-elev); }
.callout.warning { border-left-color: var(--c-warn); background: var(--c-warn-soft); }
.callout.link { border-left-color: var(--c-good); }
.callout-title { margin: 0 0 4px; font-weight: 750; }
.example { margin: 1.3em 0; padding: 14px 18px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.example-title { margin: 0 0 6px; font-weight: 750; }
details.solution { margin: 8px 0 6px; border-top: 1px dashed var(--line-strong); }
details.solution > summary { padding: 8px 0 4px; color: var(--acc); font-weight: 700; cursor: pointer; list-style: revert; }
details.solution[open] > summary { margin-bottom: 6px; }
.src { margin: 0.2em 0 0.8em; color: var(--ink-faint); font-size: 0.8rem; }
.src::before { content: "📖 "; }
p.src { font-style: normal; }
.toc { margin: 0 0 1.2rem; padding: 10px 16px; border-radius: var(--radius-sm); background: var(--bg-sunken); font-size: 0.9rem; }
.toc ol { margin: 4px 0; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 2rem; }
.pager a { display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-elev); color: var(--ink); text-decoration: none; }
.pager a:hover { border-color: var(--acc); }
.pager small { display: block; color: var(--ink-faint); }
.pager .next { text-align: right; grid-column: 2; }
.complete-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 2rem 0 0; padding: 14px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
.complete-box.is-done { border-color: color-mix(in srgb, var(--c-good) 45%, transparent); background: var(--c-good-soft); }
.table-wrap { overflow-x: auto; margin: 1em 0; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
table.data caption { margin-bottom: 6px; color: var(--ink-muted); font-size: 0.86rem; text-align: left; caption-side: top; }
table.data th, table.data td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data thead th { border-bottom: 2px solid var(--line-strong); font-size: 0.85rem; }
table.data tbody tr:nth-child(even) { background: var(--row-alt); }
.table-scroll { overflow-x: auto; max-width: 100%; }
table.data.stat { font-size: 0.8rem; font-variant-numeric: tabular-nums; }
table.data.stat th, table.data.stat td { padding: 3px 7px; text-align: right; white-space: nowrap; }
table.data.stat tbody th { font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.cross-link { display: inline-flex; gap: 6px; align-items: baseline; }

/* 7. Figures ----------------------------------------------------------------- */
figure.figure { margin: 1.4em 0; }
.viz { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--viz-bg); }
.viz-stage { position: relative; }
.viz-stage svg, .viz-stage canvas { display: block; width: 100%; height: auto; touch-action: none; }
.viz-stage .katex svg { height: inherit; }   /* KaTeX draws roots and long arrows as SVG: keep its own sizing in figure labels */
.viz-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--bg-elev); font-size: 0.9rem; }
.viz-controls label { display: inline-flex; align-items: center; gap: 8px; }
.viz-controls input[type="range"] { width: 150px; accent-color: var(--acc); }
.viz-readout { font-variant-numeric: tabular-nums; color: var(--ink-muted); }
figure.figure figcaption { margin-top: 8px; color: var(--ink-muted); font-size: 0.88rem; line-height: 1.55; }
.fig-label { position: absolute; transform: translate(-50%, -50%); padding: 0 2px; border-radius: 3px; background: var(--viz-ui-bg); color: var(--ink); font-size: 0.86rem; line-height: 1.2; white-space: nowrap; pointer-events: none; }
.fig-overlay { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { margin: 0 0 6px; padding-left: 10px; border-left: 4px solid var(--cc, var(--acc)); }
.quiz-q { margin: 0 0 1.6rem; }
#review-list { margin: 0; padding: 0; list-style: none; }
#review-list > li { margin: 0 0 8px; }
.gl-entry { scroll-margin-top: calc(var(--topbar-h) + 12px); }
.fig-hint { position: absolute; top: 8px; right: 10px; padding: 3px 8px; border-radius: 6px; background: var(--viz-ui-bg); color: var(--ink-muted); font-size: 0.75rem; pointer-events: none; }
.fig-btn { position: absolute; top: 8px; left: 8px; z-index: 2; padding: 4px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--viz-ui-bg); font-size: 0.78rem; font-weight: 650; cursor: pointer; }

/* 8. Question cards ------------------------------------------------------------ */
.q-card { margin: 1.2em 0; padding: 14px 18px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.q-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; }
.q-title { margin: 0 0 6px; font-size: 0.82rem; color: var(--acc); font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; }
.q-head .src { margin: 0; }
.q-prompt { margin-bottom: 8px; }
.q-field { position: relative; margin: 8px 0; padding: 6px 30px 6px 0; }
.q-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.q-label { font-weight: 600; }
.q-input { min-width: 0; width: min(100%, 280px); min-height: 38px; font-family: var(--font-mono); }
.q-textarea { width: 100%; font-family: var(--font-mono); }
.q-unit { color: var(--ink-muted); }
.q-echo { min-height: 1.2em; margin-top: 3px; color: var(--ink-muted); font-size: 0.86rem; }
.echo-bad { color: var(--c-warn); }
.q-mark { position: absolute; top: 10px; right: 4px; font-weight: 900; }
.q-field.is-right .q-mark { color: var(--c-good); }
.q-field.is-wrong .q-mark { color: var(--c-bad); }
.q-field.is-right .q-input { border-color: var(--c-good); }
.q-field.is-wrong .q-input { border-color: var(--c-bad); }
.q-choices { margin: 0; padding: 0; border: 0; }
.q-opt { display: flex; gap: 10px; align-items: baseline; margin: 5px 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.q-opt:hover { border-color: var(--acc); }
.q-opt input { flex: none; margin-top: 4px; }
.q-note { margin: 4px 0 0; color: var(--ink-faint); font-size: 0.82rem; }
.q-order { margin: 6px 0; padding: 0; list-style: none; counter-reset: ord; }
.q-order-item { display: flex; gap: 10px; align-items: center; margin: 5px 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-elev); counter-increment: ord; }
.q-order-item::before { content: counter(ord); flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--bg-sunken); font-size: 0.8rem; font-weight: 750; }
.q-order-text { flex: 1; }
.q-order-btns { display: flex; gap: 4px; }
.q-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.q-feedback { margin-top: 8px; padding: 0; border-radius: var(--radius-sm); }
.q-feedback:not(:empty) { padding: 9px 12px; }
.q-feedback.good { background: var(--c-good-soft); color: var(--ink); border-left: 4px solid var(--c-good); }
.q-feedback.bad { background: var(--c-bad-soft); border-left: 4px solid var(--c-bad); }
.q-feedback.info { background: var(--c-info-soft); border-left: 4px solid var(--c-info); }
.q-hints { margin: 10px 0 0; padding: 10px 14px 6px 34px; border-radius: var(--radius-sm); background: var(--c-warn-soft); }
.q-solution { margin-top: 10px; padding: 10px 14px 4px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--bg-sunken); }
.q-key { margin-bottom: 8px; }
.q-keylabel { color: var(--ink-muted); }
.steps { padding-left: 1.3em; }
.steps li { margin: 0.35em 0; }
.ans-pre { display: inline-block; margin: 4px 0; }

/* 9. Tools ------------------------------------------------------------------ */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin: 10px 0 14px; }
.toolbar label { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.92rem; }
.lab-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; color: var(--ink-muted); font-size: 0.88rem; }
.lab-streak.is-hot { background: var(--c-warn-soft); color: var(--c-warn); }
.review-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.quiz-timer { position: sticky; top: calc(var(--topbar-h) + 8px); z-index: 5; display: inline-flex; gap: 10px; align-items: center; padding: 6px 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--bg-elev); box-shadow: var(--shadow-sm); font-variant-numeric: tabular-nums; font-weight: 700; }
.quiz-timer.low { border-color: var(--c-bad); color: var(--c-bad); }
.q-num { color: var(--ink-faint); font-weight: 750; }
.formula-sec { margin: 0 0 1.2rem; break-inside: avoid; }
.formula-sec h2 { margin: 1.2em 0 0.5em; font-size: 1.1rem; }
.formula-sec > .fi-note { margin: -0.2em 0 0.6em; color: var(--ink-faint); font-size: 0.85rem; }
.formula-sec.extra { border-left: 3px dashed var(--line); padding-left: 0.8rem; }
@media print { .formula-sec.extra { display: none; } }
.formula-item { display: grid; grid-template-columns: minmax(0, 12em) minmax(0, 1fr); gap: 4px 14px; padding: 6px 0; border-bottom: 1px solid var(--line); break-inside: avoid; }
.formula-item .fi-name { color: var(--ink-muted); font-size: 0.9rem; }
.formula-item .fi-note { grid-column: 2; color: var(--ink-faint); font-size: 0.8rem; }
@media (max-width: 559.98px) { .formula-item { grid-template-columns: 1fr; } .formula-item .fi-note { grid-column: 1; } }
.gloss dt { margin-top: 12px; font-weight: 750; }
.gloss dd { margin: 2px 0 0; color: var(--ink); }
.gloss .gl-links { color: var(--ink-faint); font-size: 0.82rem; }
.letter-nav { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 14px; }
.letter-nav a { min-width: 28px; padding: 2px 6px; border-radius: 6px; background: var(--bg-sunken); text-align: center; text-decoration: none; font-weight: 650; }
.ws-problem { margin: 0 0 18px; padding: 0 0 12px; border-bottom: 1px solid var(--line); break-inside: avoid; }
.ws-space { height: 150px; border: 1px dashed var(--line-strong); border-radius: 6px; margin-top: 8px; }
.ws-key li { margin-bottom: 8px; }

/* 10. Print ------------------------------------------------------------------ */
@media print {
  :root { --bg: #fff; --bg-elev: #fff; }
  .topbar, .sidebar, .scrim, .foot, .btn-row, .toolbar, .q-actions, .pager, .complete-box, .no-print, .fig-btn { display: none !important; }
  body.has-course main, main { margin: 0 !important; max-width: none; padding: 0; }
  .card, .example, .q-card, .key-result { box-shadow: none; break-inside: avoid; }
  details.solution:not([open]) { display: none; }
  a { color: inherit; text-decoration: none; }
  .print-break { break-before: page; }
  .formula-cols { columns: 2; column-gap: 24px; font-size: 0.84rem; }
}

/* C trace (fig/ctrace.js): C Tutor-style memory diagrams ------------------ */
.ctrace { border: 1px solid var(--line); border-radius: var(--radius); background: var(--viz-bg); padding: 10px; margin: 12px 0; }
.ct-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.ct-bar input[type=range] { flex: 1 1 140px; }
.ct-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 12px; }
@media (max-width: 719.98px) { .ct-grid { grid-template-columns: 1fr; } }
.ct-code { margin: 0; max-height: 340px; overflow: auto; font: 0.8rem/1.45 var(--font-mono); background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 0; }
.ct-line { display: block; padding: 0 8px 0 0; white-space: pre; }
.ct-line.cur { background: var(--acc-soft); box-shadow: inset 3px 0 0 var(--acc); }
.ct-ln { display: inline-block; width: 2.6em; text-align: right; margin-right: 10px; color: var(--ink-faint); user-select: none; }
.ct-outlabel, .ct-head { font-size: 0.78rem; font-weight: 600; color: var(--ink-muted); margin: 8px 0 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.ct-out { margin: 0; min-height: 2.2em; max-height: 120px; overflow: auto; font: 0.8rem/1.4 var(--font-mono); background: var(--bg-sunken); border-radius: var(--radius-sm); padding: 6px 8px; white-space: pre-wrap; }
.ct-mem { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-content: start; overflow: auto; font-size: 0.82rem; }
.ct-arrows { position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none; overflow: visible; color: var(--c-curve); }
.ct-arrows path { fill: none; stroke: currentColor; stroke-width: 1.6; }
.ct-col { position: relative; min-width: 0; }
.ct-frame, .ct-block { background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: 6px; margin-bottom: 8px; padding: 4px 6px; }
.ct-frame.top { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc); }
.ct-frame.global { border-style: dashed; }
.ct-fname { font: 600 0.78rem var(--font-mono); color: var(--ink-muted); margin-bottom: 2px; }
.ct-frame table, .ct-struct { border-collapse: collapse; }
.ct-frame th, .ct-struct th { text-align: right; font: 0.78rem var(--font-mono); padding: 2px 6px 2px 0; color: var(--ink-muted); font-weight: 500; }
.ct-frame td, .ct-struct td { padding: 2px 0; }
.ct-struct { border: 1px solid var(--line); margin: 1px 0; }
.ct-struct caption { font: 0.72rem var(--font-mono); color: var(--ink-faint); text-align: left; }
.ct-val, .ct-null, .ct-undef, .ct-str { display: inline-block; min-width: 2em; padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 3px; font-family: var(--font-mono); background: var(--viz-bg); }
.ct-null { color: var(--ink-faint); } .ct-undef { color: var(--ink-faint); } .ct-str { color: var(--c-curve2); }
.ct-dot { display: inline-block; width: 12px; height: 12px; margin: 3px 8px; border-radius: 50%; background: var(--c-curve); vertical-align: middle; }
.ct-dot.dangling { background: var(--c-bad); }
.ct-arr { display: inline-flex; flex-wrap: wrap; }
.ct-cell { display: inline-flex; flex-direction: column; align-items: center; border: 1px solid var(--line-strong); margin-right: -1px; padding: 1px 3px; background: var(--bg-elev); }
.ct-cell .ct-val, .ct-cell .ct-null { border: 0; padding: 0 2px; min-width: 1.4em; text-align: center; }
.ct-idx { font-size: 0.65rem; color: var(--ink-faint); }
.ct-empty { color: var(--ink-faint); font-style: italic; }

/* Two side-by-side blocks (e.g. a .h and a .c file) that stack on phones */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.grid-2 pre { margin-top: 4px; }
@media (max-width: 719.98px) { .grid-2 { grid-template-columns: 1fr; } }

/* Digital-logic figures (fig/logic.js) ------------------------------------ */
.lg-stage { background: var(--viz-bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.lg-stage svg.lg-svg { margin: 0 auto; touch-action: auto; }
.lg-text { fill: var(--ink); font: 14px var(--font-sans); }
.lg-kvar { font-style: italic; font-size: 15px; }
.lg-khead { font: 13px var(--font-mono); fill: var(--ink-muted); }
.lg-kidx { font-size: 10px; fill: var(--ink-faint); }
.lg-kval { font: 600 18px var(--font-mono); fill: var(--ink-muted); }
.lg-kval.is-one { fill: var(--ink); }
.lg-kval.is-x { fill: var(--c-warn); }
.lg-kcell { fill: var(--bg-elev); stroke: var(--line-strong); stroke-width: 1; }
.lg-kcell.is-shaded { fill: var(--acc-soft); }
.lg-kline { stroke: var(--line-strong); stroke-width: 1; }
.lg-loop { fill-opacity: .07; stroke-width: 2.5; }
.lg-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; margin-top: 6px; font-size: .95rem; }
.lg-leg-item { display: inline-flex; align-items: center; gap: 6px; }
.lg-leg-item i { display: inline-block; width: 18px; height: 12px; border: 2.5px solid; border-radius: 6px; }
.lg-wire { fill: none; stroke: var(--ink-faint); stroke-width: 1.6; stroke-linejoin: round; }
.lg-wire.is-one { stroke: var(--c-curve); stroke-width: 2.6; }
.lg-dot { fill: var(--ink-faint); }
.lg-dot.is-one { fill: var(--c-curve); }
.lg-gate { fill: var(--bg-elev); stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; }
.lg-gate-line, .lg-clk { fill: none; stroke: var(--ink); stroke-width: 1.8; }
.lg-bubble { fill: var(--bg-elev); stroke: var(--ink); stroke-width: 1.6; }
.lg-g.is-hl .lg-gate { fill: var(--c-warn-soft); stroke: var(--c-warn); stroke-width: 2.6; }
.lg-pin { font-size: 12px; }
.lg-glabel { font-size: 12px; fill: var(--ink-muted); font-style: italic; }
.lg-note { font-size: 11.5px; fill: var(--ink-muted); }
.lg-rail-name, .lg-out-name { font-weight: 600; }
.lg-const { font: 13px var(--font-mono); }
.lg-toggles { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.lg-toggle[aria-pressed="true"] { background: var(--c-info-soft); border-color: var(--c-curve); color: var(--ink); }
.lg-hint { font-size: .85rem; color: var(--ink-muted); }
.lg-tgrid { stroke: var(--c-grid); stroke-width: 1; stroke-dasharray: 3 3; }
.lg-wave { fill: none; stroke: var(--c-curve); stroke-width: 2; stroke-linejoin: miter; }
.lg-wave-x { fill: none; stroke: var(--ink-faint); stroke-width: 1.4; }
.lg-tname { font-weight: 600; }
.lg-edge { fill: none; stroke: var(--ink-muted); stroke-width: 1.6; }
.lg-edge.is-hl { stroke: var(--c-curve2); stroke-width: 2.8; }
.lg-arrowhead { fill: var(--ink-muted); }
.lg-elabel { font: 12.5px var(--font-mono); fill: var(--ink); paint-order: stroke; stroke: var(--viz-bg); stroke-width: 4px; }
.lg-state-c { fill: var(--bg-elev); stroke: var(--ink); stroke-width: 1.8; }
.lg-state.is-current .lg-state-c { fill: var(--c-info-soft); stroke: var(--c-curve); stroke-width: 3; }
.lg-state-t { font: 600 14px var(--font-mono); }
.lg-seqsim { display: block; }
.lg-seq-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lg-seq-readout { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 8px 0; font-size: .95rem; }
.lg-seq-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: start; }
.lg-seq-two .lg-stage { padding: 4px; border: 0; }
@media (max-width: 640px) { .lg-seq-two { grid-template-columns: minmax(0, 1fr); } }
.lg-kwidget { border-collapse: collapse; margin: 6px 0; }
.lg-kwidget th { font: 13px var(--font-mono); color: var(--ink-muted); padding: 4px 8px; font-weight: 400; }
.lg-kwidget td { border: 1px solid var(--line-strong); padding: 0; }
.lg-kwidget th.lg-kcorner { position: relative; min-width: 56px; height: 40px; font-style: italic; }
.lg-kcorner .r { position: absolute; left: 4px; bottom: 2px; }
.lg-kcorner .c { position: absolute; right: 4px; top: 2px; }
.lg-kbtn { width: 48px; height: 44px; border: 0; background: var(--bg-elev); color: var(--ink); font: 600 18px var(--font-mono); cursor: pointer; }
.lg-kbtn:hover:not(:disabled) { background: var(--acc-soft); }
.lg-kbtn.is-one { color: var(--c-curve); }
.lg-kbtn:focus-visible { outline: 2px solid var(--acc); outline-offset: -2px; }
table.data.tt td, table.data.tt th { text-align: center; font-family: var(--font-mono); padding: 3px 10px; }
table.data.tt td.sep, table.data.tt th.sep { border-left: 2px solid var(--line-strong); }
.bits { font-family: var(--font-mono); letter-spacing: .04em; }
.ieee { display: inline-flex; font-family: var(--font-mono); border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.ieee span { padding: 3px 6px; }
.ieee .s { background: var(--c-fill2); } .ieee .e { background: var(--c-fill); } .ieee .m { background: var(--bg-sunken); word-break: break-all; }.lg-conv { border: 1px solid var(--line); border-radius: var(--radius); background: var(--viz-bg); padding: 12px; }
.lg-conv-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lg-conv-row .q-input { width: auto; min-width: 7em; }
.lg-conv-out { margin-top: 8px; overflow-x: auto; }
.lg-conv-all { font-size: 1.05rem; }.lg-bits { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.lg-bit { display: inline-flex; flex-direction: column; align-items: center; min-width: 46px; padding: 4px 2px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg-elev); color: var(--ink); cursor: pointer; }
.lg-bit .v { font: 700 20px var(--font-mono); }
.lg-bit .w { font-size: 11px; color: var(--ink-muted); }
.lg-bit.is-one { background: var(--c-info-soft); border-color: var(--c-curve); }
.lg-bit:focus-visible { outline: 2px solid var(--acc); }
/* Topic picker (Practice questions, mock exam) ----------------------------------- */
.topic-picker { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); margin: 10px 0 14px; }
.topic-picker > summary { cursor: pointer; padding: 10px 14px; list-style-position: inside; }
.topic-picker > summary .tp-sum { color: var(--ink-muted); }
.topic-picker[open] > summary { border-bottom: 1px solid var(--line); }
.tp-body { padding: 8px 14px 12px; }
.tp-global { margin: 4px 0 8px; }
.tp-group { border: 0; border-top: 1px solid var(--line); margin: 6px 0 0; padding: 8px 0 0; min-width: 0; }
.tp-group legend { font-weight: 600; padding: 0 6px 0 0; }
.tp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 6px; }
.tp-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 2px 14px; }
.tp-topic, .tp-mixed { display: flex; gap: 6px; align-items: baseline; padding: 3px 0; cursor: pointer; }
.tp-topic input, .tp-mixed input { flex: none; }
/* Motion explorer (fig/motion.js, explorer.html, "Visualize" in problems) ------ */
.mf-controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.mf-toggles { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; width: 100%; }
.mf-tog { display: inline-flex; gap: 5px; align-items: baseline; cursor: pointer; }
.mf-readouts dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 6px 16px; margin: 8px 0 0; }
.mf-readouts dl > div { background: var(--bg-sunken); border-radius: var(--radius-sm); padding: 6px 10px; }
.mf-readouts dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-muted); }
.mf-readouts dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; }
.mf-locked { margin: 8px 0 0; }
.q-explore { margin: 10px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--viz-bg); padding: 10px; }
.q-explore .q-explore-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; justify-content: space-between; margin: 0 0 6px; }
.ex-custom { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-sunken); margin-top: 10px; }
.ex-custom .ex-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.ex-custom label { display: grid; gap: 3px; font-size: .88rem; font-weight: 600; color: var(--ink-muted); }
.ex-custom input, .ex-custom select { font-family: var(--font-mono); }
.ex-msg.is-bad { color: var(--c-bad); }.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.grid-cards .card { display: flex; flex-direction: column; gap: 6px; }
.grid-cards .card h3, .grid-cards .card p { margin: 0; }
.grid-cards .card .btn-row { margin-top: auto; }
.card-meta { font-size: .85rem; color: var(--ink-muted); }
.ex-desc { color: var(--ink-muted); margin: 6px 0; }

/* Motion explorer: editor, parameter sliders, linked time graphs (assets/js/explorer.js) ---- */
.ex-pick { display: flex; gap: 8px; align-items: center; max-width: 100%; min-width: 0; }
.ex-pick select { min-width: 0; flex: 1 1 auto; text-overflow: ellipsis; font-size: 16px; min-height: 40px; }
.ex-layout { display: block; margin-top: 10px; }
.ex-layout > * { min-width: 0; }
.ex-layout.is-custom { display: grid; gap: 12px 16px; grid-template-columns: minmax(0, 1fr); }
.ex-editor, .ex-params { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-sunken); }
.ex-editor { display: grid; gap: 10px; }
.ex-tools { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; }
.ex-tools > label { flex: 1 1 9em; min-width: 0; }
.ex-tools label, .ex-fields label, .ex-prange label { display: grid; gap: 3px; font-size: .86rem; font-weight: 600; color: var(--ink-muted); }
.ex-tools select, .ex-tools .btn { min-height: 40px; }
.ex-tools .ex-num { width: 7.5em; }
.ex-rows { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr)); gap: 10px; }
.ex-row { margin: 0; padding: 10px; border: 1px solid var(--line); border-left: 6px solid var(--rc, var(--acc)); border-radius: var(--radius-sm); background: var(--bg-elev); display: grid; gap: 8px; }
.ex-row.is-off { opacity: .6; }
.ex-row-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.ex-swatch { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--rc); color: var(--bg-elev); font-weight: 750; font-size: .85rem; }
.ex-kind { min-height: 40px; flex: 1 1 100%; font-size: .9rem; }
.ex-chk { display: inline-flex; gap: 6px; align-items: center; min-height: 40px; font-size: .88rem; cursor: pointer; }
.ex-chk input { width: 20px; height: 20px; accent-color: var(--rc, var(--acc)); }
.ex-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.ex-fields input, .ex-params input[type="text"], .ex-tools input, .ex-editor select { font-family: var(--font-mono); font-size: 16px; min-height: 40px; width: 100%; }
.ex-fields input[aria-invalid="true"], .ex-param input[aria-invalid="true"] { border-color: var(--c-bad); box-shadow: 0 0 0 1px var(--c-bad); }
.ex-err { margin: 0; padding: 6px 8px; border-radius: 6px; background: var(--c-bad-soft); color: var(--c-bad); font-size: .88rem; }
.ex-ctx { background: transparent; color: inherit; padding: 0; white-space: pre-wrap; word-break: break-all; }
.ex-ctx mark { background: var(--c-bad); color: var(--bg-elev); border-radius: 3px; padding: 0 2px; }
.ex-help { font-size: .84rem; margin: 0; }
.ex-params h3 { margin: 0 0 8px; font-size: 1rem; }
.ex-param { display: grid; gap: 4px; padding: 8px 0; border-top: 1px solid var(--line); }
.ex-param:first-of-type { border-top: 0; padding-top: 0; }
.ex-prow { display: flex; gap: 8px; align-items: center; }
.ex-pname { font-weight: 700; font-family: var(--font-mono); min-width: 3.2em; }
.ex-pnum { width: 7em !important; }
.btn.small.ex-pplay, .ex-row .btn.small, .ex-pick + .btn.small, .ex-tools .btn.small { min-width: 44px; min-height: 40px; }
.ex-pslider { width: 100%; height: 32px; accent-color: var(--acc); touch-action: pan-y; }
.ex-prange summary { cursor: pointer; font-size: .82rem; color: var(--ink-muted); min-height: 32px; display: flex; align-items: center; }
.ex-prange[open] { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.ex-prange[open] summary { grid-column: 1 / -1; }
.ex-graphs { margin-top: 0; }
.ex-graph-set { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--viz-bg); padding: 8px 10px; }
.ex-graph-set:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.ex-graph svg { display: block; width: 100%; height: auto; cursor: ew-resize; }
.ex-gh { display: flex; flex-wrap: wrap; gap: 2px 14px; align-items: baseline; font-size: .86rem; }
.ex-gt { margin-left: auto; font-size: .78rem; }
.ex-gv { font-variant-numeric: tabular-nums; color: var(--ink); }
.ex-gv::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 50%; background: var(--rc); }
@media (min-width: 901px) {
  .ex-layout.is-custom { grid-template-columns: minmax(0, 1fr) 270px; grid-template-areas: "editor editor" "viz params" "graphs graphs" "ro ro"; align-items: start; }
  .ex-layout.is-custom > .ex-editor { grid-area: editor; } .ex-layout.is-custom > .ex-viz { grid-area: viz; }
  .ex-layout.is-custom > .ex-params { grid-area: params; } .ex-layout.is-custom > .ex-graphs { grid-area: graphs; margin-top: 0; }
  .ex-layout.is-custom > .ex-ro { grid-area: ro; }
}
@media (max-width: 900px) {
  .ex-pslider { height: 40px; }
}
@media print { .ex-side, .ex-graphs { display: none; } }
/* Zoom and pan on 2-D plots (fig/plot2d.js) ----------------------------------- */
.viz-stage { position: relative; }
.plot-zoom { position: absolute; top: 6px; right: 6px; display: flex; gap: 3px; align-items: center; z-index: 3; background: var(--viz-ui-bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px; box-shadow: var(--shadow-sm); }
.plot-zoom button { min-width: 28px; height: 28px; padding: 0 5px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--ink); font: 600 16px/1 var(--font-sans); cursor: pointer; }
.plot-zoom button:hover:not(:disabled) { background: var(--acc-soft); }
.plot-zoom button:disabled { opacity: .35; cursor: default; }
.plot-zoom button[aria-pressed="true"] { background: var(--c-info-soft); border-color: var(--c-curve); }
.plot-zoom button:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }
.plot-zoom-level { font: 12px var(--font-mono); color: var(--ink-muted); padding: 0 3px; }
.plot-zoom-level:empty { display: none; }
.plot-pan { position: absolute; inset: 0; z-index: 2; cursor: grab; touch-action: none; }
.plot-pan[hidden] { display: none; }
@media print { .plot-zoom { display: none; } }
/* Difficulty meter, adaptive practice and mock tests ------------------------------ */
.dmeter { display: inline-flex; align-items: center; gap: 2px; vertical-align: middle; }
.dmeter i { display: inline-block; width: 7px; height: 13px; border-radius: 2px; background: var(--track); }
.dmeter.d1 i:nth-child(1) { background: var(--c-good); }
.dmeter.d2 i:nth-child(-n+2) { background: var(--c-warn); }
.dmeter.d3 i { background: var(--c-bad); }
.dmeter .dmeter-t { margin-left: 6px; font-size: .78rem; font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .04em; }
.q-head .q-diff { display: inline-block; margin: 2px 0 4px; }
.lab-level-wrap { display: inline-flex; align-items: center; gap: 6px; }
.lab-adaptive { background: var(--c-info-soft); }
.lab-adapt { margin-top: 10px; }
.mock-list { margin-bottom: 18px; }
.mock-card .mock-parts { margin: 4px 0; padding-left: 18px; font-size: .92rem; }
.mock-sec { margin: 26px 0 8px; padding-bottom: 4px; border-bottom: 2px solid var(--line); font-size: 1.15rem; }
.custom-head { margin-top: 10px; }
/* Diagrams (fig/sketch.js, the "Diagram" button) ---------------------------------- */
.q-diagram { margin: 10px 0; }
.sk-wrap { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 380px)); gap: 10px; }
.sk-panel.sk-wide { grid-column: 1 / -1; max-width: 780px; }
.sk-panel { margin: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--viz-bg); padding: 8px; }
.sk-title { font-weight: 600; font-size: .92rem; margin: 0 0 4px; }
.sk-note { margin: 6px 2px 0; font-size: .85rem; color: var(--ink-muted); }
.plot-zoom.is-outside { position: static; width: fit-content; margin: 4px 0 0 auto; box-shadow: none; background: transparent; border-color: transparent; }
.sk-panel .plot-zoom.is-outside button { min-width: 24px; height: 24px; font-size: 14px; }
/* past mock-exam attempts (quiz page) */
.attempt-list td { vertical-align: middle; }
.attempt-list .btn.small { white-space: nowrap; }
.delta-up { color: var(--c-good); font-weight: 600; }
.delta-down { color: var(--c-bad); font-weight: 600; }
/* dynamics copy: textbook / original problem sets, original practice papers */
.set-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.set-note { margin: 0 0 12px; font-size: .95rem; }
.paper-row { gap: 8px; }
.paper-best { font-weight: 400; font-size: .85em; opacity: .85; margin-left: 4px; }

/* ==========================================================================
   ASSIGNMENT + INSTRUCTOR DEMO (assignment.html, instructor.html; brief 05). Calm and quiet: no timers in red, no
   countdowns, no streaks. Motion is limited to focus rings; nothing here animates.
   ========================================================================== */
.as-h, .in-h2 { margin: 1.2em 0 .4em; font-size: 1.3rem; line-height: 1.3; }
.as-h:focus, .as-qh:focus, .as-msg:focus, .in-status:focus, #in-reject:focus { outline: 2px solid var(--acc); outline-offset: 3px; }
.as-rules { max-width: 62ch; }
.as-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 14px; margin-top: 12px; }
.as-card h3 { margin: 0 0 4px; font-size: 1.08rem; }
.as-status { margin: .6em 0; }
.as-adjusted { display: inline-block; margin: 0 0 .4em; padding: 2px 10px; border: 1px solid var(--c-info); border-radius: 99px; background: var(--c-info-soft); font-size: .88rem; font-weight: 600; }
td .as-adjusted { margin: 0 0 0 4px; padding: 0 8px; font-size: .78rem; }
.as-head { margin-bottom: 8px; }
.as-meta, .as-qmeta { margin: 0 0 .6em; font-size: .88rem; font-variant-numeric: tabular-nums; }
.as-q { margin: 0 0 28px; padding-top: 6px; border-top: 1px solid var(--line); }
.as-qh { margin: .4em 0 .1em; font-size: 1.1rem; }
.as-actions { margin-top: .4em; }
.as-msg { margin: .6em 0; padding: 0; min-height: 0; border-radius: var(--radius-sm); }
.as-msg:not(:empty) { padding: 9px 12px; border-left: 4px solid var(--line-strong); background: var(--bg-sunken); }
.as-msg.good { border-left-color: var(--c-good); background: var(--c-good-soft); }
.as-msg.bad { border-left-color: var(--c-warn); background: var(--c-warn-soft); }
.as-msg.info { border-left-color: var(--c-info); background: var(--c-info-soft); }
.as-hints { margin: .4em 0 .8em 1.2em; padding: 0; }
.as-score { margin: 8px 0 14px; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
.as-score p { margin: .2em 0; }
.as-big { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.as-tablewrap { position: relative; max-width: 100%; overflow-x: auto; margin: 8px 0 14px; }
.as-table td, .as-table th { white-space: nowrap; }
.as-badge { display: inline-block; padding: 1px 9px; border: 1px solid var(--line-strong); border-radius: 99px; background: var(--bg-sunken); color: var(--ink); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.as-badge-note { color: var(--ink-muted); font-size: .76rem; }
.as-tbc { display: inline-block; margin-left: 8px; padding: 0 7px; border: 1px dashed var(--c-warn); border-radius: 4px; color: var(--c-warn); font-size: .72rem; font-weight: 700; letter-spacing: .04em; vertical-align: middle; }
.in-role, .in-controls { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: flex-end; margin: 0 0 14px; }
.in-controls { padding: 10px 0; border-top: 1px solid var(--line); }
.in-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.in-label { font-size: .86rem; font-weight: 600; }
.in-field select, .in-field input, .in-field textarea { max-width: 100%; min-height: 38px; padding: 6px 10px; border: 1px solid var(--line-input); border-radius: var(--radius-sm); background: var(--bg-elev); color: var(--ink); font: inherit; }
.in-field textarea { width: 100%; }
.in-help { margin: 0; font-size: .86rem; }
.in-status { min-height: 1.4em; margin: 0 0 8px; color: var(--ink-muted); }
.in-legend { margin: 8px 0; font-size: .9rem; }
.in-table th[scope="row"] { white-space: nowrap; }
.in-actions { white-space: nowrap; }
.in-actions .btn + .btn { margin-left: 4px; }
.in-detail > td { background: var(--bg-sunken); }
.in-sub td, .in-sub th { white-space: nowrap; font-size: .86rem; }
.in-median td, .in-median th { text-align: center; font-variant-numeric: tabular-nums; }
.in-settings { margin: 0; padding: 12px 14px 4px; border: 1px solid var(--line); border-radius: var(--radius); }
.in-settings legend { padding: 0 6px; font-weight: 700; }
.in-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 12px 18px; }
.in-custom { display: flex; gap: 6px; }
.in-custom input { width: 5.2em; }
.in-dialog { width: min(480px, calc(100vw - 24px)); padding: 18px 20px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg-elev); color: var(--ink); box-shadow: var(--shadow-lg); }
.in-dialog::backdrop { background: var(--scrim); }
.in-form h2 { margin: 0 0 .4em; font-size: 1.2rem; }
.in-form .in-field { margin: 10px 0; }
.in-reset { margin-top: 24px; }
@media (max-width: 559.98px) { .as-big { font-size: 1.7rem; } .in-field select { width: 100%; } .in-field { flex: 1 1 100%; } }

/* ==========================================================================
   11. Engagement layer (assets/js/engage/*, opt-in with <body data-engage>; see ENGAGEMENT.md)
   Motion tokens are the ONE shared set: every transition below names its properties and uses these curves.
   Only transform and opacity move; nothing animates layout. Reduced motion keeps opacity, drops movement.
   ========================================================================== */
:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);          /* entering, feedback, anything the user just did */
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);      /* things that move on screen */
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);       /* panels that slide */
  --dur-press: 140ms; --dur-fast: 180ms; --dur-ui: 240ms; --dur-fill: 300ms; --dur-celebrate: 640ms;
  --eg-paper: #fbf8ef; --eg-ink: #26221b; --eg-ink-soft: #5a5347; --eg-rule: #e6dfcd; --eg-card: #fffdf7;
  --eg-gold: #8a5a00; --eg-gold-soft: #fbf0d4;
}
@media screen {
  html[data-theme="dark"] {
    --eg-paper: #17150f; --eg-ink: #ece6d8; --eg-ink-soft: #b3aa98; --eg-rule: #2c2920; --eg-card: #1d1b14;
    --eg-gold: #f1c15d; --eg-gold-soft: #2e2511;
  }
}

html:has(body[data-engage]) { scroll-padding-top: calc(var(--topbar-h) + 84px); }       /* the sticky HUD sits under the top bar */
html.eg-focus:has(body[data-engage]) { scroll-padding-top: 20px; }
body[data-engage] { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }   /* landscape notch (viewport-fit=cover) */
/* shared: press feedback, touch behaviour (mobile-native baseline, scoped to engaged pages) */
body[data-engage] :is(button, a, label, summary, input, .eg-opt) { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
body[data-engage] :is(button, .eg-btn, .eg-seg label, summary) { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body[data-engage] .btn { transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-press) var(--ease-out), border-color var(--dur-press) var(--ease-out), color var(--dur-press) var(--ease-out); }
body[data-engage] .btn:active:not(:disabled), .eg-btn:active:not(:disabled), .eg-opt:active { transform: scale(0.97); }
body[data-engage] input[type="text"], body[data-engage] .q-input { font-size: max(16px, 1em); }          /* no iOS zoom on focus */
.eg-icon { width: 18px; height: 18px; flex: none; }

/* ---- HUD ---------------------------------------------------------------- */
.eg-hud { position: sticky; top: var(--topbar-h); z-index: 35; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0 calc(-1 * var(--gutter)) 14px; padding: 8px var(--gutter); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg-elev) 94%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.eg-hud-main { display: flex; flex: 1 1 170px; align-items: center; gap: 10px; min-width: 0; min-height: 44px; padding: 2px 6px 2px 2px; border: 0; border-radius: 12px; background: transparent; color: var(--ink); cursor: pointer; text-align: left; }
.eg-level { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 10px; background: var(--acc); color: #fff; font-weight: 800; font-size: 0.95rem; font-variant-numeric: tabular-nums; }
html[data-theme="dark"] .eg-level { color: #0b1015; }
.eg-xpwrap { display: grid; flex: 1 1 auto; gap: 4px; min-width: 110px; }
.eg-xptext { display: flex; justify-content: space-between; gap: 8px; color: var(--ink-muted); font-size: 0.78rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1; }
.eg-xpbar { position: relative; height: 8px; overflow: hidden; border-radius: 99px; background: var(--track); }
.eg-xpfill { position: absolute; inset: 0; border-radius: inherit; background: var(--acc); transform-origin: left center; transform: scaleX(var(--p, 0)); transition: transform var(--dur-fill) var(--ease-out); }
.eg-chip { display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 3px 11px; border-radius: 99px; background: var(--bg-sunken); color: var(--ink-muted); font-size: 0.8rem; font-weight: 650; white-space: nowrap; }
.eg-chip b { color: var(--ink); font-weight: 750; }
.eg-mini { position: relative; display: inline-block; width: 40px; height: 6px; overflow: hidden; border-radius: 99px; background: var(--track); }
.eg-mini > i { position: absolute; inset: 0; border-radius: inherit; background: var(--c-good); transform-origin: left center; transform: scaleX(var(--p, 0)); transition: transform var(--dur-fill) var(--ease-out); }
.eg-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 4px 12px; border: 1px solid var(--line-strong); border-radius: 99px; background: var(--bg-elev); color: var(--ink); font-size: 0.85rem; font-weight: 650; cursor: pointer; transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-press) var(--ease-out), border-color var(--dur-press) var(--ease-out); }
.eg-btn[aria-pressed="true"], .eg-btn.is-primary { border-color: var(--acc); background: var(--acc); color: #fff; }
html[data-theme="dark"] .eg-btn[aria-pressed="true"], html[data-theme="dark"] .eg-btn.is-primary { color: #0b1015; }
.eg-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.eg-dot { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px; background: var(--acc); color: #fff; font-size: 0.72rem; font-weight: 800; }
html[data-theme="dark"] .eg-dot { color: #0b1015; }
@media (hover: hover) and (pointer: fine) {
  .eg-btn:hover:not(:disabled) { border-color: var(--acc); }
  .eg-hud-main:hover { background: var(--bg-sunken); }
  .eg-opt:hover { border-color: var(--acc); }
}
.eg-btn .eg-lab { white-space: nowrap; }
@media (max-width: 639.98px) {
  .eg-hud { flex-wrap: nowrap; gap: 6px; padding-top: 4px; padding-bottom: 4px; }
  .eg-hud-main { flex: 1 1 auto; gap: 8px; }
  .eg-xpwrap { min-width: 60px; }
  .eg-chip.eg-mastery { display: none; }
  .eg-chip { padding: 3px 9px; }
  .eg-chip .eg-lab, .eg-btn .eg-lab { display: none; }
  .eg-btn { padding: 4px 10px; min-width: 44px; }
  .eg-xptext .eg-xp-sub { display: none; }
}

/* ---- Progress panel (opens from the HUD; origin-aware: grows out of the HUD button) ---- */
.eg-panel { position: absolute; top: calc(100% + 6px); left: var(--gutter); right: var(--gutter); max-width: 460px; max-height: min(78vh, 78dvh); overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-lg); transform-origin: top left; opacity: 0; transform: scale(0.96) translateY(-4px); visibility: hidden; transition: opacity var(--dur-press) var(--ease-out), transform var(--dur-press) var(--ease-out), visibility 0s linear var(--dur-press); }
.eg-panel.is-open { opacity: 1; transform: none; visibility: visible; transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), visibility 0s; }
.eg-panel h3 { margin: 14px 0 6px; font-size: 0.78rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-faint); }
.eg-panel h3:first-child { margin-top: 0; }
.eg-panel p { margin: 0 0 6px; font-size: 0.92rem; }
.eg-week { display: flex; gap: 6px; margin: 6px 0 4px; }
.eg-day { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--line-strong); color: var(--ink-faint); font-size: 0.7rem; font-weight: 700; }
.eg-day.is-on { border-color: var(--acc); background: var(--acc); color: #fff; }
html[data-theme="dark"] .eg-day.is-on { color: #0b1015; }
.eg-day.is-rest { border-style: dashed; border-color: var(--acc); color: var(--acc); }
.eg-day.is-today { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 3.5px var(--line-strong); }
.eg-badges { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.eg-badge { display: flex; gap: 10px; align-items: center; margin: 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--bg-sunken); font-size: 0.88rem; }
.eg-badge .eg-medal { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--eg-gold-soft); color: var(--eg-gold); }
.eg-badge.is-locked { opacity: 0.75; }
.eg-badge.is-locked .eg-medal { background: var(--track); color: var(--ink-faint); }
.eg-badge small { display: block; color: var(--ink-muted); font-size: 0.78rem; }
.eg-meter { position: relative; height: 10px; overflow: hidden; border-radius: 99px; background: var(--track); margin: 6px 0; }
.eg-meter > i { position: absolute; inset: 0; border-radius: inherit; background: var(--c-good); transform-origin: left center; transform: scaleX(var(--p, 0)); transition: transform var(--dur-fill) var(--ease-out); }
.eg-checkline { display: flex; gap: 8px; align-items: center; min-height: 36px; font-size: 0.9rem; }
.eg-small { color: var(--ink-muted); font-size: 0.82rem; }

/* ---- Toasts and the short celebration ------------------------------------ */
.eg-toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 80; display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); transform: translateX(-50%); pointer-events: none; }
html.eg-focus .eg-toasts { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
.eg-toast { position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-lg); pointer-events: auto; opacity: 0; transform: translateY(12px); transition: opacity var(--dur-press) var(--ease-out), transform var(--dur-press) var(--ease-out); }
.eg-toast.is-in { opacity: 1; transform: none; transition: opacity var(--dur-ui) var(--ease-out), transform var(--dur-ui) var(--ease-out); }
.eg-toast.is-level, .eg-toast.is-badge { border-color: var(--eg-gold); background: linear-gradient(0deg, var(--eg-gold-soft), var(--eg-gold-soft)), var(--bg-elev); }
.eg-toast.has-actions { flex-wrap: wrap; }
.eg-toast.has-actions .eg-toast-body { flex: 1 1 100%; }
.eg-toast-body { display: grid; flex: 1; gap: 2px; min-width: 0; font-size: 0.92rem; }
.eg-toast-title { font-size: 1rem; }
.eg-toast-text { color: var(--ink-muted); }
.eg-toast-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.eg-toast-x { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-muted); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.eg-burst { position: absolute; left: 30px; top: 50%; width: 0; height: 0; pointer-events: none; }
.eg-burst i { position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%; background: var(--acc); opacity: 0; animation: eg-burst var(--dur-celebrate) var(--ease-out) both; }
.eg-burst i[style*="--h:1"] { background: var(--c-good); } .eg-burst i[style*="--h:2"] { background: var(--eg-gold); } .eg-burst i[style*="--h:3"] { background: var(--c-info); }
@keyframes eg-burst { 0% { opacity: 1; transform: translate(0, 0) scale(0.5); } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1); } }
.eg-xpnote { display: inline-block; margin-left: 8px; padding: 1px 9px; border-radius: 99px; background: var(--eg-gold-soft); color: var(--eg-gold); font-size: 0.8rem; font-weight: 750; font-variant-numeric: tabular-nums; animation: eg-note var(--dur-ui) var(--ease-out) both; }
@keyframes eg-note { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- Cards used by predict, ladder, boss and Daily 5 ----------------------- */
.eg-card { margin: 1.4em 0; padding: 14px 18px 14px; border: 1px solid var(--line); border-left: 5px solid var(--acc); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.eg-kicker { display: inline-flex; align-items: center; gap: 7px; margin: 0 0 6px; color: var(--acc); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; }
.eg-card h3 { margin: 0 0 6px; font-size: 1.08rem; }
.eg-card > p:last-child { margin-bottom: 0; }
.eg-prompt { margin: 0 0 10px; font-size: 1.04rem; }
.eg-paper-note { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 10px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--eg-gold-soft); color: var(--ink); font-size: 0.9rem; }
.eg-paper-note svg { margin-top: 2px; color: var(--eg-gold); }
html.eg-nopaper .eg-paper-note { display: none; }
.eg-opts { display: grid; gap: 8px; margin: 0 0 10px; padding: 0; border: 0; }
.eg-opt { display: flex; gap: 12px; align-items: center; min-height: 48px; padding: 8px 14px; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg-elev); cursor: pointer; transition: transform var(--dur-press) var(--ease-out), border-color var(--dur-press) var(--ease-out), background-color var(--dur-press) var(--ease-out); }
.eg-opt input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--acc); }
.eg-opt:has(input:checked) { border-color: var(--acc); background: var(--acc-soft); }
.eg-opt:has(input:focus-visible) { outline: 2px solid var(--acc); outline-offset: 2px; }
.eg-opts .eg-opt.is-true { border-color: var(--c-good); background: var(--c-good-soft); }
.eg-opts .eg-opt.is-picked-wrong { border-color: var(--c-warn); background: var(--c-warn-soft); }
.eg-seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; padding: 0; border: 0; }
.eg-seg legend { margin: 0 0 4px; padding: 0; color: var(--ink-muted); font-size: 0.86rem; font-weight: 650; }
.eg-seg label { display: inline-flex; align-items: center; min-height: 44px; padding: 4px 14px; border: 1.5px solid var(--line-strong); border-radius: 99px; background: var(--bg-elev); font-size: 0.88rem; font-weight: 650; cursor: pointer; }
.eg-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.eg-seg label:has(input:checked) { border-color: var(--acc); background: var(--acc-soft); color: var(--acc); }
.eg-seg label:has(input:focus-visible) { outline: 2px solid var(--acc); outline-offset: 2px; }
.eg-slider { display: grid; gap: 4px; margin: 0 0 12px; }
.eg-slider input[type="range"] { width: 100%; height: 36px; accent-color: var(--acc); }
.eg-slider-read { display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; color: var(--ink-muted); font-size: 0.85rem; }
.eg-slider-val { color: var(--ink); font-size: 1.5rem; font-weight: 750; }
.eg-slider-val.is-empty { color: var(--ink-muted); font-size: 0.95rem; font-weight: 600; }
.eg-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.eg-fb { margin: 10px 0 0; padding: 0; border-radius: var(--radius-sm); }
.eg-fb:focus { outline: none; }
.eg-fb:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.eg-fb:not(:empty) { padding: 10px 14px; }
.eg-fb.good { background: var(--c-good-soft); border-left: 4px solid var(--c-good); }
.eg-fb.learn { background: var(--c-info-soft); border-left: 4px solid var(--c-info); }     /* a surprise is information, not an error */
.eg-fb.try { background: var(--c-warn-soft); border-left: 4px solid var(--c-warn); }
.eg-fb p { margin: 0 0 6px; }
.eg-fb p:last-child { margin-bottom: 0; }


.eg-card.eg-after { margin: 12px 0 1.4em; padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; }
.eg-after > .eg-fb:first-child { margin-top: 0; }
.eg-retry { margin-top: 18px; padding-top: 12px; border-top: 1px dashed var(--line-strong); }
/* gate: the figure or solution stays dim until the student has committed to a prediction */
.eg-gated { opacity: 0.22; filter: blur(5px); pointer-events: none; -webkit-user-select: none; user-select: none; }
.eg-gate-release { transition: opacity var(--dur-ui) var(--ease-out), filter var(--dur-ui) var(--ease-out); }      /* added for the moment of release: the clearing animates, the gating itself is instant */
.eg-gate-note { margin: 0 0 8px; color: var(--ink-muted); font-size: 0.86rem; }
.eg-skip { border: 0; background: none; color: var(--ink-muted); font-size: 0.84rem; text-decoration: underline; cursor: pointer; min-height: 44px; padding: 0 6px; }

/* ---- "Do it with me" ladder ------------------------------------------------- */
.eg-rungs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; padding: 0; list-style: none; }
.eg-rungs li { margin: 0; border-radius: 99px; background: var(--bg-sunken); color: var(--ink-muted); font-size: 0.8rem; font-weight: 650; }
.eg-rungbtn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px 0 8px; border: 0; border-radius: 99px; background: none; color: inherit; font: inherit; cursor: pointer; }
.eg-rungbtn:disabled { opacity: 0.55; cursor: not-allowed; }
.eg-rungs b { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--track); color: var(--ink); font-size: 0.74rem; }
.eg-rungs li.is-done b { background: var(--c-good); color: #fff; }
html[data-theme="dark"] .eg-rungs li.is-done b { color: #0b1015; }
.eg-rungs li.is-now { background: var(--acc-soft); color: var(--acc); }
.eg-rungs li.is-now b { background: var(--acc); color: #fff; }
html[data-theme="dark"] .eg-rungs li.is-now b { color: #0b1015; }
.eg-steps { margin: 0 0 8px; padding: 0; list-style: none; counter-reset: egs; }
.eg-step { position: relative; margin: 0 0 8px; padding: 10px 12px 10px 44px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-elev); counter-increment: egs; }
.eg-step::before { content: counter(egs); position: absolute; left: 10px; top: 10px; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--bg-sunken); color: var(--ink-muted); font-size: 0.78rem; font-weight: 750; }
.eg-step.is-blank { border-color: var(--acc); background: var(--acc-soft); }
.eg-step.is-blank::before { background: var(--acc); color: #fff; }
html[data-theme="dark"] .eg-step.is-blank::before { color: #0b1015; }
.eg-step.is-done::before { content: "✓"; background: var(--c-good); color: #fff; }
html[data-theme="dark"] .eg-step.is-done::before { color: #0b1015; }
.eg-step.is-enter { animation: eg-note var(--dur-ui) var(--ease-out) both; }
.eg-step-title { margin: 0 0 2px; font-size: 0.82rem; font-weight: 750; color: var(--ink-muted); }
.eg-step p { margin: 0 0 4px; }
.eg-ask { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.eg-ask label { font-weight: 650; }
.eg-input { min-width: 0; width: min(100%, 200px); min-height: 44px; font-family: var(--font-mono); }
.eg-unit { color: var(--ink-muted); }
.eg-hintbox { margin: 8px 0 0; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--c-warn-soft); font-size: 0.92rem; }
.eg-given { margin: 0 0 8px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--bg-sunken); }
.eg-boss { border-left-color: var(--eg-gold); background: linear-gradient(0deg, color-mix(in srgb, var(--eg-gold-soft) 55%, transparent), color-mix(in srgb, var(--eg-gold-soft) 55%, transparent)), var(--bg-elev); }
.eg-boss .eg-kicker { color: var(--eg-gold); }
.eg-daily-pips { display: flex; gap: 6px; margin: 4px 0 10px; }
.eg-pip { width: 28px; height: 8px; border-radius: 99px; background: var(--track); transition: background-color var(--dur-fast) var(--ease-out); }
.eg-pip.is-now { background: var(--acc-soft); box-shadow: inset 0 0 0 1.5px var(--acc); }
.eg-pip.is-ok { background: var(--c-good); }
.eg-pip.is-miss { background: var(--c-warn); }
.eg-intro ul { margin: 0 0 12px; padding-left: 1.2em; }
.eg-intro li { margin: 0.35em 0; }
details.eg-card > summary { cursor: pointer; list-style: none; min-height: 44px; display: flex; align-items: center; gap: 10px; }
details.eg-card > summary::-webkit-details-marker { display: none; }
.eg-chev { flex: none; color: var(--ink-muted); transition: transform var(--dur-fast) var(--ease-out); }
details[open] > summary > .eg-chev { transform: rotate(180deg); }

/* ---- Focus mode ("paper mode") ---------------------------------------------- */
.eg-focusbar { display: none; }
html.eg-focus body[data-engage] { background: var(--eg-paper); color: var(--eg-ink); }
html.eg-focus body[data-engage] :is(.topbar, .sidebar, .scrim, .toc, .foot, .lesson-meta, .eyebrow) { display: none !important; }
html.eg-focus body[data-engage] main { max-width: 41rem; margin: 0 auto !important; padding: 20px 20px calc(110px + env(safe-area-inset-bottom, 0px)); font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif; font-size: clamp(1.1rem, 1rem + 0.5vw, 1.28rem); line-height: 1.78; }
html.eg-focus body[data-engage] main :is(h1, h2, h3, .btn, button, input, label, .eg-btn, .q-card, .eg-card, .eg-kicker, .eg-panel, .eg-hud, .eg-step-title, .viz) { font-family: var(--font-sans); }
html.eg-focus body[data-engage] main :is(.btn, button, input, .eg-opt, label) { font-size: 1rem; }
html.eg-focus body[data-engage] h1 { font-size: clamp(1.9rem, 1.5rem + 2vw, 2.6rem); }
html.eg-focus body[data-engage] main > section:not(.objectives):not(.takeaways) > h2 { margin-top: 0; font-size: 1.6em; }
html.eg-focus body[data-engage] .lesson-header::before { display: none; }
html.eg-focus body[data-engage] :is(.key-result, .example, .objectives, .takeaways, .callout, .q-card, .eg-card) { box-shadow: none; background: var(--eg-card); border-color: var(--eg-rule); }
html.eg-focus body[data-engage] .eg-card { border-left-color: var(--acc); }
html.eg-focus body[data-engage] .key-result { background: color-mix(in srgb, var(--acc) 7%, var(--eg-card)); }
html.eg-focus body[data-engage] .lesson-header { border-bottom-color: var(--eg-rule); }
html.eg-focus body[data-engage] .src { color: var(--eg-ink-soft); }
html.eg-focus body[data-engage] .lede { color: var(--eg-ink-soft); }
html.eg-focus body[data-engage] .eg-off { display: none !important; }
html.eg-focus body[data-engage] .eg-hud { position: relative; top: auto; margin: 0 0 18px; padding: 4px 0; border: 0; background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; }
html.eg-focus body[data-engage] .eg-hud :is(.eg-chip, .eg-btn:not(.eg-focus-btn)) { display: none; }
html.eg-focus body[data-engage] .eg-hud-main { flex: 1; }
html.eg-focus body[data-engage] .eg-page-in { animation: eg-page var(--dur-fast) var(--ease-out) both; }
@keyframes eg-page { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
html.eg-focus .eg-focusbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--eg-rule); background: color-mix(in srgb, var(--eg-paper) 94%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); font-family: var(--font-sans); }
.eg-focusbar .eg-where { flex: 1; min-width: 0; text-align: center; color: var(--eg-ink-soft); font-size: 0.82rem; line-height: 1.25; }
.eg-focusbar .eg-where b { display: block; color: var(--eg-ink); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eg-focusbar .eg-dots { display: flex; justify-content: center; gap: 4px; margin-top: 4px; }
.eg-focusbar .eg-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--eg-rule); }
.eg-focusbar .eg-dots i.is-on { background: var(--acc); }
.eg-focusbar .eg-btn { min-width: 92px; }
.eg-focusbar .eg-btn.is-primary { min-width: 104px; }

@media (prefers-reduced-motion: reduce) {
  .eg-burst { display: none; }
  .eg-toast, .eg-panel { transform: none; }
  .eg-chev { transition: none; }
  .eg-xpfill, .eg-mini > i, .eg-meter > i { transition: none; }
  .eg-xpnote, .eg-step.is-enter, html.eg-focus body[data-engage] .eg-page-in { animation-name: eg-fade; }
  .eg-gate-release { transition: opacity var(--dur-fast) linear; }
  body[data-engage] .btn:active:not(:disabled), .eg-btn:active:not(:disabled), .eg-opt:active { transform: none; }
}
@keyframes eg-fade { from { opacity: 0; } to { opacity: 1; } }
@media print { .eg-hud, .eg-toasts, .eg-focusbar, .eg-card, .eg-gate-note { display: none !important; } }
