/* Neutral surroundings, since flags come in every colour; one accent for actions and the player's own name */
:root {
    color-scheme: light dark;
    --bg: #f3f4f6;
    --surface: #fff;
    --surface-hover: #f9fafb;
    --border: #d1d5db;
    --text: #111827;
    --text-muted: #4b5563;
    --accent: #1d4ed8;
    --accent-hover: #1e40af;
    --on-accent: #fff;
    --correct: #15803d;
    --wrong: #b91c1c;
    --tiebreak: #b45309;
    --on-semantic: #fff;
    --flag-edge: rgb(0 0 0 / 0.08);
    --flag-shadow: 0 12px 25px rgb(0 0 0 / 0.15);
    --lift-shadow: 0 4px 12px rgb(0 0 0 / 0.1);
    --text-sm: 0.875rem;
    --text-md: 1rem;
    --text-lg: 1.25rem;
    --text-xl: 2rem;
    --radius: 6px;
    --fade: 0.5s ease;
    --drawer: 0.3s;
    /* How long the correct answer shows before the drawer slides away; the server's
       ROUND_TRANSITION_SECS (main.py) starts the next round just after it */
    --reveal: 0.6s;
    /* The flag and answers fading between rounds */
    --round-fade: 0.3s ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111318;
        --surface: #1c1f26;
        --surface-hover: #252932;
        --border: #3a3f4b;
        --text: #e5e7eb;
        --text-muted: #9ca3af;
        --accent: #60a5fa;
        --accent-hover: #93c5fd;
        --on-accent: #0b1220;
        --correct: #22c55e;
        --wrong: #ef4444;
        --tiebreak: #f59e0b;
        --on-semantic: #0b1220;
        --flag-edge: rgb(255 255 255 / 0.12);
        --flag-shadow: 0 12px 25px rgb(0 0 0 / 0.5);
        --lift-shadow: 0 4px 12px rgb(0 0 0 / 0.4);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    font-family: "Roboto", sans-serif;
    font-size: var(--text-md);
    color: var(--text);
    background: var(--bg);
    /* Stops double-tap zoom without disabling pinch zoom */
    touch-action: manipulation;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    background: radial-gradient(ellipse at 50% 40%, var(--surface), var(--bg) 70%);
}

/* Header, stage and answers form one column; the background stays full width */
header,
main,
footer {
    inline-size: 100%;
    max-inline-size: 720px;
    margin-inline: auto;
}

[hidden] {
    display: none !important;
}

#connection-banner {
    flex-shrink: 0;
    margin: 0;
    padding: 0.5rem 1rem;
    text-align: center;
    font-size: var(--text-sm);
    font-weight: 700;
    background: var(--wrong);
    color: var(--on-semantic);
}

header {
    flex-shrink: 0;
    padding: 1rem 1rem 0;
}

/* Explicit columns, so a hidden round progress doesn't shift the leaderboard */
.top-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.75rem;
}

.top-bar > * {
    min-width: 0;
    overflow-wrap: anywhere;
}

.player-chip {
    grid-column: 1;
    justify-self: start;
    display: flex;
    flex-direction: column;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

/* Looks like the name; clicking it opens the account page */
#player-name {
    padding: 0;
    border: 0;
    background: none;
    text-align: start;
    font-weight: 700;
    color: var(--accent);
    overflow-wrap: anywhere;
}

#player-name:hover:enabled {
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

#player-name:disabled {
    cursor: default;
}

.player-points {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

#round-progress {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--text-sm);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#round-bar {
    appearance: none;
    inline-size: 7rem;
    block-size: 4px;
    border: 0;
    border-radius: 2px;
    background: var(--border);
    color: var(--accent);
}

#round-bar::-webkit-progress-bar {
    border-radius: 2px;
    background: var(--border);
}

#round-bar::-webkit-progress-value {
    border-radius: 2px;
    background: var(--accent);
    transition: inline-size var(--fade);
}

