/* Beyond Intelligence: tokens first, then components. Raw values live only in :root. */

:root {
  /* colour roles, light */
  --bg: #f7f5ef;
  --surface: #fffdf8;
  --text: #1b1b18;
  --text-2: #55544d;
  --line: #dcd8cc;
  --line-strong: #bdb8a8;
  --accent: #0b4f9c;
  --accent-ink: #ffffff;
  --accent-soft: #e4edf8;
  --bar: #0b4f9c;
  --bar-muted: #b9c9de;
  --positive: #17703f;
  --negative: #a8271f;
  --banner-bg: #fbeed0;
  --banner-text: #5a3d00;
  --focus: #0b4f9c;
  --skeleton: #e9e5d9;

  /* spacing scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* type scale: title, body, caption */
  --fs-title: clamp(1.25rem, 1.1rem + 0.7vw, 1.5rem);
  --fs-body: 0.9375rem;
  --fs-caption: 0.8125rem;
  --lh-title: 1.2;
  --lh-body: 1.45;
  --font-serif: "Iowan Old Style", "Charter", "Georgia", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --radius: 8px;
  --radius-pill: 999px;
  --tap: 44px;
  --measure: 68ch;
  --col-side: 380px;
  --dur: 120ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121317;
    --surface: #1a1c22;
    --text: #ebe9e2;
    --text-2: #a6a49b;
    --line: #2e3038;
    --line-strong: #484b56;
    --accent: #7db4f2;
    --accent-ink: #0c1626;
    --accent-soft: #1f2e45;
    --bar: #7db4f2;
    --bar-muted: #3a4c68;
    --positive: #62cf92;
    --negative: #f28b82;
    --banner-bg: #3a2f12;
    --banner-text: #f3dca0;
    --focus: #7db4f2;
    --skeleton: #252830;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-body) / var(--lh-body) var(--font-sans);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3, p, ul, ol, dl, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
a { color: var(--accent); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

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

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: var(--s4); top: -100px; z-index: 10;
  background: var(--accent); color: var(--accent-ink); padding: var(--s2) var(--s3); border-radius: var(--radius);
}
.skip:focus { top: var(--s2); }

.num { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--text-2); }
.caption { font-size: var(--fs-caption); }

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding-left: max(var(--s4), env(safe-area-inset-left)); padding-right: max(var(--s4), env(safe-area-inset-right)); }

/* ---------------------------------------------------------------- masthead */

.masthead { border-bottom: 1px solid var(--line-strong); background: var(--bg); }
.masthead .wrap { padding-top: var(--s4); padding-bottom: var(--s3); display: grid; gap: var(--s3); }
.masthead-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.title { font: 700 var(--fs-title) / var(--lh-title) var(--font-serif); letter-spacing: -0.01em; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button {
  min-height: var(--tap); padding: 0 var(--s4); border: 0; background: transparent; color: var(--text-2);
  font-weight: 500; transition: background var(--dur), color var(--dur);
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg button:focus-visible { outline-offset: -3px; }

.stepper { display: inline-flex; align-items: center; gap: var(--s1); }
.range { font-size: var(--fs-body); font-weight: 600; min-width: 11.5em; text-align: center; font-variant-numeric: tabular-nums; }
.icon-btn {
  width: var(--tap); height: var(--tap); display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--text);
}
.icon-btn:disabled { color: var(--line-strong); cursor: not-allowed; border-color: var(--line); }

.search { flex: 1 1 220px; max-width: 420px; margin-left: auto; }
.search input {
  width: 100%; min-height: var(--tap); padding: 0 var(--s3);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.search input::placeholder { color: var(--text-2); opacity: 1; }
.search input:focus-visible { outline-offset: 0; border-color: var(--focus); }

@media (max-width: 520px) {
  .masthead-row:nth-child(2) { display: grid; grid-template-columns: 1fr; }
  .stepper { justify-content: space-between; }
  .range { flex: 1; min-width: 0; }
  .search { max-width: none; margin-left: 0; }
  .seg { width: 100%; }
  .seg button { flex: 1; }
  .masthead-row:first-child { display: grid; }
}

/* ---------------------------------------------------------------- banner */

#banner:empty { display: none; }
.banner {
  margin-top: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--radius);
  background: var(--banner-bg); color: var(--banner-text); font-weight: 600;
}
.banner.error { background: var(--surface); color: var(--negative); border: 1px solid var(--negative); }
.banner button { margin-left: var(--s3); }

/* ---------------------------------------------------------------- layout */

.layout { display: grid; gap: var(--s5); padding-top: var(--s5); padding-bottom: var(--s6); align-items: start; }
.col-main, .col-side { display: contents; }
#brief { order: 1; }
#kpis { order: 2; }
#rounds { order: 3; }
#charts { order: 4; }
#lists { order: 5; display: grid; gap: var(--s5); }
.layout > * , .col-main > *, .col-side > * { min-width: 0; }

@media (min-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr) var(--col-side); gap: var(--s6); }
  .col-main, .col-side { display: grid; gap: var(--s5); align-content: start; min-width: 0; }
  #brief, #kpis, #rounds, #charts, #lists { order: 0; }
  .col-side { position: sticky; top: var(--s4); max-height: calc(100vh - var(--s5)); overflow-y: auto; padding-right: var(--s1); }
}

