:root {
    --bg-primary: #060911;
    --bg-secondary: #0d1322;
    --panel: rgba(12, 18, 31, 0.78);
    --border: rgba(255, 255, 255, 0.1);
    --text: #ecf2ff;
    --text-muted: #8ea0c8;
    --accent: #00d4ff;
    --danger: #ff5577;
    --mana: #00ecff;
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at top left, #111a33, #05070f 45%);
    color: var(--text);
    font-family: 'Segoe UI', Tahoma, sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

#game-shell {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 10px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 10px;
    -webkit-user-select: none;
    user-select: none;
}

.glass-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.35);
}

#top-hud {
    min-height: 64px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.hud-stat {
    display: flex;
    flex-direction: column;
    min-width: 70px;
}

.hud-stat .label {
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-size: 10px;
    font-weight: 700;
}

.hud-stat .value {
    font-size: 22px;
    line-height: 1.1;
    font-weight: 700;
}

.hud-stat .value.mana {
    color: var(--mana);
}

.hud-stat .value.lives {
    color: #ff788e;
}

#hud-controls {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.hud-btn {
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    min-height: 42px;
    touch-action: manipulation;
}

.hud-btn:hover {
    border-color: rgba(0, 212, 255, 0.55);
}

#game-main {
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 10px;
}

#battlefield-shell {
    min-height: 0;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: #03050c;
}

#battlefield-stage {
    position: relative;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#battlefield-stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#ui-overlay-canvas {
    z-index: 5;
    pointer-events: auto;
    touch-action: none;
}

#wave-banner {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 14px;
    z-index: 20;
    font-weight: 700;
    letter-spacing: 0.8px;
    color: var(--accent);
}

#wave-banner.hidden {
    opacity: 0;
    pointer-events: none;
}

#wave-banner.active {
    opacity: 1;
    transition: opacity 0.2s ease;
}

#selection-panel {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 280px;
    padding: 12px;
    z-index: 25;
}

#selection-panel h3 {
    margin: 0 0 8px;
    font-size: 18px;
}

#selection-panel p {
    margin: 0;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.35;
}

.selection-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}

.selection-actions button {
    flex: 1;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.25);
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    min-height: 42px;
    touch-action: manipulation;
}

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

#control-rail {
    min-height: 0;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: auto;
}

.panel-block h3 {
    margin: 0 0 8px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.panel-block select,
.panel-block button {
    font-family: inherit;
}

#active-map-name {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

#menu-map-select {
    width: 100%;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(0, 0, 0, 0.35);
    color: var(--text);
    padding: 9px;
}
#challenge-label {
    margin: 8px 0 0;
    font-size: 11px;
    line-height: 1.3;
    color: var(--text-muted);
}

.button-grid {
    display: grid;
    gap: 8px;
}

.button-grid.two {
    grid-template-columns: 1fr 1fr;
}

.button-grid.four {
    grid-template-columns: repeat(2, 1fr);
}

.mode-btn,
.buy-gem-btn {
    border-radius: 11px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(0, 0, 0, 0.36);
    color: var(--text);
    padding: 12px 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    min-height: 42px;
    touch-action: manipulation;
}

.mode-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(0, 212, 255, 0.4) inset;
}

.buy-gem-btn.red {
    border-color: rgba(239, 68, 68, 0.55);
}

.buy-gem-btn.green {
    border-color: rgba(34, 197, 94, 0.55);
}

.buy-gem-btn.yellow {
    border-color: rgba(250, 204, 21, 0.55);
}

.buy-gem-btn.blue {
    border-color: rgba(59, 130, 246, 0.55);
}

.talent-list {
    display: grid;
    gap: 6px;
}

.talent-row {
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.24);
    padding: 8px;
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}

.talent-row strong {
    display: block;
    font-size: 12px;
}

.talent-row small {
    color: var(--text-muted);
}

.talent-upgrade {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(0, 212, 255, 0.45);
    background: rgba(0, 212, 255, 0.12);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.talent-upgrade:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#stash-bar {
    min-height: 88px;
    padding: 10px 14px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    align-items: center;
}

.stash-title {
    font-size: 12px;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--text-muted);
}

#stash-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 8px;
}

.stash-slot {
    min-height: 58px;
    border-radius: 12px;
    border: 1px dashed rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.28);
    color: var(--text);
    display: grid;
    place-content: center;
    gap: 2px;
    cursor: pointer;
    touch-action: none;
}

