/* ==========================================================================
   Field Guide design system v2: light-first, vivid, motion-rich.
   Owned by the framework; chapter authors use classes and CSS variables,
   never edit this file.
   ========================================================================== */

@font-face { font-family: "Bricolage"; src: url("../../vendor/fonts/bricolage-grotesque-latin-standard-normal.woff2") format("woff2"); font-weight: 200 800; font-stretch: 75% 100%; font-display: swap; }
@font-face { font-family: "InterV"; src: url("../../vendor/fonts/inter-latin-wght-normal.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "InterV"; src: url("../../vendor/fonts/inter-latin-wght-italic.woff2") format("woff2"); font-weight: 100 900; font-style: italic; font-display: swap; }
@font-face { font-family: "JetBrainsV"; src: url("../../vendor/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2"); font-weight: 100 800; font-display: swap; }

:root {
  /* Paper (light) theme: the default */
  --bg: #f3f0ea;
  --bg-2: #ebe6dd;
  --surface: #ffffff;
  --surface-2: #f6f3ee;
  --line: #e3ddd2;
  --ink: #131a2e;
  --ink-2: #39415a;
  --muted: #868b99;

  --accent: #ef6f45;   /* coral: the policy / the model / main actor */
  --blue: #3d9cf0;     /* sky: reference model, data, baseline */
  --green: #22b07d;    /* reward, good outcome, correct */
  --violet: #7a5cff;   /* value function, latent, hidden state */
  --red: #ec4458;      /* penalty, failure, misalignment */
  --gold: #f1a92b;     /* KL, constraint, highlight */
  --teal: #12a9b5;     /* oversight, monitor, verifier */
  --pink: #ec5aa0;     /* humans, preferences, judges */

  --hero-ink: var(--ink);
  --glass: rgba(255, 255, 255, .72);
  --radius: 22px;
  --radius-sm: 14px;
  --shadow-sm: 0 1px 2px rgba(19, 26, 46, .05), 0 2px 8px rgba(19, 26, 46, .04);
  --shadow: 0 1px 2px rgba(19, 26, 46, .04), 0 8px 24px rgba(19, 26, 46, .06), 0 24px 56px rgba(19, 26, 46, .06);
  --shadow-lg: 0 2px 4px rgba(19, 26, 46, .04), 0 14px 36px rgba(19, 26, 46, .08), 0 40px 80px rgba(19, 26, 46, .10);
  --font-display: "Bricolage", "InterV", system-ui, sans-serif;
  --font-sans: "InterV", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --font-serif: var(--font-sans);
  --font-mono: "JetBrainsV", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --prose: 740px;
  --wide: 1180px;
  --topbar: 64px;
  --sidebar: 0px;
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

:root[data-theme="dark"] {
  --bg: #0c1020;
  --bg-2: #11162a;
  --surface: #161c31;
  --surface-2: #1d2440;
  --line: #2a3354;
  --ink: #eef1fa;
  --ink-2: #c2c8da;
  --muted: #7f88a3;
  --accent: #ff8458;
  --blue: #5fb4ff;
  --green: #3ddc9b;
  --violet: #9b84ff;
  --red: #ff5f72;
  --gold: #ffc14d;
  --teal: #34d0dc;
  --pink: #ff78bb;
  --glass: rgba(18, 23, 42, .72);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .3), 0 24px 60px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar) + 20px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-sans); font-size: 18px; line-height: 1.72; font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background-color .4s ease, color .4s ease;
}
a { color: var(--accent); text-decoration: none; background-image: linear-gradient(currentColor, currentColor); background-size: 0% 1.5px; background-position: 0 100%; background-repeat: no-repeat; transition: background-size .35s var(--ease-out); }
a:hover { background-size: 100% 1.5px; }
p a, li a { background-size: 100% 1px; background-image: linear-gradient(color-mix(in srgb, currentColor 40%, transparent), color-mix(in srgb, currentColor 40%, transparent)); }
p a:hover, li a:hover { background-image: linear-gradient(currentColor, currentColor); }
code, kbd, pre { font-family: var(--font-mono); font-size: .84em; font-variant-ligatures: none; }
:not(pre) > code { background: color-mix(in srgb, var(--violet) 9%, var(--surface)); color: color-mix(in srgb, var(--violet) 70%, var(--ink)); padding: .12em .42em; border-radius: 7px; }
pre {
  background: #121829; color: #e6e9f2; border-radius: var(--radius-sm); padding: 20px 22px; overflow-x: auto;
  line-height: 1.6; font-size: 14px; box-shadow: var(--shadow); position: relative;
}
pre::before { content: ""; position: absolute; top: 12px; left: 14px; width: 10px; height: 10px; border-radius: 50%; background: #ff5f57; box-shadow: 16px 0 #febc2e, 32px 0 #28c840; opacity: .9; }
pre code { display: block; padding-top: 14px; }
hr { border: 0; height: 1px; background: var(--line); margin: 3em 0; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
img { max-width: 100%; }

/* ---------- Ambient background ---------- */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 600px at 110% -10%, color-mix(in srgb, var(--blue) 10%, transparent), transparent 60%),
    radial-gradient(800px 600px at -10% 30%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 60%);
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar); z-index: 80;
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
  background: var(--glass); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  font-family: var(--font-sans); font-size: 14px; transition: transform .4s var(--ease-out);
}
.topbar.hide { transform: translateY(-100%); }
.topbar .brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-family: var(--font-display); font-weight: 700; font-size: 16px; background: none; white-space: nowrap; }
.topbar .mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); position: relative; overflow: hidden; flex: none; box-shadow: inset 0 -3px 0 rgba(0,0,0,.12); }
.topbar .mark i { position: absolute; width: 6px; height: 6px; background: #fff; top: 9px; border-radius: 1.5px; animation: blink 5s infinite; }
.topbar .mark i:first-child { left: 7px; } .topbar .mark i:last-child { right: 7px; }
.topbar .mark::after { content: ""; position: absolute; left: 6px; right: 6px; bottom: 6px; height: 4px; background: rgba(255,255,255,.75); border-radius: 2px; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
.topbar .crumb { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .crumb b { color: var(--ink); font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .tb-btn { height: 38px; padding: 0 14px; border-radius: 999px; }
.topbar .ring-wrap { display: inline-flex; flex: none; }
.topbar .ring { width: 38px; height: 38px; flex: none; }
.topbar .ring circle { fill: none; stroke-width: 3.5; }
.topbar .ring .bgc { stroke: var(--line); }
.topbar .ring .fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .2s; transform: rotate(-90deg); transform-origin: 50% 50%; }
.topbar .ring text { font: 600 10px var(--font-mono); fill: var(--ink-2); }
#read-progress { position: fixed; top: var(--topbar); left: 0; right: 0; height: 3px; z-index: 79; pointer-events: none; transition: top .4s var(--ease-out); }
body.bar-hidden #read-progress { top: 0; }
#read-progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--gold), var(--pink)); border-radius: 0 3px 3px 0; }

/* ---------- Drawer (chapters) ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(12, 16, 32, .35); backdrop-filter: blur(3px); z-index: 90; opacity: 0; pointer-events: none; transition: opacity .35s; }
.drawer {
  position: fixed; top: 10px; bottom: 10px; left: 10px; width: min(420px, calc(100vw - 20px)); z-index: 95;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 22px 18px 28px; overflow-y: auto;
  transform: translateX(calc(-100% - 20px)); transition: transform .55s var(--ease-out), visibility 0s .55s; font-family: var(--font-sans);
  visibility: hidden; /* closed drawer is off-canvas: keep it out of tab order and hit testing */
}
body.drawer-open .drawer { transform: none; visibility: visible; transition: transform .55s var(--ease-out); }
body.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }
.drawer h4 { font: 700 11px var(--font-sans); text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin: 18px 8px 10px; }
.drawer .d-title { font: 800 24px/1.1 var(--font-display); margin: 4px 8px 4px; letter-spacing: -.02em; }
.drawer .d-sub { color: var(--muted); font-size: 13.5px; margin: 0 8px 8px; line-height: 1.45; }
.drawer .d-home { display: inline-block; margin: 2px 8px 6px; padding: 6px 0; font-size: 13.5px; font-weight: 600; color: var(--accent); text-decoration: none; }
.drawer .d-home:hover { text-decoration: underline; }
.drawer ol, .drawer ul { list-style: none; margin: 0; padding: 0; }
.drawer li + li { margin-top: 4px; }
.drawer a.ch { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 9px 10px; border-radius: 14px; color: var(--ink); background: none; transition: background .2s, transform .25s var(--ease-out); }
.drawer a.ch:hover { background: var(--surface-2); transform: translateX(4px); }
.drawer a.ch.current { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.drawer a.ch .n { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font: 700 13px var(--font-mono); color: #fff; background: var(--c, var(--ink)); }
.drawer a.ch .t { font-size: 14.5px; font-weight: 600; line-height: 1.3; }
.drawer a.ch .ok { color: var(--green); font-weight: 700; }
.drawer .onpage a { display: block; padding: 6px 10px; color: var(--ink-2); font-size: 14px; border-radius: 9px; background: none; }
.drawer .onpage a:hover { background: var(--surface-2); }

/* ---------- Right rail (on this page) ---------- */
.rail { position: fixed; top: calc(var(--topbar) + 40px); right: 26px; width: 230px; z-index: 40; font-family: var(--font-sans); display: none; }
.rail h4 { font: 700 11px var(--font-sans); text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin: 0 0 10px 12px; }
.rail ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.rail li { margin: 0; }
.rail a { display: block; padding: 6px 0 6px 14px; margin-left: -2px; border-left: 2px solid transparent; color: var(--muted); font-size: 13.5px; line-height: 1.35; background: none; transition: color .2s, border-color .2s, transform .3s var(--ease-out); }
.rail a:hover { color: var(--ink); transform: translateX(3px); }
.rail a.active { color: var(--ink); border-left-color: var(--accent); font-weight: 600; }
.rail a.passed { color: var(--ink-2); }
@media (min-width: 1500px) { .rail { display: block; } }

/* ---------- Dock (chapter switcher) ---------- */
.dock {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 70;
  display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; height: 60px;
  background: #121829; border-radius: 20px; box-shadow: 0 10px 40px rgba(12, 16, 32, .35);
  transition: transform .5s var(--ease-out), opacity .4s;
}
.dock.hide { transform: translate(-50%, 130%); opacity: 0; }
.dock a {
  --s: 1; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  font: 700 12.5px var(--font-mono); color: #cfd5e6; background: #1f2740; position: relative;
  transform-origin: 50% 100%; transform: scale(var(--s)); transition: transform .18s ease-out, background .2s; margin: 0 calc((var(--s) - 1) * 14px);
}
.dock a:hover { background: var(--c, var(--accent)); color: #fff; }
.dock a.current { background: var(--accent); color: #fff; }
.dock a.read::after { content: ""; position: absolute; bottom: -6px; width: 4px; height: 4px; border-radius: 50%; background: #9aa3bb; }
.dock a .tip-d {
  position: absolute; bottom: calc(100% + 12px); left: 50%; transform: translateX(-50%) scale(calc(1 / var(--s))); transform-origin: 50% 100%;
  white-space: nowrap; background: #121829; color: #fff; font: 600 12.5px var(--font-sans); padding: 6px 10px; border-radius: 9px; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.dock a:hover .tip-d { opacity: 1; }
.dock .sep { width: 1px; align-self: stretch; background: #2c3550; margin: 4px 4px; }
@media (max-width: 760px) { .dock { display: none; } }

/* ---------- Layout ---------- */
main { padding: var(--topbar) 28px 140px; }
.prose { max-width: var(--prose); margin: 0 auto; }
.prose > * + * { margin-top: 1.1em; }
.wide { max-width: var(--wide); margin-left: auto; margin-right: auto; }
.prose .wide { width: min(var(--wide), calc(100vw - 56px)); position: relative; left: 50%; transform: translateX(-50%); }
@media (min-width: 1500px) { .prose .wide { width: min(var(--wide), calc(100vw - 560px)); } }
@media (max-width: 760px) {
  main { padding: var(--topbar) 16px 100px; }
  .prose .wide { width: calc(100vw - 32px); }
  body { font-size: 17px; }
  .topbar .crumb { display: none; }
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.12; letter-spacing: -.022em; color: var(--ink); font-weight: 750; }
h2 { font-size: clamp(1.9rem, 3.4vw, 2.6rem); margin-top: 3.4em !important; margin-bottom: .2em; position: relative; }
h2 .sec {
  display: grid; place-items: center; width: max-content; min-width: 2.1em; height: 2.1em; padding: 0 .55em; margin-bottom: .6em;
  font: 700 .36em var(--font-mono); letter-spacing: .02em; color: #fff; background: var(--accent); border-radius: .7em;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 35%, transparent);
}
h2::after { content: ""; display: block; height: 3px; width: 64px; margin-top: .45em; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--gold)); transform-origin: 0 50%; }
h3 { font-size: 1.45em; margin-top: 2.2em !important; font-weight: 700; }
h4 { font-size: 1.12em; margin-top: 1.8em !important; font-weight: 700; }
p.lead { font-size: 1.24em; line-height: 1.6; color: var(--ink-2); font-weight: 450; }
p { color: color-mix(in srgb, var(--ink) 88%, var(--muted)); }
.muted { color: var(--muted); }
.small { font-size: .85em; }
strong, b { color: var(--ink); font-weight: 650; }
ul, ol { padding-left: 1.3em; }
li + li { margin-top: .4em; }
li::marker { color: var(--accent); font-weight: 700; }
blockquote { margin: 1.8em 0; padding: .4em 0 .4em 1.2em; border-left: 4px solid var(--accent); font: 500 1.25em/1.5 var(--font-display); color: var(--ink); }
.split-line { overflow: hidden; display: block; padding-bottom: .1em; margin-bottom: -.1em; }

.c-accent { color: var(--accent); } .c-blue { color: var(--blue); } .c-green { color: var(--green); }
.c-violet { color: var(--violet); } .c-red { color: var(--red); } .c-gold { color: color-mix(in srgb, var(--gold) 78%, var(--ink)); }
.c-teal { color: var(--teal); } .c-pink { color: var(--pink); } .c-muted { color: var(--muted); }
b[class^="c-"], strong[class^="c-"] { color: inherit; }
b.c-accent, strong.c-accent { color: var(--accent); } b.c-blue, strong.c-blue { color: var(--blue); } b.c-green, strong.c-green { color: var(--green); }
b.c-violet, strong.c-violet { color: var(--violet); } b.c-red, strong.c-red { color: var(--red); } b.c-gold, strong.c-gold { color: color-mix(in srgb, var(--gold) 78%, var(--ink)); }
b.c-teal, strong.c-teal { color: var(--teal); } b.c-pink, strong.c-pink { color: var(--pink); }
.hl { background: linear-gradient(transparent 58%, color-mix(in srgb, var(--gold) 45%, transparent) 58%); padding: 0 .1em; }

/* ---------- Hero ---------- */
.hero { position: relative; min-height: min(94vh, 980px); display: flex; align-items: center; padding: 70px 0 90px; margin: 0 -28px; overflow: hidden; isolation: isolate; }
.hero .hero-bg { position: absolute; inset: 0; z-index: -1; }
.hero .hero-bg canvas, .hero .hero-bg svg { width: 100%; height: 100%; display: block; }
.hero .blobs { position: absolute; inset: -10%; z-index: -2; filter: blur(70px) saturate(1.2); opacity: .55; pointer-events: none; }
.hero .blobs i { position: absolute; border-radius: 50%; animation: drift 22s ease-in-out infinite alternate; }
.hero .blobs i:nth-child(1) { width: 46vw; height: 46vw; left: 48%; top: -6%; background: var(--accent); opacity: .55; }
.hero .blobs i:nth-child(2) { width: 38vw; height: 38vw; left: 62%; top: 34%; background: var(--blue); opacity: .5; animation-delay: -6s; }
.hero .blobs i:nth-child(3) { width: 30vw; height: 30vw; left: 30%; top: 50%; background: var(--violet); opacity: .32; animation-delay: -12s; }
@keyframes drift { 0% { transform: translate(0, 0) scale(1); } 50% { transform: translate(-6%, 8%) scale(1.12); } 100% { transform: translate(5%, -4%) scale(.94); } }
.hero::after { content: ""; position: absolute; inset: auto 0 0 0; height: 30%; background: linear-gradient(180deg, transparent, var(--bg)); z-index: -1; pointer-events: none; }
.hero .hero-text { position: relative; z-index: 2; max-width: var(--wide); margin: 0 auto; width: 100%; padding: 0 28px; pointer-events: none; }
.hero .hero-text > * { pointer-events: auto; }
.hero .kicker {
  display: inline-flex; align-items: center; gap: 10px; font: 600 13px var(--font-mono); color: var(--ink); letter-spacing: .06em; text-transform: uppercase;
  background: var(--glass); backdrop-filter: blur(10px); border: 1px solid var(--line); padding: 7px 14px 7px 8px; border-radius: 999px; box-shadow: var(--shadow-sm);
}
.hero .kicker::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 2.2s infinite; margin-left: 4px; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); } 50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--accent) 0%, transparent); } }
.hero h1 {
  font-size: clamp(2.9rem, 6.6vw, 6rem); line-height: 1; margin: .32em 0 .32em; letter-spacing: -.028em; font-weight: 800; max-width: 13ch;
  color: var(--hero-ink);
}
.hero h1 .char { display: inline-block; }
.hero h1 .word { display: inline-block; white-space: nowrap; }
.hero .subtitle { font-size: clamp(1.1rem, 1.6vw, 1.38rem); color: var(--ink-2); max-width: 620px; line-height: 1.55; font-weight: 450; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.hero .scroll-cue { position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 3; width: 26px; height: 42px; border: 2px solid var(--muted); border-radius: 14px; opacity: .7; }
.hero .scroll-cue::after { content: ""; position: absolute; left: 50%; top: 8px; width: 4px; height: 8px; margin-left: -2px; border-radius: 2px; background: var(--muted); animation: cue 1.8s infinite; }
@keyframes cue { 0% { transform: translateY(0); opacity: 1; } 80% { transform: translateY(14px); opacity: 0; } 100% { opacity: 0; } }
@media (max-width: 760px) { .hero { margin: 0 -16px; min-height: 88vh; } .hero .hero-text { padding: 0 18px; } }

.chip {
  display: inline-flex; align-items: center; gap: 7px; background: var(--surface); padding: 8px 14px; border-radius: 999px;
  color: var(--ink); font: 600 13.5px var(--font-sans); box-shadow: var(--shadow-sm); border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}

/* "In one breath" */
.tldr { background: var(--surface); border-radius: var(--radius); padding: 26px 28px 22px; box-shadow: var(--shadow); position: relative; overflow: hidden; margin-top: 0 !important; }
.tldr::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: linear-gradient(90deg, var(--accent), var(--gold), var(--green), var(--blue), var(--violet)); }
.tldr h5 { margin: 0 0 14px; font: 700 12px var(--font-sans); text-transform: uppercase; letter-spacing: .14em; color: var(--accent); display: flex; align-items: center; gap: 8px; }
.tldr h5::before { content: "⚡"; font-size: 15px; }
.tldr ul { list-style: none; padding: 0; margin: 0; counter-reset: tl; display: grid; gap: 10px; }
.tldr li { counter-increment: tl; position: relative; padding: 12px 14px 12px 52px; margin: 0 !important; background: var(--surface-2); border-radius: 14px; line-height: 1.55; font-size: .96em; }
.tldr li::before { content: counter(tl); position: absolute; left: 12px; top: 11px; width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; font: 700 13px var(--font-mono); color: #fff; background: var(--tc, var(--accent)); }
.tldr li:nth-child(5n+1) { --tc: var(--accent); } .tldr li:nth-child(5n+2) { --tc: var(--blue); } .tldr li:nth-child(5n+3) { --tc: var(--green); }
.tldr li:nth-child(5n+4) { --tc: var(--violet); } .tldr li:nth-child(5n+5) { --tc: var(--gold); }

/* ---------- Spotlight (applied by core.js) ---------- */
.spot { position: relative; isolation: isolate; }
.spot::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: 0; transition: opacity .3s; z-index: 1;
  background: radial-gradient(380px circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--c, var(--accent)) 12%, transparent), transparent 65%);
}
.spot:hover::after { opacity: 1; }
.tilt { transition: transform .5s var(--ease-out), box-shadow .3s; will-change: transform; }

