/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(40% 35% at 18% 12%, var(--blob-a), transparent 70%),
    radial-gradient(45% 30% at 90% 38%, var(--blob-b), transparent 70%),
    radial-gradient(40% 30% at 30% 88%, var(--blob-c), transparent 70%);
}
h1, h2, h3 { font-family: var(--font-round); line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 17px; }
p { margin: 0; }
img { max-width: 100%; display: block; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: no-preference) {
  a, button { transition: background-color var(--ease-ui), border-color var(--ease-ui), color var(--ease-ui); }
}

.num { font-variant-numeric: tabular-nums; }
.muted, .meta, .hint { color: var(--muted); }
.meta { font-size: 13px; }
.hint { font-size: 12.5px; }
.label { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.pad { padding: 14px 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.btn-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn-row form { margin: 0; }
.empty { color: var(--muted); }
kbd {
  font: 600 12px var(--font-mono);
  padding: 1px 6px;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  background: var(--glass-bg);
}
code { font-family: var(--font-mono); font-size: 13px; }

/* ---------- glass ---------- */
.card {
  border-radius: var(--radius);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 -1px 0 var(--glass-edge-low), var(--glass-shadow);
}
.chrome {
  background: var(--glass-chrome);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; border-color: var(--glass-border); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: var(--accent-glow); }
.btn-primary:hover { border-color: transparent; filter: brightness(1.06); }
.btn-danger { color: var(--danger); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-big { min-height: 52px; font-size: 16px; padding: 0 22px; }
.btn-block { width: 100%; }
.btn.busy { opacity: 0.7; }
.btn.busy::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.seg {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  flex-wrap: wrap;
}
.chip {
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
}
.chip:hover { background: var(--accent-soft); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-size: 13px; font-weight: 600; padding: 0; margin-bottom: 6px; }
.field input, .field textarea, .field select, .option-label {
  min-height: 46px;
  padding: 10px 14px;
  border-radius: var(--radius-input);
  border: 1px solid var(--glass-border);
  background: var(--field);
  color: var(--ink);
  width: 100%;
}
.field textarea { resize: vertical; }
.checkline { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.checkline input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); }

.notice { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; background: var(--accent-soft); }
.notice ul { margin: 0; padding-left: 18px; }
.notice-error { color: var(--danger); background: var(--danger-soft); }
.notice-success { color: var(--success); background: var(--success-soft); }

.state {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: var(--muted);
}
.state-open { background: var(--success-soft); color: var(--success); }
.state-closed { background: var(--warn-soft); color: var(--warn); }
.state-archived { background: var(--line); }

.opt-pos-1 { --c: var(--opt-1); }
.opt-pos-2 { --c: var(--opt-2); }
.opt-pos-3 { --c: var(--opt-3); }
.opt-pos-4 { --c: var(--opt-4); }

/* ---------- admin ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 10px max(var(--gutter), env(safe-area-inset-left));
  border-bottom: 1px solid var(--glass-border);
}
.brand { display: flex; align-items: center; gap: 8px; font: 700 17px var(--font-round); color: var(--ink); text-decoration: none; }
.bar-nav { display: flex; align-items: center; gap: 14px; }
.bar-nav a { color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px; }
.bar-nav a:hover { color: var(--accent); }
.bar-nav form { margin: 0; }

.page {
  max-width: 60rem;
  margin: 0 auto;
  padding: 18px var(--gutter) calc(40px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.page.narrow { max-width: 40rem; }
.page.wide { max-width: 80rem; }

.poll-list { display: grid; gap: 12px; }
.poll-card { display: grid; gap: 12px; }
.poll-card p { margin-top: 4px; }
@media (min-width: 720px) {
  .poll-card { grid-template-columns: 1fr auto; align-items: start; }
}
.opt-chips { list-style: none; margin: 10px 0 0; padding: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.opt-chips li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  font-size: 13px;
}
.opt-chips li:not(:has(img)) { padding-left: 10px; }
.opt-chips img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }

.run-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.run-card { display: flex; flex-direction: column; gap: 10px; }
.result-mini { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.result-mini li { display: flex; justify-content: space-between; gap: 8px; }
.result-mini li.lead { font-weight: 700; color: var(--accent); }

.option-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  grid-template-areas: "sw label rm" "sw img img";
  gap: 8px 10px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.option-row:last-child { border-bottom: 0; padding-bottom: 0; }
.option-row .swatch { grid-area: sw; align-self: stretch; border-radius: 5px; background: var(--opt-1); }
.option-row:nth-child(2) .swatch { background: var(--opt-2); }
.option-row:nth-child(3) .swatch { background: var(--opt-3); }
.option-row:nth-child(4) .swatch { background: var(--opt-4); }
.option-row .option-label { grid-area: label; }
.option-row .remove-option { grid-area: rm; }
.option-img { grid-area: img; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.option-img .thumb { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); }
.file-btn { cursor: pointer; }

.layout-picks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.layout-pick {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.layout-pick input { position: absolute; opacity: 0; }
.layout-pick:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.layout-pick:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.mini { display: flex; width: 64px; height: 40px; gap: 4px; }
.mini i { display: block; border-radius: 3px; }
.mini i:nth-child(1) { background: var(--opt-1); }
.mini i:nth-child(2) { background: var(--opt-2); }
.mini i:nth-child(3) { background: var(--opt-3); }
.mini-vbars { align-items: flex-end; }
.mini-vbars i { flex: 1; }
.mini-vbars i:nth-child(1) { height: 100%; }
.mini-vbars i:nth-child(2) { height: 60%; }
.mini-vbars i:nth-child(3) { height: 35%; }
.mini-hbars { flex-direction: column; justify-content: center; }
.mini-hbars i { height: 8px; }
.mini-hbars i:nth-child(1) { width: 100%; }
.mini-hbars i:nth-child(2) { width: 60%; }
.mini-hbars i:nth-child(3) { width: 35%; }
.mini-corners { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 6px 18px; }
.mini-corners i:nth-child(3) { grid-column: 1 / 3; justify-self: center; width: 50%; }

.enter { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.enter-card { width: min(100%, 360px); align-items: center; text-align: center; padding: 28px 22px; }
.enter-card form { width: 100%; text-align: left; }
.brand-big { filter: drop-shadow(0 8px 18px rgba(47, 111, 191, 0.35)); }

.control-head { display: grid; gap: 12px; }
@media (min-width: 900px) {
  .control-head { grid-template-columns: 1fr auto; align-items: start; }
  .url-row { grid-column: 1 / -1; }
}
.url-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.url-row code { padding: 6px 10px; border-radius: var(--radius-sm); background: var(--field); word-break: break-all; }
.control-grid { display: grid; gap: 16px; }
@media (min-width: 900px) { .control-grid { grid-template-columns: minmax(340px, 1fr) minmax(340px, 1fr); align-items: start; } }
.ctl-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-weight: 600; }
.live { display: flex; flex-direction: column; gap: 14px; }
.live-stats { display: flex; gap: 20px; flex-wrap: wrap; align-items: baseline; }
.live-stats .num { font: 700 20px var(--font-round); }
.live-stats .num.big { font-size: 40px; }
.live-opts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.live-opts li { display: grid; grid-template-columns: 1fr auto 52px; gap: 4px 12px; align-items: baseline; font-weight: 600; }
.live-opts .pct { text-align: right; color: var(--muted); }
.live-opts .opt-track { grid-column: 1 / -1; height: 10px; }
.live-opts .opt-bar { height: 100%; width: calc(var(--bar, 0) * 100%); }
.live-opts li.is-leader .lbl { color: var(--accent); }

/* ---------- results (shared by display and voter mirror) ---------- */
.opt { --bar: 0; --s: 1; min-width: 0; }
.opt-track { position: relative; overflow: hidden; border-radius: var(--radius-sm); background: var(--track); }
.opt-bar { background: var(--c); border-radius: var(--radius-sm); }
.opt-label { font-weight: 600; overflow-wrap: anywhere; }
.opt-value { font-family: var(--font-round); font-weight: 700; white-space: nowrap; }
.results-hidden .opt-value { visibility: hidden; }
.opt.is-leader .opt-bar { box-shadow: 0 0 24px var(--c); }
/* Media sits in a solid frame in the option colour (the visible "border" is its padding),
   so an image that lags a resize never shows a gap. Motion and share scaling move the frame.
   .no-frame (Controller "Image border" off) removes it, e.g. for transparent images. */
.opt-frame {
  display: block;
  width: 100%;
  height: 100%;
  padding: var(--frame-w, 3px);
  border-radius: var(--frame-r, var(--radius-sm));
  background: var(--c);
}
.opt-frame > .opt-img,
.opt-frame > .opt-tile { display: block; width: 100%; height: 100%; border-radius: calc(var(--frame-r, var(--radius-sm)) - var(--frame-w, 3px)); }
.opt-frame > .opt-img { object-fit: cover; }
/* One compositing layer per option: the browser then scales frame and image as a single
   bitmap, so they cannot drift apart mid-animation (seen in Firefox). */
.opt-media { will-change: transform, scale; }
.layout.motion .opt-frame { will-change: transform, translate, scale; }
.opt.is-leader .opt-frame { box-shadow: 0 0 28px var(--c); }
.layout.no-frame .opt-frame { padding: 0; background: none; box-shadow: none; }
.layout.no-frame .opt-frame > .opt-img { object-fit: contain; }
.layout.no-frame .opt.is-leader .opt-frame { box-shadow: none; filter: drop-shadow(0 0 14px var(--c)); }
.badge { display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.opt-tile {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 12px;
  background: var(--bg);
  font: 700 clamp(18px, 2.4vw, 44px)/1.15 var(--font-round);
  overflow-wrap: anywhere;
}

/* ---------- voter ---------- */
.voter-app {
  max-width: 34rem;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) calc(140px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.vhead { display: flex; align-items: flex-start; gap: 10px; }
.vhead .brand-mark { flex: none; margin-top: 2px; }
.vhead .question { font-size: 22px; }
.screen { display: flex; flex-direction: column; gap: 14px; }

.waiting { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 28px 16px; }
.pulse { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); margin-bottom: 10px; }
@media (prefers-reduced-motion: no-preference) {
  .pulse { animation: pulse 1.6s ease-in-out infinite; }
}
@keyframes pulse {
  0%, 100% { transform: scale(0.8); box-shadow: 0 0 0 0 var(--accent-soft); }
  50% { transform: scale(1); box-shadow: 0 0 0 14px transparent; }
}

.choices { display: grid; gap: 12px; }
.choices.with-img.n-4 { grid-template-columns: 1fr 1fr; }
.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 48px 12px 22px;
  text-align: left;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.choice::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: var(--c);
}
.choices.with-img .choice { flex-direction: column; align-items: stretch; padding: 16px 10px 12px; }
.choices.with-img .choice::before { right: 0; bottom: auto; width: auto; height: 6px; }
.choice img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm); }
.choice-label { font: 700 18px/1.2 var(--font-round); overflow-wrap: anywhere; }
.choices.with-img .choice-label { padding-right: 30px; }
.choice .check {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--glass-border);
  background: var(--field);
}
.choices:not(.with-img) .choice .check { top: 50%; bottom: auto; margin-top: -13px; }
.choice[aria-checked="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent), var(--glass-shadow); }
.choice[aria-checked="true"] .check { background: var(--accent); border-color: var(--accent); }
.choice[aria-checked="true"] .check::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 3px;
  width: 6px;
  height: 12px;
  border: solid var(--accent-ink);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}

