:root {
  --bg: #f5efe5;
  --paper: rgba(255, 250, 242, 0.9);
  --ink: #1e2426;
  --muted: #5b605d;
  --line: rgba(43, 55, 53, 0.12);
  --accent: #ca5a34;
  --shadow: 0 28px 80px rgba(27, 31, 35, 0.12);
  --radius: 28px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% 0%, rgba(216, 122, 78, 0.16), transparent 28%),
    radial-gradient(circle at 100% 20%, rgba(48, 143, 125, 0.14), transparent 26%),
    linear-gradient(180deg, #f8f3ea 0%, #efe6d8 100%);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
}

body {
  padding: 28px;
}

a {
  color: inherit;
}

.page-shell {
  max-width: 1540px;
  margin: 0 auto;
}

.hero {
  position: relative;
  overflow: hidden;
  padding: 44px;
  border-radius: 40px;
  background:
    linear-gradient(135deg, rgba(28, 65, 75, 0.96), rgba(14, 34, 38, 0.94)),
    linear-gradient(180deg, #0e2226, #18353a);
  box-shadow: var(--shadow);
}

.hero__top {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 26px;
}

.hero__content {
  position: relative;
  z-index: 2;
  max-width: 880px;
}

.hero h1 {
  margin: 0;
  max-width: 14ch;
  color: #fff7ef;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: clamp(2.8rem, 5vw, 5.3rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.hero__lede {
  max-width: 62ch;
  color: rgba(255, 247, 239, 0.84);
  font-size: 1.06rem;
  line-height: 1.65;
}

.hero__lede--compact {
  margin-top: 12px;
  font-size: 0.98rem;
}

.hero__lede a {
  color: #fff7ef;
  font-weight: 700;
}

.hero__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-top: 28px;
}

.page-switch {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 10px;
}

.page-switch__link {
  display: inline-flex;
  align-items: center;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 247, 239, 0.16);
  background: rgba(255, 247, 239, 0.08);
  color: rgba(255, 247, 239, 0.84);
  text-decoration: none;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.page-switch__link:hover {
  transform: translateY(-1px);
  background: rgba(255, 247, 239, 0.14);
}

.page-switch__link.is-active {
  border-color: rgba(255, 247, 239, 0.28);
  background: rgba(255, 247, 239, 0.18);
  color: #fff7ef;
}

.stat-card,
.panel,
.source-card {
  backdrop-filter: blur(10px);
}

.stat-card {
  display: grid;
  gap: 8px;
  padding: 18px 20px;
  border: 1px solid rgba(255, 247, 239, 0.14);
  border-radius: 22px;
  background: rgba(255, 247, 239, 0.08);
  color: #fff7ef;
}

.stat-card span {
  opacity: 0.7;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-card strong {
  font-size: 1.6rem;
  font-weight: 700;
}

.hero__ornament {
  position: absolute;
  border-radius: 50%;
  filter: blur(10px);
  opacity: 0.65;
}

.hero__ornament--left {
  left: -60px;
  bottom: -40px;
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(209, 102, 66, 0.7), rgba(209, 102, 66, 0.02));
}

.hero__ornament--right {
  top: -40px;
  right: -60px;
  width: 280px;
  height: 280px;
  background: radial-gradient(circle, rgba(40, 126, 116, 0.62), rgba(40, 126, 116, 0.03));
}

.layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 22px;
  margin-top: 22px;
}

.panel {
  padding: 24px;
  border: 1px solid rgba(34, 49, 47, 0.08);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 16px 50px rgba(31, 36, 38, 0.07);
}

.panel--chart,
.panel--map,
.panel--cluster,
.panel--table,
.panel--sources {
  grid-column: 2;
}

.panel__header {
  margin-bottom: 18px;
}

.panel__header--spread {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}

.chart-toolbar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: flex-end;
}

.simulation-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
}

.play-button {
  padding: 10px 16px;
  border: 1px solid rgba(27, 104, 93, 0.24);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(29, 119, 107, 0.14), rgba(202, 90, 52, 0.1));
  color: #154d46;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.simulation-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.panel h2,
.source-card h3,
.filter-group h3 {
  margin: 0;
}

.panel h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 2rem;
  letter-spacing: -0.03em;
}

.pill-grid,
.checkbox-grid,
.source-list {
  display: grid;
  gap: 12px;
}

.pill-grid {
  grid-template-columns: 1fr;
}

