:root {
    --bg-dark: #030308;
    --card-bg: rgba(6, 6, 14, 0.92);
    --border-color: rgba(0, 243, 255, 0.25);
    --neon-purple: #bd00ff;
    --neon-pink: #ff0055;
    --neon-cyan: #00f3ff;
    --neon-green: #39ff14;
    --neon-yellow: #ffe600;
    --text-color: #f0f5ff;
    --text-muted: #737e96;
    --font-pixel: 'Press Start 2P', monospace;
    --font-sans: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
}

body {
    background-color: var(--bg-dark);
    color: var(--text-color);
    font-family: var(--font-sans);
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background: radial-gradient(circle at center, #0e0b1f 0%, #020205 100%);
    touch-action: none;
}

/* Main Container - locks aspect ratios to simulate physical cabinet */
#game-container {
    position: relative;
    width: 95vw;
    height: auto;
    max-height: 82vh;
    max-height: 82dvh;
    aspect-ratio: 16 / 9;
    max-width: min(1000px, calc(82vh * 16 / 9));
    max-width: min(1000px, calc(82dvh * 16 / 9));
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(189, 0, 255, 0.15),
                0 0 80px rgba(0, 243, 255, 0.1),
                inset 0 0 20px rgba(0, 243, 255, 0.15);
    border: 2px solid var(--border-color);
    touch-action: none;
}

#game-container:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: none !important;
}
#game-container:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: none !important;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #010103;
    z-index: 1;
}

#canvas-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Heads Up Display (HUD) */
#hud {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    padding: 0 30px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    z-index: 10;
}

.hud-item {
    background: rgba(4, 4, 10, 0.85);
    border: 1px solid rgba(0, 243, 255, 0.35);
    border-radius: 8px;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.5), 0 0 10px rgba(0, 243, 255, 0.15);
}

.hud-btn {
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    pointer-events: auto;
    transition: all 0.2s ease;
    border: 1px solid rgba(189, 0, 255, 0.35);
    box-shadow: 0 4px 15px rgba(0,0,0,0.5), 0 0 10px rgba(189, 0, 255, 0.15);
}

.hud-btn:hover {
    background: rgba(189, 0, 255, 0.25);
    border-color: var(--neon-purple);
    color: #fff;
    box-shadow: 0 0 15px rgba(189, 0, 255, 0.5);
    transform: translateY(-2px);
}

.hud-btn:active {
    transform: scale(0.92);
}

.hud-label {
    font-family: var(--font-pixel);
    font-size: 7px;
    color: var(--text-muted);
    margin-bottom: 5px;
    letter-spacing: 1px;
}

.hud-value {
    font-family: var(--font-pixel);
    font-size: 14px;
    color: #fff;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.35);
}

#score-val {
    color: var(--neon-cyan);
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.6);
}

#level-val {
    color: var(--neon-purple);
    text-shadow: 0 0 10px rgba(189, 0, 255, 0.6);
}

#lives-val {
    color: var(--neon-pink);
    text-shadow: 0 0 8px rgba(255, 0, 85, 0.5);
    letter-spacing: 2px;
}

#highscore-val {
    color: var(--neon-yellow);
    text-shadow: 0 0 10px rgba(255, 230, 0, 0.5);
}

