/* In the Studio — inthestudiobook.com
   Design language: the book cover (studio black, record-label orange,
   condensed display caps) over Palatino body text, matching the print
   edition's mathpazo typography. Dark is the default; light is one tap. */

@font-face {
  font-family: "Anton";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/anton-latin.woff2") format("woff2");
}

:root,
html[data-theme="dark"] {
  --topbar-h: 52px; /* refined at runtime by reader.js */
  --bg: #131110;
  --bg-soft: #1a1715;
  --panel: #1d1a17;
  --panel-2: #23201b;
  --ink: #ece7de;
  --ink-strong: #ffffff;
  --muted: #a89d8f;
  --accent: #f08122;
  --accent-ink: #17100a;
  --line: rgba(255, 255, 255, 0.11);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --fig-well: #ffffff;
}

html[data-theme="light"] {
  --bg: #faf7f1;
  --bg-soft: #f2ede4;
  --panel: #ffffff;
  --panel-2: #f7f2e9;
  --ink: #29241f;
  --ink-strong: #16120e;
  --muted: #70675c;
  --accent: #ad520a; /* >=4.5:1 on every light surface (WCAG AA) */
  --accent-ink: #ffffff;
  --line: rgba(40, 28, 16, 0.14);
  --shadow: 0 10px 26px rgba(60, 40, 20, 0.10);
  --fig-well: #ffffff;
}

* { box-sizing: border-box; }

::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  font-size: 1.0625rem;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 16px;
  z-index: 100;
}
.skip:focus { left: 12px; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--ink-strong); }

em em { font-style: normal; }

code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.bar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: baseline;
  gap: 18px;
}

.wordmark {
  font-family: "Anton", "Arial Narrow", sans-serif;
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.wordmark:hover { color: var(--accent); opacity: 0.85; }

.bar-sub {
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-links {
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: system-ui, sans-serif;
  font-size: 0.86rem;
}
.bar-links a { color: var(--ink); text-decoration: none; }
.bar-links a:hover { color: var(--accent); }

#themeToggle {
  display: flex;
  align-items: center;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
}
#themeToggle svg { width: 16px; height: 16px; display: block; }
html[data-theme="dark"] #themeToggle .ico-moon { display: none; }
html[data-theme="light"] #themeToggle .ico-sun { display: none; }
#themeToggle:hover { border-color: var(--accent); color: var(--accent); }

.search-open {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 500 0.84rem/1 system-ui, sans-serif;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
}
.search-open:hover { border-color: var(--accent); color: var(--accent); }
.search-open svg { width: 15px; height: 15px; }
.search-open kbd {
  font-family: ui-monospace, monospace;
  font-size: 0.7rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ---------- search modal ---------- */

.search-modal { position: fixed; inset: 0; z-index: 200; }
.search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
}
.search-box {
  position: relative;
  max-width: 640px;
  margin: 8vh auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.search-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.search-ic { width: 20px; height: 20px; color: var(--accent); flex: none; }
#searchInput {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink-strong);
  font: 1.1rem "Palatino Linotype", Palatino, Georgia, serif;
  outline: none;
}
.search-input-row kbd {
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 7px;
}
.search-results {
  max-height: 60vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.search-input-row:focus-within { box-shadow: inset 0 -2px 0 var(--accent); }
@media (max-width: 640px) {
  .search-box { margin: 6vh 12px 0; }
}
.search-hit {
  display: block;
  padding: 12px 20px;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
}
.search-hit:hover, .search-hit.active {
  background: var(--bg-soft);
  border-left-color: var(--accent);
}
.hit-crumb {
  display: block;
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 2px;
}
.hit-title {
  display: block;
  font-size: 1.02rem;
  color: var(--ink-strong);
  margin-bottom: 2px;
}
.hit-snip {
  display: block;
  font-family: system-ui, sans-serif;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.45;
}
.hit-snip mark, .search-hit mark {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--ink-strong);
  border-radius: 2px;
  padding: 0 1px;
}
.search-hint, .search-none {
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 18px 20px;
  margin: 0;
}

.progress { height: 3px; background: transparent; }
#progressBar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* ---------- layout ---------- */

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 80px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 60px;
}