#round-bar::-moz-progress-bar {
    border-radius: 2px;
    background: var(--accent);
}

#round-progress.tiebreak {
    color: var(--tiebreak);
}

#round-progress.tiebreak #round-bar::-webkit-progress-value {
    background: var(--tiebreak);
}

#round-progress.tiebreak #round-bar::-moz-progress-bar {
    background: var(--tiebreak);
}

/* Phones: name and leaderboard share the first row, round progress gets the full width below */
@media (max-width: 600px) {
    /* The chip keeps its width; the leaderboard wraps instead */
    .top-bar {
        grid-template-columns: auto minmax(0, 1fr);
        row-gap: 0.5rem;
    }

    #round-progress {
        grid-row: 2;
        grid-column: 1 / -1;
        flex-direction: row;
        gap: 0.75rem;
    }

    #round-bar {
        flex: 1;
    }

    .top-bar > .leaderboard {
        grid-column: 2;
    }
}

.leaderboard {
    grid-column: 3;
    justify-self: end;
    text-align: right;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.leaderboard h2 {
    margin: 0 0 0.125rem;
    font-size: inherit;
    font-weight: 400;
}

/* Name, then score or wins; a "+3" pops up to the left of a score that just rose */
#scoreboard p {
    display: flex;
    justify-content: flex-end;
    align-items: baseline;
    gap: 0.375rem;
    margin: 0;
}

#scoreboard strong {
    color: var(--text);
}

#scoreboard .value {
    white-space: nowrap;
}

/* The player on a run of first-try answers: "🔥 4" */
#scoreboard .streak {
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#scoreboard .me strong {
    color: var(--accent);
}

#scoreboard .me .value {
    color: var(--text);
    font-weight: 700;
}

.score-pop {
    font-weight: 700;
    color: var(--correct);
    animation: score-pop 1.6s ease-out forwards;
}

@keyframes score-pop {
    from { opacity: 1; transform: translateY(0.25rem); }
    20% { transform: translateY(0); }
    70% { opacity: 1; }
    to { opacity: 0; transform: translateY(-0.25rem); }
}

/* Replaces the points in the name chip while the player watches someone else's game */
#spectator-badge {
    align-self: flex-start;
    margin-top: 0.125rem;
    padding: 0 0.375rem;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--tiebreak);
    border: 1px solid currentColor;
}

.toolbar {
    display: flex;
    flex-wrap: wrap-reverse;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin-top: 0.75rem;
}

#status {
    flex: 1 1 12rem;
    margin: 0;
    font-size: var(--text-sm);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

#active-players {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* Fits "Copied", so the toolbar doesn't reflow for two seconds */
#invite-btn {
    min-width: 5.5rem;
}

button {
    font: inherit;
    color: var(--text);
    cursor: pointer;
    touch-action: manipulation;
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.actions button {
    min-height: 40px;
    padding: 0.5rem 1rem;
    font-size: var(--text-sm);
    font-weight: 700;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.actions button:hover,
#lobby-link:hover {
    background: var(--surface-hover);
}

/* Back to the lobby; looks like the toolbar's buttons */
#lobby-link {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    box-sizing: border-box;
    padding: 0.5rem 1rem;
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

#lobby-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* During a game it is Exit, which gives the game up */
#lobby-link.exit {
    color: var(--wrong);
    border-color: var(--wrong);
}

.exit-confirm {
    inline-size: min(24rem, calc(100vw - 2rem));
    padding: 1.25rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--flag-shadow);
}

.exit-confirm::backdrop {
    background: rgb(0 0 0 / 0.45);
}

.exit-confirm h2 {
    margin: 0 0 0.5rem;
    font-size: var(--text-lg);
}

.exit-error {
    color: var(--wrong);
    font-size: var(--text-sm);
}

.exit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