.block { min-width: 0; }
.block + .block { border-top: 0; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; padding-bottom: var(--s2); border-bottom: 2px solid var(--text); margin-bottom: var(--s3); }
.section-head h2 { font-size: var(--fs-caption); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.section-head .meta { font-size: var(--fs-caption); color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- brief */

.brief-headline { font: 700 var(--fs-title) / var(--lh-title) var(--font-serif); margin-bottom: var(--s2); max-width: var(--measure); }
.brief-summary { max-width: var(--measure); margin-bottom: var(--s4); }
.brief-section + .brief-section { margin-top: var(--s4); }
.brief-section h3 { font-size: var(--fs-body); font-weight: 700; margin-bottom: var(--s1); }
.brief-section ul { display: grid; gap: var(--s2); max-width: var(--measure); }
.brief-section li { padding-left: var(--s4); position: relative; }
.brief-section li::before { content: ""; position: absolute; left: 2px; top: 0.65em; width: 5px; height: 5px; border-radius: 50%; background: var(--text-2); }
.cite { font-size: var(--fs-caption); }
.cite a { display: inline-block; white-space: nowrap; padding: 0 var(--s1); }
.cite .n { font-variant-numeric: tabular-nums; color: var(--text-2); margin-right: 2px; }
.brief-foot { margin-top: var(--s4); font-size: var(--fs-caption); color: var(--text-2); }
.empty { color: var(--text-2); padding: var(--s3) 0; max-width: var(--measure); }
.empty code, .code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: var(--fs-caption); background: var(--accent-soft); padding: 1px var(--s1); border-radius: 4px; color: var(--text); overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- KPIs */

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s3); min-width: 0; display: grid; gap: var(--s1); align-content: start; }
.kpi dt { font-size: var(--fs-caption); color: var(--text-2); }
.kpi dd { margin: 0; }
.kpi-value { font: 700 var(--fs-title) / var(--lh-title) var(--font-serif); font-variant-numeric: tabular-nums lining-nums; overflow-wrap: anywhere; }
.kpi-note { font-size: var(--fs-caption); color: var(--text-2); overflow-wrap: anywhere; }
.delta { font-size: var(--fs-caption); font-variant-numeric: tabular-nums; font-weight: 600; }
.delta.up { color: var(--positive); }
.delta.down { color: var(--negative); }
.delta.flat, .delta.none { color: var(--text-2); font-weight: 500; }

/* ---------------------------------------------------------------- controls */

.controls { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); align-items: center; margin-bottom: var(--s3); }
.group { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.group-label { font-size: var(--fs-caption); color: var(--text-2); }
.pills { display: inline-flex; flex-wrap: wrap; gap: var(--s1); }
.pill {
  min-height: 36px; padding: 0 var(--s3); border: 1px solid var(--line-strong); border-radius: var(--radius-pill);
  background: var(--surface); font-size: var(--fs-caption); font-weight: 500; font-variant-numeric: tabular-nums;
  transition: background var(--dur), color var(--dur);
}
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pill .count { opacity: 0.75; margin-left: var(--s1); }
@media (pointer: coarse) { .pill { min-height: var(--tap); } }
.chips { margin-bottom: var(--s3); }

.link-btn { background: none; border: 0; padding: 0 var(--s1); color: var(--accent); text-decoration: underline; text-underline-offset: 0.2em; min-height: 36px; }
.more { display: block; margin: var(--s3) auto 0; min-height: var(--tap); padding: 0 var(--s4); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); font-weight: 600; }

/* ---------------------------------------------------------------- rounds table */