article.chapter { max-width: 72ch; }

/* ---------- chapter hero ---------- */

.ch-hero { margin: 56px 0 40px; position: relative; }

/* record-sleeve ghost numeral behind each chapter opening */
.ch-hero[data-num]::before {
  content: attr(data-num);
  position: absolute;
  top: -0.28em;
  right: -0.04em;
  z-index: -1;
  font-family: "Anton", "Arial Narrow", sans-serif;
  font-size: clamp(9rem, 22vw, 15rem);
  line-height: 1;
  color: var(--ink-strong);
  opacity: 0.055;
  pointer-events: none;
  user-select: none;
}

.ch-eyebrow {
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 10px;
}

.ch-hero h1 {
  font-family: "Anton", "Arial Narrow", sans-serif;
  font-weight: 400;
  font-size: clamp(2.5rem, 6vw, 3.9rem);
  line-height: 1.04;
  letter-spacing: 0.012em;
  text-transform: uppercase;
  color: var(--ink-strong);
  margin: 0 0 14px;
}

.ch-meta {
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 26px;
}

.epigraph {
  margin: 0;
  padding: 6px 0 6px 22px;
  border-left: 3px solid var(--accent);
  font-style: italic;
  color: var(--muted);
}
.epigraph p { margin: 0 0 6px; font-size: 1.02rem; }
.epigraph cite,
.pull cite {
  font-style: normal;
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ---------- sections ---------- */

.sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 3.2rem 0 0.4rem;
  border-top: 1px solid var(--line);
  padding-top: 2.1rem;
}

.sec-head h2,
.panel-head h2 {
  font-size: 1.62rem;
  line-height: 1.25;
  color: var(--ink-strong);
  margin: 0;
}

.sec-head h2::before {
  content: "";
  display: block;
  width: 44px;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  margin-bottom: 14px;
}

.fix {
  font-family: system-ui, sans-serif;
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  opacity: 0.75;
}
.fix:hover { color: var(--accent); opacity: 1; }

h3 {
  font-size: 1.18rem;
  color: var(--ink-strong);
  margin: 2.1rem 0 0.3rem;
}

p { margin: 0.9rem 0; }

ul, ol { padding-left: 1.5rem; margin: 0.9rem 0; }
li { margin: 0.45rem 0; }
li::marker { color: var(--accent); font-weight: 700; }

/* definition terms */
.term {
  padding-left: 16px;
  border-left: 3px solid var(--accent);
  margin: 1.35rem 0;
}
.term-name { color: var(--ink-strong); }

/* mid-chapter quotes */
.pull {
  margin: 2.2rem 0;
  padding: 4px 0 4px 22px;
  border-left: 3px solid var(--accent);
  font-style: italic;
  color: var(--muted);
}
.pull p { margin: 0 0 6px; }

/* ---------- boxed features ---------- */

.chip {
  display: inline-block;
  font-family: system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 5px 12px;
  margin-bottom: 14px;
}

.objectives {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 26px 30px;
  margin: 2.6rem 0;
  box-shadow: var(--shadow);
}
.objectives .obj-intro { margin: 0 0 10px; font-style: italic; color: var(--muted); }
.objectives ul { margin: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 30px 34px;
  margin: 3rem 0;
  box-shadow: var(--shadow);
}
.panel-head { margin-bottom: 12px; }
.panel-head .chip { display: inline-block; }
.panel-head h2 { margin-top: 4px; }