.stash-slot.occupied {
    border-style: solid;
    border-color: color-mix(in srgb, var(--gem-color), white 20%);
    box-shadow: 0 0 20px color-mix(in srgb, var(--gem-color), transparent 68%);
}

.slot-lvl {
    font-size: 12px;
    font-weight: 700;
}

.slot-shape {
    font-size: 10px;
    color: color-mix(in srgb, var(--gem-color), white 40%);
}

.slot-empty {
    opacity: 0.5;
    font-size: 20px;
}

.drag-ghost {
    --gem-color: #ffffff;
    position: fixed;
    width: 70px;
    height: 70px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--gem-color), white 20%);
    background: color-mix(in srgb, var(--gem-color), black 75%);
    box-shadow: 0 0 24px color-mix(in srgb, var(--gem-color), transparent 50%);
    pointer-events: none;
    z-index: 200;
    display: grid;
    place-content: center;
    text-align: center;
}

.drag-ghost .g-lvl {
    font-size: 14px;
    font-weight: 700;
}

.drag-ghost .g-shape {
    margin-top: 2px;
    font-size: 10px;
}

#menu-overlay {
    position: absolute;
    inset: 0;
    z-index: 130;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(2, 4, 10, 0.76);
}

#menu-overlay.active {
    display: flex;
}

#menu-overlay .menu-screen.hidden {
    display: none;
}

.menu-screen {
    width: min(560px, 94vw);
    padding: 24px;
}

#menu-screen-title {
    text-align: center;
}

#menu-screen-title h1 {
    margin: 0;
    font-size: clamp(32px, 5vw, 46px);
    letter-spacing: 1.2px;
}

#menu-screen-title p {
    margin: 10px 0 0;
    color: var(--text-muted);
    line-height: 1.4;
}

#menu-screen-level h2,
#menu-screen-shop h2 {
    margin: 0 0 14px;
    font-size: 26px;
}

#menu-screen-level label {
    display: block;
    margin: 0 0 8px;
    font-size: 11px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

#menu-challenge-label {
    margin: 10px 0 0;
    font-size: 12px;
    line-height: 1.35;
    color: var(--text-muted);
}

#menu-screen-shop h2 span {
    color: var(--accent);
}

.menu-actions {
    margin-top: 14px;
    display: flex;
    gap: 10px;
}

.menu-actions .menu-btn {
    flex: 1;
}

.menu-btn {
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.36);
    color: var(--text);
    padding: 11px 14px;
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
}

.menu-btn.primary {
    border-color: rgba(0, 212, 255, 0.58);
    background: rgba(0, 212, 255, 0.18);
}

#menu-back-link {
    position: absolute;
    left: 16px;
    bottom: 16px;
    z-index: 132;
    color: var(--text);
    text-decoration: none;
    padding: 8px 12px;
    font-size: 12px;
}
#run-overlay,
#preview-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 4, 10, 0.72);
}

#run-overlay {
    z-index: 120;
}

#preview-overlay {
    z-index: 140;
}
#run-overlay.hidden,
#preview-overlay.hidden,
#selection-panel.hidden {
    display: none;
}

.run-card,
.preview-card {
    width: min(420px, 92vw);
    padding: 20px;
    text-align: center;
}

.run-card h2,
.preview-card h3 {
    margin: 0 0 10px;
}

#run-summary {
    text-align: left;
    white-space: pre-wrap;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.26);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 10px;
    min-height: 132px;
}

#btn-play-again,
#btn-return-title,
#btn-open-fullscreen {
    margin-top: 12px;
    border-radius: 10px;
    border: 1px solid rgba(0, 212, 255, 0.5);
    background: rgba(0, 212, 255, 0.15);
    color: var(--text);
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
}

#btn-play-again,
#btn-return-title {
    width: 100%;
}

#btn-return-title {
    margin-top: 8px;
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.08);
}
body.preview-mode #control-rail,
body.preview-mode #stash-bar,
body.preview-mode #top-hud,
body.preview-mode #selection-panel {
    opacity: 0.35;
    pointer-events: none;
}

@media (max-width: 1180px) {
    #game-main {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
    }

    #control-rail {
        max-height: 280px;
    }

    #stash-grid {
        grid-template-columns: repeat(8, minmax(50px, 1fr));
    }
}

