:root {
  --bg: #f5f0e6;
  --paper: #fbf8f1;
  --ink: #1d1a15;
  --ink2: #473f33;
  --line: #bfb39b;
  --line-soft: #ddd3bf;
  --acc: #9b2d20;      /* the law */
  --data: #1d5a66;     /* what the data says */
  --data-soft: #b9d3d8;
  --hypo: #8a5a00;     /* a calculation, not data */
  --hypo-soft: #ecd7a8;
  --ok: #2c6b3a;
  --warn: #8a5a00;
  --bad: #9b2d20;
  --sr-line: #7d725d;
  --sr-ink: var(--ink);
  --sr-acc: var(--acc);
  --sr-ok: var(--ok);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --bar-h: 3rem;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #14120f;
  --paper: #1c1915;
  --ink: #efe8d8;
  --ink2: #c4baa5;
  --line: #5a5240;
  --line-soft: #332e24;
  --acc: #ff9f8a;
  --data: #7fcbd8;
  --data-soft: #24454c;
  --hypo: #f0c065;
  --hypo-soft: #4d3b14;
  --ok: #8fd19e;
  --warn: #f0c065;
  --bad: #ff9f8a;
  --sr-line: #8c8268;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14120f; --paper: #1c1915; --ink: #efe8d8; --ink2: #c4baa5; --line: #5a5240; --line-soft: #332e24;
    --acc: #ff9f8a; --data: #7fcbd8; --data-soft: #24454c; --hypo: #f0c065; --hypo-soft: #4d3b14;
    --ok: #8fd19e; --warn: #f0c065; --bad: #ff9f8a; --sr-line: #8c8268; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { animation: none !important; transition: none !important; } }
body { margin: 0; background: var(--bg); color: var(--ink); font: 1.0625rem/1.62 var(--serif); font-variant-numeric: lining-nums; text-rendering: optimizeLegibility; }
a { color: var(--data); text-underline-offset: 0.18em; }
a:hover { color: var(--acc); }
:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; border-radius: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--bg); padding: .6rem 1rem; z-index: 50; }
.skip:focus { left: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* top bar: one line */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--bar-h); display: flex; align-items: center; gap: 1rem; padding: 0 clamp(.9rem, 3vw, 1.6rem); background: color-mix(in srgb, var(--bg) 92%, transparent); border-bottom: 1px solid var(--line-soft); backdrop-filter: blur(6px); font: .875rem/1 var(--sans); }
.topbar .home { color: var(--ink); text-decoration: none; font-weight: 600; white-space: nowrap; }
.topnav { display: flex; gap: 1rem; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { color: var(--ink2); text-decoration: none; white-space: nowrap; padding: .9rem 0; }
.topnav a:hover { color: var(--acc); }
.chip { color: var(--ink); text-decoration: none; border: 1px solid var(--line); border-radius: 99px; padding: .3rem .7rem; white-space: nowrap; }
.icon-btn { display: inline-grid; place-items: center; width: 2.2rem; height: 2.2rem; border-radius: 50%; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; flex: none; }
.icon-btn svg { display: block; }
.icon-btn svg[hidden] { display: none; }
.progress { position: fixed; top: var(--bar-h); left: 0; height: 2px; width: 100%; background: var(--acc); transform-origin: 0 0; transform: scaleX(0); z-index: 29; pointer-events: none; }

main { display: block; }
section[id], header[id] { scroll-margin-top: calc(var(--bar-h) + 1rem); }
.shell { width: min(68rem, 100% - 2 * clamp(1rem, 4vw, 2rem)); margin-inline: auto; }
.col { max-width: 41rem; }
.kicker { font: 600 .78rem/1.2 var(--sans); letter-spacing: .09em; text-transform: uppercase; color: var(--acc); margin: 0 0 .9rem; }
h1 { font: 700 clamp(1.9rem, 4.6vw, 3.2rem)/1.12 var(--serif); letter-spacing: -.01em; margin: 0 0 1.1rem; max-width: 24ch; text-wrap: balance; }
h2 { font: 700 clamp(1.4rem, 2.8vw, 1.9rem)/1.2 var(--serif); margin: 0 0 .9rem; text-wrap: balance; }
h3 { font: 700 1.05rem/1.3 var(--sans); margin: 1.4rem 0 .4rem; }
p { margin: 0 0 1.05rem; }
.deck { font-size: clamp(1.1rem, 1.9vw, 1.3rem); line-height: 1.5; color: var(--ink2); max-width: 44rem; }
.hero { padding: clamp(2rem, 6vw, 4rem) 0 1.5rem; }
.sec { padding: clamp(2rem, 5vw, 3.4rem) 0; border-top: 1px solid var(--line-soft); }
.num, .tabular { font-variant-numeric: tabular-nums lining-nums; }
.dim { color: var(--ink2); }
.small { font-size: .9rem; line-height: 1.5; }
code { font: .9em var(--mono); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin: 1.6rem 0 0; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.stats > div { padding: .9rem 1rem; border-left: 1px solid var(--line-soft); }
.stats > div:first-child { border-left: 0; }
.stats b { display: block; font: 700 clamp(1.4rem, 3.6vw, 2.1rem)/1.1 var(--mono); letter-spacing: -.02em; }
.stats span { display: block; font: .82rem/1.35 var(--sans); color: var(--ink2); margin-top: .25rem; }
@media (max-width: 36rem) { .stats { grid-template-columns: 1fr; } .stats > div { border-left: 0; border-top: 1px solid var(--line-soft); } .stats > div:first-child { border-top: 0; } }

/* figures */
.fig { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: clamp(.8rem, 2vw, 1.3rem); margin: 1.4rem 0 1.2rem; }
.fig h3:first-child { margin-top: 0; }
.fig figcaption { font: .86rem/1.45 var(--sans); color: var(--ink2); margin-top: .7rem; }
.twin { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
@media (max-width: 52rem) { .twin { grid-template-columns: 1fr; } }
.ladder-twin { grid-template-columns: 1.5fr 1fr; align-items: start; }
.stick { position: sticky; top: calc(var(--bar-h) + 1rem); }
@media (max-width: 52rem) { .ladder-twin { grid-template-columns: 1fr; } .stick { position: static; } }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin: 0 0 .9rem; padding: 0; list-style: none; }
.chips button, .btn { font: 600 .84rem/1.2 var(--sans); color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 99px; padding: .5rem .9rem; cursor: pointer; min-height: 2.2rem; }
.chips button[aria-current="true"], .chips button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn:hover, .chips button:hover { border-color: var(--acc); }
@media (pointer: coarse) { .chips button, .btn { min-height: 2.75rem; } }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font: 12.5px var(--sans); fill: var(--ink2); }
.chart .val { font: 600 12px var(--mono); fill: var(--ink); }
.chart .ax { stroke: var(--line); stroke-width: 1; }
.chart .grid { stroke: var(--line-soft); stroke-width: 1; }
.chart .bar { fill: var(--data); }
.chart .bar.hypo { fill: var(--hypo); }
.chart .band { fill: var(--data-soft); }
.chart .band.hypo { fill: var(--hypo-soft); }
.chart .law { stroke: var(--acc); stroke-width: 2.4; }
.chart .lawline { stroke: var(--acc); stroke-width: 1.6; stroke-dasharray: 5 4; fill: none; }
.chart .cap { stroke: var(--acc); stroke-width: 1.6; }
.chart .caplab { fill: var(--acc); font: 600 12.5px var(--sans); }
.chart .tick { stroke: var(--ink2); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; font: .8rem/1.3 var(--sans); color: var(--ink2); margin: .5rem 0 0; padding: 0; list-style: none; }
.legend i { display: inline-block; width: .8rem; height: .8rem; margin-right: .35rem; vertical-align: -.1rem; border-radius: 2px; }
.legend .l-data { background: var(--data); } .legend .l-law { background: var(--acc); height: 3px; vertical-align: .2rem; } .legend .l-band { background: var(--data-soft); } .legend .l-hypo { background: var(--hypo); }
.readout { font: .9rem/1.5 var(--sans); margin: .6rem 0 0; color: var(--ink); }
.readout b { font-family: var(--mono); font-weight: 700; }
.tag-hypo { display: inline-block; font: 700 .72rem/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--hypo); border: 1px solid var(--hypo); border-radius: 3px; padding: .2rem .4rem; margin-right: .5rem; vertical-align: .08rem; }

