/* ==========================================================================
   Comet — design system
   Color roles (shared with the canvas renderers):
     amber  = you (comet, score, primary actions)
     violet = gravity (black holes, selection)
     red    = danger (debris, damage)
     teal/blue = help (power-ups, shield)
   ========================================================================== */

:root {
    --bg-0: #05060f;
    --bg-1: #0b0d22;
    --bg-2: #151838;
    --surface: rgba(24, 27, 62, 0.62);
    --surface-strong: rgba(13, 15, 36, 0.94);
    --surface-hover: rgba(40, 44, 92, 0.7);
    --line: rgba(170, 178, 255, 0.14);
    --line-strong: rgba(170, 178, 255, 0.28);

    --text: #eef0ff;
    --text-dim: #a3a9d1;
    --text-faint: #6d73a0;

    --comet: #ffb547;
    --comet-hot: #ff7a2f;
    --comet-soft: #ffe2a8;
    --comet-ink: #22120a;
    --void: #8b7bff;
    --void-soft: #c9c0ff;
    --danger: #ff4d5e;
    --danger-soft: #ffb3ba;
    --aurora: #3ee6c8;
    --shield: #5cc8ff;
    --surge: #ffd23f;

    --grad-primary: linear-gradient(135deg, #ffd27a 0%, #ffb547 45%, #ff7a2f 100%);
    --glow-primary: 0 10px 30px -8px rgba(255, 138, 61, 0.65), 0 0 0 1px rgba(255, 226, 168, 0.35) inset;

    --r-l: 22px;
    --r-m: 16px;
    --r-s: 12px;

    --font: 'Outfit', ui-rounded, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

    --safe-t: env(safe-area-inset-top, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

html,
body {
    height: 100%;
}

body {
    font-family: var(--font);
    background:
        radial-gradient(120% 60% at 50% 0%, #1b1a4a 0%, transparent 60%),
        radial-gradient(90% 50% at 80% 100%, #2a0f2e 0%, transparent 60%),
        var(--bg-0);
    color: var(--text);
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

button,
input,
textarea,
select {
    font-family: inherit;
}

button {
    touch-action: manipulation;
}

.ic {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#game-container {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-canvas {
    display: block;
    background: var(--bg-0);
    /* Let Phaser Scale Manager control the canvas size (prevents pointer/cursor offset). */
    max-width: 100%;
    max-height: 100%;
    touch-action: none;
}

#ui-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* ---- Buttons ----------------------------------------------------------- */

.screen button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 48px;
    margin-top: 12px;
    padding: 12px 22px;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    cursor: pointer;
    pointer-events: all;
    transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.screen button:active {
    transform: scale(0.97);
    background: var(--surface-hover);
}

.screen button:focus-visible,
#pause-btn:focus-visible {
    outline: 2px solid var(--comet);
    outline-offset: 3px;
}

.screen button:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
}

.screen .btn-primary,
.screen #duo-home button,
.screen #duo-submit-btn,
.screen #duo-ready-btn,
.screen #duo-start-btn,
.screen #duo-rematch-btn,
.screen #mv-enter-btn {
    color: var(--comet-ink);
    background: var(--grad-primary);
    border: 0;
    box-shadow: var(--glow-primary);
    font-weight: 900;
    letter-spacing: 0.06em;
}

.screen .btn-primary:active,
.screen #duo-home button:active,
.screen #duo-submit-btn:active,
.screen #duo-ready-btn:active,
.screen #duo-start-btn:active,
.screen #duo-rematch-btn:active,
.screen #mv-enter-btn:active {
    background: var(--grad-primary);
    filter: brightness(1.08);
}

.screen .secondary-action {
    background: var(--surface);
}

.screen .text-action {
    min-height: 44px;
    padding: 8px 12px;
    background: none;
    border-color: transparent;
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 700;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.screen .text-action:active {
    background: rgba(255, 255, 255, 0.06);
}

.screen .danger-action {
    color: var(--danger-soft);
    border-color: rgba(255, 77, 94, 0.5);
}

/* ---- Screens ------------------------------------------------------------ */

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(5, 6, 15, 0.8);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    pointer-events: all;
    z-index: 100;
    padding:
        calc(var(--safe-t) + 20px)
        calc(var(--safe-r) + 20px)
        calc(var(--safe-b) + 20px)
        calc(var(--safe-l) + 20px);
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    animation: screen-in 0.22s ease-out;
}

@keyframes screen-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.screen.hidden {
    display: none;
}

.screen h1 {
    font-size: 40px;
    font-weight: 900;
    letter-spacing: 0.04em;
    line-height: 1;
    margin-bottom: 14px;
    color: var(--text);
}

.screen p {
    font-size: 16px;
    margin: 8px 0;
    color: var(--text-dim);
}

.kicker,
.mv-kicker {
    font-size: 12px !important;
    font-weight: 800;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-faint) !important;
}

/* ---- Home --------------------------------------------------------------- */

#start-screen {
    justify-content: space-between;
    /* The live comet flies behind the home screen: keep the middle clear. */
    background:
        linear-gradient(to bottom,
            rgba(5, 6, 15, 0.55) 0%,
            rgba(5, 6, 15, 0) 30%,
            rgba(5, 6, 15, 0) 42%,
            rgba(5, 6, 15, 0.72) 62%,
            rgba(5, 6, 15, 0.92) 100%);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    padding-top: calc(var(--safe-t) + 28px);
}

