/* All colours, sizes and radii come from the tokens in the :root blocks below.
   DESIGN.md explains every token. test/lint.test.js fails if a hex colour
   appears outside a :root block. */

/* ---------- Fonts (self hosted, copied from @fontsource by build.js) ---------- */
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-ext-400-normal.woff2") format("woff2"); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 400; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-400-italic.woff2") format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 400; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-ext-400-italic.woff2") format("woff2"); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-ext-700-normal.woff2") format("woff2"); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Lexend"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/lexend-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Lexend"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/lexend-latin-ext-600-normal.woff2") format("woff2"); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Lexend"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/lexend-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Lexend"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/lexend-latin-ext-700-normal.woff2") format("woff2"); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
/* Metric-matched fallbacks, so text barely moves when the real fonts arrive.
   Values measured from the font files against Arial. */
@font-face { font-family: "Atkinson Fallback"; src: local("Arial"); size-adjust: 120.98%; ascent-override: 78.53%; descent-override: 23.97%; line-gap-override: 0%; }
@font-face { font-family: "Lexend Fallback"; src: local("Arial"); size-adjust: 139.78%; ascent-override: 71.54%; descent-override: 17.89%; line-gap-override: 0%; }

/* ---------- Tokens: light (default) ---------- */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f6f7f9;
  --ink: #141a26;
  --muted: #556070;
  --line: #e3e6eb;
  --tint-neutral: #f3f5f8;
  --amber-bg: #fff5e0;
  --amber-ink: #8a5300;
  --good: #1b7a4f;
  --bad: #b42318;
  --on-accent: #ffffff;
  --visited: #4b5a8f;
  --brand: #1d2b4f;
  --on-brand: #ffffff;
  --brand-mark: #ffd166;
  /* Book pages set --accent-light and --accent-dark inline on <html>. */
  --accent: var(--accent-light, var(--brand));
  --accent-tint: color-mix(in srgb, var(--accent) 8%, var(--bg));
  --accent-mid: color-mix(in srgb, var(--accent) 22%, var(--bg));
  --good-tint: color-mix(in srgb, var(--good) 10%, var(--bg));
  --bad-tint: color-mix(in srgb, var(--bad) 10%, var(--bg));

  /* Type */
  --font-body: "Atkinson Hyperlegible", "Atkinson Fallback", Arial, sans-serif;
  --font-head: "Lexend", "Lexend Fallback", Arial, sans-serif;
  --t-display: 40px;
  --t-h2: 28px;
  --t-h3: 21px;
  --t-body: 18px;
  --t-small: 15px;
  --t-label: 14px;

  /* Space, radius, size */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-pill: 999px;
  --tap: 44px;
  --measure: 68ch;
}
.book-row { --accent: var(--accent-light); }

/* ---------- Tokens: dark (system setting, or data-theme="dark") ----------
   Screen only, so printing always uses the light theme. */
@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f131a;
    --surface: #171c25;
    --ink: #e9edf3;
    --muted: #a4adbb;
    --line: #283040;
    --tint-neutral: #1a202b;
    --amber-bg: #2a2213;
    --amber-ink: #f1c36b;
    --good: #5fd39d;
    --bad: #ff8a80;
    --on-accent: #0f131a;
    --visited: #a7b2d4;
    --brand: #b8c4e6;
    --on-brand: #0f131a;
    --accent: var(--accent-dark, var(--brand));
    --accent-tint: color-mix(in srgb, var(--accent) 14%, var(--bg));
    --accent-mid: color-mix(in srgb, var(--accent) 30%, var(--bg));
  }
  :root:not([data-theme="light"]) .book-row { --accent: var(--accent-dark); }
}
@media screen {
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f131a;
  --surface: #171c25;
  --ink: #e9edf3;
  --muted: #a4adbb;
  --line: #283040;
  --tint-neutral: #1a202b;
  --amber-bg: #2a2213;
  --amber-ink: #f1c36b;
  --good: #5fd39d;
  --bad: #ff8a80;
  --on-accent: #0f131a;
  --visited: #a7b2d4;
  --brand: #b8c4e6;
  --on-brand: #0f131a;
  --accent: var(--accent-dark, var(--brand));
  --accent-tint: color-mix(in srgb, var(--accent) 14%, var(--bg));
  --accent-mid: color-mix(in srgb, var(--accent) 30%, var(--bg));
}
:root[data-theme="dark"] .book-row { --accent: var(--accent-dark); }
}

