:root {
  color-scheme: light;
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --ink: #16191d;
  --ink-2: #4a4f57;
  --muted: #7a7f87;
  --line: #e4e1d9;
  --accent: #00369f;
  --accent-ink: #ffffff;
  --accent-soft: #e6ecf8;
  --banner: #fff4d6;
  /* Chart tokens (dataviz reference palette, light steps). */
  --chart-surface: #ffffff;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --axis-ink: #898781;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --shadow: 0 1px 2px rgba(20, 20, 20, .04), 0 4px 16px rgba(20, 20, 20, .05);
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111312;
    --surface: #1a1a19;
    --surface-2: #232422;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #93918a;
    --line: #2f302d;
    --accent: #2698ba;
    --accent-ink: #06161c;
    --accent-soft: #15303a;
    --banner: #3a3115;
    --chart-surface: #1a1a19;
    --grid: #2c2c2a;
    --axis: #383835;
    --axis-ink: #898781;
    --series-1: #3987e5;
    --series-2: #d95926;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111312;
  --surface: #1a1a19;
  --surface-2: #232422;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #93918a;
  --line: #2f302d;
  --accent: #2698ba;
  --accent-ink: #06161c;
  --accent-soft: #15303a;
  --banner: #3a3115;
  --chart-surface: #1a1a19;
  --grid: #2c2c2a;
  --axis: #383835;
  --axis-ink: #898781;
  --series-1: #3987e5;
  --series-2: #d95926;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 var(--sans);
}
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1, .prose h2 { font-family: var(--serif); font-weight: 600; }
h2 { font-size: 1.35rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
strong, b { color: var(--accent); font-weight: 600; }
.tooltip strong { color: var(--ink); }

.wrap { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 16px; }

.demo-banner {
  background: var(--banner);
  color: var(--ink);
  text-align: center;
  font-size: .875rem;
  padding: 6px 16px;
}

/* Header and footer */
.site-header { border-bottom: 1px solid var(--line); background: var(--surface); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); flex: none; }
.site-header nav { display: flex; gap: 20px; font-size: .95rem; }
.site-header nav a { color: var(--ink-2); text-decoration: none; }
.site-header nav a:hover { color: var(--accent); }

.site-footer { margin-top: 72px; border-top: 1px solid var(--line); padding: 28px 0 40px; font-size: .875rem; color: var(--ink-2); }
.site-footer p { max-width: 72ch; }

/* Home */
.hero { padding: 56px 0 24px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 600; color: var(--accent); margin-bottom: .75em; }
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.4rem); margin-bottom: .2em; }
.subtitle { font-size: 1.2rem; color: var(--ink-2); margin-bottom: .4em; }
.byline { font-weight: 500; }

.section { margin-top: 48px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head p { margin: 0; font-size: .875rem; }

.stream { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.stream-item { padding: 20px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.stream-item h3 { font-family: var(--serif); font-weight: 600; font-size: 1.3rem; margin-bottom: .3em; }
.stream-item h3 a { color: var(--ink); text-decoration: none; }
.stream-item h3 a:hover { color: var(--accent); }
.stream-item .notes { margin: 10px 0 0; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.timeline li { position: relative; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; padding: 8px 0; }
.timeline li::before { content: ""; position: absolute; left: -24px; top: 16px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--bg); }
.timeline time { color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; min-width: 6.5em; }
.timeline a { color: var(--ink); text-decoration: none; }
.timeline a:hover { color: var(--accent); }
.tag-new { font-size: .75rem; font-weight: 600; color: var(--accent); }

.meta { font-size: .875rem; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums; }
.badge-muted { background: var(--surface-2); color: var(--muted); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 500; font-size: .95rem; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { color: var(--accent-ink); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-meta { font-size: .8rem; opacity: .75; font-weight: 400; }

.share { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 24px; }
.share-label { font-size: .875rem; color: var(--muted); margin-right: 4px; }
.chip { font: inherit; font-size: .85rem; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); text-decoration: none; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* Chapter */
.crumbs { margin-top: 28px; font-size: .875rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.chapter-head { padding: 24px 0 8px; }
.chapter-head h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); }
.reader object { width: 100%; height: 80vh; min-height: 480px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); display: block; }
.reader-fallback { padding: 24px; }
@media (max-width: 700px) { .reader { display: none; } }

.versions { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.version { padding: 16px 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.version.is-latest { border-color: var(--accent); }
.version-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.version-head time { color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.tag-latest { font-size: .75rem; font-weight: 600; color: var(--accent); }
.version-dl { margin-left: auto; font-size: .9rem; }
.notes { margin-top: 10px; color: var(--ink-2); font-size: .95rem; }
.notes ul { margin: 0; padding-left: 1.2em; }
.notes p:last-child { margin-bottom: 0; }

.prose { max-width: 70ch; padding-top: 48px; }
.prose h2 { margin-top: 1.6em; font-size: 1.3rem; }

/* Dashboard */
.dash { padding-top: 40px; }
.dash-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.dash-head h1 { margin-bottom: .1em; }
.dash-head p { margin: 0; }
.range { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.range button { font: inherit; font-size: .875rem; border: 0; background: transparent; color: var(--ink-2); padding: 8px 14px; cursor: pointer; }
.range button + button { border-left: 1px solid var(--line); }
.range button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); }
.tile-label { font-size: .85rem; color: var(--ink-2); }
.tile-value { font-size: 2rem; font-weight: 600; line-height: 1.2; margin: 4px 0; }
.tile-delta { font-size: .8rem; color: var(--muted); }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.card { margin: 0 0 12px; background: var(--chart-surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 18px 14px; box-shadow: var(--shadow); min-width: 0; }
.grid-2 .card { margin: 0; }
.card h2 { font-family: var(--sans); font-size: 1rem; font-weight: 600; margin: 0 0 2px; }
.card figcaption p { font-size: .8rem; margin: 0 0 8px; }
.card summary { cursor: pointer; font-weight: 600; }

.chart { position: relative; width: 100%; height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .empty, .bars .empty { color: var(--muted); font-size: .9rem; padding: 40px 0; text-align: center; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--axis-ink); font-size: 11px; font-variant-numeric: tabular-nums; }
.crosshair { stroke: var(--axis); stroke-width: 1; }

.bars { display: grid; gap: 10px; margin-top: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 15rem) 1fr; gap: 12px; align-items: center; font-size: .875rem; }
.bar-name { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar { height: 16px; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.bar-value { color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-row:hover .bar { filter: brightness(1.12); }
@media (max-width: 560px) { .bar-row { grid-template-columns: 1fr; gap: 2px; } }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: .8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td code { font-size: .8rem; color: var(--ink-2); word-break: break-all; }

.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: .8rem; box-shadow: 0 4px 16px rgba(0, 0, 0, .12); }
.tooltip strong { font-size: 1rem; display: block; }
.tooltip .key { display: inline-block; width: 12px; height: 2px; vertical-align: middle; margin-right: 6px; }
