/* Main Entry Point *//* Self-hosted Nunito (variable weight, latin subset) — replaces the Google
   Fonts origins. One 39 KB woff2 covers 400–900; native apps get fonts
   offline, agent fetchers that skip third-party CSS still see the brand
   face, and two preconnect origins disappear. Non-latin text falls back to
   the system sans stack. */
@font-face {
    font-family: 'Nunito';
    font-style: normal;
    font-weight: 400 900;
    font-display: swap;
    src: url('/fonts/nunito-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
        U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
        U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* CSS Variables - Theme Definition */
:root {
    --native-banner-height: 0px;
    --native-status-bar-height: 0px;
    --safe-area-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
    --safe-area-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
    --safe-area-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
    --safe-area-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
    /* The widest screen. Web side banners are placed outside it. */
    --game-screen-max-width: 52rem;
    --app-edge-gap: clamp(0.42rem, 1.8vw, 0.72rem);
    --app-top-gap: clamp(0.42rem, 1.25vh, 0.7rem);
    --app-bottom-gap: clamp(0.34rem, 1.15vh, 0.62rem);
    --safe-top-header-gap: clamp(0.46rem, 1.6vh, 0.74rem);
    --banner-dead-zone: clamp(0.18rem, 0.85vh, 0.46rem);
    --native-banner-gap: min(var(--native-banner-height), var(--banner-dead-zone));
    --top-system-intrusion-height: 0px;
    --app-chrome-top: max(
        var(--safe-area-top),
        var(--safe-area-inset-top, var(--native-status-bar-height, 0px)),
        var(--top-system-intrusion-height, 0px)
    );
    --app-chrome-right: var(--safe-area-right);
    --app-chrome-bottom: calc(
        var(--safe-area-bottom) +
            var(--native-banner-height, 0px) +
            var(--native-banner-gap)
    );
    --app-chrome-left: var(--safe-area-left);
    --app-canvas-height: calc(
        100dvh -
            var(--app-top-gap) -
            var(--app-bottom-gap) -
            var(--app-chrome-top) -
            var(--app-chrome-bottom)
    );
    --surface-top-padding: var(--safe-top-header-gap);
    --surface-bottom-padding: clamp(0.58rem, 1.55vh, 0.86rem);
    --fixed-overlay-top-padding: calc(var(--app-chrome-top) + var(--safe-top-header-gap));
    --fixed-overlay-bottom-padding: calc(var(--surface-bottom-padding) + var(--app-chrome-bottom));
    --fixed-overlay-available-height: calc(
        100dvh -
            var(--fixed-overlay-top-padding) -
            var(--fixed-overlay-bottom-padding)
    );
    --transient-notice-bottom: calc(16px + var(--app-chrome-bottom));
    --dev-panel-bottom: calc(48px + var(--app-chrome-bottom));
    --dev-toggle-bottom: calc(8px + var(--app-chrome-bottom));
    --game-screen-top-padding: var(--surface-top-padding);
    --game-screen-bottom-padding: clamp(0.34rem, 1vh, 0.48rem);
    --meta-top-intrusion-buffer: clamp(0.86rem, 2.8vh, 1.46rem);
    --meta-cta-safety-gap: clamp(0.54rem, 1.85vh, 1.06rem);
    --meta-top-dead-zone: calc(var(--surface-top-padding) + var(--meta-top-intrusion-buffer));
    --meta-title-size: clamp(1.04rem, 3.2vw, 1.2rem);
    --meta-subtitle-size: clamp(0.62rem, 1.8vw, 0.7rem);
    --screen-content-padding: clamp(0.6rem, 2.5vw, 0.9rem);
    --touch-target-size: 2.75rem;
    /* iOS zooms focused text fields below 16px; still honor larger text settings. */
    --form-input-font-size: max(16px, 1rem);

    /* Slate Palette */
    --color-slate-50: #f8fafc;
    --color-slate-100: #f1f5f9;
    --color-slate-200: #e2e8f0;
    --color-slate-300: #cbd5e1;
    --color-slate-400: #94a3b8;
    --color-slate-500: #64748b;
    --color-slate-600: #475569;
    --color-slate-700: #334155;
    --color-slate-800: #1e293b;
    --color-slate-900: #0f172a;

    /* Bathroom-signage identity: shared by play, rewards, rooms and menus. */
    --brand-ink: #172126;
    --brand-charcoal: #232e33;
    --brand-charcoal-raised: #303c41;
    --brand-porcelain: #fffaf0;
    --brand-cream: #eee5d3;
    --brand-yellow: #ffcf27;
    --brand-yellow-light: #ffde64;
    --brand-yellow-deep: #c69810;
    --brand-metal: #8d9da2;
    --font-display: Impact, "Arial Narrow", "Helvetica Neue", sans-serif;

    /* Keep color aliases so existing components share the same identity. */
    --color-primary: var(--brand-yellow);
    --color-primary-hover: var(--brand-yellow-light);
    --color-success: #22c55e;
    /* Green 500 */
    --color-success-hover: #16a34a;
    /* Green 600 */
    --color-danger: #ef4444;
    /* Red 500 */
    --color-warning: #f59e0b;
    /* Amber 500 */
    --color-orange-400: #fb923c;
    /* Orange 400 */
    --color-accent: var(--brand-yellow);
    --color-purple: #8b5cf6;
    /* Violet 500 */
    --color-purple-hover: #7c3aed;
    /* Violet 600 */

    /* Semantic Colors */
    --bg-app: var(--brand-ink);
    --bg-card: var(--brand-charcoal);
    --bg-overlay: rgba(0, 0, 0, 0.6);

    --text-main: var(--brand-porcelain);
    --text-muted: #d5d9d5;
    --text-subtle: #aab6b6;
    --text-soft: var(--brand-cream);

    /* Shared Surface Tokens */
    --surface-radius-sm: 8px;
    --surface-radius-md: 10px;
    --surface-radius-lg: 12px;
    --surface-border-subtle: rgb(255 250 240 / 0.13);
    --surface-border-default: rgb(255 250 240 / 0.2);
    --surface-border-strong: rgb(255 250 240 / 0.3);
    --surface-bg-soft: rgb(23 33 38 / 0.72);
    --surface-bg-muted: rgb(23 33 38 / 0.4);
    --surface-bg-raised: var(--brand-charcoal-raised);
    --shadow-card-soft: 0 4px 8px -2px rgb(0 0 0 / 0.22);
    --shadow-card-strong: 0 8px 14px -3px rgba(0, 0, 0, 0.3);
    --shadow-modal: 0 16px 34px rgba(2, 6, 23, 0.52);
    --focus-ring: 2px solid var(--brand-yellow-light);

    /* Action hierarchy: yellow always carries dark text. */
    --action-primary-bg: linear-gradient(180deg, var(--brand-yellow-light), var(--brand-yellow));
    --action-primary-hover-bg: var(--brand-yellow-light);
    --action-primary-text: var(--brand-ink);
    --action-primary-border: var(--brand-yellow-deep);
    --action-primary-shadow: 0 3px 0 var(--brand-yellow-deep), 0 6px 14px rgb(0 0 0 / 0.22);
    --action-secondary-bg: var(--brand-charcoal-raised);
    --action-secondary-hover-bg: #3c484c;
    --action-selected-bg: rgb(255 207 39 / 0.12);
    --action-selected-border: rgb(255 207 39 / 0.7);
    --action-selected-shadow: 0 0 0 2px rgb(255 207 39 / 0.18);
    --motion-interaction: 160ms;
    --motion-surface: 200ms;

    /* Room materials use per-world colors with a shared light/tile scale. */
    --room-tile-width: 3.7rem;
    --room-tile-height: 2.8rem;
    --room-grout-width: 1px;
    --room-floor-height: clamp(1.6rem, 5vh, 2.5rem);
    --room-light-height: 40%;
    --room-prop-inset: 5%;
    --room-sign-top: 0.8rem;
    --room-sign-padding: 0.34rem 0.52rem;
    --room-sign-font-size: clamp(0.48rem, 1.8vw, 0.68rem);
    --room-prop-shadow: 0 3px 5px rgb(0 0 0 / 0.22);
    --room-reveal-duration: 650ms;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Borders */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;
}
/* Gameplay Readability Tokens */
:root {
    --gameplay-empty-fill: #f8fafc;
    --gameplay-empty-stroke: #64748b;

    --gameplay-occupied-fill: #cbd5e1;
    --gameplay-occupied-stroke: #475569;
    --gameplay-occupied-shadow: rgba(15, 23, 42, 0.28);

    --gameplay-hazard-dirty: #a16207;
    --gameplay-hazard-messy: #ca8a04;
    --gameplay-hazard-broken: #dc2626;
    --gameplay-hazard-chatty: #9333ea;
    --gameplay-hazard-janitor: #0f766e;

    /* Correct is pee-yellow on purpose, not success-green: the joke lands,
       and yellow-vs-red verdicts stay separable for deutan vision. */
    --gameplay-highlight-correct: #eab308;
    --gameplay-highlight-incorrect: #ef4444;
    --gameplay-highlight-solution: #d18c09;
    --gameplay-highlight-pending: #3b82f6;
    --gameplay-highlight-hover: #0284c7;
    --gameplay-golden-fill: #fef08a;
    --gameplay-golden-stroke: var(--color-accent);

    --gameplay-contour-width: 2;
    --gameplay-contour-hover-width: 3;
    --gameplay-contour-feedback-width: 4;
    --gameplay-contour-focus-dash: 4 3;
    --gameplay-contour-transition: 160ms;

    --gameplay-queue-chip-bg: rgba(15, 23, 42, 0.72);
    --gameplay-queue-light: rgba(59, 130, 246, 0.2);
    --gameplay-queue-busy: rgba(245, 158, 11, 0.26);
    --gameplay-queue-crunch: rgba(239, 68, 68, 0.28);
}
/* Base / Global Styles */

* {
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: "Nunito", sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: calc(var(--app-top-gap) + var(--app-chrome-top))
        calc(var(--app-edge-gap) + var(--app-chrome-right))
        calc(var(--app-bottom-gap) + var(--app-chrome-bottom))
        calc(var(--app-edge-gap) + var(--app-chrome-left));
    overscroll-behavior: none;
    overflow: hidden;
    width: 100%;
    margin: 0;
}

body.top-intrusion-simulated::before {
    content: "";
    position: fixed;
    left: 50%;
    top: calc(var(--safe-area-top) + 0.08rem);
    width: min(82vw, 340px);
    height: calc(var(--top-system-intrusion-height, 0px) + 0.82rem);
    transform: translateX(-50%);
    background: radial-gradient(
        ellipse at center,
        rgba(15, 23, 42, 0.46) 0%,
        rgba(15, 23, 42, 0.12) 58%,
        rgba(15, 23, 42, 0) 78%
    );
    filter: blur(0.5px);
    pointer-events: none;
    z-index: 12000;
}

body.top-intrusion-simulated::after {
    content: "";
    position: fixed;
    left: 50%;
    top: calc(var(--safe-area-top) + 0.14rem);
    width: clamp(168px, 50vw, 244px);
    height: var(--top-system-intrusion-height, 0px);
    transform: translateX(-50%);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.96) 0%, rgba(30, 41, 59, 0.94) 100%);
    border: 1px solid rgba(148, 163, 184, 0.42);
    box-shadow: 0 10px 24px -12px rgba(2, 6, 23, 0.88),
        inset 0 1px 0 rgba(248, 250, 252, 0.16);
    pointer-events: none;
    z-index: 12001;
}

/* Typography Defaults */
h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0;
    font-weight: 700;
}

p {
    margin: 0;
}

/* Utilities */

.hidden {
    display: none !important;
}

/* Animations that don't belong to specific components logic yet, or shared ones */
@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

.opacity-0 {
    opacity: 0 !important;
    transition: opacity 0.3s ease;
}

.pointer-events-none {
    pointer-events: none !important;
}

.bg-transparent {
    background-color: transparent !important;
}

/* Components */

/* Button Components */

/* --- Start Screen Buttons --- */
.start-screen-button {
    color: var(--text-main);
    font-weight: 700;
    width: 100%;
    min-height: 2.82rem;
    padding: 0.5rem 0.64rem;
    border-radius: var(--surface-radius-lg);
    font-size: 0.92rem;
    line-height: 1.12;
    background: var(--action-secondary-bg);
    box-shadow: var(--shadow-card-soft);
    transition: background-color var(--motion-surface) ease, transform var(--motion-interaction) ease, box-shadow var(--motion-surface) ease;
    border: 1px solid var(--surface-border-default);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.08rem;
    text-align: left;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.start-screen-button:hover {
    transform: translateY(-1px);
    background: var(--action-secondary-hover-bg);
}

.start-screen-button:active {
    transform: translateY(0);
}

.start-screen-button:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

/* Split Daily card: the mode button keeps the whole card's look; the share
   button docks INSIDE its right edge as a sibling (nested buttons are invalid
   HTML). Reserved padding keeps the subtitle clear of the glyph. */
.daily-mode-slot {
    position: relative;
    width: 100%;
    display: flex;
}

.daily-mode-slot .start-screen-button {
    width: 100%;
}

.daily-mode-slot.daily-share-available .start-screen-button {
    padding-right: 3.1rem;
}

.daily-share-button {
    position: absolute;
    top: 50%;
    right: 0.42rem;
    transform: translateY(-50%);
    width: 2.35rem;
    height: 2.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    /* A floating rounded chip, matching the home-chip corner language —
       hard-cornered split edges read foreign inside fully-rounded cards. */
    border-radius: var(--surface-radius-md);
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s ease, transform 0.16s ease;
}

.daily-share-button:hover {
    background: rgba(255, 255, 255, 0.22);
}

.daily-share-button:active {
    transform: translateY(-50%) scale(0.94);
}

.daily-share-button:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

/* One reveal pulse when the button first appears for the day. */
.daily-share-button.daily-share-reveal {
    animation: daily-share-pop 0.6s ease-out 1;
}

@keyframes daily-share-pop {
    0% { transform: translateY(-50%) scale(0.6); opacity: 0; }
    60% { transform: translateY(-50%) scale(1.12); opacity: 1; }
    100% { transform: translateY(-50%) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .daily-share-button.daily-share-reveal {
        animation: none;
    }
}

.mode-button-title {
    font-size: 0.87rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    line-height: 1.02;
}

.mode-button-subtitle {
    font-size: 0.66rem;
    font-weight: 600;
    line-height: 1.1;
    color: var(--text-soft);
    opacity: 0.95;
}

.home-leaderboard-button {
    width: 100%;
    min-height: 2.52rem;
    margin-top: 0.32rem;
    padding: 0.42rem 0.64rem;
    border: 1px solid var(--surface-border-default);
    border-radius: var(--surface-radius-md);
    background: var(--surface-bg-soft);
    color: var(--text-main);
    box-shadow: var(--shadow-card-soft);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.06rem;
    text-align: left;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.18s ease, border-color 0.18s ease,
        transform 0.16s ease, box-shadow 0.18s ease;
}

.home-leaderboard-button .mode-button-title {
    color: var(--text-main);
}

.home-leaderboard-button .mode-button-subtitle {
    color: var(--text-muted);
}

.home-leaderboard-button:hover {
    transform: translateY(-1px);
    border-color: var(--surface-border-strong);
    background: var(--action-secondary-hover-bg);
    box-shadow: var(--shadow-card-strong);
}

.home-leaderboard-button:active {
    transform: translateY(0);
}

.home-leaderboard-button:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

.home-leaderboard-button:disabled {
    opacity: 0.72;
    cursor: default;
    transform: none;
}

.mission-claim-button {
    margin-top: 0;
    border: 2px solid rgba(74, 222, 128, 0.5);
    border-radius: var(--surface-radius-md);
    background-color: rgba(21, 128, 61, 0.15);
    color: #4ade80;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 800;
    min-height: 1.8rem;
    min-width: 4rem;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 2px 4px -1px rgba(2, 6, 23, 0.4);
}

.mission-claim-button.featured {
    border-color: #4ade80;
    background-color: rgba(34, 197, 94, 0.2);
    color: #86efac;
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.2);
}

.mission-claim-button.secondary {
    border-color: rgba(74, 222, 128, 0.3);
    background-color: rgba(15, 23, 42, 0.4);
    color: rgba(74, 222, 128, 0.9);
    box-shadow: none;
}

.mission-claim-button:hover {
    background-color: rgba(34, 197, 94, 0.3);
    border-color: #86efac;
    color: #ffffff;
    transform: scale(1.04) translateY(-1px);
    box-shadow: 0 4px 8px -2px rgba(2, 6, 23, 0.6);
}

.mission-claim-button:disabled {
    opacity: 0.62;
    cursor: default;
}

.home-mission-share-button {
    margin-bottom: 0.35rem;
    border: 1px solid var(--surface-border-strong);
    border-radius: var(--surface-radius-sm);
    background-color: rgba(15, 23, 42, 0.38);
    color: var(--text-soft);
    font-size: 0.76rem;
    font-weight: 700;
    min-height: 2.2rem;
    padding: 0.26rem 0.56rem;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.home-mission-share-button:hover {
    background-color: rgba(30, 41, 59, 0.72);
    color: #fff;
}

.home-mission-share-button:disabled {
    opacity: 0.7;
    cursor: default;
}

#start-progression-button {
    background: var(--action-secondary-bg);
    border-color: var(--surface-border-strong);
}

#start-progression-button:hover {
    background: var(--action-secondary-hover-bg);
}