/* ---------- Callouts ---------- */
.callout {
  --c: var(--accent); position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 26px 22px 84px; margin: 2em 0 !important; overflow: hidden;
}
.callout::before {
  content: var(--icon, "●"); position: absolute; left: 22px; top: 22px; width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center; font-size: 21px; line-height: 1; color: #fff; font-family: var(--font-sans); font-weight: 800;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 70%, #000)); box-shadow: 0 6px 16px color-mix(in srgb, var(--c) 35%, transparent);
}
.callout > .label { font: 700 12px var(--font-sans); text-transform: uppercase; letter-spacing: .14em; color: var(--c); margin-bottom: 6px; display: block; }
.callout > :last-child { margin-bottom: 0; }
.callout > p:first-of-type { margin-top: 0; }
.callout > .label + * { margin-top: 0; }
.callout.analogy   { --c: var(--gold);   --icon: "🎭"; background: linear-gradient(135deg, color-mix(in srgb, var(--gold) 15%, var(--surface)), color-mix(in srgb, var(--accent) 8%, var(--surface)) 75%); }
.callout.analogy > .label { color: color-mix(in srgb, var(--gold) 65%, var(--ink)); }
.callout.analogy p { font-size: 1.03em; }
.callout.keyidea   { --c: var(--accent); --icon: "◆"; background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 9%, var(--surface)), var(--surface) 60%); }
.callout.intuition { --c: var(--blue);   --icon: "💡"; }
.callout.pitfall   { --c: var(--red);    --icon: "!"; background: linear-gradient(135deg, color-mix(in srgb, var(--red) 7%, var(--surface)), var(--surface) 60%); }
.callout.anthropic { --c: var(--pink);   --icon: "✦"; background: linear-gradient(135deg, color-mix(in srgb, var(--pink) 9%, var(--surface)), var(--surface) 65%); }
.callout.mathbox   { --c: var(--violet); --icon: "∑"; }
.callout.frontier  { --c: var(--teal);   --icon: "↗"; background: linear-gradient(135deg, color-mix(in srgb, var(--teal) 9%, var(--surface)), var(--surface) 65%); }
.callout.question  { --c: var(--green);  --icon: "?"; }
.callout.history   { --c: var(--muted);  --icon: "⧗"; }
.callout.analogy::before, .callout.intuition::before, .callout.question::before { background: color-mix(in srgb, var(--c) 20%, var(--surface)); box-shadow: none; }
.callout.question::before { color: var(--c); font-size: 24px; }
@media (max-width: 600px) { .callout { padding: 72px 20px 20px; } .callout::before { left: 20px; top: 18px; width: 40px; height: 40px; } }

