:root {
    color-scheme: light;
    --ink: #273742;
    --muted: #445865;
    --paper: #fffdf7;
    --ground: #f5eddf;
    --grout: #fff8e9;
    --teal: #12606b;
    --focus: #24276e;
    --edge: #dbcab2;
    --tile-a: #e77c75;
    --tile-b: #72c0c5;
    --tile-c: #efc161;
    --tile-d: #a3a4e2;
    --tile-e: #9bc69b;
    --tile-f: #e8a377;
    --radius: 8px;
    font-family: system-ui, sans-serif;
    line-height: 1.4;
    color: var(--ink);
    background: var(--ground);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    min-height: 100vh;
    min-height: 100svh;
    margin: 0;
    padding: 0 clamp(12px, 3vw, 52px) 24px;
    border-block: 8px solid transparent;
    border-image: repeating-linear-gradient(90deg,
        #dc514e 0 38px, var(--grout) 38px 43px, #187b83 43px 78px, var(--grout) 78px 83px,
        #dca231 83px 116px, var(--grout) 116px 121px, #585bb3 121px 158px, var(--grout) 158px 163px,
        #74ac83 163px 197px, var(--grout) 197px 202px, #df8245 202px 238px, var(--grout) 238px 243px) 8;
    background: radial-gradient(ellipse at 50% 0%, #fff7e5, transparent 62%), var(--ground);
}

body.has-wallpaper {
    background-image: linear-gradient(#fff7e5d9, #f5eddf8f), var(--quiz-wallpaper);
    background-position: center;
    background-size: cover;
}

.has-wallpaper .panel { --paper: #fffdf7e8; }

a { color: #074f5b; text-underline-offset: .18em; }
:where(a, button, input, select, summary):focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
:where(button, input, select) { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
img { display: block; max-width: 100%; }
h1, h2, p, ul, ol { margin: 0; }
p, h1, h2, li { overflow-wrap: anywhere; }
h1 { font-size: clamp(1.65rem, 6.5vw, 2.5rem); font-weight: 850; line-height: 1.1; letter-spacing: -.04em; }
h2 { font-size: 1.2rem; line-height: 1.2; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: fixed;
    z-index: 20;
    inset: 8px auto auto 12px;
    padding: 12px;
    transform: translateY(-170%);
    background: var(--paper);
}
.skip-link:focus { transform: none; }

.brand {
    max-width: 40rem;
    min-height: 72px;
    margin: 0 auto;
    padding: 14px 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.brand-copy { min-width: 0; }
.wordmark, .eyebrow { font-size: .82rem; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.wordmark { color: var(--teal); }
.brand-title { font-size: clamp(1.12rem, 4.3vw, 1.75rem); font-weight: 850; letter-spacing: -.025em; }
.brand-detail { color: var(--muted); font-size: .94rem; }
.brand-logo { width: clamp(52px, 17vw, 100px); max-height: 65px; object-fit: contain; }
.test-chip { margin-top: 4px; }

main, .connection { max-width: 40rem; margin-inline: auto; }
main:focus { outline: none; }
.panel {
    display: grid;
    gap: 14px;
    padding: clamp(14px, 4.2vw, 30px);
    border: 2px solid var(--edge);
    border-radius: 14px;
    background: var(--paper);
    box-shadow: 0 6px 0 #d7c6aa6b;
}
.intro { color: var(--muted); font-size: 1.02rem; }
.notice {
    padding: 10px 12px;
    border: 2px solid #e3c277;
    border-radius: var(--radius);
    background: #fff3cf;
    font-weight: 650;
}
.connection { margin-bottom: 12px; }
.confirmed { border-color: #87af97; background: #e9f6e9; }

.join-form, .setup-form { display: grid; gap: 8px; }
.join-form label, .setup-form > label { font-weight: 730; }
.join-form input, .setup-form select {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 8px 12px;
    border: 2px solid #ac9b83;
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    font-size: 1rem;
}
.join-form input[name="code"] { letter-spacing: .14em; font-weight: 780; text-transform: uppercase; }
.join-form > label:not(:first-child), .join-form > button, .setup-form > button { margin-top: 5px; }
.test-toggle { display: flex; align-items: center; gap: 7px; min-height: 44px; }
.test-toggle input { width: 20px; height: 20px; accent-color: var(--teal); }
.form-error { color: #811b2c; font-weight: 680; }
.form-error:empty { display: none; }

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 7px 14px;
    border: 2px solid transparent;
    border-radius: var(--radius);
    color: var(--ink);
    text-align: center;
    text-decoration: none;
    font-weight: 750;
    line-height: 1.18;
}
.primary { background: var(--teal); border-color: #054751; color: #fff; }
.primary:hover:not(:disabled) { background: #0a515b; }
.secondary { background: #f8e9d2; border-color: #c9b18c; }
.secondary:hover:not(:disabled) { background: #f5dfbc; }
.quiet { background: transparent; color: #0c5964; text-decoration: underline; text-underline-offset: .2em; }
.danger { background: #fff2ef; color: #821f2a; border-color: #e3b0ab; }
.button:disabled { opacity: .65; }

.privacy { padding-top: 8px; border-top: 1px solid var(--edge); color: var(--muted); font-size: .94rem; }
.privacy summary { display: list-item; align-content: center; min-height: 44px; cursor: pointer; font-weight: 700; }
.privacy p + p { margin-top: 8px; }
.leave { justify-self: start; }
.public-wait > button { justify-self: start; }

.chip {
    display: inline-block;
    width: fit-content;
    max-width: 100%;
    padding: 4px 9px;
    border: 1px solid #c7ad88;
    border-radius: 5px;
    background: #fff0ce;
    color: #554023;
    font-size: .93rem;
    font-weight: 750;
}
.question-meta { display: flex; gap: 8px 12px; flex-wrap: wrap; align-items: center; }
.player .question-meta:has(.timer) { position: sticky; z-index: 2; top: 0; padding-block: 5px; background: var(--paper); }
.prompt, .explanation { white-space: pre-wrap; }
.question-content { display: grid; gap: 14px; align-items: center; }
.timer {
    margin-left: auto;
    border: 2px solid #b39f7b;
    border-radius: var(--radius);
    padding: 4px 10px;
    background: #fff4db;
    font-variant-numeric: tabular-nums;
}
.timer.ending { border-color: #aa3938; background: #ffdfdb; color: #731e22; }
.timer-value { min-width: 3ch; display: inline-block; text-align: right; }
.question-image { max-height: min(36svh, 280px); justify-self: center; object-fit: contain; border-radius: var(--radius); }
.vote-count { color: var(--muted); font-weight: 730; }
.option-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; }
.tile {
    --ceramic: var(--tile-a);
    position: relative;
    min-width: 0;
    min-height: 54px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-content: center;
    align-items: center;
    gap: 5px 9px;
    padding: 10px;
    border: 2px solid #28385061;
    border-radius: var(--radius);
    background: linear-gradient(150deg, #ffffff36, transparent 48%), var(--ceramic);
    box-shadow: inset 0 2px 0 #ffffffa0, inset 0 -2px 0 #2838502b;
    color: #182a35;
    text-align: left;
    line-height: 1.2;
}
.tile-b { --ceramic: var(--tile-b); }
.tile-c { --ceramic: var(--tile-c); }
.tile-d { --ceramic: var(--tile-d); }
.tile-e { --ceramic: var(--tile-e); }
.tile-f { --ceramic: var(--tile-f); }
.tile:focus-visible { z-index: 1; }
button.tile:hover:not(:disabled) { box-shadow: inset 0 0 0 2px #273742; }
button.tile:active:not(:disabled) { filter: brightness(.92); }
.tile-letter {
    display: grid;
    place-items: center;
    width: 33px;
    height: 33px;
    border: 1px solid #26384252;
    border-radius: 5px;
    background: #fffaf0db;
    font-weight: 850;
}
.tile-text { font-weight: 760; overflow-wrap: anywhere; }
.tile-image {
    grid-column: 2;
    max-height: 145px;
    width: min(100%, 280px);
    object-fit: contain;
    object-position: left;
    border-radius: 4px;
}
.tile-meta, .result-bar, .tile-badge { grid-column: 2; }
.tile-meta { font-size: .87em; font-weight: 700; }
.result-bar { height: 8px; border-radius: 3px; background: #ffffffa0; overflow: hidden; }
.result-bar span { height: 100%; display: block; background: #28434e; }
.tile-badge { justify-self: start; padding: 3px 5px; border-radius: 4px; background: #fffaf0ed; font-size: .83em; font-weight: 780; }
.tile.correct { border: 3px solid #145437; padding: 9px; }
.tile.correct .tile-badge { color: #105334; }
.tile .own-choice { color: #243174; }
.explanation {
    padding: 10px 12px;
    border-inline-start: 4px solid #187b83;
    background: #f4eee1;
    font-weight: 650;
}
.me-card { padding: 12px; border: 1px solid #93b6b8; border-radius: var(--radius); background: #e7f4f1; }
.me-card p + p, .me-card .award + p { margin-top: 4px; }
.award { display: block; font-size: 1.25em; }
.personal-score, .high-place { font-weight: 780; }
.finale-panel {
    background:
        radial-gradient(circle at 3% 8%, #ecc37c 0 3px, transparent 4px),
        radial-gradient(circle at 97% 12%, #a3a4e2 0 4px, transparent 5px),
        radial-gradient(circle at 92% 5%, #72c0c5 0 4px, transparent 5px),
        var(--paper);
}
.rounds, .leader-list, .player-list, .podium ul { list-style: none; padding: 0; }
.rounds li + li { margin-top: 8px; }
.rounds a { justify-content: start; }

:is(.moderator, .presentation) {
    height: 100vh;
    height: 100svh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 10px;
}
:is(.moderator, .presentation) .brand,
:is(.moderator, .presentation) main,
:is(.moderator, .presentation) .connection { width: min(100%, 98rem); max-width: none; }
:is(.moderator, .presentation) .brand, :is(.moderator, .presentation) .connection { flex: none; }
:is(.moderator, .presentation) main { flex: 1 1 auto; min-height: 0; padding: 0 4px 8px; overflow-y: auto; overscroll-behavior: contain; }
:is(.moderator, .presentation) .brand { min-height: 76px; padding-block: 10px; gap: clamp(16px, 3vw, 52px); }
:is(.moderator, .presentation) .brand:not(:has(.brand-title)) { display: none; }
:is(.moderator, .presentation) .brand-title { font-size: clamp(1.5rem, 3.6vw, 3rem); }
:is(.moderator, .presentation) .brand-detail { font-size: clamp(.95rem, 1.45vw, 1.3rem); }
:is(.moderator, .presentation) .brand-logo {
    flex: none;
    align-self: flex-start;
    width: clamp(104px, 27vw, 360px);
    max-width: 45%;
    height: auto;
    max-height: clamp(60px, 11vw, 138px);
    object-position: right center;
}
:is(.moderator, .presentation) .panel { gap: clamp(10px, 1.4vh, 18px); }
:is(.moderator, .presentation) h1 { font-size: clamp(1.8rem, 4.8vw, 5rem); }
:is(.moderator, .presentation) .prompt { font-size: clamp(1.6rem, 3.65vw, 3.85rem); }
:is(.moderator, .presentation) :is(.intro, .explanation, .notice) { font-size: clamp(1rem, 1.65vw, 1.6rem); }
:is(.moderator, .presentation) :is(.chip, .eyebrow) { font-size: clamp(.88rem, 1.35vw, 1.3rem); }
.moderator .setup-panel { max-width: 50rem; }
:is(.moderator, .presentation) .question-image { max-height: clamp(110px, 20vh, 245px); }
:is(.moderator, .presentation) .timer { font-size: clamp(1.15rem, 3vw, 2.95rem); }
:is(.moderator, .presentation) .question-panel:has(.question-image) .tile-image { max-height: min(10vh, 100px); }
:is(.moderator, .presentation) .tile-image { max-height: min(12vh, 130px); }
:is(.moderator, .presentation) .tile { font-size: clamp(.95rem, 2.05vw, 2rem); }
:is(.moderator, .presentation) .tile-letter { width: clamp(34px, 3.45vw, 60px); height: clamp(34px, 3.45vw, 60px); }
:is(.moderator, .presentation) .vote-count { font-size: clamp(.92rem, 1.45vw, 1.35rem); }

.lobby-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 15px; align-items: center; }
.qr { display: block; width: min(100%, 360px, 45vh); height: auto; border: 2px solid var(--edge); border-radius: var(--radius); background: #fff; }
.join-info { display: grid; min-width: 0; justify-items: start; gap: 8px; }
.game-code { font-size: clamp(1.8rem, 5.7vw, 6rem); font-weight: 900; line-height: 1.02; letter-spacing: .07em; }
.join-link { font-weight: 760; font-size: clamp(1rem, 2.1vw, 2rem); overflow-wrap: anywhere; }
.lobby-note { color: var(--muted); }
.leader-list { display: grid; gap: 7px; }
.leader-list li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 54px;
    padding: 7px 12px;
    border: 1px solid #ad9c82;
    border-radius: var(--radius);
    background: #f8ead0;
    font-size: clamp(1rem, 2.45vw, 2.2rem);
    font-weight: 690;
}
.rank { color: #564127; }
.score { font-variant-numeric: tabular-nums; }
.podium { display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; align-items: end; }
.podium-place { padding: 14px; border: 2px solid #69669a; border-radius: var(--radius); background: #d5d3eb; }
.podium-place[data-place="1"] { background: #efc86e; border-color: #946d26; }
.podium-place[data-place="2"] { background: #a6ced0; border-color: #4a7a81; }
.podium-place h2 { font-size: clamp(1.3rem, 2.8vw, 2.7rem); }
.podium-place .score { font-size: clamp(.95rem, 1.75vw, 1.55rem); }
.podium-place li { font-weight: 830; font-size: clamp(1.1rem, 2vw, 1.95rem); }

.controls {
    flex: none;
    width: min(100%, 98rem);
    margin: 12px auto 0;
    padding: 7px;
    border: 2px solid #c4af91;
    border-radius: 10px;
    background: #fff9ec;
    box-shadow: 0 2px 8px #42351b26;
    font-size: .92rem;
}
.control-top, .action-row { display: flex; flex-wrap: wrap; gap: 5px 8px; align-items: center; }
.control-top { justify-content: space-between; }
.presentation-fallback { margin-top: 7px; }
.control-count { color: var(--muted); font-weight: 700; }
.control-body { margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--edge); }
.player-list { display: grid; gap: 5px; max-height: 26vh; overflow: auto; margin: 8px 0 0; }
.player-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 3px 8px; background: #f3e9d8; }

.moderator-login .panel > a { justify-self: start; }
.login-dialog {
    width: min(500px, calc(100% - 24px));
    max-height: calc(100svh - 24px);
    padding: 0;
    border: 2px solid var(--edge);
    border-radius: 12px;
    background: var(--paper);
    color: var(--ink);
}
.login-dialog::backdrop { background: #172831aa; }
.login-dialog-header, .login-dialog-footer { display: flex; align-items: center; gap: 8px; padding: 9px 12px; }
.login-dialog-header { justify-content: space-between; }
.login-dialog-header h2 { font-size: clamp(1rem, 3.5vw, 1.2rem); }
.login-frame { display: block; width: 100%; height: min(500px, 60svh); border: 0; background: #f0f0f1; }
.login-dialog-footer { justify-content: center; }

@media (min-width: 700px) {
    .lobby-grid { grid-template-columns: minmax(190px, .7fr) minmax(0, 1.3fr); gap: clamp(16px, 4vw, 65px); }
    :is(.moderator, .presentation) .question-content:has(.question-image) { grid-template-columns: minmax(0, 1fr) minmax(190px, .36fr); }
    :is(.moderator, .presentation) .option-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    :is(.moderator, .presentation) .tile { padding: 12px; }
    :is(.moderator, .presentation) .tile.correct { padding: 11px; }
    :is(.moderator, .presentation) .tile:has(.tile-image) { grid-template-columns: auto minmax(0, 1fr) minmax(60px, 25%); }
    :is(.moderator, .presentation) .tile-image {
        grid-column: 3;
        grid-row: 1;
        width: 100%;
        max-height: min(10svh, 100px);
        object-position: center;
    }
    :is(.moderator, .presentation) .revealed .tile-image { grid-row: 1 / span 3; }
    :is(.moderator, .presentation) .podium { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .podium-place[data-place="1"] { grid-column: 2; grid-row: 1; min-height: 12rem; }
    .podium-place[data-place="2"] { grid-column: 1; grid-row: 1; min-height: 9rem; }
    .podium-place[data-place="3"] { grid-column: 3; grid-row: 1; min-height: 7rem; }
}

@media (min-width: 1100px) {
    :is(.moderator, .presentation) .brand-logo {
        width: clamp(280px, 18.75vw, 360px);
        max-height: clamp(110px, 12.8svh, 138px);
    }
}

@media (prefers-reduced-motion: no-preference) {
    .tile, .button { transition: background-color .16s, box-shadow .16s; }
    .result-bar span { transition: width .25s; }
}