.exit-actions button {
    min-height: 40px;
    padding: 0.5rem 1rem;
    font-size: var(--text-sm);
    font-weight: 700;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

.exit-actions button:hover:enabled {
    background: var(--surface-hover);
}

#exit-leave {
    border-color: var(--wrong);
    background: var(--wrong);
    color: var(--on-semantic);
}

#exit-leave:hover:enabled {
    filter: brightness(1.1);
}

#exit-leave:disabled {
    cursor: default;
    opacity: 0.5;
}

/* A player's general score (the leaderboard's) next to their name in the room; a pseudo-element,
   so it isn't part of the line's text */
.global-points::before {
    content: "★ " attr(data-points);
}

.global-points {
    font-size: var(--text-sm);
    font-weight: 400;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Gave up this game: shown with 0 */
.gave-up-tag {
    font-size: var(--text-sm);
    color: var(--text-muted);
    font-style: italic;
}

/* Whether the room shows up in the lobby */
.room-badge {
    align-self: center;
    padding: 0.125rem 0.5rem;
    font-size: var(--text-sm);
    font-weight: 700;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.room-badge.private {
    border-color: var(--tiebreak);
    color: var(--tiebreak);
}

/* A segmented switch: the pressed half is the language in use */
.lang-switch {
    display: flex;
}

.actions .lang-switch button {
    min-width: 0;
    padding-inline: 0.625rem;
    font-weight: 400;
    color: var(--text-muted);
}

.lang-switch button:first-child {
    border-start-end-radius: 0;
    border-end-end-radius: 0;
}

.lang-switch button:last-child {
    border-start-start-radius: 0;
    border-end-start-radius: 0;
    margin-inline-start: -1px;
}

.actions .lang-switch button[aria-pressed="true"] {
    position: relative;
    font-weight: 700;
    border-color: var(--text-muted);
    background: var(--bg);
    color: var(--text);
}

#ready-btn {
    min-width: 80px;
}

#ready-btn,
#pregame-ready {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

#ready-btn:hover:enabled,
#pregame-ready:hover:enabled {
    border-color: var(--accent-hover);
    background: var(--accent-hover);
}

/* Disabled means "you're ready", not "broken" */
#ready-btn:disabled,
#pregame-ready:disabled {
    cursor: default;
    border-color: var(--correct);
    background: transparent;
    color: var(--correct);
}

#ready-btn:disabled::before,
#pregame-ready:disabled::before {
    content: "✓ ";
}

#player-score,
#scoreboard,
#results-message .points,
#results-message .place {
    font-variant-numeric: tabular-nums;
}

#player-score {
    font-weight: 700;
    color: var(--text);
}

main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Between games: last game's results (if any) above the pre-game screen, centred, scrolling if long */
main.pregame-open {
    justify-content: safe center;
    overflow-y: auto;
}

/* Anchored to the top, so the gap under the header doesn't change with each flag's shape */
#flag-container {
    flex: 1;
    min-height: 0;
    width: 100%;
    padding: 1.5rem 1rem 1rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* Scale the fade around where the flag sits, not the middle of the empty area */
    transform-origin: 50% 30%;
}

#flag-container img {
    display: block;
    max-width: 100%;
    max-height: 85%;
    border-radius: var(--radius);
    box-shadow: var(--flag-shadow);
    /* Keeps flags with white edges (Japan, Cyprus, Israel) from blending into the page */
    outline: 1px solid var(--flag-edge);
    outline-offset: -1px;
}

#flag-container,
#answers-grid {
    transition: opacity var(--round-fade), transform var(--round-fade);
}

.fade-out {
    opacity: 0;
    transform: scale(0.1);
    pointer-events: none;
}

.pregame-open #flag-container {
    flex: none;
}

.pregame-open #flag-container:empty {
    display: none;
}

#results-message {
    inline-size: 100%;
    max-inline-size: 26rem;
    padding-inline: 1rem;
    text-align: center;
}

