:root {
  --bg: #121012;
  --surface: #1b181b;
  --surface-2: #231f23;
  --line: #322c31;
  --ink: #f2ebe5;
  --ink-2: #c9bfb8;
  --muted: #958a85;
  --orange: #ff8a3d;
  --pink: #ff5c8a;
  --ok: #8fd19e;
  --focus: #ffd2a8;
  --serif: "Iowan Old Style", "Charter", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  overflow-x: hidden;
}

a { color: var(--ink); text-decoration-color: var(--orange); text-underline-offset: 3px; }
a:hover { color: var(--orange); }

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

.skip { position: absolute; left: -9999px; top: 8px; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 6px; z-index: 10; }
.skip:focus { left: 16px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 32px; } }

h1, h2 { font-family: var(--serif); font-weight: 600; line-height: 1.1; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(2.1rem, 7vw, 4.2rem); letter-spacing: -0.01em; }
h2 { font-size: clamp(1.6rem, 4.4vw, 2.3rem); }
p { margin: 0 0 1em; text-wrap: pretty; }
.muted { color: var(--muted); }
.tnum { font-variant-numeric: tabular-nums; }

/* Hero */
.hero { display: grid; gap: 24px; padding-top: 48px; padding-bottom: 32px; align-items: end; }
.hero-text { max-width: 760px; }
.kicker { color: var(--orange); font-size: 0.95rem; margin-bottom: 18px; }
.lede { font-size: 1.15rem; color: var(--ink-2); margin-top: 24px; max-width: 640px; }
.sunset { width: 160px; height: auto; order: -1; }
.sunset .sun { fill: var(--orange); }
.sunset .band { fill: var(--bg); }
.sunset .horizon { fill: var(--pink); }
.sunset .water { fill: var(--pink); opacity: 0.55; }
@media (min-width: 900px) {
  .hero { grid-template-columns: 1fr 240px; padding-top: 88px; padding-bottom: 48px; }
  .sunset { width: 240px; order: 0; }
}

/* Facts */
.facts { padding-bottom: 40px; }
.asof { color: var(--muted); font-size: 0.9rem; }
.fact-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 0; }
@media (min-width: 560px) { .fact-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .fact-grid { grid-template-columns: repeat(4, 1fr); } }
.fact { background: var(--surface); border-radius: var(--radius); padding: 18px; }
.fact dt { color: var(--muted); font-size: 0.9rem; }
.fact dd { margin: 0; font-size: 0.92rem; color: var(--ink-2); line-height: 1.5; }
.fact dd.big { font-family: var(--serif); font-size: 1.6rem; color: var(--ink); margin: 4px 0 10px; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 0.78rem; padding: 1px 8px; border-radius: 999px; margin-right: 6px; border: 1px solid currentColor; line-height: 1.5; }
.tag::before { margin-right: 4px; }
.tag-ok { color: var(--ok); }
.tag-ok::before { content: "✓"; }
.tag-rep { color: var(--orange); }
.tag-rep::before { content: "~"; }
.tag-est { color: var(--pink); }
.tag-est::before { content: "?"; }

/* Section heads */
.section-head { max-width: 720px; margin-bottom: 24px; }
.section-head p:last-child { color: var(--ink-2); }
.num { color: var(--orange); font-variant-numeric: tabular-nums; font-size: 0.95rem; margin-bottom: 8px; }
.section-head h2 { margin-bottom: 14px; }