/* Big statement (optional for authors) */
.statement { font: 750 clamp(1.6rem, 3vw, 2.3rem)/1.18 var(--font-display); letter-spacing: -.025em; color: var(--ink); margin: 1.6em 0 !important; }
.statement em { font-style: normal; color: var(--accent); }

/* Stat tiles (optional for authors): <div class="stats"><div class="stat"><span class="v">42%</span><span class="k">label</span></div></div> */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin: 1.8em 0 !important; }
.stat { background: var(--surface); border-radius: var(--radius-sm); padding: 18px 18px 16px; box-shadow: var(--shadow-sm); font-family: var(--font-sans); }
.stat .v { display: block; font: 800 2.1rem/1 var(--font-display); letter-spacing: -.03em; color: var(--sc, var(--accent)); }
.stat:nth-child(4n+2) { --sc: var(--blue); } .stat:nth-child(4n+3) { --sc: var(--green); } .stat:nth-child(4n+4) { --sc: var(--violet); }
.stat .k { display: block; margin-top: 8px; font-size: 13.5px; color: var(--ink-2); line-height: 1.4; }

/* ---------- Annotated equations ---------- */
.eqx { margin: 2.2em 0 !important; border-radius: var(--radius); background: var(--surface); padding: 30px 26px 20px; box-shadow: var(--shadow); position: relative; }
.eqx::before { content: "EQUATION · hover the terms"; position: absolute; top: 14px; left: 22px; font: 700 10.5px var(--font-mono); letter-spacing: .12em; color: var(--muted); }
.eqx .tex { font-size: 1.22em; overflow-x: auto; overflow-y: hidden; padding: 16px 0 14px; text-align: center; }
.eqx .legend { list-style: none; padding: 0; margin: 10px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; font-size: .86em; font-family: var(--font-sans); }
.eqx .legend li { margin: 0; padding: 9px 12px; border-radius: 12px; background: var(--surface-2); cursor: default; transition: background .2s, transform .25s var(--ease-out), box-shadow .2s; line-height: 1.45; }
.eqx .legend li:hover, .eqx .legend li.hot { transform: translateY(-2px); background: color-mix(in srgb, var(--gold) 18%, var(--surface)); box-shadow: var(--shadow-sm); }
.eqx .tex .hot { background: color-mix(in srgb, var(--gold) 30%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 30%, transparent); border-radius: 6px; }
.eqx .tex [class^="t-"], .eqx .tex [class*=" t-"] { transition: background .2s, box-shadow .2s; border-radius: 5px; cursor: default; }