.confirm-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 12px max(var(--gutter), env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  border-top: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.confirm-bar .btn { max-width: 34rem; gap: 0.3em; }
.vote-msg { font-size: 14px; color: var(--danger); text-align: center; }
.vote-msg:empty { display: none; }
.banner { padding: 14px 16px; font-weight: 600; text-align: center; }

/* ---------- display ---------- */
body.display { overflow: hidden; }
.display-app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 3vh;
  padding: 4vh 4vw;
}
.display-head { display: flex; align-items: center; gap: 1.6vw; }
.display-head .brand-mark { width: clamp(32px, 3vw, 56px); height: auto; flex: none; }
.display-head .question { font: 700 clamp(32px, 4.2vw, 72px)/1.15 var(--font-round); }
.display-app[data-layout="corners"] .display-head .question { visibility: hidden; }
.display-main { flex: 1; min-height: 0; }
.display-main .layout { height: 100%; }
.display .opt-label { font-size: clamp(20px, 2.2vw, 40px); }
.display .opt-value { font-size: clamp(28px, 3.2vw, 56px); }

/* QR lives inside the layout; each layout CSS file places it. */
.display-app { --qr: min(30vh, 20vw); }
.layout-question { display: none; }
.voter .layout-center { display: none; }
.qr-panel {
  padding: 18px;
  border-radius: 24px;
  background: #FFFFFF;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
}
.qr-panel img { width: var(--qr); height: auto; image-rendering: pixelated; }
.qr-visible .qr-panel { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .qr-panel { transition: opacity 0.4s ease, transform 0.4s ease; }
  .display-app { transition: padding-right 0.5s ease; }
}
.conn-pill {
  position: fixed;
  top: 12px;
  right: 12px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .opt-bar, .opt-media { transition: none !important; }
}

