:root {
    --bg: #f6f5f2;
    --surface: #ffffff;
    --field: #f6f5f2;
    --text: #1d1c1a;
    --muted: #625f59;
    --border: #dedad3;
    --accent: #2f5bd3;
    --accent-text: #ffffff;
    --danger: #b3261e;
    --host: #6d3bd1;
    --you: #1f5fd0;
    --online: #0a7d43;
    --gold: #8f6400;
    --heart: #d92d3a;
    --heart-lost: #b4b0a9;
    --bar: #8fa6e6;
    --bar-out: #b4b0a9;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #161615;
        --surface: #222120;
        --field: #161615;
        --text: #f1efea;
        --muted: #a29f98;
        --border: #3a3936;
        --accent: #7c9bff;
        --accent-text: #10131c;
        --danger: #ff6b6b;
        --host: #c4a1ff;
        --you: #7cb0ff;
        --online: #1fc873;
        --gold: #ffd95a;
        --heart: #f0505c;
        --heart-lost: #5c5a56;
        --bar: #5a6fb0;
        --bar-out: #5c5a56;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #161615;
    --surface: #222120;
    --field: #161615;
    --text: #f1efea;
    --muted: #a29f98;
    --border: #3a3936;
    --accent: #7c9bff;
    --accent-text: #10131c;
    --danger: #ff6b6b;
    --host: #c4a1ff;
    --you: #7cb0ff;
    --online: #1fc873;
    --gold: #ffd95a;
    --heart: #f0505c;
    --heart-lost: #5c5a56;
    --bar: #5a6fb0;
    --bar-out: #5c5a56;
    color-scheme: dark;
}

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

html {
    scrollbar-color: var(--border) var(--bg);
    /* With this on html too, body's clip below applies to body. On body alone the browser moves it to the viewport,
       and a phone then widens the page by the size of the shake. */
    overflow-x: clip;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    caret-color: var(--accent);
    /* The shake moves the whole page; this stops it spilling into a sideways scroll. */
    overflow-x: clip;
}

::selection {
    background: var(--accent);
    color: var(--accent-text);
}

h1, h2 {
    margin: 0;
    text-wrap: balance;
}

h1 {
    font-size: 2rem;
    letter-spacing: -0.02em;
}

h1:focus {
    outline: none;
}

/* Page frame */

.top-bar {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    min-height: 3.25rem;
    padding: 0.75rem 1rem 0;
}

.page {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 90rem;
    margin: 0 auto;
    padding: 0.5rem 1rem 2rem;
}

.page-start {
    align-items: center;
}

.page-start h1,
.start-card {
    width: 100%;
    max-width: 28rem;
}

.credit {
    padding: 0 1rem 1rem;
    color: var(--muted);
    font-size: 0.75rem;
    text-align: center;
}

.credit a {
    color: inherit;
    text-underline-offset: 2px;
}

.card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
}

/* Controls */

label, .label {
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
}

input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font: inherit;
    color: var(--text);
    background: var(--field);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

input::placeholder {
    color: var(--muted);
    opacity: 1;
}

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

.code-input {
    text-transform: uppercase;
    letter-spacing: 0.3em;
}

button {
    padding: 0.6rem 1rem;
    font: inherit;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: filter 120ms ease-out;
}

button:hover:not(:disabled) {
    filter: brightness(1.1);
}

button.secondary {
    color: var(--text);
    background: transparent;
    border-color: var(--border);
}