.daw { background: var(--panel-2); }
.daw-outline { background: transparent; border-style: dashed; }
.callout {
  background: var(--panel-2);
  border-left: 4px solid var(--accent);
}
.panel .term { border-left-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.panel table { font-size: 0.86rem; }

/* ---------- "Hear It" audio demos ---------- */

.demo .chip { background: var(--ink-strong); color: var(--bg); }
.demo-note { color: var(--muted); margin-top: 0; }
.demo-play {
  font: 600 0.95rem/1 system-ui, sans-serif;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer;
  margin: 6px 0 14px;
}
.demo-play:hover { opacity: 0.9; }
.demo-play[aria-pressed="true"] { background: var(--ink-strong); color: var(--bg); }
.demo-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 10px 0;
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
}
.demo-row label { min-width: 92px; color: var(--muted); }
.demo-row output { min-width: 64px; color: var(--ink-strong); font-variant-numeric: tabular-nums; }
.demo-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.demo-choices { flex-wrap: wrap; gap: 8px; }
.demo-choice {
  font: 600 0.8rem/1 system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.demo-choice:hover { border-color: var(--accent); color: var(--accent); }
.demo-choice.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.demo-status {
  font-family: system-ui, sans-serif;
  font-size: 0.86rem;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 12px;
  margin-bottom: 0;
}

/* question mark-done checkboxes */
.qlist > li { position: relative; }
.qdone {
  position: absolute;
  left: -2.9rem;
  top: 0.15rem;
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
  cursor: pointer;
}
.qlist > li.done { opacity: 0.55; }
.qprog {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  color: var(--accent);
  margin: 6px 0 0;
}
.res-cta { margin-top: 4px; }

.ak-note {
  font-family: system-ui, sans-serif;
  font-size: 0.86rem;
  color: var(--muted);
  border-bottom: 1px dashed var(--line);
  padding-bottom: 14px;
}

.qlist { padding-left: 1.7rem; }
.qlist > li { margin: 0.9rem 0; padding-bottom: 0.9rem; border-bottom: 1px dashed var(--line); }
.qlist > li:last-child { border-bottom: none; }
.mc { list-style-type: lower-alpha; margin-top: 0.4rem; }
.mc li { margin: 0.15rem 0; }

.sc { font-variant: small-caps; letter-spacing: 0.03em; }

/* ---------- tables ---------- */

.tablewrap {
  margin: 2rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-family: system-ui, sans-serif;
  font-size: 0.92rem;
  line-height: 1.45;
}
thead th {
  text-align: left;
  color: var(--ink-strong);
  font-weight: 700;
  border-bottom: 2px solid var(--accent);
  padding: 10px 14px;
  vertical-align: bottom;
}
tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--panel) 55%, transparent); }
.table-cap {
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 10px 2px 0;
}

/* ---------- description lists ---------- */

.deflist { margin: 1.4rem 0; }
.deflist dt {
  font-weight: 700;
  color: var(--ink-strong);
  margin-top: 1rem;
}
.deflist .dl-letter {
  font-family: "Anton", "Arial Narrow", sans-serif;
  font-weight: 400;
  font-size: 1.9rem;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 4px;
  margin-top: 2.6rem;
}
.deflist dd {
  margin: 0.2rem 0 0;
  padding-left: 16px;
  border-left: 3px solid var(--accent);
}

/* glossary A-Z jump strip */
.az {
  position: sticky;
  top: calc(var(--topbar-h) + 8px);
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  margin: 1.6rem 0 0;
}
.az a {
  padding: 4px 8px;
  text-decoration: none;
  font-weight: 700;
  border-radius: 6px;
}
.az a:hover { background: var(--bg-soft); }

ol.alpha { list-style-type: lower-alpha; }
ol.alpha li::marker { color: var(--muted); font-weight: 400; }

/* ---------- display math ---------- */

.mathblock {
  margin: 1.8rem 0;
  padding: 16px 20px;
  text-align: center;
  font-size: 1.2rem;
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
}
.mathblock sub, .mathblock sup { font-size: 0.7em; }
.panel .mathblock { background: color-mix(in srgb, var(--bg) 40%, transparent); }

/* ---------- figures ---------- */

.fig {
  margin: 2.4rem 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.fig img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--fig-well);
  border-radius: 8px;
  padding: 14px;
  cursor: zoom-in;
}
/* Screenshots and photos are dark-UI images: in dark mode the white well
   becomes a glare halo, so frame rasters with a hairline instead. Line-art
   SVG diagrams keep the white well (their strokes need it). */
