/* ---------------------------------------------------------------- tokens */
:root {
  color-scheme: light;
  --bg: #fcfcfb;
  --surface: #ffffff;
  --surface-2: #f4f3f0;
  --border: #e3e1dc;
  --grid: #ecebe7;
  --axis: #9a9892;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7873;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --on-accent: #ffffff;

  --s-pre: #2a78d6;     /* counterfactual / baseline / pre */
  --s-post: #eb6834;    /* empirical / post / one-off */
  --s-flow: #1baf7a;    /* flow disutility */
  --s-neutral: #8f8d87; /* interest-only reference */
  --fill-B: rgba(235, 104, 52, 0.18);
  --fill-M: rgba(42, 120, 214, 0.16);
  --window: rgba(120, 118, 112, 0.08);

  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #141413; --surface: #1a1a19; --surface-2: #232321; --border: #33332f; --grid: #2a2a27; --axis: #6f6d67;
    --text: #ffffff; --text-2: #c3c2b7; --text-3: #95938b; --accent: #3987e5; --accent-ink: #86b6ef; --on-accent: #ffffff;
    --s-pre: #3987e5; --s-post: #d95926; --s-flow: #199e70; --s-neutral: #8a8880;
    --fill-B: rgba(217, 89, 38, 0.26); --fill-M: rgba(57, 135, 229, 0.24); --window: rgba(255,255,255,0.04);
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --surface: #1a1a19; --surface-2: #232321; --border: #33332f; --grid: #2a2a27; --axis: #6f6d67;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #95938b; --accent: #3987e5; --accent-ink: #86b6ef; --on-accent: #ffffff;
  --s-pre: #3987e5; --s-post: #d95926; --s-flow: #199e70; --s-neutral: #8a8880;
  --fill-B: rgba(217, 89, 38, 0.26); --fill-M: rgba(57, 135, 229, 0.24); --window: rgba(255,255,255,0.04);
  --shadow: 0 1px 2px rgba(0,0,0,.3);
}

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-underline-offset: 2px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.9rem, 4.2vw, 3rem); letter-spacing: -0.01em; max-width: 22ch; }
h2 { font-size: clamp(1.5rem, 2.8vw, 2rem); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1em; }
var { font-style: italic; font-family: var(--serif); }
main { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
@media (max-width: 600px) { main { padding: 0 16px; } }

/* ---------------------------------------------------------------- top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 20px; }
.brand { font-family: var(--serif); font-weight: 600; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.brand-venue { font: 600 .7rem var(--sans); letter-spacing: .06em; color: var(--text-3); margin-left: 4px; }
.nav { display: flex; gap: 18px; margin-left: auto; }
.nav a { color: var(--text-2); text-decoration: none; font-size: .9rem; }
.nav a:hover { color: var(--text); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
@media (max-width: 860px) { .nav { display: none; } .topbar-actions { margin-left: auto; } }
@media (max-width: 480px) { .topbar-inner { gap: 10px; padding: 10px 16px; } .brand { font-size: .9rem; } .brand-venue { display: none; } .topbar-actions .btn-ghost { display: none; } }

/* ---------------------------------------------------------------- buttons & controls */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 500 .9rem var(--sans); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--axis); }
.btn:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
:root[data-theme="dark"] .btn-primary:hover { background: #2a78d6; }
.btn-ghost { background: transparent; }
.btn-small { padding: 5px 10px; font-size: .82rem; }
.btn-icon { padding: 7px; }

.controls { display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: flex-end; padding: 16px 18px; background: var(--surface-2); border-radius: var(--radius); margin: 0 0 18px; }
.controls-tight { padding: 0; background: none; margin: 8px 0 10px; }
.control { display: flex; flex-direction: column; gap: 6px; }
.control-label { font-size: .78rem; font-weight: 600; letter-spacing: .02em; color: var(--text-2); }
.control-label output { font-weight: 500; color: var(--text); margin-left: 4px; font-variant-numeric: tabular-nums; }
.control-slider { min-width: 170px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; color: var(--text-2); padding: 7px 12px; font: 500 .86rem var(--sans); cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); border-radius: 999px; padding: 4px 11px; font: 500 .84rem var(--sans); cursor: pointer; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { border-color: currentColor; font-weight: 600; }
.chip.pre[aria-pressed="true"] { color: var(--s-pre); background: color-mix(in srgb, var(--s-pre) 10%, var(--surface)); }
.chip.post[aria-pressed="true"] { color: var(--s-post); background: color-mix(in srgb, var(--s-post) 10%, var(--surface)); }
.select { font: 500 .9rem var(--sans); padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

/* ---------------------------------------------------------------- hero */
.hero { padding: 56px 0 32px; }
.eyebrow { font-size: .8rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin-bottom: 14px; }
.authors { font-size: 1.1rem; color: var(--text-2); margin: 14px 0 20px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 26px; }
.abstract { font-family: var(--serif); font-size: 1.08rem; line-height: 1.65; color: var(--text-2); max-width: 72ch; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 28px; }
@media (max-width: 900px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 460px) { .tiles { grid-template-columns: 1fr; } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.tile-num { font: 600 2rem/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.tile-unit { font-size: 1rem; color: var(--text-3); margin-left: 2px; }
.tile-label { font-size: .86rem; color: var(--text-2); margin-top: 6px; line-height: 1.45; }

/* ---------------------------------------------------------------- sections */
.section { padding: 48px 0; border-top: 1px solid var(--border); }
.section-head { margin-bottom: 22px; max-width: 76ch; }
.kicker { font-size: .78rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-ink); margin-bottom: 6px; }
.lede { color: var(--text-2); margin-top: 10px; }
.subhead { margin: 38px 0 14px; max-width: 76ch; }
.subhead p { color: var(--text-2); margin-top: 6px; }
.h3-tight { margin-bottom: 8px; }
.prose p, .prose-small { color: var(--text-2); max-width: 68ch; }
.prose-small { font-size: .95rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }
.mech-text { color: var(--text-2); max-width: 80ch; min-height: 3.2em; }

/* ---------------------------------------------------------------- figures */
.figure { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 12px; min-width: 0; }
.figure figcaption { font-size: .8rem; color: var(--text-3); margin-top: 8px; line-height: 1.5; }
.chart { position: relative; width: 100%; height: var(--h, 300px); }
.chart svg { display: block; overflow: visible; }
.chart text { font-family: var(--sans); fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis-title { fill: var(--text-2); font-size: 11px; }
.chart .dlabel { fill: var(--text-2); font-size: 11px; font-weight: 500; }
.chart .dlabel-strong { fill: var(--text); font-size: 11.5px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .8rem; color: var(--text-2); margin: 0 0 6px 4px; min-height: 1.2em; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.legend i.sw-box { height: 10px; width: 10px; border-radius: 2px; }
.legend i.sw-dash { background: none !important; border-top: 2px dashed; height: 0; }
.badge { display: inline-block; font-size: .68rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); margin-right: 4px; }

.ev-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; align-items: start; }
.sp-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.ca-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 230px; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .ca-grid { grid-template-columns: 1fr 1fr; } .ca-grid .readouts { grid-column: 1 / -1; } }
@media (max-width: 860px) { .ev-grid, .sp-grid, .ca-grid { grid-template-columns: 1fr; } }

.readouts { display: grid; gap: 10px; }
.readout { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.readout-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.readout-name { font-size: .8rem; font-weight: 600; color: var(--text-2); }
.readout-val { font: 600 1.55rem/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.readout-sub { font-size: .78rem; color: var(--text-3); margin-top: 4px; font-variant-numeric: tabular-nums; }
.readout-sub b { color: var(--text-2); font-weight: 600; }
.readout.match { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }

.multiples { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 860px) { .multiples { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.multiples .figure { padding: 8px 8px 4px; }
.multiples .mtitle { font-size: .8rem; font-weight: 600; margin: 0 0 2px 4px; }

.detail { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; font-size: .9rem; }
.detail h4 { margin: 0 0 4px; font: 600 1rem var(--serif); }
.detail .src { color: var(--text-3); font-size: .8rem; margin-bottom: 10px; }
.detail table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.detail td { padding: 5px 0; border-bottom: 1px solid var(--grid); }
.detail td:last-child { text-align: right; }
.detail .hint { color: var(--text-3); font-size: .82rem; }

/* ---------------------------------------------------------------- notes, tables */
details.note { background: var(--surface-2); border-radius: var(--radius); padding: 12px 16px; margin: 14px 0 0; }
details.note summary { cursor: pointer; font-weight: 600; font-size: .92rem; color: var(--text-2); }
details.note[open] summary { margin-bottom: 10px; }
details.note p { color: var(--text-2); font-size: .92rem; max-width: 80ch; }
.eq { font-family: var(--serif); font-size: 1.06rem; color: var(--text); overflow-x: auto; padding: 4px 0; }
.table-wrap { overflow-x: auto; }
table.params { border-collapse: collapse; font-size: .88rem; min-width: 520px; width: 100%; }
table.params th { text-align: left; font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--border); padding: 6px 10px 6px 0; }
table.params td { padding: 5px 10px 5px 0; border-bottom: 1px solid var(--grid); color: var(--text-2); font-variant-numeric: tabular-nums; }
table.params td:nth-child(2) { font-family: var(--serif); font-style: italic; color: var(--text); }
table.params tr.grp td { font-weight: 600; color: var(--text); padding-top: 12px; font-style: normal; font-family: var(--sans); }

/* ---------------------------------------------------------------- cite */
.cite-ref { font-family: var(--serif); font-size: 1.1rem; line-height: 1.6; background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 16px 20px; max-width: 86ch; overflow-wrap: anywhere; }
.cite-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0; }
.copied { font-size: .85rem; color: var(--text-2); }
.bibtex { font: .84rem/1.55 var(--mono); background: var(--surface-2); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; max-width: 86ch; color: var(--text); }
.links { color: var(--text-2); padding-left: 20px; }
.links li { margin: 4px 0; }

.footer { max-width: 1120px; margin: 0 auto; padding: 28px 20px 48px; border-top: 1px solid var(--border); color: var(--text-3); font-size: .82rem; }
.footer p { max-width: 90ch; }

/* ---------------------------------------------------------------- tooltip */
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: 8px 10px; font-size: .8rem; line-height: 1.45; min-width: 140px; max-width: 260px; font-variant-numeric: tabular-nums; }
.tooltip .tt-h { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-r { display: flex; justify-content: space-between; gap: 14px; color: var(--text-2); }
.tooltip .tt-r i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.tooltip .tt-r b { color: var(--text); font-weight: 600; }

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
