:root {
  color-scheme: light;
  --ink: #243127;
  --muted: #5f6e63;
  --paper: #ffffff;
  --canvas: #faf8f4;
  --accent: #4d7654;
  --accent-soft: #e6efe7;
  --line: #e6e0d5;
  --empty: #eef0ec;
  --shadow: 0 16px 42px rgba(38, 30, 13, 0.10);
  --radius: 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.3rem, 2.6vw, 1.9rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; margin-top: 1.25rem; }

.site-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem .5rem;
}
.site-header__logo { width: 56px; height: 56px; border-radius: 14px; object-fit: cover; }
.site-header__brand { margin: 0; color: var(--accent); font-weight: 700; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas: "controls controls" "map side";
  gap: 1rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
}
.controls { grid-area: controls; display: flex; flex-wrap: wrap; gap: 1rem 2rem; }
.map-card { grid-area: map; }
.side-card { grid-area: side; }

.map-card, .side-card {
  min-width: 0;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.control-group { display: flex; flex-direction: column; gap: .35rem; }
.control-group__label { color: var(--muted); font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: .25rem;
  padding: .3rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
}
.segmented button {
  padding: .45rem .95rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.segmented button:hover, .segmented button:focus-visible { color: var(--ink); background: var(--accent-soft); }
.segmented button[aria-pressed="true"] { color: #fff; background: var(--accent); }

.map-card__header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem 1rem; }
.map-card__total { margin: 0; color: var(--muted); font-weight: 700; }
.breadcrumb { display: flex; align-items: baseline; gap: .5rem; }
.breadcrumb__link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}
.breadcrumb__separator { color: var(--muted); font-size: 1.25rem; }

.map-wrapper { position: relative; margin-top: .75rem; }
.map { display: block; width: 100%; height: auto; max-height: 75vh; }
.map path { stroke: #ffffff; stroke-width: .6; stroke-linejoin: round; vector-effect: non-scaling-stroke; cursor: pointer; transition: opacity .12s; }
.map path.is-municipality { stroke: rgba(36, 49, 39, .55); stroke-width: .5; }
.map path:hover, .map path:focus-visible, .map path.is-active { stroke: var(--ink); stroke-width: 2; outline: none; }
.map .outline { fill: none; stroke: var(--ink); stroke-width: 1.4; pointer-events: none; vector-effect: non-scaling-stroke; }
.map text { pointer-events: none; font-family: inherit; font-weight: 700; text-anchor: middle; dominant-baseline: central; paint-order: stroke; stroke: #ffffff; stroke-linejoin: round; fill: var(--ink); }
.map text.name { font-weight: 600; fill: var(--muted); }
.map-status { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; margin: 0; color: var(--muted); pointer-events: none; }
.map-status[hidden] { display: none; }

.tooltip {
  position: absolute;
  z-index: 2;
  max-width: 280px;
  padding: .6rem .8rem;
  border-radius: 12px;
  background: rgba(36, 49, 39, .94);
  color: #fff;
  font-size: .9rem;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.tooltip strong { display: block; font-size: 1rem; }
.tooltip ul { margin: .35rem 0 0; padding-left: 1.1rem; }

.legend { display: flex; align-items: center; gap: .6rem; margin-top: .75rem; color: var(--muted); font-size: .9rem; }
.legend__bar { flex: 1; height: 12px; border-radius: 999px; background: linear-gradient(90deg, hsl(120, 55%, 45%), hsl(60, 75%, 50%), hsl(0, 70%, 50%)); }
.hint { margin: .5rem 0 0; color: var(--muted); font-size: .9rem; }

.ranking { margin: .75rem 0 0; padding: 0; list-style: none; counter-reset: rank; }
.ranking li { display: flex; justify-content: space-between; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--line); counter-increment: rank; }
.ranking li::before { content: counter(rank) "."; min-width: 1.8rem; color: var(--muted); }
.ranking li span:first-of-type { flex: 1; overflow-wrap: anywhere; }
.ranking li span:last-of-type { font-weight: 700; }
.ranking button { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-align: left; text-decoration: underline; cursor: pointer; }
.ranking__empty { color: var(--muted); }
.unassigned__info { color: var(--muted); font-size: .85rem; }

.site-footer { max-width: 1280px; margin: 0 auto; padding: .5rem 1.25rem 2rem; color: var(--muted); font-size: .85rem; }
.noscript { max-width: 1280px; margin: 0 auto 2rem; padding: 0 1.25rem; font-weight: 700; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "controls" "map" "side"; }
}

@media (prefers-reduced-motion: reduce) {
  .map path { transition: none; }
}