/* ruler */
.ruler { width: 100%; height: auto; display: block; }
.ruler text { font: 12px var(--sans); fill: var(--ink2); }
.ruler .rb { fill: var(--data-soft); stroke: var(--paper); stroke-width: 2; }
.ruler .rb.d1 { fill: var(--data); }
.ruler .rt { stroke: var(--ink2); }
.ruler .pct { font: 600 12px var(--mono); fill: var(--ink); }
.ruler .pct.on { fill: var(--bg); font-size: 16px; }

/* odometer */
.odo { display: grid; grid-template-columns: 11rem 1fr; gap: 1.2rem; align-items: center; }
@media (max-width: 40rem) { .odo { grid-template-columns: 1fr; } }
.odo-val { font: 700 clamp(1.5rem, 4vw, 2.1rem)/1.1 var(--mono); border: 1px solid var(--line); border-radius: 6px; padding: .7rem .8rem; background: var(--bg); overflow-wrap: anywhere; }
.odo-val small { display: block; font: .78rem/1.3 var(--sans); color: var(--ink2); margin-top: .3rem; }
.play { display: inline-flex; align-items: center; gap: .5rem; margin-top: .6rem; }
.play .ic-pause { display: none; }
.play[data-on="true"] .ic-play { display: none; }
.play[data-on="true"] .ic-pause { display: inline; }

