:root {
  color-scheme: light;
  --bg: #f5f4f0;
  --panel: #ffffff;
  --text: #0b0b0b;
  --text-2: #52514e;
  --border: #dcdad3;
  --accent: #2a78d6;
  --chip: #f1f0ec;
  --chip-on: #0b0b0b;
  --chip-on-text: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --panel: #1a1a19;
    --text: #f4f3ec;
    --text-2: #c3c2b7;
    --border: #3a3a37;
    --accent: #3987e5;
    --chip: #2a2a28;
    --chip-on: #f4f3ec;
    --chip-on-text: #1a1a19;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app { display: grid; grid-template-columns: 410px 1fr; height: 100vh; }
.panel {
  overflow-y: auto;
  padding: 18px 20px 28px;
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }

h1 { font-size: 20px; line-height: 1.25; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 8px; }
.sub { margin: 0 0 16px; color: var(--text-2); }

.control { margin: 0 0 16px; }
.control > label, .control > .label { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.val { font-weight: 700; color: var(--accent); }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--text-2); }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }
.ticks { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); padding: 0 2px; }

.control > label.check { justify-content: flex-start; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; cursor: pointer; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.check.opt { font-weight: 400; margin-bottom: 6px; }
.sub-h { font-size: 13px; margin: 12px 0 4px; }
.check.disabled { opacity: 0.55; cursor: not-allowed; }

.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; padding: 8px 6px; border: 0; border-right: 1px solid var(--border);
  background: var(--chip); color: var(--text); font: inherit; cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-text); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 11px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--chip); color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-text); border-color: var(--chip-on); font-weight: 600; }

button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#summary, #response, #top { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 4px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--chip); border-radius: 10px; padding: 10px 12px; }
.tile .big { font-size: 24px; font-weight: 700; line-height: 1.15; }
.tile .lbl { font-size: 13px; color: var(--text-2); }
.empty { color: var(--text-2); margin: 0 0 8px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 0 4px 6px 0; }
td { padding: 5px 4px 5px 0; border-top: 1px solid var(--border); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.warn-note { font-size: 12.5px; color: #b42318; margin: 4px 0 0; font-weight: 600; }
.gap-h { font-size: 12.5px; font-weight: 700; margin: 10px 0 4px; }
.gap { border-top: 1px solid var(--border); padding: 6px 0; font-size: 13.5px; }
.gap .strong, .link.strong { font-weight: 600; }
.cands { margin: 2px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--text-2); }
.link { border: 0; background: none; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; text-align: left; }
.note { font-size: 12.5px; color: var(--text-2); margin: 8px 0 0; }

ol.toplist { margin: 0; padding: 0; list-style: none; }
.toplist li { border-top: 1px solid var(--border); }
.toplist button {
  display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
  padding: 8px 2px; border: 0; background: none; color: var(--text); font: inherit; cursor: pointer;
}
.toplist button:hover { background: var(--chip); }
.toplist .place { font-weight: 600; }
.toplist .sub2 { color: var(--text-2); font-size: 12.5px; }
.toplist .n { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.about { margin-top: 18px; font-size: 13px; color: var(--text-2); }
.about summary { cursor: pointer; font-weight: 600; color: var(--text); }
.about p { margin: 8px 0; }

.regions {
  position: absolute; top: 10px; left: 10px; right: 56px; z-index: 2;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0;
}
.regions::-webkit-scrollbar { display: none; }
.region {
  flex: none; padding: 6px 11px; border: 1px solid #dcdad3; border-radius: 999px;
  background: rgba(255, 255, 255, 0.95); color: #0b0b0b; font: inherit; font-size: 13px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
.region:hover { background: #fff; border-color: #8f8d85; }
.legend {
  position: absolute; left: 10px; bottom: 28px; max-width: 250px; padding: 10px 12px;
  background: rgba(255, 255, 255, 0.94); border: 1px solid #dcdad3; border-radius: 10px;
  font-size: 12.5px; color: #0b0b0b; z-index: 2;
}
.legend summary { cursor: pointer; font-weight: 600; }
.legend[open] summary { margin-bottom: 6px; }
.legend h3 { margin: 0 0 6px; font-size: 12.5px; }
.legend .row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.legend .sw { width: 18px; height: 12px; border-radius: 2px; flex: none; border: 1px solid rgba(0, 0, 0, 0.25); }
.legend .sw.line { height: 0; border: 0; border-top: 2px solid #3b3a37; border-radius: 0; }
.legend .sw.line.dash { border-top-style: dashed; }
.legend .sw.dia { width: 9px; height: 9px; transform: rotate(45deg); margin: 0 4px; border: 1px solid #fff; }
.legend .sw.sq { width: 11px; height: 11px; margin: 0 3px; border: 2px solid #fff; }
.legend .sw.house { width: 13px; height: 13px; margin: 0 2px; border: 0; border-radius: 0; clip-path: polygon(50% 0, 100% 42%, 100% 100%, 0 100%, 0 42%); }
.legend .sw.ring { width: 13px; height: 13px; border-radius: 50%; border: 2.5px solid #d03b3b; background: rgba(208,59,59,0.12); margin: 0 2px; }
.legend .sw.uncov { width: 16px; height: 11px; border: 2px dashed #4a148c; background: rgba(123,31,162,0.35); border-radius: 1px; }
.legend .sw.road { height: 0; border: 0; border-top: 3px solid #d03b3b; border-radius: 0; }
.legend .ramp { display: flex; margin-top: 4px; }
.legend .ramp div { flex: 1; height: 12px; }
.legend .ramp-labels { display: flex; justify-content: space-between; font-size: 11.5px; color: #52514e; margin-top: 2px; }
.legend hr { border: 0; border-top: 1px solid #dcdad3; margin: 8px 0; }

.maplibregl-popup-content { color: #0b0b0b; font: 13.5px/1.4 system-ui, sans-serif; padding: 12px 14px; min-width: 210px; }
.maplibregl-popup-content h4 { margin: 0 24px 6px 0; font-size: 14px; }
.maplibregl-popup-content p { margin: 3px 0; }
.maplibregl-popup-content .warn { color: #6b4a00; font-size: 12.5px; }

@media (max-width: 820px) {
  .app { display: flex; flex-direction: column; height: auto; }
  .mapwrap { order: -1; position: sticky; top: 0; height: 52vh; z-index: 3; border-bottom: 1px solid var(--border); }
  .panel { overflow: visible; border-right: 0; }
  .legend { bottom: 22px; max-width: 190px; padding: 6px 8px; font-size: 11.5px; }
  .legend .row { margin: 1px 0; }
}