html[data-theme="dark"] .fig img:not([src$=".svg"]) {
  background: none;
  padding: 0;
  border: 1px solid var(--line);
}
.fig img + img { margin-top: 14px; }
.fig-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.fig-pair img + img { margin-top: 0; }
@media (max-width: 560px) {
  .fig-pair { grid-template-columns: 1fr; }
  .fig-pair img + img { margin-top: 14px; }
}
.fig figcaption {
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--muted);
  margin-top: 13px;
}
.fig-no {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-right: 6px;
}

/* ---------- figure lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(4px);
}
.lb-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 4vh 4vw;
  cursor: zoom-out;
}
.lb-scroll img {
  max-width: min(1600px, 94vw);
  width: auto;
  height: auto;
  background: #fff;
  border-radius: 6px;
  cursor: default;
}
.lb-close {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 301;
  font: 400 1.6rem/1 system-ui, sans-serif;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  width: 42px;
  height: 42px;
  cursor: pointer;
}
.lb-close:hover { background: rgba(255, 255, 255, 0.25); }

/* ---------- resume chip ---------- */

.resume {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 0;
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
}
.resume a {
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 9px 14px;
  color: var(--ink);
}
.resume a:hover { border-color: var(--accent); color: var(--accent); }
.resume button {
  font: 400 1rem/1 system-ui, sans-serif;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
}
.resume button:hover { color: var(--accent); }

/* section copy-link button (injected by reader.js) */
.hlink {
  font: 700 0.95rem/1 system-ui, sans-serif;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 7px;
  margin-left: 6px;
  border-radius: 6px;
  opacity: 0;
  vertical-align: 2px;
  transition: opacity 0.12s ease;
}
.sec-head:hover .hlink, .hlink:focus-visible { opacity: 0.8; }
.hlink:hover { color: var(--accent); opacity: 1; }
.hlink.done { color: var(--accent); opacity: 1; }
@media (hover: none) { .hlink { opacity: 0.45; } }

/* ---------- chapter prev/next nav ---------- */