/* Phone type sizes */
@media (max-width: 599px) {
  :root {
    --t-display: 30px;
    --t-h2: 23px;
    --t-h3: 19px;
    --t-body: 17px;
    --t-small: 14px;
    --t-label: 13px;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
/* The hidden attribute always wins over a component display rule. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; accent-color: var(--accent); caret-color: var(--accent); scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::selection { background: color-mix(in srgb, var(--accent) 25%, var(--bg)); color: var(--ink); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--t-body);
  line-height: 1.65;
}
h1, h2, h3, h4 { font-family: var(--font-head); line-height: 1.25; font-weight: 600; text-wrap: balance; }
a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
img, svg { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip-link {
  position: absolute; left: var(--s-4); top: calc(-1 * var(--s-8)); z-index: 30;
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--s-4);
  background: var(--accent); color: var(--on-accent); border-radius: var(--r-md);
  font: 600 var(--t-label) var(--font-head); text-decoration: none;
}
.skip-link:focus { top: var(--s-2); }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 var(--s-4); }

/* ---------- Header and footer ---------- */
.site-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-1) var(--s-5); border-bottom: 1px solid var(--line); background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.brand { flex-shrink: 0; display: inline-flex; align-items: center; gap: var(--s-3); min-height: var(--tap); text-decoration: none; color: var(--ink); font-family: var(--font-head); font-weight: 700; font-size: var(--t-h3); }
.site-head nav a { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--s-2); color: var(--muted); text-decoration: none; font: 600 var(--t-label) var(--font-head); }
.site-head nav a:hover { color: var(--ink); }
.site-foot { border-top: 1px solid var(--line); margin-top: var(--s-8); padding: var(--s-5) var(--s-4); text-align: center; color: var(--muted); font-size: var(--t-small); }

/* ---------- Home: study launcher ---------- */
.launcher { padding: var(--s-7) 0 var(--s-5); max-width: 720px; display: grid; justify-items: start; gap: var(--s-4); }
.launcher h1 { font-size: var(--t-display); line-height: 1.15; margin: 0; font-weight: 700; }
.section-title { font-size: var(--t-h2); margin: var(--s-6) 0 var(--s-3); }
.book-list { list-style: none; padding: 0; margin: 0; max-width: var(--measure); border-top: 1px solid var(--line); }
.book-list li { border-bottom: 1px solid var(--line); }
.book-row { display: flex; align-items: center; gap: var(--s-4); min-height: var(--tap); padding: var(--s-3) var(--s-2); color: var(--ink); text-decoration: none; transition: background-color .12s; }
a.book-row:hover { background: var(--tint-neutral); }
.book-row.is-soon { color: var(--muted); }
.book-mark { flex: none; width: var(--s-7); height: var(--s-7); display: grid; place-items: center; border-radius: var(--r-md); background: var(--accent); color: var(--on-accent); font: 700 var(--t-h2) var(--font-head); }
.mark-icon { width: 1.15em; height: 1.15em; }
.is-soon .book-mark { background: var(--tint-neutral); color: var(--muted); }
.br-text { flex: 1; display: grid; }
.br-text strong { font: 600 var(--t-h3) var(--font-head); text-wrap: balance; }
.br-text small { color: var(--muted); font-size: var(--t-small); font-variant-numeric: tabular-nums; }
.br-go { color: var(--accent); font: 600 var(--t-h3) var(--font-head); }
.trust { color: var(--muted); font-size: var(--t-small); margin: var(--s-5) 0 0; max-width: var(--measure); }
.launcher .level-switch { margin-top: var(--s-1); }

