:root {
  --bg: #eef3fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #4b5563;
  --line: #d7deeb;
  --accent: #b3001b;
  --accent-dark: #7f0012;
  --blue: #1f5cbf;
  --party-a: #ef4444;
  --party-b: #3b82f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 10% -10%, #dce8ff 0%, transparent 60%),
    radial-gradient(1000px 500px at 90% -20%, #f8dfe4 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", Roboto, sans-serif;
  padding-bottom: 72px;
}

.topbar {
  background: linear-gradient(120deg, #0c1e3f 0%, #142a54 70%, #1c3566 100%);
  color: #fff;
  padding: 14px 18px 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  border-bottom: 3px solid var(--accent);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2vw, 1.5rem);
  font-weight: 700;
  text-align: center;
}

.live-pill {
  background: var(--accent);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
}

main {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 14px;
}

.controls,
.status,
.grid-wrap,
.feed-wrap,
.districts-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 26px rgba(0, 20, 65, 0.08);
}

.controls,
.status {
  padding: 12px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: hidden;
  white-space: nowrap;
}

.controls > * {
  flex: 0 1 auto;
}

.controls .action-buttons {
  margin-left: auto;
  align-items: center;
}

button,
select,
input {
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid #b8c5de;
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 11px;
}

button {
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
}

#start-btn {
  background: #16a34a;
  border-color: #0f8a3e;
  color: #fff;
}

#reset-btn {
  background: #f6f8fd;
}

label,
.status {
  font-size: 0.9rem;
}

.party-row {
  display: grid;
  grid-template-columns: 34px 48px auto;
  gap: 6px;
  align-items: center;
}

.mascot-pick {
  width: 48px;
  padding: 7px 4px;
  text-align: center;
}

.party-row input[type="text"] {
  width: 120px;
  min-width: 96px;
  padding: 7px 9px;
}

.control-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-field input[type="number"] {
  width: 82px;
  padding: 7px 8px;
}

.control-field select {
  width: 88px;
  padding: 7px 8px;
}

.preset-field select {
  width: 320px;
}

.action-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.action-buttons button {
  height: 38px;
  min-height: 38px;
}

.status {
  display: grid;
  gap: 10px;
}

.status-meta {
  display: flex;
  justify-content: center;
  font-size: 0.85rem;
  color: #334155;
  padding-bottom: 2px;
}

.status-year {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
  width: 100%;
  border-radius: 8px;
  padding: 8px 10px;
  color: #ffffff;
  background: #64748b;
}

.content-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1.2fr 1fr;
  align-items: stretch;
  min-height: 0;
}

.grid-wrap,
.feed-wrap,
.districts-wrap {
  padding: 12px;
}

.grid-wrap {
  display: flex;
  flex-direction: column;
}

.rhs-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

.feed-wrap {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: #1c3360;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
}

canvas {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  background: #f8fbff;
  border: 1px solid #d6dfef;
  border-radius: 8px;
}

#log {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: none;
  height: auto;
  flex: 1;
  min-height: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  scrollbar-width: auto;
  scrollbar-color: #90a4c7 #e7edf8;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

#log::-webkit-scrollbar {
  width: 11px;
}

#log::-webkit-scrollbar-track {
  background: #e7edf8;
  border-left: 1px solid #d1daea;
}

#log::-webkit-scrollbar-thumb {
  background: #90a4c7;
  border: 2px solid #e7edf8;
  border-radius: 8px;
}

#log li {
  list-style: none;
}

.district-bars {
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.district-card {
  border: 1px solid #d7deeb;
  border-radius: 8px;
  padding: 6px;
  background: #fbfdff;
  display: grid;
  gap: 5px;
}

.district-shape {
  width: 100%;
  height: 44px;
  border: 1px solid #dbe4f2;
  border-radius: 6px;
  background: #f3f6ff;
  overflow: hidden;
}

.district-shape svg {
  width: 100%;
  height: 100%;
  display: block;
  shape-rendering: crispEdges;
}

.district-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.district-score {
  font-size: 0.64rem;
  color: #334155;
  font-weight: 700;
}

.party {
  font-weight: 700;
}

.party-a {
  color: var(--party-a);
}

.party-b {
  color: var(--party-b);
}

.party-bg-a {
  background: var(--party-a);
}

.party-bg-b {
  background: var(--party-b);
}

.play-btn {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.color-chip {
  width: 38px;
  height: 30px;
  padding: 2px;
  border-radius: 6px;
  border: 1px solid #9fb0cc;
  background: #fff;
  cursor: pointer;
}

.color-chip::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-chip::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.color-chip::-moz-color-swatch {
  border: none;
  border-radius: 4px;
}

.result-card {
  border: 1px solid #d7deeb;
  border-radius: 8px;
  padding: 6px 8px;
  background: #fbfdff;
}

.election-row {
  display: flex;
  gap: 7px;
  align-items: center;
}

#recent-election-row .result-card,
#projected-election-row .result-card {
  background: #f8fbff;
}

.row-label {
  width: 108px;
  font-size: 0.68rem;
  font-weight: 800;
  color: #1f325a;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.row-year {
  width: 54px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #1f325a;
}

.mini-metric {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 3px;
}

.winner-badge {
  width: 21px;
  height: 21px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.22);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.winner-emoji {
  font-size: 0.8rem;
  line-height: 1;
}

.emoji-tint {
  display: inline-block;
  filter: none;
}

.metric-tag {
  width: 13px;
  font-size: 0.64rem;
  font-weight: 800;
  color: #475569;
  text-align: center;
}

.metric-score {
  width: 48px;
  font-size: 0.7rem;
  color: #334155;
  text-align: right;
  font-weight: 700;
}

.bar-track {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: #e7edf8;
}

.bar-fill {
  height: 100%;
}

.ticker {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 64px;
  background: #0b162d;
  border-top: 4px solid var(--accent);
  display: grid;
  grid-template-columns: auto 1fr;
  z-index: 10;
}

.ticker-label {
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-weight: 800;
  font-size: 0.84rem;
  letter-spacing: 0.05em;
}

.ticker-viewport {
  overflow: hidden;
  display: flex;
  align-items: center;
}

.ticker-track {
  white-space: nowrap;
  color: #f6f8ff;
  font-size: 0.94rem;
  font-weight: 600;
  padding-left: 100%;
  animation: ticker-scroll 48s linear infinite;
}

@keyframes ticker-scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-100%); }
}

@media (max-width: 980px) {
  .controls {
    flex-wrap: wrap;
    overflow-x: visible;
    white-space: normal;
  }

  .action-buttons {
    margin-left: 0;
  }

  .play-btn {
    min-width: 42px;
  }

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

  #log {
    max-height: 260px;
  }

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

@media (max-width: 640px) {
  .row-label {
    width: 92px;
    font-size: 0.62rem;
  }

  .row-year {
    width: 46px;
    font-size: 0.72rem;
  }

  .metric-score {
    width: 42px;
    font-size: 0.64rem;
  }

  .ticker {
    height: 58px;
  }

  body {
    padding-bottom: 66px;
  }

  .ticker-label {
    padding: 0 10px;
    font-size: 0.75rem;
  }

  .ticker-track {
    font-size: 0.84rem;
  }

  .district-bars {
    grid-template-columns: 1fr;
  }
}
