:root {
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --ink: #12151a;
  --ink-soft: #5b6472;
  --line: #d9dde3;
  --accent: #0a4d8c;
  --panel-width: 380px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --bg-soft: #1c2027;
    --ink: #f2f4f7;
    --ink-soft: #a5aeba;
    --line: #2c323b;
    --accent: #5aa9f7;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.topbar__kicker {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.topbar__headline {
  margin: 2px 0 0;
  font-size: 20px;
  line-height: 1.2;
}

.topbar__search {
  position: relative;
  flex: 1 1 320px;
  min-width: 240px;
}

#search-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink);
}

#search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.search-results {
  position: absolute;
  z-index: 1200;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 340px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgb(0 0 0 / 18%);
}

.search-results li button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}

.search-results li button:hover,
.search-results li button:focus-visible {
  background: var(--bg-soft);
}

.search-results .result__sub {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
}

.search-results .result__empty {
  padding: 10px;
  font-size: 14px;
  color: var(--ink-soft);
}

/* ---------- layout ---------- */

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.mapwrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--bg-soft);
}

.maploading {
  position: absolute;
  z-index: 900;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgb(0 0 0 / 65%);
  color: #fff;
  font-size: 14px;
}

.maploading[hidden] {
  display: none;
}

.overlay {
  position: absolute;
  z-index: 800;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.overlay--top-left {
  top: 12px;
  left: 12px;
  flex-direction: column;
}

.overlay--top-right {
  top: 12px;
  right: 12px;
}

.overlay--bottom {
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
}

.opacity-control {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: 0 4px 14px rgb(0 0 0 / 12%);
}

.opacity-control label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
}

.opacity-control output {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  min-width: 34px;
}

.opacity-control input[type='range'] {
  width: 84px;
  margin: 0;
  accent-color: var(--accent);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: 0 4px 14px rgb(0 0 0 / 12%);
}

.segmented button {
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}

.segmented button[aria-pressed='true'] {
  background: var(--accent);
  color: #fff;
}

.legend[hidden] {
  display: none;
}

.legend {
  min-width: 150px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: 0 4px 14px rgb(0 0 0 / 12%);
  font-size: 13px;
}

.legend__title {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--ink-soft);
}

.legend__ramp {
  height: 12px;
  border-radius: 4px;
  margin: 4px 0;
}

.legend__scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-soft);
}

/* ---------- panel ---------- */

.panel {
  width: var(--panel-width);
  flex: none;
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 18px 20px 28px;
  background: var(--bg);
}

.panel__empty h2,
.panel__content h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.panel__empty p {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
}

.panel__breadcrumb {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--ink-soft);
}

.panel__breadcrumb button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.panel__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 10px 0 16px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.panel__stats div span {
  display: block;
  color: var(--ink-soft);
  font-size: 12px;
}

.panel__stats strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.results {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
}

.result {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.result__name {
  font-weight: 700;
}

.result__cand {
  display: block;
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 12px;
}

.result__bar {
  height: 14px;
  border-radius: 3px;
  min-width: 2px;
}

.result__num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.result__diff {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
}

.result__diff--up {
  color: #1a7f37;
}

.result__diff--down {
  color: #c0392b;
}

.panel__section-title {
  margin: 20px 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.chips button,
.chips span {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
}

.chips span {
  cursor: default;
  font-variant-numeric: tabular-nums;
}

.button {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.panel__note {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ---------- sources ---------- */

.sources {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 12px;
  color: var(--ink-soft);
}

.sources summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}

.sources__list {
  margin: 8px 0 0;
  padding-left: 18px;
  line-height: 1.6;
}

.sources__list a {
  word-break: break-word;
}

/* ---------- map bits ---------- */

.leaflet-container {
  background: var(--bg-soft);
  font: inherit;
}

.region-tip {
  font-size: 13px;
}

.region-tip strong {
  display: block;
  font-size: 14px;
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .mapwrap {
    height: 58vh;
    flex: none;
  }

  .panel {
    width: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 42vh;
  }

  .overlay--top-right {
    top: auto;
    bottom: 66px;
    right: 12px;
  }
}
