:root {
  --bg: #1b1464;
  --bg-deep: #120d47;
  --surface: #ffffff;
  --ink: #333;
  --muted: #6b7280;
  --brand: #46178f;
  --brand-soft: #7b4fd0;
  --ok: #26890c;
  --bad: #e21b3c;
  --warn: #ffa602;
  --a0: #e21b3c;
  --a1: #1368ce;
  --a2: #ffa602;
  --a3: #26890c;
  --a4: #7b4fd0;
  --a5: #00a2a8;
  --a6: #d1740f;
  --a7: #3c7ac2;
  --radius: 14px;
  --shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--surface);
  min-height: 100%;
}

body { -webkit-text-size-adjust: 100%; }

a { color: #cbb3ff; }

h1, h2, h3 { margin: 0 0 0.4em; line-height: 1.2; font-weight: 800; }

button {
  font-family: inherit;
  font-weight: 700;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.8em 1.2em;
  font-size: 1rem;
  background: var(--brand-soft);
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform 0.06s ease, filter 0.12s ease;
}
button:hover:not(:disabled) { filter: brightness(1.1); }
button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18); }
button:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

button.primary { background: var(--ok); }
button.danger { background: var(--bad); }
button.ghost { background: rgba(255, 255, 255, 0.16); box-shadow: none; }
button.big { font-size: 1.35rem; padding: 1em 1.4em; width: 100%; }
button.block { width: 100%; }

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.7em 0.85em;
  border-radius: 10px;
  border: 2px solid #d8d8e8;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 3px solid #b79cff; border-color: var(--brand-soft); }
textarea { resize: vertical; min-height: 3.2em; }

label { display: block; font-size: 0.86rem; font-weight: 700; margin-bottom: 0.3em; opacity: 0.9; }

.screen { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 0; }
.row.tight { gap: 0.4rem; }
.row.auto > * { flex: 0 0 auto; }
.stack { display: flex; flex-direction: column; gap: 0.9rem; }

.card {
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  padding: 1.1rem;
}
.card.light { background: var(--surface); color: var(--ink); border: 0; }

.muted { opacity: 0.72; font-weight: 500; }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }
.mono { font-variant-numeric: tabular-nums; }

.topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 1.1rem; background: var(--bg-deep);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.topbar .spacer { flex: 1 1 auto; }
.topbar a, .topbar button { font-size: 0.9rem; padding: 0.5em 0.8em; }

