/* ==================================================================== *
 *  IGCSE Revision — stylesheet
 *  A calm, academic reading environment built for long study sessions.
 *  Sections: tokens · base · header · command palette · home · subject ·
 *            lesson (+TOC) · content blocks · quiz · flashcards ·
 *            responsive · print
 * ==================================================================== */

/* ---------------- tokens ---------------- */
:root {
  --font-ui: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-read: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, "Bitstream Charter", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;

  --measure: 66ch;
  --shell: 1200px;
  --header-h: 58px;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;

  --sp-1: .25rem; --sp-2: .5rem; --sp-3: .75rem; --sp-4: 1rem;
  --sp-5: 1.5rem; --sp-6: 2rem; --sp-7: 3rem;

  /* light — warm paper */
  --bg: #faf8f4;
  --bg-tint: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f6f4ee;
  --surface-3: #ece8de;
  --text: #1f2027;
  --text-soft: #565964;
  --text-faint: #8b8e99;
  --border: #e7e2d7;
  --border-strong: #d5cfc0;
  --accent: #3c6ade;
  --accent-ink: #2a4fae;
  --accent-wash: #edf2fe;
  --good: #2c8f57;
  --good-wash: #e8f5ee;
  --warn: #c8811f;
  --warn-wash: #fdf3e3;
  --bad: #c8455b;
  --bad-wash: #fdedf0;
  --supp-ink: #8a5d10;
  --supp-wash: #fdf4e3;
  --supp-border: #eedcb4;

  --sh-1: 0 1px 2px rgba(28,25,18,.05);
  --sh-2: 0 1px 3px rgba(28,25,18,.06), 0 8px 24px -8px rgba(28,25,18,.10);
  --sh-3: 0 2px 6px rgba(28,25,18,.08), 0 20px 48px -12px rgba(28,25,18,.18);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);

  /* diagram palette — figures reference these instead of literal hexes so the
     whole set re-themes at once and nothing goes invisible in dark mode.
     Six categorical hues, chosen to stay distinguishable in both themes and
     under the common forms of colour blindness. */
  --fig-paper: #ffffff;      /* knockout / "behind the label" fill        */
  --fig-ink:   #24262e;      /* primary strokes and label text            */
  --fig-muted: #62656f;      /* secondary labels, annotations             */
  --fig-line:  #b9b3a4;      /* structural rules, leader lines            */
  --fig-grid:  #e2ddd1;      /* graph paper, faint guides                 */
  --fig-1: #3562cf;  --fig-2: #1d7f52;  --fig-3: #b4761a;
  --fig-4: #c03e56;  --fig-5: #6f4cc0;  --fig-6: #0d7d78;
}

:root[data-theme="dark"] {
  --bg: #101116;
  --bg-tint: #14161c;
  --surface: #191b22;
  --surface-2: #20232b;
  --surface-3: #292d37;
  --text: #e9eaef;
  --text-soft: #a6aab7;
  --text-faint: #757a89;
  --border: #282c35;
  --border-strong: #363b47;
  --accent: #7ba2ff;
  --accent-ink: #a6c1ff;
  --accent-wash: #1a2440;
  --good: #4cc283;
  --good-wash: #12291d;
  --warn: #dfa254;
  --warn-wash: #2a2113;
  --bad: #f0768a;
  --bad-wash: #2c161b;
  --supp-ink: #e8c384;
  --supp-wash: #272013;
  --supp-border: #443a22;

  --sh-1: 0 1px 2px rgba(0,0,0,.4);
  --sh-2: 0 1px 3px rgba(0,0,0,.4), 0 10px 28px -10px rgba(0,0,0,.6);
  --sh-3: 0 2px 8px rgba(0,0,0,.5), 0 24px 56px -16px rgba(0,0,0,.7);

  /* diagram palette, dark. Hues are lifted and desaturated: a fill tuned for
     white paper reads as a glare on a dark surface. --fig-paper is the panel
     colour, not white, so knockouts stay invisible. */
  --fig-paper: #191b22;
  --fig-ink:   #e4e6ec;
  --fig-muted: #9ea2b0;
  --fig-line:  #4a4f5c;
  --fig-grid:  #2b2f39;
  --fig-1: #7ba2ff;  --fig-2: #4cc283;  --fig-3: #e0a75f;
  --fig-4: #f0768a;  --fig-5: #b096f2;  --fig-6: #46c4bc;
}

/* ---------------- base ---------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 1.5rem); }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16.5px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { line-height: 1.22; font-weight: 640; letter-spacing: -.011em; margin: 0; }
p { margin: 0 0 1em; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
img, svg { max-width: 100%; }
code { font-family: var(--font-mono); font-size: .9em; }
kbd {
  font-family: var(--font-ui); font-size: .72em; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: 6px; padding: .15em .45em; color: var(--text-soft);
  white-space: nowrap;
}
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }
.visually-hidden, .skip-link:not(:focus) {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: 10px; left: 10px; z-index: 200; background: var(--accent);
  color: #fff; padding: .6rem 1rem; border-radius: var(--r-sm); font-weight: 600;
}
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }

/* ---------------- header ---------------- */
.site-header {
  position: sticky; top: 0; z-index: 60;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: var(--shell); margin: 0 auto; height: var(--header-h);
  display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem;
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--text); font-weight: 700; font-size: 1rem; white-space: nowrap; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #9b6ef3));
  color: #fff; font-size: .7rem; box-shadow: var(--sh-1);
}
.header-spacer { flex: 1; }

/* search trigger (opens command palette) */
.search-trigger {
  display: flex; align-items: center; gap: .5rem; cursor: pointer;
  font: inherit; font-size: .875rem; color: var(--text-faint);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: .42rem .55rem .42rem .85rem; min-width: 210px;
  transition: border-color .15s, background .15s;
}
.search-trigger:hover { border-color: var(--border-strong); background: var(--surface); }
.search-trigger .st-label { flex: 1; text-align: left; }
.search-trigger kbd { font-size: .68rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: 10px; cursor: pointer; flex: 0 0 auto;
  background: transparent; border: 1px solid transparent; color: var(--text-soft); font-size: 1rem;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }

/* reading progress */
.read-progress {
  position: absolute; left: 0; bottom: -1px; height: 2px; width: 0%;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 50%, #9b6ef3));
  transition: width .1s linear;
}