#pregame {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    inline-size: 100%;
    max-inline-size: 26rem;
    margin-inline: auto;
    padding: 1rem;
}

#countdown {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: var(--text-sm);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

#countdown.final #countdown-number {
    font-size: 4rem;
    font-weight: 700;
    line-height: 1;
    color: var(--accent);
}

.pregame-actions {
    display: flex;
    gap: 0.5rem;
}

.pregame-actions button {
    min-height: 3.5rem;
    padding: 0.75rem 1.25rem;
    font-size: var(--text-lg);
    font-weight: 700;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

#pregame-ready {
    flex: 1;
}

#pregame-invite:hover {
    background: var(--surface-hover);
}

#pregame h2 {
    margin: 0 0 -0.5rem;
    font-size: var(--text-sm);
    font-weight: 400;
    color: var(--text-muted);
}

#pregame-count {
    font-variant-numeric: tabular-nums;
}

#pregame-players {
    margin: 0;
    padding: 0;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

#pregame-players li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.5rem 0.75rem;
    overflow-wrap: anywhere;
}

#pregame-players li + li {
    border-top: 1px solid var(--border);
}

#pregame-players .me {
    font-weight: 700;
    color: var(--accent);
}

.ready-tag {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--correct);
    white-space: nowrap;
}

.ready-tag::before {
    content: "✓ ";
}

#results-message h2 {
    margin: 0;
    font-size: var(--text-sm);
    font-weight: 400;
    color: var(--text-muted);
}

#results-message .headline {
    margin: 0.25rem 0 1rem;
    font-size: var(--text-xl);
    font-weight: 700;
    overflow-wrap: anywhere;
}

#results-message ol,
#results-message ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* 2nd, 1st, 3rd from left to right; the steps' heights follow the place */
.podium {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 0.5rem;
}

.podium .step {
    flex: 0 1 8rem;
    min-inline-size: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.podium .place-1 { order: 2; }
.podium .place-2 { order: 1; }
.podium .place-3 { order: 3; }

.podium .medal {
    font-size: 2rem;
    line-height: 1;
}

.podium .names li {
    display: flex;
    flex-direction: column;
    overflow-wrap: anywhere;
}

.podium .name {
    font-weight: 700;
}

.podium .points {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* "🌟 Perfect game! +20" under its player's points (always the winner) */
#results-message .perfect {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--accent);
}

.podium .block {
    display: flex;
    justify-content: center;
    padding-top: 0.5rem;
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--surface);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-muted);
}

.podium .place-1 .block { block-size: 5rem; border-color: var(--accent); color: var(--accent); }
.podium .place-2 .block { block-size: 3.5rem; }
.podium .place-3 .block { block-size: 2.5rem; }

.podium .me .name,
.results-rest .me {
    color: var(--accent);
}

/* Everyone below the podium */
#results-message .results-rest {
    margin-top: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    text-align: start;
}

.results-rest li {
    display: flex;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    overflow-wrap: anywhere;
}

.results-rest li + li {
    border-top: 1px solid var(--border);
}

.results-rest .place {
    min-inline-size: 1.5rem;
    color: var(--text-muted);
}

.results-rest .name {
    flex: 1;
}

.results-rest .me .name {
    font-weight: 700;
}

footer {
    flex-shrink: 0;
}

/* Result of the player's last click, next to the buttons; the header status line is the log */
#round-feedback {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0 1rem;
    font-size: var(--text-sm);
}

#round-feedback p {
    margin: 0;
    /* Keeps the row's height when empty, so the grid doesn't jump */
    min-height: 1lh;
}

#feedback-text {
    font-weight: 700;
}

#feedback-text.good {
    color: var(--correct);
}

#feedback-text.bad {
    color: var(--wrong);
}

#points-left {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#answers-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 1fr;
    gap: 0.5rem;
    padding: 1rem;
}

