:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #14171c;
  --ink-2: #414856;
  --muted: #5d6573;
  --rule: #dce0e6;
  --rule-strong: #c3c9d2;
  --accent: #0b6b73;
  --accent-soft: #e2f0f1;
  --code-bg: #eef1f4;
  --warn: #a4540a;
  --warn-soft: #fbf0e3;
  --good: #1b7a45;
  --bad: #b3261e;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e6e9ee;
  --font-body: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-ui: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1215;
    --surface: #161a1f;
    --ink: #e8ebef;
    --ink-2: #bcc3cd;
    --muted: #8e97a4;
    --rule: #2a3038;
    --rule-strong: #3a424c;
    --accent: #56b6bf;
    --accent-soft: #15292c;
    --code-bg: #1b2027;
    --warn: #f0a24a;
    --warn-soft: #2a2015;
    --good: #5cc28a;
    --bad: #f07a72;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #232830;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1215;
  --surface: #161a1f;
  --ink: #e8ebef;
  --ink-2: #bcc3cd;
  --muted: #8e97a4;
  --rule: #2a3038;
  --rule-strong: #3a424c;
  --accent: #56b6bf;
  --accent-soft: #15292c;
  --code-bg: #1b2027;
  --warn: #f0a24a;
  --warn-soft: #2a2015;
  --good: #5cc28a;
  --bad: #f07a72;
  --series-1: #3987e5;
  --series-2: #d95926;
  --grid: #232830;
}

* { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.62;
  padding-inline: 20px;
  padding-block: 0 80px;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.page {
  max-width: 1160px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 48px;
}
@media (min-width: 1100px) {
  .page { grid-template-columns: 210px minmax(0, 760px); justify-content: center; }
}

/* ---------- header ---------- */
.masthead {
  max-width: 1160px;
  margin: 0 auto;
  padding-block: 56px 36px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 40px;
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
}
h1 {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: clamp(34px, 5.2vw, 56px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 18px;
  max-width: 22ch;
  text-wrap: balance;
}
.dek {
  font-size: 21px;
  line-height: 1.5;
  color: var(--ink-2);
  max-width: 62ch;
  margin: 0 0 22px;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
}

/* ---------- toc ---------- */
.toc { font-family: var(--font-ui); font-size: 14px; }
.toc nav { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 24px); }
.toc h2 {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
}
.toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; counter-reset: toc; }
.toc li { counter-increment: toc; display: grid; grid-template-columns: 26px 1fr; }
.toc li::before { content: counter(toc, decimal-leading-zero); font-family: var(--font-mono); font-size: 12px; color: var(--muted); padding-top: 1px; }
.toc a { color: var(--ink-2); text-decoration: none; line-height: 1.35; }
.toc a:hover { color: var(--accent); }
@media (max-width: 1099px) {
  .toc nav { position: static; border: 1px solid var(--rule); background: var(--surface); padding: 16px 18px; border-radius: 6px; }
}