#start-endless-button {
    background: var(--action-primary-bg);
    color: var(--action-primary-text);
    box-shadow: var(--action-primary-shadow);
    border-color: var(--action-primary-border);
}

#start-endless-button:hover {
    background: var(--action-primary-hover-bg);
}

#start-endless-button:active {
    transform: translateY(2px);
    box-shadow: var(--shadow-card-soft);
}

#start-daily-challenge-button {
    background: var(--surface-bg-soft);
    border-color: var(--action-selected-border);
    box-shadow: var(--shadow-card-soft);
}

#start-daily-challenge-button .mode-button-title {
    color: var(--brand-yellow-light);
}

#start-daily-challenge-button .mode-button-subtitle {
    color: var(--text-muted);
}

#start-daily-challenge-button:hover {
    background: var(--action-secondary-hover-bg);
    border-color: var(--brand-yellow-light);
}

#start-daily-challenge-button:active {
    transform: translateY(0);
    box-shadow: var(--shadow-card-soft);
}

#start-daily-challenge-button:disabled {
    opacity: 0.72;
    cursor: not-allowed;
    filter: saturate(0.55);
}

/* Completed-today carryover: acknowledge the ritual is done without dimming the
   replay affordance. A reward-ready state nudges the player toward the payoff. */
#start-daily-challenge-button.daily-complete-today .mode-button-subtitle {
    color: #d1fae5;
}

#start-daily-challenge-button.daily-reward-ready {
    border-color: #4ade80;
    box-shadow: 0 0 0 1px rgba(74, 222, 128, 0.45), 0 6px 16px -4px rgba(22, 163, 74, 0.5);
}

#start-daily-challenge-button.daily-reward-ready .mode-button-subtitle {
    color: #bbf7d0;
    opacity: 1;
}

#start-daily-challenge-button.attention-pulse {
    animation: daily-cta-pulse 620ms ease-out 2;
}

@keyframes daily-cta-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.55);
    }

    100% {
        box-shadow: 0 0 0 9px rgba(245, 158, 11, 0);
    }
}

#character-select-start-button {
    background: var(--action-primary-bg);
    color: var(--action-primary-text);
    align-items: center;
    text-align: center;
    justify-content: center;
    min-height: 2.66rem;
    border-color: var(--action-primary-border);
    box-shadow: var(--action-primary-shadow);
}

#start-endless-button .mode-button-subtitle,
#character-select-start-button .mode-button-subtitle {
    color: var(--action-primary-text);
}

#character-select-start-button .mode-button-subtitle {
    display: none;
}

#character-select-start-button:disabled {
    opacity: 0.58;
    cursor: not-allowed;
    transform: none;
}

/* --- Control Buttons (Modal Hierarchy) --- */
.control-button {
    width: 100%;
    min-height: 3rem;
    padding: 0.75rem 1rem;
    border-radius: var(--surface-radius-md);
    font-weight: 700;
    font-size: 1.05rem;
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.control-button:active {
    transform: translateY(1px) scale(0.995);
}

.control-button:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

/* Primary */
.btn-primary {
    background: var(--action-primary-bg);
    color: var(--action-primary-text);
    border: 1px solid var(--action-primary-border);
    box-shadow: var(--action-primary-shadow);
    font-size: 1.18rem;
    padding: 0.95rem;
}

.btn-primary:hover {
    transform: translateY(-1px);
    background: var(--action-primary-hover-bg);
}

#play-again-button.btn-primary {
    font-size: 1.28rem;
    letter-spacing: 0.01em;
}

/* Secondary */
.btn-secondary {
    background: var(--action-secondary-bg);
    color: var(--text-main);
    box-shadow: var(--shadow-card-soft);
    border: 1px solid var(--surface-border-strong);
    font-size: 1rem;
    padding: 0.82rem 0.95rem;
}

.btn-secondary:hover {
    background: var(--action-secondary-hover-bg);
}

/* Tertiary */
.btn-tertiary {
    background-color: var(--surface-bg-muted);
    color: var(--text-soft);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.58rem 0.8rem;
    box-shadow: none;
    border: 1px solid var(--surface-border-default);
    margin-top: 0;
}

.btn-tertiary:hover {
    color: var(--text-main);
    background-color: var(--surface-bg-soft);
    border-color: var(--surface-border-strong);
}

.btn-tertiary:active {
    background-color: var(--action-secondary-bg);
}

#share-button.btn-tertiary {
    margin-top: 0.1rem;
}

#revive-button.btn-secondary {
    margin-top: 0.12rem;
}

/* --- Peek & Restore Buttons --- */
#peek-modal-button,
#restore-modal-button {
    position: static;
    order: 1;
    align-self: center;
    flex-shrink: 0;
    min-height: var(--result-review-control-height);
    min-width: 10.6rem;
    max-width: 100%;
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius-full);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--surface-border-default);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

#peek-modal-button,
#restore-modal-button {
    background-color: var(--brand-charcoal);
    color: var(--brand-porcelain);
    border-color: var(--brand-metal);
}

#peek-modal-button:hover {
    color: white;
    background-color: rgba(30, 41, 59, 0.72);
    border-color: rgba(148, 163, 184, 0.48);
}

#restore-modal-button:hover {
    background-color: var(--brand-charcoal-raised);
    transform: translateY(-1px);
}

#peek-modal-button svg,
#restore-modal-button svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

/* Mute Toggle */
#mute-toggle.icon-button {
    background-color: var(--surface-bg-soft);
    border: 1px solid var(--surface-border-strong);
    border-radius: 9999px;
    color: var(--color-slate-100);
    font-size: 1.05rem;
    line-height: 1;
    min-width: var(--hud-control-size);
    min-height: var(--hud-control-size);
    padding: 0.2rem 0.45rem;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

#mute-toggle.icon-button:focus-visible,
#peek-modal-button:focus-visible,
#restore-modal-button:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

@media (pointer: coarse) {
    .start-screen-button,
    .control-button,
    .home-leaderboard-button,
    #character-select-start-button {
        min-height: 3.3rem;
    }

    #mute-toggle.icon-button {
        min-width: var(--hud-control-size);
        min-height: var(--hud-control-size);
    }
}

@media (prefers-reduced-motion: reduce) {
    .start-screen-button,
    .control-button,
    .home-leaderboard-button,
    .mission-claim-button,
    .daily-share-button {
        transition: none;
        animation: none !important;
    }
}

/* Modal Components */

.custom-modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    padding: var(--fixed-overlay-top-padding) 0.7rem var(--fixed-overlay-bottom-padding);
    background-color: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 1000;
}

.custom-modal-content {
    background-color: var(--bg-card);
    background-image: linear-gradient(180deg, var(--brand-charcoal-raised), var(--brand-charcoal));
    padding: 1.34rem 1.08rem 1.08rem;
    border-radius: 12px;
    text-align: left;
    box-shadow: var(--shadow-modal);
    border: 1px solid rgba(148, 163, 184, 0.28);
    max-width: calc(100vw - 1.12rem);
    width: min(430px, calc(100vw - 1.12rem));
    max-height: var(--fixed-overlay-available-height);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    position: relative;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(1.5px);
}

/* Results leave the resolved room visible. Only this overlay changes size;
   the gameplay stage and its tap coordinates are never reflowed. */
.custom-modal.custom-modal--result {
    --result-review-control-height: 2.75rem;
    --result-review-gap: 0.45rem;
    align-items: center;
    flex-direction: column;
    justify-content: flex-end;
    gap: var(--result-review-gap);
    background: linear-gradient(180deg, transparent 20%, rgb(23 33 38 / 0.16) 50%, rgb(23 33 38 / 0.74));
}

.custom-modal--result .custom-modal-content {
    width: min(430px, calc(100vw - 1.12rem));
    max-height: min(48dvh, calc(var(--fixed-overlay-available-height) - var(--result-review-control-height) - var(--result-review-gap)));
    padding: 0.95rem 1rem 0.8rem;
    border-top: 4px solid var(--brand-yellow);
    border-radius: 1rem 1rem 0.7rem 0.7rem;
    scrollbar-gutter: auto;
}

.custom-modal--result #modal-controls-area .btn-primary {
    flex-shrink: 0;
}

.custom-modal:not(.hidden) .custom-modal-content {
    animation: modal-content-enter 170ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes modal-content-enter {
    from {
        opacity: 0;
        transform: translateY(7px) scale(0.99);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Override for Peek Mode transparency */
.custom-modal--result.bg-transparent {
    background: none;
}

.custom-modal.bg-transparent {
    background-color: transparent !important;
}

#custom-modal-message {
    font-size: 0.98rem;
    line-height: 1.32;
    color: var(--text-main);
    margin-bottom: 0.78rem;
    font-weight: 500;
}

#custom-modal-message .result-modal-body {
    display: flex;
    flex-direction: column;
    gap: 0.34rem;
}

#custom-modal-message .loss-reason {
    color: var(--color-orange-400);
    display: block;
    font-size: 1.14rem;
    margin-bottom: 0;
    line-height: 1.25;
    font-weight: 800;
}

#custom-modal-message .result-support-line {
    color: var(--text-main);
    display: block;
    font-size: 0.88rem;
    line-height: 1.3;
    margin: 0;
}

#custom-modal-message .result-summary-line {
    color: var(--text-soft);
    display: block;
    font-size: 0.84rem;
    line-height: 1.26;
    font-weight: 700;
}

#custom-modal-message .result-earned-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.32rem;
    margin-top: 0.08rem;
}

#custom-modal-message .result-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.18rem 0.42rem;
    border-radius: var(--radius-full);
    border: 1px solid rgba(125, 211, 252, 0.28);
    background: rgba(15, 23, 42, 0.56);
    color: #dbeafe;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.2;
}

#custom-modal-message .result-chip--daily {
    border-color: rgba(125, 211, 252, 0.5);
    background: rgba(8, 47, 73, 0.62);
    color: #bae6fd;
}

#custom-modal-message .result-chip--reward {
    border-color: rgba(74, 222, 128, 0.55);
    background: rgba(20, 83, 45, 0.5);
    color: #bbf7d0;
    font-weight: 800;
}

#custom-modal-message .result-meta-line {
    font-size: 0.76rem;
    line-height: 1.25;
    margin-top: 0.2rem;
}

#custom-modal-message .social-fallback-note {
    color: var(--text-muted);
}

#modal-controls-area {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.36rem;
    margin-top: 0.62rem;
    padding-bottom: 0.16rem;
    width: 100%;
}

#modal-controls-area.result-actions-compact {
    gap: 0.3rem;
    margin-top: 0.5rem;
}

#modal-controls-area.result-actions-compact .control-button {
    min-height: 2.78rem;
}

#modal-controls-area.result-actions-expanded {
    gap: 0.4rem;
}

#modal-controls-area.result-actions-replay-focused .btn-primary {
    min-height: 2.9rem;
}

#modal-controls-area.result-actions-footer-minimal .modal-footer-row {
    margin-top: 0.26rem;
    padding-top: 0;
    border-top: none;
}

.modal-footer-row {
    display: flex;
    flex-direction: row;
    gap: 0.42rem;
    width: 100%;
    justify-content: center;
    margin-top: 0.44rem;
    padding-top: 0.38rem;
    border-top: 1px solid var(--surface-border-default);
}

.modal-footer-row.compact-inline {
    margin-top: 0.26rem;
    padding-top: 0;
    border-top: none;
}

.modal-footer-row.single-action {
    justify-content: stretch;
}

.modal-footer-row.single-action .control-button {
    width: 100%;
}

#custom-modal-message .near-miss-text {
    color: #facc15;
    display: block;
    font-size: 0.84rem;
    margin-bottom: 0.32rem;
}

#custom-modal-message .onboarding-tip-text {
    color: var(--text-soft);
    display: block;
    font-size: 0.82rem;
    margin-top: 0.34rem;
    line-height: 1.28;
}

@media (max-height: 700px) {
    .custom-modal {
        align-items: flex-end;
    }

    .custom-modal-content {
        width: min(430px, 94vw);
        padding: 1.08rem 0.92rem 0.9rem;
        max-height: var(--fixed-overlay-available-height);
    }

    #custom-modal-message {
        margin-bottom: 0.72rem;
    }

    #custom-modal-message .loss-reason {
        font-size: 1.08rem;
    }
}

/* Short screens use the space actually available above the banner instead
   of clipping the action row at a portrait-oriented viewport percentage. */
@media (max-height: 500px) {
    .custom-modal--result .custom-modal-content {
        max-height: calc(var(--fixed-overlay-available-height) - var(--result-review-control-height) - var(--result-review-gap));
        padding-block: 0.65rem;
    }
}
/* Character Cards */

#character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
    gap: 0.56rem;
    /* start, not stretch: stretched items take the track's height and the
       track never grows for OS-scaled text (stretch/auto circularity), so
       card text spilled into the next row. With `start` each card sizes to
       its own content; the card min-height keeps the normal look uniform. */
    align-items: start;
    /* max-content, not minmax(min, auto): this grid is a height-constrained
       flex item (layout.css sets flex:1 1 auto; min-height:0), so an `auto`
       growth limit resolved ~9px SHORT of a locked card's real height. Cards
       kept their own height (align-items:start) and overflowed the track,
       leaving a measured 1.1px overlap between rows once the 8px gap absorbed
       the rest. max-content sizes each row to its tallest card. The uniform
       look is preserved by .character-card's own min-height, which already
       carried the same clamp() the track min duplicated. */
    grid-auto-rows: max-content;
}

.character-card {
    background: linear-gradient(180deg, var(--surface-bg-raised), var(--bg-card));
    border-radius: var(--surface-radius-lg);
    min-height: clamp(7.8rem, 19.5vh, 9.35rem);
    padding: clamp(0.42rem, 1.25vh, 0.54rem) 0.5rem 0.6rem;
    cursor: pointer;
    transition: transform var(--motion-interaction) ease, border-color var(--motion-surface) ease, box-shadow var(--motion-surface) ease;
    border: 2px solid var(--surface-border-default);
    box-shadow: var(--shadow-card-soft);
    text-align: center;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* One explicit gap between every stacked piece (badge, art, name,
       subtitle, quip, progress, unlock line) instead of per-element micro
       margins: spacing stays even and can never fold into overlap when the
       OS scales text. */
    gap: 0.18rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

@media (hover: hover) and (pointer: fine) {
    .character-card:hover {
        transform: translateY(-2px);
        border-color: var(--action-selected-border);
        box-shadow: var(--shadow-card-strong);
    }
}

.character-card:active {
    transform: translateY(0);
}

.character-card.selected,
.character-card.preselected {
    border-color: var(--brand-yellow);
    box-shadow: var(--shadow-card-soft);
    background: linear-gradient(180deg, var(--action-selected-bg), var(--bg-card));
    transform: translateY(-1px);
}

.character-card-selection {
    min-height: 1.08rem;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--brand-yellow-light);
}

.character-card:focus-visible {
    border-color: var(--brand-yellow-light);
    border-style: dashed;
    outline: none;
}

.character-card.locked {
    cursor: not-allowed;
    background: var(--surface-bg-soft);
    border-style: dashed;
}

.character-card.locked:hover:not(:focus-visible) {
    transform: none;
    border-color: var(--surface-border-default);
    box-shadow: var(--shadow-card-soft);
}

.character-card.locked svg {
    opacity: 0.65;
    filter: grayscale(0.8);
}

.character-card.locked .character-name {
    color: var(--text-soft);
}

.character-card.locked .character-unlock-info {
    color: var(--text-muted);
}

.character-card svg {
    width: 100%;
    height: clamp(52px, 8.5vh, 70px);
    flex-shrink: 0;
    filter: drop-shadow(0 4px 3px rgb(0 0 0 / 0.25));
}

/* Vertical rhythm comes from the card's flex gap — the stacked pieces below
   carry NO margins of their own. */
.character-name {
    font-weight: 800;
    margin-top: 0.08rem;
    color: var(--text-main);
    font-size: 0.82rem;
}

.character-unlock-info {
    font-size: 0.68rem;
    color: var(--text-soft);
    line-height: 1.2;
}

/* Collection personality: every card carries its runner's Flow line.
   Clamped to two lines so a long quip (or OS-scaled text) can never crowd
   the unlock line beneath it. */
.character-quip {
    font-size: 0.66rem;
    font-style: italic;
    color: var(--text-subtle);
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Endowed progress toward the nearer unlock path — a partially-filled bar
   turns "someday" into "soon". */
.character-unlock-progress {
    width: 82%;
    height: 5px;
    margin: 0.1rem auto 0;
    border-radius: 3px;
    background: var(--surface-border-default);
    overflow: hidden;
}

.character-unlock-progress span {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: var(--action-primary-bg);
    transition: width 0.4s ease;
}

.character-subtitle {
    font-size: 0.72rem;
    color: var(--text-subtle);
    line-height: 1.2;
}

@media (prefers-reduced-motion: reduce) {
    .character-card,
    .character-unlock-progress span {
        transition: none;
    }
}

@media (max-width: 480px) {
    #character-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
    }

    .character-card {
        min-height: clamp(7.45rem, 18.8vh, 9.1rem);
        padding: clamp(0.38rem, 1.1vh, 0.5rem) 0.44rem 0.55rem;
    }
}