/* Diagram */
.flow, .math { padding-top: 40px; padding-bottom: 40px; }
.diagram-card { background: var(--surface); border-radius: var(--radius); padding: 16px; }
@media (min-width: 720px) { .diagram-card { padding: 24px; } }
.controls { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.seg {
  font: inherit; font-size: 0.92rem; color: var(--ink-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer;
  min-height: 36px; touch-action: manipulation;
}
.seg:hover { color: var(--ink); }
.seg[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 0.92rem; color: var(--ink-2); cursor: pointer; min-height: 36px; }
.switch input { width: 18px; height: 18px; accent-color: var(--orange); margin: 0; }

.diagram { width: 100%; margin: 8px 0 4px; }
.diagram svg { display: block; width: 100%; height: auto; overflow: visible; }
.d-link { fill: none; stroke: var(--line); stroke-linecap: round; transition: stroke-width 300ms ease, stroke 300ms ease; }
.d-link.hot { stroke: #5a3a2c; }
.d-link.dashed { stroke-dasharray: 4 6; }
.d-node rect { fill: var(--surface-2); stroke: var(--line); }
.d-node.pub rect { stroke: var(--orange); }
.d-node.off rect { stroke-dasharray: 4 4; }
.d-node.off text { fill: var(--muted); }
.d-node.bypass rect { opacity: 0.35; }
.d-node.bypass text { fill: var(--muted); }
.d-node text { fill: var(--ink); font-family: var(--sans); font-size: 13px; }
.d-node text.sub { fill: var(--muted); font-size: 11px; }
.d-tier { fill: var(--muted); font-family: var(--sans); font-size: 12px; paint-order: stroke; stroke: var(--surface); stroke-width: 5px; stroke-linejoin: round; }
.d-home rect { fill: var(--surface-2); stroke: var(--line); }
.d-home.ready rect { stroke: var(--orange); }
.d-home.locked path { fill: var(--muted); }
.d-home.unlocked path { fill: var(--pink); }
.p-data { fill: var(--orange); }
.p-key { fill: var(--pink); }

.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.dot-data { background: var(--orange); }
.dot-key { background: var(--pink); }
.readout { border-top: 1px solid var(--line); padding-top: 14px; }
.caption { color: var(--ink-2); min-height: 3.2em; max-width: 760px; }
.loadline { margin: 0; font-size: 0.92rem; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; }
.loadline strong { font-size: 1.3rem; color: var(--ink); }

/* Calculator */
.calc { display: grid; gap: 16px; }
@media (min-width: 900px) { .calc { grid-template-columns: 1fr 1fr; gap: 24px; } }
.sliders { background: var(--surface); border-radius: var(--radius); padding: 18px; display: grid; gap: 18px; }
.slider label { display: flex; justify-content: space-between; gap: 12px; font-size: 0.95rem; color: var(--ink-2); }
.slider output { color: var(--ink); font-weight: 600; }
.slider input[type="range"] { width: 100%; margin: 10px 0 0; accent-color: var(--orange); height: 28px; touch-action: manipulation; }
.hint { font-size: 0.82rem; color: var(--muted); margin: 4px 0 0; }
.results { display: grid; gap: 12px; }
.result { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; }
.r-label { font-size: 0.9rem; color: var(--muted); margin: 0; }
.r-val { font-family: var(--serif); font-size: clamp(1.9rem, 6vw, 2.6rem); line-height: 1.1; margin: 4px 0 6px; }
.r-sub { margin: 0; color: var(--ink-2); font-size: 0.92rem; }
.accent-pink { color: var(--pink); }

.chart-card { margin: 24px 0 0; background: var(--surface); border-radius: var(--radius); padding: 16px; }
@media (min-width: 720px) { .chart-card { padding: 24px; } }
.chart-card figcaption { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; margin-bottom: 8px; }
.chart-title { font-weight: 600; }
.chart-key { display: flex; gap: 16px; font-size: 0.85rem; color: var(--ink-2); }
.line { display: inline-block; width: 18px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.line-no { background: var(--pink); }
.line-yes { background: var(--orange); }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-axis { fill: var(--muted); font-family: var(--sans); font-size: 11px; font-variant-numeric: tabular-nums; }
.c-ref { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 4; }
.c-ref-label { fill: var(--ink-2); font-family: var(--sans); font-size: 11px; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.c-no { fill: none; stroke: var(--pink); stroke-width: 2; }
.c-yes { fill: none; stroke: var(--orange); stroke-width: 2; }
.c-yes-area { fill: var(--orange); opacity: 0.16; }
.c-launch { stroke: var(--ink); stroke-width: 1; }
.c-launch-label { fill: var(--ink); font-family: var(--sans); font-size: 11px; }
.c-cursor { stroke: var(--ink-2); stroke-width: 1; }
.c-hit { fill: transparent; }
.chart-read { font-size: 0.88rem; color: var(--ink-2); margin: 8px 0 6px; min-height: 1.6em; }
.fine { font-size: 0.85rem; color: var(--muted); margin: 0; max-width: 760px; }

.compare { margin-top: 24px; background: var(--surface); border-radius: var(--radius); padding: 18px; }
.compare h3 { font-size: 1rem; margin: 0 0 14px; font-weight: 600; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin-bottom: 14px; font-size: 0.9rem; }
.bar-row:last-child { margin-bottom: 0; }
.bar-name { color: var(--ink-2); }
.bar-val { color: var(--ink); font-variant-numeric: tabular-nums; text-align: right; }
.bar-track { grid-column: 1 / -1; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--muted); }
.bar-fill.you { background: var(--pink); }
.bar-fill.you-pre { background: var(--orange); }
.compare .fine { margin-top: 12px; }

/* Chapters */
.chapters { padding-top: 24px; padding-bottom: 24px; display: grid; gap: 48px; }
.chapter { max-width: 720px; }
.chapter h2 { margin-bottom: 18px; }
.chapter p { color: var(--ink-2); }
.chapter strong { color: var(--ink); font-weight: 600; }
.plain { padding-left: 0; list-style: none; margin: 0 0 1em; display: grid; gap: 12px; color: var(--ink-2); }
.plain li { padding-left: 18px; position: relative; }
.plain li::before { content: ""; position: absolute; left: 0; top: 0.72em; width: 7px; height: 7px; border-radius: 50%; background: var(--orange); }
.aside { font-size: 0.92rem; color: var(--muted) !important; }
@media (min-width: 1000px) {
  .chapters { grid-template-columns: 1fr 1fr; column-gap: 64px; row-gap: 56px; }
}

/* Sources */
.sources { padding-top: 48px; padding-bottom: 32px; }
.sources h2 { font-size: 1.5rem; margin-bottom: 16px; }
.source-list { padding-left: 1.4em; margin: 0 0 40px; display: grid; gap: 8px; font-size: 0.9rem; color: var(--muted); max-width: 820px; overflow-wrap: anywhere; }
.source-list a { color: var(--ink-2); }
.unverified li::before { background: var(--pink); }
.unverified { font-size: 0.92rem; max-width: 820px; }

.footer { padding-top: 32px; padding-bottom: 56px; font-size: 0.88rem; color: var(--ink-2); border-top: 1px solid var(--line); margin-top: 24px; }
.footer p { max-width: 820px; }

.notfound { padding-top: 120px; padding-bottom: 120px; }
.notfound h1 { margin-bottom: 24px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
