:root {
  --bg: #10151f;
  --panel: #171e2b;
  --panel-2: #1f2937;
  --line: #334155;
  --text: #f8fafc;
  --muted: #aab4c3;
  --red: #d94c4c;
  --red-dark: #8f2428;
  --blue: #3f7ee8;
  --blue-dark: #254f9a;
  --gold: #e0b44b;
  --green: #28a17d;
  --white: #ffffff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: 1rem;
  z-index: 20;
  transform: translateY(-150%);
  border-radius: 6px;
  background: var(--white);
  color: var(--bg);
  padding: 0.65rem 0.9rem;
  font-weight: 800;
}

.skip-link:focus {
  transform: translateY(0);
}

.map-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 70px;
  padding: 0.9rem clamp(1rem, 2.4vw, 2rem);
  background: rgba(16, 21, 31, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 900;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: var(--white);
  color: var(--bg);
  font-weight: 900;
}

.race-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(94px, 1fr));
  gap: 0.35rem;
  padding: 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.tab,
.reset-button,
.back-button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.tab.active {
  background: var(--white);
  color: var(--bg);
}

.politics-app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 29vw);
  min-height: calc(100vh - 70px);
}

.map-stage {
  display: grid;
  grid-template-rows: auto minmax(500px, 1fr);
  gap: 1rem;
  padding: clamp(1rem, 2.4vw, 2rem);
}