.party-pill {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.party-pill:hover,
.checkbox-card:hover {
  transform: translateY(-1px);
}

.party-pill span {
  font-size: 1.2rem;
  font-weight: 800;
}

.party-pill small {
  color: var(--muted);
}

.party-pill.is-active {
  border-color: color-mix(in srgb, var(--party-color) 40%, transparent);
  background: color-mix(in srgb, var(--party-color) 15%, white);
}

.filter-group {
  margin-top: 24px;
}

.filter-group__head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
}

.text-button {
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}

.checkbox-card {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
  cursor: pointer;
}

.checkbox-card input {
  accent-color: #1d776b;
  margin-top: 3px;
}

.checkbox-card__body {
  display: grid;
  gap: 4px;
}

.checkbox-card__body small,
.source-card__coverage {
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.segmented-control {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.segmented-control--stack {
  display: grid;
  justify-content: stretch;
}

.segment-button {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.segment-button.is-active {
  border-color: rgba(27, 104, 93, 0.32);
  background: rgba(29, 119, 107, 0.12);
  color: #17584f;
}

.field-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.62);
}

.field-label {
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.search-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(32, 48, 46, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font: inherit;
}

.search-input:focus {
  outline: 2px solid rgba(29, 119, 107, 0.18);
  border-color: rgba(29, 119, 107, 0.32);
}

.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
}

.legend__item i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.chart-frame {
  position: relative;
}

.chart-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: stretch;
}

.map-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: stretch;
}

.seat-card {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 0%, rgba(27, 119, 107, 0.08), transparent 42%),
    rgba(255, 255, 255, 0.72);
}

.seat-card h3 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

.seat-context,
.seat-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.seat-note span {
  font-weight: 700;
}

#seat-chart {
  width: 100%;
  height: auto;
  display: block;
}

.seat-ring-base {
  fill: rgba(124, 111, 103, 0.08);
}

.seat-slice {
  stroke: rgba(255, 250, 242, 0.96);
  stroke-width: 2.5;
}

.seat-label {
  fill: #1d2426;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
}

.seat-center-title {
  fill: #6a5d54;
  font-size: 13px;
  text-anchor: middle;
}

.seat-center-value {
  fill: #182224;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 34px;
  font-weight: 700;
  text-anchor: middle;
}

.seat-summary {
  display: grid;
  gap: 10px;
}

.seat-summary__totals,
.seat-summary__list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seat-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  font-size: 0.92rem;
}

.seat-pill--zero {
  background: rgba(120, 126, 130, 0.12);
  color: #7a8084;
}

.seat-pill i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.mandate-strip-card {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
}

.mandate-strip-card h3 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

#seat-strip-chart {
  width: 100%;
  height: auto;
  display: block;
}

.seat-strip-base {
  fill: rgba(124, 111, 103, 0.1);
}

.seat-strip-segment {
  stroke: rgba(255, 250, 242, 0.96);
  stroke-width: 2;
}

.seat-strip-center {
  stroke: rgba(110, 88, 72, 0.85);
  stroke-width: 3;
  stroke-dasharray: 6 6;
}

.seat-strip-label {
  fill: #42352f;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
}

.seat-strip-title {
  fill: #6a5d54;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  letter-spacing: 0.08em;
}

#chart {
  width: 100%;
  height: 540px;
  display: block;
}

.chart-bg {
  fill: rgba(255, 252, 246, 0.72);
}

.chart-grid {
  stroke: rgba(48, 57, 58, 0.08);
  stroke-width: 1;
}

.chart-grid--vertical {
  stroke-dasharray: 4 8;
}

.chart-axis,
.chart-axis-line {
  fill: #5c4d45;
  stroke: rgba(53, 62, 63, 0.15);
}

.chart-axis {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 13px;
}

.chart-axis--party {
  font-size: 12px;
}

.chart-axis-line {
  stroke-width: 1.2;
}

.chart-dot {
  filter: drop-shadow(0 4px 10px rgba(14, 24, 24, 0.18));
}

.simulation-line {
  stroke: rgba(202, 90, 52, 0.92);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 5 8;
}

.simulation-handle {
  fill: #ca5a34;
  stroke: rgba(255, 252, 246, 0.96);
  stroke-width: 2.5;
  filter: drop-shadow(0 6px 12px rgba(45, 31, 23, 0.18));
}

.simulation-label {
  fill: #8f4128;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
}

.tooltip {
  position: absolute;
  z-index: 10;
  max-width: 240px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(22, 28, 30, 0.94);
  color: #fff7ef;
  font-size: 0.92rem;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 12px 32px rgba(14, 18, 22, 0.22);
}

.source-list {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.source-card {
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.68);
}