.ch-nav {
  display: flex;
  gap: 16px;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
}
.ch-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.ch-nav a:hover { border-color: var(--accent); transform: translateY(-2px); }
.ch-nav-next { text-align: right; }
.ch-nav span {
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.ch-nav strong { color: var(--ink-strong); font-size: 0.98rem; }

/* ---------- on-page rail ---------- */

.onpage {
  font-family: system-ui, sans-serif;
  font-size: 0.84rem;
  align-self: start;
  position: sticky;
  top: 92px;
  padding-top: 64px;
}
.onpage-h {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}
.onpage ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.onpage li { margin: 0; }
.onpage a {
  display: block;
  padding: 6px 0 6px 14px;
  color: var(--muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1px;
  line-height: 1.4;
}
.onpage a:hover { color: var(--ink-strong); }
.onpage a.active { color: var(--accent); border-left-color: var(--accent); }

/* ---------- mobile section nav ---------- */
/* Hidden on desktop, where the on-page rail does the job. */
.ch-toc-m { display: none; }

@media (max-width: 1080px) {
  .ch-toc-m {
    display: block;
    position: sticky;
    top: var(--topbar-h);
    z-index: 40;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
  }
  .ch-toc-m > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 24px;
    font-family: system-ui, sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ink-strong);
    -webkit-tap-highlight-color: transparent;
  }
  .ch-toc-m > summary::-webkit-details-marker { display: none; }
  .toc-m-label { color: var(--accent); }
  .toc-m-count {
    font-weight: 400;
    font-size: 0.78rem;
    color: var(--muted);
    letter-spacing: 0.03em;
  }
  .ch-toc-m .chev {
    width: 16px;
    height: 16px;
    margin-left: auto;
    color: var(--muted);
    transition: transform 0.2s ease;
  }
  .ch-toc-m[open] .chev { transform: rotate(180deg); }
  .ch-toc-m > nav {
    max-height: min(60vh, 460px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow);
  }
  .ch-toc-m > nav ol {
    list-style: none;
    margin: 0;
    padding: 6px 0 10px;
    counter-reset: toc;
  }
  .ch-toc-m > nav li { margin: 0; counter-increment: toc; }
  .ch-toc-m > nav a {
    display: block;
    padding: 11px 24px;
    color: var(--ink);
    text-decoration: none;
    font-family: system-ui, sans-serif;
    font-size: 0.94rem;
    line-height: 1.35;
    border-left: 3px solid transparent;
  }
  .ch-toc-m > nav a::before {
    content: counter(toc) ".";
    color: var(--accent);
    font-weight: 700;
    margin-right: 10px;
  }
  .ch-toc-m > nav a:active,
  .ch-toc-m > nav a:focus-visible {
    background: var(--bg-soft);
    border-left-color: var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ch-toc-m .chev { transition: none; }
}

/* ---------- home ---------- */

.home-hero {
  max-width: 1000px;
  margin: 0 auto;
  padding: 72px 24px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 56px;
  align-items: center;
  text-align: left;
}
.hero-cover { text-align: center; }
.home-cover {
  width: 100%;
  max-width: 290px;
  height: auto;
  border-radius: 4px;
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.45),
    0 6px 14px rgba(0, 0, 0, 0.35);
  transform: perspective(1400px) rotateY(-7deg);
  transition: transform 0.25s ease;
}
.home-cover:hover { transform: perspective(1400px) rotateY(-2deg); }
html[data-theme="light"] .home-cover {
  box-shadow:
    0 22px 44px rgba(60, 40, 20, 0.28),
    0 6px 14px rgba(60, 40, 20, 0.18);
}
.cover-note {
  font-family: system-ui, sans-serif;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  line-height: 1.6;
  color: var(--muted);
  margin: 16px 0 0;
}
.home-lede {
  max-width: 820px;
  margin: 34px auto 0;
  padding: 0 24px;
}
@media (max-width: 840px) {
  .home-hero {
    grid-template-columns: 1fr;
    gap: 34px;
    text-align: center;
    padding-top: 56px;
  }
  .hero-cover { order: -1; }
  .home-cover { max-width: 200px; transform: none; }
  .home-cover:hover { transform: none; }
  .home-cred { margin-inline: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .home-cover, .home-cover:hover { transform: none; transition: none; }
}
.home-title {
  font-family: "Anton", "Arial Narrow", sans-serif;
  font-weight: 400;
  font-size: clamp(3.2rem, 10vw, 6rem);
  line-height: 1;
  letter-spacing: 0.015em;
  color: var(--accent);
  margin: 10px 0 6px;
}
.home-sub {
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-strong);
  margin: 0 0 6px;
}
.home-by {
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 18px;
}
.home-cred {
  font-family: system-ui, sans-serif;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--ink);
  max-width: 560px;
  margin: 0 0 26px;
}
.home-cred a { white-space: nowrap; }