@media (max-width: 480px) and (max-height: 700px) {
    #character-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.42rem;
        /* max-content, not minmax(min, auto): same track-underestimation as
           the base rule. .character-card's min-height holds the floor. */
        grid-auto-rows: max-content;
    }

    .character-card {
        min-height: 0;
        padding: 0.32rem 0.28rem;
    }

    .character-card-selection {
        min-height: 0.88rem;
        font-size: 0.56rem;
        margin-bottom: 0.04rem;
    }

    .character-name {
        margin-top: 0.12rem;
        font-size: 0.72rem;
    }

    .character-unlock-info {
        margin-top: 0.06rem;
        font-size: 0.62rem;
        line-height: 1.2;
    }
}

/* Short screens prioritize the runner, selection, and unlock requirement.
   Scale portraits from the usable canvas so a banner does not crowd actions. */
@media (max-width: 480px) and (max-height: 700px),
    (min-width: 600px) and (max-height: 500px) {
    .character-card {
        gap: 0.12rem;
        padding-block: 0.25rem;
    }

    .character-card svg {
        height: clamp(56px, calc(var(--app-canvas-height) * 0.13), 68px);
    }

    .character-card-selection,
    .character-name {
        line-height: 1.2;
    }

    .character-subtitle,
    .character-quip {
        display: none;
    }
}

@media (min-width: 600px) and (max-height: 500px) {
    #character-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .character-card {
        min-height: 0;
        padding-inline: 0.4rem;
    }

    .character-unlock-info {
        font-size: 0.64rem;
    }
}

@media (max-width: 480px) {
    body.has-native-banner .character-quip {
        display: none;
    }
}

/* Desktop side banners: AdSense display units in the empty space either side
   of the game, web only. WebSideBanners.ts adds the rails, sizes them, and
   shows a rail only while it fits inside the window. See docs/web-ads.md. */

.web-side-banner {
    /* Google recommends at least 150px between an ad and the edge of a game. */
    --web-side-banner-game-gap: 160px;
    /* From the centre line: half the widest screen (the game), then the gap. */
    --web-side-banner-offset: calc(
        var(--game-screen-max-width) / 2 + var(--web-side-banner-game-gap)
    );
    /* Above the modal (1000) and leaderboard (1100) overlays, whose backdrops
       would otherwise dim or cover an ad. Their dialogs are narrower than the
       game, so they never reach a rail. */
    --web-side-banner-layer: 1200;
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: var(--web-side-banner-layer);
    line-height: 0;
}

.web-side-banner[data-side="left"] {
    right: calc(50% + var(--web-side-banner-offset));
}

.web-side-banner[data-side="right"] {
    left: calc(50% + var(--web-side-banner-offset));
}

/* Test environments only, when `webAds.sideBanners.testPlaceholder` is on:
   marks where a banner sits when Google returns no ad. It lies over the empty
   unit. WebSideBanners.ts never adds it for live ads. */
.web-side-banner__placeholder {
    position: absolute;
    top: 0;
    left: 0;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    padding: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--surface-border-default);
    border-radius: var(--surface-radius-md);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 700;
    /* The rail sets line-height to 0 for the ad unit. */
    line-height: 1.4;
    text-align: center;
}

/* Measurable, but out of sight and out of reach, until the rail fits. Google
   marks its ad container `visibility: visible`, which shows through a hidden
   parent and stays clickable, so the rail is clipped away as well. */
.web-side-banner[data-state="standby"] {
    visibility: hidden;
    clip-path: inset(100%);
    pointer-events: none;
}
/* Game Specific */
/* Game Layout & HUD */

/* --- Screens Container --- */
#start-screen,
#character-select-screen {
    background: var(--brand-charcoal);
    border-radius: clamp(16px, 4vw, 22px);
    padding: 0.78rem 0.78rem;
    padding-top: var(--meta-top-dead-zone);
    padding-bottom: var(--surface-bottom-padding);
    text-align: center;
    border: 1px solid var(--surface-border-subtle);
    box-shadow: 0 10px 34px -18px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(148, 163, 184, 0.08);
    width: 100%;
    max-width: 34rem;
    height: var(--app-canvas-height);
    min-height: min(100%, var(--app-canvas-height));
    max-height: var(--app-canvas-height);
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    scroll-padding-top: var(--meta-top-dead-zone);
    scroll-padding-bottom: calc(var(--surface-bottom-padding) + var(--banner-dead-zone));
    position: relative;
    display: flex;
    flex-direction: column;
    /* Anchor for absolute children like privacy link */
}

#home-content-stack {
    width: 100%;
    min-height: 0;
    margin-block: auto;
    display: flex;
    flex-direction: column;
}

#home-content-stack>*+*,
#character-select-screen>*+* {
    margin-top: 0.34rem;
}

#start-screen:not(.hidden),
#character-select-screen:not(.hidden),
#game-screen:not(.hidden) {
    animation: screen-surface-enter 170ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes screen-surface-enter {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.995);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#start-screen-title,
#character-select-title {
    font-size: calc(var(--meta-title-size) * 1.35);
    line-height: 1;
    font-weight: 900;
    color: var(--color-primary);
    text-shadow: 0 4px 6px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.6);
    margin: 0;
    letter-spacing: -0.015em;
}

#home-hero {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 0.08rem;
    flex-shrink: 0;
}

#start-screen-subtitle {
    font-size: var(--meta-subtitle-size);
    line-height: 1.08;
    color: var(--text-muted);
    font-weight: 600;
}

#home-mode-section {
    text-align: left;
    margin-top: var(--meta-cta-safety-gap);
    flex-shrink: 0;
}

#start-screen-buttons {
    display: flex;
    justify-content: flex-start;
    gap: 0.32rem;
    flex-direction: column;
}

/* Privacy Link */
.start-privacy-link {
    position: static;
    display: inline-block;
    width: auto;
    text-align: center;
    margin-top: clamp(0.36rem, 1vh, 0.62rem);
    padding-top: 0;
    font-size: 0.75rem;
    opacity: 0.6;
    text-decoration: underline;
    color: var(--text-muted);
    flex-shrink: 0;
}

.start-privacy-link:focus,
.start-privacy-link:hover {
    opacity: 1;
}

/* The web home offers downloads alongside the game title on larger screens. */
#home-store-links {
    --store-badge-width: 7.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs) var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

#home-store-heading {
    flex-basis: 100%;
    font-size: 0.875rem;
    font-weight: 800;
    color: var(--brand-porcelain);
}

.store-badge {
    flex: 1 1 var(--store-badge-width);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    min-height: max(var(--touch-target-size), 3rem);
    padding: var(--spacing-xs) var(--spacing-sm);
    border: 1px solid var(--brand-metal);
    border-radius: var(--surface-radius-md);
    background: var(--brand-cream);
    color: var(--brand-ink);
    text-decoration: none;
}

.store-badge:hover,
.store-badge:focus-visible {
    background: var(--brand-porcelain);
    border-color: var(--brand-porcelain);
}

.store-badge:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

.store-badge-art {
    width: 1.5rem;
    height: 1.5rem;
    flex-shrink: 0;
}

.store-badge-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    text-align: left;
}

.store-badge-eyebrow {
    font-size: 0.7rem;
    font-weight: 650;
}

.store-badge-name {
    font-size: 1rem;
    font-weight: 850;
}

@media (min-width: 42rem) {
    .platform-web #home-hero {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "eyebrow downloads"
            "title   downloads"
            "tagline downloads"
            "preview preview";
        column-gap: var(--spacing-md);
    }

    .platform-web #home-hero .home-eyebrow { grid-area: eyebrow; }
    .platform-web #start-screen-title { grid-area: title; }
    .platform-web #start-screen-subtitle { grid-area: tagline; }
    .platform-web #home-room-preview { grid-area: preview; }

    #home-store-links {
        grid-area: downloads;
        display: grid;
        grid-template-columns: minmax(9.5rem, max-content);
        align-self: center;
        margin-top: 0;
    }
}

#home-onboarding-hint {
    margin-top: 0.36rem;
    font-size: 0.73rem;
    font-weight: 600;
    color: var(--text-soft);
    background: rgba(15, 23, 42, 0.28);
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: var(--surface-radius-md);
    padding: 0.28rem 0.46rem;
    min-height: 0;
}

#home-status-strip {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    background: rgba(15, 23, 42, 0.25);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: var(--surface-radius-md) var(--surface-radius-md) 0 0;
    padding: 0.43rem 0.58rem;
    border-bottom: none;
    flex-shrink: 0;
}

.home-status-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    background: transparent;
    border: none;
    padding: 0;
}

.home-character-chip {
    cursor: pointer;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: var(--surface-radius-md);
    padding: 0.2rem 0.5rem;
    background: rgba(30, 41, 59, 0.45);
    transition: border-color 140ms ease, background-color 140ms ease;
    font: inherit;
    color: inherit;
}

.home-character-chip:hover,
.home-character-chip:focus-visible {
    border-color: rgba(96, 165, 250, 0.6);
    background: rgba(37, 99, 235, 0.18);
    outline: none;
}

#home-character-value {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--color-slate-50);
    line-height: 1.2;
    text-shadow: 0 2px 4px rgba(15, 23, 42, 0.8);
    white-space: nowrap;
}

.home-streak-freeze {
    font-size: 0.8rem;
    line-height: 1;
    margin-left: 0.15rem;
    filter: drop-shadow(0 0 3px rgba(125, 211, 252, 0.75));
}

#home-daily-calendar {
    display: flex;
    justify-content: center;
    gap: 0.28rem;
    padding: 0.3rem 0.58rem 0.1rem;
}

.home-daily-calendar-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: rgba(148, 163, 184, 0.22);
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.home-daily-calendar-dot.completed {
    background: #f59e0b;
    border-color: rgba(251, 191, 36, 0.9);
    box-shadow: 0 0 5px rgba(245, 158, 11, 0.55);
}

.home-daily-calendar-dot.today {
    border-color: rgba(96, 165, 250, 0.95);
    border-width: 1.5px;
}

.home-status-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
    line-height: 1;
}

.home-status-value-wrapper {
    display: flex;
    align-items: baseline;
    gap: 0.05rem;
}

#home-high-score-value,
#home-streak-value {
    font-size: 1.25rem;
    font-weight: 900;
    color: var(--color-slate-50);
    line-height: 1;
    text-shadow: 0 2px 4px rgba(15, 23, 42, 0.8);
}

.home-status-unit {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--color-slate-300);
}

#home-progression {
    text-align: center;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-top: 1px dashed rgba(148, 163, 184, 0.3);
    border-radius: 0 0 var(--surface-radius-md) var(--surface-radius-md);
    background: rgba(15, 23, 42, 0.25);
    padding: 0.36rem 0.5rem 0.5rem;
    margin-top: 0 !important;
    flex-shrink: 0;
}

#home-progression-headline {
    color: #ffffff;
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 0.02em;
    text-shadow: 0 2px 4px rgba(15, 23, 42, 0.8);
}

.home-level-prefix {
    color: var(--color-primary);
    font-size: 0.75rem;
    font-weight: 800;
}

#home-level-title-value {
    margin-left: 0.15rem;
    color: var(--color-orange-400);
}

#home-progression-detail {
    margin-top: 0.25rem;
}

.home-xp-capsule {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: rgba(15, 23, 42, 0.4);
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--color-orange-300);
}

.home-xp-icon {
    font-size: 0.75rem;
    color: var(--color-orange-400);
    text-shadow: 0 0 4px rgba(251, 146, 60, 0.5);
}

.progression-dot {
    margin: 0 0.35rem;
    opacity: 0.5;
}

#home-progression-note {
    margin-top: 0.14rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}

#home-missions {
    margin-top: 0.35rem;
    text-align: left;
    border: none;
    border-radius: 0;
    padding: 0.28rem 0.12rem 0.12rem;
    background: transparent;
    flex: 0 1 auto;
    min-height: 0;
    max-height: clamp(8rem, 25vh, 12rem);
    overflow-y: auto;
    overscroll-behavior-y: contain;
}

#home-missions.onboarding-locked {
    border: 1px solid rgba(148, 163, 184, 0.15);
    background: radial-gradient(circle at center top, rgba(15, 23, 42, 0.4) 0%, rgba(15, 23, 42, 0.15) 100%);
    border-radius: var(--surface-radius-lg);
    /* The locked teaser is a static placard, not the scrollable mission list:
       the container's viewport-clamped max-height + overflow-y:auto would put
       a scrollbar on three lines of copy. Size it naturally instead. */
    max-height: none;
    overflow-y: visible;
    padding: 0.6rem 0.5rem;
    text-align: center;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.1);
}

#home-missions.onboarding-locked #home-missions-title {
    color: var(--color-slate-400);
    font-size: 0.65rem;
    letter-spacing: 0.05em;
    margin-bottom: 0.2rem;
}

#home-missions.onboarding-locked #home-missions-summary {
    color: var(--color-slate-50);
    font-weight: 700;
    font-size: 0.75rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    margin-top: 0;
    margin-bottom: 0.25rem;
}

#home-missions.onboarding-locked .home-mission-feedback {
    /* If any text gets rendered by fallback, make it blend */
    color: var(--text-muted);
    font-size: 0.65rem;
}

#home-missions-title {
    margin: 0;
    font-size: 0.75rem;
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-weight: 700;
}

#home-missions-summary {
    margin-top: 0.08rem;
    margin-bottom: 0.25rem;
    color: var(--text-soft);
    font-size: 0.72rem;
}

#home-mission-feedback {
    margin-bottom: 0.22rem;
    font-size: 0.72rem;
    color: var(--color-success);
    font-weight: 600;
}

#home-mission-feedback:not(.hidden) {
    animation: status-fade-slide 160ms ease-out;
}

/* Level-up ceremony: character art + their Flow line + a doorway to the
   roster, rendered under the plain claim line. */
.level-up-celebration {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.4rem;
    padding: 0.55rem 0.7rem;
    border-radius: var(--surface-radius-md);
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.16), rgba(56, 189, 248, 0.10));
    border: 1px solid rgba(245, 158, 11, 0.35);
}

.level-up-celebration-art svg {
    width: 34px;
    height: 56px;
    display: block;
}

.level-up-celebration-copy {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.level-up-celebration-headline {
    font-size: 0.82rem;
    font-weight: 800;
    color: #fbbf24;
}

.level-up-celebration-detail {
    font-size: 0.7rem;
    font-style: italic;
    color: var(--text-soft);
}

.level-up-celebration-freeze {
    font-size: 0.7rem;
    font-weight: 700;
    color: #7dd3fc;
}

.level-up-celebration-cta {
    border: none;
    border-radius: var(--surface-radius-md);
    background: var(--color-warning);
    color: var(--color-slate-900);
    font-weight: 800;
    font-size: 0.72rem;
    padding: 0.45rem 0.7rem;
    cursor: pointer;
    white-space: nowrap;
    touch-action: manipulation;
}

.level-up-celebration-cta:hover {
    background: #fbbf24;
}

/* Near-miss magnetism: one gentle pulse on the XP capsule when a runner is
   a single level away. */
.near-miss-pulse {
    animation: near-miss-breathe 1.1s ease-in-out 2;
}

@keyframes near-miss-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

@media (prefers-reduced-motion: reduce) {
    .near-miss-pulse {
        animation: none;
    }
}

#home-missions-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.home-mission-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.3rem;
    border: none;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 0;
    padding: 0.3rem 0;
    background: transparent;
}

.home-mission-row:last-child {
    border-bottom: none;
}

.home-mission-main {
    min-width: 0;
}

.home-mission-row.onboarding-locked {
    opacity: 0.5;
}

@keyframes reward-pulse {
    0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.2); }
    70% { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.home-mission-row.completed,
.home-mission-row.claim-featured,
.home-mission-row.claim-secondary {
    border-color: rgba(74, 222, 128, 0.3);
    background: linear-gradient(90deg, rgba(74, 222, 128, 0.08) 0%, transparent 100%);
    border-radius: var(--surface-radius-sm);
    padding-left: 0.35rem;
}

#home-missions.has-claim-ready .home-mission-row.claim-featured,
#home-missions.has-claim-ready .home-mission-row.claim-secondary {
    animation: reward-pulse 2s infinite ease-out;
}

#home-missions.multi-claim-ready .home-mission-row.claim-secondary {
    border-style: dashed;
    background: rgba(30, 41, 59, 0.34);
}

#home-missions.has-claim-ready #home-missions-summary {
    color: #bbf7d0;
}

#home-missions.multi-claim-ready .home-mission-row.deemphasized-progress {
    opacity: 0.9;
}

.home-mission-title {
    color: var(--text-soft);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.18;
}

.home-mission-row.daily-reward {
    border-left: 2px solid rgba(125, 211, 252, 0.55);
    padding-left: 0.35rem;
    border-radius: var(--surface-radius-sm);
}

.home-mission-badge {
    display: inline-block;
    margin-right: 0.32rem;
    padding: 0.04rem 0.3rem;
    border-radius: var(--radius-full);
    border: 1px solid rgba(125, 211, 252, 0.4);
    background: rgba(8, 47, 73, 0.6);
    color: #bae6fd;
    font-size: 0.56rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    vertical-align: middle;
}

.home-mission-row.claim-secondary .home-mission-title,
.home-mission-row.deemphasized-progress .home-mission-title {
    font-weight: 600;
}

.home-mission-progress {
    margin-top: 0.08rem;
    color: var(--text-muted);
    font-size: 0.69rem;
}

.home-mission-status {
    margin-top: 0.2rem;
    color: var(--color-success);
    font-size: 0.73rem;
    font-weight: 700;
}

