/* Tokens follow the dataviz reference palette; dark values are their own validated steps. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;  /* blue: HTTP/3, default bars */
  --series-2: #eb6834;  /* orange: accent / emphasis */
  --series-3: #1baf7a;  /* aqua */
  --series-4: #eda100;  /* yellow */
  --context: #c3c2b7;   /* de-emphasized marks */
  --http2: #8f8d86;
  --http1: #c9c7bf;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface-1: #1a1a19; --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --context: #52514e; --http2: #77756f; --http1: #4a4945;
    --seq-1: #0d366b; --seq-2: #104281; --seq-3: #184f95; --seq-4: #1c5cab; --seq-5: #2a78d6; --seq-6: #5598e7; --seq-7: #9ec5f4;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19; --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --context: #52514e; --http2: #77756f; --http1: #4a4945;
  --seq-1: #0d366b; --seq-2: #104281; --seq-3: #184f95; --seq-4: #1c5cab; --seq-5: #2a78d6; --seq-6: #5598e7; --seq-7: #9ec5f4;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text-primary); font-family: var(--font); }
body { line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--series-1); }
main { max-width: 1180px; margin: 0 auto; padding: 32px 16px 48px; }

.page-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
h1 { font-size: 28px; margin: 0 0 8px; letter-spacing: -0.01em; }
.lede { max-width: 760px; color: var(--text-secondary); margin: 0; }
h2 { font-size: 18px; margin: 0 0 4px; }
.sub { color: var(--text-secondary); margin: 0 0 16px; max-width: 820px; font-size: 14px; }
.theme-toggle { background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; font-size: 18px; flex: none; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 24px 0 16px; }
.filter-label { color: var(--text-muted); font-size: 13px; margin-right: 4px; }
.filters button { font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); cursor: pointer; }
.filters button[aria-pressed="true"] { border-color: var(--series-1); box-shadow: inset 0 0 0 1px var(--series-1); font-weight: 600; }
.filters button:hover { background: color-mix(in srgb, var(--text-primary) 5%, var(--surface-1)); }
.segmented { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -4px 0 16px; }
.segmented button { font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); cursor: pointer; }
.segmented button[aria-pressed="true"] { border-color: var(--series-1); box-shadow: inset 0 0 0 1px var(--series-1); font-weight: 600; }
.segmented button:hover { background: color-mix(in srgb, var(--text-primary) 5%, var(--surface-1)); }
.segmented button:focus-visible, .filters button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.status { color: var(--text-muted); font-size: 13px; margin-left: 8px; }

