/* Each chapter sets its own palette on <body data-ch>; everything below reads these variables,
   so the page (charts included) re-colours smoothly as you scroll between chapters. */
:root {
  --less: #e0612d; --more: #2a6fcf; --violet: #4a3aa7;
  --bg: #f4f1ea; --card: #fffdf9; --ink: #16181d; --ink2: #464b55; --muted: #747a85; --rule: #dcd6cb;
  --add-bg: #e1ebf8; --drop-bg: #fbe4d9; --shadow: 0 10px 30px rgba(30, 25, 15, .10), 0 1px 3px rgba(30, 25, 15, .08);
}
body[data-ch="dir"] { --bg: #eaf0f6; --card: #ffffff; --rule: #d3dce7; --ink2: #434b58; }
body[data-ch="noise"] {
  --bg: #0f1724; --card: #172235; --ink: #eef2f7; --ink2: #c3cad6; --muted: #8e99aa; --rule: #283449;
  --less: #f07a4a; --more: #5b9cf0; --add-bg: #1d3557; --drop-bg: #4a2a1c; --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
body[data-ch="adds"] { --bg: #f2edf3; --card: #fffcff; --rule: #ddd3df; }
body[data-ch="record"] { --bg: #e9f1ee; --card: #fbfffd; --rule: #cfddd7; --ink2: #43504b; }
body[data-ch="end"] { --bg: #f4f1ea; }
@media (prefers-color-scheme: dark) {
  :root, body[data-ch="intro"], body[data-ch="case"], body[data-ch="end"] {
    --less: #f07a4a; --more: #5b9cf0; --violet: #9085e9;
    --bg: #17171a; --card: #212126; --ink: #f2f2f4; --ink2: #c8c8d0; --muted: #9a9aa6; --rule: #33333b;
    --add-bg: #1d3557; --drop-bg: #4a2a1c; --shadow: 0 10px 30px rgba(0, 0, 0, .4);
  }
  body[data-ch="dir"] { --bg: #131a24; --card: #1c2533; --ink: #f2f4f7; --ink2: #c4cbd6; --muted: #95a0b0; --rule: #2b3646; --less: #f07a4a; --more: #5b9cf0; --add-bg: #1d3557; --drop-bg: #4a2a1c; --shadow: 0 10px 30px rgba(0,0,0,.4); }
  body[data-ch="noise"] { --bg: #070b12; --card: #111a28; }
  body[data-ch="record"] { --bg: #111c18; --card: #1a2823; --ink: #f1f6f4; --ink2: #c3d0cb; --muted: #94a59e; --rule: #2b3d36; --less: #f07a4a; --more: #5b9cf0; --add-bg: #1d3557; --drop-bg: #4a2a1c; --shadow: 0 10px 30px rgba(0,0,0,.4); }
  body[data-ch="adds"] { --bg: #1b1520; --card: #251d2b; --ink: #f4f1f6; --ink2: #cdc5d2; --muted: #a197a8; --rule: #3a3141; --less: #f07a4a; --more: #5b9cf0; --add-bg: #1d3557; --drop-bg: #4a2a1c; --shadow: 0 10px 30px rgba(0,0,0,.4); }
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-text-size-adjust: 100%; transition: background-color .7s ease, color .7s ease; }
p { margin: 0 0 14px; }
b { color: var(--ink); }

/* reading progress */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 30px; z-index: 20; pointer-events: none; }
.progress .bar { height: 3px; width: 0; background: var(--ink); transition: background-color .7s; }
.progress span { position: absolute; top: 9px; right: 16px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* opening */
.hero-scrolly .fig.full { position: sticky; top: 0; height: 100svh; z-index: 0; }
.dots { position: absolute; inset: 0; }
.dots svg { width: 100%; height: 100%; display: block; }
.dots text { fill: var(--ink); transition: fill .7s; }
.hero-card { max-width: 640px; }
.kicker { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }
h1 { font-size: clamp(32px, 5.6vw, 58px); line-height: 1.06; margin: 0 0 18px; letter-spacing: -0.02em; text-wrap: balance; }
.answer { font-size: clamp(18px, 2.4vw, 21px); line-height: 1.45; color: var(--ink2); }
.scroll-cue { font-size: 14px; color: var(--muted); margin: 18px 0 0; animation: bob 1.8s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(6px); } }

/* chapter openers */
.opener { min-height: 92svh; display: flex; flex-direction: column; justify-content: center; max-width: 1100px; margin: 0 auto; padding: 0 24px; }
.opener .part { font-size: 14px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.opener h2 { font-size: clamp(44px, 9vw, 104px); line-height: .98; letter-spacing: -0.03em; margin: 0 0 18px; }
.opener .dek { font-size: clamp(19px, 2.6vw, 26px); color: var(--ink2); max-width: 26em; margin: 0; }

/* scroll-driven chapters: graphic pinned, text cards scroll over it */
.scrolly { position: relative; max-width: 1240px; margin: 0 auto; padding: 0 18px; }
.fig { position: sticky; top: 0; height: 100svh; z-index: 0; display: flex; flex-direction: column; padding-top: 44px; }
.fig-inner { width: 100%; }
.steps { position: relative; z-index: 2; margin-top: -100svh; pointer-events: none; }
.step { min-height: 100svh; display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 7svh; }
.step:last-child { min-height: 115svh; }
.card { pointer-events: auto; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 18px 20px; max-width: 520px; transition: background-color .7s; }
.card h3 { font-size: 20px; line-height: 1.22; margin: 0 0 8px; text-wrap: balance; }
.card p { font-size: 16.5px; line-height: 1.5; color: var(--ink2); margin: 0; }
.card .n { font-size: 12px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px; display: block; }
.hero-scrolly .steps .step { justify-content: center; padding-bottom: 0; }
.hero-scrolly .step.title-step { min-height: 110svh; }
@media (min-width: 900px) {
  .scrolly { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); column-gap: 56px; }
  .scrolly .fig { grid-column: 2; grid-row: 1; justify-content: center; padding-top: 0; }
  .scrolly .steps { grid-column: 1; grid-row: 1; margin-top: 0; }
  .scrolly .step { justify-content: center; padding-bottom: 0; min-height: 95vh; }
  .scrolly .step:first-child { margin-top: 10vh; }
  .card { padding: 26px 28px; }
  .card h3 { font-size: 26px; }
  .card p { font-size: 18.5px; }
  .hero-scrolly { display: block; max-width: none; padding: 0; }
  .hero-scrolly .steps { margin-top: -100svh; }
  .hero-scrolly .step { padding: 0 6vw; }
  .hero-card { padding: 34px 38px; max-width: 680px; }
}

/* the example case */
.fig-title { font-size: 16px; font-weight: 700; margin: 0 0 8px; }
.fig-title span { font-weight: 400; color: var(--muted); font-size: 13.5px; margin-left: 6px; }
.seg.mini { display: inline-flex; border-radius: 99px; overflow: hidden; margin-bottom: 10px; background: var(--card); box-shadow: var(--shadow); }
.seg.mini span { font-size: 13px; padding: 6px 14px; color: var(--muted); transition: background-color .3s, color .3s; }
.seg.mini span.on { background: var(--ink); color: var(--bg); }
.case-box { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 16px 18px; transition: background-color .7s; }
dl { margin: 0; display: grid; gap: 9px; font-size: 15px; line-height: 1.4; }
dt { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
dd { margin: 1px 0 0; }
.prompt dd { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13.5px; }
.changed { background: var(--add-bg); border-radius: 4px; padding: 3px 6px; margin: -1px -6px; display: block; }
.changed mark { background: var(--more); color: #fff; border-radius: 3px; padding: 0 3px; }
.plan ul { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 5px 6px; }
.plan li { border: 1px solid var(--rule); border-radius: 99px; padding: 2px 10px; font-size: 13.5px; }
.plan li.add { background: var(--add-bg); border-color: var(--more); }
.plan li.add::before { content: "+ "; color: var(--more); font-weight: 700; }
.plan li.drop { background: var(--drop-bg); border-color: var(--less); text-decoration: line-through; text-decoration-color: var(--less); color: var(--ink2); }
.none { color: var(--muted); font-size: 13.5px; }
.score { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--rule); font-size: 13px; }
.score span { padding: 3px 10px; border-radius: 99px; background: var(--rule); color: var(--ink2); }
.score span.add { background: var(--more); color: #fff; }
.score span.mix { background: linear-gradient(90deg, var(--less) 50%, var(--more) 50%); color: #fff; }
@media (min-width: 900px) {
  dl { font-size: 16px; gap: 11px; }
  .prompt dd { font-size: 14.5px; }
  .plan li { font-size: 14.5px; }
  .case-box { padding: 22px 24px; }
}

/* charts: no boxes, drawn straight on the page */
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13.5px; color: var(--ink2); margin: 0 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 16px; height: 11px; border-radius: 3px; display: inline-block; }
.sw.less { background: var(--less); } .sw.more { background: var(--more); }
.tick { width: 3px; height: 16px; background: var(--ink); display: inline-block; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.hollow { border: 2.5px solid var(--muted); background: var(--bg); }
.dot.real { background: var(--more); }
.dot.diamond { border-radius: 0; background: var(--ink); transform: rotate(45deg) scale(.8); }
.chart svg { display: block; width: 100%; height: auto; font-family: inherit; overflow: visible; }
.chart text { fill: var(--ink); transition: fill .7s; }
.chart .m { fill: var(--muted); }
.chart .grid { stroke: var(--rule); transition: stroke .7s; }
.chart .axis0 { stroke: var(--ink); transition: stroke .7s; }
.chart .f-less { fill: var(--less); } .chart .f-more { fill: var(--more); }
.chart .s-less { stroke: var(--less); } .chart .s-more { stroke: var(--more); }
.chart .f-ink { fill: var(--ink); } .chart .s-ink { stroke: var(--ink); }
.chart .hollow { fill: var(--bg); stroke: var(--muted); transition: fill .7s; }
.chart .ring { stroke: var(--bg); transition: stroke .7s; }
.chart .hit { fill: transparent; }
.tip { position: fixed; z-index: 30; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 13.5px; line-height: 1.4; padding: 8px 10px; border-radius: 6px; max-width: 260px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.tip b { display: block; margin-bottom: 2px; color: inherit; }

/* closing */
.plain { max-width: 860px; margin: 0 auto; padding: 72px 22px 40px; }
.plain h2 { font-size: clamp(30px, 5vw, 48px); line-height: 1.08; letter-spacing: -0.02em; margin: 0 0 24px; }
.summary { min-height: 80svh; display: flex; flex-direction: column; justify-content: center; }
.short { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 14px; }
.short li { counter-increment: s; background: var(--card); box-shadow: var(--shadow); border-radius: 12px; padding: 18px 20px 18px 64px; position: relative; font-size: clamp(17px, 2.3vw, 20px); line-height: 1.42; }
.short li::before { content: counter(s); position: absolute; left: 20px; top: 14px; font-size: 28px; font-weight: 800; color: var(--more); }
.fine { font-size: 13.5px; color: var(--muted); line-height: 1.45; margin-top: 12px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 6px 0 22px; }
.facts div { background: var(--card); box-shadow: var(--shadow); border-radius: 12px; padding: 14px 16px; font-size: 14px; color: var(--ink2); }
.facts b { display: block; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; margin-bottom: 4px; }
details { border-top: 1px solid var(--rule); padding: 14px 0; }
summary { cursor: pointer; font-weight: 600; font-size: 17px; }
summary:focus-visible { outline: 2px solid var(--more); outline-offset: 2px; }
details p { margin-top: 10px; color: var(--ink2); font-size: 16px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; font-size: 13.5px; width: 100%; min-width: 520px; }
th, td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 600; color: var(--ink2); white-space: normal; vertical-align: bottom; }
@media (prefers-reduced-motion: reduce) { body, .card, .chart text { transition: none; } .scroll-cue { animation: none; } }
.hero-scrolly .step:not(.title-step) { justify-content: flex-end; padding-bottom: 7svh; }
.hero-scrolly .fig.full { padding-top: 0; }
@media (min-width: 900px) {
  .hero-scrolly .step:not(.title-step) { justify-content: center; padding-bottom: 0; }
  .hero-scrolly .step:not(.title-step) .card { max-width: 440px; }
}

@media (max-width: 899px) {
  /* phones: compact figure header, smaller cards, shorter gaps between steps */
  .fig { padding-top: 34px; }
  .fig-title { font-size: 15px; margin-bottom: 4px; line-height: 1.25; }
  .fig-title span { display: block; margin: 1px 0 0; font-size: 12.5px; }
  .legend { font-size: 12.5px; gap: 2px 12px; margin-bottom: 6px; }
  .step { min-height: 86svh; padding-bottom: calc(3svh + env(safe-area-inset-bottom, 0px)); }
  .step:last-child { min-height: 104svh; }
  .card { padding: 14px 16px; border-radius: 10px; }
  .card h3 { font-size: 18px; margin-bottom: 6px; }
  .card p { font-size: 15.5px; line-height: 1.45; }
  .card .n { margin-bottom: 4px; }
  .opener { min-height: 78svh; padding: 0 20px; }
  .opener h2 { font-size: clamp(38px, 11vw, 60px); }
  .opener .dek { font-size: 18px; }
  .seg.mini { margin-bottom: 6px; }
  .seg.mini span { font-size: 12.5px; padding: 5px 11px; }
  .case-box { padding: 10px 12px; }
  dl { gap: 5px; font-size: 13.5px; line-height: 1.34; }
  dt { font-size: 10px; }
  .prompt dd { font-size: 12px; }
  .plan li { font-size: 12px; padding: 1px 7px; }
  .plan ul { gap: 3px 4px; }
  .score { margin-top: 6px; padding-top: 6px; font-size: 11.5px; gap: 4px; }
  .score span { padding: 2px 8px; }
  .progress span { background: var(--bg); padding: 2px 8px; border-radius: 99px; top: 6px; right: 10px; font-size: 11px; transition: background-color .7s; }
  .hero-card { padding: 20px 18px; }
  .plain { padding: 52px 18px 32px; }
  .short li { padding: 14px 16px 14px 52px; }
  .short li::before { left: 16px; top: 11px; font-size: 24px; }
  pre { font-size: 12px; padding: 12px; }
}
.fine a { color: inherit; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; background: var(--card); box-shadow: var(--shadow); border-radius: 10px; padding: 14px 16px; margin: 6px 0 14px; color: var(--ink); }
.pre-label { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 14px 0 0; }
table.versions td, table.versions th { text-align: left; white-space: normal; vertical-align: top; }
@media (max-width: 899px) { pre { font-size: 12px; padding: 12px; } }
@media (max-width: 899px) {
  /* give the pinned figure time to settle before the first card reaches reading height */
  .scrolly:not(.hero-scrolly) .step:first-child { min-height: 114svh; }
}

/* closing summary: takeaway line, then number-led rows (same as the poster's conclusions) */
.take { font-size: clamp(20px, 3vw, 27px); line-height: 1.25; font-weight: 700; margin: 0 0 18px; }
.short.kn li { padding-left: 20px; }
.short.kn li::before { content: none; }
.short .num { display: block; font-size: clamp(24px, 3.6vw, 30px); font-weight: 800; color: var(--more); line-height: 1.15; margin-bottom: 4px; white-space: nowrap; }
@media (max-width: 760px) { .short.kn li { padding-left: 16px; } }
.card p.byline { font-size: 12.5px; line-height: 1.4; color: var(--ink2); margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--rule); }
.card p.byline b { font-size: 14px; color: var(--ink); }
