/* Layout: one working screen. The map takes the room and a scrolling results
   ledger sits beside it. Neutrals lean cool so red and blue carry all the color. */
:root {
  --bg: #e9ecf3;
  --surface: #f8f9fc;
  --ink: #141829;
  --muted: #565d73;
  --line: #d1d5e1;
  --sea: #e9ecf3;
  --halo: rgba(255, 255, 255, 0.88);
  --border-map: #ffffff;
  --alert-bg: #fff1cf;
  --alert-ink: #5d4100;

  --party-d: #3f7bdc;
  --party-r: #e0503f;
  --party-o: #d9a72e;
  --d1: #9dbff2; --d2: #4f88e3; --d3: #1b54b5;
  --r1: #f5ab9f; --r2: #e45e4c; --r3: #b4261b;
  --o1: #f0d68f; --o2: #dcae37; --o3: #a97a10;
  /* Party colors for text: shaded to stay readable on the panel background. */
  --text-d: #1f5fc4; --text-r: #c22f1f; --text-o: #8a6508;
  --none: #cdd1dd;
  --norace: #e1e4ec;
  --norace-line: #c8ccd9;
  --tie: #8e84b8;

  --font-display: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Public Sans", "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10131e;
    --surface: #171b2a;
    --ink: #eef0f7;
    --muted: #a4abc0;
    --line: #2c3147;
    --sea: #10131e;
    --halo: rgba(12, 14, 24, 0.85);
    --border-map: #10131e;
    --alert-bg: #41320b;
    --alert-ink: #ffe3a3;
    --party-d: #4f8cf0;
    --party-r: #cf4436;
    --party-o: #b98d25;
    --d1: #264d8c; --d2: #2f69c6; --d3: #4f8ff5;
    --r1: #7d302a; --r2: #b53e30; --r3: #ef5a48;
    --o1: #7d6119; --o2: #c49a2d; --o3: #f0cf72;
    --text-d: #7aaaf7; --text-r: #f2796b; --text-o: #dcb64a;
    --none: #30354a;
    --norace: #1a1e2d;
    --norace-line: #2c3147;
    --tie: #8378b0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.45 var(--font-body);
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12.5px; }

