/* main.css — the single stylesheet of the site.
   Local: colour tokens (light + dark), typography, chapter layout, figures, dashboard grid, tooltips, widgets.
   Global: every page links this file; figure renderers read the same tokens (via getComputedStyle) so canvas
   heatmaps and Plotly charts match the page in both themes.
   Sources: prefers-color-scheme (https://developer.mozilla.org/docs/Web/CSS/@media/prefers-color-scheme);
   CSS grid auto-fill (https://developer.mozilla.org/docs/Web/CSS/grid-template-columns). */

:root {
  --bg: #fbfaf7;            /* page background */
  --bg-soft: #f2f0ea;       /* panels, code */
  --card: #ffffff;          /* figure cards */
  --ink: #1d1d1f;           /* body text */
  --ink-soft: #5b5b63;      /* secondary text */
  --line: #e2dfd6;          /* borders */
  --accent: #b4532a;        /* links, highlights (terracotta) */
  --accent-soft: #f6e3d8;
  --train: #2b6cb0;         /* training-set colour used in every chart */
  --test: #c0392b;          /* test-set colour */
  --restricted: #2f855a;    /* restricted loss */
  --excluded: #805ad5;      /* excluded loss */
  --phase1: rgba(43, 108, 176, 0.07);  /* memorisation band */
  --phase2: rgba(128, 90, 213, 0.08);  /* circuit-formation band */
  --phase3: rgba(47, 133, 90, 0.08);   /* cleanup band */
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161a; --bg-soft: #1d1f24; --card: #1b1d22; --ink: #ebeaf0; --ink-soft: #a3a3ad; --line: #2e3038;
    --accent: #f0915f; --accent-soft: #3a2a22; --train: #6aa6ec; --test: #f07a6c; --restricted: #63c995; --excluded: #b49af0;
    --phase1: rgba(106, 166, 236, 0.10); --phase2: rgba(180, 154, 240, 0.10); --phase3: rgba(99, 201, 149, 0.10);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15161a; --bg-soft: #1d1f24; --card: #1b1d22; --ink: #ebeaf0; --ink-soft: #a3a3ad; --line: #2e3038;
  --accent: #f0915f; --accent-soft: #3a2a22; --train: #6aa6ec; --test: #f07a6c; --restricted: #63c995; --excluded: #b49af0;
  --phase1: rgba(106, 166, 236, 0.10); --phase2: rgba(180, 154, 240, 0.10); --phase3: rgba(99, 201, 149, 0.10);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 5rem; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.65 var(--sans); }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 0.88em; }
code { background: var(--bg-soft); padding: 0.1em 0.3em; border-radius: 4px; }
/* long formulas and code blocks scroll sideways inside their own box instead of being cut off on phones
   (KaTeX docs suggest `.katex-display { overflow: auto hidden }`: https://katex.org/docs/issues#css-customization) */