.home-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.logo {
    position: relative;
    font-size: clamp(56px, 18vw, 88px) !important;
    font-weight: 900 !important;
    letter-spacing: 0.08em !important;
    padding-left: 0.08em;
    margin-bottom: 0 !important;
    background: linear-gradient(180deg, #ffffff 0%, var(--comet-soft) 55%, var(--comet) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 6px 24px rgba(255, 138, 61, 0.35));
}

#start-screen h1::after {
    content: attr(data-badge);
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    color: var(--comet-soft);
    font-size: 10px;
    letter-spacing: 0.2em;
    -webkit-text-fill-color: var(--comet-soft);
    white-space: nowrap;
}

.home-tagline {
    margin: 2px 0 14px !important;
    font-size: 13px !important;
    font-weight: 800;
    letter-spacing: 0.42em;
    padding-left: 0.42em;
    text-transform: uppercase;
    color: var(--text-dim) !important;
}

.best-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    margin: 0 !important;
    padding: 7px 14px;
    border-radius: 999px;
    background: rgba(255, 181, 71, 0.1);
    border: 1px solid rgba(255, 181, 71, 0.28);
    font-size: 16px !important;
    font-variant-numeric: tabular-nums;
}

.best-chip span {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.16em;
    color: var(--text-dim);
}

.best-chip b {
    color: var(--comet);
    font-weight: 900;
}

.home-stage {
    flex: 1;
    min-height: 90px;
}

.home-controls {
    width: min(420px, 100%);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.screen .segmented button {
    min-height: 40px;
    margin: 0;
    padding: 8px 6px;
    font-size: 14px;
    font-weight: 800;
    color: var(--text-dim);
    background: transparent;
    border: 1px solid transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.screen .segmented button[aria-pressed="true"] {
    color: var(--comet-soft);
    background: rgba(255, 181, 71, 0.16);
    border-color: rgba(255, 181, 71, 0.45);
}

.screen .segmented button:disabled {
    opacity: 1;
}

.screen .home-play {
    width: 100%;
    min-height: 76px;
    margin: 0;
    padding: 12px 26px;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 16px;
    align-items: center;
    justify-items: start;
    border-radius: var(--r-l);
    text-align: left;
}

.home-play .ic {
    grid-row: 1 / span 2;
    width: 34px;
    height: 34px;
}

.home-play-label {
    font-size: 26px;
    font-weight: 900;
    letter-spacing: 0.14em;
    line-height: 1;
}

#start-btn-hint {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    opacity: 0.72;
}

.home-tiles {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.screen .tile {
    margin: 0;
    min-height: 66px;
    padding: 10px 4px 8px;
    flex-direction: column;
    gap: 5px;
    border-radius: var(--r-m);
    font-size: 12px;
    font-weight: 800;
    color: var(--text-dim);
}

.tile .ic {
    width: 22px;
    height: 22px;
    color: var(--void-soft);
}

.tile-race .ic { color: var(--comet); }
.tile-worlds .ic { color: var(--aurora); }



.challenge-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.challenge-heading > span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.challenge-heading em {
    font-style: normal;
    color: var(--text-faint);
    letter-spacing: 0.06em;
}

.challenge-heading > span .ic {
    width: 14px;
    height: 14px;
    color: var(--comet);
}

.home-switches {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.screen .switch {
    min-height: 32px;
    margin: 0;
    padding: 4px 11px 4px 8px;
    gap: 6px;
    font-size: 12px;
    font-weight: 800;
    color: var(--text-faint);
    background: transparent;
    border: 1px solid var(--line);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.screen .switch::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.screen .switch[aria-pressed="true"] {
    color: var(--text);
    border-color: var(--line-strong);
}

.screen .switch[aria-pressed="true"]::before {
    background: var(--aurora);
    box-shadow: 0 0 8px var(--aurora);
}

#challenge-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 10px;
}

.challenge-row {
    display: grid;
    grid-template-columns: 1fr auto;
    row-gap: 5px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    text-align: left;
}

.challenge-row strong {
    color: var(--comet-soft);
    font-size: 12px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.challenge-bar {
    grid-column: 1 / -1;
    height: 3px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
    position: relative;
}

.challenge-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    transform-origin: left;
    transform: scaleX(var(--p, 0));
    background: var(--grad-primary);
    border-radius: inherit;
}

.challenge-row.done {
    color: var(--text-dim);
}

.challenge-row.done strong {
    color: var(--aurora);
}

.challenge-row.done .challenge-bar::after {
    background: var(--aurora);
}

/* Short phones (iPhone SE/mini class, landscape splits): tighten the home. */
@media (max-height: 720px) {
    #start-screen { padding-top: calc(var(--safe-t) + 14px); }
    .logo { font-size: clamp(44px, 14vw, 64px) !important; }
    .home-tagline { margin-bottom: 8px !important; font-size: 11px !important; }
    .home-controls { gap: 9px; }
    .screen .home-play { min-height: 64px; }
    .home-play-label { font-size: 22px; }
    .screen .tile { min-height: 56px; padding-block: 7px; }
    .screen .segmented button { min-height: 36px; font-size: 13px; }
}

@media (max-height: 620px) {
    #challenge-panel { display: none; }
    .home-stage { min-height: 60px; }
}

@media (max-width: 360px) {
    .screen .segmented button { font-size: 12px; padding-inline: 2px; }
    #start-btn-hint { font-size: 12px; }
    .screen .tile { font-size: 11px; }
}

.screen .segmented button,
.screen .tile span {
    white-space: nowrap;
}

/* ---- HUD ---------------------------------------------------------------- */

#hud {
    position: absolute;
    top: calc(var(--safe-t) + 14px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 10;
}

#hud-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
}

#distance-counter {
    font-size: 46px;
    font-weight: 900;
    line-height: 1;
    letter-spacing: 0.01em;
    color: #fff;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 18px rgba(255, 138, 61, 0.55), 0 2px 6px rgba(0, 0, 0, 0.8);
}

#distance-counter::after {
    content: attr(data-flow);
    display: block;
    min-height: 13px;
    margin-top: 4px;
    color: var(--comet);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.18em;
    text-align: center;
    text-shadow: 0 0 10px rgba(255, 138, 61, 0.7);
}