#answers-grid button {
    position: relative;
    min-height: 4rem;
    padding: 0.75rem 1rem;
    font-size: clamp(var(--text-md), 2vh, var(--text-lg));
    text-wrap: balance;
    border: 1px solid var(--border);
    background-color: var(--surface);
    border-radius: var(--radius);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
    #answers-grid button:enabled:hover {
        transform: translateY(-2px);
        background-color: var(--surface-hover);
        box-shadow: var(--lift-shadow);
    }
}

#answers-grid button:enabled:active,
#answers-grid button.pending {
    transform: scale(0.97);
    box-shadow: none;
}

/* Tapped, waiting for the server */
#answers-grid button.pending {
    border-color: var(--accent);
    outline: 1px solid var(--accent);
    outline-offset: -2px;
}

#answers-grid button:disabled {
    cursor: default;
}

/* ✓ and ✗ as well as colour. In CSS, so the PL | EN switch (which resets the text) keeps them. */
#answers-grid button.correct {
    border-color: var(--correct);
    background-color: var(--correct);
    color: var(--on-semantic);
    font-weight: 700;
}

/* Inline blocks, so the wrong answer's strike-through doesn't cross out the mark */
#answers-grid button.correct::before,
#answers-grid button.wrong::before {
    display: inline-block;
    margin-inline-end: 0.3em;
}

#answers-grid button.correct::before {
    content: "✓";
}

#answers-grid button.wrong {
    border-color: var(--wrong);
    color: var(--wrong);
    text-decoration: line-through;
}

#answers-grid button.wrong::before {
    content: "✗";
}

/* A spectator sees the options, but can't pick one */
#answers-grid.spectating button:not(.correct),
#answers-grid button.dimmed:not(.wrong) {
    opacity: 0.45;
}

/* Key hints on desktop; the alt text after "/" keeps them out of the button's spoken name */
@media (hover: hover) and (pointer: fine) {
    #answers-grid button::after {
        content: attr(data-key) / "";
        position: absolute;
        top: 0.25rem;
        left: 0.5rem;
        font-size: 0.75rem;
        color: var(--text-muted);
    }

    #answers-grid button.correct::after {
        color: inherit;
    }
}

/* The answers drawer. Both fill forwards: swap one class for the other, never remove one on a timer. */
.drawer-slide-up {
    animation: slideUp var(--drawer) forwards ease-out;
}

/* Delayed, so the highlighted answer stays in view for a moment */
.drawer-slide-down {
    animation: slideDown var(--drawer) var(--reveal) forwards ease-in;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slideDown {
    from { transform: translateY(0); opacity: 1; }
    to { transform: translateY(100%); opacity: 0; }
}

#confetti-container {
    pointer-events: none;
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: 9999;
}

.confetti-piece {
    position: absolute;
    bottom: -10px;
    border-radius: 2px;
    animation: confetti-fly 3s linear forwards;
}

@keyframes confetti-fly {
    50% { opacity: 1; }
    to { transform: translateY(-110vh) rotate(720deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    /* Keep the opacity fade, drop the scale */
    .fade-out {
        transform: none;
    }

    #answers-grid button:hover,
    #answers-grid button:active,
    #answers-grid button.pending {
        transform: none;
    }

    #confetti-container {
        display: none;
    }

    /* Still fades, so the gain is shown */
    .score-pop {
        animation-name: score-fade;
    }
}

@keyframes score-fade {
    70% { opacity: 1; }
    to { opacity: 0; }
}

/* 404 page for an unknown or expired room */
.not-found {
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    text-align: center;
}

.not-found h1 {
    margin: 0;
    font-size: var(--text-xl);
}

.not-found p {
    margin: 0;
    color: var(--text-muted);
}

.not-found .primary-link {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--on-accent);
    font-size: var(--text-lg);
    font-weight: 700;
    text-decoration: none;
}

.not-found .primary-link:hover {
    background: var(--accent-hover);
}

/* The lobby (/): who is online, and new rooms */
.lobby-page main {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1rem 2rem;
    box-sizing: border-box;
}

