:root {
  --bg: #f5f6f2;
  --surface: #ffffff;
  --ink: #1c2420;
  --muted: #5d6862;
  --line: #dfe3dc;
  --track: #eceee9;
  --gruen: #1f8a3b;
  --gruen-hell: #e3f3e6;
  --gruen-ink: #14602a;
  --sonne: #ffe16b;
  --warn: #9a5b00;
  --warn-bg: #fff4dc;
  --rot: #b3261e;
  --neutral-bar: #9aa39d;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1b211e;
    --ink: #e8ece9;
    --muted: #9aa59f;
    --line: #2c3530;
    --track: #262e2a;
    --gruen: #46b862;
    --gruen-hell: #1d3324;
    --gruen-ink: #8fdca3;
    --warn: #f0b85a;
    --warn-bg: #33291a;
    --rot: #f2958f;
    --neutral-bar: #69736d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1280px; margin: 0 auto; padding-inline: 16px; }

.num { font-variant-numeric: tabular-nums; }

/* Kopf */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding-block: 14px 10px;
}
.headline { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.eyebrow { margin: 0; color: var(--muted); font-size: 13px; }
h1 { margin: 2px 0 0; font-size: clamp(20px, 3vw, 28px); letter-spacing: -.01em; line-height: 1.15; }

.refresh { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; padding-top: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--neutral-bar); }
.dot.live { background: var(--gruen); animation: pulse 2s infinite; }
.dot.error { background: var(--rot); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--gruen) 60%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.summary { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { display: inline-flex; align-items: baseline; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.chip b { color: var(--ink); font-size: 15px; font-variant-numeric: tabular-nums; }
.chip.win { background: var(--gruen-hell); border-color: transparent; color: var(--gruen-ink); }
.chip.win b { color: var(--gruen-ink); }

.controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-top: 10px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 6px 12px; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.sort { font-size: 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.sort select { font: inherit; font-size: 13px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }

main { padding-block: 18px 8px; }

.notice { margin: 0 0 14px; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: var(--warn); font-size: 14px; }

/* Gebiete */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 600px), 1fr)); gap: 16px; }

.gebiet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; min-width: 0; }
.gebiet-head { padding: 12px 16px 10px; border-bottom: 1px solid var(--line); }
.gebiet-head h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.wahlen { display: grid; grid-template-columns: 1fr 1fr; }
.wahlen > .panel + .panel { border-left: 1px solid var(--line); }
@media (max-width: 640px) {
  .wahlen { grid-template-columns: 1fr; }
  .wahlen > .panel + .panel { border-left: 0; border-top: 1px solid var(--line); }
}

.panel { padding: 12px 16px 10px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel.gewaehlt { box-shadow: inset 0 3px 0 var(--gruen); }
.panel.flash { animation: flash 1.6s ease-out; }
.panel-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.panel-head h3 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.panel-head .who { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.panel-head .who strong { color: var(--ink); font-weight: 600; }
.badge.fertig { background: var(--track); color: var(--ink); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  transition: border-color .3s;
}
.card.gewaehlt { border-color: var(--gruen); box-shadow: 0 0 0 1px var(--gruen) inset, var(--shadow); }
.card.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--sonne) 45%, var(--surface)); } to { background: var(--surface); } }

.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card-head h2 { margin: 0; font-size: 17px; line-height: 1.2; }
.card-head .who { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.card-head .who strong { color: var(--ink); font-weight: 600; }

.badge { flex-shrink: 0; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--track); color: var(--muted); white-space: nowrap; }
.badge.laeuft { background: color-mix(in srgb, var(--sonne) 55%, transparent); color: #5a4700; }
.badge.gewaehlt { background: var(--gruen); color: #fff; }
.badge.stichwahl { background: var(--gruen-hell); color: var(--gruen-ink); }
.badge.aus { background: var(--track); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .badge.laeuft { color: #ffe9a0; background: #4a3f12; }
  /* sehr dunkle Parteifarben (CDU) sonst unsichtbar */
  .cand .track i { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28); }
}

.hero { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.hero .pct { font-size: 36px; font-weight: 750; letter-spacing: -.02em; line-height: 1; color: var(--gruen-ink); font-variant-numeric: tabular-nums; }
.hero .pct.none { color: var(--muted); font-size: 22px; font-weight: 600; letter-spacing: 0; }
.hero .place { font-size: 14px; color: var(--muted); }
.hero .place b { color: var(--ink); }

.progress { display: grid; gap: 4px; }
.progress .bar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--ink); border-radius: 3px; transition: width .6s; }
.progress .label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.cands { display: grid; gap: 5px; margin: 2px 0; padding: 0; list-style: none; }
.cand { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: center; font-size: 13px; }
.cand .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand .name small { color: var(--muted); }
.cand .val { text-align: right; font-variant-numeric: tabular-nums; }
.cand .track { grid-column: 1 / -1; position: relative; height: 7px; background: var(--track); border-radius: 4px; }
.cand .track i { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--neutral-bar); transition: width .6s; }
.cand.mehrheit .track::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--muted); opacity: .45; }
.cand .mark { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--ink); opacity: .55; border-radius: 1px; }
.cand .val small { font-size: 11px; margin-left: 2px; }
.cand.gruen .name { font-weight: 650; }
.cand.gruen .track { box-shadow: 0 0 0 1px var(--gruen); }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fact { background: var(--bg); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.fact .k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.fact .v { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.fact .v small { font-size: 13px; font-weight: 500; color: var(--muted); }
.fact .s { font-size: 12px; color: var(--muted); }
.up { color: var(--gruen-ink); }
.down { color: var(--rot); }

.card-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; margin-top: auto; flex-wrap: wrap; }
.card-foot a { color: inherit; }
.stale { color: var(--warn); }

.waiting { font-size: 14px; color: var(--muted); margin: 0; }

/* Tabelle */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tr.gewaehlt td:first-child { box-shadow: 4px 0 0 var(--gruen) inset; }
td .mini { display: inline-block; width: 60px; height: 5px; background: var(--track); border-radius: 3px; vertical-align: middle; margin-right: 6px; overflow: hidden; }
td .mini i { display: block; height: 100%; background: var(--ink); }
th.grp { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; border-bottom: 0; padding-bottom: 0; }
th.sep, td.sep { border-left: 1px solid var(--line); }
thead tr:first-child th { position: static; }

/* Methodik */
.method { margin: 26px 0 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.method summary { cursor: pointer; font-weight: 600; }
.method p { color: var(--muted); max-width: 75ch; }

.foot { color: var(--muted); font-size: 12px; padding-block: 8px 28px; }

@media (max-width: 520px) {
  .hero .pct { font-size: 34px; }
  .top { position: static; }
}