/* ---------- article ---------- */
article { min-width: 0; }
article > section { margin-bottom: 64px; }
h2 {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0 0 18px;
  text-wrap: balance;
  scroll-margin-top: 24px;
}
h2 .num { font-family: var(--font-mono); font-weight: 500; font-size: 15px; color: var(--accent); display: block; margin-bottom: 6px; letter-spacing: 0.04em; }
h3 {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 19px;
  margin: 34px 0 10px;
  text-wrap: balance;
}
p { margin: 0 0 16px; max-width: 68ch; }
ul, ol { margin: 0 0 18px; padding-left: 22px; max-width: 66ch; }
li { margin-bottom: 6px; }
strong { font-weight: 600; }
code {
  font-family: var(--font-mono);
  font-size: 0.83em;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  overflow-wrap: anywhere;
}
pre {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.55;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 16px 18px;
  overflow-x: auto;
  margin: 0 0 22px;
  color: var(--ink);
}
pre code { background: none; padding: 0; font-size: inherit; overflow-wrap: normal; }
pre .c { color: var(--muted); }
pre .k { color: var(--accent); }

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  margin: 0 0 40px;
}
.stat { background: var(--surface); padding: 18px 18px 16px; display: grid; gap: 6px; align-content: start; }
.stat .v { font-family: var(--font-ui); font-weight: 700; font-size: 30px; line-height: 1; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat .l { font-family: var(--font-ui); font-size: 13.5px; line-height: 1.4; color: var(--ink-2); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 0 24px; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-family: var(--font-ui); font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 600; color: var(--ink-2); font-size: 12.5px; letter-spacing: 0.02em; background: var(--code-bg); white-space: nowrap; }
td.n, th.n { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td .pos { color: var(--good); font-weight: 600; }
td .neg { color: var(--bad); font-weight: 600; }
tr.hl td { background: var(--accent-soft); }
.caption { font-family: var(--font-ui); font-size: 13.5px; color: var(--muted); margin: -14px 0 24px; max-width: 72ch; line-height: 1.5; }

/* ---------- callouts ---------- */
.note, .finding {
  border-radius: 6px;
  padding: 14px 18px;
  margin: 0 0 22px;
  font-size: 16.5px;
  line-height: 1.55;
}
.finding { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.note { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.finding p, .note p { margin: 0; max-width: none; }
.finding .tag, .note .tag {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 4px;
}
.finding .tag { color: var(--accent); }
.note .tag { color: var(--warn); }

/* ---------- figures ---------- */
figure { margin: 0 0 28px; }
figcaption { font-family: var(--font-ui); font-size: 13.5px; color: var(--muted); margin-top: 10px; line-height: 1.5; max-width: 72ch; }
.diagram { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 16px; overflow-x: auto; }
.diagram pre.mermaid { background: none; border: none; padding: 0; margin: 0; text-align: center; }

.chart-card { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 18px 16px 12px; }
.chart-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 20px; align-items: baseline; margin-bottom: 8px; font-family: var(--font-ui); }
.chart-head .t { font-weight: 600; font-size: 15px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 16px; height: 2px; border-radius: 2px; display: inline-block; }
.legend i.s1 { background: var(--series-1); }
.legend i.s2 { background: var(--series-2); }
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 8px 22px; }
.panel { position: relative; }
.panel h4 { font-family: var(--font-ui); font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 6px 0 2px; }
.panel svg { width: 100%; height: auto; display: block; overflow: visible; }
.panel svg text { font-family: var(--font-ui); font-size: 11px; fill: var(--muted); }
.panel svg .dl { font-size: 11px; font-weight: 600; fill: var(--ink-2); }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--rule-strong);
  border-radius: 6px; padding: 8px 10px; font-family: var(--font-ui); font-size: 12.5px; line-height: 1.45;
  color: var(--ink); box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; z-index: 2;
}
.tip b { font-weight: 600; }
.tip .sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
details.tableview { margin-top: 10px; font-family: var(--font-ui); font-size: 13.5px; }
details.tableview summary { cursor: pointer; color: var(--accent); }
details.tableview .table-wrap { margin-top: 10px; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin: 0 0 24px; }
.kv { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 14px 16px; font-family: var(--font-ui); font-size: 14px; }
.kv h4 { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kv ul { margin: 0; padding-left: 18px; }
.kv li { margin-bottom: 5px; }

footer.end { border-top: 1px solid var(--rule); padding-top: 22px; font-family: var(--font-ui); font-size: 14px; color: var(--muted); }

@media (max-width: 600px) {
  body { font-size: 17px; }
  h2 { font-size: 24px; }
  .dek { font-size: 18.5px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* ---------- standalone page basics (GitHub Pages has no host reset) ---------- */
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- site nav ---------- */
.sitenav {
  max-width: 1160px;
  margin: 0 auto;
  padding-block: 18px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  align-items: baseline;
  font-family: var(--font-ui);
  font-size: 14px;
}
.sitenav .brand { font-weight: 700; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; margin-right: auto; }
.sitenav a { color: var(--ink-2); text-decoration: none; }
.sitenav a:hover, .sitenav a[aria-current="page"] { color: var(--accent); }
.sitenav a[aria-current="page"] { font-weight: 600; }

/* ---------- single-column post ---------- */
.post { max-width: 760px; margin: 0 auto; }
.post .masthead { max-width: none; }
.post pre { margin-bottom: 22px; }
.byline { font-family: var(--font-ui); font-size: 14px; color: var(--muted); margin: 0; }
blockquote {
  margin: 0 0 20px;
  padding: 2px 0 2px 18px;
  border-left: 3px solid var(--accent);
  color: var(--ink-2);
  font-style: italic;
  max-width: 64ch;
}
blockquote p { margin: 0; }
hr { border: none; border-top: 1px solid var(--rule); margin: 44px 0; }

