:root {
  color-scheme: light;
  --paper: #f3efe5;
  --paper-deep: #e6e0d3;
  --panel: #ebe5d9;
  --ink: #191914;
  --muted: #6e6c64;
  --line: #aaa598;
  --hairline: rgba(25, 25, 20, 0.2);
  --coral: #ff705c;
  --coral-soft: #ffc0b4;
  --lime: #d6f18e;
  --lime-deep: #9bbd45;
  --accent: var(--coral);
  --display: Georgia, "Times New Roman", serif;
  --sans: "Helvetica Neue", Helvetica, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --masthead: 4.5rem;
  --gutter: clamp(1.15rem, 4vw, 3.5rem);
  --max-copy: 46rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #171713;
  --paper-deep: #22221c;
  --panel: #202019;
  --ink: #eee9dd;
  --muted: #aaa79d;
  --line: #5a594f;
  --hairline: rgba(238, 233, 221, 0.18);
  --coral: #ff846f;
  --coral-soft: #68372f;
  --lime: #c5e47d;
  --lime-deep: #92ac54;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;
    --paper: #171713;
    --paper-deep: #22221c;
    --panel: #202019;
    --ink: #eee9dd;
    --muted: #aaa79d;
    --line: #5a594f;
    --hairline: rgba(238, 233, 221, 0.18);
    --coral: #ff846f;
    --coral-soft: #68372f;
    --lime: #c5e47d;
    --lime-deep: #92ac54;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--masthead) + 1rem); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}
body[data-accent="lime"] { --accent: var(--lime); }
body[data-accent="ink"] { --accent: var(--ink); }
body.menu-open { overflow: hidden; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .2em; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
img, svg { display: block; max-width: 100%; }
::selection { background: var(--accent); color: #171713; }

:focus-visible {
  outline: 3px solid var(--coral);
  outline-offset: 4px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: .75rem;
  left: .75rem;
  padding: .75rem 1rem;
  transform: translateY(-180%);
  background: var(--ink);
  color: var(--paper);
  font: 700 .75rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.skip-link:focus { transform: translateY(0); }

.reading-progress {
  position: fixed;
  z-index: 80;
  inset: 0 0 auto;
  height: 3px;
  background: transparent;
}
.reading-progress span { display: block; width: 0; height: 100%; background: var(--coral); }

.masthead {
  position: sticky;
  z-index: 60;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: var(--masthead);
  padding: .75rem var(--gutter);
  border-bottom: 1px solid var(--ink);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(12px);
}
.wordmark {
  display: inline-flex;
  gap: .7rem;
  align-items: center;
  width: max-content;
  text-decoration: none;
}
.wordmark-symbol {
  display: grid;
  place-items: center;
  width: 2.4rem;
  aspect-ratio: 1;
  border: 1px solid var(--ink);
  background: var(--accent);
  color: #171713;
  font: 700 .9rem/1 var(--mono);
}
.wordmark strong, .wordmark small { display: block; line-height: 1; }
.wordmark strong { font-size: .84rem; letter-spacing: .12em; }
.wordmark small { margin-top: .3rem; color: var(--muted); font: 500 .58rem/1 var(--mono); letter-spacing: .08em; }
.masthead-state { display: none; margin: 0; font: 500 .62rem/1 var(--mono); letter-spacing: .08em; }
.masthead-state span { display: inline-block; width: .55rem; height: .55rem; margin-right: .5rem; border-radius: 50%; background: var(--lime-deep); }
.masthead-actions { display: flex; align-items: center; gap: .35rem; }
.icon-button, .menu-button {
  min-height: 44px;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
}
.icon-button { width: 44px; font-size: 1.15rem; }
.menu-button { display: inline-flex; gap: .8rem; align-items: center; padding: 0 .85rem; font: 600 .7rem/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; }
.menu-button i, .menu-button i::before {
  display: block;
  width: 1rem;
  height: 1px;
  background: currentColor;
  transition: transform .25s var(--ease);
  content: "";
}
.menu-button i::before { transform: translateY(5px); }
.menu-button[aria-expanded="true"] i { transform: rotate(45deg); }
.menu-button[aria-expanded="true"] i::before { transform: rotate(90deg); }

.site-frame { min-height: calc(100vh - var(--masthead)); }
.chapter-rail {
  position: fixed;
  z-index: 50;
  inset: var(--masthead) 0 0;
  overflow-y: auto;
  padding: 1.5rem var(--gutter) 3rem;
  transform: translateX(105%);
  background: var(--paper-deep);
  transition: transform .35s var(--ease);
}
.chapter-rail.is-open { transform: translateX(0); }
.rail-label, .section-index, .hero-meta, .rail-foot {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: .07em;
}
.rail-label { margin: 0 0 1rem; color: var(--muted); font-size: .65rem; }
.chapter-rail ol { margin: 0; padding: 0; border-top: 1px solid var(--ink); list-style: none; }
.chapter-rail li { border-bottom: 1px solid var(--line); }
.chapter-rail a {
  display: grid;
  grid-template-columns: 2.5rem 1fr;
  align-items: center;
  min-height: 3.4rem;
  padding: .55rem 0;
  text-decoration: none;
}
.chapter-rail a span { color: var(--muted); font: 500 .65rem/1 var(--mono); }
.chapter-rail a strong { font-size: .92rem; }
.chapter-rail a[aria-current="page"] strong { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: .45rem; text-underline-offset: -.18rem; text-decoration-skip-ink: none; }
.rail-foot { max-width: 24rem; margin: 2rem 0 0; color: var(--muted); font-size: .62rem; }

.article { min-width: 0; }
.chapter-hero { padding: clamp(3rem, 8vw, 7.5rem) var(--gutter) clamp(3rem, 7vw, 6rem); border-bottom: 1px solid var(--ink); }
.hero-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem; margin-bottom: clamp(2.5rem, 7vw, 6rem); font-size: .66rem; }
.hero-meta p { margin: 0; }
.hero-meta span { padding: .35rem .55rem; border: 1px solid var(--ink); background: var(--accent); color: #171713; }
.chapter-hero h1 {
  max-width: 15ch;
  margin: 0;
  font: 600 clamp(3.25rem, 13vw, 8.8rem)/.89 var(--display);
  letter-spacing: -.055em;
}
.hero-dek { max-width: 38rem; margin: clamp(2rem, 5vw, 4rem) 0 0 auto; font-size: clamp(1.2rem, 2.4vw, 1.65rem); line-height: 1.35; }
.hero-note { display: grid; grid-template-columns: .8rem 1fr; gap: 1rem; max-width: 38rem; margin: 2rem 0 0 auto; padding-top: 1rem; border-top: 1px solid var(--ink); }
.hero-note span { width: .72rem; height: .72rem; margin-top: .42rem; background: var(--accent); }
.hero-note p { margin: 0; color: var(--muted); }

.section-tabs {
  position: sticky;
  z-index: 30;
  top: var(--masthead);
  display: flex;
  gap: 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
  scrollbar-width: thin;
}
.section-tabs a {
  flex: 0 0 auto;
  min-height: 44px;
  padding: .82rem 1rem;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font: 600 .65rem/1.2 var(--mono);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.section-tabs a[aria-current="location"] { background: var(--accent); color: #171713; }
.chapter-section { padding: clamp(3.5rem, 8vw, 7rem) var(--gutter); border-bottom: 1px solid var(--ink); }
.section-head { display: grid; gap: 1rem; margin-bottom: clamp(2.5rem, 5vw, 4.5rem); }
.section-index { margin: 0; color: var(--muted); font-size: .65rem; }
.section-head h2 { max-width: 16ch; margin: 0; font: 600 clamp(2.45rem, 7vw, 5rem)/.98 var(--display); letter-spacing: -.04em; }
.section-body { max-width: 78rem; }
.section-body > p, .section-body > ul, .section-body > ol, .section-body > blockquote { max-width: var(--max-copy); }
.section-body > p:first-child { margin-top: 0; font-size: 1.12rem; }
.section-body p + p { margin-top: 1.25rem; }
.section-body h3 { margin: 2.4rem 0 .75rem; font-size: 1.25rem; line-height: 1.2; }
.section-body code { padding: .1em .3em; background: var(--paper-deep); font: .86em/1.5 var(--mono); }
.section-body ul, .section-body ol { padding-left: 1.2rem; }
.section-body li { margin: .55rem 0; }

.metric-grid, .card-grid, .comparison-grid, .split-grid, .shot-grid { display: grid; gap: 1rem; margin: 2.5rem 0; }
.metric, .evidence-card, .comparison-card, .shot-card {
  min-width: 0;
  padding: 1.25rem;
  border: 1px solid var(--ink);
  background: var(--panel);
}
.metric { min-height: 10rem; display: flex; flex-direction: column; justify-content: space-between; }
.metric strong { font: 600 clamp(2.7rem, 8vw, 5rem)/1 var(--display); letter-spacing: -.05em; }
.metric span, .card-kicker { color: var(--muted); font: 500 .65rem/1.4 var(--mono); text-transform: uppercase; letter-spacing: .07em; }
.metric.accent { background: var(--accent); color: #171713; }
.metric.accent span { color: #34342c; }
.evidence-card h3, .comparison-card h3, .shot-card h3 { margin: .9rem 0 .65rem; font-size: 1.2rem; }
.evidence-card p, .comparison-card p, .shot-card p { margin: 0; color: var(--muted); }

.pipeline { display: grid; gap: 0; margin: 2.5rem 0; border: 1px solid var(--ink); }
.flow-node { position: relative; padding: 1.3rem; border-bottom: 1px solid var(--ink); }
.flow-node:last-child { border-bottom: 0; }
.flow-node span { display: block; margin-bottom: .55rem; color: var(--muted); font: 500 .62rem/1 var(--mono); text-transform: uppercase; letter-spacing: .07em; }
.flow-node strong { display: block; font-size: 1.05rem; }
.flow-node p { margin: .5rem 0 0; color: var(--muted); font-size: .92rem; }
.flow-node.highlight { background: var(--accent); color: #171713; }
.flow-node.highlight span, .flow-node.highlight p { color: #35352e; }

.callout, .claim-box, .quote-box { max-width: 56rem; margin: 2.5rem 0; padding: 1.4rem; border-left: .7rem solid var(--accent); background: var(--paper-deep); }
.callout strong, .claim-box strong { display: block; margin-bottom: .5rem; font: 700 .72rem/1.2 var(--mono); text-transform: uppercase; letter-spacing: .07em; }
.callout p, .claim-box p { margin: 0; }
.claim-box { border: 1px solid var(--ink); border-left-width: .7rem; }
.quote-box blockquote { margin: 0; font: 500 clamp(1.5rem, 4vw, 2.45rem)/1.15 var(--display); letter-spacing: -.025em; }
.quote-box cite { display: block; margin-top: 1rem; color: var(--muted); font: normal .65rem/1.4 var(--mono); text-transform: uppercase; }

.timeline { margin: 2.5rem 0; border-top: 1px solid var(--ink); }
.timeline article { display: grid; grid-template-columns: 4.5rem 1fr; gap: 1rem; padding: 1.2rem 0; border-bottom: 1px solid var(--line); }
.timeline time { font: 500 .7rem/1.4 var(--mono); }
.timeline h3 { margin: 0 0 .35rem; }
.timeline p { margin: 0; color: var(--muted); }

.table-wrap { margin: 2.5rem 0; overflow-x: auto; border: 1px solid var(--ink); }
table { width: 100%; min-width: 42rem; border-collapse: collapse; }
th, td { padding: .9rem 1rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--paper-deep); font: 600 .66rem/1.4 var(--mono); text-transform: uppercase; letter-spacing: .06em; }
tr:last-child td { border-bottom: 0; }

.sample-output { margin: 2rem 0; border: 1px solid var(--ink); }
.sample-output header { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem 1rem; border-bottom: 1px solid var(--ink); background: var(--ink); color: var(--paper); font: 500 .65rem/1.3 var(--mono); text-transform: uppercase; }
.sample-output pre { margin: 0; padding: 1.2rem; overflow-x: auto; white-space: pre-wrap; font: .84rem/1.7 var(--mono); }
.copy-button { min-height: 44px; padding: .4rem .75rem; border: 1px solid currentColor; background: transparent; color: inherit; cursor: pointer; }

details { max-width: 56rem; margin: 1rem 0; border: 1px solid var(--line); }
summary { min-height: 44px; padding: .85rem 1rem; cursor: pointer; font-weight: 700; }
details > div { padding: 0 1rem 1rem; color: var(--muted); }

.status-strip { display: flex; flex-wrap: wrap; gap: .5rem; margin: 2rem 0; }
.status-strip span { padding: .5rem .7rem; border: 1px solid var(--ink); font: 600 .65rem/1 var(--mono); text-transform: uppercase; }
.status-strip .done { background: var(--lime); color: #171713; }
.status-strip .pending { background: var(--coral-soft); color: #171713; }

.chapter-pager { display: grid; grid-template-columns: 1fr; border-bottom: 1px solid var(--ink); }
.pager-link { min-height: 8rem; padding: 1.5rem var(--gutter); border-top: 1px solid var(--ink); text-decoration: none; }
.pager-link span { display: block; margin-bottom: 1rem; color: var(--muted); font: 500 .65rem/1 var(--mono); text-transform: uppercase; }
.pager-link strong { font: 600 2rem/1 var(--display); }
.pager-link.next { text-align: right; background: var(--accent); color: #171713; }
.pager-link.next span { color: #35352e; }
.pager-spacer { display: none; }

.not-found { min-height: calc(100vh - var(--masthead)); padding: clamp(4rem, 12vw, 10rem) var(--gutter); }
.not-found h1 { max-width: 8ch; margin: 1rem 0; font: 600 clamp(4rem, 16vw, 9rem)/.88 var(--display); letter-spacing: -.055em; }
.button-link { display: inline-flex; align-items: center; min-height: 44px; margin-top: 2rem; padding: .75rem 1rem; border: 1px solid var(--ink); background: var(--accent); color: #171713; font-weight: 700; text-decoration: none; }

.site-footer { display: grid; gap: 1.5rem; padding: 2.5rem var(--gutter); background: var(--ink); color: var(--paper); font-size: .85rem; }
.site-footer p { margin: 0; }
.site-footer span { color: var(--muted); font: 500 .62rem/1 var(--mono); text-transform: uppercase; }
.site-footer a { align-self: end; }

@media (min-width: 48rem) {
  .masthead { grid-template-columns: 1fr auto 1fr; }
  .masthead-state { display: block; }
  .masthead-actions { justify-self: end; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid, .comparison-grid, .split-grid, .shot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline { grid-template-columns: repeat(2, 1fr); }
  .flow-node { border-right: 1px solid var(--ink); }
  .flow-node:nth-child(2n) { border-right: 0; }
  .flow-node:nth-last-child(-n + 2) { border-bottom: 0; }
  .section-head { grid-template-columns: minmax(9rem, 1fr) minmax(0, 3fr); align-items: start; }
  .chapter-pager { grid-template-columns: 1fr 1fr; }
  .pager-link { border-right: 1px solid var(--ink); }
  .pager-spacer { display: block; border-top: 1px solid var(--ink); }
  .site-footer { grid-template-columns: 2fr 1fr 1fr; }
}

@media (min-width: 72rem) {
  :root { --masthead: 5rem; }
  .menu-button { display: none; }
  body.menu-open { overflow: auto; }
  .site-frame { display: grid; grid-template-columns: minmax(14rem, 19rem) minmax(0, 1fr); }
  .chapter-rail {
    position: sticky;
    z-index: 20;
    top: var(--masthead);
    align-self: start;
    height: calc(100vh - var(--masthead));
    padding: 2.25rem 1.5rem;
    transform: none;
    border-right: 1px solid var(--ink);
    background: var(--paper-deep);
  }
  .chapter-rail a { grid-template-columns: 2.25rem 1fr; }
  .chapter-rail a:hover strong { transform: translateX(.3rem); }
  .chapter-rail a strong { transition: transform .2s var(--ease); }
  .chapter-hero, .chapter-section { padding-left: clamp(3rem, 7vw, 8rem); padding-right: clamp(3rem, 7vw, 8rem); }
  .section-tabs { top: var(--masthead); }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
  .card-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pipeline { grid-template-columns: repeat(4, 1fr); }
  .flow-node, .flow-node:nth-child(2n) { border-right: 1px solid var(--ink); border-bottom: 0; }
  .flow-node:last-child { border-right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  .masthead, .chapter-rail, .section-tabs, .reading-progress, .chapter-pager, .site-footer { display: none !important; }
  body { background: white; color: black; }
  .chapter-hero, .chapter-section { padding: 2rem 0; }
  .chapter-section { break-inside: avoid; }
}
