:root {
  --bg: #000;
  --panel: #0b0b0b;
  --line: #262626;
  --fg: #e6e6e6;
  --dim: #8a8a8a;
  --amber: #ffb000;
  --amber-dim: #7a5500;
  --up: #23d160;
  --down: #ff3b3b;
  --dem: #2f7bff;
  --rep: #ff3d3d;
  --ind: #b46bff;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 12px/1.35 var(--mono); }
body { display: flex; flex-direction: column; }
button, input { font: inherit; color: inherit; }
.dim { color: var(--dim); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: stretch; gap: 16px; padding: 6px 10px; border-bottom: 1px solid var(--amber-dim); background: var(--panel); }
.brand { color: var(--amber); font-weight: 700; letter-spacing: .5px; align-self: center; white-space: nowrap; }
.tiles { display: flex; gap: 10px; flex: 1; overflow: hidden; }
.tile { border: 1px solid var(--line); padding: 2px 8px; min-width: 190px; }
.tile .t { color: var(--amber); font-size: 10px; }
.tile .v { display: flex; gap: 10px; white-space: nowrap; }
.tile b { font-weight: 600; }
.modes { display: flex; gap: 4px; align-self: center; }
.modes button, .seg button {
  background: #141414; border: 1px solid var(--line); padding: 3px 10px; cursor: pointer; color: var(--dim);
}
.modes button.active, .seg button.active { background: var(--amber); color: #000; border-color: var(--amber); font-weight: 700; }
.clock { color: var(--amber); align-self: center; white-space: nowrap; }

/* ---------- views ---------- */
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.label { color: var(--amber); font-size: 10px; }
.seg { display: flex; }
.seg button + button { border-left: 0; }
.chk { color: var(--dim); cursor: pointer; user-select: none; }
#tbl-search { background: #0f0f0f; border: 1px solid var(--line); padding: 3px 8px; width: 260px; color: var(--amber); }
#tbl-search:focus { outline: 1px solid var(--amber); }
.count { color: var(--dim); margin-left: auto; }

/* ---------- map ---------- */
.map-layout { flex: 1; display: flex; min-height: 0; }
.map-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 8px; min-width: 0; }
#map { width: 100%; height: 100%; max-height: calc(100vh - 120px); }
#map path.state { stroke: #000; stroke-width: .8; cursor: pointer; transition: fill .4s; }
#map path.state:hover { stroke: var(--amber); stroke-width: 2; }
#map path.state.none { fill: #1a1a1a; stroke: #333; cursor: default; }
#map path.borders { fill: none; stroke: #000; stroke-width: .6; pointer-events: none; }
#map text { font: 600 10px var(--mono); fill: #fff; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: #000; stroke-width: 2.5px; }
#map text .p { font-weight: 400; }
.legend { display: flex; align-items: center; gap: 6px; color: var(--dim); margin-left: auto; }
.legend .bar { width: 180px; height: 10px; border: 1px solid var(--line); }
.watch { width: 430px; border-left: 1px solid var(--line); overflow: auto; }
.watch-title { color: var(--amber); padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 10px; }
.tooltip { position: fixed; z-index: 10; pointer-events: none; background: #050505; border: 1px solid var(--amber); padding: 6px 8px; min-width: 280px; }
.tooltip h4 { margin: 0 0 4px; color: var(--amber); font-size: 12px; }
.tooltip table { border-collapse: collapse; width: 100%; }
.tooltip td { padding: 1px 4px; text-align: right; }
.tooltip td:first-child { text-align: left; }

/* ---------- grid ---------- */
.table-wrap { flex: 1; overflow: auto; }
table.grid { border-collapse: collapse; width: 100%; }
.grid th { position: sticky; top: 0; background: #111; color: var(--amber); font-weight: 600; font-size: 10px; padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--amber-dim); white-space: nowrap; z-index: 1; }
.grid tr.group th { top: 0; border-bottom: 0; text-align: center; color: var(--dim); }
.grid thead tr:nth-child(2) th { top: 19px; }
.grid th.l, .grid td.l { text-align: left; }
.grid td { padding: 2px 6px; text-align: right; white-space: nowrap; border-bottom: 1px solid #141414; font-variant-numeric: tabular-nums; }
.grid tbody tr:hover td { background: #161616; }
.grid tr.race-start td { border-top: 1px solid #2c2c2c; }
.grid td.race { color: var(--amber); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.grid td.race a { color: inherit; text-decoration: none; }
.grid td.race a:hover { text-decoration: underline; }
.grid td.cand { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.grid td.mid { font-weight: 700; }
.grid td.na { color: #444; }
.grid .venue-k { color: #3ddc97 !important; }
.grid .venue-p { color: #5aa9ff !important; }
.grid.compact td { padding: 2px 5px; }
.grid.compact th { position: static; }
.watch .grid tr { cursor: pointer; }

.pty { font-weight: 700; }
.pty.D { color: var(--dem); }
.pty.R { color: var(--rep); }
.pty.I, .pty.L { color: var(--ind); }
.pos { color: var(--up); }
.neg { color: var(--down); }
.arb-live td.arb { background: #0d3b1d; color: #6dff9e; font-weight: 700; }
.settled { color: var(--amber); font-weight: 700; }

/* Fixed layout: changing cell text never forces the browser to re-measure all ~1000 rows. */
#tbl { table-layout: fixed; min-width: 1280px; }
#tbl td { overflow: hidden; text-overflow: ellipsis; }

/* ---------- status bar ---------- */
.statusbar { display: flex; gap: 18px; padding: 3px 10px; border-top: 1px solid var(--line); background: var(--panel); color: var(--dim); font-size: 11px; white-space: nowrap; overflow: hidden; }
.statusbar .ok { color: var(--up); }
.statusbar .warn { color: var(--amber); }
.statusbar .bad { color: var(--down); }

/* ---------- staleness ---------- */
.alert { align-self: center; background: var(--down); color: #fff; font-weight: 700; padding: 3px 10px; white-space: nowrap; animation: blink 1.2s steps(2, start) infinite; }
.alert[hidden] { display: none; }
@keyframes blink { to { opacity: .55; } }
body.stale-k #tbl td.kb, body.stale-k #tbl td.ka, body.stale-k #tbl td.km,
body.stale-p #tbl td.pb, body.stale-p #tbl td.pa, body.stale-p #tbl td.pm { opacity: .35; text-decoration: line-through; }
