:root {
  color-scheme: dark;
  font-family: Inter, "Atkinson Hyperlegible Next", system-ui, sans-serif;
  background: #081938;
  color: #f5f8ff;
  --brand: #003ca6;
  --gold: #ffc735;
  --muted: #b9c9e7;
  --line: #385786;
  --panel: #10284d;
  --tile: #15345e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 86% 0%, #143d82 0, transparent 52%), #081938;
}

.shell { max-width: 1260px; margin: auto; padding: 0 clamp(16px, 4vw, 64px) 48px; }
.site-header {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: clamp(10px, 2vw, 22px);
  color: #fff;
  font-weight: 750;
  text-decoration: none;
  line-height: 1.2;
}
.brand img {
  width: clamp(86px, 13vw, 136px);
  height: auto;
  display: block;
  border-radius: 7px;
}
.brand span { border-inline-start: 1px solid var(--line); padding-inline-start: clamp(10px, 2vw, 22px); }
#connection { color: var(--gold); font-size: .85rem; text-align: end; }
main { padding-top: clamp(22px, 4vw, 54px); }
h1, h2, h3, p { margin: 0 0 .65em; }
h1 { font-size: clamp(1.85rem, 4.3vw, 3.65rem); line-height: 1.1; letter-spacing: -.035em; }
h2 { font-size: clamp(1.25rem, 2.4vw, 1.85rem); line-height: 1.22; }
p { line-height: 1.55; color: var(--muted); }
.eyebrow { color: var(--gold); font-size: .92rem; font-weight: 750; margin-bottom: 14px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(16px, 3vw, 32px);
  margin-bottom: 16px;
}
.narrow { max-width: 590px; margin-inline: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(270px, 100%), 1fr)); gap: 14px; }
.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-block: 16px; }
.option {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--tile);
  padding: 16px;
  text-align: start;
  font-size: inherit;
  color: inherit;
  overflow-wrap: anywhere;
}
.option.selected, .option.correct { border-color: var(--gold); background: #2e3c48; color: #ffe39a; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-block: 12px; }
button, .button {
  font: inherit;
  font-weight: 750;
  color: #101e38;
  background: var(--gold);
  border: 1px solid transparent;
  padding: 11px 17px;
  border-radius: 9px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:disabled { opacity: .48; cursor: default; }
.secondary { background: transparent; color: #eaf1ff; border-color: var(--line); }
.danger { color: #ffd1d5; }
label { display: block; margin: 12px 0 7px; }
input, textarea {
  display: block;
  width: 100%;
  font: inherit;
  color: inherit;
  background: #0a1d3c;
  border: 1px solid #5476a8;
  border-radius: 9px;
  padding: 12px;
}
textarea { resize: vertical; }
form button { margin-top: 12px; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.timer {
  display: inline-block;
  color: var(--gold);
  font-size: clamp(2.2rem, 6vw, 5rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  margin-bottom: 15px;
}
.scoreboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: 8px; }
.score { padding: 12px; background: var(--tile); border-radius: 11px; text-align: center; overflow-wrap: anywhere; }
.score strong { display: block; font-size: 1.5em; color: var(--gold); }
#notice {
  position: fixed;
  bottom: 14px;
  right: 14px;
  left: 14px;
  max-width: 650px;
  margin: auto;
  color: #fff;
  background: #57272e;
  border: 1px solid #f08089;
  border-radius: 10px;
  padding: 12px;
  z-index: 2;
}
.lobby {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(22px, 6vw, 90px);
  border-top: 4px solid var(--gold);
  background: linear-gradient(120deg, var(--brand), #10264d 88%);
}
.lobby-copy > p { max-width: 36ch; font-size: clamp(1rem, 2vw, 1.35rem); color: #e4eeff; }
.lobby-copy .registration-count { margin: 1.5em 0 0; }
.registration-count strong { color: var(--gold); margin-inline-end: .25em; }
.qr { display: block; background: white; width: min(270px, 65vw); height: auto; margin: auto; border-radius: 10px; }
.code { direction: ltr; display: inline-block; font-family: monospace; font-size: 1.15rem; letter-spacing: .1em; color: var(--gold); }
.print-only { display: none; }
[data-role=screen] .shell { max-width: 1600px; }
[data-role=screen] .option { font-size: clamp(1.3rem, 2.7vw, 2.5rem); }
[data-role=screen] h1 { font-size: clamp(2rem, 5.7vw, 5.4rem); max-width: 23ch; }
[data-role=screen] .panel { padding: clamp(18px, 4vw, 52px); }
[data-role=screen] .round-panel { border-top: 4px solid var(--gold); }
[data-role=play] .options { grid-template-columns: 1fr; }
.good { color: #8fe2bb; }
.bad { color: #ffc0c9; }
.answer { white-space: pre-wrap; overflow-wrap: anywhere; }
.captain-name { color: var(--muted); overflow-wrap: anywhere; margin-block: 4px; font-weight: 600; }
.history-heading { margin-top: 1.25em; }
.history-round { border-top: 1px solid var(--line); padding: 12px 0; overflow-wrap: anywhere; }
.history-round summary { cursor: pointer; font-weight: 750; }
.history-round[open] summary { margin-bottom: .65em; }
.grade-correct { --grade-fill: #174636; --grade-border: #59bd97; --grade-ink: #d6faea; }
.grade-incorrect { --grade-fill: #57272e; --grade-border: #f08089; --grade-ink: #ffe0e4; }
button[data-action=grade] { background: var(--grade-fill); border-color: var(--grade-border); color: var(--grade-ink); }
button[data-action=grade][aria-pressed=true] { background: var(--grade-border); color: #101719; box-shadow: inset 0 0 0 2px #101719; }
button[data-action=grade][aria-pressed=true]::after { content: " ✓"; }

@media (max-width: 680px) {
  .lobby { grid-template-columns: 1fr; text-align: center; }
  .lobby-copy > p, [data-role=screen] .lobby h1 { margin-inline: auto; }
  .qr { width: min(220px, 65vw); }
}
@media (max-width: 520px) {
  .site-header { min-height: 65px; }
  .brand { font-size: .92rem; }
  .options { grid-template-columns: 1fr; }
}
@media print {
  body { background: white; color: black; }
  header, main, #notice { display: none; }
  .print-only { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; padding: 10px; }
  .print-only article { border: 1px dashed #333; break-inside: avoid; padding: 20px; }
  .print-only p, .print-only .code { color: black; }
  .print-logo { width: 98px; height: auto; margin-bottom: 10px; }
}

#new-game {
  width: min(420px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: inherit;
}
#new-game::backdrop { background: #030b1bcc; }
#new-game select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #5476a8;
  border-radius: 9px;
  background: #0a1d3c;
  color: inherit;
  font: inherit;
}
#new-game .actions { justify-content: flex-end; margin-bottom: 0; }
#new-game .actions button { margin-top: 0; }
.new-game-note { margin-top: 14px; }

[data-role=screen] .scoreboard {
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: clamp(3px, .7vw, 10px);
}
[data-role=screen] .scoreboard > .score {
  min-width: 0;
  padding: clamp(4px, 1vw, 14px);
  font-size: clamp(.625rem, 1.15vw, 1rem);
}
[data-role=screen] .scoreboard .score p { line-height: 1.3; }

[data-role=screen] .result-round, [data-role=screen] .results-panel {
  padding: clamp(16px, 2vw, 28px);
}
[data-role=screen] .result-round h1 {
  font-size: clamp(1.8rem, 3.9vw, 3.9rem);
  max-width: 35ch;
  margin-bottom: .35em;
}
[data-role=screen] .result-round .option {
  font-size: clamp(1rem, 1.55vw, 1.5rem);
  padding: 9px 14px;
}
[data-role=screen] .result-round .options { margin-bottom: 0; }

[data-role=screen] .results-panel h2 { font-size: clamp(1.1rem, 2vw, 1.65rem); }
[data-role=screen] .results-panel .score p { margin-bottom: .3em; }
[data-role=screen] .results-panel .score strong { font-size: 1.2em; }

.stat-counts { margin: 0; text-align: start; }
.stat-counts > div { display: flex; justify-content: space-between; gap: 6px; padding: 6px 0; }
.stat-counts > div + div { border-top: 1px solid var(--line); }
.stat-counts dt { color: var(--muted); }
.stat-counts dd { margin: 0; font-weight: 750; font-variant-numeric: tabular-nums; }

.score-points > div:first-child { font-weight: 750; }
.score-points > div:first-child dd { color: var(--gold); }
[data-role=screen] .score-points > div { padding-block: 4px; }

#question-editor {
  width: min(1420px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: clamp(12px, 2vw, 24px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: inherit;
}
#question-editor::backdrop { background: #030b1bcc; }
#question-editor-message:empty { display: none; }
.question-table-scroll { overflow: auto; max-height: min(65vh, 680px); }
.question-table { width: 100%; min-width: 940px; border-collapse: collapse; text-align: start; }
.question-table th, .question-table td { padding: 7px; border-bottom: 1px solid var(--line); vertical-align: top; }
.question-table thead th { position: sticky; top: 0; background: var(--panel); text-align: start; }
.question-table th:nth-child(3) { min-width: 225px; }
.question-table input, .question-table textarea, .question-table select { padding: 7px; }
.question-table input[type=checkbox] { width: 1.1rem; height: 1.1rem; margin: 7px auto; accent-color: var(--gold); }
.question-table textarea { min-height: 3.5em; }
.question-table select { border: 1px solid var(--line); border-radius: 7px; background: #0a1d3c; color: inherit; font: inherit; }
#question-editor .actions { justify-content: flex-end; margin-bottom: 0; }
#question-editor .actions button { margin-top: 0; }

[data-role=screen] .winner-panel {
  text-align: center;
  border-top: 4px solid var(--gold);
  padding: clamp(16px, 2.3vh, 30px);
  background: radial-gradient(ellipse at 50% 15%, #214581 0, var(--panel) 62%);
}
.winner-panel .championship-trophy {
  display: block;
  height: clamp(105px, 29vh, 290px);
  width: auto;
  max-width: 100%;
  margin: 0 auto 12px;
  object-fit: contain;
  filter: drop-shadow(0 10px 22px #050d2288);
}
[data-role=screen] .winner-panel h1 {
  color: var(--gold);
  font-size: clamp(1.15rem, 2.4vw, 2.3rem);
  margin: 0 auto .4em;
}
.winners { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px clamp(14px, 3vw, 36px); }
.winner { min-width: 0; max-width: min(100%, 650px); overflow-wrap: anywhere; }
.winner h2 { font-size: clamp(1.55rem, 4vw, 4rem); margin-bottom: .12em; }
.winner p { font-size: clamp(1rem, 1.9vw, 1.55rem); margin-bottom: 0; }
[data-role=screen] .final-results .panel { padding: clamp(10px, 1.8vw, 25px); }
[data-role=screen] .final-results h2 { font-size: clamp(1rem, 1.7vw, 1.5rem); }
@media (max-height: 780px) {
  [data-role=screen] main:has(.winner-panel) { padding-top: 18px; }
  [data-role=screen] .winner-panel { padding-block: 12px; }
  .winner-panel .championship-trophy { height: clamp(90px, 23vh, 175px); margin-bottom: 8px; }
  [data-role=screen] .final-results .score-points > div { padding-block: 3px; }
}

#question-editor .question-editor-tools { justify-content: flex-start; margin-block: 10px; }
.question-table [data-delete-question] { margin: 0; padding: 7px 9px; }

@media (max-width: 960px) {
  .team-scoreboard, [data-role=screen] .team-scoreboard {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-flow: row;
    grid-auto-columns: auto;
    gap: clamp(4px, 1vw, 8px);
  }
  .team-scoreboard:not(:has(> :nth-child(4))) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .team-scoreboard:not(:has(> :nth-child(3))) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .team-scoreboard > .score, [data-role=screen] .team-scoreboard > .score {
    min-width: 0;
    padding: clamp(5px, 1.25vw, 12px);
    font-size: clamp(.7rem, 1.8vw, .95rem);
  }
}
@media (max-width: 520px) {
  .team-scoreboard .score-points > div {
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding-block: 3px;
    text-align: center;
  }
}