/* Overlays and Cards */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(2, 2, 6, 0.82);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.card {
    background: var(--card-bg);
    border: 2px solid var(--neon-cyan);
    border-radius: 20px;
    padding: 35px 45px;
    width: 90%;
    max-width: 460px;
    text-align: center;
    box-shadow: 0 0 35px rgba(0, 243, 255, 0.2), 
                inset 0 0 15px rgba(0, 243, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 18px;
    animation: cardPulse 4s infinite alternate;
}

.border-red {
    border-color: var(--neon-pink);
    box-shadow: 0 0 35px rgba(255, 0, 85, 0.25), 
                inset 0 0 15px rgba(255, 0, 85, 0.1);
    animation: cardPulseRed 4s infinite alternate;
}

@keyframes cardPulse {
    0% { border-color: rgba(0, 243, 255, 0.4); box-shadow: 0 0 25px rgba(0, 243, 255, 0.15); }
    100% { border-color: rgba(0, 243, 255, 0.85); box-shadow: 0 0 45px rgba(0, 243, 255, 0.35); }
}

@keyframes cardPulseRed {
    0% { border-color: rgba(255, 0, 85, 0.4); box-shadow: 0 0 25px rgba(255, 0, 85, 0.15); }
    100% { border-color: rgba(255, 0, 85, 0.85); box-shadow: 0 0 45px rgba(255, 0, 85, 0.35); }
}

.logo {
    font-family: var(--font-pixel);
    font-size: 26px;
    letter-spacing: 2px;
    color: #fff;
    background: linear-gradient(to right, var(--neon-cyan), var(--neon-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 10px rgba(0, 243, 255, 0.5));
    text-shadow: none; /* overrides logo text-shadow for background-clip */
}

.gameover-title {
    font-family: var(--font-pixel);
    font-size: 22px;
    color: var(--neon-pink);
    filter: drop-shadow(0 0 8px rgba(255, 0, 85, 0.6));
    letter-spacing: 1px;
}

.tagline {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-top: 3px;
}

.controls-card {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 13px;
    text-align: left;
    line-height: 1.4;
}

.controls-card p {
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.key {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-bottom: 3px solid rgba(0, 0, 0, 0.6);
    border-radius: 6px;
    padding: 3px 8px;
    font-weight: bold;
    color: #fff;
    font-family: monospace;
    font-size: 12px;
}

.btn {
    background: linear-gradient(135deg, var(--neon-purple) 0%, var(--neon-pink) 100%);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-family: var(--font-sans);
    font-weight: bold;
    font-size: 15px;
    padding: 14px 28px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 0 15px rgba(189, 0, 255, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(189, 0, 255, 0.7), 0 0 10px rgba(0, 243, 255, 0.4);
}

.btn:active {
    transform: translateY(0);
}

.btn-restart {
    background: linear-gradient(135deg, var(--neon-pink) 0%, #ff5e00 100%);
    box-shadow: 0 0 15px rgba(255, 0, 85, 0.35);
}

.btn-restart:hover {
    box-shadow: 0 0 25px rgba(255, 0, 85, 0.7);
}

.btn-share {
    background: linear-gradient(135deg, var(--neon-cyan) 0%, var(--neon-purple) 100%);
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.3);
}

.btn-share:hover {
    box-shadow: 0 0 25px rgba(0, 243, 255, 0.7);
}

.btn-back {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-color);
    box-shadow: none;
    text-decoration: none;
    display: inline-block;
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.25);
    color: #fff;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.08);
}

.gameover-desc {
    font-size: 14px;
    color: var(--text-muted);
}

.scores-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.score-card {
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 13px;
}

.score-card span {
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.5px;
}

.score-card strong {
    font-family: var(--font-pixel);
    font-size: 18px;
    color: var(--neon-cyan);
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.4);
}

#card-final-best strong {
    color: var(--neon-yellow);
    text-shadow: 0 0 10px rgba(255, 230, 0, 0.4);
}

.stats-footer {
    font-size: 11px;
    color: var(--text-muted);
}

.story-box {
    background: rgba(0, 243, 255, 0.03);
    border: 1px solid rgba(0, 243, 255, 0.18);
    border-radius: 10px;
    padding: 15px;
    font-size: 13px;
    line-height: 1.5;
    color: #cbd5e1;
    text-align: left;
    box-shadow: inset 0 0 12px rgba(0, 243, 255, 0.05);
}

/* Fallback Mobile responsive scaling overrides */
@media (max-width: 550px) {
    .logo {
        font-size: 20px;
    }
    .hud-value {
        font-size: 11px;
    }
    .card {
        padding: 25px 20px;
        gap: 14px;
    }
}

/* Portrait aspect ratio overrides for mobile browsers */
@media (max-aspect-ratio: 1/1) {
    #game-container {
        width: 92vw;
        height: auto;
        aspect-ratio: 9 / 16;
        max-height: 80vh;
        max-height: 80dvh;
        max-width: min(480px, calc(80vh * 9 / 16));
        max-width: min(480px, calc(80dvh * 9 / 16));
    }
    #hud {
        padding: 0 15px;
        top: 15px;
    }
    .hud-item {
        padding: 6px 10px;
    }
    .hud-value {
        font-size: 10px;
    }
    .hud-label {
        font-size: 6px;
    }
    .card {
        padding: 20px 22px;
        gap: 12px;
        max-height: 95%;
        overflow-y: auto;
    }
    .story-box {
        font-size: 11px;
        padding: 10px 12px;
        line-height: 1.45;
    }
    .logo {
        font-size: 20px;
    }
    .tagline {
        font-size: 8px;
    }
    .controls-card {
        font-size: 11px;
        padding: 10px 12px;
        gap: 6px;
    }
}