#character-select-subtitle {
    font-size: var(--meta-subtitle-size);
    color: var(--text-soft);
    line-height: 1.1;
    max-width: 24ch;
    margin-inline: auto;
    flex-shrink: 0;
}

#character-grid {
    margin-top: var(--meta-cta-safety-gap);
    flex: 1 1 auto;
    min-height: 0;
    align-content: stretch;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    padding: 0.08rem 0.1rem;
    margin-inline: -0.1rem;
}

#character-select-selection-status {
    margin-top: 0.22rem;
    min-height: 1.2rem;
    font-size: 0.78rem;
    color: var(--text-soft);
    border-radius: var(--surface-radius-md);
    border: 1px solid rgba(148, 163, 184, 0.24);
    background: rgba(15, 23, 42, 0.2);
    padding: 0.3rem 0.42rem;
    transition: color 140ms ease;
    flex-shrink: 0;
}

#character-select-start-button {
    margin: 0.18rem auto 0;
    width: 100%;
    flex-shrink: 0;
}

.character-select-back-button {
    margin: 0.3rem auto 0;
    background: transparent;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: var(--surface-radius-md);
    color: var(--text-soft);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    min-height: var(--touch-target-size);
    padding: 0.45rem 1.4rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 140ms ease, border-color 140ms ease;
}

.character-select-back-button:hover,
.character-select-back-button:focus-visible {
    color: var(--color-slate-50);
    border-color: rgba(96, 165, 250, 0.6);
    outline: none;
}

@keyframes status-fade-slide {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 480px) {
    #start-screen,
    #character-select-screen {
        --meta-top-intrusion-buffer: clamp(0.74rem, 2.55vh, 1.2rem);
        --meta-cta-safety-gap: clamp(0.44rem, 1.65vh, 0.86rem);
        --meta-title-size: clamp(0.98rem, 6.1vw, 1.14rem);
        --meta-subtitle-size: clamp(0.58rem, 2.6vw, 0.66rem);
        padding: 0.68rem 0.56rem;
        padding-top: var(--meta-top-dead-zone);
        padding-bottom: clamp(0.48rem, 1.3vh, 0.68rem);
    }
}

/* --- Main Game Screen --- */
#game-screen {
    color: var(--brand-porcelain) !important;
    width: 100%;
    max-width: var(--game-screen-max-width);
    text-align: center;
    background: var(--brand-charcoal) !important;
    border-radius: clamp(12px, 3.2vw, 18px);
    padding: 0.58rem 0.52rem;
    padding-top: var(--game-screen-top-padding);
    padding-bottom: var(--game-screen-bottom-padding);
    position: relative;
    border: 1px solid rgba(148, 163, 184, 0.08);
    transition: background-color 0.5s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.18rem;
    height: var(--app-canvas-height);
    min-height: min(100%, var(--app-canvas-height));
    max-height: var(--app-canvas-height);
    box-shadow: 0 8px 24px -18px rgba(2, 6, 23, 0.74);
}

#game-screen>*+* {
    margin-top: 0;
}

/* --- Headers & HUD --- */
/* --- Headers & HUD --- */
#score-header,
#level-timer-header {
    width: 100%;
    padding: 0.15rem 0.25rem;
    margin-bottom: 0.1rem;
}

#score-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--color-slate-200);
    gap: 0.55rem;
}

#score-area {
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.4rem;
    border-radius: 9999px;
    background: rgba(15, 23, 42, 0.42);
}

#high-score-area {
    padding: 0.2rem 0.4rem;
    border-radius: 9999px;
    background: rgba(15, 23, 42, 0.42);
    font-size: 0.8rem;
}

#score-character-avatar {
    position: relative;
    width: 20px;
    height: 27px;
    border-radius: 999px;
    transition: background-color 160ms ease, box-shadow 160ms ease;
}

#score-character-avatar svg {
    width: 100%;
    height: 100%;
    display: block;
}

#score-character-avatar.flow-state-avatar {
    background: rgba(250, 204, 21, 0.14);
    box-shadow:
        0 0 0 2px rgba(254, 240, 138, 0.88),
        0 0 12px rgba(250, 204, 21, 0.72);
    animation: flow-state-avatar-glow 1400ms ease-in-out infinite alternate;
}

#score-character-avatar.flow-state-avatar::after {
    content: "✦";
    position: absolute;
    top: -0.42rem;
    right: -0.46rem;
    color: #fde047;
    font-size: 0.68rem;
    line-height: 1;
    text-shadow: 0 0 6px rgba(250, 204, 21, 0.9);
}

#flow-state-quip {
    position: absolute;
    top: 50%;
    left: calc(100% + 0.5rem);
    z-index: 45;
    width: max-content;
    max-width: min(54vw, 13.5rem);
    padding: 0.3rem 0.55rem;
    border: 1px solid rgba(254, 240, 138, 0.58);
    border-radius: 0.65rem 0.65rem 0.65rem 0.16rem;
    background: rgba(66, 32, 6, 0.96);
    box-shadow: 0 7px 16px rgba(2, 6, 23, 0.36);
    color: #fef9c3;
    font-size: 0.7rem;
    font-weight: 800;
    line-height: 1.2;
    text-align: left;
    pointer-events: none;
    transform: translateY(-50%);
    animation: flow-state-quip-in 160ms ease-out;
}

@keyframes flow-state-avatar-glow {
    from {
        box-shadow:
            0 0 0 2px rgba(254, 240, 138, 0.74),
            0 0 8px rgba(250, 204, 21, 0.46);
    }

    to {
        box-shadow:
            0 0 0 2px rgba(254, 240, 138, 0.96),
            0 0 15px rgba(250, 204, 21, 0.78);
    }
}

@keyframes flow-state-quip-in {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(-3px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0) scale(1);
    }
}

#level-timer-header {
    display: grid;
    grid-template-areas: "mute title timer";
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.38rem;
}

#mute-toggle {
    --hud-control-size: 44px;
    grid-area: mute;
    justify-self: start;
    font-size: 1.05rem;
    min-width: var(--hud-control-size);
    min-height: var(--hud-control-size);
    background: none;
    border: 1px solid rgba(148, 163, 184, 0.45);
    border-radius: 9999px;
    cursor: pointer;
    padding: 0.18rem 0.42rem;
    line-height: 1;
    color: var(--color-slate-100);
    background-color: rgba(15, 23, 42, 0.45);
}

#level-title-container {
    grid-area: title;
    justify-self: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    white-space: normal;
    margin-bottom: 0;
    min-width: 0;
}

#level-title {
    font-size: clamp(0.78rem, 3.1vw, 1rem);
    line-height: 1.2;
    font-weight: 900;
    color: var(--brand-porcelain);
    letter-spacing: 0.01em;
    text-wrap: balance;
}

#star-container {
    --hud-star-size: 0.8rem;
    --hud-star-gap: 0.16rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--hud-star-gap);
    min-height: 0;
}

#star-container:empty {
    display: none;
}

#star-container > div {
    display: flex;
}

#star-container .star {
    display: block;
    width: var(--hud-star-size);
    height: var(--hud-star-size);
    fill: var(--brand-charcoal-raised);
    stroke: var(--brand-metal);
    stroke-width: 1.5;
}

#star-container .star.filled {
    fill: var(--brand-yellow);
    stroke: var(--brand-yellow-deep);
}

#timer-container {
    grid-area: timer;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.17rem 0.38rem;
    border-radius: 9999px;
    border: 1px solid rgba(245, 158, 11, 0.35);
    background: rgba(15, 23, 42, 0.45);
}

#timer-area {
    font-size: 1.28rem;
    font-weight: 900;
    color: var(--color-warning);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

.time-bonus-flash {
    animation: pulse-green 0.4s ease-in-out;
    color: var(--color-success) !important;
}

@keyframes pulse-green {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }

    100% {
        transform: scale(1);
    }
}

@media (max-width: 480px) {
    #game-screen {
        --game-screen-top-padding: clamp(0.42rem, 1.3vh, 0.62rem);
        --game-screen-bottom-padding: clamp(0.32rem, 0.9vh, 0.42rem);
        padding: 0.5rem 0.42rem;
        padding-top: var(--game-screen-top-padding);
        padding-bottom: var(--game-screen-bottom-padding);
    }

    #score-header {
        font-size: 0.78rem;
    }

    #level-title {
        font-size: 0.84rem;
        line-height: 1.08;
    }

    #timer-area {
        font-size: 1.1rem;
    }

    #score-header,
    #level-timer-header {
        gap: 0.35rem;
        padding-left: 0.05rem;
        padding-right: 0.05rem;
    }

    #timer-container {
        padding: 0.12rem 0.3rem;
    }

    #mute-toggle {
        font-size: 0.94rem;
        padding: 0.14rem 0.35rem;
    }
}

/* --- Bladder --- */
#bladder-container {
    width: 18px;
    height: 24px;
    border: 2px solid var(--color-accent);
    border-radius: 50% 50% 30% 30% / 60% 60% 40% 40%;
    position: relative;
    overflow: hidden;
    background-color: var(--color-slate-700);
}

#bladder-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--color-accent);
    transition: height 1s linear;
}

#bladder-fill.emptying {
    height: 0 !important;
    transition: height 0.5s ease-in-out !important;
}

/* ===== World map (campaign hub) ===== */
#world-map-screen {
    width: 100%;
    max-width: 30rem;
    display: flex;
    flex-direction: column;
    padding: 0;
    background: var(--bg-card);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: clamp(12px, 3.2vw, 18px);
    height: var(--app-canvas-height);
    max-height: var(--app-canvas-height);
    min-height: 0;
    flex-shrink: 0;
    overflow: hidden;
}

#world-map-screen.hidden {
    display: none;
}

.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    flex-shrink: 0;
    padding: var(--screen-content-padding);
    background: var(--brand-charcoal-raised);
    border-bottom: 1px solid var(--surface-border-subtle);
}

/* Only the content scrolls. Headers and actions occupy real layout space,
   so cards cannot slip behind them or into the native banner reserve. */
.screen-scroll-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding: var(--screen-content-padding);
    scroll-padding-block: var(--screen-content-padding);
}

#world-map-continue-button {
    width: 100%;
    margin-bottom: var(--screen-content-padding);
}

#character-select-screen {
    padding: 0;
    overflow: hidden;
    scrollbar-gutter: auto;
    flex-shrink: 0;
}

#character-select-screen > * + * {
    margin-top: 0;
}

.screen-header .character-select-back-button {
    margin: 0;
    padding-inline: 0.85rem;
}

.screen-header-copy {
    flex: 1;
    min-width: 0;
    text-align: left;
}

#character-select-title {
    font-size: var(--meta-title-size);
    text-shadow: none;
    line-height: 1.2;
}

#character-select-subtitle {
    max-width: none;
    margin-top: 0.2rem;
}

#character-select-screen #character-grid {
    margin: 0;
    padding: var(--screen-content-padding);
    scroll-padding-block: var(--screen-content-padding);
    align-content: start;
}

.screen-footer {
    flex-shrink: 0;
    padding: 0.5rem var(--screen-content-padding) var(--screen-content-padding);
    border-top: 1px solid var(--surface-border-subtle);
    background: var(--bg-card);
}

#character-select-selection-status {
    margin: 0 0 0.4rem;
    padding: 0;
    border: 0;
    background: none;
    min-height: 0;
}

#character-select-start-button {
    margin: 0;
}

/* In the header the button is a compact leading control, not a centred footer
   action, so the auto margins from .character-select-back-button are dropped. */
.world-map-back-button {
    margin: 0;
    padding: 0.32rem 0.85rem;
    font-size: 0.78rem;
}

#world-map-title {
    font-size: 1.35rem;
    font-weight: 900;
    color: var(--color-slate-50);
    margin: 0;
}

#world-map-total-stars {
    font-size: 1rem;
    font-weight: 800;
    color: #fbbf24;
    text-shadow: 0 1px 4px rgba(2, 6, 23, 0.7);
}

.world-map-section {
    background: rgba(30, 41, 59, 0.45);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: var(--surface-radius-md);
    padding: 0.6rem 0.65rem 0.7rem;
    margin-bottom: 0.55rem;
}

.world-map-section-locked {
    opacity: 1;
}

.world-map-section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.world-map-section-name {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--color-slate-50);
}

.world-map-section-stars {
    font-size: 0.75rem;
    font-weight: 700;
    color: #fbbf24;
    white-space: nowrap;
}

.world-map-section-locked .world-map-section-stars {
    color: var(--text-subtle);
}

.world-map-level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr));
    gap: 0.4rem;
}

.world-map-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    min-height: 3rem;
    border-radius: 10px;
    border: 1.5px solid rgba(148, 163, 184, 0.3);
    background: rgba(15, 23, 42, 0.5);
    color: var(--color-slate-50);
    font: inherit;
    cursor: pointer;
    padding: 0.25rem 0.15rem;
    transition: border-color 140ms ease, transform 140ms ease;
}

.world-map-node:hover:not(.world-map-node-locked),
.world-map-node:focus-visible {
    border-color: rgba(96, 165, 250, 0.75);
    transform: translateY(-1px);
    outline: none;
}

.world-map-node-level {
    font-size: 0.95rem;
    font-weight: 900;
    line-height: 1;
}

.world-map-node-stars {
    font-size: 0.6rem;
    line-height: 1;
    color: #fbbf24;
    min-height: 0.65rem;
    letter-spacing: 0.05em;
}

.world-map-node-cleared {
    background: rgba(37, 99, 235, 0.28);
    border-color: rgba(96, 165, 250, 0.45);
}

.world-map-node-current {
    border-color: rgba(251, 191, 36, 0.9);
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.35);
    animation: world-map-current-pulse 1.6s ease-in-out infinite;
}

.world-map-node-locked {
    cursor: not-allowed;
    opacity: 0.55;
}

@keyframes world-map-current-pulse {
    0%,
    100% {
        box-shadow: 0 0 4px rgba(251, 191, 36, 0.25);
    }

    50% {
        box-shadow: 0 0 10px rgba(251, 191, 36, 0.55);
    }
}

@media (prefers-reduced-motion: reduce) {
    .world-map-node-current {
        animation: none;
    }
}

#world-map-back-button {
    align-self: center;
}

#world-map-continue-button {
    background: var(--action-primary-bg);
    border: 1px solid var(--action-primary-border);
    color: var(--action-primary-text);
    text-align: left;
}

#world-map-continue-button:hover,
#world-map-continue-button:focus-visible {
    background: var(--action-primary-hover-bg);
    outline: var(--focus-ring);
}

#coach-banner {
    position: absolute;
    /* Bottom-anchored: the top band is owned by the timer egg and the queue
       strip — the banner used to tangle with both. Down here it floats over
       the bathroom floor, the emptiest zone on the screen. */
    bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    max-width: min(86%, 26rem);
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(96, 165, 250, 0.5);
    border-radius: 999px;
    color: var(--color-slate-50, #f8fafc);
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1.3;
    padding: 0.45rem 0.95rem;
    pointer-events: none;
    box-shadow: 0 10px 22px rgba(2, 6, 23, 0.45);
    /* Dedicated keyframes: the shared status-fade-slide animates transform
       and silently dropped the translateX(-50%) centering mid-entry, which
       is what shoved the banner into the timer egg. */
    animation: coach-banner-in 220ms ease;
}

@keyframes coach-banner-in {
    from {
        opacity: 0;
        transform: translate(-50%, 6px);
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

#coach-banner.hidden {
    display: none;
}

#game-stage {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 0.12rem;
    padding-bottom: 0;
}

@media (max-height: 760px) {
    #game-screen {
        --game-screen-top-padding: clamp(0.32rem, 1vh, 0.5rem);
        --game-screen-bottom-padding: clamp(0.28rem, 0.8vh, 0.38rem);
        min-height: min(100%, var(--app-canvas-height));
        max-height: var(--app-canvas-height);
        padding-top: var(--game-screen-top-padding);
        padding-bottom: var(--game-screen-bottom-padding);
    }

    #score-header,
    #level-timer-header {
        margin-bottom: 0;
    }

    #level-title {
        font-size: 0.82rem;
    }

    #timer-area {
        font-size: 1.02rem;
    }
}

@media (max-height: 740px) {
    #start-screen,
    #character-select-screen {
        --meta-top-intrusion-buffer: clamp(0.64rem, 2.15vh, 1.04rem);
        --meta-cta-safety-gap: clamp(0.38rem, 1.35vh, 0.74rem);
    }

    #home-content-stack>*+* {
        margin-top: 0.28rem;
    }

    #home-content-stack {
        margin-block: 0;
    }

    #home-missions {
        max-height: clamp(5.8rem, 18vh, 8.4rem);
        overflow-y: auto;
        padding: 0.24rem 0.12rem 0.1rem;
        min-height: 0;
    }

    #home-missions-summary,
    #home-mission-feedback {
        margin-bottom: 0.18rem;
    }

    #character-select-subtitle {
        font-size: clamp(0.62rem, 1.8vw, 0.68rem);
    }
}

/* --- Overlays --- */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

#flicker-overlay,
#frenzy-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

#flicker-overlay.flicker-active {
    background-color: rgba(0, 0, 0, 0.3);
    opacity: 0.3;
}

#frenzy-overlay {
    background: radial-gradient(
        circle at 50% 42%,
        transparent 36%,
        rgba(250, 204, 21, 0.2) 100%
    );
    animation: flow-state-wash 1800ms ease-in-out infinite alternate;
}

