:root {
    --night: #0B0D24;
    --sky: #1C2156;
    --ink: #F7F1E3;
    --muted: #A9AFD1;
    --gold: #F4C95D;
    --gold-deep: #D99A2B;
    --rose: #EF476F;
    --mint: #2EE6A8;
    --card: rgba(24, 28, 70, 0.72);
    --line: rgba(170, 180, 255, 0.2);
    --chalk: #FDF3D8;

    --display: 'Fredoka', system-ui, sans-serif;
    --font: 'Nunito', system-ui, sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --hud-height: 56px;

    color-scheme: dark;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.45;
    color: var(--ink);
    background: #3E2A1D;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

[hidden] {
    display: none !important;
}

button {
    font: inherit;
    color: inherit;
    border: none;
    background: none;
    cursor: pointer;
}

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

.ms {
    font-family: 'Material Symbols Rounded';
    font-size: 22px;
    line-height: 1;
    font-feature-settings: 'liga';
    user-select: none;
}

/* Sparks and confetti in front of the page */
.sparks {
    position: fixed;
    inset: 0;
    z-index: 50;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Home: a blackboard on a classroom wall. The title is a hangman puzzle solving itself, the gallows is drawn in chalk */
.board {
    --slate: #22463A;
    --chalk-white: #F3EFE2;
    --chalk-yellow: #F7E27A;
    --chalk-pink: #F4A6B8;
    --hand: 'Caveat', 'Comic Sans MS', cursive;
    position: relative;
    z-index: 2;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(22px + var(--safe-top)) 16px calc(26px + var(--safe-bottom));
    background:
        radial-gradient(ellipse 70% 50% at 50% 0%, rgba(255, 220, 160, 0.16), transparent 70%),
        repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.05) 0 2px, transparent 2px 120px),
        linear-gradient(180deg, #5B3F2B, #3E2A1D);
}

.board-frame {
    position: relative;
    width: min(1060px, 100%);
    padding: 16px;
    border-radius: 10px;
    background: linear-gradient(135deg, #A87446, #7A4E2C 40%, #95633A 70%, #6B4325);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.45), inset 0 2px 0 rgba(255, 230, 190, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.3);
}

.board-surface {
    position: relative;
    overflow: hidden;
    padding: 22px clamp(18px, 4vw, 44px) 30px;
    border-radius: 4px;
    color: var(--chalk-white);
    font-family: var(--hand);
    background:
        radial-gradient(ellipse 30% 18% at 22% 76%, rgba(255, 255, 255, 0.07), transparent 70%),
        radial-gradient(ellipse 36% 22% at 78% 22%, rgba(255, 255, 255, 0.06), transparent 70%),
        radial-gradient(ellipse 22% 12% at 60% 88%, rgba(255, 255, 255, 0.05), transparent 70%),
        radial-gradient(ellipse at 50% 40%, #2A5344, var(--slate) 70%, #1B3A30);
    box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.45);
}

/* Old eraser sweeps left on the board */
.board-surface::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(100deg, transparent 8%, rgba(255, 255, 255, 0.035) 10%, rgba(255, 255, 255, 0.035) 24%, transparent 26%),
        linear-gradient(80deg, transparent 58%, rgba(255, 255, 255, 0.03) 60%, rgba(255, 255, 255, 0.03) 72%, transparent 74%);
}

.board-top {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chalk-scribble {
    font-size: 24px;
    font-weight: 500;
    color: rgba(243, 239, 226, 0.75);
    transform: rotate(-2deg);
    border-bottom: 2px solid rgba(243, 239, 226, 0.35);
}

.board .lang-switch {
    display: flex;
    gap: 6px;
}

.board .lang-switch button {
    min-width: 46px;
    height: 36px;
    padding: 0 8px;
    border-radius: 50%;
    font-family: var(--hand);
    font-size: 24px;
    font-weight: 700;
    color: rgba(243, 239, 226, 0.6);
}

/* The chosen language gets a chalk circle round it */
.board .lang-switch button[aria-pressed="true"] {
    color: var(--chalk-yellow);
    box-shadow: 0 0 0 2px rgba(247, 226, 122, 0.8), 0 0 10px rgba(247, 226, 122, 0.25);
    transform: rotate(-4deg);
}

.board-grid {
    position: relative;
    margin-top: 10px;
    display: grid;
    grid-template-columns: minmax(180px, 0.8fr) 1.4fr;
    gap: clamp(16px, 4vw, 48px);
    align-items: center;
}

.board-art {
    text-align: center;
}

.chalk-art {
    width: 100%;
    max-width: 280px;
    height: auto;
}

.chalk-lines .draw {
    fill: none;
    stroke: var(--chalk-white);
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    transition: stroke-dashoffset 0.55s ease-out, opacity 0.6s;
}

.chalk-lines .draw.on {
    stroke-dashoffset: 0;
}

.chalk-lines.wiping .draw {
    opacity: 0;
}

.chalk-lines.resetting .draw {
    transition: none;
}

.misses {
    margin-top: 4px;
    font-size: 26px;
    color: var(--chalk-pink);
}

.misses s {
    margin: 0 3px;
    text-decoration-thickness: 2px;
}

/* Title: one tile per letter over a chalk dash; letters appear in a shuffled order as if guessed */
.chalk-title {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 22px;
    font-family: var(--hand);
    font-weight: 700;
    line-height: 1;
}

.chalk-word {
    display: inline-flex;
    gap: clamp(3px, 0.8vw, 8px);
}

.chalk-tile {
    position: relative;
    width: clamp(30px, 5.4vw, 58px);
    height: clamp(46px, 7.6vw, 80px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-size: clamp(40px, 7vw, 76px);
    color: var(--chalk-white);
    text-shadow: 0 0 1px rgba(255, 255, 255, 0.6);
}

.chalk-tile::after {
    content: '';
    position: absolute;
    left: 8%;
    right: 8%;
    bottom: -4px;
    height: 3px;
    border-radius: 2px;
    background: rgba(243, 239, 226, 0.7);
}

.chalk-tile span {
    opacity: 0;
    transform: translateY(-8px) rotate(-6deg) scale(0.8);
    animation: chalk-letter 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) forwards;
    animation-delay: var(--d);
}

.chalk-word:last-child .chalk-tile span {
    color: var(--chalk-yellow);
}

@keyframes chalk-letter {
    to { opacity: 1; transform: none; }
}

.chalk-intro {
    margin-top: 22px;
    max-width: 560px;
    font-size: clamp(21px, 2.4vw, 25px);
    line-height: 1.25;
    color: rgba(243, 239, 226, 0.9);
}

.chalk-label {
    display: block;
    margin-top: 16px;
    font-size: 24px;
    font-weight: 700;
    color: var(--chalk-yellow);
}

/* Name field: just a chalk line to write on */
.chalk-input {
    width: min(360px, 100%);
    height: 44px;
    padding: 0 4px;
    border: none;
    border-bottom: 3px dashed rgba(243, 239, 226, 0.55);
    background: transparent;
    color: var(--chalk-white);
    font-family: var(--hand);
    font-size: 28px;
    font-weight: 700;
}

.chalk-input::placeholder {
    color: rgba(243, 239, 226, 0.35);
    font-weight: 500;
}

.chalk-input:focus {
    outline: none;
    border-bottom-style: solid;
    border-bottom-color: var(--chalk-yellow);
}

.chalk-actions {
    margin-top: 22px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
}

/* Main button: a yellow sticky note pinned to the board */
.chalk-primary {
    position: relative;
    min-height: 58px;
    padding: 10px 26px;
    border-radius: 3px 3px 14px 3px;
    background: linear-gradient(170deg, #FFF08F, #F6D84E);
    color: #3A2A06;
    font-family: var(--hand);
    font-size: 27px;
    font-weight: 700;
    line-height: 1.05;
    transform: rotate(-1.5deg);
    box-shadow: 0 10px 18px rgba(0, 0, 0, 0.35), inset 0 -8px 12px rgba(160, 120, 0, 0.12);
    transition: transform 0.15s, box-shadow 0.15s;
}

.chalk-primary::before {
    content: '';
    position: absolute;
    top: -9px;
    left: 50%;
    width: 16px;
    height: 16px;
    margin-left: -8px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #FF8A8A, #C6283A);
    box-shadow: 0 3px 4px rgba(0, 0, 0, 0.4);
}

.chalk-primary:hover {
    transform: rotate(0deg) translateY(-2px);
    box-shadow: 0 14px 24px rgba(0, 0, 0, 0.4), inset 0 -8px 12px rgba(160, 120, 0, 0.12);
}

/* Second button: circled in chalk */
.chalk-secondary {
    min-height: 54px;
    padding: 8px 22px;
    border: 3px solid rgba(243, 239, 226, 0.7);
    border-radius: 48% 52% 46% 54% / 60% 44% 56% 40%;
    font-family: var(--hand);
    font-size: 25px;
    font-weight: 700;
    color: var(--chalk-white);
    transform: rotate(1deg);
    transition: background 0.15s, transform 0.15s;
}

.chalk-secondary:hover {
    background: rgba(243, 239, 226, 0.08);
    transform: rotate(-1deg);
}

.chalk-note {
    margin-top: 18px;
    max-width: 560px;
    font-size: 20px;
    line-height: 1.2;
    color: rgba(243, 239, 226, 0.6);
}

.chalk-room {
    margin-top: 12px;
}

.chalk-room .chalk-label {
    display: inline;
    margin-right: 10px;
}

#guest-room {
    font-family: var(--hand);
    font-size: 36px;
    font-weight: 700;
    color: var(--chalk-yellow);
    border-bottom: 3px solid rgba(247, 226, 122, 0.6);
}

/* Chalk tray under the board */
.tray {
    position: relative;
    height: 16px;
    margin: 10px -6px -4px;
    border-radius: 3px;
    background: linear-gradient(180deg, #8C5C34, #5E3B20);
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.35);
}

.tray i {
    position: absolute;
    bottom: 9px;
    height: 9px;
    border-radius: 3px;
}

.stick {
    left: 12%;
    width: 46px;
    background: #F3EFE2;
}

.stick-yellow {
    left: 17%;
    width: 30px;
    background: var(--chalk-yellow);
    transform: rotate(-6deg);
}

.stick-pink {
    left: 21%;
    width: 38px;
    background: var(--chalk-pink);
}

.eraser {
    right: 14%;
    width: 72px;
    height: 16px !important;
    background: linear-gradient(180deg, #C98C4A 0 45%, #3C3F4E 45%);
}

@media (max-width: 720px) {
    .board {
        align-items: flex-start;
        padding: calc(10px + var(--safe-top)) 8px calc(16px + var(--safe-bottom));
    }

    .board-frame {
        padding: 10px;
    }

    .board-surface {
        padding: 16px 16px 24px;
    }

    .board-grid {
        grid-template-columns: 1fr;
    }

    .board-art {
        order: 2;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
    }

    .chalk-art {
        max-width: 130px;
    }

    .chalk-actions > * {
        flex: 1 1 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chalk-tile span {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .chalk-lines .draw {
        transition: none;
    }
}

/* Form pieces shared with the game screen */
.field-label {
    margin-top: 20px;
    font-size: 14px;
    font-weight: 700;
    color: var(--muted);
}

.text-input {
    margin-top: 8px;
    height: 48px;
    padding: 0 14px;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: rgba(12, 14, 40, 0.6);
    color: var(--ink);
    font: inherit;
    font-weight: 700;
    min-width: 0;
}

.text-input::placeholder {
    color: rgba(169, 175, 209, 0.55);
    font-weight: 500;
}

.text-input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 4px rgba(244, 201, 93, 0.15);
}

.primary-button,
.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 14px;
    font-weight: 800;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.primary-button {
    height: 54px;
    padding: 0 22px;
    background: linear-gradient(180deg, #FFDF85, var(--gold) 55%, var(--gold-deep));
    color: #22160A;
    font-size: 17px;
    box-shadow: 0 8px 26px rgba(244, 201, 93, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.primary-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(244, 201, 93, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.primary-button:active {
    transform: translateY(0) scale(0.98);
}

.secondary-button {
    height: 48px;
    padding: 0 18px;
    border: 1px solid var(--line);
    background: rgba(24, 28, 70, 0.6);
}

.secondary-button:hover {
    background: rgba(40, 46, 110, 0.7);
}

.room-code-inline {
    font-family: var(--display);
    font-size: 30px;
    font-weight: 700;
    color: var(--gold);
    text-shadow: 0 0 18px rgba(244, 201, 93, 0.4);
}

/* Game screen: the same blackboard, filling the screen */
.game-screen {
    --slate: #22463A;
    --chalk-white: #F3EFE2;
    --chalk-yellow: #F7E27A;
    --chalk-pink: #F4A6B8;
    --hand: 'Caveat', 'Comic Sans MS', cursive;
    position: fixed;
    inset: 0;
    z-index: 1;
    display: flex;
    padding: calc(8px + var(--safe-top)) 8px calc(10px + var(--safe-bottom));
    background:
        radial-gradient(ellipse 70% 50% at 50% 0%, rgba(255, 220, 160, 0.16), transparent 70%),
        repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.05) 0 2px, transparent 2px 120px),
        linear-gradient(180deg, #5B3F2B, #3E2A1D);
}

.game-board {
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 12px;
}

.game-surface {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.hud {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--hud-height);
    padding: 6px 14px;
    border-bottom: 2px dashed rgba(243, 239, 226, 0.25);
    font-family: var(--hand);
}

.hud-button {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: rgba(243, 239, 226, 0.75);
    flex: none;
    transition: box-shadow 0.15s, color 0.15s;
}

.hud-button:hover {
    color: var(--chalk-yellow);
    box-shadow: 0 0 0 2px rgba(247, 226, 122, 0.7);
}

.hud-round {
    font-size: 24px;
    font-weight: 700;
    color: rgba(243, 239, 226, 0.8);
    white-space: nowrap;
}

.scoreboard {
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.score {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.score-name {
    font-size: 22px;
    font-weight: 700;
    color: rgba(243, 239, 226, 0.75);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 22vw;
}

.score-value {
    font-size: 38px;
    font-weight: 700;
    line-height: 1;
    color: var(--chalk-yellow);
}

.score-value.bump {
    animation: bump 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.6);
}

@keyframes bump {
    40% { transform: scale(1.6) rotate(-6deg); color: #FFFFFF; }
}

.score-sep {
    font-size: 30px;
    color: rgba(243, 239, 226, 0.5);
}

.hud-status {
    font-size: 20px;
    color: rgba(243, 239, 226, 0.6);
    white-space: nowrap;
}

.hud-status.is-live::before {
    content: '';
    display: inline-block;
    width: 9px;
    height: 9px;
    margin-right: 6px;
    border-radius: 50%;
    background: #9BE8B5;
    box-shadow: 0 0 6px #9BE8B5;
}

.arena {
    flex: 1;
    min-height: 0;
    display: flex;
    gap: 24px;
    align-items: center;
    justify-content: center;
    padding: 10px 22px 16px;
}

.stage {
    flex: 0 1 440px;
    min-width: 0;
    height: 100%;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.scene {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow: visible;
}

.panel {
    flex: 0 1 580px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Gallows, rope and ground in chalk */
.chalk-scene path,
.rope path {
    fill: none;
    stroke: var(--chalk-white);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chalk-scene .ground {
    stroke-width: 4;
    stroke: rgba(243, 239, 226, 0.6);
}

.chalk-scene .tuft {
    stroke-width: 2.5;
    stroke: rgba(155, 232, 181, 0.7);
}

.rope path {
    stroke: #E8D3A8;
    stroke-width: 4;
}

/* The chalk man */
.man .stroke {
    fill: none;
    stroke: var(--chalk-white);
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    transition: stroke-dashoffset 0.6s cubic-bezier(0.6, 0, 0.3, 1), stroke 0.6s;
}

.man .part.on .stroke,
.man .part.on.stroke {
    stroke-dashoffset: 0;
}

.man .eyes,
.man .mouth,
.man .sweat {
    opacity: 0;
    transition: opacity 0.4s 0.4s;
}

.man .eyes {
    fill: var(--chalk-white);
}

.man .mouth {
    fill: none;
    stroke: var(--chalk-white);
    stroke-width: 3;
    stroke-linecap: round;
    transition: opacity 0.4s 0.4s, d 0.4s;
}

.man .part.on .eyes,
.man .part.on .mouth {
    opacity: 1;
}

.man .sweat {
    fill: #9FD8F2;
    transform-box: view-box;
}

.man.nervous .sweat {
    opacity: 0.9;
    animation: drip 1.6s ease-in infinite;
}

@keyframes drip {
    0% { transform: translateY(0); opacity: 0.9; }
    80% { transform: translateY(18px); opacity: 0; }
    100% { transform: translateY(18px); opacity: 0; }
}

.man.dead .eyes {
    opacity: 0;
}

/* Swings on the rope once there's a head */
.man.swaying,
.rope.swaying {
    transform-box: view-box;
    transform-origin: 215px 45px;
    animation: sway 3.4s ease-in-out infinite;
}

@keyframes sway {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
}

.scene.shake {
    animation: shake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shake {
    15%, 85% { transform: translateX(-3px) rotate(-0.5deg); }
    30%, 70% { transform: translateX(6px) rotate(0.8deg); }
    45%, 55% { transform: translateX(-8px) rotate(-1deg); }
}

.stage.flash-miss::after,
.stage.flash-hit::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    animation: flash 0.6s ease-out forwards;
}

.stage.flash-miss::after {
    background: radial-gradient(circle, transparent 40%, rgba(244, 110, 140, 0.3));
}

.stage.flash-hit::after {
    background: radial-gradient(circle, transparent 50%, rgba(247, 226, 122, 0.18));
}

@keyframes flash {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Saved: the rope snaps, he drops to the ground and cheers, drawn in yellow chalk */
.scene.saved .man .stroke,
.scene.saved .man .mouth {
    stroke: var(--chalk-yellow);
}

.scene.saved .man .eyes {
    fill: var(--chalk-yellow);
}

.scene.saved .rope {
    animation: snap 0.6s ease-in forwards;
}

@keyframes snap {
    to { transform: translateY(-30px); opacity: 0; }
}

.scene.saved .man {
    transform-box: view-box;
    animation: land 0.55s cubic-bezier(0.5, 0, 1, 1) forwards, hop 0.7s 0.6s ease-in-out infinite;
}

@keyframes land {
    to { transform: translateY(46px); }
}

@keyframes hop {
    0%, 100% { transform: translateY(46px); }
    50% { transform: translateY(26px); }
}

.scene.saved .arm {
    transform-box: view-box;
    transform-origin: 215px 160px;
    transition: transform 0.5s 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

.scene.saved .arm-left {
    transform: rotate(95deg);
}

.scene.saved .arm-right {
    transform: rotate(-95deg);
}

/* Lost: he is half wiped off the board and floats up like a ghost */
.scene.lost .man .stroke,
.scene.lost .man .mouth {
    stroke: #BFD7FF;
}

.scene.lost .man {
    transform-box: view-box;
    animation: ghost 2.6s 0.6s ease-out forwards;
}

@keyframes ghost {
    to { transform: translateY(-34px); opacity: 0.4; }
}

.lives-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
    font-family: var(--hand);
    font-size: 22px;
    font-weight: 700;
    color: rgba(243, 239, 226, 0.75);
}

.hearts {
    display: flex;
    gap: 5px;
}

.heart {
    font-size: 22px;
    color: var(--chalk-pink);
    transition: color 0.3s, transform 0.3s, opacity 0.3s;
}

.heart.gone {
    color: rgba(243, 239, 226, 0.25);
    transform: scale(0.8);
}

.heart.breaking {
    animation: heartbreak 0.6s ease-out;
}

@keyframes heartbreak {
    30% { transform: scale(1.5) rotate(-12deg); color: #FFFFFF; }
    100% { transform: scale(0.8); }
}

/* The word: chalk letters on chalk dashes, like the title on the home screen */
.hint {
    font-family: var(--hand);
    font-size: 28px;
    font-weight: 700;
    color: var(--chalk-yellow);
    text-align: center;
}

.tiles {
    margin: 18px 0 8px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px 8px;
}

.tile {
    position: relative;
    width: clamp(28px, 6.4vw, 46px);
    height: clamp(42px, 9vw, 62px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-family: var(--hand);
    font-size: clamp(34px, 6.6vw, 54px);
    font-weight: 700;
    line-height: 1;
    color: var(--chalk-white);
}

.tile::after {
    content: '';
    position: absolute;
    left: 6%;
    right: 6%;
    bottom: -5px;
    height: 3px;
    border-radius: 2px;
    background: rgba(243, 239, 226, 0.7);
}

.tile.gap {
    width: 16px;
}

.tile.gap::after {
    display: none;
}

.tile.shown {
    animation: write-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
    animation-delay: calc(var(--i, 0) * 0.07s);
}

.tile.shown.fresh {
    color: var(--chalk-yellow);
}

@keyframes write-in {
    from { opacity: 0; transform: translateY(-10px) rotate(-8deg) scale(0.8); }
}

.tile.known {
    color: rgba(243, 239, 226, 0.4);
}

.tile.missed {
    color: var(--chalk-pink);
    animation: write-in 0.5s both;
    animation-delay: calc(var(--i, 0) * 0.06s);
}

.tile.missed::after {
    background: var(--chalk-pink);
}

.watching {
    margin: 10px 0;
    text-align: center;
    font-family: var(--hand);
    font-size: 24px;
    color: rgba(243, 239, 226, 0.7);
}

/* Keyboard: letters chalked on the board; a hit gets a yellow circle, a miss is crossed out in pink */
.keys {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    gap: 6px;
}

.key {
    height: 46px;
    border-radius: 46% 54% 50% 50% / 52% 48% 52% 48%;
    border: 2px solid rgba(243, 239, 226, 0.28);
    font-family: var(--hand);
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
    color: var(--chalk-white);
    transition: transform 0.1s, border-color 0.15s, background 0.15s, color 0.2s;
}

.key:hover:not(:disabled) {
    transform: rotate(-4deg) scale(1.06);
    border-color: rgba(243, 239, 226, 0.7);
    background: rgba(243, 239, 226, 0.06);
}

.key:active:not(:disabled) {
    transform: scale(0.94);
}

.key:disabled {
    cursor: default;
}

.key.hit {
    border-color: var(--chalk-yellow);
    color: var(--chalk-yellow);
    box-shadow: 0 0 10px rgba(247, 226, 122, 0.25);
    animation: pop 0.35s ease-out;
}

.key.miss {
    border-color: transparent;
    color: rgba(244, 166, 184, 0.75);
    text-decoration: line-through;
    text-decoration-thickness: 3px;
    animation: pop 0.35s ease-out;
}

.keys.locked .key:not(.hit):not(.miss) {
    opacity: 0.4;
}

@keyframes pop {
    40% { transform: scale(1.2) rotate(-6deg); }
}

/* Guess the whole word on a chalk line */
.word-guess {
    margin-top: 16px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
}

.word-guess .text-input {
    margin-top: 0;
    height: 46px;
    padding: 0 4px;
    border: none;
    border-bottom: 3px dashed rgba(243, 239, 226, 0.55);
    border-radius: 0;
    background: transparent;
    color: var(--chalk-white);
    font-family: var(--hand);
    font-size: 28px;
    text-transform: uppercase;
    box-shadow: none;
}

.word-guess .text-input::placeholder {
    color: rgba(243, 239, 226, 0.35);
    text-transform: none;
}

.word-guess .text-input:focus {
    border-bottom-style: solid;
    border-bottom-color: var(--chalk-yellow);
}

.guess-cost {
    grid-column: 1 / -1;
    font-family: var(--hand);
    font-size: 19px;
    color: rgba(243, 239, 226, 0.55);
}

/* Paper notes pinned to the board: picking the word, waiting, round results and messages */
.card {
    position: relative;
    border: none;
    border-radius: 3px;
    color: #2E2A24;
    background:
        repeating-linear-gradient(180deg, transparent 0 29px, rgba(80, 120, 190, 0.22) 29px 30px),
        linear-gradient(180deg, #FFFBEA, #F6EBC8);
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.4);
    font-family: var(--hand);
    transform: rotate(-0.6deg);
}

.card::before {
    content: '';
    position: absolute;
    top: -9px;
    left: 50%;
    width: 18px;
    height: 18px;
    margin-left: -9px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #FF8A8A, #C6283A);
    box-shadow: 0 3px 4px rgba(0, 0, 0, 0.4);
}

.card .field-label {
    font-family: var(--hand);
    font-size: 22px;
    color: #6B5A3C;
}

.card .text-input {
    height: 44px;
    border: none;
    border-bottom: 3px solid rgba(46, 42, 36, 0.35);
    border-radius: 0;
    background: transparent;
    color: #2E2A24;
    font-family: var(--hand);
    font-size: 26px;
    box-shadow: none;
}

.card .text-input::placeholder {
    color: rgba(46, 42, 36, 0.4);
}

.card .text-input:focus {
    border-bottom-color: #C6283A;
    box-shadow: none;
}

/* Buttons: a yellow sticky note and a hand-drawn outline, as on the home screen */
.game-screen .primary-button {
    min-height: 50px;
    height: auto;
    padding: 8px 22px;
    border-radius: 3px 3px 12px 3px;
    background: linear-gradient(170deg, #FFF08F, #F6D84E);
    color: #3A2A06;
    font-family: var(--hand);
    font-size: 25px;
    font-weight: 700;
    line-height: 1.05;
    box-shadow: 0 8px 14px rgba(0, 0, 0, 0.3);
    transform: rotate(-1deg);
}

.game-screen .primary-button:hover {
    transform: rotate(0deg) translateY(-2px);
    box-shadow: 0 12px 20px rgba(0, 0, 0, 0.35);
}

.game-screen .secondary-button {
    min-height: 48px;
    padding: 6px 16px;
    border: 3px solid rgba(46, 42, 36, 0.55);
    border-radius: 48% 52% 46% 54% / 60% 44% 56% 40%;
    background: transparent;
    color: #2E2A24;
    font-family: var(--hand);
    font-size: 23px;
    font-weight: 700;
}

.game-screen .secondary-button:hover {
    background: rgba(46, 42, 36, 0.06);
}

.choose,
.waiting {
    padding: 26px 24px 20px;
    display: flex;
    flex-direction: column;
}

.choose h2 {
    font-family: var(--hand);
    font-size: 34px;
    font-weight: 700;
    line-height: 1.1;
}

.secret-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.secret-row .text-input {
    flex: 1;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.icon-button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(46, 42, 36, 0.4);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #5A4A30;
}

.form-error {
    min-height: 1.4em;
    margin-top: 8px;
    font-size: 21px;
    font-weight: 700;
    color: #C6283A;
}

.choose-actions {
    margin-top: 6px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    align-items: center;
}

.waiting {
    align-items: center;
    gap: 6px;
    text-align: center;
    font-size: 28px;
    color: #4A3F2E;
}

.quill {
    font-size: 44px;
    color: #C6283A;
    animation: write 1.2s ease-in-out infinite;
}

@keyframes write {
    0%, 100% { transform: translate(0, 0) rotate(0); }
    25% { transform: translate(6px, -3px) rotate(8deg); }
    75% { transform: translate(-6px, 2px) rotate(-6deg); }
}

.dots span {
    animation: blink 1.2s infinite;
}

.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 60%, 100% { opacity: 0.2; }
    30% { opacity: 1; }
}

/* Round over and messages */
.result,
.overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(20, 16, 10, 0.45);
    animation: fade-in 0.3s ease-out;
}

.result {
    /* No dimming, so the rescue or the ghost stays visible behind the note */
    background: none;
    pointer-events: none;
    align-items: flex-end;
    padding-bottom: calc(40px + var(--safe-bottom));
}

.result-card {
    pointer-events: auto;
}

.result-card,
.overlay-card {
    width: 100%;
    max-width: 420px;
    padding: 28px 24px 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: center;
    animation: card-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

.result-card h2,
.overlay-card h2 {
    font-family: var(--hand);
    font-size: 38px;
    font-weight: 700;
    line-height: 1.05;
}

.result.won h2 {
    color: #2E7D4F;
}

.result.lost h2 {
    color: #3B5B99;
}

.result-word {
    font-family: var(--hand);
    font-size: 30px;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: #2E2A24;
}

.overlay-card p {
    font-size: 22px;
    color: #5A4A30;
}

.overlay-card .room-code-inline {
    font-family: var(--hand);
    font-size: 34px;
    color: #C6283A;
    text-shadow: none;
}

@keyframes fade-in {
    from { opacity: 0; }
}

@keyframes card-in {
    from { opacity: 0; transform: translateY(18px) scale(0.94) rotate(-3deg); }
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + var(--safe-bottom));
    z-index: 60;
    padding: 8px 18px;
    border-radius: 3px;
    background: linear-gradient(170deg, #FFF08F, #F6D84E);
    color: #3A2A06;
    font-family: 'Caveat', cursive;
    font-size: 24px;
    font-weight: 700;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translate(-50%, 12px) rotate(-1deg);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0) rotate(-1deg);
}

/* Phones: the scene on top, the word and keyboard under it */
@media (max-width: 860px) {
    .game-screen {
        padding: calc(4px + var(--safe-top)) 4px calc(6px + var(--safe-bottom));
    }

    .game-board {
        padding: 7px;
    }

    .game-board .tray {
        display: none;
    }

    .hud {
        padding: 4px 8px;
        gap: 6px;
    }

    .arena {
        flex-direction: column;
        gap: 6px;
        padding: 6px 12px 12px;
        justify-content: flex-start;
        overflow-y: auto;
    }

    .stage {
        flex: none;
        width: 100%;
        height: 30dvh;
        min-height: 170px;
    }

    .panel {
        flex: none;
        width: 100%;
    }

    .tiles {
        margin-top: 8px;
    }

    .keys {
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
        gap: 4px;
    }

    .key {
        height: 42px;
        font-size: 26px;
    }

    .hud-round,
    .hud-status {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
