:root {
  --bg: #0f1720;
  --panel: #16212e;
  --panel-2: #1d2c3d;
  --ink: #e8eef5;
  --muted: #92a4b8;
  --line: #2a3a4d;
  --accent: #4aa3ff;
  --r: #d9534f;
  --d: #4a8cf0;
  --open: #f0ad4e;
  --uncontested: #6c7a89;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.controls { display: flex; gap: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  background: transparent; color: var(--muted); border: 0; padding: 7px 14px;
  font-size: 13px; cursor: pointer; font-weight: 600;
}
.seg button span { opacity: .6; font-weight: 500; margin-left: 4px; }
.seg button.active { background: var(--accent); color: #04121f; }

/* Main / views */
main { flex: 1; position: relative; min-height: 0; }
.view { display: none; position: absolute; inset: 0; }
.view.active { display: block; }
#map { position: absolute; inset: 0; background: #0b1219; }

.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500;
  background: rgba(22,33,46,.92); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font-size: 12px; color: var(--muted);
}
.legend .lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin: 0 4px 0 10px; }
.legend .lg:first-child { margin-left: 0; }
.lg-uncontested { background: var(--uncontested); }
.lg-contested { background: var(--accent); }
.lg-open { background: var(--open); }

/* List view */
#list-view { overflow: auto; padding: 16px 20px 40px; }
.list-toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
#list-filter {
  flex: 1; min-width: 240px; background: var(--panel); border: 1px solid var(--line);
  color: var(--ink); padding: 9px 12px; border-radius: 8px; font-size: 14px;
}
.list-summary { color: var(--muted); font-size: 13px; }
#race-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.race-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; cursor: pointer; transition: border-color .12s, transform .12s;
}
.race-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.race-card h3 { margin: 0 0 2px; font-size: 15px; }
.race-card .meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.cand-line { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; }
.pill {
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  color: #04121f; min-width: 20px; text-align: center;
}
.p-R { background: var(--r); color: #fff; }
.p-D { background: var(--d); color: #fff; }
.p-N, .p-U, .p-L, .p-AI, .p-G, .p-V, .p-NP, .p-x { background: var(--uncontested); color: #fff; }
.inc-tag { font-size: 10px; font-weight: 700; color: var(--open); border: 1px solid var(--open); border-radius: 4px; padding: 0 4px; }
.tag {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; margin-left: 6px;
}
.tag.uncontested { background: #2a3744; color: var(--muted); }
.tag.contested { background: rgba(74,163,255,.18); color: var(--accent); }
.tag.open { background: rgba(240,173,78,.18); color: var(--open); }

/* Detail panel */
.detail {
  position: absolute; top: 0; right: 0; width: 380px; max-width: 92vw; height: 100%;
  background: var(--panel); border-left: 1px solid var(--line); z-index: 600;
  transform: translateX(100%); transition: transform .18s ease; overflow: auto; padding: 20px;
}
.detail.open { transform: translateX(0); box-shadow: -8px 0 30px rgba(0,0,0,.35); }
.detail .close {
  position: absolute; top: 10px; right: 12px; background: none; border: 0;
  color: var(--muted); font-size: 26px; cursor: pointer; line-height: 1;
}
.detail h2 { margin: 0 28px 2px 0; font-size: 20px; }
.detail .hint { color: var(--muted); }
.detail .lean { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.detail h4 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.cand-block { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; margin-bottom: 8px; }
.cand-block .nm { font-weight: 600; }
.cand-block .sub { color: var(--muted); font-size: 12px; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.stat .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 16px; font-weight: 600; }
.reg-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: 4px 0 2px; background: var(--line); }
.reg-bar span { display: block; height: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; }

.foot { padding: 8px 20px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.foot a { color: var(--accent); }

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .detail { width: 100%; }
}