/* Compact Flow State status. Internal frenzy-* selectors preserve the runtime
   and analytics contract while player-facing copy owns the branded name.
   Mount #frenzy-status as a direct child of
   #game-screen so it participates in the flex layout without covering a
   tappable urinal. JS owns the benefit/time text and may update
   #frenzy-progress width or --frenzy-progress (1 -> 0). */
#frenzy-status {
    --frenzy-progress: 1;
    align-self: center;
    position: relative;
    z-index: 35;
    isolation: isolate;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
        "copy"
        "track";
    align-items: center;
    row-gap: 0.2rem;
    width: min(100%, 28rem);
    min-height: 2rem;
    padding: 0.28rem 0.48rem 0.24rem;
    overflow: hidden;
    border: 1px solid rgba(250, 204, 21, 0.72);
    border-radius: 0.7rem;
    background: linear-gradient(105deg, rgba(69, 26, 3, 0.96), rgba(15, 23, 42, 0.96));
    color: var(--color-slate-50, #f8fafc);
    box-shadow: 0 5px 14px rgba(2, 6, 23, 0.34), 0 0 12px rgba(250, 204, 21, 0.16);
    pointer-events: none;
    animation: frenzy-status-enter 180ms ease-out, frenzy-status-glow 900ms ease-in-out infinite alternate;
}

#frenzy-status[hidden],
#frenzy-status[aria-hidden="true"],
#frenzy-status[data-active="false"] {
    display: none;
}

/* If Frenzy expires while a choice is still live, keep its flex row until the
   round resolves. Removing it immediately would shift tappable urinals under
   the player's finger. JS releases the row during the board transition. */
#frenzy-status[data-active="false"][data-reserve-space="true"] {
    display: grid;
    visibility: hidden;
    animation: none;
}

.frenzy-status-copy {
    grid-area: copy;
    min-width: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "title benefit time";
    align-items: center;
    column-gap: 0.42rem;
}

.frenzy-status-title {
    grid-area: title;
    color: #422006;
    background: linear-gradient(180deg, #fef08a, #fbbf24);
    border: 1px solid rgba(254, 240, 138, 0.9);
    border-radius: 999px;
    padding: 0.16rem 0.4rem;
    font-size: 0.64rem;
    font-weight: 900;
    line-height: 1;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.frenzy-status-benefit {
    grid-area: benefit;
    min-width: 0;
    display: block;
    color: #fef3c7;
    font-size: 0.62rem;
    font-weight: 800;
    line-height: 1.05;
    white-space: nowrap;
}

#frenzy-time {
    grid-area: time;
    min-width: 2.8rem;
    color: #fde047;
    font-size: 0.82rem;
    font-weight: 900;
    line-height: 1;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

.frenzy-status-track {
    grid-area: track;
    width: 100%;
    height: 0.2rem;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(254, 243, 199, 0.18);
}

#frenzy-progress {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(
        90deg,
        #f59e0b 0%,
        #fde047 38%,
        #fef9c3 50%,
        #fbbf24 64%,
        #fde047 100%
    );
    background-size: 180% 100%;
    transform: scaleX(var(--frenzy-progress, 1));
    transform-origin: left center;
    transition: transform 100ms linear;
    animation: flow-state-meter 1400ms ease-in-out infinite alternate;
}

@keyframes flow-state-meter {
    from {
        background-position: 100% 0;
    }

    to {
        background-position: -80% 0;
    }
}

#frenzy-status[data-expiring="true"] {
    border-color: rgba(251, 146, 60, 0.9);
}

#frenzy-status[data-expiring="true"] #frenzy-time {
    color: #fb923c;
}

@keyframes frenzy-status-enter {
    from {
        opacity: 0;
        transform: translateY(-4px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes frenzy-status-glow {
    from {
        box-shadow: 0 5px 14px rgba(2, 6, 23, 0.34), 0 0 7px rgba(250, 204, 21, 0.12);
    }

    to {
        box-shadow: 0 5px 14px rgba(2, 6, 23, 0.34), 0 0 15px rgba(250, 204, 21, 0.28);
    }
}

@keyframes flow-state-wash {
    from {
        opacity: 0.42;
    }

    to {
        opacity: 0.58;
    }
}

@media (max-width: 520px) {
    #frenzy-status {
        padding-inline: 0.38rem;
    }

    .frenzy-status-copy {
        column-gap: 0.3rem;
    }

    .frenzy-status-title {
        font-size: 0.62rem;
        padding-inline: 0.32rem;
    }

    .frenzy-status-benefit {
        font-size: 0.72rem;
        white-space: normal;
    }

    #frenzy-time {
        min-width: 2.45rem;
        font-size: 0.76rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #frenzy-overlay,
    #frenzy-status,
    #score-character-avatar.flow-state-avatar,
    #flow-state-quip,
    #frenzy-progress {
        animation: none;
    }

    #frenzy-overlay {
        opacity: 0.48;
    }

    #frenzy-progress {
        transition: none;
    }
}

/* WAIT/GO phase indicator: a floating word, not a scrim — the board stays
   readable through the queue (the dim lives on .bathroom-walls) and the
   WAIT→GO! flip is the loudest signal that the turn has started. */
#wait-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: transparent;
    pointer-events: none;
    font-size: 2.6rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 6;
    border-radius: 8px;
    -webkit-text-stroke: 1px var(--color-warning);
    color: var(--color-accent);
    text-shadow: 0 4px 18px rgba(2, 6, 23, 0.55);
    animation: wait-indicator-in 0.25s ease;
}

#wait-overlay.go {
    color: #4ade80;
    -webkit-text-stroke: 1px #166534;
    animation: go-indicator-pop 0.45s ease;
}

@keyframes wait-indicator-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes go-indicator-pop {
    0% {
        opacity: 0;
        transform: scale(0.55);
    }

    60% {
        opacity: 1;
        transform: scale(1.16);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Phone surfaces fill the usable viewport. The outer shell alone reserves
   native chrome; scrollable content never adds another copy of that inset. */
@media (max-width: 600px), (max-height: 500px) {
    :root {
        --app-edge-gap: 0px;
        --app-top-gap: 0px;
        --app-bottom-gap: 0px;
        --meta-top-dead-zone: var(--surface-top-padding);
    }

    #start-screen,
    #character-select-screen,
    #world-map-screen,
    #game-screen {
        border-radius: 0;
        border: 0;
        box-shadow: none;
    }
}

@media (min-width: 600px) and (max-height: 500px) {
    #character-select-screen {
        max-width: 52rem;
    }

    #character-select-header,
    #character-select-footer {
        padding-block: 0.35rem;
    }

    #character-select-screen #character-grid {
        padding-block: 0.35rem;
    }

    #character-select-start-button {
        min-height: var(--touch-target-size);
        padding-block: 0.35rem;
    }
}

/* Urinals & Environment */

#bathroom-container {
    position: relative;
    margin: 0 auto;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: stretch;
    flex: 1;
    min-height: 0;
}

.bathroom-walls {
    background-color: var(--color-slate-200);
    border: 2px solid var(--color-slate-400);
    border-radius: 10px;
    padding: var(--room-top-inset, 64px) 2px var(--room-bottom-inset, 48px);
    margin: 0 auto;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    height: 100%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: background-color 0.5s ease, border-color 0.5s ease;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#urinal-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    width: 100%;
    transform-origin: center center;
    /* Board coordinates stay fixed while a choice is live. */
}

.urinal-row {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: var(--fixture-gap, 8px);
    width: 100%;
}

.urinal-row-divider {
    width: 80%;
    max-width: 500px;
    height: 2px;
    flex-shrink: 0;
    background-color: var(--color-slate-600);
    margin-block: calc((var(--board-row-separation, 12px) - 2px) / 2);
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Single Urinal Item */
.urinal {
    height: var(--fixture-height, 100px);
    width: var(--fixture-width, 58px);
    flex: 0 0 var(--fixture-width, 58px);
    cursor: pointer;
    transition: transform 0.16s ease-in-out, filter 0.16s ease-in-out;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    border-radius: 12px;
    isolation: isolate;
}

.urinal-fixture-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: visible;
}

.urinal-path-main {
    stroke-width: var(--gameplay-contour-width);
    transition: fill var(--gameplay-contour-transition) ease-in-out,
        stroke var(--gameplay-contour-transition) ease-in-out,
        stroke-width var(--gameplay-contour-transition) ease-in-out;
}

.urinal-state-layer {
    transition: filter 0.18s ease-in-out, opacity 0.18s ease-in-out;
}

/* Baseline Readability States */
.urinal.state-empty .urinal-path-main {
    fill: var(--gameplay-empty-fill);
    stroke: var(--gameplay-empty-stroke);
}

.urinal.state-empty .urinal-cake.playable-cake {
    fill: #67e8f9;
    stroke: #0284c7;
    stroke-width: 0.85;
}

.urinal.state-occupied .urinal-path-main,
.urinal.state-blocked .urinal-path-main {
    fill: var(--gameplay-occupied-fill);
    stroke: var(--gameplay-occupied-stroke);
}

.urinal .urinal-cake.blocked-cake {
    fill: #94a3b8;
    stroke: #64748b;
    stroke-width: 0.6;
}

/* Fixture variants keep their native silhouette and the same bowl contour. */

/* Crouch for the tiny fixture: squash the avatar (and its walking clone —
   the clone inherits the class) plus the occupant dressed into the stall on
   arrival, with apologetic dignity. The fixture svg itself stays upright.
   Transition-only, so reduced-motion needs no special case. */
#player-avatar.kids-crouch svg,
.player-walker.kids-crouch svg {
    transform: scaleY(0.78) translateY(9px);
    transition: transform 0.3s ease;
}

.urinal.kids-crouch .urinal-state-layer {
    /* Keep feet on the step while compressing the pose from the shoulders. */
    transform-box: fill-box;
    transform-origin: center bottom;
    transform: translateY(-7px) scaleY(0.78);
}

/* A single bowl contour carries interaction feedback. Golden porcelain stays
   gold; the contour follows this order: idle -> hover/focus -> hint -> pending
   -> correct -> wrong. :where keeps hover/focus at the same specificity as
   state classes, so later verdicts always win, including mixed reveal states. */
.urinal.golden .urinal-path-main {
    fill: var(--gameplay-golden-fill);
    stroke: var(--gameplay-golden-stroke);
}

@media (hover: hover) and (pointer: fine) {
    .urinal.state-selectable:where(:hover) .urinal-path-main {
        stroke: var(--gameplay-highlight-hover);
        stroke-width: var(--gameplay-contour-hover-width);
    }
}

.urinal.state-selectable:active {
    transform: scale(0.98);
}

/* Keyboard focus uses the same bowl path. Its dash survives later result
   colors, so focus remains visible without a second rectangular outline. */
.urinal[role="button"]:focus-visible {
    outline: none;
}

.urinal[role="button"]:where(:focus-visible) .urinal-path-main {
    stroke: var(--gameplay-highlight-pending);
    stroke-width: var(--gameplay-contour-feedback-width);
    stroke-dasharray: var(--gameplay-contour-focus-dash);
}

.urinal.ai-chosen .urinal-path-main {
    stroke: var(--gameplay-highlight-pending);
    stroke-width: var(--gameplay-contour-feedback-width);
}

/* Tutorial and fail reveals point at the solution without moving the target
   or adding a pulse outside its porcelain silhouette. */
.urinal.tutorial-hint-pulse .urinal-path-main,
.urinal.urinal-solution-highlight .urinal-path-main {
    stroke: var(--gameplay-highlight-solution);
    stroke-width: var(--gameplay-contour-feedback-width);
}

.urinal.player-selection-pending .urinal-path-main {
    stroke: var(--gameplay-highlight-pending);
    stroke-width: var(--gameplay-contour-feedback-width);
}

.urinal.player-chosen-correct .urinal-path-main {
    stroke: var(--gameplay-highlight-correct);
    stroke-width: var(--gameplay-contour-feedback-width);
}

/* The red verdict is steady for every hazard. The native content explains
   the cause, while the contour remains the only selection/result mark. */
.urinal.player-chosen-incorrect .urinal-path-main {
    stroke: var(--gameplay-highlight-incorrect);
    stroke-width: var(--gameplay-contour-feedback-width);
}

.urinal.family-occupied .urinal-state-layer {
    filter: drop-shadow(0 1px 1px var(--gameplay-occupied-shadow));
}

/* Hazard families carry NO body strokes, tinted fills, or cell rings — every
   fixture is a normal urinal; the CONTENT differentiates (mess decals, the
   chatty patron, the maintenance sign, the janitor). Colored outlines were
   pre-decal color-coding and read as extra UI ("why is this one outlined?").
   The only body-color identity in the game is the golden urinal.
   Dirty/messy keep white porcelain (one step dimmer than selectable-empty
   #f8fafc) so the mess pops; other blocked fixtures keep the blocked slate
   body from the baseline rules above. */
.urinal.family-dirty .urinal-path-main,
.urinal.family-messy .urinal-path-main {
    fill: #f1f5f9;
}

.urinal-divider {
    width: var(--divider-width, 7px);
    height: var(--divider-height, 72px);
    flex: 0 0 var(--divider-width, 7px);
    background-color: var(--color-slate-400);
    border-radius: 3px;
    transition: background-color 0.5s ease;
}

/* Misc Urinal Elements */
.urinal-cake {
    fill: #7dd3fc;
    stroke: #0ea5e9;
    stroke-width: 0.8;
}

.flusher.broken {
    transform: rotate(-20deg) translate(-7px, 3px);
    opacity: 0.6;
}

/* Characters/Animations on Urinals */
.head-shake .body {
    animation: head-shake-anim 0.5s ease-in-out;
}

@keyframes head-shake-anim {

    0%,
    100% {
        transform: translateX(0) rotate(0);
    }

    20% {
        transform: translateX(-3px) rotate(-2deg);
    }

    40% {
        transform: translateX(3px) rotate(2deg);
    }

    60% {
        transform: translateX(-3px) rotate(-2deg);
    }

    80% {
        transform: translateX(3px) rotate(2deg);
    }
}

.speech-bubble {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Door */
#door {
    position: absolute;
    bottom: 0px;
    right: 100%;
    margin-right: 2px;
    width: 25px;
    height: 85px;
    background-color: #78350f;
    border: 2px solid #451a03;
    border-right: none;
    border-radius: 4px 0 0 4px;
    z-index: 10;
}

#door-knob {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 4px;
    width: 4px;
    height: 4px;
    background-color: #facc15;
    border-radius: 50%;
}

#player-avatar,
.player-walker {
    position: absolute;
    bottom: 10px;
    left: -40px;
    /* Initial position (off-screen or by door), JS moves it */
    width: 45px;
    height: 80px;
    z-index: 20;
    transition: left 0.5s linear, top 0.5s linear;
}

/* Note: Player Avatar styles seem to be mostly dynamic, but ensuring basic style here */

/* Short rooms reserve their limited height for the decision. */
.bathroom-walls[data-compact-room="true"] #room-decor,
.bathroom-walls[data-compact-room="true"]::before {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    .head-shake .body, .speech-bubble { animation: none; }
}

/* Queue Area
   The strip is the gate for all input during the wait phase, so its states
   are explicit: live "N ahead" chip → "You're up!" → the whole strip fades
   (keeping its layout space) once the turn starts. The board itself dims
   under #game-screen.phase-queue and brightens back as the standing GO cue. */

#queue-area {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 0.05rem;
    margin-right: 2px;
    min-height: 78px;
    margin-bottom: 0;
    padding: 0.14rem 0.18rem;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.26);
    background: var(--gameplay-queue-light);
    position: relative;
    /* The "You" label hangs below the row; keep it above the board chrome. */
    z-index: 3;
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

/* Turn handoff: fade the strip out but keep its space so the board never
   shifts mid-level. The 0.9s delay lets the "You're up!" flip land first.
   The transition lives on this state only, so removing the class (next
   level's render) snaps the strip back instantly. */
#queue-area.queue-strip-done {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.45s ease 0.9s, visibility 0s linear 1.35s;
}

#queue-label {
    align-self: center;
    font-weight: 700;
    color: var(--color-slate-200);
    margin-right: 0.35rem;
    font-size: 0.74rem;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    background: var(--gameplay-queue-chip-bg);
    border: 1px solid rgba(148, 163, 184, 0.36);
    border-radius: 999px;
    padding: 0.18rem 0.5rem;
    white-space: nowrap;
}

.queue-person {
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
    position: relative;
    /* Bottom room keeps the hanging "You" label inside the strip. */
    margin-bottom: 16px;
    animation: queue-bob 2.5s ease-in-out infinite;
    filter: drop-shadow(0 2px 1px rgba(15, 23, 42, 0.28));
}

@keyframes queue-bob {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }
}

.queue-person.player-in-queue {
    animation: player-bob 1.5s ease-in-out infinite;
}

.queue-player-marker svg path {
    fill: #fb923c;
    stroke: #9a3412;
    stroke-width: 0.6;
}

@keyframes player-bob {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* "You're up" pulse on the player marker at turn start. Declared after
   .player-in-queue so it wins the animation shorthand. */
.queue-person.player-turn-active {
    animation: player-turn-pulse 0.5s ease-in-out 2;
    filter: drop-shadow(0 0 7px rgba(251, 146, 60, 0.95));
}

@keyframes player-turn-pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.22);
    }
}

.queue-person-label {
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.5);
    padding: 1px 4px;
    border-radius: 3px;
    color: var(--color-slate-200);
    white-space: nowrap;
    z-index: 1;
}

