:root {
  --bg: #fdf6ff;
  --card: #ffffff;
  --ink: #23142f;
  --muted: #6b5a78;
  --brand: #7b2ff7;
  --brand-ink: #ffffff;
  --ok: #138a4b;
  --bad: #c0262d;
  --line: #e5d8f0;
  --opt-a: #e8f0ff; --opt-b: #fff1d6; --opt-c: #e3f8ec; --opt-d: #ffe3ea; --opt-e: #eee6ff; --opt-f: #e0f6fa;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #160d1f; --card: #23162f; --ink: #f6eefc; --muted: #b9a7c9; --brand: #a46bff; --line: #3c2a4d;
    --ok: #4cd38a; --bad: #ff6b72;
    --opt-a: #1f2b45; --opt-b: #3d2f15; --opt-c: #15362a; --opt-d: #40202a; --opt-e: #2d2346; --opt-f: #163a40;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 120px; }
main.wide { max-width: 1100px; }
h1 { font-size: 1.5rem; margin: 0.3em 0; }
h2 { font-size: 1.2rem; margin: 0.8em 0 0.4em; }
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin: 12px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.prompt { font-size: 1.25rem; font-weight: 600; white-space: pre-wrap; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--line); font-size: 0.85rem; }
.pill.ok { background: var(--ok); color: #fff; }
.pill.bad { background: var(--bad); color: #fff; }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer;
}
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.small { min-height: 44px; padding: 6px 12px; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; margin: 8px 0 4px; font-weight: 600; }

.options { display: grid; gap: 10px; }
.option {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  min-height: 60px; font-size: 1.05rem; border-width: 2px;
}
.option .letter {
  flex: 0 0 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  font-weight: 700; background: var(--card); border: 1px solid var(--line);
}
.opt-0 { background: var(--opt-a); } .opt-1 { background: var(--opt-b); } .opt-2 { background: var(--opt-c); }
.opt-3 { background: var(--opt-d); } .opt-4 { background: var(--opt-e); } .opt-5 { background: var(--opt-f); }
.option.selected { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand); }
.option.selected .letter::after { content: " ✓"; }

.slider-value { font-size: 2.6rem; font-weight: 700; text-align: center; margin: 8px 0; }
input[type=range] { width: 100%; height: 44px; accent-color: var(--brand); }
.endpoints { display: flex; justify-content: space-between; gap: 12px; font-size: 0.9rem; color: var(--muted); }
.endpoints span:last-child { text-align: right; }

.order-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.order-item {
  display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 12px;
  background: var(--card); border: 2px solid var(--line); touch-action: none; user-select: none;
}
.order-item.dragging { border-color: var(--brand); opacity: 0.85; }
.order-item .rank { flex: 0 0 32px; font-weight: 700; text-align: center; }
.order-item .text { flex: 1; }
.order-item .handle { cursor: grab; padding: 0 6px; font-size: 1.3rem; color: var(--muted); }
.order-item button { min-width: 44px; padding: 4px; }

.submit-bar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); border-top: 1px solid var(--line);
}
.submit-bar button { width: 100%; max-width: 608px; display: block; margin: 0 auto; font-size: 1.15rem; }

.banner { position: sticky; top: 0; z-index: 5; padding: 10px 16px; text-align: center; font-weight: 600; background: var(--bad); color: #fff; }
.hidden { display: none !important; }
.notice { padding: 10px 14px; border-radius: 12px; background: var(--opt-c); font-weight: 600; }
.answer-box { white-space: pre-wrap; padding: 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }

.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) 2.5em; gap: 8px; align-items: center; }
.bar-label { overflow-wrap: anywhere; }
.bar-track { height: 24px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--muted); }
.bar.correct .bar-fill { background: var(--ok); }
.bar.correct .bar-label { font-weight: 700; color: var(--ok); }
.bar-count { text-align: right; font-weight: 700; }

.leaderboard { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.leaderboard li { display: flex; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.leaderboard .place { width: 2em; font-weight: 700; }
.leaderboard .nick { flex: 1; overflow-wrap: anywhere; }
.leaderboard .points { font-weight: 700; }
.leaderboard .top1 { background: #ffe9a8; color: #3a2a00; }
.leaderboard .top2 { background: #e6e9ef; color: #222; }
.leaderboard .top3 { background: #f3d2b5; color: #3a1d00; }

table { width: 100%; border-collapse: collapse; }
td, th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }

/* Shared display: big type for a TV */
body.display main { max-width: 1400px; font-size: 1.5rem; }
body.display .prompt { font-size: 2.6rem; }
body.display .option { min-height: 90px; font-size: 1.8rem; cursor: default; }
body.display .qr { width: min(42vh, 420px); background: #fff; padding: 12px; border-radius: 16px; }
body.display .code { font-size: 4rem; font-weight: 800; letter-spacing: 0.2em; }
body.display .timer { font-size: 3rem; font-weight: 800; }

@media (prefers-reduced-motion: no-preference) {
  .bar-fill { transition: width 0.6s ease; }
  .option { transition: box-shadow 0.15s; }
}

.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; align-items: end; margin: 16px 0; }
.podium-step { text-align: center; }
.podium-names { font-weight: 700; overflow-wrap: anywhere; }
.podium-points { color: var(--muted); margin-bottom: 4px; }
.podium-block { border-radius: 12px 12px 0 0; display: flex; flex-direction: column; justify-content: center; font-size: 2rem; font-weight: 800; }
.place1 .podium-block, .podium-step:nth-child(2) .podium-block { height: 160px; background: #ffd75e; color: #3a2a00; }
.podium-step:nth-child(1) .podium-block { height: 115px; background: #d9dde5; color: #222; }
.podium-step:nth-child(3) .podium-block { height: 85px; background: #e8b98f; color: #3a1d00; }
body.display .podium-block { font-size: 3.5rem; }
body.display .podium-step:nth-child(2) .podium-block { height: 300px; }
body.display .podium-step:nth-child(1) .podium-block { height: 220px; }
body.display .podium-step:nth-child(3) .podium-block { height: 160px; }
@media (prefers-reduced-motion: no-preference) {
  .podium-block { animation: rise 0.8s ease-out both; }
  @keyframes rise { from { transform: scaleY(0); transform-origin: bottom; } to { transform: scaleY(1); transform-origin: bottom; } }
}

.question-image { display: block; max-width: 100%; max-height: 38vh; margin: 8px auto 12px; border-radius: 12px; object-fit: contain; }
body.display .question-image { max-height: 40vh; }

.card:empty { display: none; }