#health-bar-container {
    display: flex;
    align-items: center;
}

#health-bar {
    width: 132px;
    height: 7px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    overflow: hidden;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

#health-fill {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: var(--grad-primary);
    transition: width 0.1s ease-out;
}

#health-fill[data-state="low"] {
    background: linear-gradient(90deg, #ff4d5e, #ff7a2f);
}

#health-fill[data-state="critical"] {
    background: var(--danger);
    animation: hull-blink 0.5s steps(2) infinite;
}

@keyframes hull-blink {
    50% { opacity: 0.45; }
}

#best-progress {
    width: 132px;
    height: 2px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
}

#best-progress.hidden { display: none; }

#best-progress-fill {
    width: 0;
    height: 100%;
    background: var(--void-soft);
    transition: width 0.2s linear;
}

#objective-status,
#powerup-effects {
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--surface-strong);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 13px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#powerup-effects {
    display: flex;
    gap: 10px;
    padding: 5px 10px;
}

.fx-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.fx-chip .ic {
    width: 15px;
    height: 15px;
}

.fx-surge { color: var(--surge); }
.fx-shield { color: var(--shield); }
.fx-drag { color: var(--danger); }

#pause-btn {
    position: absolute;
    top: calc(var(--safe-t) + 14px);
    right: calc(var(--safe-r) + 14px);
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--text);
    pointer-events: all;
    cursor: pointer;
    z-index: 50;
    touch-action: manipulation;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

#pause-btn .ic {
    width: 18px;
    height: 18px;
}

#pause-btn.hidden {
    display: none;
}

#pause-btn:active {
    transform: scale(0.94);
}

#run-banner,
#race-countdown {
    position: absolute;
    top: calc(var(--safe-t) + 128px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 55;
    padding: 8px 16px;
    border-radius: 999px;
    background: var(--surface-strong);
    border: 1px solid var(--line-strong);
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 0.12em;
    white-space: nowrap;
    animation: banner-in 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes banner-in {
    from { transform: translateX(-50%) scale(0.8); opacity: 0; }
    to { transform: translateX(-50%) scale(1); opacity: 1; }
}

#run-banner[data-tone="danger"] { color: var(--danger-soft); border-color: rgba(255, 77, 94, 0.7); }
#run-banner[data-tone="safe"] { color: #b9fbe9; border-color: rgba(62, 230, 200, 0.6); }
#run-banner[data-tone="milestone"] { color: var(--void-soft); border-color: rgba(139, 123, 255, 0.7); }
#run-banner[data-tone="best"] {
    color: var(--comet-ink);
    background: var(--grad-primary);
    border-color: transparent;
    box-shadow: var(--glow-primary);
}
#run-banner.hidden, #race-countdown.hidden { display: none; }

#race-countdown {
    top: 40%;
    padding: 16px 30px;
    font-size: 64px;
    color: #fff;
    border-color: var(--void);
}

#low-health-vignette {
    position: absolute;
    inset: 0;
    z-index: 25;
    pointer-events: none;
    box-shadow: inset 0 0 90px 24px rgba(255, 77, 94, 0.4);
    animation: low-health-pulse 1.2s ease-in-out infinite alternate;
}

#low-health-vignette.hidden { display: none; }

@keyframes low-health-pulse {
    from { opacity: 0.4; }
    to { opacity: 0.85; }
}

/* ---- Pause -------------------------------------------------------------- */

#pause-screen > * {
    width: min(360px, 100%);
}

#pause-screen h1 {
    text-align: center;
    font-size: 34px;
    margin-bottom: 18px;
}

#pause-screen #resume-btn {
    min-height: 60px;
    font-size: 18px;
    margin-top: 0;
}