#queue-area[data-queue-pressure="busy"] {
    background: var(--gameplay-queue-busy);
    border-color: rgba(245, 158, 11, 0.56);
}

#queue-area[data-queue-pressure="crunch"] {
    background: var(--gameplay-queue-crunch);
    border-color: rgba(239, 68, 68, 0.54);
}

/* --- Wait phase: the room is visibly "not yours yet" ------------------- */

/* Re-declare the base transitions (urinals.css) alongside filter — the
   shorthand would otherwise clobber the themed wall color transitions. */
.bathroom-walls {
    transition: background-color 0.5s ease, border-color 0.5s ease, filter 0.25s ease;
}

/* Dim + desaturate the whole room (urinals, patrons, themed props like the
   stadium banner) while the queue runs. Light enough to study the board;
   the lift at turn start is the persistent "go" signal. */
#game-screen.phase-queue .bathroom-walls {
    filter: brightness(0.74) saturate(0.55);
}

#game-screen.phase-queue .urinal,
#game-screen.phase-queue .urinal.state-selectable {
    cursor: default;
}

#game-screen.phase-queue .urinal.state-selectable:active {
    transform: none;
}

/* Denied tap during the wait: a quick "not yet" headshake on the tapped
   urinal (paired with the soft thud + coach toast from the game loop). */
.urinal.queue-denied-shake {
    animation: queue-denied-shake 0.4s ease;
}

@keyframes queue-denied-shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-6px) rotate(-1.2deg);
    }

    40% {
        transform: translateX(5px) rotate(1deg);
    }

    60% {
        transform: translateX(-4px);
    }

    80% {
        transform: translateX(3px);
    }
}

/* --- Turn handoff beats ------------------------------------------------ */

/* Golden pulse on the timer group the moment the countdown becomes live. */
.timer-active-flash {
    animation: timer-flash 0.8s ease;
    border-radius: 999px;
}

@keyframes timer-flash {

    0%,
    100% {
        transform: scale(1);
        box-shadow: none;
    }

    35% {
        transform: scale(1.12);
        box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.4), 0 0 18px rgba(250, 204, 21, 0.6);
    }
}

/* Door held hidden through the wait pops in when it's finally your turn. */
#door.door-reveal {
    animation: door-reveal 0.45s ease;
}

@keyframes door-reveal {
    0% {
        opacity: 0;
        transform: translateX(-10px);
    }

    60% {
        opacity: 1;
        transform: translateX(2px);
    }

    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* A patron settling into the spot they just took during the queue. */
.urinal.just-arrived {
    animation: just-arrived-pop 0.4s ease;
}

@keyframes just-arrived-pop {
    0% {
        transform: scale(1.08);
    }

    100% {
        transform: scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {

    .urinal.queue-denied-shake,
    #door.door-reveal,
    .urinal.just-arrived,
    .queue-person.player-turn-active,
    .timer-active-flash {
        animation: none;
    }
}

@media (max-height: 760px) {
    #queue-area {
        min-height: 64px;
    }
}

@media (max-width: 390px) {
    #queue-area {
        min-height: 60px;
    }

    #queue-label {
        font-size: 0.68rem;
    }
}

/* A small bathroom-signage bubble: a moving clue, never a safe-choice outline. */
#game-screen[data-departure-encounter] .bathroom-walls {
    /* Board layout reads these before sizing fixtures, including in landscape. */
    --board-min-top-inset: 48px;
    --board-min-bottom-inset: 80px;
}

#game-screen[data-departure-encounter] #coach-banner {
    width: calc(100% - 2rem);
    border-radius: 0.75rem;
    background: var(--brand-charcoal);
    border-color: var(--brand-metal);
    color: var(--brand-cream);
    text-align: center;
}

.departure-cue {
    position: absolute;
    --departure-cue-tail: 0.45rem;
    --departure-cue-pointer: 50%;
    bottom: calc(100% + 0.6rem);
    z-index: 3;
    width: max(100%, 6.3rem);
    box-sizing: border-box;
    padding: 0.35rem 0.45rem 0.4rem;
    border-radius: 0.6rem;
    background: var(--brand-yellow);
    color: var(--brand-ink);
    box-shadow: 0 2px 0 var(--brand-yellow-deep), 0 4px 8px rgb(0 0 0 / 0.2);
    font-size: 0.7rem;
    line-height: 1.3;
    font-weight: 900;
    white-space: nowrap;
    text-align: center;
    pointer-events: none;
}

.departure-cue::after {
    content: "";
    position: absolute;
    top: calc(100% - 1px);
    left: var(--departure-cue-pointer);
    border: var(--departure-cue-tail) solid transparent;
    border-top-color: var(--brand-yellow);
    transform: translateX(-50%);
}

.departure-cue[data-edge="start"] {
    left: 0;
    --departure-cue-pointer: calc(var(--fixture-width) / 2);
}
.departure-cue[data-edge="end"] {
    right: 0;
    --departure-cue-pointer: calc(100% - var(--fixture-width) / 2);
}

.departure-cue-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* A code-native drop keeps the cue consistent across emoji/platform fonts. */
.departure-cue-label::before {
    content: "";
    flex: none;
    width: 0.5rem;
    height: 0.6rem;
    background: currentColor;
    border-radius: 70% 30% 65% 35%;
    transform: rotate(-45deg);
}

.departure-meter {
    box-sizing: border-box;
    height: 0.4rem;
    margin-top: 0.3rem;
    border: 1px solid var(--brand-ink);
    background: var(--brand-ink);
    border-radius: 999px;
    overflow: hidden;
}

.departure-meter-fill {
    display: block;
    height: 100%;
    width: 100%;
    transform-origin: left center;
    border-radius: inherit;
    background: var(--brand-yellow);
    /* Updates follow active game time. No CSS animation can run while paused. */
}

/* Round-feedback juice: score pops, room verdict, frenzy burst.
   All elements are pointer-events:none overlays inside #game-screen. */

.score-pop {
    position: absolute;
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.05rem;
    transform: translate(-50%, -100%);
    pointer-events: none;
    animation: score-pop-rise 900ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

.score-pop-points {
    font-size: 1.15rem;
    font-weight: 900;
    color: #4ade80;
    text-shadow: 0 2px 6px rgba(2, 6, 23, 0.75);
    line-height: 1;
}

.score-pop-stars {
    font-size: 0.75rem;
    color: #fbbf24;
    text-shadow: 0 1px 4px rgba(2, 6, 23, 0.7);
    line-height: 1;
    letter-spacing: 0.12em;
}

.score-pop-frenzy .score-pop-points {
    color: #fde047;
    font-size: 1.35rem;
}

@keyframes score-pop-rise {
    0% {
        opacity: 0;
        transform: translate(-50%, -92%) scale(0.7);
    }

    18% {
        opacity: 1;
        transform: translate(-50%, -112%) scale(1.08);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -190%) scale(1);
    }
}

.frenzy-particle {
    position: absolute;
    z-index: 42;
    font-size: 1rem;
    transform: translate(-50%, -50%);
    pointer-events: none;
    animation: frenzy-particle-burst 1000ms ease-out forwards;
}

@keyframes frenzy-particle-burst {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }

    12% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--burst-x, 0px)), calc(-50% + var(--burst-y, -40px))) scale(1.15);
    }
}

/* A verdict occupies the room's existing signage area, never the board's
   layout. It stays visible until the next board even without animation. */
.round-feedback {
    position: absolute;
    top: 0.6rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 46;
    display: flex;
    flex-direction: column;
    gap: 0.08rem;
    width: max-content;
    max-width: calc(100% - 1rem);
    padding: 0.38rem 0.72rem;
    border: 2px solid var(--brand-ink);
    border-radius: 0.55rem;
    background: var(--brand-porcelain);
    color: var(--brand-ink);
    box-shadow: 0 3px 0 rgb(23 33 38 / 0.25);
    text-align: center;
    pointer-events: none;
}

.round-feedback:empty { display: none; }
.round-feedback[data-tone="perfect"] { background: var(--brand-yellow); }
.round-feedback[data-tone="fail"] { border-color: var(--color-orange-400); }
.round-feedback strong { font-size: 0.93rem; line-height: 1.1; font-weight: 900; }
.round-feedback span { font-size: 0.7rem; line-height: 1.2; }

@media (prefers-reduced-motion: reduce) {
    .score-pop { animation: none; }
    .frenzy-particle { display: none; }
}

/* Room materials and set dressing. Shared tokens define the composition;
   theme classes supply palette and material. Decoration never affects board
   geometry or input, and stays below #urinal-area. */

.bathroom-walls {
    --room-wall-top: #f7efdf;
    --room-wall-bottom: #e3d7c1;
    --room-grout: rgb(114 101 79 / 0.17);
    --room-trim: #a99e88;
    --room-floor-top: #657174;
    --room-floor-bottom: #424c50;
    --room-glow: rgb(255 248 211 / 0.68);
    --room-sign-bg: var(--brand-yellow);
    --room-sign-text: var(--brand-ink);
    --room-sign-border: var(--brand-ink);
}

.bathroom-walls::before,
.bathroom-walls::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    pointer-events: none;
    z-index: 0;
}

.bathroom-walls::before {
    top: 0;
    height: var(--room-light-height);
    background:
        radial-gradient(ellipse at 20% 0, var(--room-glow), transparent 62%),
        radial-gradient(ellipse at 80% 0, var(--room-glow), transparent 62%);
}

.bathroom-walls::after {
    bottom: 0;
    height: var(--room-floor-height);
    background:
        repeating-linear-gradient(90deg, transparent 0 calc(var(--room-tile-width) - var(--room-grout-width)), rgb(255 255 255 / 0.14) calc(var(--room-tile-width) - var(--room-grout-width)) var(--room-tile-width)),
        linear-gradient(180deg, var(--room-floor-top), var(--room-floor-bottom));
    border-top: 2px solid var(--room-trim);
    box-shadow: inset 0 5px 8px rgb(0 0 0 / 0.14);
}

#urinal-area {
    position: relative;
    z-index: 1;
}

#room-decor {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.decor-prop {
    position: absolute;
    line-height: 1;
    user-select: none;
    pointer-events: none;
}

.prop-room-sign {
    top: var(--room-sign-top);
    left: var(--room-prop-inset);
    max-width: 66%;
    padding: var(--room-sign-padding);
    border: 2px solid var(--room-sign-border);
    border-radius: var(--radius-sm);
    background: var(--room-sign-bg);
    color: var(--room-sign-text);
    font-size: var(--room-sign-font-size);
    font-weight: 900;
    letter-spacing: 0.06em;
    line-height: 1.15;
    box-shadow: var(--room-prop-shadow);
}

/* Reusable pendant silhouette: a stem, enamel shade and a warm diffuser. */
.prop-room-light {
    top: 0;
    width: 2.2rem;
    height: 1.6rem;
    background: linear-gradient(var(--brand-ink), var(--brand-ink)) center top / 3px 60% no-repeat;
}

.prop-room-light::before {
    content: "";
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 55%;
    border-radius: 100% 100% 15% 15%;
    background: var(--brand-charcoal);
    border-bottom: 3px solid var(--brand-porcelain);
    box-shadow: 0 4px 9px var(--room-glow);
}

.prop-room-light-left { left: 14%; }
.prop-room-light-right { right: 14%; }

/* Native accessories inherit the character's SVG scale and body transform.
   These rules select the outfit; the art owns its fit and placement. */
.patron-accessory {
    display: none;
    pointer-events: none;
}

/* Animate only the room container; the queue owns the wall dim/filter. */
#game-screen.world-reveal #bathroom-container {
    animation: room-reveal var(--room-reveal-duration) ease;
}

@keyframes room-reveal {
    0% { opacity: 0.15; transform: scale(0.982); }
    60% { opacity: 1; }
    100% { opacity: 1; transform: scale(1); }
}

/* Shared tile and light treatment. Individual material overrides below
   keep each world recognizable without introducing another renderer. */
:is(.theme-office, .theme-luxury-hotel, .theme-dive-bar, .theme-airport,
    .theme-stadium, .theme-renovation, .theme-gala, .theme-space-station) .bathroom-walls {
    background:
        repeating-linear-gradient(0deg, transparent 0 calc(var(--room-tile-height) - var(--room-grout-width)), var(--room-grout) calc(var(--room-tile-height) - var(--room-grout-width)) var(--room-tile-height)),
        repeating-linear-gradient(90deg, transparent 0 calc(var(--room-tile-width) - var(--room-grout-width)), var(--room-grout) calc(var(--room-tile-width) - var(--room-grout-width)) var(--room-tile-width)),
        linear-gradient(180deg, var(--room-wall-top), var(--room-wall-bottom)) !important;
    border-color: var(--room-trim) !important;
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.55), inset 0 -14px 24px rgb(0 0 0 / 0.08), var(--shadow-card-soft);
}

/* Office: warm ceramic, enamel lighting, passive-aggressive HR signage. */
.theme-office {
    background-color: var(--brand-cream) !important;
    color: var(--brand-ink) !important;
}

.theme-office .prop-office-poster {
    top: var(--room-sign-top);
    left: 50%;
    transform: translateX(-50%) rotate(-2deg);
    padding: var(--room-sign-padding);
    white-space: pre-line;
    text-align: center;
    color: var(--brand-ink);
    background: var(--brand-porcelain);
    border: 2px solid var(--brand-charcoal);
    border-top: 5px solid var(--brand-yellow);
    border-radius: var(--radius-sm);
    font-size: var(--room-sign-font-size);
    font-weight: 900;
    line-height: 1.3;
    letter-spacing: 0.06em;
    box-shadow: var(--room-prop-shadow);
}

.theme-office .prop-office-clock {
    top: 3.4rem;
    right: var(--room-prop-inset);
    font-size: 1.1rem;
    padding: 0.1rem;
    background: var(--brand-porcelain);
    border: 2px solid var(--brand-metal);
    border-radius: 50%;
    box-shadow: var(--room-prop-shadow);
}

