:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #e2e0d9;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74726c;
  --grid: #e6e4de;
  --s1: #2a78d6;  /* candidato de menor número */
  --s2: #eb6834;  /* candidato de maior número */
  --s0: #a3a19a;  /* demais / sem dados */
  --good: #0f7a3d;
  --warn: #9a6200;
  --warn-bg: #fff4dc;
  --crit: #b3261e;
  --crit-bg: #fde8e6;
  --radius: 14px;
  --font: "Inter Tight", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #141413; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #94938b; --grid: #2c2c29;
    --s1: #3987e5; --s2: #d95926; --s0: #5f5e58;
    --good: #4cc27e; --warn: #f0b44c; --warn-bg: #2d2416; --crit: #f08a82; --crit-bg: #321b19;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #94938b; --grid: #2c2c29;
  --s1: #3987e5; --s2: #d95926; --s0: #5f5e58;
  --good: #4cc27e; --warn: #f0b44c; --warn-bg: #2d2416; --crit: #f08a82; --crit-bg: #321b19;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-underline-offset: 3px; }
.wrap { max-width: 1180px; margin: 0 auto; padding-block: 24px 48px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: clamp(28px, 5vw, 44px); font-weight: 800; line-height: 1.05; }
h2 { font-size: 18px; font-weight: 700; }
.eyebrow { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: .02em; text-transform: uppercase; }

.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; border: 1px solid var(--border); background: var(--surface); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-live { color: var(--crit); }
.pill-live::before { animation: pulse 1.6s infinite; }
.pill-final { color: var(--good); }
.pill-wait { color: var(--muted); }
.pill-demo { color: var(--warn); }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .pill-live::before { animation: none; } }

.banner { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; background: var(--warn-bg); color: var(--text); border: 1px solid color-mix(in oklab, var(--warn) 40%, transparent); }
.banner strong { color: var(--warn); }

.progress-block { margin-bottom: 20px; }
.progress-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; font-size: 15px; }
.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--text); border-radius: 999px; transition: width .6s ease; }

.score { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.cand { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px 20px; overflow: hidden; }
.cand::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--c); }
.cand.right { text-align: right; }
.cand.right::before { inset: 0 0 0 auto; }
.cand-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cand.right .cand-top { flex-direction: row-reverse; }
.cand-num { font-family: var(--mono); font-size: 13px; color: var(--text-2); }
.cand-name { font-size: clamp(18px, 2.6vw, 24px); font-weight: 800; letter-spacing: -0.01em; margin: 2px 0 0; }
.cand-sub { font-size: 13px; color: var(--muted); }
.cand-pct { font-size: clamp(40px, 8vw, 72px); font-weight: 800; letter-spacing: -0.04em; line-height: 1; margin-top: 12px; }
.cand-pct small { font-size: .4em; font-weight: 700; letter-spacing: 0; margin-left: 2px; }
.cand-votes { font-size: 15px; color: var(--text-2); margin-top: 6px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; padding: 4px 10px; border-radius: 999px; background: var(--text); color: var(--surface); }
.badge-lead { background: transparent; color: var(--text); border: 1.5px solid var(--text); }
.others { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-2); padding: 0 4px; }

.split-block { margin-bottom: 20px; }
.split { position: relative; display: flex; gap: 2px; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.split-a { background: var(--s1); width: 50%; transition: width .6s ease; }
.split-b { background: var(--s2); flex: 1; }
.split-mid { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); opacity: .7; }
.lead-line { margin: 10px 0 0; font-size: 15px; color: var(--text-2); }
.lead-line strong { color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat-sub { font-size: 12px; color: var(--muted); }

.grid2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 12px; margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 18px 16px; min-width: 0; }
.card + .card, .grid2 + .card { margin-top: 0; }
.card-head { margin-bottom: 12px; }
.card-head p { margin: 4px 0 0; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; background: var(--c); }

.chart { position: relative; width: 100%; aspect-ratio: 16 / 10; min-height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .ref { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 4; opacity: .7; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .end-label { font-size: 12px; font-weight: 700; fill: var(--text); }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.empty { color: var(--muted); font-size: 14px; display: grid; place-items: center; height: 100%; margin: 0; text-align: center; }

.tilemap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; max-width: 460px; margin: 4px auto 0; }
.tile { aspect-ratio: 1; border-radius: 7px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: clamp(10px, 1.6vw, 13px); font-weight: 800; position: relative; cursor: default; border: none; padding: 0; font-family: var(--font); color: var(--tile-ink, var(--text)); background: var(--tile-bg, var(--surface-2)); }
.tile span { font-size: .78em; font-weight: 600; opacity: .9; }
.tile:focus-visible, .tile:hover { outline: 2px solid var(--text); outline-offset: 1px; }
.tile .bar { position: absolute; left: 5px; right: 5px; bottom: 4px; height: 3px; border-radius: 2px; background: color-mix(in oklab, currentColor 25%, transparent); overflow: hidden; }
.tile .bar i { display: block; height: 100%; background: currentColor; }
.tile.zz { grid-column: span 2; aspect-ratio: auto; }
.map-key { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 12px; color: var(--text-2); }
.map-key .ramp { display: inline-flex; gap: 2px; vertical-align: middle; margin: 0 6px; }
.map-key .ramp b { width: 16px; height: 10px; border-radius: 2px; display: inline-block; }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; cursor: pointer; user-select: none; }
th[aria-sort] { color: var(--text); }
th[aria-sort="ascending"]::after { content: " ↑"; }
th[aria-sort="descending"]::after { content: " ↓"; }
td .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; background: var(--c); }
td.win { font-weight: 700; }
tbody tr:hover { background: var(--surface-2); }
.minibar { display: inline-block; width: 60px; height: 6px; border-radius: 3px; background: var(--surface-2); vertical-align: middle; margin-left: 8px; overflow: hidden; }
.minibar i { display: block; height: 100%; background: var(--text-2); }

.foot { margin-top: 28px; font-size: 13px; color: var(--text-2); }
.foot p { margin: 4px 0; }

.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13px; box-shadow: 0 6px 24px rgb(0 0 0 / .14); min-width: 160px; }
.tooltip .tt-title { font-weight: 700; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .tt-row i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; background: var(--c); }

@media (max-width: 860px) {
  .grid2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .score { gap: 8px; }
  .cand { padding: 14px 14px 16px; }
  .meta { align-items: flex-start; }
  .top { align-items: flex-start; }
}

/* o gráfico ocupa a altura disponível ao lado do mapa */
.grid2 > .card { display: flex; flex-direction: column; }
.grid2 .chart { flex: 1; aspect-ratio: auto; min-height: 260px; }
@media (max-width: 860px) { .grid2 .chart { aspect-ratio: 4 / 3; flex: none; } }

@media (max-width: 620px) {
  table { min-width: 0; font-size: 13px; }
  th, td { padding: 8px 6px; }
  .opt, .minibar { display: none; }
  th { white-space: normal; vertical-align: bottom; line-height: 1.2; }
  td:first-child { white-space: normal; line-height: 1.25; }
  td .sw { margin-right: 4px; }
  .card { padding: 16px 12px 14px; }
  .table-wrap { margin: 0; }
}