/* ---------------- command palette ---------------- */
.cmdk-backdrop {
  position: fixed; inset: 0; z-index: 120;
  background: color-mix(in srgb, #0a0a0e 45%, transparent);
  backdrop-filter: blur(3px); display: flex; justify-content: center;
  padding: max(8vh, 3rem) 1rem 2rem;
}
.cmdk-backdrop[hidden] { display: none; }
.cmdk {
  width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-lg); box-shadow: var(--sh-3); overflow: hidden;
  animation: cmdk-in .16s cubic-bezier(.2,.8,.3,1);
}
@keyframes cmdk-in { from { opacity: 0; transform: translateY(-8px) scale(.985); } }
.cmdk-input-row { display: flex; align-items: center; gap: .7rem; padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); }
.cmdk-input-row .cmdk-icon { color: var(--text-faint); }
.cmdk input {
  flex: 1; border: none; background: none; outline: none;
  font: inherit; font-size: 1.02rem; color: var(--text);
}
.cmdk input::placeholder { color: var(--text-faint); }
.cmdk-results { overflow-y: auto; padding: .4rem; }
.cmdk-group { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); padding: .7rem .8rem .35rem; }
.cmdk-item {
  display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left;
  padding: .55rem .8rem; border-radius: var(--r-sm); color: var(--text);
  cursor: pointer; border: none; background: none; font: inherit;
}
.cmdk-item:hover, .cmdk-item[aria-selected="true"] { background: var(--accent-wash); text-decoration: none; }
.cmdk-item[aria-selected="true"] { box-shadow: inset 2px 0 0 var(--accent); }
.cmdk-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.cmdk-body { flex: 1; min-width: 0; }
.cmdk-title { font-weight: 560; font-size: .94rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-crumb { font-size: .74rem; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-item mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; border-radius: 3px; padding: 0 .1em; }
.cmdk-empty { padding: 2rem 1rem; text-align: center; color: var(--text-soft); }
.cmdk-foot {
  display: flex; gap: 1rem; padding: .55rem 1rem; border-top: 1px solid var(--border);
  font-size: .74rem; color: var(--text-faint); background: var(--surface-2);
}
.cmdk-foot span { display: inline-flex; align-items: center; gap: .3rem; }

/* ---------------- layout ---------------- */
.site-main { max-width: var(--shell); margin: 0 auto; padding: 2rem 1.25rem 4rem; min-height: 70vh; }
.site-footer {
  border-top: 1px solid var(--border); color: var(--text-faint); font-size: .8rem;
  text-align: center; padding: 2rem 1.25rem 3rem;
}
.site-footer code { background: var(--surface-2); padding: .12em .4em; border-radius: 5px; }
.breadcrumb { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; font-size: .82rem; color: var(--text-faint); margin-bottom: 1.1rem; }
.breadcrumb a { color: var(--text-soft); }
.breadcrumb .sep { opacity: .5; }

/* ---------------- home ---------------- */
.hero { margin: .5rem 0 2rem; max-width: 60ch; }
.hero h1 { font-size: clamp(1.9rem, 5vw, 2.7rem); margin-bottom: .5rem; }
.hero .hero-sub { color: var(--text-soft); font-size: 1.05rem; margin: 0; }
.hero .hero-sub kbd { margin: 0 .1em; }

.stat-strip {
  display: grid; grid-template-columns: auto 1fr; gap: 1.5rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 1.4rem 1.6rem; margin-bottom: 1.5rem; box-shadow: var(--sh-1);
}
.ring { --sz: 104px; --pct: 0; --pct2: 0;
  width: var(--sz); height: var(--sz); border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto;
  background: conic-gradient(var(--good) 0 calc(var(--pct) * 1deg), var(--warn) calc(var(--pct) * 1deg) calc(var(--pct2) * 1deg), var(--surface-3) calc(var(--pct2) * 1deg) 360deg);
}
.ring-hole {
  width: 74%; height: 74%; border-radius: 50%; background: var(--surface);
  display: grid; place-items: center; line-height: 1.05; box-shadow: inset 0 0 0 1px var(--border);
}
.ring-hole b { font-size: 1.4rem; font-weight: 680; letter-spacing: -.02em; }
.ring-hole span { font-size: .6rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; }
.stat-body h2 { font-size: 1.05rem; margin-bottom: .5rem; }
.stat-legend { display: flex; flex-wrap: wrap; gap: .35rem 1.1rem; font-size: .87rem; color: var(--text-soft); }
.stat-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.stat-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.stat-meta { margin-top: .6rem; font-size: .82rem; color: var(--text-faint); }

/* continue studying */
.continue {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem;
  background: linear-gradient(120deg, var(--accent-wash), color-mix(in srgb, var(--accent-wash) 40%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  border-radius: var(--r-lg); padding: 1rem 1.3rem; color: var(--text);
}
.continue:hover { text-decoration: none; border-color: var(--accent); }
.continue .cont-icon { font-size: 1.3rem; }
.continue .cont-body { flex: 1; min-width: 0; }
.continue .cont-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--accent-ink); font-weight: 700; }
.continue .cont-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue .cont-go { color: var(--accent-ink); font-weight: 600; font-size: .88rem; white-space: nowrap; }

.section-label { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); margin-bottom: .8rem; }

/* loading states (lesson content arrives per subject) */
.spinner {
  display: inline-block; width: 14px; height: 14px; flex: 0 0 auto;
  border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; vertical-align: -2px; margin-right: .5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } }
.loading-panel {
  display: flex; align-items: center; justify-content: center;
  min-height: 45vh; color: var(--text-soft); font-size: .95rem;
}
.cmdk-hint {
  display: flex; align-items: center; padding: .7rem .8rem .4rem;
  font-size: .78rem; color: var(--text-faint);
}

/* progress backup */
.backup-panel {
  display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: center; justify-content: space-between;
  margin-top: 2.75rem; padding: 1.35rem 1.5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--warn); border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.backup-panel .bp-body { flex: 1 1 340px; min-width: 0; }