.pause-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.pause-preferences {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 18px;
}

.screen .pref-toggle {
    margin: 0;
    min-height: 70px;
    flex-direction: column;
    gap: 6px;
    border-radius: var(--r-m);
    font-size: 12px;
    color: var(--text-faint);
    background: transparent;
    border-color: var(--line);
}

.screen .pref-toggle[aria-pressed="true"] {
    color: var(--text);
    background: var(--surface);
    border-color: rgba(62, 230, 200, 0.45);
}

.pref-toggle[aria-pressed="true"] .ic {
    color: var(--aurora);
}

.pause-links {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
}

.pause-links .text-action .ic {
    width: 17px;
    height: 17px;
}

#pause-help {
    margin-top: 6px;
    padding: 14px 16px;
    border-radius: var(--r-m);
    background: var(--surface);
    border: 1px solid var(--line);
    text-align: center;
}

.howto {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-dim);
}

.howto b { color: var(--text); }
.howto i { font-style: normal; font-weight: 800; }
.c-surge { color: var(--surge); }
.c-shield { color: var(--shield); }
.c-repair { color: var(--aurora); }
.c-drag { color: var(--danger); }

/* ---- Game over ---------------------------------------------------------- */

#game-over-screen {
    justify-content: space-between;
}

.result-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: min(380px, 100%);
}

#game-over-screen h1 {
    font-size: 26px;
    letter-spacing: 0.2em;
    padding-left: 0.2em;
    color: var(--text-dim);
    margin: 4px 0 0;
}

.result-distance {
    margin: 6px 0 2px !important;
    font-size: clamp(72px, 26vw, 120px) !important;
    font-weight: 900;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    background: linear-gradient(180deg, #ffffff 10%, var(--comet-soft) 60%, var(--comet) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 8px 30px rgba(255, 138, 61, 0.35));
    animation: score-pop 0.45s cubic-bezier(0.2, 1.5, 0.4, 1);
}

@keyframes score-pop {
    from { transform: scale(0.6); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

#result-best {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

#result-message {
    min-height: 1.4em;
    margin-top: 14px !important;
    padding: 8px 16px;
    border-radius: 999px;
    color: var(--text);
    font-size: 15px !important;
    font-weight: 700;
    background: var(--surface);
    border: 1px solid var(--line);
}

#result-message:empty {
    visibility: hidden;
}

#result-message[data-tone="best"] {
    color: var(--comet-ink);
    background: var(--grad-primary);
    border-color: transparent;
    box-shadow: var(--glow-primary);
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.result-actions {
    width: min(380px, 100%);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.result-actions button {
    width: 100%;
    margin: 0 !important;
}

.result-actions #restart-btn {
    min-height: 64px;
    font-size: 20px;
    border-radius: var(--r-l);
}

.reduced-motion *,
.reduced-motion *::before,
.reduced-motion *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
}

/* ---- Overlays / panels ------------------------------------------------- */

.duo-sub {
    margin-top: -4px !important;
    font-size: 14px !important;
}

#duo-game-type {
    width: min(360px, 88vw);
    margin-top: 6px;
}

#duo-lobby .duo-lobby-actions button {
    min-width: 120px;
}

#settings-overlay {
    position: absolute;
    inset: 0;
    background: rgba(5, 6, 15, 0.6);
    pointer-events: all;
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    backdrop-filter: blur(6px);
}

#settings-overlay.hidden {
    display: none;
}

#settings-panel {
    width: min(560px, 100%);
    max-height: 55dvh;
    background: var(--surface-strong);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    touch-action: auto; /* Allow all touch actions within panel */
}

#settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

#settings-title {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.02em;
}

#settings-close-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
}

#settings-close-btn:active {
    background: rgba(255, 255, 255, 0.14);
}

#settings-body {
    padding: 10px 14px 12px 14px;
    overflow: auto;
    overflow-y: scroll; /* Force scrollbar space */
    -webkit-overflow-scrolling: touch; /* Smooth iOS scrolling */
    overscroll-behavior: contain; /* Prevent bounce scroll to parent */
    touch-action: pan-y; /* Allow vertical touch scrolling */
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.settings-section {
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 14px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.04);
}

.settings-section-title {
    font-size: 12px;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.75);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.setting-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px 0;
}

.setting-row + .setting-row {
    border-top: 1px solid rgba(255, 255, 255, 0.10);
}

.setting-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.setting-name {
    font-size: 14px;
    font-weight: 700;
}

.setting-hint {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.65);
}

.setting-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.setting-value {
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.75);
    min-width: 44px;
    text-align: right;
}

.setting-control input[type="range"] {
    width: 160px;
    accent-color: var(--void);
    touch-action: pan-x; /* Allow horizontal dragging on mobile */
}

/* Stacked rows (label above control) for wide controls like selects */
.setting-row-stacked {
    grid-template-columns: 1fr;
}

.setting-select {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.setting-select button {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.setting-select button.active {
    background: rgba(139, 123, 255, 0.25);
    border-color: var(--void);
    color: #fff;
}

#settings-footer {
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
}

#settings-footer button {
    height: 44px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
}

