/* Statizoid — light and dark are both selected, not an automatic flip.
   Series colours come from the validated categorical palette; the dark column is
   the same eight hues re-stepped for the dark surface. */

:root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #eeeeec;
  --border:    #dcdcd8;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #6f6e6a;
  --accent: #2a78d6;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --radius: 10px;
  --maxw: 1120px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --border:    #34343200;
    --border:    #343432;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #9a998f;
    --accent: #3987e5;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --border:    #343432;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #9a998f;
  --accent: #3987e5;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

.muted { color: var(--text-muted); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip {
  position: absolute; left: -9999px; top: 0; background: var(--surface-1);
  padding: .6rem 1rem; z-index: 20;
}
.skip:focus { left: .5rem; top: .5rem; }

/* ── header ── */
.site-header {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.header-inner {
  display: flex; align-items: center; gap: 1rem;
  padding-top: .7rem; padding-bottom: .7rem; flex-wrap: wrap;
}
.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 700; text-decoration: none; color: var(--text-primary);
  font-size: 1.1rem; letter-spacing: -.01em;
}
.brand-mark { color: var(--accent); font-size: 1.3rem; }
.crumb {
  color: var(--text-secondary); font-size: .9rem;
  border-left: 1px solid var(--border); padding-left: 1rem;
  max-width: 40ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-form { margin-left: auto; display: flex; gap: .4rem; }
.search-form input {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: var(--radius);
  padding: .45rem .7rem; min-width: 12rem; font: inherit; font-size: .9rem;
}
.search-form button, .theme-toggle {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: var(--radius);
  padding: .45rem .8rem; font: inherit; font-size: .9rem; cursor: pointer;
}
.search-form button:hover, .theme-toggle:hover { background: var(--border); }

/* ── hero ── */
.hero { padding: 3rem 0 1.5rem; }
.hero h1 {
  font-size: clamp(1.9rem, 5vw, 3rem); line-height: 1.1;
  letter-spacing: -.02em; margin: 0 0 .75rem;
}
.lede { font-size: 1.1rem; color: var(--text-secondary); max-width: 62ch; margin: 0; }
.hero-stats { display: flex; gap: 2.5rem; list-style: none; padding: 0; margin: 2rem 0 0; flex-wrap: wrap; }
.hero-stats li { display: flex; flex-direction: column; }
.hero-num { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }
.hero-cap { color: var(--text-muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }

/* ── cards & categories ── */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; margin: 1.5rem 0;
}
.card h2, .category-title { margin-top: 0; }
.empty-state { text-align: center; padding: 2.5rem 1.5rem; }

.category-block { margin: 2.5rem 0; }
.category-title {
  display: flex; align-items: center; gap: .6rem;
  font-size: 1.35rem; margin-bottom: .25rem;
}
.category-title a { color: var(--text-primary); text-decoration: none; }
.category-title a:hover { color: var(--accent); }
.category-title .count {
  font-size: .8rem; color: var(--text-muted); background: var(--surface-2);
  border-radius: 999px; padding: .1rem .55rem; font-weight: 500;
}
.category-desc { margin: 0 0 1rem; font-size: .95rem; }

.topic-grid {
  list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
}
.topic-card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem;
}
.topic-card:hover { border-color: var(--accent); }
.topic-link { text-decoration: none; color: inherit; }
.topic-card h3 { margin: 0 0 .35rem; font-size: 1.05rem; line-height: 1.35; }
.topic-sub { margin: 0; color: var(--text-secondary); font-size: .92rem; }
.topic-meta { margin: .8rem 0 0; font-size: .8rem; }
.topic-meta code { background: var(--surface-2); padding: .1rem .4rem; border-radius: 5px; }

.cat-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); }
.cat-list li { display: flex; justify-content: space-between; gap: .5rem;
  padding: .4rem .6rem; background: var(--surface-2); border-radius: 8px; }
.cat-list a { text-decoration: none; }

/* ── topic page ── */
.topic-header { padding: 2.5rem 0 1rem; }
.eyebrow { margin: 0 0 .5rem; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.eyebrow a { text-decoration: none; }
.topic-header h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); line-height: 1.15;
  letter-spacing: -.02em; margin: 0 0 .6rem; }
.topic-facts { display: flex; gap: 2rem; flex-wrap: wrap; margin: 1.5rem 0 0; }
.topic-facts div { display: flex; flex-direction: column; }
.topic-facts dt { color: var(--text-muted); font-size: .78rem;
  text-transform: uppercase; letter-spacing: .05em; }