/* ---------- Book page ---------- */
.crumbs { font: 600 var(--t-label) var(--font-head); color: var(--muted); margin: var(--s-4) 0 var(--s-1); }
.crumbs a { display: inline-flex; align-items: center; min-height: var(--tap); color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.book-hero h1 { font-size: var(--t-display); line-height: 1.15; font-weight: 700; margin: var(--s-2) 0; color: var(--accent); }
.book-hero > p { font-size: var(--t-body); color: var(--muted); max-width: 680px; margin: 0 0 var(--s-4); }
.unit h2 { font-size: var(--t-h2); margin: var(--s-7) 0 var(--s-3); display: flex; align-items: baseline; gap: var(--s-3); flex-wrap: wrap; }
.unit-n { font: 600 var(--t-label) var(--font-head); color: var(--accent); }
.chapter-list { list-style: none; padding: 0; margin: 0; max-width: var(--measure); display: grid; grid-template-columns: minmax(0, 1fr); column-gap: var(--s-6); border-top: 1px solid var(--line); }
.chapter-list li { border-bottom: 1px solid var(--line); }
.chapter-list a { display: flex; gap: var(--s-3); align-items: flex-start; min-height: var(--tap); height: 100%; padding: var(--s-3) var(--s-2); text-decoration: none; color: var(--ink); transition: background-color .12s; }
.chapter-list a:hover { background: var(--tint-neutral); }
@media (min-width: 900px) {
  .chapter-list { max-width: none; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.ch-n { flex: none; width: var(--s-6); height: var(--s-6); border-radius: 50%; background: var(--accent-tint); display: grid; place-items: center; font: 600 var(--t-label) var(--font-head); color: var(--accent); font-variant-numeric: tabular-nums; }
.ch-t strong { display: block; font-family: var(--font-head); font-weight: 600; line-height: 1.3; margin-bottom: 2px; }
.ch-t small { color: var(--muted); font-size: var(--t-small); line-height: 1.4; display: block; }

/* ---------- Chapter layout ---------- */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: var(--s-6); max-width: 1180px; margin: 0 auto; padding: 0 var(--s-5); }
.sidebar { position: sticky; top: 70px; align-self: start; max-height: calc(100vh - 80px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; padding: var(--s-5) 0; font-size: var(--t-small); }
.side-details summary { display: flex; align-items: center; min-height: var(--tap); font-family: var(--font-head); font-weight: 600; cursor: pointer; list-style: none; }
.side-details summary::-webkit-details-marker { display: none; }
.side-unit { font: 600 var(--t-label) var(--font-head); color: var(--muted); margin: var(--s-4) 0 var(--s-1); }
.side-nav ol { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s-2); }
.side-nav a { display: flex; align-items: center; gap: var(--s-2); min-height: var(--tap); padding: var(--s-1) var(--s-2); border-radius: var(--r-md); text-decoration: none; color: var(--ink); line-height: 1.35; }
.side-nav a span { color: var(--muted); min-width: 18px; font: 600 var(--t-label) var(--font-head); font-variant-numeric: tabular-nums; }
.side-nav a:hover { background: var(--tint-neutral); }
.side-nav li.current a { background: var(--accent); color: var(--on-accent); }
.side-nav li.current a span { color: var(--on-accent); }

.chapter { min-width: 0; max-width: var(--measure); padding-bottom: var(--s-6); }
.ch-head { margin-bottom: var(--s-5); }
.ch-head h1 { font-size: var(--t-display); line-height: 1.15; font-weight: 700; margin: 0 0 var(--s-2); }
.ch-blurb { color: var(--muted); font-size: var(--t-body); margin: 0 0 var(--s-4); }

.level-switch { display: inline-flex; align-items: center; gap: var(--s-2); background: var(--tint-neutral); border-radius: var(--r-pill); padding: var(--s-1); flex-wrap: wrap; }
.ls-label { font: 600 var(--t-label) var(--font-head); color: var(--muted); padding: 0 var(--s-2) 0 var(--s-3); }
.level-switch button {
  min-height: var(--tap); border: 0; background: transparent; color: var(--ink); font: 600 var(--t-label) var(--font-head); padding: 0 var(--s-4); border-radius: var(--r-pill); cursor: pointer;
}
.level-switch button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
/* First visit: the switch asks "Which year are you in?" until a year is chosen. */
.level-switch.is-prompt { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: min(100%, 420px); border-radius: var(--r-md); background: var(--accent-tint); outline: 2px solid var(--accent); outline-offset: 0; }
.level-switch.is-prompt .ls-label { grid-column: 1 / -1; padding: var(--s-2) var(--s-3) 0; }
.level-switch.is-prompt button { border-radius: var(--r-md); }
.level-switch.is-prompt .ls-label { color: var(--ink); }
.toc { border-block: 1px solid var(--line); margin: 0 0 var(--s-5); font-size: var(--t-small); }
.toc summary { display: flex; align-items: center; min-height: var(--tap); cursor: pointer; font-family: var(--font-head); font-weight: 600; }
.toc ol { margin: 0 0 var(--s-2); padding-left: var(--s-5); }
.toc a { display: flex; align-items: center; min-height: var(--tap); color: var(--ink); text-decoration: none; }
.toc a:hover { color: var(--accent); }

/* Level filter */
html[data-show="10"] [data-level="11"],
html[data-show="10"] [data-level="12"],
html[data-show="11"] [data-level="12"] { display: none !important; }

/* ---------- Prose ---------- */
.prose h2 { font-size: var(--t-h2); margin: var(--s-7) 0 var(--s-3); scroll-margin-top: 80px; }
.prose h3 { font-size: var(--t-h3); margin: var(--s-6) 0 var(--s-2); }
.prose p { margin: 0 0 var(--s-4); }
.prose ul, .prose ol { padding-left: var(--s-5); margin: 0 0 var(--s-4); }
.prose li { margin-bottom: var(--s-1); }
.prose strong { font-weight: 700; }
.prose a:visited { color: var(--visited); }
.prose code { background: var(--tint-neutral); padding: 1px var(--s-1); border-radius: var(--r-sm); font-size: 0.9em; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-6) 0; }
.prose .katex { font-size: 1.08em; }
.prose .katex-display { overflow-x: auto; overflow-y: hidden; padding: var(--s-1) 0; margin: var(--s-4) 0; }
.table-wrap { overflow-x: auto; margin: 0 0 var(--s-4); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
.prose table { border-collapse: collapse; width: 100%; font-size: var(--t-small); }
.prose th, .prose td { text-align: left; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--line); vertical-align: top; }
.prose th { font-family: var(--font-head); font-weight: 600; background: var(--tint-neutral); }
.prose tr:last-child td { border-bottom: 0; }
.prose figure { margin: var(--s-5) 0; }
.prose figure.svg-fig { background: var(--surface); border-radius: var(--r-md); padding: var(--s-4); text-align: center; }
.prose figcaption { font-size: var(--t-small); color: var(--muted); margin-top: var(--s-2); text-align: center; }
.prose blockquote { margin: var(--s-4) 0; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--tint-neutral); font-family: var(--font-head); }
.prose blockquote p { margin: 0; }