.backup-panel h2 { font-size: 1.02rem; margin-bottom: .4rem; }
.backup-panel p { margin: 0 0 .5rem; color: var(--text-soft); font-size: .9rem; line-height: 1.55; max-width: 62ch; }
.backup-panel .bp-stats { color: var(--text-faint); font-size: .84rem; margin-bottom: 0; }
.backup-panel .bp-actions { display: flex; flex-direction: column; gap: .5rem; align-items: stretch; min-width: 190px; }
.bp-msg { font-size: .82rem; line-height: 1.45; color: var(--text-soft); min-height: 1em; }
.bp-msg.ok { color: var(--good); }
.bp-msg.bad { color: var(--bad); }

/* independent-study block, visually set apart from the exam subjects */
.independent-block { margin-top: 2.75rem; padding-top: 2rem; border-top: 1px dashed var(--border-strong); }
.independent-note { margin: -.4rem 0 1rem; color: var(--text-faint); font-size: .9rem; font-style: italic; }

/* philosophy: "common misreadings" are not examiner notes */
.mistakes.phil-mistakes .mistake { border-left-color: var(--accent); }
.mistakes.phil-mistakes .m-trap::before { content: "≠"; color: var(--accent); }
.mistakes.phil-mistakes .m-mark::before { content: "Actually "; color: var(--accent-ink); }

/* philosophy: open questions have no single right answer */
.practice-item.is-open-question .p-answer { background: var(--accent-wash); }
.practice-item.is-open-question .p-answer b { color: var(--accent-ink); }

.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 1.1rem; }
.subject-card {
  --accent: #3c6ade;
  position: relative; display: flex; flex-direction: column; gap: .85rem; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 1.3rem; color: var(--text); box-shadow: var(--sh-1);
  transition: transform .16s cubic-bezier(.2,.8,.3,1), box-shadow .16s, border-color .16s;
}
.subject-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 40%, transparent));
}
.subject-card:hover { transform: translateY(-3px); box-shadow: var(--sh-2); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); text-decoration: none; }
.sc-head { display: flex; align-items: flex-start; gap: .8rem; }
.sc-glyph {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: 0 0 auto;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent); font-size: 1.15rem;
}
.sc-titles { min-width: 0; flex: 1; }
.subject-card h3 { font-size: 1.15rem; }
.sc-code { font-size: .74rem; color: var(--text-faint); font-family: var(--font-mono); }
.sc-tag { color: var(--text-soft); font-size: .88rem; margin: 0; line-height: 1.5; }
.sc-foot { display: flex; justify-content: space-between; align-items: baseline; font-size: .8rem; color: var(--text-faint); }
.sc-foot b { color: var(--text); font-weight: 640; }

/* progress bar */
.pbar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; display: flex; }
.pbar > i { display: block; height: 100%; transition: width .35s cubic-bezier(.2,.8,.3,1); }
.pbar .seg-confident { background: var(--good); }
.pbar .seg-learning { background: var(--warn); }

/* ---------------- subject page ---------------- */
.subject-hero {
  display: flex; align-items: flex-start; gap: 1.1rem; margin-bottom: 1.5rem;
  padding-bottom: 1.5rem; border-bottom: 1px solid var(--border);
}
.subject-hero .sh-glyph {
  width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; flex: 0 0 auto;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-size: 1.5rem;
}
.subject-hero h1 { font-size: clamp(1.65rem, 4vw, 2.15rem); margin-bottom: .3rem; }
.subject-hero .sh-meta { color: var(--text-soft); font-size: .9rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1.75rem; }
.toolbar-spacer { flex: 1; }
.btn {
  display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; white-space: nowrap;
  font: inherit; font-size: .875rem; font-weight: 560; padding: .5rem .95rem;
  border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn .badge { background: color-mix(in srgb, #fff 25%, transparent); border-radius: 999px; padding: 0 .4em; font-size: .78em; }

.filter-chips { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.filter-chips button {
  font: inherit; font-size: .8rem; font-weight: 550; cursor: pointer; border: none;
  background: none; color: var(--text-soft); padding: .3rem .8rem; border-radius: 999px;
}
.filter-chips button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

.unit { margin-bottom: 1rem; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.unit-head {
  display: flex; align-items: center; gap: .9rem; width: 100%; text-align: left;
  padding: .95rem 1.1rem; cursor: pointer; border: none; background: none; font: inherit; color: var(--text);
}
.unit-head:hover { background: var(--surface-2); }
.unit-num {
  min-width: 32px; height: 32px; padding: 0 .5rem; border-radius: 9px; display: grid; place-items: center; flex: 0 0 auto;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
  font-weight: 700; font-size: .85rem;
}
.unit-title { flex: 1; font-weight: 600; font-size: 1rem; }
.unit-count { font-size: .78rem; color: var(--text-faint); white-space: nowrap; }
.unit-mini { width: 54px; }
.unit-chev { color: var(--text-faint); transition: transform .2s; font-size: .8rem; }
.unit[data-open="false"] .unit-chev { transform: rotate(-90deg); }
.unit[data-open="false"] .topic-list { display: none; }
.topic-list { list-style: none; margin: 0; padding: 0 .55rem .55rem; display: grid; gap: 2px; }
.topic-row {
  display: flex; align-items: center; gap: .8rem; padding: .6rem .75rem;
  border-radius: var(--r-sm); color: var(--text); transition: background .12s;
}
.topic-row:hover { background: var(--accent-wash); text-decoration: none; }
.t-num { font-family: var(--font-mono); font-size: .78rem; color: var(--text-faint); min-width: 3em; }
.t-title { flex: 1; font-size: .94rem; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--border-strong); flex: 0 0 auto; }
.status-dot.learning { background: var(--warn); border-color: var(--warn); }
.status-dot.confident { background: var(--good); border-color: var(--good); }
.pending-badge { font-size: .64rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); border: 1px dashed var(--border-strong); border-radius: 999px; padding: .05rem .45rem; }

/* ---------------- lesson ---------------- */
.lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr) 232px; gap: 3rem; align-items: start; }
.lesson-main { min-width: 0; }

.lesson-hero { margin-bottom: 1.5rem; }
.l-eyebrow { display: inline-flex; align-items: center; gap: .45rem; color: var(--accent-ink); font-weight: 600; font-size: .8rem; letter-spacing: .01em; margin-bottom: .5rem; }
.l-eyebrow .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.lesson-hero h1 { font-size: clamp(1.75rem, 4.5vw, 2.5rem); margin-bottom: .6rem; }
.lesson-hero h1 .l-num { color: var(--text-faint); font-weight: 500; }
.l-summary { color: var(--text-soft); font-size: 1.05rem; max-width: var(--measure); margin: 0; line-height: 1.55; }
.l-facts { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin-top: .9rem; font-size: .8rem; color: var(--text-faint); }
.l-facts span { display: inline-flex; align-items: center; gap: .35rem; }

/* status control */
.status-picker {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: .7rem .9rem; margin: 1.5rem 0 2.5rem;
}
.status-picker .sp-label { font-size: .85rem; color: var(--text-soft); font-weight: 550; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  font: inherit; font-size: .82rem; font-weight: 550; cursor: pointer; border: none;
  background: none; color: var(--text-soft); padding: .32rem .85rem; border-radius: 999px;
  display: inline-flex; align-items: center; gap: .35rem; transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { color: #fff; box-shadow: var(--sh-1); }
.seg button.s-learning[aria-pressed="true"] { background: var(--warn); }
.seg button.s-confident[aria-pressed="true"] { background: var(--good); }
.seg button.s-notstarted[aria-pressed="true"] { background: var(--text-faint); }

/* section headings */
.l-section { margin: 0 0 3rem; scroll-margin-top: calc(var(--header-h) + 1.5rem); }
.l-section-head { margin-bottom: 1.4rem; padding-bottom: .85rem; border-bottom: 2px solid var(--border); }
.l-section-title { display: flex; align-items: center; gap: .7rem; font-size: 1.35rem; }
.l-section-title .num-chip {
  width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--accent); color: #fff; font-size: .8rem; font-weight: 700;
  box-shadow: 0 2px 6px -1px color-mix(in srgb, var(--accent) 55%, transparent);
}
.l-section-kicker { margin: .5rem 0 0 2.3rem; font-size: .89rem; color: var(--text-faint); line-height: 1.45; }

/* sub-heading chips at the top of the explanation */
.prose-outline {
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem;
  margin: 0 0 1.6rem; padding: .85rem 1rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r);
  max-width: var(--measure);
}
.po-label {
  width: 100%; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-faint); margin-bottom: .15rem;
}
.po-chip {
  font: inherit; font-size: .82rem; font-weight: 550; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text-soft); border-radius: 999px; padding: .28rem .75rem;
  transition: color .15s, border-color .15s, background .15s;
}
.po-chip:hover { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-wash); }