@media (orientation: portrait) and (max-width: 980px) {
    #game-shell {
        padding: 5px;
        gap: 5px;
    }

    #top-hud {
        flex-wrap: wrap;
        gap: 4px;
        padding: 6px 8px;
        min-height: 58px;
    }

    .hud-stat {
        min-width: 56px;
    }

    .hud-stat .label {
        font-size: 9px;
        letter-spacing: 1px;
    }

    .hud-stat .value {
        font-size: 16px;
    }

    #hud-controls {
        width: 100%;
        margin-left: 0;
        gap: 6px;
        touch-action: manipulation;
    }

    #hud-controls .hud-btn {
        flex: 1;
        min-height: 38px;
        font-size: 12px;
        padding: 8px 8px;
    }

    #game-main {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(34vh, 40vh) auto;
    }

    #battlefield-shell {
        min-height: 34vh;
        border-radius: 14px;
    }

    #control-rail {
        max-height: 136px;
        min-height: 118px;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(176px, 1fr);
        gap: 8px;
        padding: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        touch-action: pan-x;
    }

    #control-rail .panel-block {
        min-height: 100%;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 10px;
        padding: 8px;
        background: rgba(0, 0, 0, 0.2);
        scroll-snap-align: start;
    }

    #control-rail .panel-block h3 {
        margin-bottom: 6px;
        font-size: 12px;
        letter-spacing: 0.9px;
    }

    #challenge-label {
        margin-top: 5px;
        font-size: 10px;
        line-height: 1.2;
    }

    .mode-btn,
    .buy-gem-btn,
    .selection-actions button {
        min-height: 36px;
        font-size: 12px;
        padding: 7px 6px;
        border-radius: 9px;
    }

    #stash-bar {
        grid-template-columns: 1fr;
        gap: 5px;
        min-height: auto;
        padding: 6px 8px;
    }

    .stash-title {
        font-size: 11px;
        letter-spacing: 1px;
    }

    #stash-grid {
        grid-template-columns: repeat(8, minmax(0, 1fr));
        gap: 2px;
    }

    .stash-slot {
        min-height: 40px;
        border-radius: 9px;
    }

    .slot-lvl {
        font-size: 11px;
    }

    .slot-shape {
        font-size: 9px;
    }

    .slot-empty {
        font-size: 13px;
    }

    .menu-actions {
        flex-direction: column;
    }

    #menu-back-link {
        left: 12px;
        bottom: 12px;
    }
}

body.egg-prismatic {
    background: radial-gradient(circle at 20% 10%, #2a1a44, #060911 40%, #102241);
}

body.egg-prismatic .glass-panel {
    border-color: rgba(123, 47, 255, 0.35);
}

body.egg-void #fx-canvas {
    filter: hue-rotate(140deg) saturate(1.2);
}






:root {
    --panel: linear-gradient(180deg, rgba(16, 24, 42, 0.88), rgba(8, 13, 25, 0.82));
    --border: rgba(171, 208, 255, 0.12);
    --text-muted: #9eb0d6;
    --accent: #6be8ff;
    --radius: 16px;
}

html,
body {
    background:
        radial-gradient(circle at 14% 12%, rgba(74, 114, 255, 0.16), transparent 26%),
        radial-gradient(circle at 82% 18%, rgba(0, 212, 255, 0.12), transparent 24%),
        radial-gradient(circle at 50% 100%, rgba(113, 72, 255, 0.12), transparent 30%),
        linear-gradient(180deg, #050813, #02040a 72%);
    font-family: 'Trebuchet MS', 'Segoe UI', Tahoma, sans-serif;
}

body::before,
body::after {
    content: '';
    position: fixed;
    inset: -12%;
    pointer-events: none;
    z-index: -1;
}

body::before {
    background:
        radial-gradient(circle at 24% 30%, rgba(90, 118, 255, 0.16), transparent 22%),
        radial-gradient(circle at 74% 24%, rgba(0, 212, 255, 0.13), transparent 20%),
        radial-gradient(circle at 52% 72%, rgba(167, 96, 255, 0.11), transparent 26%);
    filter: blur(28px);
    animation: body-drift 18s ease-in-out infinite alternate;
}

body::after {
    background: linear-gradient(115deg, transparent 0%, rgba(255, 255, 255, 0.03) 46%, transparent 52%);
    opacity: 0.7;
    animation: body-sheen 14s linear infinite;
}

.glass-panel {
    border: 1px solid var(--border);
    background: var(--panel);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        0 18px 45px rgba(0, 0, 0, 0.42);
}

#top-hud {
    position: relative;
    min-height: 70px;
    overflow: hidden;
    gap: 16px;
}