.topic-facts dd { margin: 0; font-weight: 600; font-size: 1.05rem; }

.notice {
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--series-4);
  border-radius: var(--radius); padding: .9rem 1.1rem; color: var(--text-secondary);
}

/* ── time range filter: one row above the charts ── */
.range-nav {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  margin: 1.5rem 0; padding: .6rem; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.range-label { color: var(--text-muted); font-size: .8rem;
  text-transform: uppercase; letter-spacing: .06em; margin-right: .3rem; }
.range-chip {
  padding: .35rem .8rem; border-radius: 999px; font-size: .88rem;
  text-decoration: none; color: var(--text-secondary); border: 1px solid transparent;
}
.range-chip:hover { background: var(--surface-2); }
.range-chip.is-active {
  background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600;
}

/* ── metric blocks & charts ── */
.metric-block {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.4rem; margin: 1.25rem 0;
}
.metric-header h2 { margin: 0 0 .3rem; font-size: 1.2rem; }
.metric-meta { font-size: .85rem; margin: .4rem 0 0; }
.chart-figure { margin: 1.2rem 0 0; }
.chart-figure figcaption { font-size: .82rem; margin-top: .5rem; }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px;
  font-family: inherit; }
.chart .pt { cursor: pointer; }
.chart .pt:hover { r: 6; }

.chart-legend {
  display: flex; flex-wrap: wrap; gap: .5rem 1.1rem;
  list-style: none; padding: 0; margin: 0 0 .8rem;
}
.lg-item { display: inline-flex; align-items: center; gap: .4rem;
  font-size: .85rem; color: var(--text-secondary); }
.lg-swatch { width: .7rem; height: .7rem; border-radius: 3px; flex: none; }