button.secondary:hover:not(:disabled) {
    filter: none;
    border-color: var(--muted);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.small {
    padding: 0.35rem 0.75rem;
    font-size: 0.9rem;
}

.icon-button {
    height: fit-content;
}

.when-dark,
.when-light,
.when-unmuted,
.when-muted {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.when-muted {
    display: none;
}

:root[data-muted] .when-muted {
    display: inline-flex;
}

:root[data-muted] .when-unmuted {
    display: none;
}

.when-dark {
    display: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .when-dark {
        display: inline-flex;
    }

    :root:not([data-theme="light"]) .when-light {
        display: none;
    }
}

:root[data-theme="dark"] .when-dark {
    display: inline-flex;
}

:root[data-theme="dark"] .when-light {
    display: none;
}

.icon-button svg {
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.row {
    display: flex;
    gap: 0.5rem;
}

.row input {
    flex: 1;
    min-width: 0;
}

.divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.5rem 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.divider::before, .divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--border);
}

/* Messages */

.muted {
    margin: 0;
    color: var(--muted);
}

.status {
    margin: 0;
    color: var(--muted);
    text-align: center;
}

.error {
    margin: 0;
    color: var(--danger);
    font-weight: 600;
    text-align: center;
}

/* Stays in view wherever the player has scrolled to. Cleared by their next action. */
.page-error {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    left: 1rem;
    z-index: 10;
    width: fit-content;
    max-width: calc(100% - 2rem);
    margin-inline: auto;
    padding: 0.6rem 1rem;
    background: var(--surface);
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgb(0 0 0 / 0.35);
}

.online {
    margin: 1rem 0 0;
    font-size: clamp(1.5rem, 4vw, 3rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.15;
    text-align: center;
    text-wrap: balance;
}

.online-count {
    color: var(--online);
    font-variant-numeric: tabular-nums;
}

/* Room bar */

.room-block {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

.brand {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.room-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
}

.room-bar button {
    margin-left: auto;
}

.room-code-inline {
    letter-spacing: 0.15em;
}

.you-are {
    color: var(--you);
    overflow-wrap: anywhere;
}

/* Player lists */

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

.players li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.tags {
    display: inline-flex;
    flex-shrink: 0;
    gap: 0.35rem;
}

.tag {
    padding: 0.05rem 0.45rem;
    font-size: 0.75rem;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.tag.host {
    color: var(--host);
    border-color: var(--host);
}

.tag.you {
    color: var(--you);
    border-color: var(--you);
}

/* The developer's draft: every player has a bar by their name, which goes monochrome when they're out. */
.game-players li {
    padding-left: 0.6rem;
    border-left: 3px solid var(--bar);
}

.game-players li.current {
    font-weight: 700;
    border-left-color: var(--accent);
}

.game-players li.out {
    color: var(--muted);
    border-left-color: var(--bar-out);
}

.player-name {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
}

.hearts {
    display: inline-flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.1rem;
    max-width: 5.75rem;
}

.heart {
    width: 1.05rem;
    height: 1.05rem;
    overflow: visible;
}

.heart path {
    fill: var(--heart-lost);
    transform-box: fill-box;
}

.heart.full path {
    fill: var(--heart);
}

.heart.breaking path {
    animation: 750ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.heart.breaking .left {
    transform-origin: 100% 100%;
    animation-name: heart-break-left;
}

.heart.breaking .right {
    transform-origin: 0% 100%;
    animation-name: heart-break-right;
}

@keyframes heart-break-left {
    0% { fill: var(--heart); transform: none; }
    45% { fill: var(--heart); transform: translate(-12%, 6%) rotate(-20deg); }
    100% { fill: var(--heart-lost); transform: none; }
}

@keyframes heart-break-right {
    0% { fill: var(--heart); transform: none; }
    45% { fill: var(--heart); transform: translate(12%, 6%) rotate(20deg); }
    100% { fill: var(--heart-lost); transform: none; }
}

/* Avatars */

.avatar {
    display: block;
    width: 4.5rem;
    height: 4.5rem;
    object-fit: contain;
    user-select: none;
}

.avatar.out {
    filter: grayscale(1) brightness(0.75);
}

.avatar-small {
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
}

.avatar-hero {
    width: clamp(5rem, 16vh, 9rem);
    height: clamp(5rem, 16vh, 9rem);
}

/* Lobby */

.lobby-grid {
    display: grid;
    grid-template-columns: minmax(0, 30rem) minmax(0, 36rem);
    gap: 2.5rem 4rem;
    justify-content: center;
    align-items: start;
}

.lobby-main {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.avatar-picker h2,
.how-to-play h2 {
    font-size: clamp(1.75rem, 4vw, 3.25rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.avatar-picker h2 {
    margin-bottom: 1.25rem;
    text-align: center;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
}

.avatar-choice {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-width: 0;
    padding: 0.5rem 0.25rem;
    color: var(--muted);
    background: transparent;
    border: 2px solid transparent;
    border-radius: 0.75rem;
    transition: transform 160ms cubic-bezier(0.16, 1, 0.3, 1), border-color 120ms ease-out;
}

.avatar-choice .avatar {
    width: clamp(3.5rem, 8vw, 6rem);
    height: clamp(3.5rem, 8vw, 6rem);
}

.avatar-choice:hover:not(:disabled) {
    filter: none;
    transform: translateY(-3px);
    border-color: var(--border);
}

.avatar-choice.mine {
    color: var(--you);
    border-color: var(--you);
}

.avatar-choice:disabled {
    opacity: 1;
}

.avatar-choice.taken .avatar {
    opacity: 0.35;
}

.avatar-owner {
    display: block;
    width: 100%;
    min-height: 1.25rem;
    overflow: hidden;
    font-size: 0.8rem;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.how-to-play {
    grid-column: 1 / -1;
    justify-self: center;
    width: 100%;
    max-width: 44rem;
    font-size: 1.15rem;
}

.how-to-play h2 {
    margin-bottom: 1rem;
    text-align: center;
}

.how-to-play ol {
    margin: 0 0 0.75rem;
    padding-left: 1.5rem;
}

.how-to-play li + li {
    margin-top: 0.5rem;
}

.how-to-play p {
    margin: 0;
}

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

.settings {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 6rem;
    align-items: center;
    gap: 0.5rem;
}

/* Game and results */

.game-grid {
    display: grid;
    grid-template-columns: minmax(13rem, 1fr) minmax(0, 40rem) minmax(13rem, 1fr);
    gap: 2rem;
    align-items: start;
}

.stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    text-align: center;
}

.stage h1 {
    font-size: clamp(2rem, 5vw, 4.25rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.eliminated {
    margin: 0.25rem 0 0;
    color: var(--danger);
    font-size: clamp(1.1rem, 2.5vw, 2rem);
    font-weight: 700;
}

.timer {
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.next-box {
    min-width: 11rem;
    max-width: 100%;
    padding: 0.75rem 1.25rem;
    background: var(--surface);
    border-radius: 0.5rem;
    text-align: left;
}

.letter {
    margin: 0.25rem 0;
    font-size: clamp(3rem, 8vw, 4.5rem);
    font-weight: 800;
    letter-spacing: 0.02em;
    line-height: 1;
    overflow-wrap: anywhere;
}

.round-note {
    max-width: 20rem;
    font-size: 0.85rem;
}

.word-row {
    width: 100%;
    max-width: 34rem;
}

.word-row input,
.word-row button {
    padding-block: 0.85rem;
    font-size: 1.15rem;
}

.event {
    font-size: 0.95rem;
}

.lineup {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem 1.5rem;
    margin-top: 0.5rem;
}

.lineup .avatar {
    width: clamp(3rem, 6.5vw, 5.5rem);
    height: clamp(3rem, 6.5vw, 5.5rem);
}

.stage .room-block {
    max-width: 30rem;
    margin-top: 1rem;
    text-align: left;
}

.words {
    margin: 0;
    padding-left: 1.5rem;
    overflow-wrap: anywhere;
}

.recent-word {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    vertical-align: middle;
}

.avatar-word {
    flex-shrink: 0;
    width: 1.1rem;
    height: 1.1rem;
}

.placing p {
    margin: 0 0 0.5rem;
    font-size: clamp(1.05rem, 2vw, 1.5rem);
    font-weight: 700;
}

.placing .avatar {
    margin-inline: auto;
}

.placing.first p {
    color: var(--gold);
    font-size: clamp(1.25rem, 2.4vw, 1.9rem);
}

.podium-rest {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem 2rem;
    margin-top: 0.75rem;
}

.result-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* A lost life shakes that player's avatar, wherever it's showing. */

.avatar-hurt {
    animation: avatar-hurt 600ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes avatar-hurt {
    10% { transform: translateX(-14%) rotate(-8deg); }
    30% { transform: translateX(12%) rotate(7deg); }
    50% { transform: translateX(-9%) rotate(-5deg); }
    70% { transform: translateX(6%) rotate(3deg); }
    90% { transform: translateX(-2%) rotate(-1deg); }
}

/* A wrong word shakes the page a little. */

.shake {
    animation: shake 420ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shake {
    15% { transform: translateX(-7px); }
    35% { transform: translateX(6px); }
    55% { transform: translateX(-4px); }
    75% { transform: translateX(3px); }
    90% { transform: translateX(-1px); }
}

@media (prefers-reduced-motion: reduce) {
    .shake,
    .avatar-hurt,
    .heart.breaking path {
        animation: none;
    }

    .avatar-choice:hover:not(:disabled) {
        transform: none;
    }
}

/* Narrower screens stack: the turn first, then the lists. */

@media (max-width: 68rem) {
    .game-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 1.25rem;
    }

    .stage {
        grid-column: 1 / -1;
        grid-row: 1;
    }
}

@media (max-width: 52rem) {
    /* Small enough that the word box stays above an on-screen keyboard. */
    .avatar-hero {
        width: 4.5rem;
        height: 4.5rem;
    }

    .stage {
        gap: 0.5rem;
    }

    .lobby-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 1.75rem;
    }

    .game-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.blazor-error-boundary {
    padding: 1rem;
    color: #ffffff;
    background: #b32121;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}