.theme-office .prop-office-cooler {
    bottom: calc(var(--room-floor-height) + 0.2rem);
    right: var(--room-prop-inset);
    font-size: 0.95rem;
    padding: 0.5rem 0.3rem 0.62rem;
    background: linear-gradient(180deg, #dbeafe, #bfdbfe 70%, var(--brand-porcelain) 70%);
    border: 2px solid var(--brand-metal);
    border-radius: 0.55rem 0.55rem 0.2rem 0.2rem;
    box-shadow: var(--room-prop-shadow);
}

.theme-office .patron-shirt { display: inline; }
.theme-office [data-patron-shape] .character-sleeve { fill: #cadde9; }
.theme-office #door { background: #ae9369; border-color: #78613e; }

/* Hotel: polished stone, gilt trim and a framed mirror. */
.theme-luxury-hotel .bathroom-walls {
    --room-wall-top: #fff7e5;
    --room-wall-bottom: #e7d4aa;
    --room-trim: #a68745;
    --room-grout: rgb(166 135 69 / 0.2);
    --room-floor-top: #f0e5ce;
    --room-floor-bottom: #cbb997;
    --room-sign-bg: var(--brand-porcelain);
    --room-sign-border: var(--room-trim);
    background:
        linear-gradient(115deg, transparent 40%, rgb(166 135 69 / 0.12) 41%, transparent 42%),
        repeating-linear-gradient(90deg, transparent 0 3.4rem, var(--room-grout) 3.4rem calc(3.4rem + 2px)) left bottom / 100% 42% no-repeat,
        linear-gradient(180deg, var(--room-wall-top) 57%, var(--room-trim) 57% calc(57% + 3px), var(--room-wall-bottom) calc(57% + 3px)) !important;
}

.theme-luxury-hotel .prop-room-sign { top: 4.2rem; }
.theme-luxury-hotel .prop-hotel-mirror {
    top: 0.5rem;
    left: 50%;
    width: 2.4rem;
    height: 3.3rem;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #dae5e5, #ffffff 42%, #c7d5d6 46%, #f4fbfb);
    border: 4px double var(--room-trim);
    border-radius: 50%;
    box-shadow: var(--room-prop-shadow);
}
.theme-luxury-hotel .prop-hotel-sconce {
    top: 1.1rem;
    font-size: 1rem;
    padding-bottom: 0.22rem;
    border-bottom: 3px solid var(--room-trim);
    filter: drop-shadow(0 0 6px var(--room-glow));
}
.theme-luxury-hotel .prop-hotel-sconce-left { left: 12%; }
.theme-luxury-hotel .prop-hotel-sconce-right { right: 12%; }
.theme-luxury-hotel .patron-hat { display: inline; }
.theme-luxury-hotel #door { background: #5d4023; border-color: #3e2a15; }

/* Bar: low-key brick and a neon glow; no flashing during a decision. */
.theme-dive-bar .bathroom-walls {
    --room-wall-top: #303a37;
    --room-wall-bottom: #202927;
    --room-grout: rgb(0 0 0 / 0.23);
    --room-trim: #54695c;
    --room-glow: rgb(190 242 100 / 0.12);
    --room-floor-top: #4a4539;
    --room-floor-bottom: #2b2924;
    --room-tile-height: 1.6rem;
}
.theme-dive-bar .prop-bar-sign {
    top: var(--room-sign-top);
    left: 50%;
    transform: translateX(-50%) rotate(-2deg);
    padding: 0.34rem 0.6rem;
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    color: #dbfbb2;
    background: var(--brand-ink);
    border: 2px solid #a4d773;
    border-radius: var(--surface-radius-sm);
    text-shadow: 0 0 8px rgb(190 242 100 / 0.7);
    box-shadow: 0 0 20px rgb(190 242 100 / 0.18);
}
.theme-dive-bar .prop-bar-sticker {
    font-size: 0.85rem;
    padding: 0.2rem;
    background: var(--brand-cream);
    border: 1px solid var(--brand-ink);
    border-radius: var(--radius-sm);
    opacity: 0.65;
    box-shadow: var(--room-prop-shadow);
}
.theme-dive-bar .prop-bar-sticker-guitar { top: 3.3rem; left: var(--room-prop-inset); transform: rotate(-14deg); }
.theme-dive-bar .prop-bar-sticker-beer { top: 3.8rem; right: var(--room-prop-inset); transform: rotate(9deg); }
.theme-dive-bar .prop-bar-sticker-star { bottom: calc(var(--room-floor-height) + 0.4rem); left: var(--room-prop-inset); transform: rotate(22deg); font-size: 0.7rem; }
.theme-dive-bar .patron-glasses { display: inline; }
.theme-dive-bar #door { background: #3f3a2d; border-color: #262218; }

/* Airport: bright terminal daylight and a wayfinding sign. */
.theme-airport .bathroom-walls {
    --room-wall-top: #edf4f7;
    --room-wall-bottom: #cddce3;
    --room-trim: #91a7b3;
    --room-glow: rgb(233 250 255 / 0.7);
    --room-floor-top: #9cabb2;
    --room-floor-bottom: #72868f;
    background:
        repeating-linear-gradient(90deg, transparent 0 4rem, var(--room-trim) 4rem calc(4rem + 3px)) left top 20% / 100% 15% no-repeat,
        linear-gradient(180deg, #a4d0ec, #e7f6ff) left top 20% / 100% 15% no-repeat,
        repeating-linear-gradient(0deg, transparent 0 calc(var(--room-tile-height) - var(--room-grout-width)), var(--room-grout) calc(var(--room-tile-height) - var(--room-grout-width)) var(--room-tile-height)),
        linear-gradient(180deg, var(--room-wall-top), var(--room-wall-bottom)) !important;
}
.theme-airport .prop-airport-window { top: 24%; left: 24%; font-size: 1.05rem; }
.theme-airport .prop-airport-gate {
    top: var(--room-sign-top);
    left: var(--room-prop-inset);
    padding: var(--room-sign-padding);
    font-size: var(--room-sign-font-size);
    font-weight: 900;
    letter-spacing: 0.08em;
    color: var(--brand-yellow);
    background: var(--brand-ink);
    border: 2px solid var(--room-trim);
    border-radius: var(--radius-sm);
    box-shadow: var(--room-prop-shadow);
}
.theme-airport .patron-headphones { display: inline; }
.theme-airport #door { background: #5b7089; border-color: #3c4c60; }

/* Stadium: concrete blocks, team color, turf and a trophy shelf. */
.theme-stadium { background-color: #293b38 !important; color: var(--text-main) !important; }
.theme-stadium .bathroom-walls {
    --room-wall-top: #e0e4df;
    --room-wall-bottom: #bec7c1;
    --room-grout: rgb(90 106 98 / 0.21);
    --room-trim: #728c7b;
    --room-floor-top: #427e4f;
    --room-floor-bottom: #2a5433;
    --room-sign-bg: #a52b29;
    --room-sign-text: var(--brand-porcelain);
    --room-sign-border: #752320;
    --room-tile-width: 5rem;
}
.theme-stadium .prop-stadium-bunting {
    top: 3rem;
    left: var(--room-prop-inset);
    right: var(--room-prop-inset);
    height: 0.8rem;
    background-image: linear-gradient(45deg, #b5362f 50%, transparent 50%), linear-gradient(-45deg, var(--brand-yellow) 50%, transparent 50%);
    background-size: 1.15rem 0.8rem;
    background-repeat: repeat-x;
    opacity: 0.75;
}
.theme-stadium .prop-stadium-trophy { top: 4.2rem; right: var(--room-prop-inset); font-size: 1rem; padding-bottom: 0.16rem; border-bottom: 3px solid var(--room-trim); filter: drop-shadow(var(--room-prop-shadow)); }
.theme-stadium .patron-scarf { display: inline; }
.theme-stadium #door { background: #8a94a1; border-color: #5a636e; }

/* Renovation: plywood, one clear caution sign and a folded dust sheet. */
.theme-renovation { background-color: #3a3125 !important; color: var(--text-main) !important; }
.theme-renovation .bathroom-walls {
    --room-wall-top: #e2d3ae;
    --room-wall-bottom: #c6b68d;
    --room-trim: #8a7043;
    --room-floor-top: #aa9670;
    --room-floor-bottom: #8c7852;
    background:
        repeating-linear-gradient(0deg, transparent 0 0.5rem, rgb(116 83 32 / 0.08) 0.5rem 0.56rem),
        repeating-linear-gradient(90deg, transparent 0 5rem, var(--room-trim) 5rem calc(5rem + 2px)),
        linear-gradient(180deg, var(--room-wall-top), var(--room-wall-bottom)) !important;
}
.theme-renovation .prop-room-sign { border-bottom-width: 6px; transform: rotate(-2deg); }
.theme-renovation .prop-reno-ladder { bottom: calc(var(--room-floor-height) + 0.2rem); left: var(--room-prop-inset); font-size: 1.7rem; transform: rotate(5deg); filter: drop-shadow(var(--room-prop-shadow)); }
.theme-renovation .prop-reno-bucket { bottom: calc(var(--room-floor-height) + 0.1rem); right: var(--room-prop-inset); font-size: 1.05rem; filter: drop-shadow(var(--room-prop-shadow)); }
.theme-renovation .prop-reno-sheet {
    top: 0;
    right: 0;
    width: 25%;
    height: 35%;
    background: linear-gradient(200deg, rgb(255 255 255 / 0.3), rgb(255 255 255 / 0.05) 78%, transparent);
    border-left: 1px solid rgb(255 255 255 / 0.4);
    border-bottom-left-radius: 40%;
    transform: skewX(-3deg);
    transform-origin: top right;
}
.theme-renovation .patron-hardhat { display: inline; }
.theme-renovation #door { background: #c9a55e; border-color: #8a6d3b; }

/* Gala: velvet, a gold chandelier and quiet ornamental wall panels. */
.theme-gala { background-color: #261d30 !important; color: var(--text-main) !important; }
.theme-gala .bathroom-walls {
    --room-wall-top: #483349;
    --room-wall-bottom: #302232;
    --room-trim: #b89956;
    --room-grout: rgb(184 153 86 / 0.18);
    --room-glow: rgb(255 220 160 / 0.13);
    --room-floor-top: #852f3c;
    --room-floor-bottom: #5c2530;
    --room-sign-bg: var(--room-wall-bottom);
    --room-sign-text: #f2d893;
    --room-sign-border: var(--room-trim);
    --room-tile-width: 5rem;
    --room-tile-height: 8rem;
}
.theme-gala .prop-room-sign { top: 3.5rem; }
.theme-gala .prop-gala-chandelier {
    top: 1.7rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.62rem;
    letter-spacing: 0.5em;
    padding-left: 0.5em;
    color: #ffe082;
    text-shadow: 0 0 8px rgb(255 224 130 / 0.75);
}
.theme-gala .prop-gala-chandelier::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 0.75rem;
    width: 2.9rem;
    height: 1.35rem;
    transform: translateX(-50%);
    border: 3px solid var(--room-trim);
    border-bottom: none;
    border-radius: 2.9rem 2.9rem 0 0;
}
.theme-gala .prop-gala-rope { bottom: calc(var(--room-floor-height) + 0.2rem); width: 4.6rem; height: 1.9rem; border-bottom: 4px solid #b94b50; border-radius: 0 0 55% 55%; }
.theme-gala .prop-gala-rope::before,
.theme-gala .prop-gala-rope::after { content: ""; position: absolute; bottom: -0.16rem; width: 0.3rem; height: 1.7rem; background: var(--room-trim); border-radius: var(--radius-full) var(--radius-full) 2px 2px; }
.theme-gala .prop-gala-rope::before { left: -0.1rem; }
.theme-gala .prop-gala-rope::after { right: -0.1rem; }
.theme-gala .prop-gala-rope-left { left: 2%; }
.theme-gala .prop-gala-rope-right { right: 2%; }
.theme-gala .patron-bowtie { display: inline; }
.theme-gala #door { background: #43245e; border-color: #b89956; }

/* Space station: pressure panels, cool underlighting, Earth in a porthole. */
.theme-space-station { background-color: #0a1625 !important; color: var(--text-main) !important; }
.theme-space-station .bathroom-walls {
    --room-wall-top: #142b46;
    --room-wall-bottom: #0d1d32;
    --room-trim: #508da6;
    --room-grout: rgb(80 141 166 / 0.2);
    --room-glow: rgb(50 174 238 / 0.2);
    --room-floor-top: #234b64;
    --room-floor-bottom: #173247;
    --room-tile-width: 5rem;
    --room-tile-height: 4.5rem;
}
.theme-space-station .bathroom-walls::after { box-shadow: 0 -3px 12px var(--room-glow), inset 0 2px 0 #72ccf0; }
.theme-space-station .prop-room-sign { max-width: 62%; }
.theme-space-station .prop-space-porthole {
    top: 0.65rem;
    right: var(--room-prop-inset);
    font-size: 1.75rem;
    padding: 0.45rem;
    background: radial-gradient(circle at 25% 25%, white 0 1px, transparent 2px), radial-gradient(circle at 80% 75%, white 0 1px, transparent 2px), #071221;
    border: 4px solid var(--brand-metal);
    border-radius: 50%;
    box-shadow: 0 0 0 3px #293f58, 0 0 14px var(--room-glow);
}
.theme-space-station .prop-space-panel { top: 3.8rem; left: var(--room-prop-inset); width: 2.7rem; height: 1.35rem; background: var(--room-wall-bottom); border: 1px solid var(--room-trim); border-radius: var(--radius-sm); }
.theme-space-station .prop-space-panel::before { content: "● ● ●"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 0.42rem; letter-spacing: 0.18em; color: #65e5cd; text-shadow: 0 0 6px var(--room-glow); }
.theme-space-station .patron-goggles { display: inline; }
.theme-space-station #door { background: #1e3a5f; border-color: #508da6; }

/* Tutorial and Arcade stay visually quiet; their selection rules lead. */
.theme-arcade .bathroom-walls::before,
.theme-arcade .bathroom-walls::after { content: none; }

@media (prefers-reduced-motion: reduce) {
    .decor-prop,
    .decor-prop::before,
    .decor-prop::after,
    #game-screen.world-reveal #bathroom-container {
        animation: none !important;
    }
}

/* Decorative room postcards share native fixture art and world materials. */
#world-map-continue-button .mode-button-subtitle {
    color: var(--action-primary-text);
}

.room-preview {
    --preview-height: 7.2rem;
    --preview-fixture-height: 5.1rem;
    --preview-fixture-width: 3rem;
    --preview-floor-clearance: 0.75rem;
    position: relative;
    height: var(--preview-height);
    overflow: hidden;
    pointer-events: none;
    isolation: isolate;
}

.room-preview .room-preview-material {
    position: absolute;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    overflow: hidden;
    --room-floor-height: 1.3rem;
    --room-tile-height: 1.5rem;
    --room-tile-width: 2.5rem;
}

.room-preview-sign {
    position: absolute;
    top: 0.45rem;
    left: 0.65rem;
    z-index: 1;
    padding: 0.22rem 0.4rem;
    border: 1px solid var(--brand-ink);
    border-radius: var(--radius-sm);
    background: var(--brand-yellow);
    color: var(--brand-ink);
    box-shadow: var(--room-prop-shadow);
    font-size: 0.58rem;
    font-weight: 900;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.room-preview-row {
    position: absolute;
    bottom: var(--preview-floor-clearance);
    inset-inline: 7%;
    z-index: 1;
    display: flex;
    justify-content: center;
    align-items: end;
    gap: 0.25rem;
}

.room-preview-fixture {
    display: block;
    position: relative;
    flex: 0 1 var(--preview-fixture-width);
    width: var(--preview-fixture-width);
    min-width: 0;
    height: var(--preview-fixture-height);
    filter: drop-shadow(0 3px 2px rgb(0 0 0 / 0.24));
}

.room-preview-fixture .urinal-fixture-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* No interactive fixture state or ambient animation leaks into the preview. */
.room-preview-fixture *,
.room-preview-fixture *::before,
.room-preview-fixture *::after {
    animation: none !important;
    transition: none !important;
}

.world-map-destination {
    padding: 0;
    overflow: hidden;
    background: var(--bg-card);
    border-color: var(--surface-border-default);
    border-radius: var(--surface-radius-lg);
    box-shadow: var(--shadow-card-soft);
}

.world-map-destination.world-map-section-locked {
    opacity: 1;
}

.world-map-destination.world-map-section-locked .room-preview {
    filter: saturate(0.65);
}

.world-map-destination-summary {
    padding: 0.65rem;
}

.world-map-chapter {
    margin: 0 0 0.3rem;
    font-size: 0.58rem;
    letter-spacing: 0.09em;
    font-weight: 800;
    color: var(--text-subtle);
}

.world-map-destination .world-map-section-header {
    margin-bottom: 0.2rem;
}

.world-map-destination .world-map-section-name {
    margin: 0;
    color: var(--text-main);
    font-size: 1rem;
    line-height: 1.15;
}

.world-map-destination .world-map-section-stars {
    color: var(--brand-yellow-light);
}

.world-map-flavor {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.35;
}

.world-map-star-progress {
    display: block;
    appearance: none;
    border: 0;
    border-radius: var(--radius-full);
    background: var(--surface-border-default);
    color: var(--brand-yellow);
    width: 100%;
    height: 0.25rem;
    margin: 0.55rem 0 0.65rem;
    overflow: hidden;
}

.world-map-star-progress::-webkit-progress-bar {
    background: var(--surface-border-default);
}

.world-map-star-progress::-webkit-progress-value {
    background: var(--brand-yellow);
}

.world-map-star-progress::-moz-progress-bar {
    background: var(--brand-yellow);
}

.world-map-gate {
    margin: 0 0 0.6rem;
    color: var(--text-soft);
    font-size: 0.72rem;
    font-weight: 700;
}

.world-map-destination .world-map-node {
    background: var(--surface-bg-soft);
    color: var(--text-main);
    border-color: var(--surface-border-default);
}

.world-map-destination .world-map-node-cleared {
    background: var(--action-selected-bg);
    border-color: var(--action-selected-border);
}

.world-map-destination .world-map-node-current {
    color: var(--action-primary-text);
    background: var(--action-primary-bg);
    border-color: var(--action-primary-border);
    box-shadow: var(--action-primary-shadow);
    animation: none;
}

.world-map-destination .world-map-node-current .world-map-node-stars {
    color: var(--action-primary-text);
}

.world-map-destination .world-map-node-locked {
    opacity: 1;
    color: var(--text-subtle);
    border-style: dashed;
}

.world-map-destination .world-map-node:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

.world-map-destination .world-map-node:hover:not(.world-map-node-locked) {
    border-color: var(--brand-yellow);
}

/* The first choice leads. Secondary progress stays below the play actions. */
#home-content-stack {
    flex: 0 0 auto;
}

#home-hero {
    gap: 0.35rem;
    text-align: left;
}

.home-eyebrow {
    color: var(--brand-yellow);
    font-size: 0.58rem;
    font-weight: 900;
    letter-spacing: 0.12em;
}

#start-screen-title {
    font-family: var(--font-display);
    font-size: clamp(2.4rem, 10vw, 3.3rem);
    text-transform: uppercase;
    color: var(--brand-porcelain);
    font-weight: 900;
    line-height: 0.95;
    letter-spacing: -0.025em;
    text-shadow: none;
}

#start-screen-subtitle {
    font-size: 0.82rem;
    color: var(--brand-cream);
    line-height: 1.3;
}

#home-room-preview {
    margin-top: 0.4rem;
    border-radius: var(--surface-radius-md);
    overflow: hidden;
    border: 1px solid var(--brand-metal);
    border-bottom: 4px solid var(--brand-yellow);
}

#home-room-preview .room-preview {
    --preview-height: 6.2rem;
    --preview-fixture-height: 4.4rem;
}

#home-room-preview .room-preview-sign {
    display: none;
}

#start-screen-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}

#start-endless-button {
    grid-column: 1 / -1;
    min-height: 3.6rem;
    padding: 0.6rem 0.8rem;
}

#start-endless-button .mode-button-title {
    font-size: 1.12rem;
    font-weight: 900;
}

#start-screen-buttons .mode-button-subtitle {
    line-height: 1.3;
}

#home-status-strip {
    margin-top: 0.9rem;
    gap: 1rem;
    background: var(--surface-bg-soft);
}

#home-progression {
    background: var(--surface-bg-soft);
}

#home-missions {
    margin-top: 0.65rem;
    flex: none;
    max-height: none;
    overflow: visible;
}

#start-screen[data-new-player="true"] #home-progression,
#start-screen[data-new-player="true"] #home-missions,
#start-screen[data-new-player="true"] #home-high-score,
#start-screen[data-new-player="true"] #home-streak {
    display: none;
}