.stat-row { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 1rem; }
.stat-tile {
  background: var(--surface-2); border-radius: var(--radius);
  padding: 1rem 1.25rem; min-width: 10rem; flex: 1 1 10rem;
}
.stat-value { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat-label { color: var(--text-secondary); font-size: .9rem; margin-top: .2rem; }
.stat-when { color: var(--text-muted); font-size: .78rem; margin-top: .3rem; }

.bar-chart { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(6rem, 12rem) 1fr auto;
  align-items: center; gap: .75rem; font-size: .9rem; }
.bar-label { color: var(--text-secondary); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 1.4rem; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 4px; }
.bar-value { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── tables (also the relief for low-contrast light-mode slots) ── */
.table-wrap { margin-top: 1.2rem; }
.table-wrap summary { cursor: pointer; color: var(--text-secondary); font-size: .9rem; }
.table-scroll { overflow-x: auto; margin-top: .8rem; }
.data-table { border-collapse: collapse; width: 100%; font-size: .88rem; min-width: 20rem; }
.data-table th, .data-table td {
  text-align: left; padding: .45rem .7rem; border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--text-muted); font-weight: 600; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .04em; }
.data-table td { font-variant-numeric: tabular-nums; }

.source-list { list-style: none; padding: 0; margin: .8rem 0 0; display: grid; gap: .4rem; }
.source-list a { word-break: break-all; font-size: .88rem; }

.prose p { max-width: 68ch; }

/* ── footer ── */
.site-footer {
  border-top: 1px solid var(--border); background: var(--surface-1);
  margin-top: 3rem; padding: 2rem 0; font-size: .9rem;
}
.site-footer p { margin: .3rem 0; }

@media (max-width: 640px) {
  .search-form { margin-left: 0; width: 100%; }
  .search-form input { flex: 1; min-width: 0; }
  .crumb { display: none; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-track { grid-column: 1 / -1; }
}

/* ── multiple views per metric (CSS-only tabs, no JS required) ── */
.views { margin-top: 1.1rem; }
.view-tabs {
  display: flex; gap: .3rem; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); padding-bottom: .5rem; margin-bottom: 1rem;
}
.view-tab {
  padding: .3rem .75rem; border-radius: 999px; font-size: .84rem;
  color: var(--text-secondary); cursor: pointer; user-select: none;
  border: 1px solid transparent;
}
.view-tab:hover { background: var(--surface-2); }
.view-panel { display: none; margin: 0; }

/* Pair the Nth radio with the Nth label and the Nth panel. */
.views .view-radio:nth-of-type(1):checked ~ .view-tabs .view-tab:nth-of-type(1),
.views .view-radio:nth-of-type(2):checked ~ .view-tabs .view-tab:nth-of-type(2),
.views .view-radio:nth-of-type(3):checked ~ .view-tabs .view-tab:nth-of-type(3),
.views .view-radio:nth-of-type(4):checked ~ .view-tabs .view-tab:nth-of-type(4),
.views .view-radio:nth-of-type(5):checked ~ .view-tabs .view-tab:nth-of-type(5),
.views .view-radio:nth-of-type(6):checked ~ .view-tabs .view-tab:nth-of-type(6),
.views .view-radio:nth-of-type(7):checked ~ .view-tabs .view-tab:nth-of-type(7),
.views .view-radio:nth-of-type(8):checked ~ .view-tabs .view-tab:nth-of-type(8),
.views .view-radio:nth-of-type(9):checked ~ .view-tabs .view-tab:nth-of-type(9) {
  background: var(--accent); color: #fff; font-weight: 600; border-color: var(--accent);
}
.views .view-radio:nth-of-type(1):checked ~ .view-panel-1,
.views .view-radio:nth-of-type(2):checked ~ .view-panel-2,
.views .view-radio:nth-of-type(3):checked ~ .view-panel-3,
.views .view-radio:nth-of-type(4):checked ~ .view-panel-4,
.views .view-radio:nth-of-type(5):checked ~ .view-panel-5,
.views .view-radio:nth-of-type(6):checked ~ .view-panel-6,
.views .view-radio:nth-of-type(7):checked ~ .view-panel-7,
.views .view-radio:nth-of-type(8):checked ~ .view-panel-8,
.views .view-radio:nth-of-type(9):checked ~ .view-panel-9 { display: block; }
.views .view-radio:focus-visible ~ .view-tabs .view-tab { outline: 2px solid var(--accent); }

/* stat tile extras */
.stat-delta { font-size: .78rem; color: var(--text-secondary); margin-top: .25rem; }
.sparkline { width: 100%; max-width: 9rem; height: 1.75rem; margin-top: .5rem; display: block; }

/* dot / lollipop plot */
.lolli-chart { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .55rem; }
.lolli-row { display: grid; grid-template-columns: minmax(6rem, 12rem) 1fr auto;
  align-items: center; gap: .75rem; font-size: .9rem; }
.lolli-label { color: var(--text-secondary); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.lolli-track { position: relative; height: 1rem; display: flex; align-items: center; }
.lolli-track::before { content: ""; position: absolute; left: 0; right: 0;
  height: 1px; background: var(--border); }
.lolli-stem { height: 2px; border-radius: 2px; position: relative; }
.lolli-dot { position: absolute; width: 10px; height: 10px; border-radius: 50%;
  transform: translateX(-50%); border: 2px solid var(--surface-1); }
.lolli-value { font-variant-numeric: tabular-nums; font-weight: 600; }

/* 100% share bar */
.share-bar { display: flex; height: 2rem; border-radius: 6px; overflow: hidden;
  margin: 1rem 0 .8rem; gap: 2px; background: var(--surface-2); }
.share-seg { display: block; height: 100%; }
.share-legend { margin-top: .5rem; }

/* heatmap */
.heatmap { border-collapse: separate; border-spacing: 2px; font-size: .7rem; }
.heatmap th { color: var(--text-muted); font-weight: 500; }
.hm-day { text-align: right; padding-right: .4rem; white-space: nowrap; }
.hm-hour { text-align: center; font-size: .65rem; }
.hm-cell { width: 14px; height: 14px; border-radius: 3px; padding: 0; }
.hm-empty { background: var(--surface-2); opacity: 1; }

@media (max-width: 640px) {
  .lolli-row { grid-template-columns: 1fr auto; }
  .lolli-track { grid-column: 1 / -1; }
}

/* ── share bar ── */
.share {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin: 1.5rem 0;
}
.share-title { margin: 0 0 .9rem; font-size: 1.05rem; }
.share-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.share-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem .8rem; border-radius: 999px; font-size: .85rem;
  text-decoration: none; cursor: pointer;
  background: var(--surface-2); color: var(--text-primary);
  border: 1px solid var(--border); font-family: inherit;
}
.share-btn:hover { border-color: var(--accent); color: var(--accent); }
.share-btn span[aria-hidden] { font-weight: 700; opacity: .8; }
.share-copy { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.share-copy:hover { color: #fff; filter: brightness(1.08); }
.share-url-wrap { display: block; margin-top: .9rem; }
.share-url {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .7rem; color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82rem;
}
.share-feedback { margin: .5rem 0 0; font-size: .82rem; min-height: 1.2em; }