/* table of contents */
.lesson-toc { position: sticky; top: calc(var(--header-h) + 1.5rem); align-self: start; }
.toc-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); margin-bottom: .6rem; padding-left: .8rem; }
.toc-list { list-style: none; margin: 0 0 1.2rem; padding: 0; border-left: 2px solid var(--border); }
.toc-list a {
  display: block; padding: .38rem .8rem; font-size: .84rem; color: var(--text-soft);
  border-left: 2px solid transparent; margin-left: -2px; line-height: 1.35;
  transition: color .15s, border-color .15s;
}
.toc-list a:hover { color: var(--text); text-decoration: none; }
.toc-list a.active { color: var(--accent-ink); border-left-color: var(--accent); font-weight: 600; }
.toc-side-actions { display: grid; gap: .4rem; padding-left: .8rem; }
.toc-side-actions button {
  font: inherit; font-size: .8rem; color: var(--text-soft); background: none; border: none;
  cursor: pointer; text-align: left; padding: .25rem 0; display: flex; align-items: center; gap: .45rem;
}
.toc-side-actions button:hover { color: var(--text); }

/* ---------------- content blocks ---------------- */
/* The measure is applied to the *text* children, not to .prose itself, so that
   figures and tables can use the full column. A diagram squeezed into 66ch
   renders its labels at ~8px; given the room it nearly doubles that. The list
   below is exhaustive — renderBlocks() only ever emits p/h3/ul/ol/note/math/
   figure/table. */
.prose { font-family: var(--font-read); font-size: 1.15rem; line-height: 1.78; color: var(--text); counter-reset: figno tblno; }
.prose > p, .prose > h3, .prose > ul, .prose > ol,
.prose > .l-note, .prose > .l-mathblock { max-width: var(--measure); }
.prose p { margin: 0 0 1.15em; }

/* opening paragraph reads as a lede */
.prose > p.lede {
  font-size: 1.28rem; line-height: 1.62; color: var(--text);
  margin-bottom: 1.4em; padding-bottom: 1.1em;
  border-bottom: 1px solid var(--border);
}
.prose > p.lede:not(.no-cap)::first-letter {
  float: left; font-size: 3.3em; line-height: .84; font-weight: 600;
  padding: .06em .1em 0 0; color: var(--accent);
}

/* sub-headings — the main structural signal inside a lesson */
.prose h3 {
  font-family: var(--font-ui); font-size: 1.12rem; font-weight: 660;
  color: var(--text); margin: 2.4em 0 .75em; padding-top: .9em;
  border-top: 1px solid var(--border);
  display: flex; align-items: baseline; gap: .6rem;
}
.prose h3::before {
  content: ""; flex: 0 0 auto; width: 14px; height: 3px; border-radius: 2px;
  background: var(--accent); transform: translateY(-.28em);
}
.prose > h3:first-child { margin-top: 0; padding-top: 0; border-top: none; }

/* key terms become scanning anchors */
.prose b, .prose strong {
  font-weight: 620;
  background: linear-gradient(transparent 62%, color-mix(in srgb, var(--accent) 20%, transparent) 62%);
  padding: 0 .05em;
}
.prose em { font-style: italic; color: var(--text-soft); }

/* inline maths sits on a subtle chip so equations pop out of prose */
.prose .katex {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border-radius: 4px; padding: .05em .28em; font-size: 1.03em;
}
.prose .katex-display > .katex { background: none; padding: 0; }

