:root {
  --ink: #14233c;
  --ink-soft: #4a5a74;
  --muted: #7a8699;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --line: #dde3ee;
  --blue: #1f5fd1;
  --blue-dark: #174aa6;
  --light-blue: #cfe6ff;
  --light-blue-ink: #0f2f5c;
  --green: #1c8a4a;
  --green-bg: #e3f5ea;
  --red: #c6352c;
  --red-bg: #fbe7e5;
  --gray: #9aa3ae;
  --gold: #c9a227;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 35, 60, .06), 0 8px 24px rgba(20, 35, 60, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
[hidden] { display: none !important; }
a { color: var(--blue); }
h1, h2, h3 { line-height: 1.15; margin: 0; }

/* ---------- Buttons & forms ---------- */
.btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 12px 20px;
  font: 600 1rem/1.2 var(--font);
  cursor: pointer;
  transition: background-color .15s, transform .05s, opacity .15s;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: .55; }
.btn:focus-visible, input:focus-visible { outline: 3px solid #9cc2ff; outline-offset: 2px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-secondary { background: #e7ecf5; color: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: #dbe2ef; }
.btn-danger { background: var(--red); color: #fff; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--blue); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

label { display: block; font-weight: 600; font-size: .95rem; margin-bottom: 16px; }
input[type=text], input[type=password] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  font: 1.05rem var(--font);
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
input:focus { border-color: var(--blue); outline: none; }
.hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
.error { color: var(--red); font-weight: 600; min-height: 1.4em; margin: 0 0 12px; }
.notice {
  background: #fff8e1;
  border: 1px solid #f0dc9c;
  color: #6b5510;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0 0 18px;
  font-size: .95rem;
}
.muted { color: var(--muted); }

/* ---------- Centered card pages (sign-in, admin) ---------- */
.card-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, #dcebff 0%, var(--bg) 60%);
}
.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.brand { text-align: center; margin-bottom: 24px; font-family: var(--serif); font-weight: 700; }
.brand small { display: block; font: 600 .8rem var(--font); letter-spacing: .16em; text-transform: uppercase; color: var(--blue); margin-bottom: 6px; }
.brand span { display: block; font-size: 2rem; color: var(--ink); }
.card h2 { font-size: 1.2rem; margin-bottom: 14px; }
.footer-links { margin-top: 20px; font-size: .95rem; color: var(--muted); }
.footer-links a { margin: 0 6px; }

.status-box {
  background: #f1f5fc;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
}
.status-box dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.status-box dt { color: var(--muted); }
.status-box dd { margin: 0; font-weight: 600; word-break: break-word; }
.stack > * + * { margin-top: 10px; }

/* ---------- Connection indicator ---------- */
.conn-pill {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: .9rem;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 50;
}

/* ---------- Host page ---------- */
.host-page { background: var(--surface); transition: background-color .2s; }
.host-top { transition: background-color .2s; }
.host-page.has-buzz,
.host-page.has-buzz .host-top { background: #FFA500; }
.host-top {
  background: var(--light-blue);
  color: var(--light-blue-ink);
  min-height: 33.333vh;
  padding: 16px clamp(16px, 4vw, 48px) 24px;
  display: flex;
  flex-direction: column;
}
.host-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: .9rem;
  color: #35557f;
}
.host-meta .spacer { flex: 1; }
.host-meta b { color: var(--light-blue-ink); }
.question-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding-top: 12px;
}
.q-ref {
  margin: 0 0 6px;
  font-weight: 700;
  font-size: .85rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #2d5d9c;
}
.q-text {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.25rem, 2.6vw, 2rem);
  line-height: 1.3;
}
.q-choices {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}
.q-choices li {
  background: rgba(255, 255, 255, .6);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: clamp(1rem, 1.6vw, 1.2rem);
}
.q-choices li b { color: #2d5d9c; margin-right: 6px; }
.q-answer {
  margin: 16px 0 0;
  padding: 12px 16px;
  background: #fff;
  border-radius: 12px;
  border-left: 6px solid var(--blue);
  font-size: clamp(1.1rem, 2vw, 1.5rem);
  font-weight: 700;
  color: var(--ink);
}
.q-answer .label {
  display: block;
  font: 700 .75rem var(--font);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.host-bottom {
  min-height: 66.667vh;
  padding: 28px clamp(16px, 4vw, 48px) 48px;
  max-width: 1100px;
  margin: 0 auto;
}
.btn-medium { font-size: 1.15rem; padding: 14px 28px; border-radius: 12px; }
.host-bottom h2 { margin: 28px 0 12px; font-size: 1.3rem; }
.buzz-list { list-style: none; margin: 0; padding: 0; }
.buzz-list li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 10px;
  background: #fff;
  animation: pop-in .18s ease-out;
}
.buzz-list li.first { border-color: #9cc2ff; background: #f3f8ff; }
.buzz-order {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--light-blue);
  color: var(--light-blue-ink);
  font-weight: 800;
}
.buzz-name { flex: 1 1 140px; font-size: 1.15rem; font-weight: 700; word-break: break-word; }
.buzz-name small { font-weight: 500; color: var(--muted); margin-left: 6px; }
.buzz-actions { display: flex; gap: 8px; }
.btn-correct { background: var(--green); color: #fff; }
.btn-incorrect { background: var(--red); color: #fff; }
.verdict { font-weight: 700; padding: 6px 12px; border-radius: 999px; font-size: .95rem; }
.verdict.correct { background: var(--green-bg); color: var(--green); }
.verdict.incorrect { background: var(--red-bg); color: var(--red); }
.verdict.bonus { background: #fdf3d3; color: #8a6a00; }
.btn-bonus { background: var(--gold); color: #fff; }
.btn-bonus:hover:not(:disabled) { background: #b08c1c; }
.btn-cancel { background: transparent; color: var(--ink-soft); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-cancel:hover:not(:disabled) { background: #f1f4f9; color: var(--ink); }
.buzz-actions { align-items: center; flex-wrap: wrap; }
.buzz-actions .btn { white-space: nowrap; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(244, 246, 251, .96);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 40;
}
.overlay .card { text-align: center; }

@keyframes pop-in { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Player page ---------- */
.player-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #eef4ff 0%, var(--bg) 100%);
  overscroll-behavior: none;
}
.player-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line);
}
.pb-name { flex: 1; min-width: 0; font-size: 1.25rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-stats { display: flex; gap: 10px; }
.pb-stat {
  min-width: 72px;
  text-align: center;
  background: #f1f5fc;
  border-radius: 10px;
  padding: 6px 10px;
}
.pb-stat .label { display: block; font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.pb-stat .value { display: block; font-size: 1.35rem; font-weight: 800; line-height: 1.1; }
.pb-stat .of { font-size: .75rem; font-weight: 600; color: var(--muted); }
#accuracy-detail { display: block; line-height: 1.1; }
#accuracy-detail:empty { display: none; }
/* Three stat boxes beside the name: keep them compact on phones. */
@media (max-width: 420px) {
  .player-bar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .pb-stats { gap: 6px; }
  .pb-stat { min-width: 0; padding: 6px 8px; }
  .pb-name { font-size: 1.1rem; }
}
.buzz-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.buzz {
  width: min(78vw, 58vh, 380px);
  width: min(78vw, 58dvh, 380px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 35% 30%, #4b8bff 0%, var(--blue) 55%, #1747a0 100%);
  color: #fff;
  font: 800 clamp(2.4rem, 12vw, 4.2rem)/1 var(--font);
  letter-spacing: .02em;
  box-shadow: 0 10px 0 #123a85, 0 18px 40px rgba(31, 95, 209, .35);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform .06s, box-shadow .06s, background .2s;
}
.buzz:active:not(:disabled) { transform: translateY(8px); box-shadow: 0 2px 0 #123a85, 0 8px 20px rgba(31, 95, 209, .3); }
.buzz:disabled { cursor: default; }
.buzz.buzzed {
  background: var(--gray);
  box-shadow: 0 4px 0 #7d858f;
  transform: translateY(6px);
  font-size: clamp(2rem, 10vw, 3.4rem);
}
.buzz.waiting { background: #b9c6db; box-shadow: 0 6px 0 #97a5bc; }
.player-footer {
  text-align: center;
  padding: 0 16px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.quit-link { color: var(--muted); font-size: .95rem; padding: 10px 14px; }

/* ---------- Leaderboard ---------- */
.board-page { background: #0f1d33; color: #fff; min-height: 100vh; }
.board-page.inactive { background: #fff; }
.board {
  max-width: 900px;
  margin: 0 auto;
  padding: clamp(20px, 5vw, 56px) 16px;
}
.board h1 { text-align: center; font-family: var(--serif); font-size: clamp(1.8rem, 5vw, 3rem); }
.board .sub { text-align: center; color: #9fb3d1; letter-spacing: .16em; text-transform: uppercase; font-size: .85rem; font-weight: 700; margin: 0 0 8px; }
.board-list { list-style: none; margin: 28px 0 0; padding: 0; }
.board-row {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, .06);
  border-radius: 14px;
  font-size: clamp(1.1rem, 3vw, 1.6rem);
}
.board-rank { font-weight: 800; color: #9fb3d1; }
.board-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.board-score small { font-size: .6em; font-weight: 600; color: #9fb3d1; margin-left: 4px; }
.board-row.rank-1 { background: linear-gradient(90deg, rgba(201, 162, 39, .35), rgba(201, 162, 39, .1)); }
.board-row.rank-1 .board-rank { color: #f3d36b; }
.board-row.rank-2 .board-rank { color: #dfe6ef; }
.board-row.rank-3 .board-rank { color: #e0a36b; }
.board-empty { text-align: center; color: #9fb3d1; margin-top: 40px; font-size: 1.2rem; }

/* Two halves: rankings on the left, buzzed-in players on the right (stacked on narrow screens). */
.board-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
}
.board-split .board { max-width: none; width: 100%; padding-left: clamp(16px, 3vw, 40px); padding-right: clamp(16px, 3vw, 40px); }
.board-buzzed { border-left: 1px solid rgba(255, 255, 255, .12); background: rgba(255, 255, 255, .03); }
.board-buzzed .board-row { grid-template-columns: 64px 1fr auto auto; animation: pop-in .18s ease-out; }
.board-gap { font-size: .75em; font-weight: 700; color: #9fb3d1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.board-buzzed .board-row.first { background: rgba(255, 165, 0, .3); }
.board-buzzed .board-row.first .board-rank { color: #FFA500; }
.board-buzzed .board-row.correct { background: rgba(46, 184, 102, .28); }
.board-buzzed .board-row.incorrect { background: rgba(230, 76, 66, .28); }
.board-verdict {
  font-size: .7em;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.board-verdict.correct { background: #2eb866; color: #fff; }
.board-verdict.incorrect { background: #e64c42; color: #fff; }
.board-verdict.bonus { background: var(--gold); color: #1a1405; }
.board-verdicts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
/* Buzz rows wrap the time and badges below the name when space is tight, so names never get squeezed. */
.board-buzzed .board-row { display: flex; flex-wrap: wrap; align-items: center; column-gap: 12px; row-gap: 8px; }
.board-buzzed .board-rank { flex: none; width: 52px; }
.board-buzzed .board-name { flex: 1 1 7em; min-width: 7em; }
.board-buzzed .board-verdicts { margin-left: auto; }
.board-buzzed .board-verdicts:empty { display: none; }
@media (max-width: 760px) {
  .board-split { grid-template-columns: 1fr; min-height: 0; }
  .board-buzzed { border-left: 0; border-top: 1px solid rgba(255, 255, 255, .12); }
}

@media (max-width: 520px) {
  .card { padding: 26px 20px; }
  .buzz-actions { width: 100%; }
  .buzz-actions .btn { flex: 1; }
  .board-row { grid-template-columns: 44px 1fr auto; padding: 12px 14px; }
}