/* ---------- Widgets ---------- */
.widget {
  --c: var(--accent); margin: 2.6em 0 !important; border-radius: 26px; background: var(--surface);
  box-shadow: var(--shadow-lg); overflow: hidden; font-family: var(--font-sans); font-size: 14.5px; line-height: 1.5; position: relative;
}
.widget > .w-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px 6px; position: relative; z-index: 2; }
.widget > .w-head .w-title { font: 700 18px/1.25 var(--font-display); letter-spacing: -.01em; color: var(--ink); }
.widget > .w-head .w-tag {
  margin-left: auto; display: inline-flex; align-items: center; gap: 7px; font: 700 10.5px var(--font-mono); color: var(--accent);
  text-transform: uppercase; letter-spacing: .12em; background: color-mix(in srgb, var(--accent) 11%, var(--surface)); padding: 6px 11px; border-radius: 999px; white-space: nowrap;
}
.widget > .w-head .w-tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 2.2s infinite; }
.widget > .w-body { padding: 14px 22px 20px; position: relative; z-index: 2; }
.widget > .w-caption { margin: 0 !important; padding: 14px 22px 18px 50px; background: var(--surface-2); color: var(--ink-2); font-size: 14px; position: relative; line-height: 1.55; z-index: 2; }
.widget > .w-caption::before { content: "↳"; position: absolute; left: 24px; top: 13px; color: var(--accent); font-weight: 800; font-size: 16px; }
.widget .w-stage { width: 100%; position: relative; }
.widget svg { display: block; max-width: 100%; overflow: visible; }
.widget svg text { fill: var(--ink-2); font-family: var(--font-sans); font-size: 12px; }
.widget svg .axis path, .widget svg .axis line { stroke: var(--line); }
.widget svg .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font-mono); }
.widget svg .grid line { stroke: var(--line); stroke-opacity: .8; stroke-dasharray: 2 4; }
.widget .controls { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center; margin-top: 16px; padding: 14px 16px; background: var(--surface-2); border-radius: 16px; }
.widget .readouts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.widget .readout { background: var(--surface-2); border-radius: 14px; padding: 10px 14px 10px 17px; min-width: 120px; flex: 1 1 120px; position: relative; overflow: hidden; }
.widget .readout::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--rc, var(--accent)); }
.widget .readout:nth-child(4n+2) { --rc: var(--blue); } .widget .readout:nth-child(4n+3) { --rc: var(--green); } .widget .readout:nth-child(4n+4) { --rc: var(--violet); }
.widget .readout .k { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.widget .readout .v { font: 700 21px/1.2 var(--font-mono); color: var(--ink); letter-spacing: -.02em; display: inline-block; }
.widget .readout .v.bump { animation: bump .35s var(--ease-spring); }
@keyframes bump { 40% { transform: scale(1.08); color: var(--rc, var(--accent)); } }
.widget .note { color: var(--muted); font-size: 13px; }
.widget-error { padding: 14px 18px; color: var(--red); font-family: var(--font-mono); font-size: 13px; }
.widget .row { display: flex; gap: 18px; flex-wrap: wrap; }
.widget .col { flex: 1 1 280px; min-width: 0; }

/* Controls */
.ctl { display: flex; flex-direction: column; gap: 6px; min-width: 180px; flex: 1 1 180px; }
.ctl label { font-size: 13px; color: var(--ink-2); display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; }
.ctl label .val { font: 700 12px var(--font-mono); color: #fff; background: var(--accent); padding: 2px 9px; border-radius: 999px; }
input[type=range] { --p: 50%; -webkit-appearance: none; appearance: none; width: 100%; height: 24px; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--accent) var(--p), var(--line) var(--p)); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: #fff; margin-top: -7px; border: 0; box-shadow: 0 0 0 5px var(--accent), 0 4px 10px rgba(0,0,0,.2); transition: transform .2s var(--ease-spring); }
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.25); }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 4px solid var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
button, .btn {
  font: 650 13.5px var(--font-sans); cursor: pointer; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 16px; display: inline-flex; align-items: center; gap: 7px; line-height: 1.2;
  transition: background .2s, border-color .2s, color .2s, transform .25s var(--ease-spring), box-shadow .2s; box-shadow: var(--shadow-sm);
}
button:hover { border-color: var(--ink); transform: translateY(-1px); }
button:active { transform: translateY(1px) scale(.97); }
button.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
button.primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
button.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
select { font: 600 13.5px var(--font-sans); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; }
textarea, input[type=text], input[type=number] { font: 14px var(--font-mono); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.seg { display: inline-flex; flex-wrap: wrap; background: var(--surface); border-radius: 999px; padding: 4px; gap: 2px; box-shadow: inset 0 0 0 1px var(--line); }
.seg button { border: 0; box-shadow: none; background: transparent; padding: 7px 14px; }
.seg button:hover { transform: none; background: var(--surface-2); }
.seg button.on { background: var(--ink); color: var(--bg); }

/* Token strips */
.tokens { display: flex; flex-wrap: wrap; gap: 5px; font-family: var(--font-mono); font-size: 13px; font-variant-ligatures: none; }
.tok { padding: 4px 8px; border-radius: 8px; background: var(--surface-2); white-space: pre; transition: background .3s, color .3s, opacity .3s, transform .3s var(--ease-spring); box-shadow: inset 0 0 0 1px var(--line); }
.tok.sys { color: var(--muted); }
.tok.user { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--blue) 60%, transparent); background: color-mix(in srgb, var(--blue) 8%, var(--surface)); }
.tok.asst { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 60%, transparent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.tok.masked { opacity: .35; text-decoration: line-through; }
.tok.loss { background: var(--accent); color: #fff; box-shadow: none; }

/* ---------- Scrollytelling ---------- */
.scrolly { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.3fr); gap: 44px; margin: 3.4em auto !important; }
.scrolly .sticky { position: sticky; top: calc(var(--topbar) + 4vh); height: calc(92vh - var(--topbar)); display: flex; align-items: center; order: 2; }
.scrolly .steps { order: 1; padding: 34vh 0 44vh; }
.scrolly .sticky > .widget { width: 100%; margin: 0 !important; }
.scrolly > * { min-width: 0; }   /* a long equation in the sticky widget must not widen the grid column */
.scrolly .step { min-height: 62vh; display: flex; align-items: center; opacity: .3; transform: scale(.97); transition: opacity .5s, transform .6s var(--ease-out); }
.scrolly .step > div { background: var(--surface); border-radius: var(--radius); padding: 22px 26px; box-shadow: var(--shadow); position: relative; border: 2px solid transparent; transition: border-color .4s; }
.scrolly .step.active { opacity: 1; transform: none; }
.scrolly .step.active > div { border-color: var(--accent); }
@media (max-width: 1000px) {
  .scrolly { grid-template-columns: 1fr; gap: 0; }
  .scrolly .sticky { order: 0; top: var(--topbar); height: auto; z-index: 5; padding: 8px 0; background: linear-gradient(var(--bg) 85%, transparent); }
  .scrolly .steps { padding: 10vh 0; }
  .scrolly .step { min-height: 50vh; }
}

/* ---------- Paper cards ---------- */
.papers { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; margin: 1.8em 0 !important; }
.paper {
  --c: var(--blue); background: var(--surface); border-radius: 18px; padding: 20px 18px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
  font-family: var(--font-sans); font-size: 14px; line-height: 1.45; display: flex; flex-direction: column; gap: 7px;
}
.paper::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c); }
.paper:nth-child(5n+2) { --c: var(--violet); } .paper:nth-child(5n+3) { --c: var(--green); } .paper:nth-child(5n+4) { --c: var(--pink); } .paper:nth-child(5n+5) { --c: var(--teal); }
.paper .p-title { font: 700 15.5px/1.3 var(--font-display); color: var(--ink); background: none; position: relative; z-index: 2; }
.paper .p-title:hover { color: var(--accent); }
.paper .p-title::after { content: " ↗"; color: var(--muted); font-size: .85em; }
.paper .p-meta { font: 500 12px var(--font-mono); color: var(--muted); }
.paper .p-take { color: var(--ink-2); }
.paper .p-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.paper .p-tags span { font: 600 11px var(--font-sans); padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.paper.must { --c: var(--accent); box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.paper.must .p-meta::before { content: "MUST READ"; display: inline-block; margin-right: 8px; font: 800 9.5px var(--font-mono); letter-spacing: .1em; color: #fff; background: var(--accent); padding: 2px 7px; border-radius: 99px; vertical-align: 1px; }

/* ---------- Quiz & flashcards ---------- */
.quiz { background: var(--surface); border-radius: var(--radius); padding: 24px 26px; margin: 2.2em 0 !important; font-family: var(--font-sans); font-size: 15.5px; box-shadow: var(--shadow); position: relative; }
.quiz .q { font: 700 1.12em/1.4 var(--font-display); margin-bottom: 14px; color: var(--ink); }
.quiz .q::before { content: "✦ Check yourself"; display: block; margin-bottom: 8px; color: var(--green); font: 700 11px var(--font-mono); text-transform: uppercase; letter-spacing: .14em; }
.quiz .opts { display: grid; gap: 9px; counter-reset: opt; }
.quiz .opt { counter-increment: opt; text-align: left; font-weight: 550; justify-content: flex-start; line-height: 1.45; padding: 12px 16px 12px 14px; border-radius: 14px; background: var(--surface-2); border: 2px solid transparent; box-shadow: none; gap: 12px; color: var(--ink); }
.quiz .opt::before { content: counter(opt, upper-alpha); flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font: 700 12px var(--font-mono); background: var(--surface); color: var(--ink-2); box-shadow: var(--shadow-sm); }
.quiz .opt:hover { border-color: var(--ink); transform: translateX(3px); }
.quiz.answered .opt:hover { transform: none; border-color: transparent; }
.quiz .opt.right, .quiz.answered .opt.right:hover { border-color: var(--green); background: color-mix(in srgb, var(--green) 13%, var(--surface)); }
.quiz .opt.right::before { content: "✓"; background: var(--green); color: #fff; }
.quiz .opt.wrong, .quiz.answered .opt.wrong:hover { border-color: var(--red); background: color-mix(in srgb, var(--red) 10%, var(--surface)); animation: shake .45s; }
.quiz .opt.wrong::before { content: "✕"; background: var(--red); color: #fff; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.quiz .why { display: none; margin-top: 14px; padding: 14px 16px; background: color-mix(in srgb, var(--green) 8%, var(--surface-2)); border-radius: 14px; color: var(--ink-2); line-height: 1.6; }
.quiz.answered .why { display: block; animation: rise .5s var(--ease-out); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.confetti { position: fixed; width: 8px; height: 8px; border-radius: 2px; pointer-events: none; z-index: 300; }

.flashcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin: 2em 0 !important; }
.flashcard { perspective: 1100px; height: 210px; cursor: pointer; font-family: var(--font-sans); font-size: 14.5px; line-height: 1.45; }
.flashcard .fc-inner { position: relative; width: 100%; height: 100%; transition: transform .75s var(--ease-spring); transform-style: preserve-3d; }
.flashcard.flipped .fc-inner { transform: rotateY(180deg); }
.flashcard .fc-front, .flashcard .fc-back {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 20px;
  padding: 20px 20px 30px; display: flex; align-items: center; justify-content: center; text-align: center; overflow: auto; box-shadow: var(--shadow);
}
.flashcard .fc-front { --fc: var(--accent); background: linear-gradient(145deg, var(--fc), color-mix(in srgb, var(--fc) 62%, #1b1030)); color: #fff; font: 700 17px/1.3 var(--font-display); letter-spacing: -.01em; }
.flashcard .fc-front::after { content: "tap to flip ↻"; position: absolute; bottom: 12px; font: 600 10.5px var(--font-mono); opacity: .7; letter-spacing: .06em; }
.flashcard:nth-child(6n+2) .fc-front { --fc: var(--blue); } .flashcard:nth-child(6n+3) .fc-front { --fc: var(--violet); }
.flashcard:nth-child(6n+4) .fc-front { --fc: var(--green); } .flashcard:nth-child(6n+5) .fc-front { --fc: var(--pink); } .flashcard:nth-child(6n+6) .fc-front { --fc: var(--teal); }
.flashcard .fc-front .katex, .flashcard .fc-front code { color: #fff; background: rgba(255,255,255,.15); }
.flashcard .fc-back { background: var(--surface); transform: rotateY(180deg); color: var(--ink-2); font-size: 14px; padding-bottom: 20px; }

/* Q&A */
details.qa { background: var(--surface); border-radius: 18px; margin: .7em 0 !important; font-family: var(--font-sans); font-size: 15px; box-shadow: var(--shadow-sm); overflow: hidden; transition: box-shadow .25s; }
details.qa:hover, details.qa[open] { box-shadow: var(--shadow); }
details.qa > summary { cursor: pointer; padding: 16px 18px; font-weight: 650; list-style: none; display: flex; gap: 14px; align-items: flex-start; color: var(--ink); line-height: 1.45; }
details.qa > summary::-webkit-details-marker { display: none; }
details.qa > summary::before { content: "Q"; flex: none; width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--green) 15%, var(--surface)); color: var(--green); font: 800 13px var(--font-mono); transition: transform .5s var(--ease-spring), background .2s, color .2s; }
details.qa[open] > summary::before { content: "A"; background: var(--green); color: #fff; transform: rotate(360deg); }
details.qa > div { padding: 0 20px 18px 60px; color: var(--ink-2); line-height: 1.65; }
details.qa .level { margin-left: auto; flex: none; font: 700 10px var(--font-mono); color: var(--lc, var(--muted)); text-transform: uppercase; letter-spacing: .1em; padding: 4px 9px; border-radius: 99px; background: color-mix(in srgb, var(--lc, var(--muted)) 12%, var(--surface)); }

/* Glossary tooltip */
.term { border-bottom: 2px dotted color-mix(in srgb, var(--accent) 60%, transparent); cursor: help; }
.term:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.tip {
  position: absolute; z-index: 200; max-width: min(330px, calc(100vw - 16px)); background: #121829; color: #eef1fa; padding: 12px 14px; border-radius: 14px;
  box-shadow: var(--shadow-lg); font: 14px/1.5 var(--font-sans); pointer-events: none; animation: rise .25s var(--ease-out);
}
.tip .katex { color: #fff; }

/* Tables with "glass focus" */
table { border-collapse: separate; border-spacing: 0; width: 100%; font-family: var(--font-sans); font-size: 14.5px; margin: 1.8em 0 !important; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
th, td { padding: 12px 14px; text-align: left; vertical-align: top; line-height: 1.45; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
th { font: 700 11px var(--font-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); background: var(--surface-2); }
tbody tr { transition: opacity .3s, filter .3s; }
tbody:hover tr:not(:hover) { opacity: .5; filter: blur(.5px); }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.widget table { box-shadow: none; border-radius: 12px; }
.widget tbody:hover tr:not(:hover) { opacity: 1; filter: none; }
.table-wrap { overflow-x: auto; border-radius: 18px; margin: 1.8em 0 !important; box-shadow: var(--shadow); }
.table-wrap table { margin: 0 !important; box-shadow: none; }

figure { margin: 2.2em 0 !important; }
figcaption { font: 13.5px var(--font-sans); color: var(--muted); margin-top: 10px; }

/* Chapter navigation */
.chapter-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 5em !important; font-family: var(--font-sans); }
.chapter-nav > span { display: block; }
.chapter-nav a { border-radius: var(--radius); padding: 22px 24px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); font: 700 18px/1.3 var(--font-display); transition: transform .35s var(--ease-out), box-shadow .3s; }
.chapter-nav a:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.chapter-nav a small { display: block; color: var(--accent); font: 700 11px var(--font-mono); text-transform: uppercase; letter-spacing: .12em; margin-bottom: 6px; }
.chapter-nav a.next { text-align: right; background: #121829; color: #fff; }
.chapter-nav a.next small { color: var(--gold); }
@media (max-width: 600px) { .chapter-nav { grid-template-columns: 1fr; } }

/* ---------- Index: bento ---------- */
.bento { display: grid; grid-template-columns: repeat(6, 1fr); gap: 18px; margin-top: 1.4em !important; }
.card {
  --c: var(--accent); grid-column: span 2; background: var(--surface); border-radius: 26px; box-shadow: var(--shadow); color: var(--ink);
  font-family: var(--font-sans); display: flex; flex-direction: column; overflow: hidden; position: relative; transition: transform .45s var(--ease-out), box-shadow .3s;
}
a.card { background-image: none; }
.card:hover { transform: translateY(-6px); box-shadow: var(--shadow-lg); }
.card .art { height: 170px; position: relative; overflow: hidden; background: color-mix(in srgb, var(--c) 10%, var(--surface-2)); }
.card .art svg { width: 100%; height: 100%; display: block; }
.card .body { padding: 18px 22px 22px; display: flex; flex-direction: column; gap: 8px; flex: 1; position: relative; z-index: 2; }
.card .num { font: 700 12px var(--font-mono); color: var(--muted); letter-spacing: .06em; display: flex; gap: 8px; align-items: center; }
.card h3 { margin: 0 !important; font: 750 1.32em/1.15 var(--font-display); letter-spacing: -.02em; }
.card h3 .arrow { display: inline-block; color: var(--c); transition: transform .35s var(--ease-spring); }
.card:hover h3 .arrow { transform: translateX(6px); }
.card p { margin: 0; color: var(--ink-2); font-size: 14.5px; line-height: 1.5; }
.card .done { color: #fff; background: var(--green); font-size: 10.5px; padding: 2px 8px; border-radius: 99px; letter-spacing: .04em; }
.card.feature { grid-column: span 4; grid-row: span 2; }
.card.feature .art { height: auto; flex: 1; min-height: 300px; }
.card.feature h3 { font-size: 2em; }
.card.long { grid-column: span 4; }
.card.dark { background: #121829; color: #eef1fa; }
.card.dark p { color: #b8bfd3; } .card.dark h3 { color: #fff; } .card.dark .art { background: #1a2238; } .card.dark .num { color: #8d96b0; }
@media (max-width: 1000px) { .bento { grid-template-columns: repeat(2, 1fr); } .card, .card.feature, .card.long { grid-column: span 2; grid-row: auto; } .card.feature .art { min-height: 220px; } }
@media (min-width: 1001px) and (max-width: 1250px) { .bento { grid-template-columns: repeat(4, 1fr); } .card.feature { grid-column: span 4; } .card.long { grid-column: span 2; } }

/* Marquee of topics (index) */
.marquee { overflow: hidden; white-space: nowrap; mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent); -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent); }
.marquee .track { display: inline-flex; gap: 12px; animation: marquee 80s linear infinite; padding: 8px 0; }
.marquee:hover .track { animation-play-state: paused; }
@keyframes marquee { to { transform: translateX(-50%); } }

/* Motion helpers */
.reveal { opacity: 0; transform: translateY(26px); }
.no-motion .reveal, .no-js .reveal { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; } html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; }
}

/* Print */
@media print {
  .topbar, .dock, .rail, .drawer, .drawer-scrim, #read-progress, .hero .hero-bg, .hero .blobs, .chapter-nav, .scroll-cue { display: none !important; }
  main { padding: 0; } body::before { display: none; }
  .reveal { opacity: 1 !important; transform: none !important; }
  .scrolly { display: block; } .scrolly .sticky { position: static; height: auto; } .scrolly .step { min-height: 0; opacity: 1; }
}

/* Long display math scrolls instead of widening the page */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; max-width: 100%; }
.katex-display > .katex { white-space: nowrap; }

/* ==========================================================================
   Mobile layer. Phones: 390-430 px wide, touch, no hover.
   Breakpoints: 760px (layout, see above), 560px (narrow, G.NARROW), pointer: coarse (touch sizing).
   ========================================================================== */

/* Horizontal scrollers: edge fades while content is hidden on that side (classes set by core.js). */
.x-more-right { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); }
.x-more-left { -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px); mask-image: linear-gradient(90deg, transparent, #000 36px); }
.x-more-left.x-more-right { -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent); }
.katex-display.x-scroll, .eqx .tex.x-scroll { overscroll-behavior-x: contain; }

/* Guide.hscroll: a wide SVG (or any block) that scrolls sideways on narrow screens, with a swipe hint. */
.hscroll { position: relative; }
.hscroll-in { overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin; }
.hscroll-in > svg { max-width: none; }
.swipe-hint {
  position: absolute; right: 10px; bottom: 10px; z-index: 3; pointer-events: none; display: inline-flex; align-items: center; gap: 6px;
  font: 650 12px var(--font-sans); color: var(--ink-2); background: var(--glass); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; box-shadow: var(--shadow-sm); transition: opacity .4s;
}
.swipe-hint b { color: var(--accent); font-weight: 800; animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(4px); } }
.hscroll.scrolled .swipe-hint, .hscroll-in:not(.x-more-right) + .swipe-hint { opacity: 0; }

/* Touch: hover-only affordances get a tap equivalent. */
@media (hover: none) {
  .eqx::before { content: "EQUATION · tap the terms"; }
  .eqx .legend li { cursor: pointer; }
}

/* Touch sizing: every core control is at least 40 px tall. */
@media (pointer: coarse) {
  button, .btn, select { min-height: 40px; }
  .seg button { min-height: 40px; }
  input[type=range] { height: 40px; }
  input[type=range]::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -10px; }
  input[type=range]::-moz-range-thumb { width: 20px; height: 20px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  label:has(> input[type=checkbox]), label:has(> input[type=radio]) { min-height: 40px; }
  .eqx .legend li { min-height: 40px; }
  .paper .p-title { display: block; padding: 6px 0; margin: -6px 0; }
  .topbar .tb-btn { height: 40px; min-width: 40px; justify-content: center; }
  .chip a { display: inline-block; padding: 8px 2px; margin: -8px -2px; }
}

/* Narrow screens: give content the width, keep text at 12 px or more. */
@media (max-width: 560px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar .tb-btn { padding: 0 12px; }
  .topbar .tb-label { display: none; }
  .topbar .brand { min-width: 0; flex: 1 1 auto; gap: 8px; font-size: 15px; line-height: 1.12; white-space: normal; }
  .topbar .brand-t { min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .topbar .spacer { display: none; }

  .widget { border-radius: 20px; }
  .widget > .w-head { flex-wrap: wrap; gap: 6px 10px; padding: 14px 14px 4px; }
  .widget > .w-head .w-title { font-size: 17px; }
  .widget > .w-head .w-tag { font-size: 12px; letter-spacing: .06em; padding: 4px 10px; }
  .widget > .w-body { padding: 10px 12px 14px; }
  .widget > .w-caption { padding: 12px 14px 14px 36px; }
  .widget > .w-caption::before { left: 14px; top: 11px; }
  .widget .controls { padding: 12px; gap: 12px 16px; }
  .widget .readout { min-width: 0; flex-basis: 130px; padding: 8px 12px 8px 15px; }
  .widget .readout .v { font-size: 19px; }
  .ctl { min-width: 140px; }
  .seg { border-radius: 22px; }

  .quiz { padding: 20px 16px; }
  details.qa > summary { padding: 14px 14px; gap: 12px; }
  details.qa > div { padding: 0 16px 16px 16px; }
  .eqx { padding: 30px 16px 16px; }
  .eqx .legend { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .stat .v { font-size: 1.8rem; }
  .papers { grid-template-columns: 1fr; }
  .tldr { padding: 22px 16px 18px; }
  .tldr li { padding: 10px 12px 10px 48px; }

  /* 12 px floor for core-styled small text */
  details.qa .level, th, .paper .p-meta, .paper .p-tags span, .chapter-nav a small, .card .done, .drawer h4, .rail h4 { font-size: 12px; }
  .paper.must .p-meta::before { font-size: 11px; }
  h2 .sec { font-size: max(12px, .36em); }
  pre { font-size: 14.3px; }
  :not(pre) > code { font-size: max(12px, .84em); }
  .topbar .ring text { font-size: 11px; }
}

/* Collapsible evidence detail: who found what, for readers who want the debate */
details.deeper { background: var(--surface); border-radius: 14px; margin: .7em 0 !important; font-size: .94em; }
details.deeper > summary { cursor: pointer; padding: 12px 16px; font-weight: 650; list-style: none; display: flex; gap: 10px; align-items: center; color: var(--ink-2); min-height: 44px; box-sizing: border-box; }
details.deeper > summary::-webkit-details-marker { display: none; }
details.deeper > summary::before { content: "+"; flex: none; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; background: var(--line, rgba(0,0,0,.08)); font-weight: 700; }
details.deeper[open] > summary::before { content: "−"; }
details.deeper > div { padding: 0 16px 14px 16px; color: var(--ink-2); line-height: 1.6; }