/* ladder */
.ladder { list-style: none; margin: 0; padding: 0; }
.ladder h4 { font: 700 .74rem/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink2); margin: 1.1rem 0 .3rem; }
.lrow { display: grid; grid-template-columns: minmax(7rem, 13rem) minmax(7rem, 1fr) 4.6rem; gap: .8rem; align-items: center; width: 100%; text-align: left; font: .86rem/1.3 var(--sans); color: var(--ink); background: transparent; border: 0; border-top: 1px solid var(--line-soft); padding: .55rem .3rem; cursor: pointer; min-height: 2.75rem; }
.lrow:hover { background: color-mix(in srgb, var(--data-soft) 35%, transparent); }
.lrow[aria-current="true"] { background: var(--data-soft); outline: 2px solid var(--data); outline-offset: -2px; }
.lrow .lab small { display: block; color: var(--ink2); font-size: .76rem; }
.track { position: relative; height: 1.3rem; border-radius: 3px; background: linear-gradient(to right, color-mix(in srgb, var(--ok) 26%, transparent) 0 var(--x1), color-mix(in srgb, var(--warn) 30%, transparent) var(--x1) var(--x3), color-mix(in srgb, var(--bad) 26%, transparent) var(--x3) 100%); }
.track .dot { position: absolute; top: 50%; width: .95rem; height: .95rem; margin: -.475rem 0 0 -.475rem; border-radius: 50%; background: var(--ink); border: 2px solid var(--paper); left: var(--x); }
.track .noise { position: absolute; top: -.1rem; bottom: -.1rem; width: 0; border-left: 2px dashed var(--ink); left: var(--xn); }
.lrow .m { font: 600 .82rem var(--mono); text-align: right; }
@media (max-width: 40rem) { .lrow { grid-template-columns: 1fr 5rem; } .lrow .track { grid-column: 1 / -1; grid-row: 2; } }
.axis-note { display: flex; justify-content: space-between; font: .74rem var(--sans); color: var(--ink2); margin: .2rem 0 0; }

/* tool */
.tool textarea { width: 100%; min-height: 8rem; font: .95rem/1.4 var(--mono); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .7rem; resize: vertical; }
.tool label { display: block; font: 600 .9rem var(--sans); margin-bottom: .35rem; }
.tool .row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0; align-items: center; }
.notes { margin: .8rem 0 0; padding: 0; list-style: none; font: .9rem/1.5 var(--sans); }
.notes li { padding: .4rem .7rem; margin: .3rem 0; border-left: 3px solid var(--line); background: var(--bg); }
.notes li.warn { border-color: var(--warn); }
.notes li.bad { border-color: var(--bad); }
.notes li.ok { border-color: var(--ok); }
input[type="range"] { width: 100%; accent-color: var(--hypo); }
.slide-row { display: grid; grid-template-columns: 1fr auto; gap: .8rem; align-items: center; margin: .3rem 0 .8rem; font: .9rem var(--sans); }
canvas.funnel { width: 100%; height: auto; display: block; background: var(--bg); border: 1px solid var(--line-soft); border-radius: 6px; }

table.data { border-collapse: collapse; width: 100%; font: .84rem/1.35 var(--sans); }
table.data th, table.data td { padding: .4rem .5rem; border-bottom: 1px solid var(--line-soft); text-align: right; vertical-align: top; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { font-weight: 700; border-bottom: 2px solid var(--line); }
table.data td.n { font-family: var(--mono); }
.tablewrap { overflow-x: auto; }
.pred { border-left: 3px solid var(--line); padding: .3rem 0 .3rem .9rem; margin: .6rem 0; font-size: .95rem; }
.pred b.fail { color: var(--bad); } .pred b.pass { color: var(--ok); }

.related { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: .8rem; margin-top: 1rem; }
.related a { display: block; padding: .9rem 1rem; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); text-decoration: none; font: .92rem/1.4 var(--sans); }
.related a:hover { border-color: var(--acc); }
.related b { display: block; font-family: var(--serif); font-size: 1.05rem; margin-bottom: .2rem; }

.share { margin: 1.4rem 0 0; }
footer { border-top: 1px solid var(--line-soft); padding: 2rem 0 3rem; font: .88rem/1.5 var(--sans); color: var(--ink2); }
footer a { color: var(--ink); }

/* reading rail */
.rail { display: none; position: fixed; right: 1.4rem; top: 50%; transform: translateY(-50%); z-index: 20; }
.rail ol { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.rail a { position: relative; display: block; width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.rail a span { position: absolute; right: 1.1rem; top: 50%; transform: translateY(-50%); white-space: nowrap; font: .75rem var(--sans); color: var(--ink); background: var(--paper); border: 1px solid var(--line); padding: .15rem .45rem; border-radius: 3px; opacity: 0; pointer-events: none; }
.rail a:hover span, .rail a:focus-visible span { opacity: 1; }
.rail a[aria-current="true"] { background: var(--acc); transform: scale(1.45); }
@media (min-width: 76rem) { .rail { display: block; } }
@media print { .topbar, .rail, .progress { display: none; } }

#hand-chart, #det-chart, #own-chart, #odo-chart { max-width: 44rem; }
.odo-val { font-size: clamp(1.3rem, 3.4vw, 1.8rem); }