.pin-display {
  font-size: clamp(3rem, 14vw, 7rem);
  font-weight: 900; letter-spacing: 0.08em; line-height: 1;
  color: #fff; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

.pill {
  display: inline-block; padding: 0.25em 0.7em; border-radius: 999px;
  background: rgba(255, 255, 255, 0.18); font-size: 0.78rem; font-weight: 700;
}
.pill.ok { background: var(--ok); }
.pill.bad { background: var(--bad); }
.pill.warn { background: var(--warn); color: #3a2a00; }

/* Answer buttons — the thing players touch most, so make them enormous. */
.answers { display: grid; gap: 0.7rem; grid-template-columns: 1fr; }
.answers.two { grid-template-columns: 1fr 1fr; }
.answer {
  min-height: 96px; border-radius: var(--radius); border: 0; color: #fff;
  font-size: clamp(1rem, 3.4vw, 1.5rem); font-weight: 800; padding: 0.9em;
  display: flex; align-items: center; justify-content: center; text-align: center;
  box-shadow: var(--shadow); line-height: 1.25; word-break: break-word;
}
.answer.a0 { background: var(--a0); } .answer.a1 { background: var(--a1); }
.answer.a2 { background: var(--a2); } .answer.a3 { background: var(--a3); }
.answer.a4 { background: var(--a4); } .answer.a5 { background: var(--a5); }
.answer.a6 { background: var(--a6); } .answer.a7 { background: var(--a7); }
.answer.selected { outline: 5px solid #fff; outline-offset: -5px; transform: scale(0.985); }
.answer.picked-correct { box-shadow: 0 0 0 6px #6cf78a, var(--shadow); }
.answer.picked-wrong { box-shadow: 0 0 0 6px #ff8fa3, var(--shadow); opacity: 0.8; }
.answer.is-correct::after { content: " \2713"; }
.answer.is-wrong::after { content: " \2717"; }

.timer-ring {
  width: clamp(84px, 18vw, 132px); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; margin: 0 auto;
  background: conic-gradient(var(--warn) calc(var(--pct, 0) * 1%), rgba(255,255,255,0.16) 0);
  position: relative;
}
.timer-ring::before { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--bg); }
.timer-ring span { position: relative; font-size: 2.1rem; font-weight: 900; }

.prompt {
  font-size: clamp(1.3rem, 4.6vw, 2.4rem); font-weight: 800;
  text-align: center; line-height: 1.3; margin: 0.4rem 0 1rem; word-break: break-word;
}

.player-list { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.player-chip {
  background: rgba(255,255,255,0.16); border-radius: 999px; padding: 0.4em 0.9em;
  font-weight: 700; font-size: 0.95rem; display: flex; align-items: center; gap: 0.4em;
}
.player-chip.offline { opacity: 0.45; text-decoration: line-through; }

.leaderboard { width: 100%; border-collapse: collapse; font-size: 1.05rem; }
.leaderboard td, .leaderboard th { padding: 0.5em 0.6em; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.14); }
.leaderboard th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.75; }
.leaderboard td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; }
.leaderboard tr.top { background: rgba(255, 215, 0, 0.14); }

.podium { display: flex; align-items: flex-end; justify-content: center; gap: 0.6rem; min-height: 210px; }
.podium .step { flex: 1 1 0; max-width: 210px; text-align: center; border-radius: 12px 12px 0 0; padding-top: 0.8em; color: #fff; font-weight: 800; }
.podium .step .rank { font-size: 2rem; line-height: 1; }
.podium .step .who { font-size: 1rem; padding: 0 0.4em; word-break: break-word; }
.podium .step .pts { font-size: 0.9rem; opacity: 0.9; }
.podium .p1 { background: linear-gradient(180deg, #ffd45e, #e8a900); height: 190px; }
.podium .p2 { background: linear-gradient(180deg, #dfe6f5, #a8b4cc); height: 140px; }
.podium .p3 { background: linear-gradient(180deg, #e6b98a, #b57a45); height: 105px; }

.bars { display: flex; flex-direction: column; gap: 0.45rem; }
.bar-row { display: grid; grid-template-columns: 2.4rem 1fr 3.4rem; gap: 0.55rem; align-items: center; }
.bar-track { background: rgba(255,255,255,0.14); border-radius: 999px; height: 1.5rem; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }
.bar-fill.a0 { background: var(--a0); } .bar-fill.a1 { background: var(--a1); }
.bar-fill.a2 { background: var(--a2); } .bar-fill.a3 { background: var(--a3); }
.bar-fill.a4 { background: var(--a4); } .bar-fill.a5 { background: var(--a5); }
.bar-fill.a6 { background: var(--a6); } .bar-fill.a7 { background: var(--a7); }

.flash { position: fixed; inset: 0; pointer-events: none; z-index: 50; opacity: 0; }
.flash.go { animation: flash 0.5s ease; }
@keyframes flash { 0% { opacity: 0.75; } 100% { opacity: 0; } }
.flash.good { background: var(--ok); }
.flash.bad { background: var(--bad); }

.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%);
  background: #222; color: #fff; padding: 0.7em 1.1em; border-radius: 10px;
  font-weight: 700; z-index: 60; max-width: 90vw; text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.countdown { font-size: clamp(5rem, 30vw, 14rem); font-weight: 900; line-height: 1; }

/* Editor + dashboard run on a light background; they are desktop tools. */
body.light-ui { background: #f3f2f9; color: var(--ink); }
body.light-ui .card { background: #fff; color: var(--ink); border: 1px solid #e2e0ef; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
body.light-ui .topbar { background: var(--brand); color: #fff; border-bottom: 0; }
body.light-ui .topbar button.ghost, body.light-ui .topbar a { background: rgba(255,255,255,0.18); color: #fff; }
body.light-ui .muted { color: var(--muted); opacity: 1; }

.quiz-item { display: flex; align-items: center; gap: 0.8rem; padding: 0.9rem; border-radius: var(--radius); background: #fff; border: 1px solid #e2e0ef; }
.quiz-item .grow { flex: 1 1 auto; min-width: 0; }
.quiz-item .actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.quiz-item button { font-size: 0.85rem; padding: 0.5em 0.8em; box-shadow: none; }

.q-editor { border: 1px solid #e2e0ef; border-radius: var(--radius); background: #fff; padding: 1rem; }
.q-editor.invalid { border-color: var(--bad); }
.q-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.7rem; flex-wrap: wrap; }
.q-head .num { font-weight: 900; font-size: 1.1rem; color: var(--brand); }
.q-head .grow { flex: 1 1 auto; }
.q-head button { font-size: 0.8rem; padding: 0.4em 0.7em; box-shadow: none; background: #ece9f7; color: var(--brand); }
.q-head button.danger { background: #fde3e7; color: var(--bad); }

.answer-edit { display: grid; grid-template-columns: 2.2rem 1fr 1fr auto; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.answer-edit .swatch { width: 100%; aspect-ratio: 1; border-radius: 8px; }
.answer-edit .swatch.a0 { background: var(--a0); } .answer-edit .swatch.a1 { background: var(--a1); }
.answer-edit .swatch.a2 { background: var(--a2); } .answer-edit .swatch.a3 { background: var(--a3); }
.answer-edit .swatch.a4 { background: var(--a4); } .answer-edit .swatch.a5 { background: var(--a5); }
.answer-edit .swatch.a6 { background: var(--a6); } .answer-edit .swatch.a7 { background: var(--a7); }
.answer-edit .correct-toggle { font-size: 0.8rem; padding: 0.5em 0.7em; box-shadow: none; background: #eee; color: #666; white-space: nowrap; }
.answer-edit .correct-toggle.on { background: var(--ok); color: #fff; }

table.report { width: 100%; border-collapse: collapse; background: #fff; color: var(--ink); }
table.report th, table.report td { padding: 0.5em 0.6em; border-bottom: 1px solid #eee; text-align: left; font-size: 0.92rem; }
table.report th { background: #f6f5fb; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
table.report td.num, table.report th.num { text-align: right; font-variant-numeric: tabular-nums; }
.diff-bad { color: var(--bad); font-weight: 800; }
.diff-mid { color: var(--warn); font-weight: 800; }
.diff-good { color: var(--ok); font-weight: 800; }

.lang-switch { display: flex; gap: 0.35rem; }
.lang-switch button { padding: 0.45em 0.9em; font-size: 0.9rem; box-shadow: none; background: rgba(255,255,255,0.16); }
.lang-switch button.on { background: #fff; color: var(--brand); }
body.light-ui .lang-switch button { background: #e6e3f2; color: var(--brand); }
body.light-ui .lang-switch button.on { background: var(--brand); color: #fff; }

/* I6: big-font mode for a large room or a trainer who wants to read the laptop from a distance. */
body.big-font { font-size: 125%; }
body.big-font .prompt { font-size: clamp(1.8rem, 5vw, 3rem); }

.confetti { position: fixed; top: -12px; width: 10px; height: 16px; z-index: 40; pointer-events: none; }

@media (max-width: 620px) {
  .screen { padding: 0.8rem; }
  .answer-edit { grid-template-columns: 1.8rem 1fr auto; }
  .answer-edit .fr-input { grid-column: 2 / 4; }
  .podium .step .who { font-size: 0.85rem; }
}
