:root {
  color-scheme: light;
  --ink: #1b1f24;
  --muted: #667085;
  --line: #d8dee8;
  --surface: #ffffff;
  --page: #f4f6f8;
  --blue: #246bfe;
  --blue-soft: #dbe7ff;
  --red: #d64545;
  --red-soft: #f8dddd;
  --green: #168a65;
  --gold: #a66a00;
  --shadow: 0 10px 24px rgba(27, 31, 36, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  text-align: right;
}

.topbar__link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: none;
}

.eyebrow,
.topbar__meta,
.panel__heading span,
.table-toolbar p,
.notes,
.stat span,
.search span {
  color: var(--muted);
  font-size: 0.85rem;
}

.eyebrow {
  margin: 0 0 4px;
  font-weight: 700;
  text-transform: uppercase;
}

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

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

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

.dashboard {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
}

.control-panel,
.map-panel,
.senate-map-panel,
.panel,
.redistricting-panel,
.chart-panel,
.state-map-panel,
.table-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 18px;
}

.control-panel__heading,
.panel__heading,
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

#ballot-label {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 700;
}

#reset-button,
.custom-scenario-button,
.custom-map-primary {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafb;
  color: var(--ink);
  cursor: pointer;
}

.ballot-slider {
  width: 100%;
  margin: 30px 0 8px;
  accent-color: var(--blue);
}

.slider-scale {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.slider-scale {
  color: var(--muted);
  font-size: 0.78rem;
}

.polling-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.polling-note a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.scenario-control {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.scenario-control span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.scenario-control select {
  min-height: 38px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.scenario-description {
  min-height: 54px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.custom-scenario-button {
  width: 100%;
  margin-top: 10px;
  font-weight: 800;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 22px;
}

.stat {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 1.75rem;
  line-height: 1;
}

.chart-panel,
.history-panel,
.state-map-panel {
  margin-top: 16px;
  padding: 18px;
}

.map-panel {
  display: flex;
  flex-direction: column;
  min-height: 306px;
  padding: 14px;
}

.seat-strip {
  display: grid;
  grid-template-columns: repeat(29, minmax(8px, 1fr));
  gap: 4px;
  flex: 1;
  align-content: start;
}

.seat {
  aspect-ratio: 1;
  min-width: 8px;
  border-radius: 3px;
  border: 1px solid rgba(27, 31, 36, 0.12);
}

.seat--d {
  background: var(--blue);
}

.seat--r {
  background: var(--red);
}

.seat--toss {
  background: var(--gold);
}

.seat--changed {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.8), 0 0 0 1px var(--gold);
}

.result-bar {
  display: flex;
  height: 18px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 4px;
  background: #eef1f5;
}

.result-bar__d {
  background: var(--blue);
}

.result-bar__r {
  background: var(--red);
}

.redistricting-panel p,
.history-panel p,
.chart-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.history-panel .panel__heading > span {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
}

.chart-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.86rem;
}

.chart-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-weight: 700;
}

.chart-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--green);
}

.seat-margin-chart {
  display: block;
  width: 100%;
  min-height: 240px;
  margin-top: 12px;
}

.forecast-history-chart {
  display: block;
  width: 100%;
  min-height: 210px;
  margin-top: 12px;
}

.chart-grid {
  stroke: #e4e9f0;
  stroke-width: 1;
}

.chart-zone {
  opacity: 0.55;
}

.chart-zone--d {
  fill: var(--blue-soft);
}

.chart-zone--r {
  fill: var(--red-soft);
}

.chart-axis {
  stroke: #8b96a6;
  stroke-width: 1.25;
}

.chart-axis--center {
  stroke-dasharray: 4 5;
}

.chart-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.chart-line--selected {
  stroke: var(--green);
}

.chart-line--baseline {
  stroke: #7d8793;
  stroke-dasharray: 8 7;
  stroke-width: 3;
}

.chart-current-line {
  stroke: var(--ink);
  stroke-dasharray: 5 5;
  stroke-width: 1.5;
}

.chart-dot {
  stroke: #fff;
  stroke-width: 3;
}

.chart-dot--d {
  fill: var(--blue);
}

.chart-dot--r {
  fill: var(--red);
}

.chart-label {
  fill: var(--muted);
  font-size: 13px;
}

.chart-legend {
  font-size: 12px;
  font-weight: 800;
}

.chart-legend--selected {
  fill: var(--green);
}

.chart-legend--baseline {
  fill: #7d8793;
}

.chart-hover-line {
  stroke: var(--ink);
  stroke-width: 1;
  stroke-dasharray: 3 4;
  pointer-events: none;
}

.chart-hover-dot {
  stroke: #fff;
  stroke-width: 3;
  pointer-events: none;
}

.chart-hover-dot--selected {
  fill: var(--green);
}

.chart-hover-dot--baseline {
  fill: #7d8793;
}