#settings-footer button:active {
    background: rgba(255, 255, 255, 0.14);
}

#settings-upload-input {
    display: none;
}

/* ---- Duo (2-player) mode ---- */

#opp-bar-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

#opp-bar-container.hidden {
    display: none;
}

#opp-name {
    min-width: 60px;
    text-align: right;
    font-weight: 800;
}

#opp-health-bar {
    width: 80px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

#opp-health-fill {
    height: 100%;
    width: 100%;
    transition: width 0.15s ease-out;
}

#opp-distance {
    min-width: 44px;
    color: rgba(255, 255, 255, 0.75);
    font-variant-numeric: tabular-nums;
}

#spectate-banner {
    position: absolute;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 18px;
    border-radius: 20px;
    background: var(--surface-strong);
    border: 1px solid rgba(255, 255, 255, 0.25);
    font-size: 14px;
    font-weight: 700;
    z-index: 40;
    white-space: nowrap;
}

#spectate-banner.hidden,
#duo-toast.hidden {
    display: none;
}

#duo-toast {
    position: absolute;
    bottom: calc(30px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 18px;
    border-radius: 20px;
    background: var(--surface-strong);
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 13px;
    font-weight: 700;
    z-index: 40;
    white-space: nowrap;
}

#action-chip {
    position: absolute;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    padding: 9px 16px;
    border-radius: 999px;
    background: var(--surface-strong);
    border: 1px solid rgba(139, 123, 255, 0.75);
    color: #ddd6fe;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.06em;
    pointer-events: none;
    z-index: 35;
    white-space: nowrap;
}

#action-chip.release {
    border-color: rgba(239, 68, 68, 0.8);
    color: #fecaca;
}

#action-chip.hidden {
    display: none;
}

#tutorial-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 45;
}

#tutorial-overlay.hidden {
    display: none;
}

#tutorial-copy {
    position: absolute;
    top: calc(var(--safe-t) + 150px);
    left: 50%;
    width: min(330px, calc(100% - 40px));
    transform: translateX(-50%);
    padding: 10px 16px;
    border-radius: 16px;
    background: var(--surface-strong);
    border: 1px solid rgba(251, 191, 36, 0.7);
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    text-align: center;
    text-shadow: 0 2px 5px #000;
}

#tutorial-skip-btn {
    position: absolute;
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(66px + env(safe-area-inset-bottom));
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--surface-strong);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.8);
    font-size: 11px;
    font-weight: 800;
    pointer-events: all;
}

#duo-screen input {
    width: min(260px, 80vw);
    padding: 12px 16px;
    margin-top: 14px;
    font-size: 18px;
    text-align: center;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 14px;
    outline: none;
}

#duo-code-input {
    text-transform: uppercase;
    letter-spacing: 0.3em;
    font-weight: 800;
}

.duo-view {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.duo-view.hidden {
    display: none;
}

#duo-conn-status {
    font-size: 14px !important;
    color: var(--comet) !important;
}

#duo-conn-status.hidden {
    display: none;
}

#duo-home button {
    margin-top: 14px;
    width: min(260px, 80vw);
}

#duo-home button:disabled {
    opacity: 0.45;
    cursor: default;
}

#duo-code-input.hidden {
    display: none;
}

#duo-submit-btn {
    margin-top: 18px;
    padding: 12px 32px;
}

#duo-submit-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.duo-label {
    margin-bottom: 0 !important;
}

.duo-code-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

#duo-room-code {
    font-size: 44px;
    font-weight: 900;
    letter-spacing: 0.35em;
    padding-left: 0.35em; /* optically recenter the tracked text */
    color: var(--comet);
    user-select: text;
    -webkit-user-select: text;
}

.duo-share-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

#duo-copy-code-btn,
#duo-copy-link-btn {
    margin-top: 0;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 14px;
    box-shadow: none;
    white-space: nowrap;
}

#duo-copy-code-btn:disabled,
#duo-copy-link-btn:disabled {
    color: var(--aurora);
    cursor: default;
}

#duo-share-hint {
    font-size: 13px !important;
    color: rgba(255, 255, 255, 0.55) !important;
    user-select: text;
    -webkit-user-select: text;
}

#duo-player-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    min-width: min(280px, 80vw);
}

.duo-player-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 16px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 15px;
    font-weight: 700;
}

.duo-player-row.slot-1 { border-left: 4px solid #f97316; }
.duo-player-row.slot-2 { border-left: 4px solid #8b5cf6; }

.duo-player-status {
    color: rgba(255, 255, 255, 0.6);
    font-weight: 600;
}

.duo-player-status.ready { color: var(--aurora); }

.duo-player-row.empty {
    justify-content: center;
    border-style: dashed;
    background: transparent;
    color: rgba(255, 255, 255, 0.4);
    font-weight: 600;
}

.duo-lobby-actions {
    display: flex;
    gap: 12px;
}

#duo-start-btn.hidden {
    display: none;
}

#duo-start-btn:disabled {
    opacity: 0.45;
    cursor: default;
    box-shadow: none;
}

#duo-wait-hint {
    font-size: 13px !important;
    color: rgba(255, 255, 255, 0.5) !important;
}