.stat-band {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 34px;
  margin: 0 0 30px;
  padding: 18px 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.stat { display: flex; flex-direction: column; gap: 1px; }
.stat strong {
  font-family: "Anton", "Arial Narrow", sans-serif;
  font-weight: 400;
  font-size: 1.7rem;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.stat span {
  font-family: system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.home-pitch {
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--ink);
  text-align: left;
}

.home-ctas {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 24px;
}
.home-ctas .intro-cta { margin-top: 0; }
.cta-stemdesk {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.45;
}
.cta-stemdesk:hover { border-color: var(--accent); }
.cta-stemdesk img { border-radius: 10px; flex: none; }
.cta-stemdesk strong { color: var(--accent); }

.intro-cta {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 26px;
  padding: 16px 26px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 12px;
  text-decoration: none;
  text-align: left;
}
.intro-cta:hover { color: var(--accent-ink); opacity: 0.92; }
.intro-eyebrow {
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.8;
}
.intro-cta strong { font-size: 1.1rem; }

.ref-row .toc-title { font-size: 1rem; }
.ref-row .toc-meta { color: var(--accent); font-size: 1rem; }
.home-reference { margin-top: 10px; }
.home-reference > h2 { margin-top: 0; }

.home-contents { max-width: 820px; margin: 30px auto 90px; padding: 0 24px; }
.home-contents h2 {
  font-size: 1.5rem;
  color: var(--ink-strong);
  border-top: 1px solid var(--line);
  padding-top: 2rem;
}
.pilot-tag {
  font-family: system-ui, sans-serif;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 3px 10px;
  vertical-align: 3px;
  margin-left: 10px;
}

.toc-part { margin: 2.4rem 0; }
.toc-part h3 {
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.toc-row {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 12px 10px;
  text-decoration: none;
  color: var(--ink);
  border-radius: 8px;
  border-bottom: 1px solid var(--line);
}
.toc-row:last-child { border-bottom: none; }
.toc-row:hover { background: var(--panel); color: var(--ink-strong); }
.toc-num {
  font-family: "Anton", sans-serif;
  font-size: 1.1rem;
  color: var(--accent);
  min-width: 32px;
}
.toc-title { flex: 1; font-size: 1.08rem; }
.toc-row:hover .toc-title { color: var(--accent); }
.toc-meta {
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.toc-row.read .toc-num { color: var(--muted); }
.toc-row.read .toc-meta::after {
  content: " ✓";
  color: var(--accent);
  font-weight: 700;
}

.print-link {
  display: block;
  margin: 14px 0 0 auto;
  font: 500 0.78rem/1 system-ui, sans-serif;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.print-link:hover { color: var(--accent); }

.rollout-note {
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 2rem;
}

/* ---------- footer ---------- */

.site-foot {
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
  font-family: system-ui, sans-serif;
  font-size: 0.88rem;
  color: var(--muted);
}
.foot-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 44px 24px 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 36px;
}
.foot-mark {
  font-family: "Anton", "Arial Narrow", sans-serif;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin: 0 0 8px;
}
.foot-h {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0 0 8px;
}
.site-foot a { color: var(--ink); }
.site-foot a:hover { color: var(--accent); }
.foot-pub {
  display: block;
  margin-top: 16px;
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.foot-pub span { display: block; margin-bottom: 8px; }
.foot-pub img { display: block; opacity: 0.9; }
.foot-pub:hover img { opacity: 1; }
html[data-theme="light"] .pub-dark { display: none; }
html[data-theme="dark"] .pub-light { display: none; }
.foot-legal {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 24px 30px;
  font-size: 0.78rem;
  opacity: 0.75;
}

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .onpage { display: none; }
}

@media (max-width: 1080px) {
  html { scroll-padding-top: calc(var(--topbar-h) + 64px); }
}

@media (max-width: 640px) {
  body { font-size: 1rem; }
  .bar-sub { display: none; }
  .panel, .objectives { padding: 20px; }
  .ch-hero { margin-top: 36px; }
  .sec-head { flex-direction: column; gap: 4px; }
  .foot-inner { grid-template-columns: 1fr; gap: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .ch-nav a { transition: none; }
  #progressBar { transition: none; }
  .hlink { transition: none; }
}

/* ---------- print ---------- */
/* Readers print chapters. Force a light page, hide the chrome, keep figures
   and boxes intact across page breaks. */
@media print {
  html[data-theme="dark"], html[data-theme="light"], :root {
    --bg: #ffffff;
    --bg-soft: #ffffff;
    --panel: #ffffff;
    --panel-2: #ffffff;
    --ink: #000000;
    --ink-strong: #000000;
    --muted: #444444;
    --accent: #a34f0d;
    --accent-ink: #ffffff;
    --line: #999999;
    --shadow: none;
    --fig-well: #ffffff;
  }
  .topbar, .progress, .onpage, .ch-toc-m, .search-modal, .fix, .ch-nav,
  .site-foot, #themeToggle, .skip { display: none !important; }
  body { font-size: 11pt; line-height: 1.55; }
  .layout { display: block; max-width: 100%; padding: 0; }
  article.chapter { max-width: 100%; }
  .fig, .panel, .objectives, .term, .pull, .epigraph, tr { break-inside: avoid; }
  h2, h3 { break-after: avoid; }
  .fig img { padding: 0; }
  a { color: #000; text-decoration: none; }
  .chip { border: 1px solid #000; background: none; color: #000; }
}
