/* Studio Wyborcze – mobile first */
:root {
  --paper: #ffffff;
  --desk: #e9ecef;
  --ink: #000000;
  --muted: #5b6370;
  --rule: #1a1a1a;
  --line: #d5d9de;
  --red: #d4213d;
  --navy: #07173a;
  --ok: #1a7f45;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 var(--font); color: var(--ink); background: var(--desk); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
a { color: inherit; }

/* ---------- Karta do głosowania ---------- */
.ballot-page { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }

.masthead {
  background: var(--paper);
  padding: calc(20px + env(safe-area-inset-top)) 18px 18px;
  border-bottom: 3px double var(--rule);
  max-width: 640px; margin: 0 auto;
}
.stamp {
  display: inline-block; font-size: 13px; font-weight: 600;
  color: var(--red); border: 1.5px solid var(--red); border-radius: 3px;
  padding: 2px 8px; transform: rotate(-1.5deg);
}
.masthead h1 {
  margin: 12px 0 2px; font-size: clamp(30px, 9vw, 44px); line-height: .95;
  font-weight: 900; font-stretch: 72%; letter-spacing: -.01em;
}
.lede { margin: 0; font-size: 17px; }
.hours { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.hours strong { color: var(--ink); }

.sheet { background: var(--paper); max-width: 640px; margin: 0 auto; padding: 14px 18px 24px; min-height: 60vh; }
.howto { margin: 0 0 12px; font-size: 14px; color: var(--muted); }

.alert { background: #fdecef; border-left: 4px solid var(--red); padding: 10px 12px; margin: 0 0 12px; font-size: 15px; }
.alert.ok { background: #e8f5ec; border-left-color: var(--ok); }

.list { list-style: none; margin: 0; padding: 0; }
.party { padding: 12px 0 10px; border-bottom: 1px solid var(--line); }
.party .row { display: flex; align-items: baseline; gap: 10px; }
.party .no {
  flex: 0 0 26px; height: 26px; display: grid; place-items: center;
  border: 1.5px solid var(--rule); font-size: 13px; font-weight: 700;
}
.party .name { flex: 1; font-weight: 700; font-size: 16px; line-height: 1.2; }
.party .val {
  font-weight: 900; font-stretch: 80%; font-size: 24px;
  font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right;
}
.ctrl { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.step {
  flex: 0 0 44px; height: 44px; border-radius: 50%;
  border: 1.5px solid var(--rule); background: var(--paper);
  font-size: 22px; font-weight: 700; line-height: 1; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.step:active { background: var(--ink); color: var(--paper); }

/* suwak */
input[type=range] {
  --p: 0%;
  -webkit-appearance: none; appearance: none;
  flex: 1; width: 100%; height: 44px; margin: 0; background: transparent; cursor: pointer;
  touch-action: pan-y;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 12px; border-radius: 6px;
  background: linear-gradient(to right, var(--c) 0 var(--p), var(--line) var(--p) 100%);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 30px; height: 30px; margin-top: -9px; border-radius: 50%;
  background: var(--paper); border: 3px solid var(--c); box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
input[type=range]::-moz-range-track { height: 12px; border-radius: 6px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 12px; border-radius: 6px; background: var(--c); }
input[type=range]::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--paper); border: 3px solid var(--c); box-shadow: 0 1px 3px rgba(0,0,0,.3);
}

/* dolny pasek z sumą – „urna” */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--paper); border-top: 3px double var(--rule);
  padding: 0 14px calc(10px + env(safe-area-inset-bottom));
}
.dock > * { max-width: 612px; margin-left: auto; margin-right: auto; }
.meter { height: 5px; background: var(--line); margin-bottom: 10px; }
.meter span { display: block; height: 100%; width: 0; background: var(--ink); transition: width .15s; }
.full .meter span { background: var(--red); }
.dock-row { display: flex; align-items: center; gap: 8px; }
.sum { flex: 1; display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 2px; }
.sum strong { font-size: 34px; font-weight: 900; font-stretch: 75%; line-height: 1; font-variant-numeric: tabular-nums; }
.sum span { font-size: 15px; color: var(--muted); }
.sum small { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.full .sum small { color: var(--red); font-weight: 700; }

.cast {
  border: 0; border-radius: 6px; background: var(--red); color: #fff;
  font-weight: 800; padding: 14px 16px; cursor: pointer; min-height: 48px;
}
.cast:disabled { background: #c6cad0; color: #fff; cursor: not-allowed; }
.ghost {
  border: 1.5px solid var(--rule); border-radius: 6px; background: transparent;
  padding: 12px; min-height: 48px; cursor: pointer; font-weight: 600;
}

/* po głosowaniu */
.done { padding: 10px 0; }
.done h2 { margin: 6px 0; font-size: 28px; font-weight: 900; font-stretch: 75%; }
.done p { margin: 0 0 14px; }
.done-mark {
  width: 56px; height: 56px; border: 2px solid var(--rule);
  display: grid; place-items: center; font-size: 40px; font-weight: 900; color: var(--red);
}
.closed h2 { color: var(--red); }
.mine { list-style: none; margin: 0; padding: 0; }
.mine li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mine .v { font-weight: 800; font-variant-numeric: tabular-nums; }
.mine .bar { grid-column: 1 / -1; height: 6px; background: linear-gradient(to right, var(--c) 0 var(--p), var(--line) var(--p) 100%); border-radius: 3px; }

/* ---------- Panel admina ---------- */
.admin { max-width: 860px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 14px 40px; }
.admin.narrow { max-width: 380px; padding-top: 18vh; }
.admin h1 { font-size: 28px; font-weight: 900; font-stretch: 75%; margin: 0 0 12px; }
.admin h2 { font-size: 18px; margin: 0 0 10px; }
.admin-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.admin-head nav { display: flex; gap: 14px; font-size: 15px; }
.panel { background: var(--paper); padding: 16px; margin: 0 0 12px; border-top: 3px solid var(--rule); }
.panel.danger { border-top-color: var(--red); }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 8px; }
.kpis div { background: var(--paper); padding: 12px; }
.kpis span { display: block; font-size: 13px; color: var(--muted); }
.kpis strong { font-size: 30px; font-weight: 900; font-stretch: 75%; font-variant-numeric: tabular-nums; }
.kpis .hl { background: var(--ink); color: var(--paper); }
.kpis .hl span { color: #c9ced6; }
.kpis .on { color: var(--ok); }
.kpis .off { color: var(--red); }

.avg { list-style: none; margin: 0 0 8px; padding: 0; }
.avg li { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 6px 0; }
.avg .bar { grid-column: 1 / -1; grid-row: 2; height: 14px; background: var(--c); width: var(--w); min-width: 2px; }
.avg .v { font-weight: 800; font-variant-numeric: tabular-nums; }

table.hours { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.hours th, table.hours td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.hours th { font-size: 13px; color: var(--muted); font-weight: 600; }

.settings { display: grid; gap: 12px; }
.settings label, .panel > label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
.settings input[type=number], .settings input[type=text], .settings input[type=datetime-local],
.panel input[type=password] {
  width: 100%; padding: 11px 12px; border: 1.5px solid var(--rule); border-radius: 4px; background: #fff; font-size: 16px;
}
.settings .check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.settings .check input { width: 22px; height: 22px; accent-color: var(--red); }
.panel .cast { margin-top: 10px; width: 100%; }
.settings .cast, .settings .ghost { width: 100%; }

@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .avg li { grid-template-columns: 260px 1fr 70px; }
  .avg .bar { grid-column: 2; grid-row: 1; align-self: center; }
  .avg .v { text-align: right; }
}

/* ---------- Ekran wyników (TV) ---------- */
@property --c { syntax: '<color>'; inherits: true; initial-value: #c9d3e6; }

.tv {
  --neutral: #c9d3e6;
  --dz: 10px; /* głębokość 3D */
  color: #fff; min-height: 100vh; min-height: 100dvh;
  background: radial-gradient(120% 70% at 50% 115%, #1d3f86 0%, var(--navy) 62%) fixed, var(--navy);
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
}
.tv-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; border-bottom: 2px solid rgba(255,255,255,.25); padding-bottom: 12px; }
.onair { background: var(--red); font-weight: 800; font-size: 13px; padding: 3px 8px; }
.tv h1 { margin: 8px 0 0; font-size: clamp(28px, 6vw, 64px); font-weight: 900; font-stretch: 70%; line-height: .95; }
.tv-meta { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 20px; }
.tv-meta span { display: block; font-size: 13px; opacity: .7; }
.tv-meta strong { font-size: clamp(24px, 4vw, 44px); font-weight: 900; font-stretch: 75%; font-variant-numeric: tabular-nums; }
.reveal-btn {
  border: 0; border-radius: 6px; background: var(--red); color: #fff; cursor: pointer;
  font-weight: 900; font-stretch: 80%; font-size: clamp(18px, 2vw, 26px);
  padding: 12px 22px; min-height: 52px; box-shadow: 0 6px 0 #8e1428; transition: transform .08s, box-shadow .08s;
}
.reveal-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #8e1428; }
.tv-wait { flex: 1; display: grid; place-content: center; text-align: center; }
.tv-wait .big { font-size: clamp(36px, 9vw, 110px); font-weight: 900; font-stretch: 70%; margin: 0; }
.tv-preview { background: #fff3; padding: 6px 10px; font-size: 14px; }
.tv-foot { font-size: 13px; opacity: .7; margin: 12px 0 0; }

/* --- słupki: wspólne (bryła 3D: front + góra + bok) --- */
.chart { flex: 1; display: grid; gap: 16px; padding: 20px 0 0; align-content: start; }
.col { --c: var(--neutral); transition: --c .7s ease; }
.col.named { --c: var(--pc); }
.col .track { position: relative; }
.col .fill {
  --h: 0%;
  position: absolute;
  background: linear-gradient(90deg, rgba(255,255,255,.22), rgba(255,255,255,0) 45%, rgba(0,0,0,.18)), var(--c);
  transition-property: height, width;
}
.col .fill::before, .col .fill::after { content: ""; position: absolute; background: var(--c); }
.col .fill::before { /* góra */
  left: 0; bottom: 100%; width: 100%; height: var(--dz);
  transform: skewX(-45deg); transform-origin: left bottom; filter: brightness(1.3);
}
.col .fill::after { /* bok */
  left: 100%; bottom: 0; width: var(--dz); height: 100%;
  transform: skewY(-45deg); transform-origin: left bottom; filter: brightness(.65);
}
.col .pv {
  position: absolute; z-index: 2; white-space: nowrap;
  font-weight: 900; font-stretch: 80%; font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 8px rgba(0,0,0,.4);
  opacity: 0; transition: opacity .3s;
}
.revealed .col .pv { opacity: 1; }
.col .lbl { opacity: 0; transform: translateY(8px); transition: opacity .5s, transform .5s; }
.col.named .lbl { opacity: 1; transform: none; }
.col.under.named .fill { opacity: .6; }
.col .track::after { /* próg */
  content: ""; position: absolute; z-index: 1; opacity: 0; transition: opacity .6s;
}
.done .col .track::after { opacity: 1; }

/* --- mobile: poziome --- */
.col { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 8px; min-width: 0; }
.col .lbl { grid-column: 1; grid-row: 1; padding-top: var(--dz); }
.col .lbl .s { font-weight: 800; font-size: 16px; }
.col .lbl .f { display: none; }
.col .track { grid-column: 2; grid-row: 1; height: calc(30px + var(--dz)); margin-right: 76px; }
.col .fill { left: 0; top: var(--dz); bottom: 0; width: var(--h); }
.col .pv { left: calc(100% + var(--dz) + 8px); top: 50%; transform: translateY(-50%); font-size: 20px; }
.col .track::after { top: 0; bottom: -3px; left: var(--thr); border-left: 2px dashed rgba(255,255,255,.6); }

/* --- duży ekran: pionowe, jak w studiu --- */
@media (min-width: 900px) {
  .tv { padding: 32px 48px; --dz: 18px; }
  .chart { grid-auto-flow: column; grid-auto-columns: 1fr; align-content: stretch; gap: 22px; padding-top: 70px; }
  .col { grid-template-columns: 1fr; grid-template-rows: 1fr auto; height: 100%; align-items: stretch; }
  .col .track { grid-column: 1; grid-row: 1; height: auto; min-height: 50vh; margin-right: 0; }
  .col .track::before { /* cień na podłodze */
    content: ""; position: absolute; left: -8%; right: -8%; bottom: -12px; height: 24px;
    background: radial-gradient(ellipse at center, rgba(0,0,0,.5), transparent 70%);
  }
  .col .fill { top: auto; left: 0; bottom: 0; width: calc(100% - var(--dz)); height: var(--h); }
  .col .pv {
    left: calc(50% + var(--dz) / 2); top: auto; bottom: calc(100% + var(--dz) + 8px);
    transform: translateX(-50%); font-size: clamp(22px, 2.6vw, 46px);
  }
  .col .track::after { top: auto; left: -6px; right: -6px; bottom: var(--thr); border-left: 0; border-top: 2px dashed rgba(255,255,255,.6); }
  .col .lbl { grid-row: 2; padding-top: 10px; text-align: center; border-top: 3px solid #fff; padding-top: 10px; margin-right: var(--dz); }
  .col .lbl .s { display: block; font-size: clamp(16px, 1.8vw, 28px); }
  .col .lbl .f { display: block; font-size: 12px; opacity: .7; line-height: 1.2; margin-top: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .col, .col .lbl, .col .pv { transition: none; }
  .meter span { transition: none; }
}

/* ---------- Mandaty: półkole Sejmu ---------- */
.tv-switch { color: #fff; opacity: .75; font-weight: 700; padding: 12px 4px; text-underline-offset: 4px; }
.tv-switch:hover { opacity: 1; }

.hemi-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-top: 12px; }
.hemi-stage { position: relative; width: 100%; max-width: min(1150px, calc((100vh - 330px) * 1.9)); margin: 0 auto; padding-top: 44px; }
.hemi {
  display: block; width: 100%; height: auto; overflow: visible;
  transform: perspective(1400px) rotateX(24deg); transform-origin: 50% 100%;
}
.hemi g { filter: drop-shadow(0 4px 2px rgba(0,0,0,.5)); }
.seat {
  fill: #2b4278; stroke: rgba(255,255,255,.18); stroke-width: 1;
  transform: scale(.6);
  transition: transform .45s cubic-bezier(.3,1.7,.5,1), fill .25s;
  animation: idle 2.4s ease-in-out infinite; animation-delay: calc(var(--a) * -.7s);
}
.seat.on { transform: scale(1); animation: none; }
@keyframes idle { 50% { fill: #44609e; } }

.majority { position: absolute; top: 0; left: 50%; transform: translateX(-50%); text-align: center; line-height: 1; }
.majority::after { content: ""; display: block; width: 0; height: 18px; margin: 4px auto 0; border-left: 2px dashed rgba(255,255,255,.7); }
.majority strong, .total strong { display: block; font-size: clamp(20px, 2.4vw, 34px); font-weight: 900; font-stretch: 75%; }
.majority span, .total span { font-size: 13px; opacity: .75; }
.total { position: absolute; left: 50%; bottom: 4%; transform: translateX(-50%); text-align: center; line-height: 1; }
.total strong { font-size: clamp(26px, 6vw, 84px); }

.seat-legend { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 22px; }
.seat-legend li { display: flex; align-items: center; gap: 8px; opacity: .25; transition: opacity .3s; }
.seat-legend li.in { opacity: 1; }
.seat-legend .chip { width: 16px; height: 16px; border-radius: 50%; background: var(--pc); box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.seat-legend .nm { font-weight: 700; font-size: clamp(15px, 1.6vw, 22px); }
.seat-legend .n { font-weight: 900; font-stretch: 75%; font-size: clamp(24px, 3vw, 44px); font-variant-numeric: tabular-nums; min-width: 2ch; }
.seat-legend li.win { outline: 2px solid #fff; outline-offset: 6px; border-radius: 4px; }
.below { text-align: center; font-size: 14px; opacity: 0; margin: 14px 0 0; transition: opacity .5s; }
.done .below { opacity: .75; }

@media (prefers-reduced-motion: reduce) {
  .seat { animation: none; transition: none; }
}

/* ---------- Admin: mandaty ---------- */
.seat-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.seat-table th, .seat-table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.seat-table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.seat-table td.num { text-align: right; font-weight: 800; }
.seat-table .sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