/* ---------- Diagrams ----------
   Chapter diagrams are inline SVG drawn with a fixed palette (DESIGN.md).
   Each drawn colour maps to a theme token, so diagrams follow light and dark.
   Real colours (spectrum gradient stops, the yellow #f3b33d) are left alone. */
.diagram { fill: var(--ink); }
.diagram [stroke="#1b2236"] { stroke: var(--ink); }
.diagram [fill="#1b2236"] { fill: var(--ink); }
.diagram [fill="#fff"] { fill: var(--surface); }
.diagram [stroke="#5b6478"], .diagram [stroke="#9aa1b2"] { stroke: var(--muted); }
.diagram [fill="#5b6478"], .diagram [fill="#9aa1b2"] { fill: var(--muted); }
.diagram [stroke="#2f5bd3"] { stroke: var(--accent); }
.diagram [fill="#2f5bd3"] { fill: var(--accent); }
.diagram [fill="#eef3ff"] { fill: var(--accent-tint); }
.diagram [stroke="#1f7a5a"] { stroke: var(--good); }
.diagram [fill="#1f7a5a"] { fill: var(--good); }
.diagram [stroke="#b3261e"] { stroke: var(--bad); }
.diagram [fill="#b3261e"] { fill: var(--bad); }
.diagram [stroke="#b4572e"] { stroke: var(--amber-ink); }
.diagram [fill="#b4572e"] { fill: var(--amber-ink); }

/* ---------- Boxes ---------- */
/* Three roles (DESIGN.md): neutral (story, key idea, worked example), amber (exam tip,
   watch out) and the book colour (Year 11, Year 12). A full soft tint, no side stripe. */