.prose ul, .prose ol { margin: 0 0 1.2em; padding-left: 0; list-style: none; }
.prose ul li, .prose ol li { position: relative; padding-left: 1.6em; margin-bottom: .55em; }
.prose ul li::before {
  content: ""; position: absolute; left: .35em; top: .62em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
.prose ol { counter-reset: pli; }
.prose ol li { counter-increment: pli; }
.prose ol li::before {
  content: counter(pli); position: absolute; left: 0; top: .18em;
  width: 1.15em; height: 1.15em; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
  font-family: var(--font-ui); font-size: .72em; font-weight: 700;
}

/* ---- callouts, differentiated by what kind of note they are ---- */
.l-note {
  --note: var(--accent); --note-ink: var(--accent-ink); --note-wash: var(--accent-wash);
  position: relative; font-family: var(--font-ui); font-size: 1rem; line-height: 1.62;
  background: var(--note-wash);
  border: 1px solid color-mix(in srgb, var(--note) 26%, transparent);
  border-left: 3px solid var(--note);
  border-radius: var(--r); padding: 1rem 1.2rem; margin: 1.9em 0;
}
.l-note .note-tag {
  display: flex; align-items: center; gap: .45rem;
  font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--note-ink); font-weight: 750; margin-bottom: .45rem;
}
.l-note .note-tag .n-ico { font-size: .95rem; line-height: 1; }
.l-note p { margin-bottom: .7em; }
.l-note p:last-child { margin-bottom: 0; }
.l-note.n-practical { --note: var(--good); --note-ink: var(--good); --note-wash: var(--good-wash); }
.l-note.n-exam      { --note: var(--warn); --note-ink: var(--warn); --note-wash: var(--warn-wash); }
.l-note.n-supp      { --note: var(--supp-ink); --note-ink: var(--supp-ink); --note-wash: var(--supp-wash); }
.l-note.n-warn      { --note: var(--bad); --note-ink: var(--bad); --note-wash: var(--bad-wash); }

/* ---------------- figures ----------------
   Diagrams are inline SVG, so the stylesheet can reach into them. Everything
   that is *presentation* — type, weight, stroke joins, palette — lives here
   rather than in 523 hand-written attributes, which is what lets the whole
   set be restyled or re-themed at once. Figure SVGs should therefore carry
   geometry and semantic classes, and leave colour and type to this file. */
figure.l-figure { margin: 2.1em 0; }
figure.l-figure .fig-frame {
  position: relative;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 1.35rem 1.2rem; text-align: center;
  box-shadow: var(--sh-1); cursor: zoom-in;
}
figure.l-figure svg { max-width: 100%; height: auto; display: inline-block; vertical-align: middle; }

/* Type: match the site's UI face instead of the browser's default Arial, and
   keep the optical weight even — SVG text has no surrounding prose to sit in,
   so it needs slightly more weight than body copy to hold up. */
.fig-frame svg text, .fig-frame svg tspan {
  font-family: var(--font-ui);
  font-weight: 500;
  letter-spacing: .005em;
}
.fig-frame svg { stroke-linecap: round; stroke-linejoin: round; }
/* figures that deliberately want a different face keep it */
.fig-frame svg .f-serif, .fig-frame svg .f-serif tspan { font-family: var(--font-read); }
.fig-frame svg .f-num, .fig-frame svg .f-num tspan { font-family: var(--font-mono); }

/* Semantic classes for figure content. Hand-written SVGs use these; the
   normalisation pass maps legacy inline attributes onto them. */
.fig-frame svg .f-ink    { fill: var(--fig-ink); }
.fig-frame svg .f-muted  { fill: var(--fig-muted); }
.fig-frame svg .f-lbl    { fill: var(--fig-ink); font-size: 12px; }
.fig-frame svg .f-sub    { fill: var(--fig-muted); font-size: 10.5px; }
.fig-frame svg .f-ttl    { fill: var(--fig-ink); font-weight: 700; font-size: 13px; }
.fig-frame svg .f-num    { font-family: var(--font-mono); font-weight: 500; }
.fig-frame svg .f-stroke { fill: none; stroke: var(--fig-line); stroke-width: 1.5; }
.fig-frame svg .f-rule   { stroke: var(--fig-line); stroke-width: 1.25; fill: none; }
.fig-frame svg .f-grid   { stroke: var(--fig-grid); stroke-width: 1; fill: none; }
.fig-frame svg .f-axis   { stroke: var(--fig-ink); stroke-width: 1.5; fill: none; }
.fig-frame svg .f-paper  { fill: var(--fig-paper); }
/* A label that crosses a line stays readable if it knocks out its background. */
.fig-frame svg .f-halo   { paint-order: stroke fill; stroke: var(--fig-paper); stroke-width: 3.5px; }

/* Categorical hues — use for parts that must be told apart, not for decoration. */
.fig-frame svg .c1 { color: var(--fig-1); } .fig-frame svg .c2 { color: var(--fig-2); }
.fig-frame svg .c3 { color: var(--fig-3); } .fig-frame svg .c4 { color: var(--fig-4); }
.fig-frame svg .c5 { color: var(--fig-5); } .fig-frame svg .c6 { color: var(--fig-6); }
.fig-frame svg .fill  { fill: currentColor; stroke: none; }
.fig-frame svg .wash  { fill: color-mix(in srgb, currentColor 14%, transparent); stroke: currentColor; stroke-width: 1.5; }
.fig-frame svg .line  { fill: none; stroke: currentColor; stroke-width: 2; }
.fig-frame svg .txt   { fill: currentColor; }

figure.l-figure figcaption, figure.l-table figcaption {
  font-family: var(--font-ui); font-size: .84rem; color: var(--text-soft);
  margin-top: .7rem; line-height: 1.5; padding-left: .9rem;
  border-left: 2px solid var(--border-strong); text-align: left;
  max-width: var(--measure);
}
/* Numbered like a textbook, so prose can say "see Figure 3". */
figure.l-figure { counter-increment: figno; }
figure.l-table { counter-increment: tblno; }
figure.l-figure figcaption::before,
figure.l-table figcaption::before {
  font-weight: 650; color: var(--text); letter-spacing: .01em;
}
figure.l-figure figcaption::before { content: "Figure " counter(figno) " · "; }
figure.l-table figcaption::before { content: "Table " counter(tblno) " · "; }
figure.l-table { margin: 1.8em 0; }

/* Enlarge control — diagrams are dense and the reading column is narrow on a
   phone, so every figure can be opened full-screen and zoomed. */