.lobby-page .top-bar {
    grid-template-columns: auto 1fr auto;
    align-items: center;
}

.lobby-page h1 {
    grid-column: 3;
    justify-self: end;
    margin: 0;
    font-size: var(--text-lg);
}

/* Lobby <-> leaderboard */
.nav-link {
    grid-column: 2;
    justify-self: end;
    padding: 0.375rem 0.75rem;
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.nav-link:hover {
    background: var(--surface-hover);
}

.new-room {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.new-room button {
    flex: 1 1 12rem;
    min-height: 56px;
    padding: 0.75rem 1.25rem;
    font-size: var(--text-lg);
    font-weight: 700;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.new-room button:hover:enabled {
    background: var(--surface-hover);
}

.new-room button:disabled {
    cursor: wait;
    opacity: 0.6;
}

#new-public {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

#new-public:hover:enabled {
    background: var(--accent-hover);
}

.lobby-page .hint {
    margin: 0.5rem 0 0;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.lobby-page #status:empty {
    display: none;
}

.lobby-page #status {
    margin: 1rem 0 0;
    font-weight: 700;
    color: var(--wrong);
}

.lobby-page h2 {
    margin: 2rem 0 0.5rem;
    font-size: var(--text-md);
}

#online-count {
    font-weight: 400;
    color: var(--text-muted);
}

#online-players {
    margin: 0;
    padding: 0;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

#online-players li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 48px;
    padding: 0.5rem 0.75rem;
}

#online-players li + li {
    border-top: 1px solid var(--border);
}

#online-players .name {
    font-weight: 700;
    overflow-wrap: anywhere;
}

#online-players .me .name::after {
    content: " (you)";
    font-weight: 400;
    color: var(--text-muted);
}

#online-players .points {
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    white-space: nowrap;
}

#online-players .where {
    flex: 1;
    text-align: end;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

#online-players .playing {
    color: var(--correct);
    font-weight: 700;
}

#online-players .join {
    padding: 0.375rem 0.875rem;
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--on-accent);
    text-decoration: none;
    border-radius: var(--radius);
    background: var(--accent);
}

#online-players .join:hover {
    background: var(--accent-hover);
}

#online-players .empty {
    justify-content: center;
    color: var(--text-muted);
}

/* The leaderboard (/leaderboard) */
#leaderboard {
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

#leaderboard li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 48px;
    padding: 0.5rem 0.75rem;
}

#leaderboard li + li {
    border-top: 1px solid var(--border);
}

/* The viewer's own place, below the top of the list */
#leaderboard li.own {
    border-top: 1px dashed var(--border);
    margin-top: 0.25rem;
}

#leaderboard .place {
    min-width: 2ch;
    text-align: end;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

#leaderboard .who {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.5rem;
    min-width: 0;
}

#leaderboard .name {
    font-weight: 700;
    overflow-wrap: anywhere;
}

/* Perfect games: a trophy and how many */
#leaderboard .perfect {
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#leaderboard .points {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    white-space: nowrap;
}

#leaderboard .me .name {
    color: var(--accent);
}

#leaderboard .me .name::after {
    content: " (you)";
    font-weight: 400;
    color: var(--text-muted);
}

.empty-board {
    margin: 0.75rem 0 0;
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.leaderboard-page h2 {
    margin-top: 0;
}

/* --- The account page: a modal over any page (name, devices, linking another device) --- */

.account-page {
    inline-size: min(32rem, calc(100vw - 2rem));
    max-block-size: calc(100dvh - 2rem);
    padding: 0;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--flag-shadow);
}

.account-body {
    padding: 1.25rem;
}

.account-page::backdrop {
    background: rgb(0 0 0 / 0.45);
}

.account-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.account-head h2 {
    margin: 0;
    font-size: var(--text-lg);
    color: var(--accent);
    overflow-wrap: anywhere;
}