#duo-wait-hint.hidden {
    display: none;
}

#duo-error {
    color: var(--danger-soft) !important;
    font-size: 14px !important;
}

#duo-error.hidden {
    display: none;
}

#duo-back-btn {
    margin-top: 16px;
    padding: 10px 24px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

#duo-results-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: min(300px, 82vw);
}

.duo-result-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 18px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 17px;
    font-weight: 700;
    flex-wrap: wrap;
}

.duo-result-row small {
    flex-basis: 100%;
    color: rgba(255,255,255,0.55);
    font-size: 11px;
}

#duo-series-score {
    margin: 18px 0 4px;
    color: var(--comet-soft);
    font-weight: 800;
}

#duo-rematch-btn {
    width: min(300px, 82vw);
}

.duo-result-row.slot-1 { border-left: 4px solid #f97316; }
.duo-result-row.slot-2 { border-left: 4px solid #8b5cf6; }

.duo-result-row.winner {
    background: rgba(251, 191, 36, 0.12);
    border-color: rgba(251, 191, 36, 0.5);
}

.duo-result-dist {
    font-variant-numeric: tabular-nums;
    color: var(--comet);
}

/* ---- Level select overlay (mirrors the settings dialog) ---- */

#level-select-overlay {
    position: absolute;
    inset: 0;
    background: rgba(5, 6, 15, 0.6);
    pointer-events: all;
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    backdrop-filter: blur(6px);
}

#level-select-overlay.hidden {
    display: none;
}

#level-select-panel {
    width: min(560px, 100%);
    max-height: 65dvh;
    background: var(--surface-strong);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    touch-action: auto;
}

#level-select-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

#level-select-title {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.02em;
}

#level-select-close-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
}

#level-list {
    padding: 10px 14px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.level-list-empty {
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    padding: 20px 0;
}

.level-row {
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 14px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.04);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.level-play-card {
    width: 100%;
    min-height: 86px;
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 12px;
    align-items: center;
    padding: 8px;
    color: #fff;
    text-align: left;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.level-thumb {
    height: 68px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background:
        radial-gradient(circle at 30% 30%, rgba(139,123,255,0.7), transparent 20%),
        linear-gradient(145deg, #111827, #312e81);
    color: var(--comet-soft);
    font-size: 28px;
}

.level-name {
    font-size: 14px;
    font-weight: 700;
}

.level-meta {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.65);
}

.level-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.level-actions button:not(.level-overflow) {
    display: none;
}

.level-actions.open button {
    display: inline-flex;
}

.level-actions .level-overflow {
    margin-left: auto;
    display: inline-flex;
}

.recently-deleted {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px dashed rgba(255,255,255,0.25);
    border-radius: 12px;
    color: rgba(255,255,255,0.7);
    font-size: 12px;
}

.recently-deleted button {
    padding: 8px 12px;
    border-radius: 10px;
    color: #fff;
    background: rgba(139,123,255,0.2);
    border: 1px solid var(--void);
}

.level-actions button {
    padding: 8px 12px;
    min-height: 40px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.85);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.level-actions button:active {
    background: rgba(255, 255, 255, 0.14);
}

#level-select-footer {
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
}

#level-select-footer button {
    height: 44px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
}

#level-import-input {
    display: none;
}

/* ---- Designer toolbar + inspector ---- */

#designer-toolbar {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(12px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 16px;
    background: var(--surface-strong);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    pointer-events: all;
    z-index: 60;
    max-width: calc(100% - 16px);
    flex-wrap: wrap;
    justify-content: center;
}

#designer-save-status {
    flex-basis: 100%;
    color: rgba(255,255,255,0.65);
    font-size: 11px;
    text-align: center;
}

#designer-toolbar.hidden {
    display: none;
}

#designer-tools,
#designer-actions {
    display: flex;
    gap: 6px;
}



#designer-toolbar button {
    min-width: 44px;
    height: 44px;
    padding: 0 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

#designer-tools button {
    height: 54px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
}

#designer-tools button small {
    max-width: 62px;
    overflow: hidden;
    color: rgba(255,255,255,0.65);
    font-size: 8px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#designer-test-btn {
    min-width: 112px !important;
    padding-inline: 16px !important;
    color: var(--comet-ink) !important;
    background: var(--grad-primary) !important;
    border: 0 !important;
}

#challenge-panel {
    width: min(360px, 88vw);
    margin-top: 22px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px;
    background: rgba(255,255,255,0.035);
}













#designer-toolbar button.active {
    background: rgba(139, 123, 255, 0.3);
    border-color: var(--void);
}

#designer-toolbar button.hidden {
    display: none;
}

#designer-actions {
    padding-left: 10px;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
}

#designer-inspector {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: min(360px, calc(100% - 24px));
    padding: 12px;
    border-radius: 16px;
    background: var(--surface-strong);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    pointer-events: all;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 10px;
    touch-action: auto;
}

#designer-inspector.hidden {
    display: none;
}

.inspector-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.inspector-label {
    font-size: 12px;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.75);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    min-width: 40px;
}

#designer-inspector button {
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