.box { border-radius: var(--r-md); padding: var(--s-4) var(--s-5) var(--s-1); margin: var(--s-5) 0; background: var(--tint-neutral); }
.box-label { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-1) var(--s-3); margin-bottom: var(--s-2); }
.box-kind { font: 600 var(--t-label) var(--font-head); color: var(--muted); }
.box-title { font-family: var(--font-head); font-weight: 600; font-size: var(--t-body); }
.box-body > :last-child { margin-bottom: var(--s-3); }
.box code { background: var(--bg); }
.box-tip, .box-mistake { background: var(--amber-bg); }
.box-tip .box-kind, .box-mistake .box-kind { color: var(--amber-ink); }
.box-depth { background: var(--accent-tint); }
.box-depth .box-kind { color: var(--on-accent); background: var(--accent); padding: 2px var(--s-2); border-radius: var(--r-pill); }

/* ---------- Mind map ---------- */
.mindmap { margin: var(--s-5) 0; padding: var(--s-5) var(--s-4); background: var(--surface); border-radius: var(--r-md); }
.mm-root {
  display: table; margin: 0 auto; padding: var(--s-2) var(--s-5); border-radius: var(--r-pill); background: var(--ink); color: var(--bg);
  font-family: var(--font-head); font-weight: 600; position: relative; text-align: center;
}
.mm-root::after { content: ""; position: absolute; left: 50%; top: 100%; height: 18px; border-left: 2px solid var(--line); }
.mm-branches { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: var(--s-3); margin-top: 18px; padding-top: var(--s-4); border-top: 2px solid var(--line); }
.mm-branch { --c: var(--accent); --c-ink: var(--on-accent); position: relative; }
.mm-branch::before { content: ""; position: absolute; left: 50%; top: calc(-1 * var(--s-4)); height: var(--s-4); border-left: 2px solid var(--line); }
.mm-branch:nth-child(3n+2) { --c: var(--accent-mid); --c-ink: var(--ink); }
.mm-branch:nth-child(3n+3) { --c: var(--accent-tint); --c-ink: var(--ink); }
.mm-branch:nth-child(3n+3) .mm-node { box-shadow: inset 0 0 0 1.5px var(--accent); }
.mm-node { background: var(--c); color: var(--c-ink); border-radius: var(--r-md); padding: var(--s-2) var(--s-3); font-family: var(--font-head); font-weight: 600; font-size: var(--t-small); text-align: center; }
.mindmap ul { list-style: none; margin: var(--s-2) 0 0; padding: 0 0 0 var(--s-3); border-left: 2px solid var(--accent-mid); }
.mindmap ul ul { margin-top: var(--s-1); border-left-style: dashed; }
.mindmap li { font-size: var(--t-small); line-height: 1.4; padding: 3px 0 3px var(--s-1); color: var(--ink); }
.mindmap li > span { display: inline-block; }
.mindmap ul ul li { color: var(--muted); }

/* ---------- Quiz ---------- */
.prose .quiz-list { list-style: none; counter-reset: q; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.q { counter-increment: q; padding: var(--s-5) 0; border-bottom: 1px solid var(--line); }
.q-text { font-weight: 700; margin-bottom: var(--s-3); }
.q-text::before { content: counter(q) ". "; color: var(--accent); font-family: var(--font-head); }
.lvl-tag { font: 600 var(--t-label) var(--font-head); background: var(--accent); color: var(--on-accent); padding: 1px var(--s-2); border-radius: var(--r-pill); vertical-align: 2px; }
.opts { display: grid; gap: var(--s-2); }
.opt {
  display: flex; gap: var(--s-3); align-items: flex-start; text-align: left; width: 100%; min-height: var(--tap); cursor: pointer;
  background: var(--bg); border: 1.5px solid var(--line); border-radius: var(--r-md); padding: var(--s-2) var(--s-3);
  font: inherit; color: var(--ink);
}
.opt:hover:not([aria-disabled="true"]) { border-color: var(--accent); }
.opt-letter { flex: none; width: var(--s-5); height: var(--s-5); border-radius: 50%; background: var(--tint-neutral); display: grid; place-items: center; font: 600 var(--t-label) var(--font-head); margin-top: 1px; }
.opt[aria-disabled="true"] { cursor: default; }
.opt.is-right { border-color: var(--good); background: var(--good-tint); }
.opt.is-right .opt-letter { background: var(--good); color: var(--on-accent); }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-tint); }
.opt.is-wrong .opt-letter { background: var(--bad); color: var(--on-accent); }
.explain { margin-top: var(--s-3); padding: var(--s-3) var(--s-4); background: var(--tint-neutral); border-radius: var(--r-md); font-size: var(--t-small); }
.explain-verdict { margin: 0 0 var(--s-1); font-family: var(--font-head); font-weight: 600; }
.q.got-it .explain-verdict { color: var(--good); }
.q.missed .explain-verdict { color: var(--bad); }

