:root {
  --navy: #101c3a;
  --blue: #1a3ea8;
  --blue-deep: #14328a;
  --blue-bright: #2e6bf0;
  --blue-soft: #eef3fc;
  --blue-line: #d6e0f5;
  --lime: #c8df3b;
  --lime-dark: #9db51a;
  --text: #17213a;
  --muted: #5b6680;
  --bg: #ffffff;
  --card: #f4f7fd;
  --danger: #c0392b;
  --ok: #1e8e4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 28, 58, 0.06), 0 8px 24px rgba(16, 28, 58, 0.06);
  --font: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.4;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.15; }
p { margin: 0; }
[hidden] { display: none !important; }

/* ---- brand bits ------------------------------------------------------------ */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-weight: 600;
  color: var(--navy);
  letter-spacing: -0.01em;
}
.brand-dot {
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  background: conic-gradient(from 200deg, #2e6bf0, #c8df3b, #1a3ea8, #6fcf5a, #2e6bf0);
}
.eyebrow {
  font-size: 0.78em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--blue-bright);
}
.muted { color: var(--muted); }
.lime-bar {
  display: inline-block;
  width: 5em;
  height: 0.5em;
  border-radius: 999px;
  background: var(--lime);
}
.pill {
  display: inline-block;
  padding: 0.2em 0.7em;
  border-radius: 999px;
  font-size: 0.75em;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--blue-soft);
  color: var(--blue);
}
.pill.open { background: var(--lime); color: var(--navy); }
.pill.closed { background: var(--navy); color: #fff; }
.pill.none { background: transparent; color: var(--muted); border: 1px solid var(--blue-line); }

/* ---- buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.75em 1.25em;
  border-radius: 999px;
  border: 2px solid transparent;
  background: var(--blue);
  color: #fff;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
  min-height: 44px;
}
.btn:hover { background: var(--blue-deep); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--blue); border-color: var(--blue-line); }
.btn.secondary:hover { background: var(--blue-soft); }
.btn.lime { background: var(--lime); color: var(--navy); }
.btn.lime:hover { background: #d7ea57; }
.btn.danger { background: #fff; color: var(--danger); border-color: #f1c9c4; }
.btn.danger:hover { background: #fdf1ef; }
.btn.block { width: 100%; }
.btn.small { padding: 0.45em 0.9em; min-height: 34px; font-size: 0.9em; }

/* ---- form controls -------------------------------------------------------- */
.input, textarea.input {
  width: 100%;
  padding: 0.8em 1em;
  border: 2px solid var(--blue-line);
  border-radius: 12px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease;
}
.input:focus, textarea.input:focus { border-color: var(--blue-bright); }
textarea.input { min-height: 6em; resize: vertical; }
.field { display: grid; gap: 0.4em; }
.field label { font-weight: 600; font-size: 0.95em; }

/* ---- cards ---------------------------------------------------------------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25em;
}
.card.white { background: #fff; box-shadow: var(--shadow); }
.card.blue { background: var(--blue); color: #fff; }
.card.blue .muted { color: rgba(255, 255, 255, 0.75); }

/* ---- results: horizontal bars --------------------------------------------- */
.bars { display: grid; gap: 0.7em; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35em 0.8em;
  align-items: center;
}
.bar-label { font-weight: 600; grid-column: 1; }
.bar-n { grid-column: 2; grid-row: 1 / span 2; font-weight: 700; color: var(--blue); font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }
.bar-track { grid-column: 1; height: 0.9em; border-radius: 999px; background: var(--blue-line); overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 999px; background: var(--blue-bright); transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.bar-row.winner .bar-fill { background: var(--lime); }
.bar-row.winner .bar-n { color: var(--navy); }
.bar-row.mine .bar-label::after { content: ' · you'; color: var(--blue-bright); font-weight: 700; font-size: 0.85em; }

/* ---- results: scale ------------------------------------------------------- */
.scale-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.3em 1em; align-items: center; }
.scale-row .bar-label { grid-column: 1; grid-row: 1; }
.scale-row .scale-dist { grid-column: 1; grid-row: 2; }
.scale-avg { font-size: 1.6em; font-weight: 700; color: var(--blue); font-variant-numeric: tabular-nums; grid-column: 2; grid-row: 1 / span 2; min-width: 3.2em; text-align: right; }
.scale-avg small { font-size: 0.5em; color: var(--muted); font-weight: 600; }
.scale-dist { display: flex; gap: 0.25em; }
.scale-dist span { flex: 1; height: 0.5em; border-radius: 999px; background: var(--blue-line); position: relative; overflow: hidden; }
.scale-dist span i { position: absolute; inset: 0; width: 0; background: var(--blue-bright); border-radius: 999px; transition: width 0.5s ease; }

/* ---- results: histogram --------------------------------------------------- */
.hist { display: grid; grid-template-columns: repeat(10, 1fr); gap: 0.4em; align-items: end; height: 12em; }
.hist-col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 0.3em; font-size: 0.8em; color: var(--muted); }
.hist-bar { width: 100%; height: 0; border-radius: 6px 6px 3px 3px; background: var(--blue-bright); transition: height 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); position: relative; }
.hist-bar[data-n]:not([data-n='0'])::after { content: attr(data-n); position: absolute; top: -1.5em; left: 0; right: 0; text-align: center; font-weight: 700; color: var(--text); }
.hist-col.answer .hist-bar { background: var(--lime); }
.hist-col.answer .hist-label { color: var(--navy); font-weight: 700; }
.hist-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.answer-big { font-size: 3.2em; font-weight: 800; color: var(--blue); line-height: 1; letter-spacing: -0.02em; }
.answer-big small { font-size: 0.4em; color: var(--muted); font-weight: 600; }