#designer-inspector button.active {
    background: rgba(139, 123, 255, 0.3);
    border-color: var(--void);
}

#insp-tier-value {
    min-width: 24px;
    text-align: center;
    font-weight: 800;
}

#insp-skins {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    overflow-x: auto;
}

.insp-skin-thumb img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    display: block;
}

#insp-delete {
    border-color: rgba(239, 68, 68, 0.5) !important;
    color: var(--danger-soft) !important;
}

#insp-art-input {
    display: none;
}



/* ---- Multiverse ------------------------------------------------------- */

#multiverse-screen {
    justify-content: flex-start;
    padding-top: max(46px, calc(env(safe-area-inset-top) + 24px));
    background:
        radial-gradient(circle at 20% 15%, rgba(103, 232, 249, 0.12), transparent 32%),
        radial-gradient(circle at 78% 42%, rgba(192, 132, 252, 0.12), transparent 34%),
        rgba(2, 6, 23, 0.96);
}

#multiverse-screen h1 {
    margin: 6px 0 12px;
    background: linear-gradient(120deg, #67e8f9, #e879f9 58%, #fef3c7);
    -webkit-background-clip: text;
    background-clip: text;
}

#multiverse-screen > p:not(.mv-kicker) {
    max-width: 440px;
    text-align: center;
    font-size: 15px;
    line-height: 1.5;
}

#multiverse-screen input,
.mv-side-panel input,
.mv-side-panel textarea,
.mv-side-panel select,
.mv-card textarea {
    width: 100%;
    padding: 11px 12px;
    color: #fff;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.34);
    border-radius: 10px;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
}

#multiverse-screen > input {
    width: min(360px, 88vw);
    margin-top: 16px;
    padding: 14px 16px;
    font-size: 18px;
    text-align: center;
}

#multiverse-screen input:focus,
.mv-side-panel input:focus,
.mv-side-panel textarea:focus,
.mv-side-panel select:focus,
.mv-card textarea:focus {
    border-color: #67e8f9;
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}

#multiverse-screen button {
    width: min(360px, 88vw);
    margin-top: 12px;
}

#mv-recover-form {
    width: min(360px, 88vw);
    margin-top: 14px;
    padding: 16px;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.86);
    border: 1px solid rgba(103, 232, 249, 0.24);
}

#mv-recover-form label {
    display: block;
    color: #cbd5e1;
    font-size: 13px;
    font-weight: 700;
}

#mv-recovery-input {
    margin-top: 8px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

#mv-entry-error {
    color: #fca5a5 !important;
    font-size: 14px !important;
}

.mv-kicker {
    color: #67e8f9 !important;
    font-size: 10px !important;
    font-weight: 900;
    letter-spacing: 0.18em;
}

.mv-modal {
    position: absolute;
    inset: 0;
    z-index: 410;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(2, 6, 23, 0.78);
    backdrop-filter: blur(12px);
    pointer-events: all;
}

.mv-card {
    width: min(440px, 92vw);
    max-height: 86dvh;
    overflow-y: auto;
    padding: 24px;
    border-radius: 20px;
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.98), rgba(15, 23, 42, 0.98));
    border: 1px solid rgba(103, 232, 249, 0.34);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.58);
    text-align: center;
    touch-action: pan-y;
}

.mv-card h2 {
    margin: 5px 0 12px;
}

.mv-card p {
    color: #cbd5e1;
    line-height: 1.5;
}

.mv-card code {
    display: block;
    margin: 18px 0 6px;
    padding: 14px 10px;
    color: #fef3c7;
    background: #020617;
    border-radius: 10px;
    font-size: clamp(16px, 5vw, 23px);
    letter-spacing: 0.08em;
    user-select: text;
    -webkit-user-select: text;
}

.mv-card button,
.mv-side-panel button,
#mv-hud button {
    padding: 10px 14px;
    color: #fff;
    background: linear-gradient(135deg, #0e7490, #7e22ce);
    border: 1px solid rgba(165, 243, 252, 0.26);
    border-radius: 11px;
    font-weight: 800;
    cursor: pointer;
    pointer-events: all;
}

.mv-card button:focus-visible,
.mv-side-panel button:focus-visible,
#mv-hud button:focus-visible,
#multiverse-screen button:focus-visible {
    outline: 3px solid #fef08a;
    outline-offset: 3px;
}

.mv-card button {
    width: 100%;
    margin-top: 10px;
}

.mv-loading-card {
    width: min(270px, 78vw);
}

.mv-spinner {
    width: 38px;
    height: 38px;
    margin: 0 auto 14px;
    border: 3px solid rgba(255, 255, 255, 0.16);
    border-top-color: #67e8f9;
    border-radius: 50%;
    animation: mv-spin 0.85s linear infinite;
}

@keyframes mv-spin {
    to { transform: rotate(360deg); }
}

#mv-hud {
    position: absolute;
    inset: 0;
    z-index: 70;
    pointer-events: none;
}

.mv-world-meta {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
    max-width: min(58vw, 360px);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 13px;
    border-radius: 13px;
    background: rgba(2, 6, 23, 0.74);
    border: 1px solid rgba(103, 232, 249, 0.26);
    backdrop-filter: blur(10px);
    text-shadow: 0 2px 6px #000;
}

