:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --ink: #1b2233;
  --muted: #5b6579;
  --line: #d8dee8;
  --primary: #2350c8;
  --primary-soft: #e4ebfb;
  --live: #0d7f57;
  --live-soft: #ddf3ea;
  --danger: #b42318;
  --radius-panel: 14px;
  --radius-ctl: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
.wrap { max-width: 620px; margin: 0 auto; padding: 14px 14px 64px; display: grid; gap: 12px; }
section:empty { display: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.15rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; margin-bottom: 10px; }
h3 { font-size: 0.98rem; font-weight: 600; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.note { background: #fff6e0; border-radius: var(--radius-ctl); padding: 8px 10px; font-size: 0.9rem; }
.note.error { background: #fdecea; color: var(--danger); }
.ok { color: var(--live); }
.eyebrow { font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; }
code.key { background: var(--bg); padding: 2px 6px; border-radius: 4px; user-select: all; word-break: break-all; }

/* header */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.brand .code { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }
.brand .code strong { color: var(--ink); letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-panel); padding: 16px; }
.panel.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.panel.quiet { background: transparent; border-style: dashed; padding: 10px 14px; }
.panel.quiet summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.panel.quiet[open] summary { margin-bottom: 8px; }
.panel.live { border-color: var(--live); box-shadow: inset 4px 0 0 var(--live); }
.start h2 { font-size: 1.2rem; }
.start .btn.primary { margin: 6px 0 14px; }
.join .inline { margin-top: 4px; }

/* controls */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; padding: 9px 14px; border-radius: var(--radius-ctl); cursor: pointer;
}
.btn:hover { border-color: #b8c2d3; }
.btn.sm { padding: 6px 10px; font-size: 0.86rem; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1c43ad; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.link { border: 0; background: none; padding-left: 4px; padding-right: 4px; color: var(--primary); }
.btn.danger-text { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
:focus-visible { outline: 3px solid #8fb0ff; outline-offset: 2px; }

input[type="text"], input:not([type]), textarea {
  font: inherit; color: inherit; width: 100%; border: 1px solid var(--line); border-radius: var(--radius-ctl);
  padding: 9px 11px; background: #fff;
}
textarea { resize: vertical; }
.field { display: grid; gap: 6px; margin: 0 0 14px; border: 0; padding: 0; }
.field > span, legend { font-size: 0.88rem; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 6px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; min-width: 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check.field { margin-bottom: 4px; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-ctl); padding: 3px; gap: 3px; background: var(--bg); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; font: inherit; font-size: 0.9rem; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }

/* option tokens: the number is the identity of every option, everywhere */
.num {
  flex: none; display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px;
  border-radius: 7px; background: var(--primary-soft); color: var(--primary); font-weight: 700;
  font-variant-numeric: tabular-nums; font-size: 0.9rem;
}
.opts { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.opt { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius-ctl); }
.opt .txt { flex: 1; overflow-wrap: anywhere; }
.opt .x { border: 0; background: none; font-size: 1.2rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.opt .x:hover { color: var(--danger); background: #fdecea; }
.opt.person .check { flex: 1; }
.people-tools { margin: -4px 0 10px; }
.add { margin-bottom: 8px; }
.paste { margin: 6px 0; }
.paste summary { cursor: pointer; color: var(--primary); font-size: 0.9rem; }
.paste textarea { margin: 8px 0; }

/* ballot */
.q { overflow-wrap: anywhere; }
.ballot .q { font-size: 1.12rem; margin-bottom: 4px; }
.choices { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1.5px solid var(--line);
  border-radius: 10px; cursor: pointer; position: relative;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .txt { flex: 1; overflow-wrap: anywhere; }
.choice:hover { border-color: #aebbd2; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice:has(input:checked) .num { background: var(--primary); color: #fff; }
.choice:has(input:focus-visible) { outline: 3px solid #8fb0ff; outline-offset: 2px; }
.choice:has(input:disabled) { cursor: not-allowed; opacity: 0.6; }

/* chips */
.chip { flex: none; font-size: 0.78rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.chip.open { background: var(--live-soft); color: var(--live); }
.chip.shown { background: var(--primary-soft); color: var(--primary); }
.live-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }

/* bars */
.bars { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 10px; }
.bar-head { display: flex; align-items: center; gap: 10px; }
.bar-head .txt { flex: 1; overflow-wrap: anywhere; }
.bar-head .val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-head .val small { font-weight: 500; color: var(--muted); margin-left: 4px; }
.track { height: 10px; background: var(--bg); border-radius: 999px; margin: 6px 0 0 38px; overflow: hidden; }
.fill { height: 100%; background: #9fb4e6; border-radius: 999px; }
.lead .fill { background: var(--primary); }
.lead .num { background: var(--primary); color: #fff; }
.who { font-size: 0.84rem; color: var(--muted); margin: 4px 0 0 38px; }
.live > .who { margin-left: 0; }

/* The reveal: bars grow from zero the first time results appear. */
.grow .fill { transform-origin: left; animation: grow 900ms cubic-bezier(.2,.7,.2,1) both; }
.grow li:nth-child(2) .fill { animation-delay: 80ms; }
.grow li:nth-child(3) .fill { animation-delay: 160ms; }
.grow li:nth-child(4) .fill { animation-delay: 240ms; }
.grow li:nth-child(n+5) .fill { animation-delay: 320ms; }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.results .result + .result { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }

/* history */
.history { list-style: none; margin: 0; padding: 0; }
.poll { padding: 12px 0; border-top: 1px solid var(--line); }
.poll:first-child { border-top: 0; padding-top: 0; }
.poll-head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.poll .actions { margin-top: 6px; }
.summary { margin-top: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.82rem; }

/* status + toast */
.status { display: none; position: sticky; top: 0; z-index: 5; background: #fff6e0; color: #6b4e00; text-align: center; padding: 6px; font-size: 0.86rem; }
.status.show { display: block; }
.toast {
  position: fixed; left: 50%; bottom: 16px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 0.9rem; max-width: calc(100% - 32px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

@media (max-width: 420px) {
  .wrap { padding: 10px 10px 56px; }
  .panel { padding: 14px; }
  .inline { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  .grow .fill { animation: none; }
  .toast { transition: none; }
}

.sel-all { margin: 0 0 6px; }