/* Progress bar: pinned under the site header while the quiz is on screen. */
.quiz-bar {
  position: sticky; top: calc(var(--tap) + var(--s-2) + 1px); z-index: 10;
  margin: 0 0 var(--s-3); padding: var(--s-2) var(--s-4); background: var(--bg); border-bottom: 1px solid var(--line);
  font: 600 var(--t-label) var(--font-head); font-variant-numeric: tabular-nums;
}
.qb-note { color: var(--muted); font-weight: 600; }

/* Result card: the one card on a chapter page. */
.quiz-result { margin-top: var(--s-5); padding: var(--s-5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: 0 4px 16px color-mix(in srgb, var(--ink) 8%, transparent); }
.qr-score { margin: 0 0 var(--s-1); font-family: var(--font-head); font-weight: 600; font-variant-numeric: tabular-nums; }
.qr-pct { font-size: var(--t-display); font-weight: 700; line-height: 1.15; margin-right: var(--s-2); }
.qr-status { margin: 0 0 var(--s-4); font-family: var(--font-head); font-weight: 600; }
.quiz-result.is-done .qr-status { color: var(--good); }
.qr-missed p { margin: 0 0 var(--s-1); }
.qr-missed ul { list-style: none; padding: 0; margin: 0 0 var(--s-4); display: flex; flex-wrap: wrap; gap: var(--s-2); }
.qr-missed a { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); font: 600 var(--t-label) var(--font-head); text-decoration: none; }
.qr-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.quiz-result.is-rising { animation: qr-rise 320ms cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes qr-rise { from { opacity: 0.6; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.btn-primary { display: inline-flex; align-items: center; min-height: var(--tap); padding: var(--s-2) var(--s-5); border-radius: var(--r-md); text-align: left; background: var(--accent); color: var(--on-accent); font: 600 var(--t-label) var(--font-head); text-decoration: none; }
.btn-ghost { min-height: var(--tap); font: 600 var(--t-label) var(--font-head); background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 0 var(--s-4); border-radius: var(--r-md); cursor: pointer; }

/* "Show answer" fold-out, used only when JavaScript does not run. */
.q-answer { margin-top: var(--s-3); font-size: var(--t-small); }
.q-answer summary { display: inline-flex; align-items: center; min-height: var(--tap); cursor: pointer; font: 600 var(--t-label) var(--font-head); color: var(--accent); }
.q-answer p { margin: 0 0 var(--s-2); }
.js .q-answer { display: none; }
html:not(.js) .level-switch, html:not(.js) .quiz-bar, html:not(.js) .quiz-result, html:not(.js) .theme-btn { display: none; }
html.js .qg-nojs { display: none; }
html:not(.js) .opt { cursor: default; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Pager ---------- */
.pager { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s-3); margin-top: var(--s-7); padding-top: var(--s-3); border-top: 1px solid var(--line); }
.pager a { display: block; min-height: var(--tap); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); text-decoration: none; color: var(--ink); font-family: var(--font-head); font-weight: 600; transition: background-color .12s; }
.pager a:hover { background: var(--tint-neutral); }
.pager small { display: block; color: var(--muted); font-weight: 600; font-size: var(--t-label); }
.pager .prev { grid-column: 1; grid-row: 1; }
.pager .next { grid-column: 2; grid-row: 1; text-align: right; color: var(--accent); }
@media (max-width: 599px) {
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pager .prev, .pager .next { grid-column: auto; grid-row: auto; text-align: left; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 0 var(--s-4); }
  .chapter { margin-inline: auto; width: 100%; }
  .sidebar { position: static; max-height: none; padding: var(--s-3) 0 0; }
  .side-details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 0 var(--s-4); }
  .side-details[open] { padding-bottom: var(--s-3); }
  .site-head { padding: var(--s-1) var(--s-4); }
}
@media (max-width: 599px) {
  .ch-head .level-switch:not(.is-prompt) { display: grid; grid-template-columns: auto repeat(3, minmax(0, 1fr)); width: 100%; }
  .ch-head .level-switch:not(.is-prompt) .ls-label { padding: 0 var(--s-1) 0 var(--s-2); }
  .ch-head .level-switch button { padding: 0 var(--s-2); white-space: nowrap; }
}
/* "WhizzNotes" is 153px. Chapter headers also hold Chapters, Books, theme and account
   (about 272px), so under 470px the logo stays and the name is kept for screen readers
   only. Other pages hold Books, theme and account (about 160px): the name goes under 360px. */
@media (max-width: 469px) {
  .chapter-page .brand span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (max-width: 359px) {
  .brand span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (max-width: 379px) {
  .mm-branches { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}
@media print {
  .site-head, .sidebar, .level-switch, .pager, .toc, .site-foot, .skip-link, .quiz-bar, .quiz-result, .theme-btn, .chapters-btn, .chapters-sheet, .outline-col, .reset, .account-btn, .auth-dialog, .quiz-gate { display: none !important; }
  .layout { display: block; }
}

/* ---------- Book page: progress hub ---------- */
.book-hero .launch-btn { margin-bottom: var(--s-4); }
.book-hero h1 .book-mark { display: inline-grid; vertical-align: middle; margin-right: var(--s-2); }
.book-progress { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; margin: 0 0 var(--s-2); font: 600 var(--t-label) var(--font-head); font-variant-numeric: tabular-nums; }
.book-progress progress { width: min(320px, 100%); height: var(--s-2); appearance: none; border: 0; border-radius: var(--r-pill); background: var(--tint-neutral); overflow: hidden; accent-color: var(--accent); }
.book-progress progress::-webkit-progress-bar { background: var(--tint-neutral); }
.book-progress progress::-webkit-progress-value { background: var(--accent); border-radius: var(--r-pill); }
.book-progress progress::-moz-progress-bar { background: var(--accent); border-radius: var(--r-pill); }
.how-line { color: var(--muted); font-size: var(--t-small); margin: 0 0 var(--s-2); }
.btn-link { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0; border: 0; background: none; color: var(--muted); font: 600 var(--t-label) var(--font-head); text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer; }
.reset-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); background: var(--amber-bg); border-radius: var(--r-md); }
.reset-question { flex-basis: 100%; margin: 0; color: var(--amber-ink); font-family: var(--font-head); font-weight: 600; }
.unit.is-soon h2 { color: var(--muted); }
.soon { font: 600 var(--t-label) var(--font-head); color: var(--muted); }
.ch-state { margin-left: auto; padding-left: var(--s-2); font: 600 var(--t-label) var(--font-head); color: var(--muted); white-space: nowrap; }
li.is-done .ch-state { color: var(--good); }
.side-nav li.current .ch-state { color: var(--on-accent); }

/* ---------- Chapter header and outline ---------- */
.ch-meta { margin: 0 0 var(--s-4); color: var(--muted); font-size: var(--t-small); font-variant-numeric: tabular-nums; }
.ch-meta a { display: inline-flex; align-items: center; min-height: var(--tap); margin-block: calc((var(--tap) - 1.5em) / -2); font-weight: 700; }
.outline-col { display: none; }
@media (min-width: 1200px) {
  .layout { grid-template-columns: 260px minmax(0, var(--measure)) 220px; max-width: 1280px; }
  .outline-col { display: block; }
  .outline { position: sticky; top: 70px; padding: var(--s-5) 0; font-size: var(--t-small); }
  .outline-title { font: 600 var(--t-label) var(--font-head); color: var(--muted); margin: 0 0 var(--s-2); }
  .outline ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
  .outline a { display: flex; align-items: center; min-height: var(--tap); padding: 0 var(--s-3); margin-left: -2px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; }
  .outline a:hover { color: var(--ink); }
  .outline a.is-active { color: var(--accent); border-left-color: var(--accent); }
  .toc { display: none; }
}

/* ---------- Header actions: Chapters button and sheet, theme button ---------- */
.head-actions { display: flex; align-items: center; gap: var(--s-2); }
.theme-btn { display: inline-grid; place-items: center; width: var(--tap); min-height: var(--tap); padding: 0; border: 0; border-radius: var(--r-md); background: transparent; color: var(--muted); cursor: pointer; transition: background-color .12s, color .12s; }
.theme-btn:hover { background: var(--tint-neutral); color: var(--ink); }
.theme-btn svg { display: none; }
.theme-btn[data-mode="auto"] [data-icon="auto"],
.theme-btn[data-mode="light"] [data-icon="light"],
.theme-btn[data-mode="dark"] [data-icon="dark"] { display: block; }
.chapters-btn { display: none; align-items: center; gap: var(--s-2); min-height: var(--tap); padding: 0 var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md); color: var(--ink); text-decoration: none; font: 600 var(--t-label) var(--font-head); }
/* ---------- Sign in ---------- */
/* Header account button: an icon on phones, icon and "Sign in" from 600px; the student's
   initial on a brand tile once signed in. Hidden until auth.js has started. */
.account-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-width: var(--tap); min-height: var(--tap); padding: 0 var(--s-2); border: 0; border-radius: var(--r-md); background: transparent; color: var(--muted); font: 600 var(--t-label) var(--font-head); cursor: pointer; transition: background-color .12s, color .12s; }
.account-btn:hover { background: var(--tint-neutral); color: var(--ink); }
.account-initial { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--r-pill); background: var(--brand); color: var(--on-brand); font: 700 var(--t-label) var(--font-head); }
.account-btn.is-signed-in .account-label { display: none; }
@media (max-width: 599px) { .account-label { display: none; } }

