/* Your own GitHub, in Sean Beaverson's North Shore brand (DESIGN.md says where each value came from).
   Dark by default (the brand's navy); light is a choice (the brand's cream). Three fonts, seven sizes, each with one job:

     --t-display  52px  the hero line
     --t-title    38px  a chapter title
     --t-head     22px  a section heading inside a chapter
     --t-lead     19px  a chapter's opening line
     --t-body     17px  reading text, step titles
     --t-small    15px  secondary text: step detail, table cells, captions
     --t-fine     13px  fine print, code, the running head
   Montserrat carries headings and anything you click; Newsreader carries reading text; IBM Plex Mono carries code.
   Labels (Montserrat caps, wide tracking) are 12px and are used only to name a block.
   The serif italic appears in exactly two places: the word GitHub in the brand, and a chapter title's accent.
   Copper is the one highlight: text in --accent, rules and fills in --sun. ✦ is the only ornament. */

:root {
  --bg: #142434;          /* navy-900 */
  --surface: #1a2e41;     /* navy-800 */
  --inset: #20384f;       /* navy-700, the beaver */
  --ink: #f4f1eb;         /* cream-100 */
  --muted: #c8d2da;       /* navy-200 */
  --line: #2e4b66;        /* navy-600 */
  --line-strong: #45627d; /* navy-500 */
  --frame: #9daebc;       /* navy-300: the framed card's 1.5px edge */
  --accent: #dcad88;      /* sun-400: copper text on navy */
  --sun: #c47d4d;         /* sun-600: copper rules, fills, marks */
  --water: #8baeba;       /* water-400 */
  --rust: #e3a196;        /* rust, lightened for navy */
  --focus: #d09466;       /* sun-500 */
  --selection: #c47d4d;
  --selection-ink: #142434;
  --shadow: 0 30px 60px -30px rgb(10 18 26 / .7);

  --sans: "Montserrat", system-ui, sans-serif;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --t-display: clamp(36px, 5vw, 52px);
  --t-title: clamp(30px, 3.6vw, 38px);
  --t-head: 22px;
  --t-lead: 19px;
  --t-body: 17px;
  --t-small: 15px;
  --t-fine: 13px;

  --page-x: 48px;
  --measure: 66ch;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f1eb;          /* cream-100, the brand's background */
  --surface: #faf8f4;     /* cream-50 */
  --inset: #eae5db;       /* cream-200 */
  --ink: #20384f;         /* navy-700 */
  --muted: #45627d;       /* navy-500 */
  --line: #dcd5c7;        /* cream-300 */
  --line-strong: #bfb6a5; /* cream-400 */
  --frame: #20384f;       /* navy-700 */
  --accent: #8a522c;      /* sun-800: the copper that passes as text */
  --sun: #c47d4d;         /* sun-600 */
  --water: #3e6573;       /* water-800 */
  --rust: #9e3f35;        /* rust-700 */
  --focus: #a9653a;       /* sun-700 */
  --selection: #efd8c5;   /* sun-200 */
  --selection-ink: #142434;
  --shadow: 0 12px 40px rgb(20 36 52 / .16);
  color-scheme: light;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font: 400 var(--t-body)/1.6 var(--serif);
  color: var(--ink);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: underline; text-decoration-color: var(--sun); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
a:hover { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
p { margin: 0 0 16px; }
h1, h2, h3, h4 { margin: 0; text-wrap: balance; }
code { font: 500 var(--t-fine) var(--mono); background: var(--inset); padding: 1px 6px; border-radius: 2px; overflow-wrap: anywhere; }
pre { margin: 12px 0 0; padding: 12px 14px; background: var(--inset); border-radius: 4px; font: 500 var(--t-fine)/1.6 var(--mono); overflow-x: auto; white-space: pre; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
::selection { background: var(--selection); color: var(--selection-ink); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip {
  position: absolute; left: 16px; top: -60px; z-index: 50;
  padding: 10px 14px; background: var(--ink); color: var(--bg); border-radius: 4px;
  font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; text-decoration: none;
}
.skip:focus { top: 16px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 var(--page-x); }

/* The brand mark: the reversed mark on navy, the full-color mark on cream */
.mark { display: block; height: auto; }
.mark-on-light { display: none; }
:root[data-theme="light"] .mark-on-dark { display: none; }
:root[data-theme="light"] .mark-on-light { display: block; }

.label {
  margin: 0 0 14px;
  font: 600 12px/1.2 var(--sans); letter-spacing: .18em; text-transform: uppercase; color: var(--muted);
}
.label .sym { color: var(--accent); margin-right: .5em; }
.num { font: 600 var(--t-fine)/1.7 var(--sans); letter-spacing: .06em; color: var(--muted); }
.small, .fine { font-size: var(--t-small); line-height: 1.55; color: var(--muted); }
.fine { font-size: var(--t-fine); }

/* ---------- Header ---------- */

.site-head { border-bottom: 1px solid var(--line); }
.site-head-inner { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; padding-top: 18px; }
.brand { display: flex; align-items: center; gap: 12px 16px; padding-bottom: 14px; text-decoration: none; }
.brand:hover { color: inherit; }
.brand .mark { width: 36px; }
.brand-name { font: 600 20px/1 var(--sans); letter-spacing: -.01em; white-space: nowrap; }
.brand-name em { font: italic 400 23px/1 var(--serif); letter-spacing: 0; }
.brand-tag { padding-left: 16px; border-left: 1px solid var(--line); font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.library-link { align-self: center; margin: 0 auto 0 0; padding: 12px 0; font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); text-decoration: none; }
.library-link:hover { color: var(--ink); text-decoration: underline; text-decoration-color: var(--sun); text-underline-offset: 4px; }
.modes { display: flex; gap: 24px; margin: 0; padding: 0; list-style: none; }
.tab {
  position: relative; display: inline-block; padding: 12px 0 14px; border: 0; background: none; min-height: 44px;
  font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); text-decoration: none;
}
.tab:hover { color: var(--ink); }
.tab[aria-current="true"] { color: var(--ink); }
.tab[aria-current="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--sun); }
/* On cream, sun-600 is 2.9:1, under the 3:1 a state marker needs; the text copper passes */
:root[data-theme="light"] .tab[aria-current="true"]::after { background: var(--accent); }

/* ---------- Hero and contents (scroll mode) ---------- */

.hero { padding: 64px var(--page-x) 48px; display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 48px; align-items: end; }
.hero h1 { font: 600 var(--t-display)/1.05 var(--sans); letter-spacing: -.02em; }
.hero h1 em { font: italic 400 1.08em/1 var(--serif); letter-spacing: -.01em; }
.hero .lede { font-size: var(--t-lead); line-height: 1.55; }
.hero .label { margin-bottom: 24px; }
.contents { padding-bottom: 56px; }
.contents ol { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); display: grid; grid-template-rows: repeat(4, auto); grid-auto-flow: column; column-gap: 48px; }
.contents a { display: grid; grid-template-columns: 44px 1fr; padding: 14px 0; border-bottom: 1px solid var(--line); text-decoration: none; font: 500 var(--t-body)/1.4 var(--sans); }
.contents a:hover span:last-child { text-decoration: underline; text-decoration-color: var(--sun); text-underline-offset: 3px; }
/* Horizon bands, from the stripes that cut through the sun in the mark */
.ribbon { height: 8px; border-top: 3px solid var(--sun); border-bottom: 1.5px solid var(--sun); }

/* ---------- Chapters, as a scroll ---------- */

.chapter { padding: 64px 0; display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 40px; border-bottom: 1px solid var(--line); }
.chapter:last-of-type { border-bottom: 0; }
.chapter > .label { margin: 0; }
.chapter-body { max-width: var(--measure); }
.chapter h2 { font: 600 var(--t-title)/1.1 var(--sans); letter-spacing: -.02em; margin-bottom: 12px; }
.chapter h2 em { font: italic 400 1.1em/1 var(--serif); letter-spacing: -.01em; }
.chapter .lede { font-size: var(--t-lead); line-height: 1.55; color: var(--muted); margin-bottom: 28px; text-wrap: pretty; }
.chapter h3 { font: 600 var(--t-head)/1.3 var(--sans); letter-spacing: -.01em; margin: 0 0 8px; }
.chapter h3 + p { margin-bottom: 28px; }
.chapter p { text-wrap: pretty; }
.chapter ul { padding-left: 20px; margin: 0 0 24px; }
.chapter li { margin-bottom: 6px; }
.page { padding-bottom: 8px; }
.page + .page { margin-top: 24px; }

/* Diagrams: inline SVG that takes the page's colors */
.figure { margin: 8px 0 28px; }
/* On a narrow screen a diagram keeps a readable size and scrolls sideways inside its own box */
.figure-art { overflow-x: auto; overscroll-behavior-x: contain; }
.figure svg { display: block; width: 100%; height: auto; color: var(--ink); font-family: var(--sans); font-size: 12px; }
.figure .dg-muted { color: var(--muted); }
.figure .dg-line { stroke: var(--line-strong); }
.figure .dg-accent { color: var(--accent); }
.figure .dg-water { color: var(--water); }
.figure .dg-rust { color: var(--rust); }
.figure .dg-box { fill: var(--surface); stroke: var(--line-strong); }
.figure .dg-inset { fill: var(--inset); stroke: var(--line-strong); }
/* Montserrat runs wide: diagram text is 12px (set on the svg, so a text's own font-size still wins), and labels stay mono so they fit */
.figure text { fill: currentColor; }
.figure .dg-label { font-family: var(--mono); font-size: 10px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase; }
.figure figcaption { margin-top: 10px; font-size: var(--t-small); line-height: 1.5; color: var(--muted); }

/* Hairline tables */
.facts { width: 100%; border-collapse: collapse; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.facts th, .facts td { text-align: left; vertical-align: top; padding: 14px 16px 14px 0; border-bottom: 1px solid var(--line); font-size: var(--t-small); line-height: 1.55; }
.facts tr:last-child th, .facts tr:last-child td { border-bottom: 0; }
.facts th { width: 36%; font-family: var(--sans); font-weight: 600; color: var(--ink); }
.facts td { color: var(--muted); padding-right: 0; }
.facts.cols thead th { width: auto; padding-top: 10px; padding-bottom: 10px; font: 600 12px/1.2 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.facts.cols tbody th { width: 38%; }
.facts.cols td { color: var(--ink); }
.facts.cols td small { display: block; font-size: var(--t-fine); color: var(--muted); margin-top: 2px; }

/* Glossary */
.glossary { margin: 0 0 28px; border-top: 1px solid var(--line); }
.glossary div { display: grid; grid-template-columns: 36% 1fr; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: var(--t-small); line-height: 1.55; }
.glossary dt { font-family: var(--sans); font-weight: 600; }
.glossary dd { margin: 0; color: var(--muted); }

/* Steps */
.steps { margin: 0 0 8px; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.step { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 16px 0; border-bottom: 1px solid var(--line); }
.step .num { line-height: 1.7; }
.step h4 { margin: 0 0 4px; font: 600 var(--t-body)/1.4 var(--sans); }
.step p { margin: 0; font-size: var(--t-small); line-height: 1.55; color: var(--muted); }
.step p + p { margin-top: 8px; }
.path { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font: 500 var(--t-fine)/1 var(--sans); color: var(--ink); }
.path span { padding: 6px 8px; background: var(--inset); border-radius: 2px; }
.done {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 4px; background: transparent;
  font: 600 12px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); white-space: nowrap;
}
.done .box { width: 16px; height: 16px; border: 1px solid var(--line-strong); border-radius: 2px; display: inline-flex; align-items: center; justify-content: center; color: #142434; }
.done svg { display: none; }
.done[aria-pressed="true"] { background: var(--surface); color: var(--ink); }
.done[aria-pressed="true"] .box { border-color: var(--sun); background: var(--sun); }
.done[aria-pressed="true"] svg { display: block; }
.forget { margin: 12px 0 0; padding: 0; border: 0; background: none; min-height: 44px; font: 600 12px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); text-decoration: underline; text-decoration-color: var(--sun); text-underline-offset: 4px; }
.forget:hover { color: var(--ink); }

/* Boxes */
.when { margin-top: 28px; padding: 20px 24px; background: var(--inset); border-radius: 8px; }
.when .label { margin-bottom: 8px; }
.when p { margin: 0; font-size: var(--t-small); line-height: 1.55; color: var(--ink); }
/* The framed card: the brand board's square 1.5px hairline */
.frame { border: 1.5px solid var(--frame); border-radius: 0; padding: 24px 28px; background: var(--surface); margin-bottom: 28px; }
.frame .label { margin-bottom: 6px; }
.frame h3 { margin-bottom: 20px; }
.frame > p { font-size: var(--t-small); color: var(--muted); }
.frame ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.frame li { display: grid; grid-template-columns: 32px 1fr; gap: 4px; margin: 0; }
.frame li .num { color: var(--accent); }
.frame li h4 { margin: 0 0 2px; font: 600 var(--t-body)/1.4 var(--sans); }
.frame li p { margin: 0; font-size: var(--t-small); line-height: 1.55; color: var(--muted); }
.frame .after { margin: 20px 0 0; }

/* Resources */
.resources h3 { margin: 0 0 8px; }
.resources ul { list-style: none; padding: 0; margin: 0 0 8px; border-top: 1px solid var(--line); }
.resources li { padding: 12px 0; border-bottom: 1px solid var(--line); margin: 0; }
.resources li a { font: 600 var(--t-small)/1.4 var(--sans); }
.resources .who { font: 600 12px/1.6 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 2px 0 4px; }
.resources .says { margin: 0; font-size: var(--t-small); line-height: 1.55; color: var(--muted); }

/* The footer: who made it, and what you may do with it */
.site-foot { padding: 32px 0 48px; border-top: 1px solid var(--line); font-size: var(--t-small); line-height: 1.55; color: var(--muted); }
.site-foot p { margin-bottom: 8px; }
.sig { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; align-items: start; padding-bottom: 20px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.sig .mark { width: 44px; }
.sig-name { margin: 0 0 4px; font: 600 var(--t-body)/1.3 var(--sans); letter-spacing: -.01em; color: var(--ink); }
.sig p:last-child { margin-bottom: 0; }
.sig a { white-space: nowrap; }
.foot-meta a { white-space: nowrap; }

/* ---------- The book ---------- */

.book { display: none; }
body[data-mode="book"] .hero, body[data-mode="book"] .contents, body[data-mode="book"] .ribbon, body[data-mode="book"] .chapters-scroll { display: none; }
body[data-mode="book"] .book { display: block; padding: 32px var(--page-x) 48px; }
.book-frame {
  position: relative; max-width: 860px; margin: 0 auto;
}
.leaf {
  position: relative; min-height: 70vh; padding: 40px 88px 72px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: var(--shadow);
}
.leaf::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--sun); border-radius: 8px 0 0 8px; }

.running { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 28px; font: 600 12px/1.6 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.running .sym { color: var(--accent); margin-right: .5em; }
.leaf-body { max-width: var(--measure); }
.leaf-body .chapter-head h2 { font: 600 var(--t-title)/1.1 var(--sans); letter-spacing: -.02em; margin-bottom: 12px; }
.leaf-body .chapter-head h2 em { font: italic 400 1.1em/1 var(--serif); }
.leaf-body .lede { font-size: var(--t-lead); line-height: 1.55; color: var(--muted); margin-bottom: 28px; }
.leaf-body h3 { font: 600 var(--t-head)/1.3 var(--sans); letter-spacing: -.01em; margin: 0 0 8px; }
.leaf-body h3 + p { margin-bottom: 24px; }
/* "Steps" is a heading for the steps under it, styled as a label */
.chapter h3.label, .leaf-body h3.label { margin: 0 0 14px; font: 600 12px/1.2 var(--sans); letter-spacing: .18em; }
.leaf-body ul { padding-left: 20px; margin: 0 0 24px; }
.leaf-body p { text-wrap: pretty; }

/* The table of contents page */
.toc-page h2 { font: 600 var(--t-title)/1.1 var(--sans); letter-spacing: -.02em; margin-bottom: 8px; }
.toc-page h2 em { font: italic 400 1.1em/1 var(--serif); }
.toc-page .lede { font-size: var(--t-lead); line-height: 1.55; color: var(--muted); margin-bottom: 24px; }
.toc-list { list-style: none; margin: 0 0 24px; padding: 0; border-top: 1px solid var(--line); }
.toc-list button { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; width: 100%; padding: 12px 0; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; font: 500 var(--t-body)/1.4 var(--sans); color: var(--ink); }
.toc-list button:hover span:nth-child(2) { text-decoration: underline; text-decoration-color: var(--sun); text-underline-offset: 3px; }
.toc-list .pages { font: 500 var(--t-fine)/1.6 var(--sans); color: var(--muted); }
.toc-list button[data-read="true"] span:nth-child(2)::after { content: " ·"; color: var(--accent); }

/* The edges that turn the page */
.edge {
  position: absolute; top: 0; bottom: 0; width: 72px; border: 0; background: none; color: var(--muted);
  display: flex; align-items: center; justify-content: center; border-radius: 4px;
}
.edge:hover { color: var(--ink); background: linear-gradient(90deg, transparent, rgb(128 128 128 / .06)); }
.edge.prev { left: 0; }
.edge.next { right: 0; }
.edge.prev:hover { background: linear-gradient(270deg, transparent, rgb(128 128 128 / .06)); }
.edge svg { width: 22px; height: 22px; }
.edge[disabled] { opacity: 0; pointer-events: none; }
.leaf-foot { position: absolute; left: 88px; right: 88px; bottom: 28px; display: flex; justify-content: space-between; align-items: center; gap: 16px; font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.leaf-foot button { border: 0; background: none; padding: 12px 0; font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit; text-decoration: underline; text-decoration-color: var(--sun); text-underline-offset: 4px; min-height: 44px; }
.leaf-foot button:hover { color: var(--ink); }
.leaf-foot button[disabled] { visibility: hidden; }
.book-hint { margin: 16px auto 0; max-width: 860px; text-align: center; font-size: var(--t-fine); color: var(--muted); }


.jump { display: none; position: sticky; top: 0; z-index: 10; padding: 10px var(--page-x); background: var(--bg); border-bottom: 1px solid var(--line); }
.jump label { font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-right: 10px; }
.jump select { font: 500 var(--t-small)/1.2 var(--sans); min-height: 44px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--surface); color: var(--ink); max-width: 100%; }

/* ---------- Narrow screens ---------- */

@media (max-width: 960px) {
  :root { --page-x: 28px; }
  .chapter { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .hero { grid-template-columns: minmax(0, 1fr); gap: 24px; padding: 44px var(--page-x) 36px; }
  .leaf { padding: 32px 56px 72px; }
  .edge { width: 48px; }
  .leaf-foot { left: 56px; right: 56px; }
}
@media (max-width: 600px) {
  :root { --page-x: 16px; --t-body: 16px; --t-lead: 18px; --t-head: 20px; }
  .site-head-inner { padding-top: 14px; }
  .brand-tag { display: none; }
  .library-link { padding: 0 0 12px; }
  .modes { gap: 18px; }
  .contents ol { grid-auto-flow: row; grid-template-rows: none; }
  .facts:not(.cols) th, .facts:not(.cols) td { display: block; width: auto; padding: 0; border: 0; }
  .facts:not(.cols) tr { display: block; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .facts:not(.cols) tr:last-child { border-bottom: 0; }
  .facts:not(.cols) th { margin-bottom: 4px; }
  .facts.cols th, .facts.cols td { padding: 10px 8px 10px 0; font-size: 14px; }
  .glossary div { grid-template-columns: 1fr; gap: 4px; }
  .step { grid-template-columns: 36px minmax(0, 1fr); }
  .step .done { grid-column: 2; justify-self: start; }
  .frame { padding: 18px; }
  .when { padding: 16px 18px; }
  body[data-mode="book"] .book { padding: 16px 0 32px; }
  .leaf { padding: 24px 20px 84px; min-height: 60vh; border-radius: 0; border-left: 0; border-right: 0; }
  .edge { display: none; }
  .leaf-foot { left: 20px; right: 20px; bottom: 20px; }
  .leaf-foot button { padding: 12px 8px; border: 1px solid var(--line-strong); border-radius: 4px; text-decoration: none; }
  .running { flex-wrap: wrap; gap: 4px 16px; }
  .leaf-foot .foot-title, .hint-turn { display: none; }
  .figure-art svg { min-width: 600px; }
}

.running:focus { outline: none; }

/* ---------- Library pages ---------- */
.shelf { padding: 56px var(--page-x) 72px; }
.shelf h1 { font: 600 clamp(34px, 4.4vw, 44px)/1.08 var(--sans); letter-spacing: -.02em; margin-bottom: 16px; }
.shelf h1 em { font: italic 400 1.12em/1 var(--serif); }
.shelf .lede { font-size: 19px; line-height: 1.6; color: var(--muted); max-width: 640px; margin-bottom: 48px; }
.item { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 32px 48px; padding: 40px 0; border-top: 1px solid var(--line); }
.item h2 { font: 600 22px/1.25 var(--sans); letter-spacing: -.01em; margin-bottom: 8px; }
.item .use { font: 400 15px/1.55 var(--serif); color: var(--muted); margin-bottom: 16px; max-width: 640px; }
.item .where { font: 500 12px/1.6 var(--mono); color: var(--muted); margin: 0; }
.file { position: relative; margin: 0 0 16px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); }
.file-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.file-head .name { font: 500 12px/1.4 var(--mono); }
.file-head .name a { text-decoration-color: var(--line-strong); }
.file pre { margin: 0; padding: 14px; font: 400 13px/1.6 var(--mono); overflow-x: auto; white-space: pre; max-height: 440px; }
.copy { min-height: 36px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 4px; background: transparent; font: 600 12px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.copy:hover { color: var(--ink); }
.copy[data-copied="true"] { color: var(--ink); background: var(--inset); }
.back { display: inline-block; margin-bottom: 24px; font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; }
.item > div { min-width: 0; }
@media (max-width: 960px) { .item { grid-template-columns: minmax(0, 1fr); gap: 12px; } }

/* A breakdown: each line of a file, then what it does */
.breakdown { list-style: none; margin: 0 0 16px; padding: 0; border-top: 1px solid var(--line); }
.breakdown li { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.breakdown li > code { display: block; padding: 8px 10px; background: var(--inset); border-radius: 3px; font: 500 var(--t-fine)/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.breakdown p { margin: 0; font-size: var(--t-small); line-height: 1.55; color: var(--muted); }
.breakdown p strong { color: var(--ink); }
.guide-step { padding: 32px 0; border-top: 1px solid var(--line); }
.guide-step h2 { font: 600 var(--t-head)/1.3 var(--sans); letter-spacing: -.01em; margin-bottom: 8px; }
.guide-step .use { max-width: 640px; }
.guide-step .file { max-width: 760px; }
@media (max-width: 600px) { .breakdown li { grid-template-columns: 1fr; gap: 6px; } }

/* Field guide: an editorial opening and a quiet, always-available route. */
[hidden] { display: none !important; }
.reader-home { font: 600 var(--t-small)/1.4 var(--sans); text-decoration: none; }
#book-jump { display: none; min-width: 0; max-width: 100%; min-height: 44px; padding: 8px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); font: 500 var(--t-fine)/1.4 var(--sans); }
.reader-layout { max-width: 1180px; margin: auto; display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 36px; align-items: start; }
.chapter-rail { position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow-y: auto; padding: 0 8px 8px 0; }
.chapter-rail > a { display: flex; gap: 12px; align-items: baseline; padding: 12px 8px; min-height: 44px; font: 500 var(--t-fine)/1.5 var(--sans); text-decoration: none; border-bottom: 1px solid var(--line); }
.chapter-rail .label { margin: 26px 8px 10px; line-height: 1.5; }
.chapter-rail > a[aria-current] { color: var(--accent); background: var(--surface); border-left: 2px solid var(--accent); padding-left: 6px; }
.rail-pages { margin: 8px 0 16px 34px; border-left: 1px solid var(--line-strong); }
.rail-pages a { display: block; padding: 10px 12px; min-height: 40px; color: var(--muted); font: 400 var(--t-fine)/1.5 var(--sans); text-decoration: none; }
.rail-pages a[aria-current] { color: var(--accent); text-decoration: underline; text-underline-offset: 4px; }
.chapter-rail a:hover { color: var(--accent); }
.chapter-rail .rail-library { margin-top: 24px; color: var(--accent); }
.reader-layout .book-frame { width: 100%; min-width: 0; }
.reader-layout .leaf { padding: 32px 48px 28px; min-height: 65vh; border-radius: 2px; }
.reader-layout .leaf::before { border-radius: 0; }
.reader-layout .edge { width: 36px; bottom: 96px; }
.reader-layout .leaf-foot { position: static; margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); align-items: stretch; }
.reader-layout .leaf-foot button { letter-spacing: .04em; text-transform: none; text-align: left; }
.reader-layout .leaf-foot #foot-next { margin-left: auto; text-align: right; color: var(--accent); }
.at-overview .reader-layout { grid-template-columns: minmax(0, 1fr); }
.at-overview .chapter-rail, .at-overview .running, .at-overview .edge, .at-overview .leaf-foot, .at-overview .book-hint { display: none; }
.at-overview .book-frame { max-width: none; }
.at-overview .leaf { background: none; box-shadow: none; border: 0; padding: 16px 0 0; }
.at-overview .leaf::before { display: none; }
.at-overview .leaf-body { max-width: none; }
.welcome { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 64px; align-items: center; padding: 16px 0 48px; }
.welcome h2 { font: 600 var(--t-display)/1.08 var(--sans); letter-spacing: -.04em; margin: 22px 0; }
.welcome h2 em { font: italic 400 1.08em/1 var(--serif); color: var(--accent); }
.welcome .lede { max-width: 44ch; margin-bottom: 24px; }
.welcome-actions { display: flex; gap: 14px; align-items: stretch; flex-wrap: wrap; margin-bottom: 16px; }
.start-button, .resume-button { min-height: 48px; padding: 14px 20px; border: 1px solid var(--accent); border-radius: 2px; font: 600 var(--t-fine)/1.5 var(--sans); text-align: left; }
.start-button { background: var(--accent); color: var(--bg); }
.start-button span { margin-left: 20px; }
.resume-button { background: transparent; color: var(--accent); }
.start-button:hover, .resume-button:hover { outline: 2px solid var(--accent); outline-offset: 3px; }
.project-preview { margin: 0; transform: rotate(2deg); }
.preview-bar { display: flex; justify-content: space-between; gap: 8px; padding: 12px 18px; background: var(--inset); border: 1px solid var(--line-strong); font: 500 var(--t-fine)/1.4 var(--mono); }
.preview-paper { padding: 32px 28px 24px; color: #20384f; background: #f4f1eb; border-bottom: 5px solid #c47d4d; }
.preview-kicker { font: 500 var(--t-fine)/1.5 var(--mono); letter-spacing: .06em; }
.preview-title { font: 400 var(--t-title)/1.04 var(--serif); margin: 20px 0 0; }
.river-art { color: #3e6573; margin: 14px -28px; overflow: hidden; }
.river-art svg { width: 100%; display: block; max-height: 120px; }
.preview-paper > p:last-child { margin-bottom: 0; font-size: var(--t-small); }
.project-preview figcaption { margin-top: 16px; text-align: center; font-size: var(--t-fine); color: var(--muted); }
.route-heading { display: flex; justify-content: space-between; gap: 24px; align-items: center; padding: 24px 0; border-top: 3px solid var(--sun); }
.route-heading .label { color: var(--accent); margin-bottom: 10px; }
.route-heading p { margin-bottom: 0; }
.route-note { font: italic 400 var(--t-lead)/1.3 var(--serif); color: var(--muted); white-space: nowrap; }
.toc-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 36px; }
.toc-list button { grid-template-columns: 30px minmax(0, 1fr) 20px; min-height: 92px; align-items: center; padding: 16px 8px; }
.toc-list small { display: block; margin-top: 6px; font: 400 var(--t-small)/1.4 var(--serif); color: var(--muted); }
.toc-list button:hover { background: var(--surface); }
.toc-arrow { color: var(--accent); }
.page { scroll-margin-top: 84px; }
body[data-mode="scroll"] .jump { display: block; }
body[data-mode="scroll"] .chapter { scroll-margin-top: 84px; }
@media (max-width: 1100px) {
  .brand-tag { display: none; }
  .reader-layout { grid-template-columns: 190px minmax(0, 1fr); gap: 24px; }
  .welcome { gap: 36px; }
}
@media (max-width: 800px) {
  .reader-layout { grid-template-columns: minmax(0, 1fr); }
  .chapter-rail { display: none; }
  #book-jump { display: block; }
  .welcome { gap: 28px; }
  .project-preview { transform: none; }
  .route-note { display: none; }
}
@media (max-width: 600px) {
  .site-head-inner { gap: 0 16px; align-items: center; }
  .site-head-inner nav { order: 3; }
  .site-head-inner > #theme { order: 4; margin-left: auto; }
  .brand-name { font-size: var(--t-body); }
  .brand { gap: 10px; }
  .library-link { margin-left: auto; margin-right: 0; }
  .reader-home { font-size: var(--t-fine); flex-shrink: 0; }
  .reader-layout .leaf { padding: 24px 20px; }
  .reader-layout .leaf-foot { gap: 12px; }
  .at-overview .leaf { padding: 12px 20px; }
  .welcome { grid-template-columns: minmax(0, 1fr); padding: 0 0 32px; gap: 24px; }
  .welcome h2 { margin: 16px 0; }
  .preview-paper { padding-top: 24px; }
  .river-art svg { max-height: 80px; }
  .toc-list { grid-template-columns: minmax(0, 1fr); }
  .toc-list button { min-height: 80px; }
  .reader-layout .running { letter-spacing: .08em; }
  .book-hint { padding: 0 20px; }
  .foot-meta a, .sig a { white-space: normal; }
}
.assistant-shortcut { display: inline-block; font: 500 var(--t-fine)/1.6 var(--sans); color: var(--accent); padding: 8px 0; }
.assistant-options { margin: 24px 0; border-top: 1px solid var(--line-strong); }
.assistant-options details { border-bottom: 1px solid var(--line-strong); }
.assistant-options summary { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 12px; cursor: pointer; font: 600 var(--t-body)/1.4 var(--sans); list-style: none; }
.assistant-options summary::-webkit-details-marker { display: none; }
.assistant-options summary small { display: block; margin-top: 6px; font: 400 var(--t-small)/1.5 var(--serif); color: var(--muted); }
.option-action { flex-shrink: 0; font: 500 var(--t-fine)/1.5 var(--sans); color: var(--accent); }
.option-action::after { content: " +"; }
.assistant-options details[open] .option-action::after { content: " −"; }
.assistant-options details[open] { background: var(--inset); }
.assistant-detail { padding: 4px 20px 16px; }
.assistant-detail pre, .setup-help pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.setup-help { margin: 20px 0; padding: 16px 20px; border: 1px solid var(--line-strong); }
.setup-help summary { cursor: pointer; font: 600 var(--t-small)/1.6 var(--sans); min-height: 28px; }
.setup-help[open] summary { margin-bottom: 16px; }
.setup-help p:last-child { margin-bottom: 0; }
.practice-prompt { border-left: 3px solid var(--accent); background: var(--inset); padding: 20px 24px; margin: 20px 0; }
.practice-prompt p:last-child { margin-bottom: 0; }
@media (max-width: 600px) {
  .assistant-detail { padding-left: 12px; padding-right: 12px; }
  .assistant-options summary { padding-left: 4px; padding-right: 4px; }
}

/* One integrated reader bar. Tactile switches adapt the reader without a settings form. */
.reading-bar { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line-strong); }
.reading-bar-inner { max-width: 1280px; }
.reading-controls { display: flex; justify-content: space-between; align-items: center; gap: 12px 24px; min-height: 72px; }
.reading-modes .modes { gap: 2px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.reading-modes .tab { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 14px; min-height: 40px; border: 1px solid transparent; border-radius: 5px; font: 500 var(--t-fine)/1.4 var(--sans); text-transform: none; letter-spacing: 0; white-space: nowrap; }
.reading-modes .tab svg, .reading-context .reader-home svg { width: 18px; height: 18px; flex-shrink: 0; }
.reading-modes .tab[aria-pressed="true"] { color: var(--accent); background: var(--bg); border-color: var(--line-strong); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.reading-modes .tab::after { display: none; }
.reading-switches { display: flex; align-items: center; gap: 24px; }
.reading-switch { position: relative; display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font: 500 var(--t-fine)/1.4 var(--sans); color: var(--muted); white-space: nowrap; }
.reading-switch:has(:checked) { color: var(--ink); }
.reading-switch:hover { color: var(--ink); }
.reading-switch input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.switch-track { position: relative; display: block; flex-shrink: 0; width: 46px; height: 26px; border-radius: 20px; border: 1px solid var(--line-strong); background: var(--inset); box-shadow: inset 1px 2px 4px rgb(0 0 0 / .3), 0 1px 0 rgb(255 255 255 / .05); }
.switch-indicator { position: absolute; inset: 4px; border-radius: inherit; background: var(--accent); opacity: 0; box-shadow: inset 0 1px 3px rgb(0 0 0 / .25); transition: opacity 180ms ease; }
.switch-thumb { position: absolute; width: 22px; height: 20px; top: 2px; left: 2px; border-radius: 12px; background: linear-gradient(155deg, #faf8f4 20%, #c8d2da 90%); box-shadow: inset 0 1px 0 #fff, 1px 2px 3px rgb(0 0 0 / .4); transition: transform 220ms cubic-bezier(.2, .8, .2, 1); }
.switch-thumb::after { content: ""; position: absolute; inset: 3px; border: 1px solid rgb(32 56 79 / .12); border-radius: inherit; }
.reading-switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.reading-switch input:checked + .switch-track .switch-indicator { opacity: 1; }
.reading-switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 4px; }
.reading-switch:has(:disabled) { cursor: default; color: var(--muted); }
.reading-switch input:disabled + .switch-track { opacity: .45; }
.reading-context { display: flex; align-items: center; gap: 24px; min-height: 56px; padding: 6px 0; border-top: 1px solid var(--line); font: 500 var(--t-fine)/1.5 var(--sans); color: var(--muted); }
.reading-context .reader-home { display: flex; align-items: center; gap: 8px; min-height: 44px; flex-shrink: 0; font: 600 var(--t-fine)/1.4 var(--sans); }
.reading-context .reader-home svg { color: var(--accent); }
.reading-context #book-jump, .reading-context .jump select { border: 0; border-radius: 4px; padding: 8px 12px; min-height: 44px; font: 500 var(--t-fine)/1.5 var(--sans); background: var(--surface); color: var(--ink); min-width: 0; }
.reading-context #book-jump { max-width: 480px; flex: 1; }
.layout-note { margin-left: auto; font: 400 var(--t-fine)/1.4 var(--serif); }
body[data-location="overview"] .reading-context { display: none; }
body:not([data-mode="book"]) #reader-location, body:not([data-mode="book"]) #book-jump { display: none; }
body[data-mode="book"] #scroll-navigation { display: none; }
body .reading-context .jump { position: static; flex: 1; min-width: 0; padding: 0; border: 0; gap: 16px; background: none; }
body .reading-context .jump-field { display: block; }
body .reading-context .jump-field label { margin: 0; }
.reader-ready .reading-context .jump-field select { width: 100%; text-overflow: ellipsis; }
@media (prefers-reduced-motion: reduce) { .switch-thumb, .switch-indicator { transition: none; } }
body[data-size="large"] #main { --t-body: 20px; --t-small: 18px; --t-lead: 22px; --t-head: 26px; --t-fine: 15px; }
body[data-width="fluid"] { --measure: 100%; }
body[data-width="fluid"] .wrap,
body[data-width="fluid"] .reading-bar-inner, body[data-width="fluid"] .reader-layout { max-width: none; }
body[data-width="fluid"] .book-frame { max-width: none; }

/* Two actual pages, with one set of controls below both. A short last page stays single. */
.book-spread { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); }
.reader-layout .leaf-body { margin: 0 auto; }
.reader-layout .leaf-foot { margin-top: 16px; padding: 12px 12px 0; }
.has-spread .reading-bar-inner, .has-spread .reader-layout { max-width: 1600px; }
.has-spread .reader-layout { grid-template-columns: 190px minmax(0, 1fr); gap: 24px; }
.has-spread .book-frame { max-width: none; }
.has-spread .book:not(.at-overview) .book-spread { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; }
.has-spread .reader-layout .leaf { padding: 28px 32px; min-width: 0; box-shadow: none; }
.has-spread .reader-layout .edge { width: 28px; }
.has-spread .running { flex-wrap: wrap; gap: 8px; letter-spacing: .08em; }
.has-spread .step { grid-template-columns: 28px minmax(0, 1fr); }
.has-spread .step .done { grid-column: 2; justify-self: start; }
.has-spread .figure-art svg { min-width: 0; max-width: 100%; }
.has-spread .at-overview .reader-layout { grid-template-columns: minmax(0, 1fr); }
.has-spread .at-overview .leaf { padding: 16px 0 0; }

/* Scroll starts with an overview, then one chapter. Whole guide is an explicit choice. */
.reader-ready[data-scope="chapter"][data-location="chapter"] .hero,
.reader-ready[data-scope="chapter"][data-location="chapter"] .contents,
.reader-ready[data-scope="chapter"][data-location="chapter"] .ribbon { display: none; }
.contents small { display: block; margin-top: 8px; font: 400 var(--t-small)/1.5 var(--serif); color: var(--muted); }
body.reader-ready:not([data-mode="book"]) .jump { display: flex; align-items: center; gap: 20px; }
.jump-overview { flex-shrink: 0; padding: 10px 0; font: 600 var(--t-fine)/1.5 var(--sans); }
.jump-field { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.jump-field label { flex-shrink: 0; margin: 0; font-size: var(--t-fine); letter-spacing: 0; text-transform: none; }
.jump-field select { width: 100%; text-overflow: ellipsis; }
.chapter-map { align-self: start; position: sticky; top: 100px; max-height: calc(100vh - 124px); overflow-y: auto; }
.chapter-map > .label { color: var(--accent); }
.chapter-map nav { padding-top: 24px; }
.chapter-map nav .label { letter-spacing: .08em; }
.chapter-map a { display: block; min-height: 44px; padding: 12px 0 12px 12px; border-left: 1px solid var(--line-strong); font: 500 var(--t-fine)/1.5 var(--sans); text-decoration: none; color: var(--muted); }
.chapter-map a[aria-current] { border-color: var(--accent); color: var(--accent); background: var(--surface); }
.reader-ready .chapters-scroll .chapter { padding-top: 40px; gap: 48px; }
.reader-ready .chapters-scroll .page + .page, .reader-ready #resource-list .page { border-top: 1px solid var(--line); margin-top: 36px; padding-top: 32px; }
.reader-ready .chapter-body { min-width: 0; width: 100%; }
.reader-ready .page, .reader-ready .chapter, .reader-ready .hero { scroll-margin-top: 100px; }
.chapter-pagination { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding-top: 24px; padding-bottom: 40px; }
.chapter-pagination a { padding: 12px 0; font: 500 var(--t-fine)/1.5 var(--sans); }
#chapter-next { margin-left: auto; text-align: right; color: var(--accent); }
@media (max-width: 960px) {
  .chapter-map { position: static; max-height: none; }
  .chapter-map nav { display: none; }
  .reader-ready .chapters-scroll .chapter { gap: 20px; }
  .jump-field { display: block; }
  .jump-field label { display: block; margin-bottom: 6px; }
  .reader-ready .page, .reader-ready .chapter { scroll-margin-top: 140px; }
}
@media (max-width: 600px) {
  .reader-ready:not([data-mode="book"]) .jump { flex-wrap: wrap; gap: 8px 16px; }
  .jump-field { flex-basis: calc(100% - 120px); display: flex; }
  .jump-field label { display: none; }
  #topic-control { flex-basis: 100%; }
  #topic-control label { display: block; margin: 0; width: 90px; }
  .chapter-pagination { flex-wrap: wrap; gap: 12px 24px; }
  .chapter-pagination a { max-width: 100%; }
  .reader-layout .leaf-foot { padding-left: 20px; padding-right: 20px; }
}
@media print {
  body { color: #000; background: #fff; }
  .site-head, .reading-bar, .book, .chapter-map nav, .chapter-pagination, .done, .forget { display: none !important; }
  body[data-mode] .hero, body[data-mode] .contents, body[data-mode] .chapters-scroll { display: block !important; }
  body[data-mode] .chapter { display: block !important; break-before: page; }
  .chapter-map { position: static; max-height: none; }
  body[data-mode] .chapter-body, body[data-mode] .wrap { max-width: none; }
  .figure-art { overflow: visible; }
  body[data-mode] .figure-art svg { min-width: 0; }
}

/* The same controls stay in reach at chapter depth and in a half-screen window. */
.reader-ready .page, .reader-ready .chapter, .reader-ready .hero, .reader-ready .leaf { scroll-margin-top: var(--reader-offset, 140px); }
.reader-ready .chapter-map, .reader-ready .chapter-rail { top: var(--reader-offset, 140px); max-height: calc(100vh - var(--reader-offset, 140px) - 24px); }
@media (min-width: 840px) and (max-width: 1399px) {
  .has-spread .reader-layout { grid-template-columns: minmax(0, 1fr); }
  .has-spread .chapter-rail { display: none; }
  .has-spread #book-jump { display: block; }
  .has-spread #reader-location { display: none; }
}
@media (min-width: 840px) and (max-width: 1100px) {
  .reading-switches { gap: 16px; }
  .reading-switch { gap: 7px; }
  .reading-modes .tab { padding: 10px; gap: 6px; }
  .has-spread .reader-layout .leaf { padding: 24px 28px; }
}
@media (max-width: 839px) {
  .reading-controls { flex-wrap: wrap; justify-content: center; gap: 4px; padding: 10px 0; }
  .reading-switches { width: 100%; justify-content: center; gap: 24px; }
  .reading-context { gap: 16px; }
  .reading-context #reader-location { display: none; }
  body[data-mode="book"] .reading-context #book-jump { display: block; }
  .layout-note { display: none; }
}
@media (max-width: 480px) {
  .reading-modes { width: 100%; }
  .reading-modes .modes { justify-content: center; }
  .reading-modes li { flex: 1; }
  .reading-modes .tab { width: 100%; padding: 8px 6px; }
  .reading-switches { gap: 20px; padding-top: 4px; }
  .reading-switch { flex-direction: column; gap: 6px; padding: 4px 0; }
  .switch-track { width: 42px; }
  .reading-switch input:checked + .switch-track .switch-thumb { transform: translateX(14px); }
  .reading-context .reader-home { gap: 6px; }
  .reading-context .reader-home svg { display: none; }
  body .reading-context .jump { flex-wrap: nowrap; gap: 8px; }
  .reading-context .jump-field, .reading-context #topic-control { flex: 1; }
  .reading-context #book-jump, .reading-context .jump select { padding: 8px 4px; }
}

/* Keep every diagram inside its leaf; open a wider view when its labels need more room. */
.diagram-expand { display: none; width: fit-content; min-height: 44px; margin: 0 0 4px auto; padding: 8px 0; border: 0; background: none; color: var(--accent); font: 500 var(--t-fine)/1.5 var(--sans); text-decoration: underline; text-underline-offset: 4px; }
.has-spread .diagram-expand { display: block; }
.diagram-dialog { width: min(1000px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 24px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.diagram-dialog::backdrop { background: rgb(10 18 26 / .75); }
.diagram-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.diagram-dialog-head .label { margin: 0; }
.diagram-dialog-head button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--bg); font: 500 var(--t-fine)/1.5 var(--sans); }
.diagram-dialog .figure { margin: 0; }
.diagram-dialog .figure-art svg { width: 100%; min-width: 0; max-width: 100%; height: auto; }
@media print { .diagram-expand, .diagram-dialog { display: none !important; } }

/* A real sheet has a front and reverse face and pivots on a shared, fixed spine. */
.turn-stage { position: absolute; inset: 0 0 auto; z-index: 3; perspective: 2200px; pointer-events: none; }
.turn-stage.turn-single { overflow: hidden; }
.turn-sheet { position: absolute; top: 0; width: 50%; height: 100%; transform-style: preserve-3d; will-change: transform; }
.reader-layout .turn-paper { position: absolute; top: 0; margin: 0; width: 100%; height: 100%; min-height: 0; overflow: hidden; border-radius: 2px; box-shadow: none; }
.reader-layout .turn-cover { width: 50%; }
.turn-front, .turn-back { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.turn-front { transform: rotateY(0deg); }
.turn-back { transform: rotateY(180deg); }
.turn-front::after, .turn-back::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, rgb(0 0 0 / .28), transparent 60%); animation: sheet-shading 680ms cubic-bezier(.45, 0, .2, 1) both; }
.turn-back::after { background: linear-gradient(270deg, rgb(0 0 0 / .28), transparent 60%); }
@keyframes sheet-shading { 0%, 100% { opacity: 0; } 45%, 55% { opacity: 1; } }
.turn-single .turn-sheet, .reader-layout .turn-single .turn-cover { width: 100%; }
.has-spread .book:not(.at-overview) #leaf { border-right: 0; }
.has-spread .book:not(.at-overview) #second-leaf::before { width: 1px; background: var(--line-strong); }
@media (prefers-reduced-motion: reduce) { .turn-stage { display: none; } }
@media print { .turn-stage { display: none !important; } }

/* Keep the Library destination alongside the reading styles. */
.reading-modes .library-link { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 0 4px; padding: 10px 14px; min-height: 44px; border: 1px solid var(--accent); border-radius: 4px; background: var(--accent); color: var(--bg); font: 600 var(--t-fine)/1.4 var(--sans); letter-spacing: 0; text-transform: none; text-decoration: none; white-space: nowrap; }
.reading-modes .library-link:hover { background: var(--surface); color: var(--accent); }
.reading-modes .library-link svg { width: 18px; height: 18px; }
.turn-ribbon { position: absolute; top: 0; left: 0; height: 100%; transform-origin: left center; transform-style: preserve-3d; will-change: transform; }
.turn-face { position: absolute; inset: 0; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.turn-face::after { content: none; }
.curl-shade { position: absolute; inset: 0; background: #000; pointer-events: none; opacity: 0; }
@media (max-width: 600px) { .reading-modes .library-link { padding: 8px 10px; gap: 6px; } }
@media (max-width: 600px) {
  .reading-modes .modes { display: grid; grid-template-columns: 1.3fr 1fr; width: 100%; gap: 3px; }
  .reading-modes .modes .tab { display: flex; flex-direction: column; justify-content: center; gap: 4px; width: 100%; min-height: 60px; margin: 0; padding: 6px 3px; font-size: 12px; }
  .reading-modes .library-link > span:last-child { display: none; }
}

.reading-modes .book-view-control { padding: 8px 14px; min-height: 44px; }
@media (max-width: 600px) {
  .reading-modes .book-view-control { flex-direction: column; justify-content: center; gap: 4px; min-height: 60px; padding: 6px 3px; font-size: 12px; }
}