.table-wrap { overflow-x: auto; }
table.rounds { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rounds caption { text-align: left; }
.rounds th, .rounds td { padding: var(--s2) var(--s3) var(--s2) 0; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.rounds th { font-size: var(--fs-caption); font-weight: 600; color: var(--text-2); white-space: nowrap; border-bottom: 1px solid var(--line-strong); }
.rounds td.amount, .rounds th.amount { text-align: right; padding-right: var(--s4); white-space: nowrap; }
.rounds td.amount { font-weight: 700; }
.rounds td.date { white-space: nowrap; color: var(--text-2); }
.rounds .co { font-weight: 600; }
.rounds .sub { display: block; font-size: var(--fs-caption); color: var(--text-2); }
.sort-btn { background: none; border: 0; padding: 0; font: inherit; color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 0.25em; text-decoration-color: var(--line-strong); min-height: 24px; }
.sort-btn[aria-pressed="true"] { color: var(--text); text-decoration-color: var(--accent); text-decoration-thickness: 2px; }

.round-cards { display: none; }
.round-card { padding: var(--s3) 0; border-bottom: 1px solid var(--line); display: grid; gap: var(--s1); }
.round-card .top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.round-card .co { font-weight: 600; }
.round-card .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.round-card .line { font-size: var(--fs-caption); color: var(--text-2); }

@media (max-width: 720px) {
  .table-wrap { display: none; }
  .round-cards { display: block; }
}

.sources { font-size: var(--fs-caption); display: inline; }
.sources a { margin-right: var(--s2); white-space: nowrap; }

/* ---------------------------------------------------------------- lists */

.rows { display: grid; }
.row { display: grid; grid-template-columns: 3.4em 1fr; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.row time { font-size: var(--fs-caption); color: var(--text-2); font-variant-numeric: tabular-nums; padding-top: 2px; }
.row-title { font-weight: 600; }
.row-summary { color: var(--text-2); max-width: var(--measure); }
.row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1) var(--s3); font-size: var(--fs-caption); color: var(--text-2); margin-top: var(--s1); }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; border: 1px solid var(--text-2); display: block; }
.dots i.on { background: var(--text); border-color: var(--text); }

/* ---------------------------------------------------------------- charts */

.chart-card + .chart-card { margin-top: var(--s5); }
.chart-title { font-size: var(--fs-body); font-weight: 700; margin-bottom: var(--s1); }
.chart-sub { font-size: var(--fs-caption); color: var(--text-2); margin-bottom: var(--s2); }
.readout { min-height: 2.9em; font-size: var(--fs-caption); font-variant-numeric: tabular-nums; margin-bottom: var(--s1); }
.readout strong { font-weight: 700; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-svg text { font: 500 var(--fs-caption) var(--font-sans); fill: var(--text-2); font-variant-numeric: tabular-nums; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart-svg .bar { fill: var(--bar); transition: fill var(--dur); }
.chart-svg .bar.zero { fill: var(--line-strong); }
.chart-svg .hit { fill: transparent; }
.chart-svg g[data-bar] { outline: none; cursor: pointer; }
.chart-svg g[data-bar]:hover .bar, .chart-svg g[data-bar]:focus-visible .bar, .chart-svg g[data-bar].active .bar { fill: var(--text); }
.chart-svg g[data-bar]:focus-visible .hit { stroke: var(--focus); stroke-width: 2; rx: 4; }
.chart-svg .peak { fill: var(--text); font-weight: 700; }

.hbars { display: grid; gap: var(--s2); }
.hbar { display: grid; gap: 2px; }
.hbar-top { display: flex; justify-content: space-between; gap: var(--s3); font-size: var(--fs-caption); }
.hbar-top .name { overflow-wrap: anywhere; }
.hbar-top .val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.hbar svg { display: block; width: 100%; height: 6px; border-radius: 3px; background: var(--line); }
.hbar rect { fill: var(--bar); }

/* ---------------------------------------------------------------- footer */

.footer { border-top: 1px solid var(--line-strong); padding-top: var(--s4); padding-bottom: var(--s6); color: var(--text-2); font-size: var(--fs-caption); display: grid; gap: var(--s1); }
.footer .errs { display: grid; gap: 2px; }
.footer .err { color: var(--negative); }

/* ---------------------------------------------------------------- states */

.skeleton { background: var(--skeleton); border-radius: var(--radius); animation: pulse 1.4s ease-in-out infinite; }
.skel-line { height: 1em; margin-bottom: var(--s2); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.state-error { border: 1px solid var(--negative); border-radius: var(--radius); padding: var(--s3) var(--s4); display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }
.state-error p { flex: 1 1 240px; }
.btn { min-height: var(--tap); padding: 0 var(--s4); background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--radius); font-weight: 600; }

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

@media print {
  .masthead .seg, .stepper button, .search, .controls, .chips, .more { display: none; }
}