.icon-button {
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--text-muted);
}

.icon-button:hover {
    background: var(--surface-hover);
}

.account-points {
    margin: 0.25rem 0 1rem;
    color: var(--text-muted);
}

.account-page .hint {
    margin: 0.25rem 0 0.75rem;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.name-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.name-form label {
    font-weight: 700;
}

.name-form input,
.link-details input {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    padding: 0.25rem 0.5rem;
    font: inherit;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

.name-form input {
    font-weight: 700;
}

.name-form input:focus-visible,
.link-details input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.account-page form button,
.account-section > button,
.link-actions button,
.device-list button,
.toast button:not(.icon-button),
.logged-out button {
    min-height: 40px;
    padding: 0.5rem 1rem;
    font-size: var(--text-sm);
    font-weight: 700;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.account-page button:hover:enabled,
.toast button:hover:enabled {
    background: var(--surface-hover);
}

.account-page button:disabled,
.toast button:disabled {
    cursor: default;
    opacity: 0.5;
}

#link-start,
.logged-out button {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

#link-start:hover:enabled,
.logged-out button:hover {
    background: var(--accent-hover);
}

.danger-button {
    color: var(--wrong);
}

.account-section {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.account-section h3 {
    margin: 0;
    font-size: var(--text-md);
}

.link-box {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-start;
}

/* Dark on white whatever the theme, so every phone camera reads it */
#link-qr {
    inline-size: 200px;
    block-size: 200px;
    background: #fff;
    border-radius: var(--radius);
    transition: opacity var(--fade), filter var(--fade);
}

.link-box.expired #link-qr {
    opacity: 0.25;
    filter: grayscale(1);
}

.link-details {
    flex: 1 1 12rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
}

.link-details input {
    flex: none;
    font-size: var(--text-sm);
}

.link-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.link-box.expired #link-countdown {
    color: var(--wrong);
    font-weight: 700;
}

.device-list {
    margin: 0.5rem 0;
    padding: 0;
    list-style: none;
}

.device-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.device-about {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.device-label {
    font-weight: 700;
}

.this-device {
    margin-inline-start: 0.5rem;
    padding: 0 0.375rem;
    font-size: var(--text-sm);
    font-weight: 400;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 999px;
}

.device-times {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.account-status:empty {
    display: none;
}

.account-status {
    margin: 1rem 0 0;
    font-size: var(--text-sm);
    color: var(--wrong);
}

/* "New device linked" on the account's other devices */
.toast {
    position: fixed;
    inset-inline: 1rem;
    inset-block-end: 1rem;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    max-inline-size: 30rem;
    margin-inline: auto;
    padding: 0.75rem 0.75rem 0.75rem 1rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--lift-shadow);
}

.toast span {
    flex: 1 1 12rem;
}

/* This device was logged out: nothing on the page works any more */
.logged-out {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgb(0 0 0 / 0.6);
}

.logged-out-box {
    max-inline-size: 24rem;
    padding: 1.5rem;
    text-align: center;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--flag-shadow);
}

.logged-out-box p {
    margin: 0 0 1rem;
    font-weight: 700;
}

/* /userlink: link this browser to an account */
.userlink-page h1 {
    overflow-wrap: anywhere;
}

.userlink-page strong {
    color: var(--accent);
}

.userlink-warning {
    max-inline-size: 30rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--tiebreak);
    border-radius: var(--radius);
}

.userlink-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.userlink-page button.primary-link {
    border: 0;
    cursor: pointer;
}

.userlink-page button.primary-link:disabled {
    opacity: 0.5;
    cursor: default;
}

.userlink-actions a:not(.primary-link) {
    color: var(--text-muted);
}

/* Under the game's results: who gave it up */
.gave-up-note {
    margin: 0.75rem 0 0;
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-align: center;
}

/* Right after the name; Ready stays at the far end */
#pregame-players .global-points {
    margin-inline-end: auto;
}