.fig-zoom {
  position: absolute; top: .5rem; right: .5rem; z-index: 1;
  width: 30px; height: 30px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text-soft);
  cursor: zoom-in; opacity: 0; transition: opacity .15s, color .15s;
}
.fig-frame:hover .fig-zoom, .fig-zoom:focus-visible { opacity: 1; }
.fig-zoom:hover { color: var(--accent); border-color: var(--accent); }
/* No hover to reveal it on touch, and it matters most on a small screen. */
@media (hover: none), (max-width: 760px) { .fig-zoom { opacity: .8; } }

.fig-lightbox {
  position: fixed; inset: 0; z-index: 120; display: grid;
  grid-template-rows: auto 1fr auto;
  background: color-mix(in srgb, var(--bg) 88%, #000);
  backdrop-filter: blur(3px);
}
.fig-lightbox .fl-bar {
  display: flex; align-items: center; gap: .5rem; justify-content: flex-end;
  padding: .6rem .9rem; border-bottom: 1px solid var(--border);
}
.fig-lightbox .fl-bar .fl-hint { margin-right: auto; font-family: var(--font-ui); font-size: .8rem; color: var(--text-faint); }
.fig-lightbox .fl-stage {
  overflow: hidden; display: grid; place-items: center; touch-action: none; cursor: grab;
}
.fig-lightbox .fl-stage.is-drag { cursor: grabbing; }
.fig-lightbox .fl-inner { transform-origin: center center; will-change: transform; }
.fig-lightbox .fl-inner svg { width: min(92vw, 1100px); height: auto; max-width: none; }
.fig-lightbox .fl-cap {
  font-family: var(--font-ui); font-size: .85rem; color: var(--text-soft);
  padding: .8rem 1.2rem; border-top: 1px solid var(--border); text-align: center;
}
.fl-btn {
  min-width: 34px; height: 34px; padding: 0 .55rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-family: var(--font-ui); font-size: .9rem; cursor: pointer;
}
.fl-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
table.data-table { border-collapse: collapse; width: 100%; font-family: var(--font-ui); font-size: .9rem; }
table.data-table th, table.data-table td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); }
table.data-table thead th { background: var(--surface-2); font-weight: 650; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); white-space: nowrap; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover td { background: var(--surface-2); }
.l-mathblock { margin: 1.5em 0; overflow-x: auto; overflow-y: hidden; padding: .2rem 0; }

/* objectives */
.objectives { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; max-width: var(--measure); }
.objectives li {
  display: flex; gap: .7rem; align-items: flex-start; padding: .7rem .9rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: .96rem; line-height: 1.5;
}
.objectives li::before { content: "✓"; color: var(--good); font-weight: 700; flex: 0 0 auto; }
.objectives li.supp { background: var(--supp-wash); border-color: var(--supp-border); }
.objectives li.supp::before { color: var(--supp-ink); }
.tag-supp {
  flex: 0 0 auto; align-self: center; font-size: .63rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--supp-ink); border: 1px solid var(--supp-border);
  border-radius: 5px; padding: .1rem .4rem; white-space: nowrap;
}

/* definitions */
.def-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; max-width: var(--measure); }
.def-list li {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--r-sm); padding: .8rem 1rem; font-size: .97rem; line-height: 1.55;
}
.def-list .term { font-weight: 680; }
.def-list .term::after { content: " — "; color: var(--text-faint); font-weight: 400; }
.def-list .def { color: var(--text-soft); }

/* formulae */
.formula-grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.formula-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 1rem 1.15rem; box-shadow: var(--sh-1); }
.f-name { font-size: .74rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 650; margin-bottom: .5rem; }
.f-eq { font-size: 1.1rem; overflow-x: auto; overflow-y: hidden; padding: .35rem 0; }
.symbol-table { width: 100%; border-collapse: collapse; margin-top: .8rem; font-size: .87rem; }
.symbol-table th, .symbol-table td { text-align: left; padding: .32rem .4rem; border-bottom: 1px solid var(--border); }
.symbol-table th { color: var(--text-faint); font-weight: 620; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
.symbol-table tr:last-child td { border-bottom: none; }
.symbol-table td:first-child { width: 3.2rem; }

/* worked examples */
.worked { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 1.1rem 1.3rem; margin-bottom: 1rem; box-shadow: var(--sh-1); }
.w-head { display: flex; justify-content: space-between; align-items: baseline; gap: .7rem; margin-bottom: .7rem; }
.w-title { font-weight: 640; font-size: 1rem; }
.w-marks { font-size: .74rem; font-weight: 650; color: var(--accent-ink); background: var(--accent-wash); padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; }
.w-question { font-family: var(--font-read); font-size: 1.03rem; line-height: 1.6; margin: 0 0 1rem; padding: .7rem .9rem; background: var(--surface-2); border-radius: var(--r-sm); }
ol.w-steps { list-style: none; margin: 0; padding: 0; counter-reset: wstep; }
ol.w-steps li { counter-increment: wstep; display: grid; grid-template-columns: 1.5rem 1fr; gap: .1rem .7rem; padding: .6rem 0; border-top: 1px solid var(--border); }
ol.w-steps li:first-child { border-top: none; padding-top: 0; }
ol.w-steps li::before {
  content: counter(wstep); grid-row: 1 / span 2; align-self: start;
  width: 1.5rem; height: 1.5rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-3); color: var(--text-soft); font-size: .68rem; font-weight: 700;
}
.w-do { font-size: 1.02rem; overflow-x: auto; overflow-y: hidden; padding: .1rem 0; }
.w-do .katex { font-size: 1.06em; }
.w-why { color: var(--text-soft); font-size: .88rem; line-height: 1.5; }

/* mistakes */
.mistakes { display: grid; gap: .6rem; max-width: var(--measure); }
.mistake {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--bad);
  border-radius: var(--r-sm); padding: .85rem 1.05rem;
}
.m-trap { font-weight: 620; display: flex; gap: .5rem; align-items: flex-start; margin-bottom: .35rem; }
.m-trap::before { content: "✕"; color: var(--bad); font-weight: 800; flex: 0 0 auto; }
.m-mark { color: var(--text-soft); font-size: .9rem; line-height: 1.5; padding-left: 1.2rem; }
.m-mark::before { content: "Examiner "; color: var(--warn); font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }

/* practice */
.practice-item { border: 1px solid var(--border); border-radius: var(--r); margin-bottom: .7rem; background: var(--surface); overflow: hidden; }
.p-q { padding: 1rem 1.15rem; }
.p-meta { display: flex; gap: .5rem; align-items: center; margin-bottom: .55rem; }
.cmd { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent-ink); background: var(--accent-wash); padding: .15rem .55rem; border-radius: 5px; }
.p-marks { font-size: .76rem; color: var(--text-faint); font-weight: 600; }
.p-qtext { font-family: var(--font-read); font-size: 1.04rem; line-height: 1.6; margin-bottom: .7rem; }
.reveal-btn {
  font: inherit; font-size: .84rem; font-weight: 600; cursor: pointer; color: var(--accent-ink);
  background: none; border: none; padding: .2rem 0; display: inline-flex; align-items: center; gap: .35rem;
}
.reveal-btn:hover { text-decoration: underline; }
.p-answer { display: none; padding: .95rem 1.15rem; background: var(--good-wash); border-top: 1px solid var(--border); font-size: .96rem; line-height: 1.6; }
.p-answer.open { display: block; }
.ms-title { font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); font-weight: 700; margin-bottom: .4rem; }
.p-answer b { color: var(--good); font-weight: 700; }

/* prev/next */
.lesson-nav { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.lesson-nav a {
  display: flex; flex-direction: column; gap: .2rem; padding: .9rem 1.1rem;
  border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); color: var(--text);
  transition: border-color .15s, background .15s;
}
.lesson-nav a:hover { border-color: var(--accent); background: var(--accent-wash); text-decoration: none; }
.ln-dir { font-size: .72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }
.ln-title { font-weight: 600; font-size: .93rem; }
.lesson-nav a.next { text-align: right; }
.lesson-nav a.disabled { visibility: hidden; }

/* pending */
.pending { max-width: var(--measure); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r-lg); padding: 2.5rem; text-align: center; color: var(--text-soft); }
.pending h2 { margin-bottom: .6rem; color: var(--text); }
.stage-pill { display: inline-block; margin-top: .9rem; font-size: .8rem; color: var(--accent-ink); background: var(--accent-wash); padding: .35rem .9rem; border-radius: 999px; }

/* ---------------- quiz ---------------- */
.quiz { display: grid; gap: .9rem; max-width: var(--measure); }
.quiz-q { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 1.1rem 1.25rem; }
.q-text { font-weight: 600; margin-bottom: .8rem; line-height: 1.5; }
.q-index { color: var(--accent); margin-right: .4rem; font-weight: 700; }
.quiz-options { display: grid; gap: .45rem; }
.quiz-opt {
  display: flex; align-items: flex-start; gap: .7rem; text-align: left; width: 100%;
  font: inherit; font-size: .95rem; cursor: pointer; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: .65rem .85rem;
  transition: border-color .12s, background .12s;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-wash); }
.opt-key { font-family: var(--font-mono); font-weight: 700; color: var(--text-faint); flex: 0 0 auto; }
.quiz-opt.correct { border-color: var(--good); background: var(--good-wash); }
.quiz-opt.correct .opt-key { color: var(--good); }
.quiz-opt.wrong { border-color: var(--bad); background: var(--bad-wash); }
.quiz-opt.wrong .opt-key { color: var(--bad); }
.quiz-opt:disabled { cursor: default; }
.opt-feedback { display: none; font-size: .87rem; line-height: 1.5; margin: .1rem 0 .3rem 2rem; padding: .5rem .75rem; border-radius: var(--r-sm); }
.opt-feedback.show { display: block; }
.opt-feedback.ok { background: var(--good-wash); color: var(--text); border-left: 2px solid var(--good); }
.opt-feedback.no { background: var(--bad-wash); color: var(--text); border-left: 2px solid var(--bad); }
.quiz-score { font-weight: 640; padding: .9rem 1.1rem; border-radius: var(--r); background: var(--accent-wash); color: var(--accent-ink); text-align: center; }

/* ---------------- flashcards ---------------- */
.fc-wrap { max-width: 620px; margin: 0 auto; }
.fc-meta { display: flex; justify-content: space-between; color: var(--text-faint); font-size: .8rem; margin-bottom: .8rem; }
.fc-stage { perspective: 1600px; margin-bottom: 1.4rem; }
.fc-card { position: relative; width: 100%; min-height: 280px; cursor: pointer; transform-style: preserve-3d; transition: transform .55s cubic-bezier(.2,.8,.25,1); }
.fc-card.flipped { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: .9rem;
  padding: 2.2rem; border-radius: var(--r-lg); border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--sh-2);
}
.fc-role { position: absolute; top: 1.1rem; left: 1.2rem; font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); font-weight: 700; }
.fc-term { font-size: 1.6rem; font-weight: 650; letter-spacing: -.015em; }
.fc-back { transform: rotateY(180deg); }
.fc-def { font-family: var(--font-read); font-size: 1.15rem; line-height: 1.6; }
.fc-hint { color: var(--text-faint); font-size: .82rem; }
.fc-controls { display: flex; gap: .6rem; justify-content: center; }
.fc-controls .btn { min-width: 9rem; justify-content: center; }
.fc-progress { text-align: center; color: var(--text-soft); font-size: .85rem; margin-top: 1rem; }
.grade-again { border-color: var(--bad) !important; color: var(--bad) !important; }
.grade-good { border-color: var(--good) !important; color: var(--good) !important; }
.fc-done { text-align: center; padding: 2.5rem 1rem; }

/* ---------------- Ask Claude tutor ---------------- */
.toc-ask { padding-left: .8rem; margin-bottom: 1rem; }
.toc-ask .tutor-launch { width: 100%; justify-content: center; }

.tutor-launch {
  display: inline-flex; align-items: center; gap: .45rem; cursor: pointer;
  font: inherit; font-size: .85rem; font-weight: 560; padding: .5rem .9rem;
  border-radius: 10px; color: var(--accent-ink);
  background: var(--accent-wash); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  transition: background .15s, border-color .15s;
}
.tutor-launch:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); border-color: var(--accent); }