.mv-world-meta strong {
    overflow: hidden;
    color: #ecfeff;
    font-size: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mv-world-meta span {
    color: #94a3b8;
    font-size: 11px;
}

#mv-count {
    color: #c4b5fd;
}

.mv-hud-actions {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    max-width: 42vw;
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
    pointer-events: all;
}

#mv-hud button {
    padding: 8px 10px;
    background: rgba(15, 23, 42, 0.82);
    border-color: rgba(255, 255, 255, 0.22);
    font-size: 10px;
    letter-spacing: 0.04em;
    backdrop-filter: blur(8px);
}

#mv-hud button.active {
    color: #082f49;
    background: #67e8f9;
}

#mv-status {
    position: absolute;
    left: 50%;
    bottom: max(22px, calc(env(safe-area-inset-bottom) + 10px));
    transform: translateX(-50%);
    width: max-content;
    max-width: min(88vw, 560px);
    padding: 9px 14px;
    border-radius: 999px;
    color: #d1fae5;
    background: rgba(6, 78, 59, 0.9);
    border: 1px solid rgba(110, 231, 183, 0.45);
    font-size: 12px;
    font-weight: 750;
    text-align: center;
}

#mv-status.error {
    color: #fee2e2;
    background: rgba(127, 29, 29, 0.92);
    border-color: rgba(252, 165, 165, 0.48);
}

.mv-side-panel {
    position: absolute;
    z-index: 320;
    top: max(82px, calc(env(safe-area-inset-top) + 68px));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: min(380px, calc(100vw - 24px));
    overflow-y: auto;
    padding: 18px;
    border-radius: 18px;
    background: rgba(2, 6, 23, 0.94);
    border: 1px solid rgba(103, 232, 249, 0.3);
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(16px);
    pointer-events: all;
    touch-action: pan-y;
}

.mv-panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.mv-panel-heading h2 {
    margin-top: 2px;
    font-size: 21px;
}

.mv-panel-heading button {
    padding: 6px 9px;
    background: rgba(255, 255, 255, 0.08);
}

#mv-save-status {
    color: #86efac;
    font-size: 11px;
    font-weight: 800;
}

.mv-side-panel label,
.mv-card label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
    color: #cbd5e1;
    font-size: 12px;
    font-weight: 750;
    text-align: left;
}

.mv-side-panel textarea,
.mv-card textarea {
    resize: vertical;
    font: inherit;
    line-height: 1.4;
}

.mv-side-panel button {
    width: 100%;
    margin-top: 12px;
}

.mv-side-panel .secondary-action,
.mv-card .secondary-action {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.mv-side-panel .text-action {
    color: #a5f3fc;
    background: transparent;
    border-color: transparent;
}

.mv-side-panel hr {
    height: 1px;
    margin: 18px 0;
    background: rgba(148, 163, 184, 0.22);
    border: 0;
}

.mv-check {
    flex-direction: row !important;
    align-items: flex-start;
    line-height: 1.4;
}

.mv-check input {
    width: 18px;
    margin-top: 1px;
    accent-color: #22d3ee;
}

.mv-editor-help {
    color: #94a3b8;
    font-size: 12px;
    line-height: 1.45;
}

.mv-number-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 10px;
}

.mv-side-panel .danger-action {
    color: #fecaca;
    background: rgba(127, 29, 29, 0.72);
    border-color: rgba(248, 113, 113, 0.42);
}

@media (max-width: 700px) {
    .mv-world-meta {
        max-width: 47vw;
    }

    .mv-hud-actions {
        max-width: 48vw;
    }

    .mv-side-panel {
        top: auto;
        left: 10px;
        right: 10px;
        bottom: max(10px, env(safe-area-inset-bottom));
        width: auto;
        max-height: 56dvh;
        border-radius: 18px 18px 10px 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mv-spinner {
        animation-duration: 2s;
    }
}

/* ---- Game modes + power-ups ------------------------------------------ */

.game-type-picker {
    width: min(360px, 88vw);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-top: 12px;
}

.screen .game-type-picker button {
    margin-top: 0;
    padding: 10px 6px;
    font-size: 12px;
    letter-spacing: 0.04em;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: none;
}

.screen .game-type-picker button[aria-pressed="true"] {
    background: var(--grad-primary);
    border-color: rgba(196, 181, 253, 0.9);
}

.screen .game-type-picker button:disabled {
    cursor: default;
    opacity: 0.55;
}

.screen .game-type-picker button[aria-pressed="true"]:disabled {
    opacity: 1;
}

#duo-game-type-hint {
    font-size: 13px;
    margin: 6px 0 0;
    text-align: center;
}

.screen .home-powerups {
    margin-top: 12px;
}

#objective-status {
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--surface-strong);
    border: 1px solid rgba(34, 211, 238, 0.55);
    color: #a5f3fc;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#powerup-effects {
    font-size: 13px;
    color: var(--comet-soft);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#powerup-effects.bad {
    color: #fecaca;
}
