:root {
    color-scheme: dark;
    --background: #101a2c;
    --panel: #192841;
    --line: #3b506c;
    --text: #f3f6fb;
    --muted: #bdcce1;
    --accent: #f9d66e;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--background); color: var(--text); }
h1, h2, p { margin: 0; }
h1 { line-height: 1.12; }
a { color: inherit; }
label, .stack { display: grid; gap: .55rem; }
button, .button, input, select {
    font: inherit; color: inherit; border: 1px solid var(--line); border-radius: .55rem;
    background: #243750; padding: .58em .85em;
}
button, .button, summary { cursor: pointer; }
.button { display: inline-block; text-decoration: none; }
.primary { background: var(--accent); color: #251d08; border-color: transparent; font-weight: 750; }
.danger { background: #782e3a; }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 3px solid #a8daff; outline-offset: 2px; }
.brand { color: var(--accent); font-size: 1.2rem; letter-spacing: -.025em; }
.brand span { color: var(--text); }
.masthead { background: var(--panel); border-bottom: 1px solid var(--line); }
.masthead > div { max-width: 68rem; margin: auto; padding: .75rem 1rem; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.masthead nav { display: flex; gap: 1rem; flex: 1 0 auto; }
.shell { max-width: 68rem; margin: auto; padding: 1.5rem 1rem; display: grid; gap: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: .9rem; padding: 1.1rem; }
.list-item { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.list-item p, details { margin: .4rem 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .8rem; }
.login { max-width: 28rem; margin: 12vh auto; padding: 1rem; display: grid; gap: 1rem; }
.notice { padding: .65rem 1rem; background: #fce6a2; color: #302100; border-radius: .5rem; }
#connection { position: fixed; z-index: 4; left: 50%; top: .55rem; width: max-content; max-width: 92vw; transform: translateX(-50%); box-shadow: 0 5px 20px #0006; }
#play-header { grid-area: head; align-self: center; }
#stage { grid-area: stage; min-width: 0; }
#ranking { grid-area: rank; min-width: 0; }
#commands { grid-area: commands; }
.projection {
    --projection-padding: clamp(.65rem, 1.8vw, 2rem);
    --commands-height: clamp(3.1rem, 6vh, 4.2rem);
    display: grid; height: 100dvh; grid-template-columns: minmax(0, 1fr) minmax(14rem, 23%);
    grid-template-rows: min-content minmax(0, 1fr) var(--commands-height);
    grid-template-areas: "head rank" "stage rank" "commands rank";
    gap: clamp(.55rem, 1.4vw, 1.5rem); padding: var(--projection-padding);
    overflow: hidden;
}
.projection #stage { display: grid; align-items: stretch; min-height: 0; }
.projection #ranking {
    background: var(--panel); border: 1px solid var(--line); border-radius: 1rem;
    padding: clamp(.65rem, 1vw, 1.35rem); align-self: stretch;
}
.projection #ranking h2 { font-size: clamp(1rem, 1.7vw, 2rem); margin-bottom: .7em; }
.score-list { margin: 0; padding: 0; list-style: none; display: grid; gap: .55rem; }
.score-list li {
    display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .25em .55em; align-items: center;
    padding: .55em; background: #253955; border-radius: .55rem; animation: score-in .25s ease-out;
}
.score-list b { overflow-wrap: anywhere; }
.projection .score-list li { font-size: clamp(.9rem, 1.45vw, 1.8rem); }
.score-list small { color: var(--muted); font-size: .66em; }
.score-list .saved { color: #a8efc2; }
.rank-number { background: #101c2e; min-width: 1.65em; padding: .22em; text-align: center; border-radius: .4em; font-weight: 800; }
.score { grid-column: 2; font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 780; }
.adjusted-score { grid-column: 2; }
#commands { display: flex; align-items: center; gap: .42rem; flex-wrap: wrap; align-content: center; position: relative; }
#commands button, #commands a { font-size: clamp(.78rem, 1vw, 1.1rem); }
.captain-presence {
    display: flex; gap: .35rem; align-items: center; margin: 0; padding: 0; list-style: none;
    max-width: 100%; color: var(--muted); font-size: clamp(.73rem, .83vw, .95rem);
}
.captain-presence li {
    display: flex; gap: .32rem; align-items: center; min-width: 0; max-width: 8rem;
    background: var(--panel); border: 1px solid var(--line); border-radius: 2rem; padding: .24rem .48rem;
}
.presence-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence-dot { flex: none; width: .55rem; height: .55rem; border-radius: 50%; background: #f2838c; }
.captain-online .presence-dot { background: #7bdca3; }
.offline .captain-presence { opacity: .55; }
.alerts { margin: 0; border-radius: .5rem; background: #fce6a2; color: #302100; padding: .45rem .55rem; font-size: .85rem; }
.alerts[open] { position: absolute; z-index: 2; bottom: 100%; right: 0; max-height: 67dvh; overflow: auto; }
.alerts .stack { padding: .6rem .15rem .15rem; margin-top: .4rem; border-top: 1px solid #a48e58; }
.alerts button { color: white; }
@media (max-width: 1450px) {
    .projection { --commands-height: 4.75rem; }
}
.announcement {
    align-self: center; display: grid; gap: .85rem; justify-items: center; text-align: center; width: 100%;
    position: relative;
}
.projection .announcement h1 { font-size: clamp(1.65rem, 4.5vw, 5rem); overflow-wrap: anywhere; }
.announcement p { font-size: clamp(1rem, 2vw, 2.1rem); color: var(--muted); }
.projection.scoring { background: #101B2D; }
.scoring-rules {
    --scoring-gold: #FFD66F;
    --scoring-card: #1D3049;
    --scoring-border: #3D506A;
    --scoring-muted: #ccd6e4;
    align-self: center; display: grid; gap: clamp(.35rem, 1.2vh, .9rem);
    width: min(100%, 75rem); margin-inline: auto; text-align: center; color: #fff;
    font-size: clamp(.76rem, min(1.18vw, 2.32vh), 1.32rem);
}
.scoring-header h1 { font-size: clamp(1.45rem, min(3.75vw, 6.6vh), 4rem); }
.scoring-header p, .scoring-detail p { color: var(--scoring-muted); margin-top: .2em; }
.scoring-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(.35rem, 1vw, 1rem); }
.scoring-card {
    display: grid; grid-template-rows: 1fr auto 1fr; align-items: center; gap: .12em;
    background: var(--scoring-card); border: 1px solid var(--scoring-border); border-radius: .65rem;
    padding: clamp(.35rem, 1.12vh, .8rem) .35rem;
}
.scoring-card h2 { font-size: .92em; letter-spacing: .045em; }
.scoring-card p { font-size: .84em; color: var(--scoring-muted); }
.scoring-ceiling { color: var(--scoring-gold); font-size: 2.35em; line-height: 1.04; }
.scoring-ceiling span { font-size: .62em; }
.scoring-difficulty {
    display: flex; align-items: center; justify-content: center; gap: .42em;
    background: #483821; border: 1px solid #856a3e; border-radius: .55rem;
    color: var(--scoring-gold); font-size: 1.02em; font-weight: 750; padding: .35em .65em;
}
.scoring-difficulty span { font-size: 1.28em; line-height: 1; }
.scoring-detail { border-top: 1px solid var(--scoring-border); padding-top: .35em; }
.scoring-detail h2 { font-size: 1.36em; }
.scoring-effects { list-style: none; margin: 0; padding: 0; display: grid; gap: .28em; }
.scoring-effects li {
    display: grid; grid-template-columns: 1.9em minmax(0, 1fr) 1.3em; align-items: center; gap: .55em;
    background: var(--scoring-card); border: 1px solid var(--scoring-border); border-radius: .5rem;
    text-align: left; padding: .21em .62em;
}
.scoring-effects p { color: var(--scoring-muted); font-size: .88em; }
.scoring-effects .positive { --scoring-effect: #87e3a6; }
.scoring-effects .negative { --scoring-effect: #ff9297; }
.scoring-effects .neutral { --scoring-effect: #b8c6d7; }
.scoring-icon, .scoring-symbol { color: var(--scoring-effect); font-weight: 800; text-align: center; }
.scoring-icon { font-size: 1.25em; }
.scoring-symbol { font-size: 1.65em; line-height: 1; }
.scoring-footnote { color: var(--scoring-gold); font-weight: 750; }
.eyebrow { color: var(--accent) !important; font-size: .8rem; font-weight: 800; letter-spacing: .09em; }
.projection .question { display: grid; grid-template-rows: minmax(0, 37%) minmax(0, 1fr); gap: 1rem; min-height: 0; }
.question-heading h1 { font-size: clamp(1.3rem, min(2.75vw, 5.3vh), 3.3rem); overflow-wrap: anywhere; white-space: pre-wrap; }
.question-reading {
    display: block; width: 100%; padding: 0; border: 0; background: none; font: inherit;
    text-align: start; white-space: inherit; overflow-wrap: inherit;
}
.projection .question-heading.long h1 { font-size: clamp(1.1rem, min(2vw, 4.4vh), 2.7rem); }
.question-heading p { margin-bottom: .55em; }
.debrief {
    display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 1rem; min-height: 0;
    padding: clamp(1rem, 2vw, 2.5rem); background: var(--panel); border: 1px solid var(--line); border-radius: 1rem;
}
.debrief h1 { color: var(--accent); font-size: clamp(1.4rem, 3vw, 3.6rem); }
.debrief p {
    overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
    font-size: clamp(1.05rem, min(2vw, 3.5vh), 2.3rem); line-height: 1.4;
}
.projection .choices {
    display: grid; gap: .6rem; grid-auto-rows: minmax(0, 1fr);
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-columns: repeat(2, round(down, calc((100% - .6rem) / 2), 1px));
}
.projection .choices.rows-2 { grid-auto-rows: round(down, calc((100% - .6rem) / 2), 1px); }
.projection .choices.rows-3 { grid-auto-rows: round(down, calc((100% - 1.2rem) / 3), 1px); }
.choice {
    background: var(--panel); padding: .65em; border: 1px solid var(--line); border-radius: .65rem;
    display: flex; align-items: center; gap: .55em; min-width: 0;
}
.projection .choice {
    container-type: size; font-size: clamp(.95rem, min(1.68vw, 2.9vh), 2rem); line-height: 1.22;
    min-height: 0; overflow: hidden; padding: .43em .65em; text-align: start;
}
.projection .choice-long { font-size: clamp(.9rem, min(1.4vw, 2.45vh), 1.65rem); }
.choice-letter { background: #101c2e; border-radius: .38em; padding: .24em .43em; flex: none; }
.choice-text { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.projection .choice-text {
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; max-height: 100%; overflow: hidden;
}
@container (min-height: 5.75rem) {
    .projection .choice-text { -webkit-line-clamp: 4; }
}
@container (min-height: 8.5rem) {
    .projection .choice-text { -webkit-line-clamp: 5; }
}
@container (min-height: 12rem) {
    .projection .choice-text { -webkit-line-clamp: 7; }
}
.correct { background: #153f32; border-color: #65be87; }
.wrong { background: #532c3a; border-color: #d67886; }
.wheel { max-width: 100%; max-height: 45vh; object-fit: contain; }
.wheel-result { color: var(--accent); min-height: 1.4em; font-size: clamp(1.4rem, 3vw, 3.5rem); }
.announcement .wheel-ids { min-height: 2em; font-size: .85rem; overflow-wrap: anywhere; }
.projection:has(#settings[open]) .lobby .qr { visibility: hidden; }
.lobby { align-self: center; justify-items: center; text-align: center; min-width: 0; }
.team-list { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.qr { justify-items: center; min-width: 0; }
.qr canvas { display: block; width: min(37vh, 100%, 23rem); height: auto; image-rendering: pixelated; }
.join-link { overflow-wrap: anywhere; font-size: clamp(1rem, 1.2vw, 1.35rem); font-variant-numeric: tabular-nums; color: var(--accent); }
.copy-status { font-size: .8rem; color: var(--muted); }
dialog {
    color: var(--text); background: var(--panel); border: 1px solid var(--line);
    border-radius: .9rem; width: min(92vw, 30rem); padding: 1.15rem; max-height: 88dvh;
}
dialog[open] { display: grid; gap: .65rem; }
dialog::backdrop { background: #070e1bb8; }
#reading {
    --reading-top: clamp(.45rem, 1vh, 1rem);
    position: fixed; inset: var(--reading-top) 0 auto; z-index: 3; margin: 0 auto;
    width: 90vw; height: 90dvh;
    max-height: calc(100dvh - var(--reading-top) - var(--projection-padding) - var(--commands-height));
    grid-template-rows: auto minmax(0, 1fr); gap: clamp(.6rem, 2vh, 1.5rem);
    padding: clamp(1rem, 2.8vw, 3.25rem);
    font-size: clamp(1.5rem, 4vmin, 2.75rem); overflow: hidden; box-shadow: 0 0 0 100vmax #070e1bb8;
}
#reading header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
#reading h2 { font-size: clamp(1rem, 1.65vw, 2rem); }
#reading button { flex: none; font-size: 1.25rem; }
.reading-scroll {
    display: flex; flex-direction: column; min-height: 0; overflow: auto; overscroll-behavior: contain;
    scrollbar-gutter: stable;
}
.reading-scroll p { flex: none; margin: auto 0; line-height: 1.16; white-space: pre-wrap; overflow-wrap: anywhere; }
.projection:has(#reading[open]) #commands { z-index: 4; }
dialog .qr canvas { width: min(24vh, 9rem); }
.captain { display: flex; flex-direction: column; min-height: 100dvh; }
.captain #play-header { display: none; }
.captain #ranking {
    position: sticky; top: 0; z-index: 1; padding: .55rem .8rem; background: #192841;
    border-bottom: 1px solid var(--line);
}
.captain #ranking button { width: 100%; text-align: start; }
.captain #ranking .score-list { margin-top: .55rem; }
.captain #stage { width: min(100%, 43rem); margin: 0 auto; padding: 1rem; }
.captain .question { display: grid; gap: .8rem; }
.captain .question-heading h1 { line-height: 1.25; }
.captain .choices { display: grid; gap: .6rem; }
.captain .choice { min-height: 3rem; cursor: pointer; }
.captain input[type="checkbox"] { accent-color: var(--accent); width: 1.25rem; height: 1.25rem; flex: none; }
.captain .choice-text small { display: block; margin-top: .2em; color: var(--muted); }
.captain .announcement { margin: 1rem auto; }
.result { font-weight: 800; color: var(--accent); }
.hint { color: var(--muted); }
.offline #stage button, .offline #commands button, .offline dialog .primary { opacity: .5; cursor: wait; }
.projection.finished {
    grid-template-columns: 1fr; grid-template-areas: "head" "stage" "commands";
}
.finished #ranking, .captain #ranking:empty { display: none; }
.final h1 { position: relative; z-index: 1; }
.final-board {
    position: relative; z-index: 1; list-style: none; padding: 0; margin: .75rem 0 0;
    width: min(96%, 70rem); display: grid; gap: clamp(.35rem, 1.2vw, .85rem);
}
.final-team {
    display: grid; gap: clamp(.25rem, .8vw, .7rem); justify-items: center; align-content: center;
    background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: .8rem;
    padding: clamp(.55rem, 1.4vw, 1.25rem); overflow-wrap: anywhere; min-width: 0;
}
.final-team .rank-number { color: var(--accent); font-size: clamp(.92rem, 1.65vw, 1.7rem); }
.final-team strong { font-size: clamp(.9rem, 2.15vw, 2.25rem); line-height: 1.12; }
.final-score { color: var(--muted); font-size: clamp(.8rem, 1.35vw, 1.45rem); font-variant-numeric: tabular-nums; }
.final-team.place-1 { background: #493a20; color: #fff1bd; border-color: var(--accent); }
.final-team.place-1 .rank-number { background: var(--accent); color: #38290b; }
.final-team.place-1 .final-score { color: #ffe499; }
.duel { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 50rem; }
.podium {
    --podium-step: clamp(1.1rem, 3.4vh, 2.45rem);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, var(--podium-step)) minmax(6rem, auto);
    row-gap: 0;
}
.podium .place-2 { grid-column: 1; grid-row: 2 / 4; }
.podium .place-1 { grid-column: 2; grid-row: 1 / 4; }
.podium .place-3 { grid-column: 3; grid-row: 3 / 4; }
.podium .place-4 { grid-column: 1 / -1; grid-row: 4; margin-top: clamp(.35rem, 1.2vw, .85rem); }
.rank-row {
    list-style: none; margin: 0; padding: 0; display: grid; grid-auto-flow: column;
    grid-auto-columns: minmax(0, 15rem); gap: clamp(.25rem, 1.2vw, .85rem); justify-content: center;
}
.celebrate .final-team { animation: reveal-rank .48s ease-out both; }
.celebrate .reveal-1 { animation-delay: .19s; }
.celebrate .reveal-2 { animation-delay: .38s; }
.celebrate .reveal-3 { animation-delay: .57s; }
@keyframes reveal-rank {
    from { opacity: 0; transform: translateY(.7rem); }
    to { opacity: 1; transform: translateY(0); }
}
.confetti-field { position: absolute; inset: -18vh 0; overflow: hidden; pointer-events: none; }
.confetti {
    position: absolute; top: 0; width: .32rem; height: .72rem; opacity: 0;
    background: #d6b65d; animation: fall 2s 1s ease-out both;
}
.confetti:nth-child(3n + 1) { background: #a7bcd4; height: .42rem; animation-delay: 1.15s; }
.confetti:nth-child(3n + 2) { background: #f2db9b; animation-delay: 1.32s; }
.confetti:nth-child(1) { left: 8%; }
.confetti:nth-child(2) { left: 15%; }
.confetti:nth-child(3) { left: 23%; }
.confetti:nth-child(4) { left: 30%; }
.confetti:nth-child(5) { left: 38%; }
.confetti:nth-child(6) { left: 46%; }
.confetti:nth-child(7) { left: 54%; }
.confetti:nth-child(8) { left: 62%; }
.confetti:nth-child(9) { left: 70%; }
.confetti:nth-child(10) { left: 78%; }
.confetti:nth-child(11) { left: 85%; }
.confetti:nth-child(12) { left: 92%; }
@keyframes fall {
    15% { opacity: .78; }
    100% { opacity: 0; transform: translate(3vw, 55vh) rotate(300deg); }
}
@keyframes score-in { from { transform: translateY(.18em); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; } }
.busy #stage button, .busy #commands button { cursor: progress; }