/* ---------- image motion (Controller toggle, adds .motion to the layout) ----------
   Animates the element inside .opt-media because layouts already transform .opt-media.
   Float uses `translate`, breathe uses `scale` and the reveal pop uses `transform`, so all
   three combine. Float and breathe run on different periods so motion never looks looped. */
.opt-pos-1 { --fd: 0s; }
.opt-pos-2 { --fd: -0.9s; }
.opt-pos-3 { --fd: -1.8s; }
.opt-pos-4 { --fd: -2.7s; }
@media (prefers-reduced-motion: no-preference) {
  .layout.motion .opt-media > * {
    animation: ivgo-float 3.6s ease-in-out infinite, ivgo-breathe 5.2s ease-in-out infinite;
    animation-delay: var(--fd), calc(var(--fd) * 1.7);
  }
  .layout.motion.results-visible .opt-media > * {
    animation: ivgo-float 3.6s ease-in-out infinite, ivgo-breathe 5.2s ease-in-out infinite,
      ivgo-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    animation-delay: var(--fd), calc(var(--fd) * 1.7), 0s;
  }
  /* Only the leader (or tied leaders) glows; without a frame the glow follows the image's shape. */
  .layout.motion.results-visible .opt.is-leader .opt-media > * {
    animation: ivgo-float 3.6s ease-in-out infinite, ivgo-breathe 5.2s ease-in-out infinite,
      ivgo-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both, ivgo-glow 4.5s ease-in-out infinite;
    animation-delay: var(--fd), calc(var(--fd) * 1.7), 0s, 0.7s;
  }
  .layout.motion.no-frame.results-visible .opt.is-leader .opt-media > * {
    animation: ivgo-float 3.6s ease-in-out infinite, ivgo-breathe 5.2s ease-in-out infinite,
      ivgo-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both, ivgo-glow-drop 4.5s ease-in-out infinite;
    animation-delay: var(--fd), calc(var(--fd) * 1.7), 0s, 0.7s;
  }
}
/* Each layout sets --float: along the bar for bar layouts, none for corners. */
@keyframes ivgo-float {
  0%, 100% { translate: 0 0; }
  50% { translate: var(--float, 0 0); }
}
@keyframes ivgo-breathe {
  0%, 100% { scale: 1; }
  50% { scale: 1.04; }
}
@keyframes ivgo-pop {
  from { transform: scale(0.8); }
  to { transform: none; }
}
@keyframes ivgo-glow {
  0%, 100% { box-shadow: 0 0 12px var(--c); }
  50% { box-shadow: 0 0 28px var(--c); }
}
@keyframes ivgo-glow-drop {
  0%, 100% { filter: drop-shadow(0 0 6px var(--c)); }
  50% { filter: drop-shadow(0 0 16px var(--c)); }
}