.card { min-width: 0; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; transition: opacity .2s; }
.loading .card:not(.method) { opacity: 0.55; }
figure { margin: 0; min-width: 0; }
figcaption { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
@media (max-width: 900px) { .grid-3 { grid-template-columns: 1fr; } }
.chart { width: 100%; min-width: 0; }
.chart svg { display: block; max-width: 100%; height: auto; overflow: visible; }

/* hero + KPI tiles */
.hero { display: grid; grid-template-columns: minmax(220px, 1.1fr) repeat(3, minmax(0, 1fr)); gap: 24px; align-items: end; }
@media (max-width: 900px) { .hero { grid-template-columns: 1fr 1fr; } }
.party-lists { margin-top: 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 16px 32px;
  padding-top: 16px; border-top: 1px solid var(--grid); }
.party-lists .tile-note { margin-top: 6px; }
.top3 th { font-size: 12px; font-weight: 500; color: var(--text-muted); padding: 2px 8px; }
.top3 td { padding: 4px 8px; }
.top3 td:first-child, .top3 th:first-child { padding-left: 0; }
.hero-figure { font-size: 56px; font-weight: 650; line-height: 1; }
.tile-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.tile-value { font-size: 26px; font-weight: 600; }
.tile-note { font-size: 12px; color: var(--text-muted); }

/* SVG marks */
.grid { stroke: var(--grid); stroke-width: 1; }
.tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.label { fill: var(--text-secondary); font-size: 12px; }
.label.small { font-size: 11px; }
.value { fill: var(--text-primary); font-size: 12px; font-weight: 600; }
.bar { fill: var(--series-1); }
.bar.accent { fill: var(--series-2); }
.bar.hover, .segment:hover, .segment:focus { filter: brightness(1.12); }
.benchmark { stroke: var(--text-secondary); stroke-width: 1; }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.end-dot { stroke: var(--surface-1); stroke-width: 2; }
.crosshair { stroke: var(--axis); stroke-width: 1; }
.dot { fill: var(--context); stroke: var(--surface-1); stroke-width: 2; }
.dot.accent { fill: var(--series-2); }
.dot.hover { stroke: var(--text-primary); }
.on-light { fill: #0b0b0b; color: #0b0b0b; }
.on-dark { fill: #ffffff; color: #ffffff; }
.hit:focus { outline: none; }
.hit:focus-visible { outline: 2px solid var(--series-1); outline-offset: -2px; }

/* legend + tooltip */
.legend { display: flex; flex-wrap: wrap; gap: 16px; list-style: none; padding: 0; margin: 0 0 8px; font-size: 12px; color: var(--text-secondary); }
.legend li { display: flex; align-items: center; gap: 6px; }
.key-box { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.key-line { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.tooltip { position: absolute; z-index: 10; pointer-events: none; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); max-width: 320px; }
.tooltip-title { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip-row { display: flex; align-items: center; gap: 6px; }
.tooltip-row strong { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }

/* tables */
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); }
th { color: var(--text-secondary); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-view { margin-top: 12px; }
.table-view summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; }
.table-scroll { overflow-x: auto; max-height: 420px; overflow-y: auto; margin-top: 8px; }
.heat { width: auto; min-width: 60%; }
.heat td { min-width: 72px; border: 2px solid var(--surface-1); border-radius: 4px; }
.heat td:focus-visible { outline: 2px solid var(--text-primary); }
.ranked { margin-top: 16px; }

/* parties: one ranked comparison, three columns that line up across rows */
.parties { list-style: none; padding: 0; margin: 0; }
.party-head, .party { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(200px, 1fr) 132px; column-gap: 32px; }
.party-head { font-size: 12px; color: var(--text-muted); padding-bottom: 8px; align-items: center; }
.party-head-meter { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.key-avg { width: 1px; height: 12px; background: var(--text-secondary); margin-left: 6px; }
.key-cmp { width: 8px; height: 8px; border-radius: 50%; background: var(--series-1); margin-left: 6px; }
.party { align-items: center; padding: 16px 0; border-top: 1px solid var(--grid); }
.party-name { font-size: 15px; font-weight: 600; line-height: 1.35; }
.party-desc { margin: 3px 0 0; font-size: 13px; line-height: 1.5; color: var(--text-secondary); max-width: 64ch; }
.party-meter { display: grid; grid-template-columns: minmax(0, 1fr) 56px; align-items: center; column-gap: 12px; row-gap: 4px; }
.meter { position: relative; height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--series-2) 16%, var(--surface-1)); }
.meter-fill { position: absolute; inset: 0 auto 0 0; min-width: 2px; border-radius: 4px; background: var(--series-2); }
.meter-avg { position: absolute; top: -5px; bottom: -5px; width: 1px; background: var(--text-secondary); }
.meter-cmp { position: absolute; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%;
  background: var(--series-1); box-shadow: 0 0 0 2px var(--surface-1); }
.meter-value { font-size: 14px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.meter-note { grid-column: 1 / -1; font-size: 12px; color: var(--text-muted); }
.party-traffic { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.traffic-value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.traffic-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
@media (max-width: 760px) {
  .party-head { display: none; }
  .party { grid-template-columns: minmax(0, 1fr) auto; row-gap: 10px; column-gap: 16px; }
  .party > :first-child { grid-column: 1 / -1; }
  .party-traffic { align-items: flex-end; }
}

.method ul { margin: 0; padding-left: 20px; color: var(--text-secondary); font-size: 14px; }
.method li { margin-bottom: 6px; }
.error { color: #d03b3b; }
footer { color: var(--text-muted); font-size: 12px; margin-top: 24px; }
.heat-wrap { overflow-x: auto; }
.halo { paint-order: stroke; stroke: var(--surface-1); stroke-width: 3px; stroke-linejoin: round; }