#top-hud::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
    transform: translateX(-100%);
    animation: hud-sheen 9s linear infinite;
    pointer-events: none;
}

.hud-stat {
    position: relative;
    min-width: 78px;
}

.hud-stat .value {
    text-shadow: 0 0 18px rgba(255, 255, 255, 0.08);
}

#hud-controls {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.hud-btn,
.mode-btn,
.buy-gem-btn,
.menu-btn,
.selection-actions button,
#btn-play-again,
#btn-return-title,
#btn-open-fullscreen {
    position: relative;
    overflow: hidden;
    transition:
        transform 0.16s ease,
        border-color 0.16s ease,
        box-shadow 0.16s ease,
        background 0.16s ease;
}

.hud-btn::before,
.mode-btn::before,
.buy-gem-btn::before,
.menu-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.09), transparent 72%);
    transform: translateX(-130%);
    transition: transform 0.22s ease;
}

.hud-btn:hover::before,
.mode-btn:hover::before,
.buy-gem-btn:hover::before,
.menu-btn:hover::before {
    transform: translateX(130%);
}

.hud-btn:hover,
.mode-btn:hover,
.buy-gem-btn:hover,
.menu-btn:hover,
.selection-actions button:hover,
#btn-play-again:hover,
#btn-return-title:hover,
#btn-open-fullscreen:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

.hud-btn:active,
.mode-btn:active,
.buy-gem-btn:active,
.menu-btn:active,
.selection-actions button:active {
    transform: translateY(0);
}

.hud-btn {
    background: linear-gradient(180deg, rgba(10, 17, 31, 0.92), rgba(4, 8, 18, 0.88));
}

.hud-btn.accent {
    border-color: rgba(107, 232, 255, 0.5);
    background: linear-gradient(180deg, rgba(7, 46, 66, 0.92), rgba(3, 20, 34, 0.92));
    box-shadow: inset 0 0 0 1px rgba(107, 232, 255, 0.12);
}

#battlefield-shell {
    background:
        radial-gradient(circle at 50% 0%, rgba(113, 164, 255, 0.08), transparent 40%),
        linear-gradient(180deg, rgba(5, 9, 19, 0.98), rgba(3, 6, 12, 1));
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.02),
        inset 0 -40px 80px rgba(0, 0, 0, 0.25),
        0 28px 80px rgba(0, 0, 0, 0.45);
}

#wave-banner {
    top: 20px;
    padding: 10px 16px;
    border-color: rgba(107, 232, 255, 0.18);
    background: linear-gradient(180deg, rgba(10, 19, 36, 0.88), rgba(7, 13, 24, 0.82));
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.32);
}

#wave-banner.active {
    animation: wave-banner-in 220ms ease;
}

#selection-panel {
    background: linear-gradient(180deg, rgba(11, 19, 35, 0.94), rgba(6, 10, 19, 0.9));
    box-shadow: 0 20px 36px rgba(0, 0, 0, 0.34);
}

.selection-actions button:hover {
    border-color: rgba(107, 232, 255, 0.38);
}

.mode-btn,
.buy-gem-btn,
.menu-btn,
.selection-actions button {
    background: linear-gradient(180deg, rgba(12, 20, 36, 0.9), rgba(6, 10, 20, 0.84));
}

.mode-btn.active {
    box-shadow:
        inset 0 0 0 1px rgba(107, 232, 255, 0.3),
        0 0 28px rgba(0, 212, 255, 0.14);
}

.talent-row {
    background: linear-gradient(180deg, rgba(9, 15, 29, 0.84), rgba(4, 8, 16, 0.82));
}

.stash-slot {
    background: linear-gradient(180deg, rgba(10, 16, 30, 0.88), rgba(4, 7, 15, 0.86));
    transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.stash-slot:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.28);
}

.stash-slot.occupied {
    background:
        radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--gem-color), white 14%) 0%, transparent 34%),
        linear-gradient(180deg, rgba(11, 17, 33, 0.92), rgba(5, 9, 18, 0.9));
}

.drag-ghost {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

#menu-overlay {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    background:
        radial-gradient(circle at top, rgba(62, 104, 255, 0.22), transparent 30%),
        rgba(2, 4, 10, 0.78);
}

body.in-run-menu #menu-overlay {
    background:
        radial-gradient(circle at top, rgba(0, 212, 255, 0.18), transparent 34%),
        rgba(2, 5, 12, 0.82);
}