#start-screen[data-new-player="true"] #daily-mode-slot,
#start-screen[data-new-player="true"] #start-progression-button {
    grid-column: 1 / -1;
}

#start-screen[data-new-player="true"] #home-status-strip {
    border-bottom: 1px solid var(--surface-border-subtle);
    border-radius: var(--surface-radius-md);
}

.home-character-chip {
    min-height: var(--touch-target-size);
}

#start-screen[data-new-player="true"] #home-room-preview .room-preview {
    --preview-height: 8.4rem;
    --preview-fixture-height: 6rem;
    --preview-fixture-width: 3.6rem;
}

@media (max-height: 650px) {
    #home-room-preview .room-preview,
    #start-screen[data-new-player="true"] #home-room-preview .room-preview {
        --preview-height: 4.7rem;
        --preview-fixture-height: 3.8rem;
    }
}

/* Web only: an ordinary website frame around the game's home screen. A header
   with the reading pages' navigation sits above the game, and a reading
   section and footer sit below it, so the page at "/" reads as a website with
   a game in it. The frame's markup is in index.html and carries
   data-web-only, so main.ts removes it in the apps before anything shows.
   Nothing here changes the game: the links live outside the game's card. */

:root {
    --site-frame-header-height: 3rem;
    --site-frame-gap: 0.5rem;
    /* The frame keeps its text a steady distance from the window's edge by
       taking up whatever side gap the game's shell does not provide. */
    --site-frame-edge: 0.95rem;
    --site-frame-inline: calc(var(--site-frame-edge) - var(--app-edge-gap));
}

/* Hidden unless the rules below lay it out. Browsers without :has() keep the
   plain full-window game, without the frame. */
.site-frame {
    display: none;
}

@supports selector(:has(*)) {
    /* While the home screen is showing, the page is a normal scrolling
       document: header, game card, reading section, footer. Every other
       screen (a run, the Worlds map, character select) hides #start-screen,
       which puts the page back into the fixed full-window shell from base.css
       and hides the frame. Inside the apps index.html marks the page
       "in-app" before the body exists and main.ts then removes the frame, so
       none of this ever applies there, not even for the first paint. */
    html:not(.in-app):has(#start-screen:not(.hidden) ~ .site-frame) {
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
        scrollbar-gutter: stable;
    }

    /* A dialog over the home screen holds the page still behind it. The
       gutter above keeps the page from shifting sideways when it does. */
    html:not(.in-app):has(#start-screen:not(.hidden) ~ .site-frame):has(#custom-modal:not(.hidden), #leaderboard-modal-overlay) {
        overflow-y: hidden;
    }

    html:not(.in-app):has(#start-screen:not(.hidden) ~ .site-frame) body {
        height: auto;
        min-height: 100vh;
        min-height: 100svh;
        overflow: visible;
    }

    /* The page scrolls, not the card. The card still fills the first screen
       under the header, so the game is what a visitor sees first. svh keeps
       that height steady while a phone's address bar slides away. */
    html:not(.in-app):has(#start-screen:not(.hidden) ~ .site-frame) #start-screen {
        flex: 0 0 auto;
        height: auto;
        max-height: none;
        min-height: calc(
            100vh - var(--app-top-gap) - var(--app-bottom-gap) - var(--app-chrome-top) -
                var(--app-chrome-bottom) - var(--site-frame-header-height) - var(--site-frame-gap)
        );
        min-height: calc(
            100svh - var(--app-top-gap) - var(--app-bottom-gap) - var(--app-chrome-top) -
                var(--app-chrome-bottom) - var(--site-frame-header-height) - var(--site-frame-gap)
        );
        overflow: visible;
    }

    html:not(.in-app):has(#start-screen:not(.hidden) ~ .site-frame) .site-frame-header,
    html:not(.in-app):has(#start-screen:not(.hidden) ~ .site-frame) .site-frame-footer {
        display: flex;
    }

    html:not(.in-app):has(#start-screen:not(.hidden) ~ .site-frame) .site-frame-about {
        display: block;
    }
}

/* The frame is as wide as the game gets during a run, so it never reaches
   the side banners, which sit beyond that width. Everything below sizes
   itself from the space it has; there are no width breakpoints. */
.site-frame {
    flex: 0 0 auto;
    width: 100%;
    max-width: var(--game-screen-max-width);
    padding-inline: var(--site-frame-inline);
}

.site-frame a:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
}

.site-frame-header {
    align-items: center;
    justify-content: space-between;
    gap: clamp(0.75rem, 3vw, 1.5rem);
    height: var(--site-frame-header-height);
    margin-bottom: var(--site-frame-gap);
}

.site-frame-brand {
    flex: 0 0 auto;
    color: var(--brand-yellow);
    font-size: clamp(0.95rem, 0.9rem + 0.25vw, 1.05rem);
    font-weight: 900;
    letter-spacing: 0.02em;
    text-decoration: none;
    text-transform: uppercase;
    white-space: nowrap;
}

/* One line at every width, so the header never grows and the game stays
   where it is. When the links do not all fit, the row scrolls sideways and
   runs off the window's edge: nothing is dropped, and a cut-off link shows
   there is more. */
.site-frame-nav {
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    gap: clamp(0.8rem, 2.6vw, 1.25rem);
    min-width: 0;
    margin-inline-end: calc(-1 * var(--site-frame-edge));
    padding-inline-end: var(--site-frame-edge);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    /* Links fade out across the run-off zone, which is empty when they fit. */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - var(--site-frame-edge)), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - var(--site-frame-edge)), transparent);
    font-size: clamp(0.85rem, 0.82rem + 0.2vw, 0.92rem);
    font-weight: 700;
}

.site-frame-nav::-webkit-scrollbar {
    display: none;
}

.site-frame-nav a {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    min-height: var(--touch-target-size);
    color: var(--text-soft);
    text-decoration: none;
    white-space: nowrap;
}

/* The scrolling row clips an outline drawn outside a link. */
.site-frame-nav a:focus-visible {
    outline-offset: -2px;
}

.site-frame-nav a:hover,
.site-frame-footer a:hover {
    color: var(--text-main);
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.site-frame-about {
    margin-top: clamp(1rem, 4vw, 2rem);
    color: var(--text-soft);
    line-height: 1.6;
    text-align: left;
}

.site-frame-about h2 {
    margin: clamp(1.1rem, 3.5vw, 1.75rem) 0 var(--spacing-sm);
    color: var(--text-main);
    font-size: clamp(1.15rem, 1.02rem + 0.75vw, 1.45rem);
    line-height: 1.25;
}

.site-frame-about p {
    max-width: 44rem;
    margin: 0 0 0.8rem;
    font-size: clamp(0.92rem, 0.9rem + 0.15vw, 1rem);
}

.site-frame-about p a {
    color: var(--brand-yellow-light);
    text-underline-offset: 0.2em;
}

/* As many columns as fit, down to one. */
.site-frame-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
    gap: clamp(0.6rem, 1.6vw, 0.9rem);
    margin: var(--spacing-md) 0;
}

.site-frame-card {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: clamp(0.8rem, 2.2vw, 1.05rem) clamp(0.9rem, 2.4vw, 1.15rem);
    background: var(--brand-charcoal);
    border: 1px solid var(--surface-border-subtle);
    border-radius: var(--surface-radius-lg);
    color: var(--text-soft);
    text-decoration: none;
}

.site-frame-card:hover {
    border-color: var(--surface-border-strong);
}

.site-frame-card-title {
    color: var(--text-main);
    font-weight: 800;
    line-height: 1.3;
}

.site-frame-card-text {
    font-size: 0.85rem;
    line-height: 1.45;
}

.site-frame-footer {
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem var(--spacing-md);
    margin-top: clamp(1rem, 4vw, 2rem);
    padding-block: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--surface-border-subtle);
    color: var(--text-subtle);
    font-size: 0.85rem;
}

.site-frame-footer p {
    margin: 0;
}

.site-frame-footer nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0 clamp(0.8rem, 2.6vw, 1.25rem);
}

.site-frame-footer a {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch-target-size);
    color: var(--text-soft);
    text-decoration: none;
}

/* Shown in the game's card only when JavaScript is off. */
.home-noscript-note {
    margin: 0.6rem 0 0;
    color: var(--text-soft);
    font-size: 0.8rem;
    line-height: 1.5;
}
/* 2.5D set construction. Projection affects decorative planes only: the
   playable board keeps its existing coordinates, hit regions and timing. */
.bathroom-walls {
    --room-depth-side-width: clamp(8px, 2.8vw, 18px);
    --room-depth-floor-min-height: clamp(2.3rem, 7vh, 3.8rem);
    --room-depth-floor-height: var(--room-depth-floor-min-height);
    --room-depth-floor-perspective: 260px;
    --room-depth-floor-angle: 52deg;
    --room-depth-plane-height-scale: 2;
    /* With a 52-degree plane and double height, this perspective ratio
       projects the visible floor back to its configured clearance. */
    --room-depth-clearance-perspective-scale: 6.82;
    --room-floor-height: var(--room-depth-floor-height);
    --room-depth-tile-width: 3.3rem;
    --room-depth-tile-height: 2rem;
    --room-depth-grout: rgb(255 255 255 / 0.19);
    --room-depth-shadow: rgb(13 23 27 / 0.34);
    --room-depth-contact-shadow: rgb(13 23 27 / 0.48);
    --room-depth-edge-light: rgb(255 255 255 / 0.58);
    --room-depth-divider-front: #bac8cc;
    --room-depth-divider-side: #4d646c;
    --room-depth-divider-cap: #e3ebeb;
    --room-prop-shadow: 4px 7px 5px var(--room-depth-shadow);
}

/* Recessed back wall: a narrow lit bevel and a soft shadow where the side
   walls meet it. No opaque wash is placed over the fixture decision area. */
:is(.theme-office, .theme-luxury-hotel, .theme-dive-bar, .theme-airport,
    .theme-stadium, .theme-renovation, .theme-gala, .theme-space-station) .bathroom-walls {
    box-shadow:
        inset 0 2px 0 var(--room-depth-edge-light),
        inset 8px 0 12px -8px var(--room-depth-contact-shadow),
        inset -8px 0 12px -8px var(--room-depth-contact-shadow),
        inset 0 -5px 10px var(--room-depth-shadow),
        var(--shadow-card-soft);
}

/* The floor is an actual tilted CSS plane. Its oversized width is clipped
   by the room, so the grout converges toward the back while the near edge
   fills the viewport. The border and inset highlights form a raised plinth. */
:is(.theme-office, .theme-luxury-hotel, .theme-dive-bar, .theme-airport,
    .theme-stadium, .theme-renovation, .theme-gala, .theme-space-station) .bathroom-walls::after {
    content: "";
    left: -50%;
    right: auto;
    width: 200%;
    height: calc(var(--room-depth-floor-height) * var(--room-depth-plane-height-scale));
    bottom: 0;
    background:
        repeating-linear-gradient(0deg, transparent 0 calc(var(--room-depth-tile-height) - 1px), var(--room-depth-grout) calc(var(--room-depth-tile-height) - 1px) var(--room-depth-tile-height)),
        repeating-linear-gradient(90deg, transparent 0 calc(var(--room-depth-tile-width) - 1px), var(--room-depth-grout) calc(var(--room-depth-tile-width) - 1px) var(--room-depth-tile-width)),
        linear-gradient(180deg, var(--room-floor-bottom), var(--room-floor-top));
    border-top: 5px solid var(--room-trim);
    box-shadow:
        0 -2px 0 var(--room-depth-edge-light),
        0 -8px 12px var(--room-depth-shadow),
        inset 0 2px 0 var(--room-depth-edge-light),
        inset 0 13px 14px -8px var(--room-depth-contact-shadow);
    transform: perspective(var(--room-depth-floor-perspective)) rotateX(var(--room-depth-floor-angle));
    transform-origin: center bottom;
    pointer-events: none;
}

/* Physical side faces remain outside the central action. Clipped corners
   describe the room's recess rather than stretching the board perspective. */
#room-decor::before,
#room-decor::after,
.room-preview::before,
.room-preview::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: var(--room-depth-side-width);
    background:
        repeating-linear-gradient(0deg, transparent 0 calc(var(--room-tile-height) - 1px), var(--room-grout) calc(var(--room-tile-height) - 1px) var(--room-tile-height)),
        linear-gradient(90deg, var(--room-depth-shadow), transparent),
        var(--room-wall-bottom);
    pointer-events: none;
}

#room-decor::before,
.room-preview::before {
    left: 0;
    clip-path: polygon(0 0, 100% var(--room-depth-side-width), 100% calc(100% - var(--room-depth-side-width)), 0 100%);
    border-right: 1px solid var(--room-depth-edge-light);
}

#room-decor::after,
.room-preview::after {
    right: 0;
    clip-path: polygon(100% 0, 0 var(--room-depth-side-width), 0 calc(100% - var(--room-depth-side-width)), 100% 100%);
    border-left: 1px solid var(--room-depth-shadow);
    background-position: right top;
}

/* Props stand proud of the wall: contact edge, side thickness, then cast
   shadow. Their existing color, shape, rotation and placement stay intact. */
.bathroom-walls :is(.prop-office-poster, .prop-office-clock, .prop-office-cooler,
    .prop-hotel-mirror, .prop-room-sign, .prop-airport-gate,
    .prop-space-panel, .prop-space-porthole) {
    box-shadow:
        inset 0 1px 0 var(--room-depth-edge-light),
        1px 2px 0 var(--room-trim),
        var(--room-prop-shadow);
}

/* Enamel shade, bright underside and a bounded cone from each real pendant.
   These are static lights; no parallax or persistent animation is added. */
.prop-room-light::before {
    background: linear-gradient(100deg, #18272d, #53656b 32%, #25373e 48%, #17252b);
    border-bottom-color: var(--brand-porcelain);
    box-shadow: inset 0 1px 0 var(--room-depth-edge-light), 0 3px 3px var(--room-glow);
}

.prop-room-light::after {
    --pendant-cone-width: 9rem;
    --pendant-cone-height: 11rem;
    content: "";
    position: absolute;
    top: 96%;
    left: 50%;
    width: var(--pendant-cone-width);
    height: var(--pendant-cone-height);
    transform: translateX(-50%);
    clip-path: polygon(40% 0, 60% 0, 100% 100%, 0 100%);
    background: linear-gradient(180deg, var(--room-glow), transparent);
    opacity: 0.72;
    pointer-events: none;
}

/* An extruded divider has a lit cap and darker side face. Both faces stay
   inside its allocated width; neither its hit gap nor its height changes. */
.urinal-divider {
    position: relative;
    background: var(--room-depth-divider-front);
    box-shadow: 2px 3px 3px var(--room-depth-shadow);
}

.urinal-divider::before,
.urinal-divider::after {
    content: "";
    position: absolute;
    pointer-events: none;
}

.urinal-divider::before {
    inset: 0 0 auto;
    height: 4px;
    border-radius: inherit;
    background: var(--room-depth-divider-cap);
    clip-path: polygon(0 0, 70% 0, 100% 100%, 0 100%);
}

.urinal-divider::after {
    inset: 1px 0 0 auto;
    width: 42%;
    background: var(--room-depth-divider-side);
    border-radius: 0 2px 2px 0;
}

/* Material-specific light response; all colors remain inherited from the
   established world palettes. Dark rooms receive less reflective grout. */
:is(.theme-dive-bar, .theme-gala, .theme-space-station) .bathroom-walls {
    --room-depth-edge-light: rgb(213 237 244 / 0.3);
    --room-depth-grout: rgb(183 218 230 / 0.13);
    --room-depth-contact-shadow: rgb(0 6 14 / 0.6);
}

.theme-space-station .bathroom-walls {
    --room-depth-divider-front: #8bb1bf;
    --room-depth-divider-side: #37576b;
    --room-depth-divider-cap: #cfedf6;
}

.theme-stadium .bathroom-walls {
    --room-depth-grout: rgb(235 255 235 / 0.13);
}

/* Compact boards keep the existing decor suppression. Floor projection is
   smaller so it stays a background cue beneath tightly stacked rows. */
.bathroom-walls[data-compact-room="true"] {
    --room-depth-floor-min-height: 1.5rem;
    --room-depth-side-width: 6px;
}

/* A sparse scene needs a floor beneath its people, not a remote strip at
   the bottom of a tall wall. The renderer supplies the last row's clearance;
   scaling perspective with it avoids the fixed-distance projection limit.
   Dense boards retain the unobtrusive minimum floor plane above. */
.bathroom-walls[data-board-density="sparse"] {
    --room-depth-floor-height: max(var(--room-depth-floor-min-height), var(--room-floor-clearance, 0px));
    --room-depth-floor-perspective: calc(var(--room-depth-floor-height) * var(--room-depth-clearance-perspective-scale));
}

/* The same construction scales down for inert home/map postcards. The
   preview wrapper owns only the two edge faces; its floor stays in the room. */
.room-preview {
    --room-depth-side-width: 5px;
    --room-depth-shadow: rgb(13 23 27 / 0.25);
    --room-depth-edge-light: rgb(255 255 255 / 0.45);
    --room-wall-bottom: transparent;
    --room-grout: transparent;
    --room-tile-height: 1.5rem;
}

.room-preview::before,
.room-preview::after {
    z-index: 2;
}

.room-preview .room-preview-material {
    --room-depth-floor-height: 1.3rem;
    --room-depth-floor-perspective: 140px;
    --room-depth-tile-width: 2rem;
    --room-depth-tile-height: 1.1rem;
}