/* ---- results: open answers ----------------------------------------------- */
.wall { columns: 1; column-gap: 1em; }
.wall .note { break-inside: avoid; margin-bottom: 1em; background: #fff; border-radius: 12px; padding: 0.9em 1em; box-shadow: var(--shadow); display: grid; gap: 0.5em; border-left: 4px solid var(--blue-line); }
.wall .note.top { border-left-color: var(--lime); }
.wall .note.fresh { animation: pop 0.4s ease; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.note-meta { display: flex; justify-content: space-between; align-items: center; gap: 0.5em; font-size: 0.85em; color: var(--muted); }
.vote {
  display: inline-flex; align-items: center; gap: 0.35em;
  padding: 0.3em 0.75em; border-radius: 999px; border: 2px solid var(--blue-line);
  background: #fff; font-weight: 700; color: var(--blue); min-height: 34px;
}
.vote.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.vote.static { border-color: transparent; background: var(--blue-soft); }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- results: word cloud -------------------------------------------------- */
.cloud { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.3em 0.9em; line-height: 1.1; }
.cloud span { font-weight: 700; color: var(--blue-bright); white-space: nowrap; transition: font-size 0.4s ease; }
.cloud span:nth-child(3n) { color: var(--blue); }
.cloud span:nth-child(5n) { color: var(--lime-dark); }
.cloud span:nth-child(7n) { color: var(--navy); }

/* ---- leaderboard ---------------------------------------------------------- */
.lb { display: grid; gap: 0.5em; counter-reset: rank; }
.lb-row { display: grid; grid-template-columns: 2.2em minmax(0, 1fr) auto; gap: 0.8em; align-items: center; background: #fff; border-radius: 12px; padding: 0.7em 1em; box-shadow: var(--shadow); }
.lb-row.me { outline: 2px solid var(--blue-bright); }
.lb-rank { font-weight: 800; color: var(--blue); font-size: 1.2em; text-align: center; }
.lb-row:nth-child(1) .lb-rank { color: var(--lime-dark); }
.lb-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--navy); }

/* ---- misc ----------------------------------------------------------------- */
.timer { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--blue); }
.timer.urgent { color: var(--danger); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }
.toast {
  position: fixed; left: 50%; bottom: 1.5em; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 0.7em 1.2em; border-radius: 999px;
  font-weight: 600; box-shadow: var(--shadow); opacity: 0; transition: opacity 0.2s ease; pointer-events: none; z-index: 10; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }
.qr svg { display: block; width: 100%; height: auto; }
.empty { color: var(--muted); font-style: italic; }
.row { display: flex; flex-wrap: wrap; gap: 0.6em; align-items: center; }
.grow { flex: 1; }