.chart-hitbox {
  fill: transparent;
  cursor: crosshair;
}

.history-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.history-line--d {
  stroke: var(--blue);
}

.history-line--r {
  stroke: var(--red);
}

.history-point {
  stroke: #fff;
  stroke-width: 2.5;
}

.history-point--d,
.history-hover-dot--d {
  fill: var(--blue);
}

.history-point--r,
.history-hover-dot--r {
  fill: var(--red);
}

.history-majority-line {
  stroke: #8b96a6;
  stroke-dasharray: 5 5;
  stroke-width: 1.25;
}

.history-legend {
  font-size: 12px;
  font-weight: 850;
}

.history-legend--d {
  fill: var(--blue);
}

.history-legend--r {
  fill: var(--red);
}

.history-majority-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chart-tooltip-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 3px 12px;
  margin-top: 7px;
}

.chart-tooltip-row span {
  color: var(--muted);
  font-weight: 700;
}

.chart-tooltip-row b {
  text-align: right;
}

.chart-tooltip-row small {
  grid-column: 1 / -1;
  color: var(--muted);
}

.chart-tooltip-row--active span,
.chart-tooltip-row--active b {
  color: var(--ink);
}

.panel {
  padding: 18px;
}

.redistricting-panel {
  margin-top: 16px;
  padding: 18px;
}