.menu-screen {
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(180deg, rgba(12, 20, 36, 0.94), rgba(6, 10, 18, 0.9));
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.42);
    animation: menu-screen-in 220ms ease;
}

#menu-screen-pause h2,
#menu-screen-title h1,
#menu-screen-level h2,
#menu-screen-shop h2 {
    text-shadow: 0 0 24px rgba(255, 255, 255, 0.08);
}

#menu-run-summary {
    margin: 14px 0 0;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.22);
    color: var(--text-muted);
    line-height: 1.5;
}

.menu-actions-stack {
    flex-direction: column;
}

#menu-back-link {
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28);
    transition: transform 0.16s ease, border-color 0.16s ease;
}

#menu-back-link:hover {
    transform: translateY(-1px);
    border-color: rgba(107, 232, 255, 0.3);
}

#menu-back-link.hidden {
    display: none;
}

.run-card,
.preview-card {
    background: linear-gradient(180deg, rgba(12, 20, 36, 0.96), rgba(6, 10, 18, 0.92));
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.42);
}

#run-summary {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.hidden {
    display: none !important;
}

@keyframes body-drift {
    from {
        transform: translate3d(-2%, -1%, 0) scale(1);
    }
    to {
        transform: translate3d(2%, 1%, 0) scale(1.04);
    }
}

@keyframes body-sheen {
    from {
        transform: translateX(-18%);
    }
    to {
        transform: translateX(18%);
    }
}

@keyframes hud-sheen {
    from {
        transform: translateX(-120%);
    }
    to {
        transform: translateX(120%);
    }
}

@keyframes wave-banner-in {
    from {
        opacity: 0;
        transform: translate(-50%, -8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes menu-screen-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (orientation: portrait) and (max-width: 980px) {
    #hud-controls {
        justify-content: stretch;
    }

    #hud-controls .hud-btn {
        flex: 1 1 calc(50% - 4px);
    }

    #menu-run-summary {
        font-size: 11px;
    }
}

@media (orientation: landscape) and (max-height: 540px) {
    #game-shell {
        padding: 4px;
        gap: 4px;
    }

    #top-hud {
        min-height: 52px;
        padding: 5px 8px;
        gap: 5px;
    }

    .hud-stat {
        min-width: 52px;
    }

    .hud-stat .label {
        font-size: 9px;
        letter-spacing: 1px;
    }

    .hud-stat .value {
        font-size: 15px;
    }

    #hud-controls {
        gap: 5px;
    }

    #hud-controls .hud-btn {
        min-height: 34px;
        font-size: 12px;
        padding: 6px 8px;
    }

    #game-main {
        grid-template-rows: minmax(42vh, 48vh) auto;
        gap: 6px;
    }

    #control-rail {
        max-height: 114px;
        min-height: 100px;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(170px, 1fr);
        gap: 6px;
        padding: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
    }

    #control-rail .panel-block {
        min-height: 100%;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 10px;
        padding: 7px;
        background: rgba(0, 0, 0, 0.2);
        scroll-snap-align: start;
    }

    #control-rail .panel-block h3 {
        margin-bottom: 5px;
        font-size: 12px;
    }

    .mode-btn,
    .buy-gem-btn {
        min-height: 34px;
        font-size: 12px;
        padding: 6px 6px;
        border-radius: 9px;
    }

    #stash-bar {
        padding: 5px 8px;
        gap: 5px;
    }

    .stash-title {
        font-size: 11px;
        letter-spacing: 1px;
    }

    #stash-grid {
        gap: 2px;
    }

    .stash-slot {
        min-height: 36px;
        border-radius: 9px;
    }

.slot-empty {
        font-size: 13px;
    }
}

.hud-actions-toggle {
    display: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: linear-gradient(180deg, rgba(10, 17, 31, 0.92), rgba(4, 8, 18, 0.88));
    color: var(--text);
    border-radius: 10px;
    width: 38px;
    height: 38px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    place-items: center;
    touch-action: manipulation;
}

@media (orientation: portrait) and (max-width: 980px), (orientation: landscape) and (max-height: 540px) {
    #top-hud {
        overflow: visible;
        position: relative;
    }

    .hud-actions-toggle {
        display: grid;
        margin-left: auto;
        flex: 0 0 auto;
    }

    #hud-controls {
        position: absolute;
        top: calc(100% + 6px);
        right: 8px;
        width: min(230px, calc(100vw - 18px));
        padding: 8px;
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.16);
        background: linear-gradient(180deg, rgba(12, 20, 36, 0.96), rgba(6, 10, 18, 0.92));
        box-shadow: 0 18px 35px rgba(0, 0, 0, 0.42);
        display: none;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        z-index: 90;
        margin-left: 0;
    }

    #top-hud.hud-controls-open #hud-controls {
        display: grid;
    }

    #hud-controls .hud-btn {
        min-height: 34px;
        font-size: 12px;
        padding: 7px 8px;
    }
}

