:root {
  --bg: #f5f5fa;
  --surface: #ffffff;
  --ink: #15152b;
  --muted: #6a6a82;
  --line: #e3e3ee;
  --accent: #5b4bff;
  --accent-strong: #4535e8;
  --accent-soft: #eeecff;
  --accent-ink: #ffffff;
  --ok: #0f9a63;
  --ok-soft: #e1f6ec;
  --warn: #9a5c00;
  --warn-soft: #fff3d9;
  --danger: #d33148;
  --danger-soft: #fde8eb;
  --gold: #f2b705;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 20, 50, .06), 0 6px 20px rgba(20, 20, 50, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 8px 0 0; }

/* ---------- logo ---------- */
.logo {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 18px; color: var(--ink); text-decoration: none; letter-spacing: -0.02em;
}
.logo::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); box-shadow: 8px 0 0 -2px var(--gold);
  margin-right: 6px;
}

/* ---------- buttons & forms ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 10px 16px; border-radius: 12px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .15s, border-color .15s, transform .05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: #cfcfe0; background: #fafaff; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: #f5c3cb; }
.btn.big { font-size: 17px; padding: 14px 22px; border-radius: 14px; }
.btn.block { width: 100%; }

label { display: block; font-weight: 600; font-size: 14px; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: 13px; margin-top: 2px; }
input[type=text], input[type=password], input[type=number], textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-size: 15px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input:disabled, textarea:disabled { background: #f3f3f7; color: var(--muted); }
textarea { resize: vertical; min-height: 44px; }
.form { display: grid; gap: 16px; }
.form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- admin layout ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar a.link { color: var(--muted); text-decoration: none; font-size: 14px; }
.topbar a.link:hover { color: var(--ink); }
.wrap { max-width: 1080px; margin: 0 auto; padding: 28px 24px 64px; }
@media (max-width: 640px) { .wrap { padding: 20px 16px 48px; } .topbar { padding: 12px 16px; } }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}
.card h2 { font-size: 17px; margin-bottom: 16px; display: flex; align-items: baseline; gap: 10px; }
.card h2 small { font-weight: 500; font-size: 13px; color: var(--muted); }
.stack { display: grid; gap: 20px; }
.cols { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }
.page-title { font-size: 28px; margin-bottom: 4px; }
.back { display: inline-block; color: var(--muted); text-decoration: none; font-size: 14px; margin-bottom: 14px; }
.back:hover { color: var(--ink); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 4px 10px; border-radius: 999px; background: #efeff5; color: var(--muted); white-space: nowrap;
}
.badge.open { background: var(--ok-soft); color: var(--ok); }
.badge.open::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.4s infinite; }
.badge.closed { background: #ececf3; color: #4a4a60; }
@keyframes pulse { 50% { opacity: .25; } }

.poll-list { display: grid; gap: 8px; }
.poll-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px;
  color: inherit; text-decoration: none; transition: border-color .15s, background .15s;
}
.poll-row:hover { border-color: #c9c4ff; background: #fbfaff; }
.poll-row-title { font-weight: 650; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.poll-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.poll-head .meta { display: flex; align-items: center; gap: 10px; margin-top: 8px; color: var(--muted); font-size: 14px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.stat { background: var(--bg); border-radius: 12px; padding: 14px 16px; }
.stat-num { font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-label { color: var(--muted); font-size: 13px; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; }

.qr-card { text-align: center; }
.qr-card img { width: 220px; height: 220px; display: block; margin: 0 auto 10px; image-rendering: pixelated; }
.qr-url { display: block; font-weight: 600; word-break: break-all; margin-bottom: 14px; }
.qr-card .controls { justify-content: center; }
.notice { font-size: 13px; text-align: left; border-radius: 10px; padding: 10px 12px; margin-top: 14px; background: var(--warn-soft); color: var(--warn); }
.danger-zone { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.danger-zone p { margin: 0 auto 0 0; color: var(--muted); font-size: 14px; }

/* ---------- result bars ---------- */
.bars { display: grid; gap: 14px; }
.bar-label { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.bar-rank { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; min-width: 1.6em; }
.bar-name { font-weight: 650; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.bar-value { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-value small { color: var(--muted); font-weight: 500; }
.bar-track { height: 14px; background: #efeff6; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.bar.is-winner .bar-fill { background: linear-gradient(90deg, var(--accent), #8b5cff); }
.bars-empty { color: var(--muted); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; }
.login .logo { margin-bottom: 20px; font-size: 22px; }

/* ---------- voter (phone) ---------- */
body.voter { background: var(--surface); }
.vote-wrap { max-width: 560px; margin: 0 auto; padding: 0 16px calc(150px + env(safe-area-inset-bottom)); min-height: 100vh; }
.vote-head {
  position: sticky; top: 0; z-index: 2; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; padding: 14px 0 12px;
}
.vote-head .logo { font-size: 16px; }
.timer {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px;
  background: var(--accent-soft); color: var(--accent-strong); padding: 5px 10px; border-radius: 999px;
}
.timer.low { background: var(--danger-soft); color: var(--danger); }
.vote-title { font-size: 26px; margin: 8px 0 6px; }
.vote-desc { color: var(--muted); margin: 0 0 6px; }
.vote-hint { margin: 10px 0 18px; font-size: 15px; }

.opts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.opt { display: flex; gap: 8px; }
.opt-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  text-align: left; font: inherit; font-size: 17px; font-weight: 600; color: var(--ink);
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 16px;
  cursor: pointer; -webkit-tap-highlight-color: transparent; transition: border-color .15s, background .15s;
}
.opt-btn:active { transform: scale(.99); }
.opt.on .opt-btn { border-color: var(--accent); background: var(--accent-soft); }
.opt-label { overflow-wrap: anywhere; }
.opt-dots { display: flex; gap: 5px; flex-shrink: 0; }
.opt-minus {
  width: 52px; flex-shrink: 0; font: inherit; font-size: 24px; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.opt-minus:disabled { opacity: .35; }
.dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #c9c9da; background: transparent; transition: background .15s, border-color .15s, transform .15s; }
.dot.on { background: var(--accent); border-color: var(--accent); transform: scale(1.05); }
.opt-dots .dot.single { width: 26px; height: 26px; display: grid; place-items: center; }
.opt-dots .dot.single.on::after {
  content: ""; width: 7px; height: 12px; border: solid #fff; border-width: 0 3px 3px 0; transform: translateY(-1px) rotate(45deg);
}

.vote-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3;
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
}
.vote-foot-inner { max-width: 560px; margin: 0 auto; }
.wallet { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.wallet-dots { display: flex; gap: 6px; }
.wallet-dots .dot { width: 16px; height: 16px; }
.wallet.shake { animation: shake .35s; color: var(--danger); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.vote-foot .error { text-align: center; margin-top: 6px; min-height: 0; }

.message { min-height: 80vh; display: grid; place-content: center; text-align: center; gap: 12px; padding: 24px 8px; }
.message h1 { font-size: 30px; }
.message p { color: var(--muted); font-size: 17px; margin: 0; max-width: 340px; }
.message-icon { font-size: 48px; line-height: 1; }
.message-icon.pulse { animation: pulse 1.6s infinite; }
.check {
  width: 88px; height: 88px; border-radius: 50%; background: var(--ok-soft); color: var(--ok);
  display: grid; place-items: center; margin: 0 auto 8px; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

/* ---------- presentation ---------- */
body.present { background: #ffffff; overflow: hidden; }
.stage { height: 100vh; display: flex; flex-direction: column; padding: 4vh 5vw 3vh; }
.stage-head { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 3vh; }
.stage-head h1 { font-size: clamp(28px, 4vw, 56px); letter-spacing: -0.02em; }
.stage-head .logo { font-size: clamp(16px, 1.5vw, 22px); flex-shrink: 0; }
.stage-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.stage-split { display: grid; grid-template-columns: auto 1fr; gap: 6vw; align-items: center; width: 100%; }
.qr-big { background: #fff; border-radius: 24px; padding: 1.5vh; box-shadow: 0 0 0 1px var(--line), var(--shadow); }
.qr-big img { display: block; height: min(62vh, 44vw); width: auto; aspect-ratio: 1; image-rendering: pixelated; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-weight: 800; color: var(--accent); font-size: clamp(14px, 1.4vw, 22px); }
.stage-big { font-size: clamp(40px, 6vw, 96px); font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; margin: 1.5vh 0; }
.stage-timer { font-size: clamp(80px, 14vw, 220px); font-weight: 800; letter-spacing: -0.04em; line-height: 1; font-variant-numeric: tabular-nums; margin: 1vh 0 2vh; }
.stage-timer.low { color: var(--danger); }
.stage-sub { font-size: clamp(18px, 2vw, 32px); color: var(--muted); }
.stage-sub b { color: var(--ink); font-variant-numeric: tabular-nums; }
.stage-url { font-size: clamp(14px, 1.5vw, 22px); color: var(--muted); margin-top: 2vh; font-weight: 600; }
.stage-center { text-align: center; }
.stage-center .btn { margin-top: 4vh; font-size: clamp(18px, 1.8vw, 26px); padding: 18px 34px; border-radius: 16px; }
.stage-results { width: 100%; max-width: 1300px; align-self: stretch; display: flex; flex-direction: column; justify-content: center; }
.stage-results .bars { gap: clamp(10px, 2vh, 24px); }
.stage-results .bar-label { font-size: clamp(18px, 2.2vw, 34px); margin-bottom: .6vh; }
.stage-results .bar-track { height: clamp(14px, 2.6vh, 30px); }
.stage-results .bar-fill { transition-duration: 1.4s; }
.stage-results .bar.is-winner .bar-name::after { content: "  🏆"; }
.stage-results .bar.is-winner .bar-label { color: var(--accent-strong); }
.stage-results .footnote { margin-top: 3vh; color: var(--muted); font-size: clamp(14px, 1.4vw, 20px); text-align: center; }
.stage-controls {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; gap: 8px; padding: 8px; border-radius: 16px; background: rgba(255, 255, 255, .92);
  box-shadow: 0 0 0 1px var(--line), var(--shadow); opacity: .12; transition: opacity .2s;
}
.stage-controls:hover, .stage-controls:focus-within { opacity: 1; }
.stage-controls .btn { font-size: 14px; padding: 8px 12px; }
@media (max-width: 760px) {
  .stage-split { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .qr-big img { height: 50vw; }
}
