:root {
    --neon-blue: #00f2ff;
    --neon-pink: #ff007b;
    --bg-dark: #020205;
    --danger: #ff244d;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    min-height: var(--app-height, 100vh);
    overflow: hidden;
    background: var(--bg-dark);
    font-family: 'Orbitron', sans-serif;
    color: #fff;
    user-select: none;
}

body {
    display: flex;
    flex-direction: column;
}

#game-container { position: relative; width: var(--app-width, 100vw); height: calc(var(--app-height, 100vh) - 64px); overflow: hidden; transition: height 220ms ease, width 220ms ease; }
body.app-initializing #game-container {
    transition: none;
}
canvas { display: block; position: relative; z-index: 1; background: transparent; }
canvas { touch-action: none; }
.hidden { display: none !important; }

#share-bar {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-top: 1px solid #1a242c;
    background: #05080d;
    padding: 0 12px;
    transition: transform 220ms ease, opacity 220ms ease;
}

body.web-share-hidden #game-container {
    height: var(--app-height, 100vh);
}

body.web-share-hidden #share-bar {
    display: none;
}


body.mobile-landscape-game-active #game-container {
    height: var(--app-height, 100vh);
    width: var(--app-width, 100vw);
}

body.mobile-landscape-game-active #share-bar {
    display: none;
}

body.mobile-landscape-game-active #in-game-branding,
body.mobile-landscape-game-active #hud .hud-top {
    display: none;
}

body.mobile-landscape-game-active #hud {
    padding: 8px 12px;
}

body.mobile-landscape-game-active #hud .progress-wrapper {
    margin-top: 0;
}

#share-btn {
    border: 2px solid var(--neon-blue);
    background: transparent;
    color: var(--neon-blue);
    padding: 10px 16px;
    font-family: inherit;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    touch-action: manipulation;
}

#share-btn:hover {
    background: rgba(0, 242, 255, 0.15);
}

#share-status {
    color: #a4fcff;
    font-size: 0.82rem;
    min-width: 120px;
}

#bg-3d { position: absolute; width: 100%; height: 100%; perspective: 800px; z-index: -1; }
#bg-3d::after {
    content: '';
    position: absolute;
    width: 200%;
    height: 100%;
    top: 80%;
    left: -50%;
    background-image: linear-gradient(var(--neon-blue) 1px, transparent 1px), linear-gradient(90deg, var(--neon-blue) 1px, transparent 1px);
    background-size: 60px 60px;
    opacity: 0.14;
    transform: rotateX(75deg);
    animation: moveGrid 1.4s linear infinite;
}
@keyframes moveGrid {
    from { transform: rotateX(75deg) translateY(0); }
    to { transform: rotateX(75deg) translateY(60px); }
}

#world-branding {
    position: absolute;
    width: 100%;
    top: 14%;
    text-align: center;
    pointer-events: none;
    z-index: 0;
}
.bg-title {
    font-size: clamp(3rem, 10vw, 8rem);
    margin: 0;
    opacity: 0.08;
    color: var(--neon-blue);
    letter-spacing: clamp(8px, 2vw, 18px);
}
.bg-subtitle {
    font-size: clamp(0.9rem, 2vw, 1.4rem);
    margin: 0;
    opacity: 0.16;
    letter-spacing: 8px;
}

#in-game-branding {
    position: absolute;
    top: clamp(86px, 14vh, 140px);
    width: 100%;
    text-align: center;
    pointer-events: none;
    z-index: 2;
}
#in-game-branding h1 {
    margin: 0;
    font-size: clamp(1.8rem, 6vw, 3rem);
    color: rgba(0, 242, 255, 0.48);
    text-shadow: 0 0 8px rgba(0, 242, 255, 0.18);
    letter-spacing: 6px;
}
#in-game-branding h2 {
    margin: 2px 0 0;
    font-size: clamp(0.72rem, 1.8vw, 1rem);
    color: rgba(170, 250, 255, 0.72);
    font-weight: 700;
    letter-spacing: 2px;
}