#boot-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 5, 12, 0.84);
    z-index: 160;
}

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

.boot-card {
    width: min(520px, 92vw);
}

#boot-overlay-message {
    margin: 0 0 12px;
    color: var(--text);
}

#boot-overlay-detail {
    margin: 0;
    white-space: pre-wrap;
    text-align: left;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.24);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px;
    font: 12px/1.5 Consolas, 'Courier New', monospace;
}

/* ==========================================================================
   2026-03 UI PASS: MOBILE MAP PRIORITY + BUBBLE-FILM RAINBOW TYPOGRAPHY
   ========================================================================== */

:root {
    --bubble-rainbow: linear-gradient(120deg, #67e8f9 0%, #86efac 18%, #fef08a 34%, #fdba74 50%, #f9a8d4 66%, #c4b5fd 82%, #67e8f9 100%);
}

#menu-screen-title h1,
#menu-screen-pause h2,
#menu-screen-level h2,
#menu-screen-shop h2,
#run-title {
    background: var(--bubble-rainbow);
    background-size: 220% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gem-rainbow-shift 11s linear infinite;
}

#top-hud .hud-stat:nth-of-type(1) .value {
    color: #bdb4ff;
}

#top-hud .hud-stat:nth-of-type(2) .value {
    color: #7ff5ff;
}

#top-hud .hud-stat:nth-of-type(3) .value {
    color: #ff9ab2;
}

#top-hud .hud-stat:nth-of-type(4) .value {
    color: #ffe08d;
}

.panel-block h3,
.stash-title {
    color: #b5c7ff;
}

@keyframes gem-rainbow-shift {
    0% {
        background-position: 0% 50%;
    }

    100% {
        background-position: 220% 50%;
    }
}

@media (prefers-reduced-motion: reduce) {
    #menu-screen-title h1,
    #menu-screen-pause h2,
    #menu-screen-level h2,
    #menu-screen-shop h2,
    #run-title {
        animation: none;
        background-size: 100% auto;
    }

    #top-hud .hud-stat .label,
    #control-rail .panel-block h3,
    .stash-title {
        animation: none;
        background-size: 100% auto;
    }
}

/* Mobile portrait: reclaim vertical space for larger battlefield */
@media (orientation: portrait) and (max-width: 980px) {
    #game-shell {
        padding: 3px;
        gap: 4px;
        grid-template-rows: auto minmax(0, 1fr) auto;
    }

    #top-hud {
        min-height: 52px;
        padding: 5px 7px;
        gap: 6px;
    }

    .hud-stat {
        min-width: 48px;
    }

    .hud-stat .label {
        font-size: 8px;
        letter-spacing: 0.9px;
    }

    .hud-stat .value {
        font-size: 14px;
    }

    #game-main {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
        gap: 4px;
    }

    #battlefield-shell {
        min-height: 0;
        height: 100%;
        border-radius: 12px;
    }

    #control-rail {
        max-height: 104px;
        min-height: 92px;
        padding: 6px;
        gap: 6px;
        grid-auto-columns: minmax(150px, 1fr);
    }

    #control-rail .panel-block {
        padding: 6px;
    }

    #control-rail .panel-block h3 {
        margin-bottom: 4px;
        font-size: 11px;
        letter-spacing: 0.6px;
    }

    #active-map-name {
        font-size: 13px;
    }

    #challenge-label {
        margin-top: 4px;
        font-size: 9px;
        line-height: 1.15;
    }

    .mode-btn,
    .buy-gem-btn,
    .selection-actions button {
        min-height: 32px;
        font-size: 11px;
        padding: 5px 6px;
        border-radius: 8px;
    }

    #stash-bar {
        padding: 5px 7px;
        gap: 4px;
    }

    .stash-title {
        font-size: 10px;
        letter-spacing: 0.8px;
    }

    #stash-grid {
        gap: 2px;
    }

    .stash-slot {
        min-height: 34px;
        border-radius: 8px;
    }

    .slot-lvl {
        font-size: 10px;
    }

    .slot-shape {
        font-size: 8px;
    }

    .slot-empty {
        font-size: 12px;
    }

    #selection-panel {
        right: 8px;
        left: 8px;
        bottom: 8px;
        width: auto;
        padding: 9px;
    }

    #selection-panel h3 {
        font-size: 14px;
    }

    #selection-panel p {
        font-size: 11px;
    }
}