.state-change-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.custom-map-controls {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.custom-map-controls[hidden] {
  display: none;
}

.custom-map-controls__intro {
  display: grid;
  gap: 2px;
}

.custom-map-controls__intro span,
.custom-map-option em {
  color: var(--muted);
  font-size: 0.82rem;
  font-style: normal;
}

.custom-map-actions,
.custom-map-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.custom-map-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

.custom-map-actions button {
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.custom-map-primary {
  justify-self: start;
  padding: 6px 12px;
  font-weight: 800;
}

.custom-map-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  min-height: 132px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.custom-map-option input {
  margin-top: 3px;
  accent-color: var(--green);
}

.custom-map-option span {
  display: grid;
  gap: 4px;
}

.custom-map-option b {
  color: var(--ink);
  font-size: 0.84rem;
}

.custom-map-option small {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.state-card {
  min-height: 168px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.state-card__top,
.state-card__numbers {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.state-card__top {
  align-items: start;
}

.state-card__top .map-badge {
  max-width: 170px;
  white-space: normal;
  text-align: center;
}

.state-card__name {
  margin-top: 6px;
  font-weight: 800;
}

.state-card__numbers {
  margin-top: 10px;
  font-size: 0.9rem;
  font-weight: 800;
}

.state-card__range,
.quality-note,
.empty-state {
  color: var(--muted);
  font-size: 0.82rem;
}

td .quality-note {
  display: block;
  margin-top: 2px;
  line-height: 1.25;
}

.state-card__range {
  margin-top: 6px;
}

.state-card p {
  line-height: 1.42;
}

.state-card__map-button {
  min-height: 32px;
  margin-top: 8px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.state-map-control {
  display: grid;
  gap: 4px;
}

.state-map-control span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.state-map-control select {
  min-height: 36px;
  min-width: 220px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.state-map-note,
.state-map-source {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.state-map-note {
  margin: 10px 0 0;
}

.state-map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 14px;
  margin-top: 14px;
}

.state-map-canvas {
  display: grid;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.state-map-svg {
  width: 100%;
  height: 100%;
  min-height: 420px;
}

.state-map__district {
  stroke: #fff;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition:
    fill-opacity 120ms ease,
    stroke-width 120ms ease;
}

.state-map__district:focus,
.state-map__district:hover {
  outline: none;
  stroke: var(--ink);
  stroke-width: 2;
}

.state-map__district--d {
  fill: var(--blue);
  fill-opacity: var(--district-alpha, 0.55);
}

.state-map__district--r {
  fill: var(--red);
  fill-opacity: var(--district-alpha, 0.55);
}

.state-map__district--unknown {
  fill: #c7d0dd;
  fill-opacity: 0.55;
}

.state-map__district--old {
  fill: none;
  stroke: #536579;
  stroke-dasharray: 5 5;
  stroke-width: 1;
  pointer-events: none;
}

.state-map-empty {
  display: grid;
  place-content: center;
  gap: 6px;
  min-height: 320px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.state-map-empty strong {
  color: var(--ink);
}

.state-map-empty span {
  display: block;
}

.state-map-summary {
  display: grid;
  align-content: start;
  gap: 10px;
}

.state-map-summary__top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 800;
}

.state-map-summary p {
  margin-bottom: 0;
}

.state-map-district-list {
  display: grid;
  max-height: 332px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.state-map-district {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.state-map-district span {
  display: grid;
  gap: 2px;
}

.state-map-district em {
  color: var(--muted);
  font-size: 0.76rem;
  font-style: normal;
}

.senate-shell h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.senate-dashboard {
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
}

.senate-blend-heading {
  margin-top: 18px;
}

.senate-map-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: 16px;
  min-height: 430px;
  padding: 16px;
}

.senate-map {
  display: grid;
  grid-template-columns: repeat(12, minmax(38px, 1fr));
  grid-auto-rows: minmax(48px, 1fr);
  gap: 6px;
  align-content: center;
}

.senate-state {
  min-height: 48px;
  padding: 6px;
  border: 1px solid rgba(27, 31, 36, 0.12);
  border-radius: 6px;
  background: #eef1f5;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.senate-state strong,
.senate-state span {
  display: block;
}

.senate-state strong {
  font-size: 0.86rem;
}

.senate-state span {
  margin-top: 2px;
  font-size: 0.74rem;
  font-weight: 800;
}

.senate-state:disabled {
  cursor: default;
  opacity: 0.42;
}

.senate-state:not(:disabled):hover,
.senate-state--selected {
  transform: translateY(-1px);
  border-color: rgba(27, 31, 36, 0.34);
  box-shadow: 0 8px 20px rgba(27, 31, 36, 0.12);
}

.senate-state--d {
  background: var(--blue-soft);
  color: #123b8a;
}

.senate-state--r {
  background: var(--red-soft);
  color: #8f2424;
}

.senate-state--tossup {
  background: #fff3cf;
  color: #704700;
}

.senate-detail {
  align-self: stretch;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.senate-detail__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.senate-detail h2 {
  margin-top: 12px;
  font-size: 1.6rem;
}

.senate-detail p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.senate-detail__numbers {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.senate-detail__numbers span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-weight: 800;
}

.senate-signal-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.senate-signal-list li {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.senate-signal-list span,
.senate-signal-list b {
  font-size: 0.84rem;
}

.senate-signal-list em {
  color: var(--muted);
  font-size: 0.76rem;
  font-style: normal;
  line-height: 1.35;
}

.senate-table-panel {
  margin-top: 16px;
}

.map-badge--precinct {
  border-color: #b7d8ca;
  background: #e9f7f0;
  color: #0b6b4b;
}

.map-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f9fafb;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.map-badge--changed {
  border-color: #f1c978;
  background: #fff4d7;
  color: #7a4b00;
}

.map-badge--stable {
  border-color: #cfd8e4;
  background: #eef2f7;
}

.rating-badge,
.rating-empty {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafb;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.rating-badge--d {
  border-color: #b9ccff;
  background: var(--blue-soft);
  color: var(--blue);
}

.rating-badge--r {
  border-color: #efb3b3;
  background: var(--red-soft);
  color: var(--red);
}

.composition-cell {
  color: var(--muted);
  font-size: 0.84rem;
}

.quality-note {
  display: block;
  margin-top: 4px;
  white-space: normal;
}

.table-panel {
  margin-top: 16px;
  overflow: hidden;
}

.table-toolbar {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.table-toolbar p {
  margin: 4px 0 0;
}

.search {
  display: grid;
  gap: 4px;
}

.search input {
  width: min(320px, 44vw);
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.district-row--changed {
  background: #fffdf7;
}

th {
  position: sticky;
  top: 0;
  background: #f9fafb;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  z-index: 1;
}

.margin-d {
  color: var(--blue);
  font-weight: 800;
}

.margin-r {
  color: var(--red);
  font-weight: 800;
}

.notes {
  max-width: 980px;
  margin-top: 16px;
  line-height: 1.5;
}

.notes p {
  margin-bottom: 6px;
}

.seat-tooltip {
  position: fixed;
  z-index: 20;
  max-width: 360px;
  padding: 12px;
  border: 1px solid rgba(27, 31, 36, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 16px 40px rgba(27, 31, 36, 0.18);
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.45;
  pointer-events: none;
}

.seat-tooltip strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1rem;
}

@media (max-width: 860px) {
  .shell {
    padding: 16px;
  }

  .topbar,
  .control-panel__heading,
  .panel__heading,
  .table-toolbar {
    align-items: start;
    flex-direction: column;
  }

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

  .state-change-list,
  .custom-map-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

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

  .seat-strip {
    grid-template-columns: repeat(19, minmax(10px, 1fr));
  }

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

  .search,
  .search input {
    width: 100%;
  }

  .senate-map-panel {
    grid-template-columns: 1fr;
    overflow-x: auto;
  }

  .senate-map {
    min-width: 700px;
  }

  th,
  td {
    padding: 10px 12px;
  }
}

@media (max-width: 520px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .seat-strip {
    grid-template-columns: repeat(15, minmax(10px, 1fr));
  }

  .state-change-list,
  .custom-map-grid {
    grid-template-columns: 1fr;
  }

  .state-map-control,
  .state-map-control select {
    width: 100%;
  }

  .state-map-canvas,
  .state-map-svg {
    min-height: 300px;
  }

  .senate-map {
    min-width: 640px;
  }
}