.katex-display, pre { overflow: auto hidden; }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 2.1rem; margin: 0.2em 0 0.3em; letter-spacing: -0.01em; }
h2 { font-size: 1.45rem; margin-top: 2.4em; border-top: 1px solid var(--line); padding-top: 1.2em; }
h3 { font-size: 1.12rem; margin-top: 1.8em; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 1.5rem; padding: 0.6rem 1.2rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand span { color: var(--accent); }
.topnav { display: flex; gap: 1.1rem; flex-wrap: wrap; font-size: 0.93rem; }
.topnav a { color: var(--ink-soft); text-decoration: none; }
.topnav a[aria-current="page"], .topnav a:hover { color: var(--ink); }
.theme-toggle { margin-left: auto; background: none; border: 1px solid var(--line); color: var(--ink); border-radius: 6px; cursor: pointer; padding: 0.15rem 0.5rem; }

/* ---------- chapters ---------- */
.chapter-layout { display: grid; grid-template-columns: minmax(0, 15rem) minmax(0, 1fr); gap: 2.5rem; max-width: 76rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.toc { position: sticky; top: 4.2rem; align-self: start; max-height: calc(100vh - 5rem); overflow: auto; font-size: 0.86rem; }
.toc-title { font-weight: 600; margin: 0 0 0.4rem; }
.toc ol { padding-left: 1.4rem; margin: 0; }
.toc li { margin: 0.2rem 0; color: var(--ink-soft); }
.toc li a { color: var(--ink-soft); text-decoration: none; }
.toc li.current a { color: var(--accent); font-weight: 600; }
.chapter { max-width: 48rem; min-width: 0; }
.kicker { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; color: var(--ink-soft); margin: 0; }
.lede { font-size: 1.12rem; color: var(--ink-soft); }
.chapter-sources { font-size: 0.85rem; color: var(--ink-soft); margin: 0.5rem 0 1.5rem; }
.prevnext { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.page { max-width: 52rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.page a, .chapter p a { overflow-wrap: anywhere; }  /* long bare URLs (reference list) wrap instead of widening phones */

/* defined terms, term uses, symbols */
dfn.term { font-style: normal; font-weight: 650; background: var(--accent-soft); padding: 0 0.15em; border-radius: 3px; }
.term { border-bottom: 1px dotted var(--accent); cursor: help; }
.sym { cursor: help; border-bottom: 1px dotted var(--ink-soft); }
.num { font-variant-numeric: tabular-nums; font-weight: 600; }

/* callouts */
.callout { border-left: 3px solid var(--accent); background: var(--bg-soft); padding: 0.8rem 1rem; margin: 1.4rem 0; border-radius: 0 6px 6px 0; }
.callout.example { border-color: var(--train); }
.callout.nuance { border-color: var(--excluded); }
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout-title { font-weight: 650; display: block; margin-bottom: 0.3rem; }
blockquote.quote { margin: 1.4rem 0; padding: 0.6rem 1rem; border-left: 3px solid var(--ink-soft); color: var(--ink); background: var(--card); font-style: italic; }
q.quote-inline { font-style: italic; }
q.quote-inline::before { content: "“"; } q.quote-inline::after { content: "”"; }
.quote-cite { font-size: 0.82em; color: var(--ink-soft); }
blockquote.quote cite { display: block; font-style: normal; font-size: 0.82rem; color: var(--ink-soft); margin-top: 0.3rem; }
.objectbox { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 1rem 1.2rem; margin: 1.5rem 0; overflow-x: auto; }
.symtable { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.symtable td { border-top: 1px solid var(--line); padding: 0.35rem 0.5rem; vertical-align: top; }
.symtable td:first-child { white-space: nowrap; width: 1%; }
table { border-collapse: collapse; margin: 1rem 0; font-size: 0.9rem; display: block; overflow-x: auto; }
th, td { border: 1px solid var(--line); padding: 0.3rem 0.6rem; text-align: left; }
th { background: var(--bg-soft); }

/* ---------- figures ---------- */
.fig { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0.9rem 1rem 0.6rem; margin: 1.6rem 0; min-width: 0; position: relative; }
/* ⤢ enlarge button (web/js/ui/expand.js); hidden in ?still=1 captures */
.fig-expand { position: absolute; top: 0.55rem; right: 0.6rem; font: inherit; font-size: 0.95rem; line-height: 1; background: transparent; color: var(--ink-soft); border: 1px solid transparent; border-radius: 6px; padding: 0.15rem 0.35rem; cursor: pointer; opacity: 0.6; }
.fig:hover .fig-expand, .fig-expand:focus-visible { opacity: 1; border-color: var(--line); }
.fig figcaption { padding-right: 2rem; } /* room for the button */
html.still .fig-expand, .fig-modal .fig-expand { display: none; }
.fig-modal { position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, 0.55); display: flex; align-items: center; justify-content: center; padding: 1.5vh 2vw; }
.fig-modal-box { position: relative; background: var(--card); width: min(1500px, 96vw); max-height: 100%; overflow: auto; border-radius: 12px; padding: 0.4rem; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); }
.fig-modal-close { position: sticky; top: 0.3rem; float: right; z-index: 2; }
.fig-modal .fig { margin: 0; border: none; }
.fig-modal .heatmap-stage { width: min(100%, 72vh) !important; } /* enlarged grids, still fitting the screen */
.fig-modal .fig-body > .plot { height: min(62vh, 640px) !important; }
body.modal-open { overflow: hidden; }
@media (max-width: 52rem) { .fig-modal { padding: 0; } .fig-modal-box { width: 100vw; height: 100%; border-radius: 0; } }
.anim-bar:empty { display: none; }
/* large figures break out of the 48rem text column to 62rem, but only where the window has room for it */
@media (min-width: 80rem) { .chapter .fig.l, .chapter .fig.xl { margin-left: calc((48rem - 62rem) / 2); margin-right: calc((48rem - 62rem) / 2); } }
.fig figcaption { margin-bottom: 0.4rem; }
.fig-title { margin: 0; font-size: 1rem; }
.fig-what { margin: 0.15rem 0 0; font-size: 0.88rem; color: var(--ink-soft); }
.fig-body { min-height: 120px; position: relative; }
.fig-body .loading { color: var(--ink-soft); font-size: 0.85rem; }
.draw-error { color: var(--test); font-size: 0.85rem; }  /* a figure whose module threw (also caught by tests/test_site_browser.py) */
.fig-more { font-size: 0.86rem; color: var(--ink-soft); margin-top: 0.4rem; }
.fig-more summary { cursor: pointer; }
.fig-eq { overflow-x: auto; padding: 0.3rem 0; color: var(--ink); }
.fig-meta { font-size: 0.8rem; }
.fig-controls { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; font-size: 0.82rem; margin: 0.3rem 0; color: var(--ink-soft); }
.fig-controls input[type=range] { width: 10rem; }
.fig-note { font-size: 0.8rem; color: var(--ink-soft); margin: 0.2rem 0 0; }
.heatmap-wrap { display: flex; gap: 0.6rem; align-items: flex-start; flex-wrap: wrap; }
.heatmap-stage { position: relative; max-width: 100%; border: 1px solid var(--line); line-height: 0; } /* marks are placed in % of this box */
.heatmap-stage canvas { display: block; width: 100%; image-rendering: pixelated; cursor: crosshair; }
.grid-mark { position: absolute; box-sizing: border-box; outline: 1.5px solid var(--ink); pointer-events: none; } /* selected cell / column / row */
.grid-mark-step { outline: none; background: color-mix(in srgb, var(--accent) 55%, transparent); min-width: 2px; } /* current checkpoint column */
.small-multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.6rem; }
.small-multiples figure { margin: 0; font-size: 0.75rem; color: var(--ink-soft); }
.small-multiples canvas { width: 100%; height: auto; image-rendering: pixelated; border: 1px solid var(--line); }
.heads-grid { display: grid; grid-template-columns: auto repeat(3, minmax(0, 1fr)); gap: 0.35rem 0.5rem; align-items: center; } /* attention-heads-grid: heads × (to a, to b, to =) */
.heads-grid .fig-note { margin: 0; text-align: center; }
.heads-grid figure { margin: 0; }
.heads-grid canvas { width: 100%; image-rendering: pixelated; border: 1px solid var(--line); cursor: crosshair; display: block; }
.heads-grid figure.selected canvas, .small-multiples figure.selected canvas { outline: 2px solid var(--accent); outline-offset: 1px; } /* selected head / neuron */
.colorbar { display: flex; align-items: center; gap: 0.4rem; font-size: 0.75rem; color: var(--ink-soft); font-family: var(--mono); }
.colorbar canvas { width: 120px; height: 10px; border: 1px solid var(--line); }
.plot { width: 100%; min-height: 260px; position: relative; } /* positions the step cursor overlay */
.step-cursor { position: absolute; left: 0; width: 0; border-left: 2px dotted var(--accent); pointer-events: none; will-change: transform; }

/* ---------- dashboard ---------- */
.controlbar { position: sticky; top: 3rem; z-index: 25; background: var(--card); border-bottom: 1px solid var(--line); padding: 0.5rem 1.2rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.04); }
.cb-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; font-size: 0.9rem; }
.cb-row.small { font-size: 0.82rem; margin-top: 0.35rem; color: var(--ink-soft); }
.cb-row input[type=number] { width: 4.2rem; }
.cb-row select { max-width: min(16rem, 60vw); }  /* long run titles must not widen the page on phones */
.cb-row select, .cb-row input { font: inherit; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 5px; padding: 0.1rem 0.3rem; }
.scrubber-wrap { flex: 1 1 18rem; position: relative; min-width: 12rem; }
.scrubber-wrap input[type=range] { width: 100%; position: relative; z-index: 2; background: transparent; }
.phase-strip { position: absolute; left: 0; right: 0; top: 50%; height: 14px; transform: translateY(-50%); z-index: 1; border-radius: 4px; overflow: hidden; }
.phase-strip span { position: absolute; top: 0; bottom: 0; }
/* ::: scrolly — the block's first figure stays in view while its sections are read (chapter 5); only where the screen has room */
@media (min-width: 60rem) and (min-height: 850px) {
  .scrolly > .fig:first-child { position: sticky; top: 3.1rem; z-index: 6; margin-left: 0; margin-right: 0; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08); } /* in the text column */
  .scrolly > .fig:first-child :is(.fig-what, .fig-more, .fig-body > .fig-note) { display: none; } /* pinned: diagram, stage formula and player only */
  .scrolly > .fig:first-child .flow { max-height: 30vh; }
}
.phase-strip .pb-paper { width: 0; border-left: 2px dashed var(--ink); opacity: 0.7; } /* the paper's own phase boundaries */
/* dashboard hero (web/js/figures/hero.js): play button + narration, then four tiles (4 → 2 → 1 columns) */
.hero-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.9rem; margin-bottom: 0.6rem; }
.hero-play { font-weight: 600; padding: 0.3rem 0.9rem; border-color: var(--accent); }
.hero-say { margin: 0; flex: 1 1 20rem; font-size: 0.92rem; color: var(--ink); min-height: 1.4em; }
.hero-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.9rem; }
.hero-tile { min-width: 0; }
.hero-tile h4 { margin: 0 0 0.3rem; font-size: 0.86rem; color: var(--ink-soft); font-weight: 600; }
.hero-tile .heatmap-wrap { flex-direction: column; gap: 0.3rem; }
.hero-tile .fig-note { font-size: 0.76rem; }
.hero-ctl { font-size: 0.78rem; color: var(--ink-soft); display: block; margin-bottom: 0.3rem; }
.hero-ctl select { font: inherit; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 5px; }
.hero-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 0.3rem; }
.canvas-plot { display: block; width: 100%; }
.view3d { display: block; width: 100%; cursor: grab; touch-action: none; } /* 3D point clouds (web/js/viz/view3d.js) */
.view3d:active { cursor: grabbing; }
@media (max-width: 80rem) { .hero-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 40rem) { .hero-tiles { grid-template-columns: minmax(0, 1fr); } }
/* interference panel (web/js/figures/output.js): controls, then the waves beside the clock inset */
.interf-ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.8rem; margin-bottom: 0.3rem; }
.interf-ctl .hero-ctl { margin: 0; }
.interf-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 0.6rem; align-items: center; }
@media (max-width: 40rem) { .interf-row { grid-template-columns: minmax(0, 1fr); } }
/* ablation playground (web/js/figures/interventions.js) */
.abl-chips .chip { min-width: 2.1rem; padding: 0.05rem 0.3rem; }
.abl-chips .chip.key { border-width: 2px; font-weight: 700; }
.abl-row { display: flex; flex-wrap: wrap; gap: 0.8rem 1.4rem; align-items: flex-start; margin-top: 0.6rem; }
.abl-stats { min-width: 11rem; }
.cvp-profile { flex: 1 1 18rem; min-width: 0; } /* clock-vs-pizza profile beside its grid */
.abl-big { margin: 0.2rem 0 0; font-size: 1.15rem; font-weight: 600; font-family: var(--mono); }
/* forward-flow diagram (web/js/figures/flow.js) */
.flow { width: 100%; height: auto; display: block; }
.flow-edges path { fill: none; stroke: var(--line); stroke-width: 1.2; }
.flow-edges path.skip { stroke-dasharray: 4 3; }
.flow-pulse { fill: var(--accent); }
.flow-cell { transition: fill 0.35s; } /* values ease to the new input (no transition under reduced motion) */
.flow-nodes > :not(.clickable):not(.hover) { pointer-events: none; } /* clicks reach the stage zones underneath */
.flow-cell.clickable { cursor: pointer; }
.flow-box { fill: var(--bg-soft); stroke: var(--line); }
.flow-bar { transition: width 0.35s; }
.flow-bar.k0 { fill: var(--train); } .flow-bar.k1 { fill: var(--restricted); } .flow-bar.k2 { fill: var(--accent); }
.flow-text { font: 600 13px Inter, sans-serif; fill: var(--ink); }
.flow-small { font: 11px Inter, sans-serif; fill: var(--ink-soft); }
.flow-head { font: 600 12px Inter, sans-serif; fill: var(--ink-soft); }
.flow-marker { fill: var(--ink); }
.flow-zone { fill: transparent; cursor: pointer; }
.flow-zone:hover, .flow-zone.on { fill: color-mix(in srgb, var(--accent) 7%, transparent); }
.flow-eq { min-height: 1.5rem; }
/* player bar (web/js/ui/player-bar.js): full on the dashboard, compact in chapters, mini inside animated figures */
.player-bar { flex: 1 1 32rem; min-width: 0; }
.pb-main { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.5rem; }
.pb-main .scrubber-wrap { flex: 1 1 14rem; }
.pb-icon { padding: 0.15rem 0.4rem; font-size: 0.8rem; }
.pb-play { min-width: 2.4rem; }
.pb-label { font-size: 0.85rem; white-space: nowrap; }
.pb-speed { font: inherit; font-size: 0.82rem; }
.pb-range { position: absolute; bottom: -3px; height: 3px; background: var(--accent); border-radius: 2px; pointer-events: none; } /* the play range under the scrubber */
.pb-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.3rem; }
.chip { font: inherit; font-size: 0.74rem; background: transparent; color: var(--ink-soft); border: 1px solid var(--line); border-radius: 999px; padding: 0.05rem 0.55rem; cursor: pointer; }
.chip:hover, .chip.active { border-color: var(--accent); color: var(--ink); }
.chip.active { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.pb-help { font-size: 0.78rem; color: var(--ink-soft); margin-top: 0.3rem; }
.pb-help kbd { font-family: var(--mono); border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3rem; }
.player-bar.mini { margin-top: 0.4rem; }
.player-bar.mini .pb-label { font-size: 0.78rem; }
.pb-slot { flex: 1 1 20rem; display: flex; }
.btn { font: inherit; background: var(--bg-soft); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 0.15rem 0.6rem; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.status { font-size: 0.78rem; color: var(--ink-soft); }
.dashboard { max-width: 110rem; margin: 0 auto; padding: 1rem 1.2rem 3rem; }
.dash-intro p { max-width: 60rem; color: var(--ink-soft); }
.dash-group h2 { margin-top: 1.6em; }
.group-blurb { color: var(--ink-soft); max-width: 60rem; font-size: 0.93rem; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: 1rem; }
.panel-grid .fig { margin: 0; }
.panel-grid .fig.l { grid-column: span 2; }
.panel-grid .fig.xl { grid-column: 1 / -1; }
@media (max-width: 52rem) { .panel-grid .fig.l { grid-column: auto; } }

/* ---------- tooltip + tour ---------- */
.tooltip { position: fixed; z-index: 60; max-width: 22rem; background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.55rem 0.7rem; font-size: 0.84rem; line-height: 1.45; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); pointer-events: none; }
.tooltip .tt-term { font-weight: 650; display: block; }
.tooltip .tt-src { display: block; font-size: 0.74rem; color: var(--ink-soft); margin-top: 0.25rem; }
.tour { position: fixed; right: 1rem; bottom: 1rem; z-index: 50; max-width: 26rem; }
.tour-card { background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: 0.8rem 1rem; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); }
.tour-title { margin: 0.1rem 0 0.3rem; }
.tour-text { font-size: 0.9rem; }
.tour-buttons { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.fig.tour-focus { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ---------- widgets ---------- */
.widget { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0.9rem 1rem; margin: 1.5rem 0; }
.widget-title { font-weight: 650; margin: 0 0 0.4rem; }
.widget label { font-size: 0.88rem; color: var(--ink-soft); }
.widget .row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.widget svg { max-width: 100%; height: auto; }
.workings { font-family: var(--mono); font-size: 0.82rem; background: var(--bg-soft); padding: 0.6rem 0.8rem; border-radius: 6px; overflow-x: auto; white-space: pre-wrap; } /* keep line breaks, wrap long lines instead of hiding them */

/* ---------- landing ---------- */
.hero { max-width: 60rem; margin: 0 auto; padding: 3rem 1rem 1rem; }
.hero h1 { font-size: 2.6rem; }
.hero p { font-size: 1.15rem; color: var(--ink-soft); }
.cta { display: flex; gap: 1rem; flex-wrap: wrap; margin: 1.5rem 0; }
.cta a { padding: 0.6rem 1.1rem; border-radius: 8px; border: 1px solid var(--accent); text-decoration: none; font-weight: 600; }
.cta a.primary { background: var(--accent); color: var(--bg); }
.footer { border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 0.8rem; padding: 1rem 1.2rem 2rem; text-align: center; }

@media (max-width: 52rem) {
  .chapter-layout { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .toc { position: static; max-height: none; border-bottom: 1px solid var(--line); padding-bottom: 0.6rem; }
  .toc-title { cursor: pointer; }  /* collapsed <details> on phones: tap "Chapters" to open the list */
  body { font-size: 16px; }
  /* phones: the header scrolls away (nav on its own row) so only the compact control bar stays pinned */
  .topbar { position: static; flex-wrap: wrap; gap: 0.4rem 0.8rem; padding: 0.5rem 1rem; }
  .topnav { order: 3; width: 100%; gap: 0.3rem 0.9rem; }
  .controlbar { top: 0; padding: 0.4rem 1rem; }
  .cb-row.small { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.2rem; }  /* one swipeable row of pickers */
  .cb-row.small label, .cb-row.small .btn { flex: none; }
  #ctl-status { display: none; }
  .tour { left: 0.5rem; right: 0.5rem; bottom: 0.5rem; max-width: none; }
}

.tiles3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.6rem; } /* three heatmaps side by side (trig-outer-product) */
.tiles3 .heatmap-wrap { flex-direction: column; gap: 0.3rem; }
.mm { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; font-family: var(--mono); } /* matmul-anim widget */
.mm table { border-collapse: collapse; }
.mm td { border: 1px solid var(--line); padding: 0.2rem 0.5rem; text-align: right; min-width: 2rem; transition: background-color 0.3s; }
.mm td.mm-col { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.mm td.mm-row { outline: 2px solid var(--ink); outline-offset: -2px; }
.mm-op { font-size: 1.2rem; color: var(--ink-soft); }
.btn.sweep { padding: 0.05rem 0.45rem; font-size: 0.8rem; margin-left: -0.4rem; } /* ▶ next to a slider (widgets/basics.js sweep) */
/* in-chapter training scrubber (widget) */
.widget.chapter-scrubber { position: sticky; top: 3.1rem; z-index: 20; padding: 0.4rem 0.8rem; box-shadow: 0 4px 14px rgba(0,0,0,0.05); }

/* Reduced motion: readers who ask their system for less motion, and ?still=1 captures (core/motion.js), get end states
   instead of transitions and smooth scrolling. Source: https://developer.mozilla.org/docs/Web/CSS/@media/prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
html.still *, html.still *::before, html.still *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