/* Mobile landscape: keep map dominant */
@media (orientation: landscape) and (max-height: 540px) {
    #game-main {
        grid-template-rows: minmax(0, 1fr) auto;
    }

    #battlefield-shell {
        min-height: 0;
    }

    #control-rail {
        max-height: 96px;
        min-height: 88px;
        grid-auto-columns: minmax(156px, 1fr);
    }

    #stash-bar {
        padding: 4px 6px;
    }

    .stash-slot {
        min-height: 32px;
    }
}

/* Second compact pass: force battlefield priority on real phone viewports */
@media (orientation: portrait) and (max-width: 980px) {
    #game-shell {
        height: 100dvh;
        padding: 2px !important;
        gap: 3px !important;
        grid-template-rows: auto minmax(0, 1fr) auto !important;
    }

    #top-hud {
        min-height: 44px !important;
        padding: 4px 6px !important;
        gap: 4px !important;
        border-radius: 11px;
    }

    #top-hud .hud-stat {
        min-width: 44px !important;
    }

    #top-hud .hud-stat .label {
        font-size: 7px !important;
        letter-spacing: 0.7px !important;
    }

    #top-hud .hud-stat .value {
        font-size: 13px !important;
        line-height: 1 !important;
    }

    .hud-actions-toggle {
        width: 34px;
        height: 34px;
        font-size: 17px;
        border-radius: 9px;
    }

    #game-main {
        min-height: 0;
        height: 100%;
        grid-template-columns: 1fr !important;
        grid-template-rows: minmax(0, 1fr) auto !important;
        gap: 3px !important;
        align-content: stretch;
    }

    #battlefield-shell {
        min-height: 0 !important;
        height: 100%;
        border-radius: 11px;
    }

    #control-rail {
        max-height: 78px !important;
        min-height: 70px !important;
        padding: 4px !important;
        gap: 4px !important;
        grid-auto-columns: minmax(138px, 1fr) !important;
    }

    #control-rail .panel-block {
        padding: 5px !important;
    }

    #control-rail .panel-block h3 {
        margin-bottom: 3px !important;
        font-size: 10px !important;
        letter-spacing: 0.6px !important;
    }

    #active-map-name {
        font-size: 12px !important;
        line-height: 1.15;
    }

    #challenge-label {
        display: none;
    }

    .mode-btn,
    .buy-gem-btn,
    .selection-actions button {
        min-height: 30px !important;
        font-size: 10px !important;
        padding: 4px 5px !important;
        border-radius: 8px !important;
    }

    #stash-bar {
        grid-template-columns: auto 1fr !important;
        min-height: 52px !important;
        padding: 4px 6px !important;
        gap: 6px !important;
        align-items: center;
    }

    .stash-title {
        font-size: 9px !important;
        letter-spacing: 0.6px !important;
        white-space: nowrap;
    }

    #stash-grid {
        gap: 2px !important;
    }

    .stash-slot {
        min-height: 30px !important;
        border-radius: 7px !important;
    }

    .slot-lvl {
        font-size: 9px !important;
    }

    .slot-shape {
        font-size: 7px !important;
    }

    .slot-empty {
        font-size: 11px !important;
    }

    #selection-panel {
        right: 6px;
        left: 6px;
        bottom: 6px;
        width: auto;
        padding: 8px;
    }

    #selection-panel h3 {
        font-size: 13px;
    }

    #selection-panel p {
        font-size: 10px;
    }
}

@media (orientation: landscape) and (max-height: 540px) {
    #game-shell {
        height: 100dvh;
        padding: 2px !important;
        gap: 3px !important;
    }

    #game-main {
        grid-template-rows: minmax(0, 1fr) auto !important;
        gap: 3px !important;
    }

    #control-rail {
        max-height: 74px !important;
        min-height: 66px !important;
        grid-auto-columns: minmax(132px, 1fr) !important;
    }

    #stash-bar {
        min-height: 46px !important;
    }

    .stash-slot {
        min-height: 28px !important;
    }
}