.stage-topline {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.kicker {
  margin: 0 0 0.35rem;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4.8rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0.45rem;
  font-size: clamp(1.7rem, 2.5vw, 3rem);
  line-height: 1;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.control-stack {
  display: flex;
  align-items: end;
  gap: 0.7rem;
}

.search-box {
  display: grid;
  gap: 0.35rem;
  min-width: min(320px, 50vw);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.swing-control,
.year-control {
  display: grid;
  gap: 0.35rem;
  min-width: min(260px, 42vw);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.swing-control span,
.year-control span {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.swing-control strong,
.year-control strong {
  color: var(--text);
}

.swing-control input,
.year-control input {
  accent-color: var(--gold);
  min-height: 44px;
}

.swing-control.is-locked {
  opacity: 0.72;
}

.swing-control input:disabled {
  cursor: not-allowed;
}

.search-box input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d121b;
  color: var(--text);
  padding: 0 0.8rem;
  text-transform: none;
}

.reset-button,
.back-button {
  border: 1px solid var(--line);
  padding: 0 1rem;
  color: var(--text);
  background: var(--panel);
}

.back-button {
  display: none;
  min-height: 40px;
  border-radius: 6px;
  font-weight: 800;
  cursor: pointer;
}

.back-button.visible {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.map-shell {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 1rem;
  min-height: 0;
}

.map-wrap {
  position: relative;
  overflow: hidden;
  min-height: 500px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent),
    #0b111b;
  box-shadow: var(--shadow);
}

#us-map {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 500px;
}

.state {
  stroke: rgba(255, 255, 255, 0.52);
  stroke-width: 0.75;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: opacity 150ms ease, stroke-width 150ms ease;
}

.state:hover,
.state.selected {
  stroke: var(--white);
  stroke-width: 2;
}

.state.dimmed {
  opacity: 0.2;
}

.nation-outline {
  fill: none;
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1;
  pointer-events: none;
}

.district-shape {
  stroke: rgba(255, 255, 255, 0.72);
  stroke-width: 1.1;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: filter 150ms ease, stroke-width 150ms ease;
}

.district-shape:hover,
.district-shape.selected {
  filter: brightness(1.18);
  stroke: #ffffff;
  stroke-width: 2.4;
}

.district-label {
  fill: #ffffff;
  paint-order: stroke;
  stroke: rgba(13, 18, 27, 0.9);
  stroke-width: 4px;
  text-anchor: middle;
  dominant-baseline: central;
  font-size: 11px;
  font-weight: 900;
  pointer-events: none;
}

.map-loading,
.map-badge,
.map-back-button,
.map-legend,
.source-note,
.tooltip {
  position: absolute;
}

.map-loading {
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

.map-loading.hidden {
  display: none;
}

.map-badge {
  left: 1rem;
  top: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(13, 18, 27, 0.82);
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 900;
  pointer-events: none;
}

.map-back-button {
  display: none;
  top: 1rem;
  right: 1rem;
  z-index: 3;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  padding: 0 0.85rem;
  background: rgba(13, 18, 27, 0.88);
  color: var(--text);
  font-weight: 800;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.map-back-button.visible {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.map-legend {
  left: 1rem;
  bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: calc(100% - 2rem);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(13, 18, 27, 0.84);
  padding: 0.55rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  pointer-events: none;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.map-legend i {
  display: block;
  width: 18px;
  height: 10px;
  border-radius: 99px;
}

.legend-blue {
  background: var(--blue);
}

.legend-gold {
  background: var(--gold);
}

.legend-red {
  background: var(--red);
}

.source-note {
  right: 1rem;
  top: 1rem;
  max-width: 230px;
  color: rgba(248, 250, 252, 0.72);
  font-size: 0.68rem;
  font-weight: 800;
  text-align: right;
  text-transform: uppercase;
  pointer-events: none;
}

.tooltip {
  display: none;
  max-width: 260px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(13, 18, 27, 0.94);
  box-shadow: var(--shadow);
  padding: 0.7rem;
  color: var(--text);
  font-size: 0.9rem;
  pointer-events: none;
}

.tooltip strong {
  display: block;
  margin-bottom: 0.25rem;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.score-card,
.panel-section {
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background: var(--panel);
}

.score-card {
  padding: 0.9rem;
}

.score-card span,
.metric-grid span,
.panel-heading span,
.vote-list span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.score-card strong {
  display: block;
  margin-top: 0.2rem;
  font-size: 2rem;
  line-height: 1;
}

.score-card.republican strong {
  color: #ff7474;
}

.score-card.democratic strong {
  color: #79a8ff;
}

.score-card.tossup strong {
  color: var(--gold);
}

.detail-panel {
  display: grid;
  align-content: start;
  gap: 1rem;
  max-height: calc(100vh - 70px);
  overflow: auto;
  padding: clamp(1rem, 2vw, 1.25rem);
  background: #0d121b;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.panel-section {
  padding: 1rem;
}

.selected-summary p {
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.metric-grid div {
  min-height: 82px;
  padding: 0.8rem;
  border-radius: 8px;
  background: var(--panel-2);
}

.metric-grid strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 1.25rem;
  line-height: 1.1;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.district-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 0.45rem;
  max-height: 260px;
  overflow: auto;
  padding-right: 0.1rem;
}

.district-tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  margin-bottom: 0.7rem;
}

.filter-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111827;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
}

.filter-button.active {
  background: var(--white);
  color: var(--bg);
}

.district-button {
  display: grid;
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111827;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
  padding: 0.6rem;
  text-align: left;
}

.district-button.active {
  border-color: var(--white);
  background: var(--white);
  color: var(--bg);
}

.district-button strong {
  font-size: 1.15rem;
  line-height: 1;
}

.district-button span {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.district-button small {
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 800;
}

.district-button.active span,
.district-button.active small {
  color: #303642;
}

.district-button.dem {
  box-shadow: inset 0 -4px 0 var(--blue);
}

.district-button.rep {
  box-shadow: inset 0 -4px 0 var(--red);
}

.district-button.even {
  box-shadow: inset 0 -4px 0 var(--gold);
}

.empty-state {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.history-chart {
  position: relative;
  display: grid;
  grid-template-columns: repeat(20, minmax(10px, 1fr));
  align-items: center;
  gap: 0.25rem;
  min-height: 120px;
  padding: 0.5rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.history-chart::before {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  content: "";
  background: rgba(255, 255, 255, 0.28);
}

.bar-column {
  position: relative;
  display: grid;
  height: 104px;
  align-items: center;
}

.history-bar {
  width: 100%;
  min-height: 4px;
  border-radius: 4px;
}

.bar-column.selected::after {
  position: absolute;
  left: 50%;
  bottom: -13px;
  width: 7px;
  height: 7px;
  content: "";
  transform: translateX(-50%) rotate(45deg);
  background: var(--white);
}

.history-bar.dem {
  align-self: end;
  background: var(--blue);
}

.history-bar.rep {
  align-self: start;
  background: var(--red);
}

.history-table-wrap {
  max-height: 220px;
  overflow: auto;
  margin-top: 0.8rem;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.history-table th,
.history-table td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.5rem 0.25rem;
  text-align: left;
}

.history-table th {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

.chamber-section {
  display: grid;
  gap: 1rem;
}

.vote-list {
  display: grid;
  gap: 0.5rem;
}

.vote-item,
.close-race-item {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 0.65rem;
  align-items: center;
  min-height: 44px;
  padding: 0.55rem;
  border-radius: 8px;
  background: var(--panel-2);
}

.close-race-list {
  display: grid;
  gap: 0.5rem;
}

.close-race-item {
  grid-template-columns: minmax(86px, 1fr) auto;
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.close-race-item strong {
  display: block;
}

.close-race-item span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.party-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 28px;
  border-radius: 999px;
  color: var(--white);
  font-weight: 900;
}

.party-pill.dem {
  background: var(--blue-dark);
}

.party-pill.rep {
  background: var(--red-dark);
}

.party-pill.even {
  background: #846914;
}

button:focus,
input:focus,
a:focus {
  outline: 3px solid rgba(224, 180, 75, 0.45);
  outline-offset: 3px;
}

@media (max-width: 1100px) {
  .politics-app {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    max-height: none;
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
}

@media (max-width: 760px) {
  .map-header,
  .stage-topline,
  .control-stack {
    align-items: stretch;
    flex-direction: column;
  }

  .race-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-box {
    min-width: 0;
  }

  .swing-control,
  .year-control {
    min-width: 0;
  }

  .map-stage {
    grid-template-rows: auto auto;
  }

  .map-wrap,
  #us-map {
    min-height: 360px;
  }

  .scoreboard,
  .metric-grid {
    grid-template-columns: 1fr;
  }
}
