:root {
  --bg: #0f1419;
  --surface: #1a222d;
  --surface2: #232d3b;
  --border: #2d3a4d;
  --text: #e8eef4;
  --muted: #8fa3b8;
  --accent: #1b7f5a;
  --accent2: #c9a227;
  --danger: #c94c4c;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.25rem;
  margin-bottom: 1.5rem;
}

header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.35rem, 4.5vw, 1.65rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.9rem, 3.2vw, 1.05rem);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.election-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: clamp(1rem, 4vw, 1.35rem);
  margin-bottom: 1.25rem;
}

.election-card h2 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.05rem, 3.5vw, 1.2rem);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.election-card .sub {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--muted);
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.winner-banner {
  background: rgba(27, 127, 90, 0.15);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  font-size: clamp(0.95rem, 3vw, 1.05rem);
  overflow-wrap: anywhere;
}

.winner-banner strong {
  color: var(--accent2);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  min-width: 0;
}

.stat .val {
  font-family: ui-monospace, monospace;
  font-size: clamp(0.8rem, 2.5vw, 1.2rem);
  font-weight: 600;
  color: var(--accent2);
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.stat .lbl {
  font-size: 0.75rem;
  color: var(--muted);
}

.charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 900px) {
  .charts {
    grid-template-columns: 1fr 1fr;
  }
}

.chart-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: clamp(0.75rem, 3vw, 1rem);
  min-height: 200px;
}

.chart-box h3 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bar-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(5rem, auto) 1fr 2.75rem;
  align-items: center;
  gap: 0.5rem 0.4rem;
  font-size: 0.85rem;
}

@media (max-width: 480px) {
  .bar-row {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
  }

  .bar-row .code {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .bar-row .bar-num {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
  }

  .bar-row .bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

.bar-row .code {
  font-family: ui-monospace, monospace;
  color: var(--text);
  font-weight: 600;
}

.bar-track {
  height: 22px;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.25s ease;
  min-width: 2px;
}

.bar-num {
  text-align: right;
  font-family: ui-monospace, monospace;
  color: var(--muted);
}

.pie-layout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
}

.pie-ring {
  width: clamp(140px, 52vw, 180px);
  height: clamp(140px, 52vw, 180px);
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid var(--border);
  mask: radial-gradient(farthest-side, transparent calc(50% - 28px), #000 calc(50% - 27px));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(50% - 28px), #000 calc(50% - 27px));
}

.pie-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.85rem;
  max-width: min(100%, 22rem);
}

.pie-legend li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
  line-height: 1.35;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.table-scroll {
  margin-top: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
}

table {
  width: 100%;
  min-width: 280px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

@media (max-width: 480px) {
  table {
    font-size: 0.8125rem;
  }

  th,
  td {
    padding: 0.55rem 0.5rem;
  }
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

@media (hover: hover) and (pointer: fine) {
  tr:hover td {
    background: rgba(27, 127, 90, 0.08);
  }
}

tr.row-winner td {
  background: rgba(201, 162, 39, 0.12);
}

.table-scroll table {
  margin: 0;
}

.table-scroll tbody tr:last-child td {
  border-bottom: none;
}

.err {
  color: var(--danger);
  padding: 1rem;
  background: rgba(201, 76, 76, 0.12);
  border-radius: 8px;
  border: 1px solid var(--danger);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1.25rem;
}

.toolbar > div {
  flex: 1 1 12rem;
  min-width: 0;
}

@media (max-width: 640px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
  }

  .toolbar > div {
    flex: none;
    width: 100%;
  }
}

.toolbar label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: block;
  margin-bottom: 0.35rem;
}

.toolbar select {
  font-family: ui-monospace, monospace;
  font-size: 16px;
  line-height: 1.3;
  padding: 0.65rem 0.75rem;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.panel-loader {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 20, 25, 0.75);
  border-radius: 12px;
  backdrop-filter: blur(3px);
}

.panel-loader[hidden] {
  display: none !important;
}

.panel-loader-inner {
  text-align: center;
  color: var(--muted);
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 0.5rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: pc-spin 0.7s linear infinite;
}

@keyframes pc-spin {
  to {
    transform: rotate(360deg);
  }
}

.panel-loader-text {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}