/* Rainbow typography accents in-game */
#top-hud .hud-stat .label,
#control-rail .panel-block h3,
.stash-title {
    background: var(--bubble-rainbow);
    background-size: 220% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gem-rainbow-shift 13s linear infinite;
}

/* Final mobile fit pass: remove oversized level card and fit build/buy controls cleanly */
@media (orientation: portrait) and (max-width: 980px) {
    #control-rail {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        grid-auto-flow: row !important;
        grid-auto-columns: initial !important;
        max-height: 76px !important;
        min-height: 68px !important;
        overflow: hidden !important;
        overflow-x: hidden !important;
        overflow-y: hidden !important;
        scroll-snap-type: none !important;
        padding: 4px !important;
        gap: 4px !important;
    }

    #control-rail .panel-block:first-child {
        display: none !important;
    }

    #control-rail .panel-block {
        min-height: 0 !important;
        padding: 4px !important;
        border-radius: 8px !important;
    }

    #control-rail .panel-block h3 {
        margin-bottom: 3px !important;
        font-size: 9px !important;
        letter-spacing: 0.7px !important;
    }

    #control-rail .button-grid.two,
    #control-rail .button-grid.four {
        gap: 3px !important;
    }

    #control-rail .button-grid.four {
        grid-template-columns: 1fr 1fr !important;
    }

    #control-rail .mode-btn,
    #control-rail .buy-gem-btn {
        min-height: 25px !important;
        padding: 2px 3px !important;
        font-size: 8px !important;
        line-height: 1.1 !important;
        border-radius: 7px !important;
        white-space: normal;
        word-break: break-word;
    }

    #stash-bar {
        min-height: 48px !important;
    }

    .stash-title {
        font-size: 8px !important;
    }

    .stash-slot {
        min-height: 26px !important;
    }
}

@media (orientation: landscape) and (max-height: 540px) {
    #control-rail .panel-block:first-child {
        display: none !important;
    }

    #control-rail {
        grid-template-columns: 1fr 1fr !important;
        grid-auto-flow: row !important;
        grid-auto-columns: initial !important;
        max-height: 66px !important;
        min-height: 60px !important;
        overflow: hidden !important;
        scroll-snap-type: none !important;
    }
}

/* Hard mobile fit: guaranteed no button clipping */
@media (orientation: portrait) and (max-width: 980px) {
    #control-rail {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        grid-template-areas: "build buy" !important;
        grid-auto-flow: row !important;
        grid-auto-columns: initial !important;
        max-height: 102px !important;
        min-height: 102px !important;
        padding: 6px !important;
        gap: 6px !important;
        overflow: hidden !important;
    }

    #control-rail .panel-block:first-child {
        display: none !important;
    }

    #control-rail .panel-block:nth-child(2) {
        grid-area: build;
    }

    #control-rail .panel-block:nth-child(3) {
        grid-area: buy;
    }

    #control-rail .panel-block {
        padding: 6px !important;
        min-height: 0 !important;
        border-radius: 9px !important;
    }

    #control-rail .panel-block h3 {
        margin-bottom: 4px !important;
        font-size: 10px !important;
        letter-spacing: 0.7px !important;
        line-height: 1 !important;
    }

    #control-rail .button-grid.two {
        grid-template-columns: 1fr 1fr !important;
        gap: 4px !important;
    }

    #control-rail .button-grid.four {
        grid-template-columns: 1fr 1fr !important;
        gap: 4px !important;
    }

    #control-rail .mode-btn,
    #control-rail .buy-gem-btn {
        min-height: 29px !important;
        padding: 4px 4px !important;
        font-size: 9px !important;
        line-height: 1.1 !important;
        border-radius: 8px !important;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    #stash-bar {
        min-height: 44px !important;
        padding: 4px 6px !important;
    }

    .stash-slot {
        min-height: 24px !important;
    }
}

@media (orientation: landscape) and (max-height: 540px) {
    #control-rail {
        max-height: 88px !important;
        min-height: 88px !important;
        grid-template-columns: 1fr 1fr !important;
        grid-auto-flow: row !important;
        grid-auto-columns: initial !important;
        padding: 5px !important;
        gap: 5px !important;
        overflow: hidden !important;
    }

    #control-rail .panel-block:first-child {
        display: none !important;
    }

    #control-rail .button-grid.four {
        grid-template-columns: 1fr 1fr !important;
    }

    #control-rail .mode-btn,
    #control-rail .buy-gem-btn {
        min-height: 26px !important;
        font-size: 8px !important;
        padding: 3px 4px !important;
    }
}