.source-card__head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.status-pill {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-pill--ingested {
  background: rgba(36, 124, 98, 0.12);
  color: #166452;
}

.status-pill--discovered {
  background: rgba(202, 90, 52, 0.12);
  color: #a14424;
}

.status-pill--official {
  background: rgba(27, 119, 107, 0.12);
  color: #17584f;
}

.table-wrap {
  overflow: auto;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(39, 54, 54, 0.08);
  text-align: left;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  background: #f8f3eb;
  z-index: 1;
}

tbody tr:hover {
  background: rgba(202, 90, 52, 0.05);
}

.panel-note {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.similarity-list {
  display: grid;
  gap: 12px;
}

.similarity-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.76);
}

.similarity-card__title {
  display: grid;
  gap: 4px;
}

.similarity-card__title span {
  color: var(--muted);
  font-size: 0.92rem;
}

.similarity-card__metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.party-cell {
  display: grid;
  gap: 3px;
}

.party-cell small {
  color: var(--muted);
}

.cluster-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.76);
}

.cluster-card.is-active {
  border-color: rgba(29, 119, 107, 0.26);
  background: linear-gradient(180deg, rgba(29, 119, 107, 0.08), rgba(255, 255, 255, 0.82));
}

.cluster-card__title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.cluster-card__title strong {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.cluster-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.cluster-card__metrics,
.cluster-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cluster-card__members {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

#cluster-chart {
  width: 100%;
  height: 540px;
  display: block;
}

.map-frame {
  position: relative;
  min-height: 760px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 0%, rgba(29, 119, 107, 0.08), transparent 40%),
    linear-gradient(180deg, rgba(255, 252, 246, 0.92), rgba(248, 241, 231, 0.86));
}

#municipality-map {
  width: 100%;
  height: min(82vh, 980px);
  display: block;
}

.map-bg {
  fill: rgba(255, 252, 246, 0.72);
}

.map-municipality__district {
  fill: var(--municipality-fill, rgba(95, 108, 108, 0.16));
  stroke: var(--municipality-stroke, rgba(104, 116, 117, 0.2));
  stroke-width: var(--municipality-stroke-width, 0.55);
  vector-effect: non-scaling-stroke;
  transition: fill 180ms ease, stroke 180ms ease, opacity 180ms ease;
}

.map-municipality--selected .map-municipality__district {
  filter: drop-shadow(0 4px 10px rgba(44, 31, 24, 0.18));
}

.map-municipality__hit {
  fill: transparent;
  stroke: none;
  pointer-events: visibleFill;
  cursor: pointer;
}

.map-focus-ring {
  fill: rgba(255, 250, 242, 0.94);
  stroke: rgba(24, 34, 36, 0.72);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.map-focus-dot {
  fill: #ca5a34;
  stroke: rgba(255, 250, 242, 0.96);
  stroke-width: 1.1;
  vector-effect: non-scaling-stroke;
}

.map-focus-dot--similar {
  fill: #1d776b;
}

.map-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.76);
}

.map-card.is-active {
  border-color: rgba(202, 90, 52, 0.28);
  background: linear-gradient(180deg, rgba(202, 90, 52, 0.08), rgba(255, 255, 255, 0.84));
}

.map-card__title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.map-card__title strong {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.map-card__meta {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.cluster-axis {
  stroke: rgba(99, 84, 71, 0.28);
  stroke-width: 1.2;
  stroke-dasharray: 5 7;
}

.cluster-point {
  stroke: rgba(255, 252, 246, 0.94);
  stroke-width: 1.8;
  filter: drop-shadow(0 4px 10px rgba(14, 24, 24, 0.16));
}

.cluster-point--selected {
  stroke: #182224;
  stroke-width: 3;
}

.cluster-label {
  fill: #5c4d45;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
}

.error-state {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

@media (max-width: 1080px) {
  body {
    padding: 18px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .panel--chart,
  .panel--map,
  .panel--table,
  .panel--sources {
    grid-column: auto;
  }

  .panel__header--spread {
    flex-direction: column;
  }

  .hero__top {
    justify-content: flex-start;
  }

  .chart-toolbar {
    align-items: flex-start;
  }

  .simulation-toolbar {
    justify-content: flex-start;
  }

  .legend,
  .segmented-control {
    justify-content: flex-start;
  }

  .chart-stage {
    grid-template-columns: 1fr;
  }

  .map-stage {
    grid-template-columns: 1fr;
  }

  #chart {
    height: 420px;
  }

  #cluster-chart {
    height: 420px;
  }

  .map-frame {
    min-height: 620px;
  }

  #municipality-map {
    height: min(72vh, 820px);
  }
}