/* --- Top bar --- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand h1 {
  margin: 0; font: 700 28px/1 var(--font-display);
  letter-spacing: 0.01em; text-transform: uppercase;
}
.brand p { margin: 0; color: var(--muted); font-size: 12.5px; }

.tabs { display: flex; gap: 2px; padding: 2px; background: var(--bg); border-radius: 8px; }
.tabs button {
  border: 0; background: none; cursor: pointer; padding: 5px 14px; border-radius: 6px;
  font: 600 16px/1.2 var(--font-display); letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted);
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.live { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.dot-live { width: 9px; height: 9px; border-radius: 50%; background: var(--none); flex: none; }
.dot-live[data-state="live"] { background: #1f9d55; animation: breathe 2.4s ease-in-out infinite; }
.dot-live[data-state="partial"] { background: var(--party-o); }
.dot-live[data-state="down"] { background: var(--party-r); }
@keyframes breathe { 50% { opacity: 0.45; } }

.link-btn {
  border: 0; background: none; padding: 0; cursor: pointer; color: var(--ink);
  text-decoration: underline; text-underline-offset: 2px; font-size: 12.5px;
}
.link-btn:disabled { color: var(--muted); cursor: default; }

.alert {
  margin: 0; padding: 8px max(16px, env(safe-area-inset-left, 0px));
  background: var(--alert-bg); color: var(--alert-ink); font-weight: 500; font-size: 13px;
}

/* --- Layout --- */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) 400px;
}
.map-column { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.map-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#map { display: block; width: 100%; height: 100%; touch-action: pan-y pinch-zoom; }

.panel {
  min-width: 0; overflow-y: auto; background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 16px;
  display: flex; flex-direction: column; gap: 18px;
}

/* --- Map marks --- */
.sea { fill: var(--sea); cursor: default; }
.st, .ar {
  stroke: var(--border-map); stroke-width: 1; vector-effect: non-scaling-stroke;
  stroke-linejoin: round; transition: opacity 0.35s ease;
}
.st { cursor: pointer; outline: none; }
.st:hover, .st:focus-visible, .st.hl { stroke: var(--ink); stroke-width: 2; }
.ar { stroke-width: 0.6; cursor: default; }
.ar:hover, .ar.hl { stroke: var(--ink); stroke-width: 2; }
.ar { outline: none; }
.ar-district { stroke-width: 1.2; }
.outline-halo, .outline-line {
  fill: none; vector-effect: non-scaling-stroke; stroke-linejoin: round; pointer-events: none;
}
.outline-halo { stroke: var(--surface); stroke-width: 6.5; }
.outline-line { stroke: var(--ink); stroke-width: 3; }
.tv .outline-halo { stroke-width: 9; }
.tv .outline-line { stroke-width: 4.5; }
.d-lbl {
  font-family: var(--font-display); font-weight: 700; text-anchor: middle; dominant-baseline: central;
  fill: var(--ink); stroke: var(--halo); paint-order: stroke; pointer-events: none;
}
.view-toggle {
  position: absolute; top: 10px; left: 10px; z-index: 4; display: flex; gap: 2px; padding: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.view-toggle button {
  border: 0; background: none; cursor: pointer; padding: 4px 12px; border-radius: 6px;
  font: 600 15px/1.2 var(--font-display); letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted);
}
.view-toggle button:hover { color: var(--ink); }
.view-toggle button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.tv .view-toggle button { font-size: clamp(15px, 1.15vw, 30px); }
.ar.out { fill: var(--norace); stroke: var(--norace-line); }
.has-focus .st:not(.sel) { opacity: 0.32; }
.has-focus .st.sel { stroke: var(--ink); stroke-width: 1.5; }

.f-D1 { fill: var(--d1); background: var(--d1); } .f-D2 { fill: var(--d2); background: var(--d2); } .f-D3 { fill: var(--d3); background: var(--d3); }
.f-R1 { fill: var(--r1); background: var(--r1); } .f-R2 { fill: var(--r2); background: var(--r2); } .f-R3 { fill: var(--r3); background: var(--r3); }
.f-O1 { fill: var(--o1); background: var(--o1); } .f-O2 { fill: var(--o2); background: var(--o2); } .f-O3 { fill: var(--o3); background: var(--o3); }
.f-none { fill: var(--none); background: var(--none); }
.f-tie { fill: var(--tie); background: var(--tie); }
.f-norace { fill: var(--norace); background: var(--norace); }
.st.f-norace { stroke: var(--norace-line); }

.lbl {
  font: 600 var(--lbl-size, 12.5px) var(--font-display); letter-spacing: 0.03em; text-anchor: middle;
  fill: var(--ink); stroke: var(--halo); stroke-width: 3px; paint-order: stroke;
  pointer-events: none; transition: opacity 0.25s;
}
.leader { stroke: var(--muted); stroke-width: 0.7; pointer-events: none; transition: opacity 0.25s; }
.is-zoomed .lbl, .is-zoomed .leader { opacity: 0; }

/* --- Tooltip --- */
.tooltip {
  position: absolute; top: 0; left: 0; z-index: 5; width: 290px; max-width: calc(100% - 16px);
  padding: 10px 12px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 22px rgba(10, 14, 30, 0.2);
  pointer-events: none;
}
.tooltip h3 {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  margin: 0 0 6px; font: 700 19px/1.15 var(--font-display); letter-spacing: 0.01em;
}
.tip-lead { font-size: 24px; font-weight: 700; white-space: nowrap; }
.lead-num { font: 700 20px/1.1 var(--font-display); color: var(--ink); white-space: nowrap; }
.tv .bop-row .lead-num { font-size: clamp(20px, 1.6vw, 42px); }
.tip-line {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 58px; column-gap: 8px;
  align-items: baseline; margin-bottom: 7px; font-size: 13px;
}
.tip-name { min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.tip-num { text-align: right; font: 700 18px/1.1 var(--font-display); }
.tv .tip-num { font-size: 1.35em; }
.tip-pct { font: 700 20px/1.1 var(--font-display); color: var(--ink); }
.tv .tip-pct { font-size: 1.5em; }
.meter { grid-column: 1 / -1; display: block; height: 5px; margin-top: 3px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 3px; }
.p-D { background: var(--party-d); } .p-R { background: var(--party-r); } .p-O { background: var(--party-o); }
.v-D { color: var(--text-d); } .v-R { color: var(--text-r); } .v-O { color: var(--text-o); }
.tip-counted { display: flex; align-items: baseline; gap: 6px; margin: 0 0 8px; font-size: 12.5px; color: var(--muted); }
.tip-counted strong { font: 700 34px/1 var(--font-display); color: var(--ink); }
.tv .tip-counted { font-size: 0.95em; }
.tv .tip-counted strong { font-size: 2em; }
.tip-votes { font: 700 24px/1 var(--font-display); color: var(--ink); }
.tv .tip-votes { font-size: 1.8em; }
.tip-note { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.tip-hint { margin: 4px 0 0; font-size: 12px; font-weight: 600; }
.won { font-size: 11.5px; font-weight: 700; white-space: nowrap; }


/* --- Panel content --- */
/* Positioned so the hidden filter label stays inside the pane's scrolling area. */
.pane { position: relative; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.panel section { display: flex; flex-direction: column; gap: 8px; }
.eyebrow { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.big { margin: 0; font: 700 44px/1 var(--font-display); }

.stack { display: flex; gap: 2px; height: 12px; }
.stack-seg { min-width: 2px; flex: 1 1 0; }
.stack-seg:first-child { border-radius: 4px 0 0 4px; }
.stack-seg:last-child { border-radius: 0 4px 4px 0; }
.stack-empty { background: var(--none); border-radius: 4px; }

.figures { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.figures dt { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.figures dd { margin: 0; font: 600 22px/1.15 var(--font-display); }
.figures dd.sub { font: 700 20px/1.15 var(--font-display); color: var(--ink); }
.fig-right { text-align: right; }
.fig-right dt { justify-content: flex-end; }
.fig-wide { grid-column: 1 / -1; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.called { margin: 0; font-size: 13px; }
.caveat { margin: 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.section-title {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 0;
  font: 700 19px/1.2 var(--font-display); letter-spacing: 0.01em;
}
.section-title .muted { font: 400 12.5px var(--font-body); text-align: right; }

.table-wrap { overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th, .grid td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
.grid thead th { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.grid tbody th { font-weight: 500; overflow-wrap: break-word; }
.grid tbody tr:hover { background: var(--bg); }
.grid .num { text-align: right; white-space: nowrap; }
.grid th:first-child, .grid td:first-child { padding-left: 2px; }
.grid th:last-child, .grid td:last-child { padding-right: 2px; }
.cell-lead { white-space: nowrap; }
.cell-lead .muted { white-space: normal; }
.is-sub th { padding-left: 16px !important; font-weight: 400 !important; color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 2px; vertical-align: -1px; }
.link { border: 0; background: none; padding: 0; cursor: pointer; font-weight: 500; text-align: left; }
.link:hover { text-decoration: underline; text-underline-offset: 2px; }

.back {
  align-self: flex-start; border: 1px solid var(--line); background: none; border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.back:hover { background: var(--bg); }
.state-name { margin: -8px 0 -14px; font: 700 38px/1.05 var(--font-display); }
.pane > p { margin: 0; }
.switchers { display: flex; gap: 12px; }

.race { padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.race-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.race-head h3 { margin: 0; font: 700 19px/1.2 var(--font-display); }
.race-pct { margin-left: auto; display: inline-flex; align-items: baseline; gap: 5px; font-size: 12.5px; color: var(--muted); }
.race-pct strong { font: 700 36px/1 var(--font-display); color: var(--ink); }
.pct-cell, .vote-cell { font: 700 20px/1.1 var(--font-display); color: var(--ink); }
.vote-cell.v-D { color: var(--text-d); } .vote-cell.v-R { color: var(--text-r); } .vote-cell.v-O { color: var(--text-o); }
.tally-state .figures dd:not(.sub) { font-size: 34px; line-height: 1.05; }
.race .tip-num:not(.tip-pct), .district-body .tip-num:not(.tip-pct) { font-size: 24px; }
.district-head .num:last-child, .grid thead .num:last-child { color: var(--ink); }
.pill { padding: 0 7px; border: 1px solid var(--ink); border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill-called { background: var(--ink); color: var(--surface); }
.race p { margin: 0; }

.district-head, .district-row {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) 78px 56px; gap: 6px; align-items: center;
}
.district-head { padding: 0 4px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.district-head .num, .district-row .num { text-align: right; }
.districts { list-style: none; margin: 0; padding: 0; }
.district { border-top: 1px solid var(--line); }
.district-row {
  width: 100%; padding: 6px 4px; border: 0; background: none; cursor: pointer; text-align: left; font-size: 13px;
}
.district-row:hover, .is-open .district-row { background: var(--bg); }
.d-name { font-weight: 500; }
.district-body { padding: 8px 4px 2px; }

.filter input {
  width: 100%; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink); font: inherit;
}
.notice { margin: 0; padding: 8px 10px; background: var(--alert-bg); color: var(--alert-ink); border-radius: 6px; font-size: 13px; }

/* Only full screen needs this line: the map's results panel, which explains the colors, is hidden there. */
.source { display: none; }
.tv:not(.page-balance) .source {
  display: block;
  padding-block: 6px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-top: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: 11.5px;
}

/* --- Balance of power: one block per office, side by side when there's room --- */
.balance {
  flex: 1; min-height: 0; overflow-y: auto; background: var(--bg);
  display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 12px;
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.bop-key {
  grid-column: 1 / -1; margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
  font-size: 12.5px; color: var(--muted);
}
.bop-key span { display: inline-flex; align-items: center; gap: 6px; }
.bop-key i { display: inline-block; width: 22px; height: 11px; border-radius: 2px; }
.bop-key .pair { display: inline-flex; gap: 2px; }
.bop-key .pair i { width: 11px; }
.bop-key .caveat-inline { flex-basis: 100%; }
.bop {
  min-width: 0; display: flex; flex-direction: column; gap: 10px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.bop-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; }
.bop-head h2 { margin: 0; font: 700 28px/1.1 var(--font-display); letter-spacing: 0.01em; text-transform: uppercase; }
.bop-score { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 12px; }
.bop-side p, .bop-mid p { margin: 0; }
.bop-party { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.bop-seats { font: 700 clamp(64px, 7vw, 112px)/0.95 var(--font-display); }
.bop-others { font: 700 20px/1.1 var(--font-display); }
.bop-detail { font-size: 12.5px; color: var(--muted); }
.bop-side-r { text-align: right; }
.bop-side-r .bop-party { justify-content: flex-end; }
.bop-mid { text-align: center; padding-bottom: 2px; }
.bop-left { font: 700 clamp(26px, 2.6vw, 40px)/1 var(--font-display); }
.bop-track { position: relative; padding-top: 18px; }
.bop-bar { display: flex; height: 22px; background: var(--none); border-radius: 4px; overflow: hidden; }
.bop-bar span { display: block; height: 100%; box-shadow: inset -2px 0 0 var(--surface); }
.bop-bar .gap { flex: 1; box-shadow: none; }
.bop-bar .right { box-shadow: inset 2px 0 0 var(--surface); }
.bop-tick { position: absolute; left: 50%; top: 14px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--ink); }
.bop-tick-label { position: absolute; left: 50%; top: 0; transform: translateX(-50%); font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.bop-needs { margin: 2px 0 0; font-size: 13.5px; font-weight: 500; }
.bop-facts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.bop-facts dt { font-size: 12px; color: var(--muted); }
.bop-facts dd { margin: 0; font-size: 13.5px; font-weight: 600; }
.bop-lists { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.bop-list h3 { margin: 0 0 2px; font: 700 17px/1.2 var(--font-display); }
.bop-list ul { list-style: none; margin: 0; padding: 0; }
.bop-list li { border-top: 1px solid var(--line); }
.bop-list p { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.bop-row {
  width: 100%; display: flex; justify-content: space-between; gap: 8px; padding: 5px 0;
  border: 0; background: none; cursor: pointer; text-align: left; font-size: 13px;
}
.bop-row:hover { background: var(--bg); }
.bop-row-name { min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.bop-row-value { flex: none; display: inline-flex; align-items: baseline; gap: 8px; color: var(--muted); }
.bop-pct { min-width: 2.6em; text-align: right; font: 700 20px/1.1 var(--font-display); color: var(--ink); }
.tv .bop-pct { font-size: clamp(20px, 1.6vw, 42px); }
.bop-note { margin: 0; font-size: 12.5px; color: var(--muted); }
body.page-balance #tv-score { display: none; }

@media (min-width: 640px) {
  .bop-lists { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1100px) and (min-aspect-ratio: 5/4) {
  .balance { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bop-lists { grid-template-columns: minmax(0, 1fr); }
}
.tv .balance { font-size: clamp(14px, 1vw, 26px); }
.tv .bop-head h2 { font-size: clamp(28px, 2.2vw, 56px); }
.tv .bop-party, .tv .bop-needs, .tv .bop-facts dd, .tv .bop-row { font-size: clamp(13.5px, 1.05vw, 28px); }
.tv .bop-detail, .tv .bop-facts dt, .tv .bop-list p, .tv .bop-note, .tv .bop-key { font-size: clamp(12.5px, 0.85vw, 22px); }
.tv .bop-list h3 { font-size: clamp(17px, 1.3vw, 34px); }
.tv .bop-seats { font-size: clamp(64px, 8vw, 200px); }
.tv .bop-left { font-size: clamp(26px, 3vw, 76px); }
.tv .bop-bar { height: clamp(22px, 2.6vh, 56px); }
.tv .bop-tick-label { font-size: clamp(11.5px, 0.85vw, 22px); }

/* --- Full screen mode: readable from across a room --- */
.tv-score {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2.2fr) minmax(0, 1fr); align-items: center; gap: 2vw;
  padding: 1.1vh 2vw; background: var(--surface); border-bottom: 1px solid var(--line);
}
.tv-score p { margin: 0; }
.tv-party { display: flex; align-items: center; gap: 0.5em; font-size: clamp(14px, 1.15vw, 30px); font-weight: 600; }
.tv-party .dot { width: 0.8em; height: 0.8em; }
.tv-votes { font: 700 clamp(30px, 3.6vw, 96px)/1 var(--font-display); }
.tv-share { font: 700 clamp(20px, 2vw, 52px)/1.1 var(--font-display); color: var(--ink); }
.tv-pct { font: 700 1.35em/1 var(--font-display); }
.tv-side-r { text-align: right; }
.tv-side-r .tv-party { justify-content: flex-end; }
.tv-middle { display: flex; flex-direction: column; align-items: center; gap: 0.5vh; min-width: 0; text-align: center; }
.tv-middle .eyebrow { font-size: clamp(12px, 0.95vw, 24px); }
.tv-total { font: 700 clamp(34px, 4.2vw, 112px)/1 var(--font-display); }
.tv-middle .stack { width: 100%; height: clamp(12px, 1.3vh, 28px); }
.tv-facts { font-size: clamp(13px, 1.05vw, 28px); }
.tv-sep { margin-inline: 0.4em; color: var(--muted); }

.tv .topbar { padding-block: 0.7vh; }
.tv .brand h1 { font-size: clamp(24px, 2vw, 52px); }
.tv .brand p, .tv .live, .tv .live .link-btn { font-size: clamp(12.5px, 0.95vw, 24px); }
.tv .tabs button { font-size: clamp(16px, 1.25vw, 32px); }
.tv .source { font-size: clamp(11.5px, 0.8vw, 20px); }
.tv .tooltip { width: clamp(290px, 24vw, 640px); font-size: clamp(13px, 1vw, 26px); }
.tv .tooltip h3 { font-size: 1.6em; }
.tv .tip-lead { font-size: 0.8em; }
.tv .tip-line { font-size: 1em; }
.tv .tip-note, .tv .tip-hint { font-size: 0.95em; }
.tv .layout { grid-template-columns: minmax(0, 1fr) clamp(360px, 27vw, 760px); }
.tv:not(.has-state) .layout { grid-template-columns: minmax(0, 1fr); }
.tv:not(.has-state) .panel { display: none; }
.tv-idle, .tv-idle * { cursor: none !important; }
.tv-idle .live .link-btn { visibility: hidden; }

@media (min-width: 1700px) {
  .tv .panel { zoom: 1.3; }
}

/* --- Half-width windows, such as split view: the map runs across the top and
   results sit below it. Used whenever a window is narrow or close to square,
   because a map beside the results would leave empty space above and below it. --- */
@media (max-width: 920px), (max-aspect-ratio: 5/4) {
  .layout { display: flex; flex-direction: column; }
  .tv .layout { display: flex; }
  .map-column { flex: none; }
  .map-wrap { flex: none; width: 100%; aspect-ratio: 1040 / 615; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .tooltip { width: 250px; }
  .topbar { padding-block: 8px; gap: 8px 20px; }
  .tv:not(.has-state) .map-column { flex: 1; min-height: 0; }
  .tv:not(.has-state) .map-wrap { aspect-ratio: auto; flex: 1; min-height: 0; max-height: none; }
}

/* Roomy enough to fit on one screen: results get two columns that scroll on their own. */
@media (min-width: 640px) and (min-height: 640px) and (max-width: 920px),
       (min-width: 921px) and (max-aspect-ratio: 5/4) {
  .map-wrap { max-height: 54vh; }
  .tv .map-wrap { max-height: 38vh; }
  .panel {
    flex: 1; min-height: 0; overflow: hidden; padding: 0; gap: 0;
    display: grid; grid-template-columns: minmax(250px, 2fr) minmax(0, 3fr);
  }
  .pane { overflow-y: auto; padding: 14px; gap: 14px; min-height: 0; }
  .pane-only { grid-column: 1 / -1; }
  .pane-summary { border-right: 1px solid var(--line); }
  .big { font-size: 38px; }
  .state-name { margin: -6px 0 -10px; font-size: 32px; }
  .figures dd { font-size: 20px; }
  .fig-wide { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
  .fig-wide dd { font-size: 16px; }
  .fig-wide dd.sub { font-size: 20px; }
  .tally-state .figures dd:not(.sub) { font-size: 25px; }
  .tally-state .fig-wide dd:not(.sub) { font-size: 22px; }
}

/* Too small for that: one column, and the page scrolls. */
@media (max-width: 639px), (max-width: 920px) and (max-height: 639px) {
  html, body { height: auto; }
  .panel { overflow: visible; }
  .map-wrap { max-height: 75vh; }
}

@media (max-width: 760px) {
  .live { margin-left: 0; flex-basis: 100%; }
}

@media (max-width: 639px) {
  .tv-score { grid-template-columns: 1fr 1fr; }
  .tv-middle { grid-column: 1 / -1; grid-row: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .st, .ar, .lbl, .leader { transition: none; }
  .dot-live[data-state="live"] { animation: none; }
}