#hud {
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    padding: 26px;
    z-index: 5;
    pointer-events: none;
}
.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    font-size: clamp(0.8rem, 2vw, 1.1rem);
}
#timer-display, #currency-display { color: var(--neon-blue); }
#level-coins-display {
    color: #ffe574;
    font-size: 0.85em;
}
#streak-display {
    color: #ff7df3;
    margin-left: auto;
    text-align: right;
}
#currency-display {
    text-align: right;
}
#stats-info {
    pointer-events: auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(0, 242, 255, 0.7);
    display: grid;
    place-items: center;
    color: #b9faff;
    background: rgba(0, 242, 255, 0.12);
    font-weight: 900;
    cursor: default;
    position: relative;
}
#stats-tooltip {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    padding: 10px;
    border: 1px solid rgba(0, 242, 255, 0.5);
    background: rgba(2, 7, 12, 0.97);
    color: #d2feff;
    font-size: 0.7rem;
    display: grid;
    gap: 4px;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 140ms ease, transform 140ms ease;
    pointer-events: none;
}
#stats-info:hover #stats-tooltip,
#stats-info:focus-within #stats-tooltip,
#stats-info:focus #stats-tooltip {
    opacity: 1;
    transform: translateY(0);
}
#audio-toggle {
    pointer-events: auto;
    border: 1px solid #52e9ff;
    background: rgba(0, 242, 255, 0.12);
    color: #baf8ff;
    font-family: inherit;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 7px 12px;
    cursor: pointer;
}
#audio-toggle:hover {
    background: rgba(0, 242, 255, 0.25);
}
.progress-wrapper { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
#progress-bar {
    flex: 1;
    height: 10px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    border: 1px solid #1d1d1d;
    overflow: hidden;
}
#progress-fill { height: 100%; width: 0%; background: var(--neon-blue); box-shadow: 0 0 14px var(--neon-blue); }
#progress-percent { min-width: 54px; text-align: right; color: var(--neon-blue); font-weight: 900; }

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}
#start-overlay {
    opacity: 0;
    transition: opacity 320ms ease;
}
#start-overlay.ready {
    opacity: 1;
}
#start-overlay.fade-out {
    opacity: 0;
}

#store-confirm-prompt {
    z-index: 12;
}