/* Where the quiz was, until the student signs in. */
.quiz-gate { margin: var(--s-4) 0 var(--s-6); padding: var(--s-5); border-radius: var(--r-md); background: var(--tint-neutral); }
.quiz-gate p { margin: 0 0 var(--s-3); }
.quiz-gate .qg-title { font: 600 var(--t-h3) var(--font-head); }
.quiz-gate .qg-status:empty, .quiz-gate .qg-actions:has(> [hidden]:only-child) { display: none; }
.quiz-gate .qg-status, .quiz-gate .qg-nojs { color: var(--muted); font-size: var(--t-small); }

/* Sign in and account dialog: centred, one column, every control at least 44px. */
.auth-dialog { width: min(420px, calc(100vw - 2 * var(--s-4))); max-height: calc(100dvh - 2 * var(--s-4)); padding: var(--s-4) var(--s-5) var(--s-5); border: 0; border-radius: var(--r-lg); background: var(--bg); color: var(--ink); overflow-y: auto; }
.auth-dialog::backdrop { background: color-mix(in srgb, var(--ink) 40%, transparent); }
.signin-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.signin-head h2 { margin: 0; font-size: var(--t-h3); }
.auth-dialog p { margin: 0 0 var(--s-4); }
.signin-why, .signin-note { color: var(--muted); font-size: var(--t-small); }
.signin-google, .signin-submit, .signin-signout { width: 100%; justify-content: center; text-align: center; }
.signin-or { display: flex; align-items: center; gap: var(--s-3); margin: var(--s-4) 0 !important; color: var(--muted); font-size: var(--t-small); }
.signin-or::before, .signin-or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.signin-field { display: grid; gap: var(--s-1); margin-bottom: var(--s-3); font: 600 var(--t-label) var(--font-head); }
.signin-field[hidden] { display: none; }
.signin-field input { min-height: var(--tap); padding: 0 var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); color: var(--ink); font: 400 var(--t-body) var(--font-body); }
.signin-field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.signin-error { min-height: 0; color: var(--bad); font-size: var(--t-small); }
.signin-error:empty { display: none; }
.signin-error.is-info { color: var(--ink); }
.signin-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 var(--s-4); margin: var(--s-2) 0 0 !important; }
.auth-dialog button:disabled { opacity: .6; cursor: progress; }

.chapters-sheet { scrollbar-width: thin; scrollbar-color: var(--line) transparent; width: min(480px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; padding: 0 var(--s-4) var(--s-5); border: 0; background: var(--bg); color: var(--ink); overflow-y: auto; }
.chapters-sheet::backdrop { background: color-mix(in srgb, var(--ink) 40%, transparent); }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) 0; background: var(--bg); border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: var(--t-h3); }
@media (max-width: 900px) {
  .chapters-btn { display: inline-flex; }
  .sidebar { display: none; }
}