.tutor-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw);
  display: flex; flex-direction: column; z-index: 90;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--sh-3);
  transform: translateX(100%); transition: transform .25s cubic-bezier(.2,.8,.3,1);
}
body.tutor-open .tutor-panel { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) { .tutor-panel { transition: none; } }

.tutor-head {
  display: flex; align-items: center; gap: .6rem; flex: 0 0 auto;
  padding: .85rem 1rem; border-bottom: 1px solid var(--border);
}
.tutor-title { flex: 1; display: flex; align-items: center; gap: .45rem; font-weight: 640; font-size: .95rem; }
.tutor-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: 0 0 auto; }
.tutor-model { color: var(--text-faint); font-weight: 400; font-size: .78rem; }

.tutor-list { flex: 1 1 auto; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.tutor-msg { display: grid; gap: .25rem; }
.tutor-who { font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; color: var(--text-faint); }
.tutor-user .tutor-who { color: var(--accent-ink); }
.tutor-body { font-size: .95rem; line-height: 1.6; overflow-wrap: anywhere; }
.tutor-body p { margin: 0 0 .7em; }
.tutor-body p:last-child { margin-bottom: 0; }
.tutor-body ul { margin: 0 0 .7em; padding-left: 1.15rem; }
.tutor-body li { margin-bottom: .3em; }
.tutor-body pre {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: .6rem .8rem; overflow-x: auto; font-size: .85rem;
}
.tutor-body code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; font-size: .88em; }
.tutor-body pre code { background: none; padding: 0; }
.tutor-user .tutor-body {
  background: var(--accent-wash); border-radius: var(--r-sm);
  padding: .55rem .75rem; white-space: pre-wrap;
}
.tutor-err { color: var(--bad); }

.tutor-meta { flex: 0 0 auto; padding: 0 1rem; font-size: .7rem; color: var(--text-faint); min-height: 1em; }
.tutor-form { flex: 0 0 auto; display: flex; gap: .5rem; align-items: flex-end; padding: .75rem 1rem 1rem; border-top: 1px solid var(--border); }
.tutor-input {
  flex: 1; resize: none; font: inherit; font-size: .92rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: .55rem .7rem; max-height: 40vh;
}
.tutor-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.tutor-send { white-space: nowrap; }
.tutor-send:disabled { opacity: .55; cursor: default; }

@media (max-width: 760px) {
  .tutor-panel { width: 100vw; }
}
@media print { .tutor-panel, .tutor-launch { display: none !important; } }

/* ---------------- shortcuts dialog ---------------- */
.shortcuts-backdrop { position: fixed; inset: 0; z-index: 130; background: color-mix(in srgb, #0a0a0e 45%, transparent); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 1rem; }
.shortcuts-backdrop[hidden] { display: none; }
.shortcuts { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--sh-3); padding: 1.4rem 1.6rem; }
.shortcuts h2 { font-size: 1.05rem; margin-bottom: 1rem; }
.shortcuts dl { display: grid; grid-template-columns: auto 1fr; gap: .6rem 1rem; margin: 0; align-items: center; }
.shortcuts dt { text-align: right; }
.shortcuts dd { margin: 0; color: var(--text-soft); font-size: .9rem; }

/* ---------------- responsive ---------------- */
@media (max-width: 1080px) {
  .lesson-layout { grid-template-columns: 1fr; gap: 0; }
  .lesson-toc { display: none; }
}
@media (max-width: 760px) {
  body { font-size: 16px; }
  .site-main { padding: 1.25rem 1rem 3rem; }
  .header-inner { padding: 0 .85rem; gap: .5rem; }
  .brand-text { display: none; }
  .search-trigger { min-width: 0; flex: 1; padding: .42rem .7rem; }
  .search-trigger kbd { display: none; }
  .subject-grid { grid-template-columns: 1fr; }
  .stat-strip { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 1rem; }
  .stat-legend { justify-content: center; }
  .prose { font-size: 1.08rem; }
  /* A 440-unit diagram squeezed into a 340px phone renders its labels at ~8px.
     Hold the figure at a legible size and let the frame scroll instead —
     scaling the whole figure uniformly can't make labels collide, whereas
     enlarging the type inside it would. Tapping still opens the lightbox. */
  figure.l-figure .fig-frame { padding: 1rem .8rem; }
  figure.l-figure .fig-scroll { overflow-x: auto; }
  figure.l-figure svg { min-width: 440px; }
  .lesson-nav { grid-template-columns: 1fr; }
  .lesson-nav a.next { text-align: left; }
  .formula-grid { grid-template-columns: 1fr; }
  .continue { flex-wrap: wrap; }
  .toolbar { gap: .5rem; }
  .worked, .quiz-q, .p-q { padding-left: 1rem; padding-right: 1rem; }
  ol.w-steps li { grid-template-columns: 1.3rem 1fr; gap: .1rem .55rem; }
}

/* ---------------- print ---------------- */
@media print {
  .site-header, .site-footer, .toolbar, .status-picker, .lesson-nav, .skip-link,
  .reveal-btn, .lesson-toc, .cmdk-backdrop, .shortcuts-backdrop, .continue, .filter-chips,
  .fig-zoom, .fig-lightbox { display: none !important; }
  /* force the light diagram palette — a dark-theme figure prints as a black box */
  :root, :root[data-theme="dark"] {
    --fig-paper: #fff; --fig-ink: #000; --fig-muted: #444;
    --fig-line: #888; --fig-grid: #ddd;
    --fig-1: #1a49b8; --fig-2: #14663f; --fig-3: #8c5a10;
    --fig-4: #a32b43; --fig-5: #553aa3; --fig-6: #0a615d;
  }
  .fig-frame { border: 1px solid #bbb !important; background: #fff !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .site-main { max-width: none; padding: 0; }
  .lesson-layout { display: block; }
  .prose, .objectives, .l-summary, .mistakes, .def-list, .quiz { max-width: none; }
  .worked, .quiz-q, .formula-card, .practice-item, .l-note, figure.l-figure, .l-section { break-inside: avoid; box-shadow: none; }
  .p-answer { display: block !important; background: none; border-top: 1px solid #ccc; }
  .opt-feedback { display: block !important; }
  .quiz-opt.is-answer { outline: 1.5px solid #000; }
  a { color: #000; text-decoration: none; }
  .l-section-title { border-bottom: 1.5px solid #000; }
}