.menu-content-wrapper {
    width: min(1150px, 94vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.neon-text { margin: 0; font-size: clamp(2.5rem, 8vw, 5rem); text-shadow: 0 0 16px var(--neon-blue); }
.start-screen-content {
    display: grid;
    place-items: center;
    gap: 10px;
    text-align: center;
    width: min(95vw, 1180px);
}
.start-logo {
    width: clamp(320px, 78vw, 1180px);
    max-width: 100%;
    height: auto;
    filter: drop-shadow(0 0 18px rgba(0, 242, 255, 0.48)) drop-shadow(0 0 28px rgba(255, 0, 123, 0.28));
}
.tap-to-start {
    margin: 2px 0 0;
    letter-spacing: 4px;
    color: #d5f7ff;
    font-size: clamp(1.1rem, 3.2vw, 1.6rem);
    font-weight: 800;
    animation: pulseTap 1.4s ease-in-out infinite;
}
.start-best-score {
    margin: 0;
    font-size: 0.95rem;
    color: #9ee7f2;
}
.install-btn {
    margin-top: 6px;
    border: 1px solid #55f4ff;
    background: rgba(0, 242, 255, 0.15);
    color: #d3fdff;
    padding: 10px 16px;
    font-family: inherit;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
}
.install-btn:hover {
    background: rgba(0, 242, 255, 0.25);
}
@keyframes pulseTap {
    0%, 100% { opacity: 0.55; text-shadow: 0 0 0 rgba(0, 242, 255, 0); }
    50% { opacity: 1; text-shadow: 0 0 12px rgba(0, 242, 255, 0.85); }
}
.menu-logo {
    width: clamp(220px, 58vw, 760px);
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    filter: drop-shadow(0 0 10px rgba(0, 242, 255, 0.32));
}
.unlock-note { margin: 8px 0 20px; color: #9ba3a8; font-size: 0.9rem; }

.menu-tabs { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-bottom: 16px; }
.main-btn {
    border: 2px solid var(--neon-pink);
    background: transparent;
    color: #fff;
    padding: 12px 22px;
    font-family: inherit;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    touch-action: manipulation;
}
.main-btn.active,
.main-btn:hover { background: var(--neon-pink); color: #000; box-shadow: 0 0 18px var(--neon-pink); }

.panel {
    width: 100%;
    height: min(62vh, 560px);
    overflow: auto;
    border: 1px solid #202a30;
    border-radius: 14px;
    background: rgba(4, 6, 10, 0.9);
    padding: 20px;
}

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 14px; }
.level-btn {
    aspect-ratio: 1/1;
    border: 2px solid #323b43;
    background: rgba(255, 255, 255, 0.03);
    color: #6d7680;
    cursor: not-allowed;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-family: inherit;
    position: relative;
}
.level-btn.unlocked { border-color: var(--neon-blue); color: #fff; cursor: pointer; }
.level-btn.unlocked:hover { background: rgba(0, 242, 255, 0.2); }
.level-btn.completed { border-color: #3cff5f; }
.level-num { font-size: 1.5rem; font-weight: 900; }
.level-prog { font-size: 0.7rem; }
.level-info {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid rgba(0, 242, 255, 0.6);
    background: rgba(0, 242, 255, 0.14);
    color: #d1fdff;
    font-size: 0.65rem;
    font-weight: 900;
    display: grid;
    place-items: center;
    line-height: 1;
}
.level-info-tooltip {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 135px;
    border: 1px solid rgba(0, 242, 255, 0.5);
    background: rgba(2, 7, 12, 0.97);
    color: #d2feff;
    font-size: 0.62rem;
    display: grid;
    gap: 2px;
    padding: 6px 8px;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 140ms ease, transform 140ms ease;
    pointer-events: none;
    text-align: left;
    z-index: 2;
}
.level-info:hover .level-info-tooltip,
.level-info:focus .level-info-tooltip,
.level-info:focus-within .level-info-tooltip {
    opacity: 1;
    transform: translateY(0);
}
.level-coins {
    display: flex;
    gap: 4px;
    min-height: 16px;
    align-items: center;
}
.coin-icon {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(255, 255, 255, 0.45);
}
.coin-icon.filled {
    background: #ffd700;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.9);
    border-color: #fff2a8;
}
.coin-icon.shadow {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.24);
}

.store-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    position: sticky;
    top: -20px;
    z-index: 1;
    padding: 10px 0;
    background: rgba(4, 6, 10, 0.95);
}
.balance-tag { margin-bottom: 0; color: var(--neon-blue); }
.total-balance {
    font-weight: 700;
    color: #bff9ff;
}
.skin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.skin-card { border: 1px solid #2a3238; background: rgba(255, 255, 255, 0.03); padding: 12px; text-align: center; cursor: pointer; }
.skin-card.active { border-color: var(--neon-blue); box-shadow: 0 0 16px rgba(0, 242, 255, 0.2); }
.skin-card.locked-mystery { border-color: rgba(57, 255, 20, 0.65); box-shadow: inset 0 0 14px rgba(57, 255, 20, 0.16); cursor: default; }
.skin-preview { position: relative; display: grid; place-items: center; overflow: hidden; }
.legendary-crown {
    position: absolute;
    top: -22px;
    font-size: 30px;
    color: #ffe87d;
    text-shadow: 0 0 10px rgba(255, 232, 125, 1), 0 0 18px rgba(255, 171, 36, 0.92), 0 0 26px rgba(255, 130, 0, 0.8);
    animation: legendaryCrownPulse 1.1s ease-in-out infinite;
}
.skin-preview-mystery {
    border-color: #39ff14 !important;
    box-shadow: 0 0 18px rgba(57, 255, 20, 0.85) !important;
}
.mystery-question {
    font-size: 26px;
    font-weight: 900;
    color: #39ff14;
    text-shadow: 0 0 10px rgba(57, 255, 20, 0.95), 0 0 18px rgba(57, 255, 20, 0.75);
}

@keyframes legendaryCrownPulse {
    0%, 100% {
        transform: scale(0.95) translateY(0);
    }
    50% {
        transform: scale(1.08) translateY(-2px);
    }
}

.store-subtabs {
    display: flex;
    gap: 10px;
    margin: 0 0 14px;
}

.store-tab {
    border: 1px solid #3f4c56;
    background: rgba(255, 255, 255, 0.03);
    color: #b7c8d3;
    padding: 9px 14px;
    font-family: inherit;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
}

.store-tab.active,
.store-tab:hover {
    border-color: #57efff;
    color: #d6fdff;
    background: rgba(0, 242, 255, 0.12);
    box-shadow: 0 0 14px rgba(0, 242, 255, 0.28);
}

.store-message {
    border: 1px solid rgba(151, 164, 171, 0.35);
    background: rgba(255, 255, 255, 0.03);
    color: #d1d9de;
    text-align: center;
    padding: 34px 18px;
    font-weight: 700;
    letter-spacing: 1px;
}

.leaderboard-list { display: grid; gap: 10px; margin-top: 14px; }
.board-entry {
    display: grid;
    grid-template-columns: minmax(96px, auto) 1fr auto auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid rgba(0, 242, 255, 0.45);
    background: linear-gradient(135deg, rgba(0, 242, 255, 0.14), rgba(255, 0, 123, 0.08));
    box-shadow: inset 0 0 12px rgba(0, 242, 255, 0.1), 0 0 12px rgba(0, 242, 255, 0.18);
}
.board-entry.is-top-rank {
    border-color: rgba(255, 233, 117, 0.9);
    box-shadow: inset 0 0 14px rgba(255, 233, 117, 0.2), 0 0 18px rgba(255, 233, 117, 0.34);
}
.board-empty {
    grid-template-columns: 1fr;
    color: #b7ccd2;
    text-align: center;
}
.board-rank {
    color: #baf8ff;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.board-top-star {
    color: #ffe975;
    text-shadow: 0 0 8px rgba(255, 233, 117, 0.95), 0 0 14px rgba(255, 233, 117, 0.6);
}
.board-name {
    color: #ffffff;
    letter-spacing: 1px;
    font-weight: 700;
}
.board-score {
    color: var(--neon-blue);
    font-weight: 700;
}
.board-meta {
    color: #9ee7f2;
    font-size: 0.85rem;
}
.dreamloLBTable {
    border-collapse: collapse;
    text-align: center;
    width: min(100%, 560px);
    margin: 8px auto 0;
}
.dreamloLBTable th {
    border-bottom: 1px solid #EEEEEE;
    font-weight: bold;
    margin: 0;
    padding: 6px;
}
.dreamloLBTable td {
    border-bottom: 1px solid #EEEEEE;
    margin: 0;
    padding: 6px;
}
.lb-row {
    display: grid;
    grid-template-columns: 50px 1fr auto;
    gap: 10px;
    border-bottom: 1px solid #1f272d;
    padding: 8px 4px;
    color: #dbfeff;
}
.lb-score { color: var(--neon-blue); }
.board-status { color: #9eb4bb; }
.board-error {
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 117, 117, 0.4);
    background: rgba(255, 70, 70, 0.12);
    color: #ffb3b3;
    font-size: 0.82rem;
    line-height: 1.4;
}

.prompt-box { background: #06070b; border: 2px solid var(--neon-pink); padding: 26px; width: min(430px, 90vw); text-align: center; }
.prompt-box h2 { margin-top: 0; }
.prompt-btns { display: flex; gap: 8px; justify-content: center; }
.prompt-btns button, .record-box button, .death-box > button {
    border: 1px solid #fff;
    background: transparent;
    color: #fff;
    padding: 8px 14px;
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
}
.record-box { margin: 14px 0; display: flex; gap: 8px; justify-content: center; }
.record-box input {
    width: 80px;
    text-align: center;
    text-transform: uppercase;
    font-family: inherit;
    background: #10151b;
    border: 1px solid #3a4952;
    color: #fff;
}
#record-save-status {
    min-height: 1.2em;
    margin: -4px 0 12px;
    font-size: 0.8rem;
    color: #9dffcf;
}
.record-box button:disabled {
    opacity: 0.55;
    cursor: wait;
}
#death-time { font-size: 2rem; color: var(--neon-blue); margin: 6px 0 12px; }


.level-complete-box {
    border-color: #39ff88;
    box-shadow: 0 0 28px rgba(57, 255, 136, 0.35), inset 0 0 18px rgba(57, 255, 136, 0.12);
}

.level-complete-box h2 {
    color: #39ff88;
    text-shadow: 0 0 10px rgba(57, 255, 136, 0.85);
}

#level-complete-reward {
    margin: 12px 0 16px;
    font-size: 1.25rem;
    color: var(--neon-blue);
    text-shadow: 0 0 10px rgba(0, 242, 255, 0.8);
}
#level-bonus-reward {
    margin: -8px 0 12px;
    font-size: 0.95rem;
    color: #66ffad;
    text-shadow: 0 0 10px rgba(102, 255, 173, 0.6);
}
#level-coin-summary {
    margin-bottom: 12px;
    font-size: 0.85rem;
    color: #d1dbdf;
}
.level-run-stats {
    margin-bottom: 10px;
    padding: 8px 10px;
    border: 1px solid rgba(130, 246, 190, 0.45);
    background: rgba(57, 255, 136, 0.08);
    color: #c9ffe2;
    display: grid;
    gap: 4px;
    text-align: left;
}
.coin-summary-icons {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 7px 0;
}
.coin-summary-note {
    color: #a6bac0;
}

@media (max-width: 720px) {
    body.mobile-game-active #game-container {
        height: var(--app-height, 100vh);
    }
    #hud {
        padding: 16px 14px 12px;
    }
    .hud-top {
        gap: 6px 10px;
        font-size: 0.75rem;
        align-items: flex-start;
    }
    #streak-display,
    #currency-display {
        margin-left: 0;
        text-align: left;
    }
    #timer-display,
    #level-coins-display,
    #streak-display,
    #currency-display {
        padding: 3px 7px;
        border-radius: 8px;
        background: rgba(4, 12, 18, 0.72);
        border: 1px solid rgba(94, 217, 233, 0.2);
    }
    #stats-info {
        display: none;
    }
    body.mobile-game-active #share-bar {
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
    }
    #hud .progress-wrapper {
        transition: transform 220ms ease, opacity 220ms ease, max-height 220ms ease, margin-top 220ms ease;
        max-height: 30px;
        overflow: hidden;
    }
    body.mobile-game-active #hud .progress-wrapper {
        transform: translateY(-10px);
        opacity: 0;
        max-height: 0;
        margin-top: 0;
        pointer-events: none;
    }
    .hud-top { flex-wrap: wrap; }
    #audio-toggle { width: 100%; }
    #in-game-branding {
        top: clamp(96px, 18vh, 170px);
    }
    .panel {
        height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }
    #menu-overlay,
    .menu-content-wrapper {
        touch-action: pan-y;
    }

    .menu-content-wrapper {
        width: min(100%, 96vw);
        max-height: calc(var(--app-height, 100vh) - 20px);
    }
    .menu-logo {
        width: clamp(200px, 84vw, 520px);
    }
    .menu-tabs {
        width: 100%;
        gap: 8px;
    }
    .main-btn {
        flex: 1;
        min-width: 0;
        padding: 12px 10px;
        font-size: 0.76rem;
        letter-spacing: 1px;
    }
    .panel {
        height: 56vh;
        padding: 14px;
    }
    .prompt-box {
        padding: 18px 14px;
        width: min(430px, 94vw);
    }
    .prompt-btns {
        flex-direction: column;
    }
    .prompt-btns button,
    .record-box button,
    .death-box > button {
        width: 100%;
    }
    .record-box {
        flex-direction: column;
        align-items: center;
    }
    .record-box input {
        width: min(170px, 100%);
        min-height: 40px;
    }
    .board-entry {
        grid-template-columns: 1fr;
        gap: 4px;
        text-align: left;
    }
    .board-rank {
        font-size: 0.85rem;
    }
    .board-score,
    .board-meta {
        font-size: 0.82rem;
    }
    #share-bar {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}


@media (max-width: 1024px) and (orientation: landscape) {
    html,
    body {
        width: 100vw;
        max-width: 100vw;
    }

    #game-container {
        width: 100vw;
        max-width: 100vw;
    }

    body.mobile-landscape-game-active #hud #progress-bar {
        height: 8px;
    }

    body.mobile-landscape-game-active #hud #progress-percent {
        min-width: 42px;
        font-size: 0.9rem;
    }
}
