:root {
    --bg-dark: #07080b;
    --card-bg: rgba(10, 11, 19, 0.78);
    --border-color: rgba(0, 243, 255, 0.15);
    --neon-purple: #7c3aed;
    --neon-pink: #ff007f;
    --neon-cyan: #00f3ff;
    --neon-green: #39ff14;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --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;
    touch-action: none;
}

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

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, #0e111d 0%, #030406 100%);
    touch-action: none;
}

#game-container {
    position: relative;
    width: 95vw;
    height: auto;
    max-height: 85vh;
    max-height: 85dvh;
    aspect-ratio: 4 / 3; /* Retronic arcade aspect ratio */
    max-width: min(900px, calc(85vh * 4 / 3));
    max-width: min(900px, calc(85dvh * 4 / 3));
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.85),
                0 0 35px rgba(0, 243, 255, 0.12);
    border: 1px solid rgba(0, 243, 255, 0.18);
    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%;
    z-index: 1;
    background-color: #050609;
}

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

.hud-item {
    background: rgba(7, 8, 14, 0.65);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.hud-btn {
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    pointer-events: auto;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.hud-btn:hover {
    background: rgba(0, 243, 255, 0.15);
    border-color: var(--neon-cyan);
    color: #fff;
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.4);
}

.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: 0.5px;
}

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

#score-val {
    color: #ffda00;
    text-shadow: 0 0 8px rgba(255, 218, 0, 0.3);
}

#level-val {
    color: var(--neon-cyan);
    text-shadow: 0 0 8px rgba(0, 243, 255, 0.3);
}

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

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

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 30px 40px;
    width: 90%;
    max-width: 460px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7),
                0 0 25px rgba(0, 243, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 15px;
    border-top: 1px solid rgba(0, 243, 255, 0.3);
}

.border-red {
    border-color: rgba(255, 0, 127, 0.35);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 25px rgba(255, 0, 127, 0.12);
    border-top: 1px solid rgba(255, 0, 127, 0.5);
}

.logo {
    font-family: var(--font-pixel);
    font-size: 26px;
    letter-spacing: 2px;
    color: #fff;
    text-shadow: 0 0 12px var(--neon-cyan), 0 0 20px var(--neon-purple);
    background: linear-gradient(to right, #00f3ff, #ff007f);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.story-box {
    background: rgba(124, 58, 237, 0.08);
    border: 1px solid rgba(124, 58, 237, 0.22);
    border-radius: 8px;
    padding: 12px 18px;
    font-size: 13px;
    line-height: 1.5;
    color: #cbd5e1;
    text-align: center;
    box-shadow: inset 0 0 10px rgba(124, 58, 237, 0.05);
}

.controls-card {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
}

.controls-header {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: var(--neon-cyan);
    margin-bottom: 2px;
}

.control-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    color: #cbd5e1;
}

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

.key, .key-wide {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-bottom: 2.5px solid rgba(0, 0, 0, 0.65);
    border-radius: 4px;
    padding: 2px 6px;
    font-weight: bold;
    color: #fff;
    font-size: 11px;
}
.key-wide {
    padding: 2px 8px;
    min-width: 24px;
    display: inline-block;
}

.btn {
    background: linear-gradient(135deg, var(--neon-purple) 0%, var(--neon-pink) 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-family: var(--font-sans);
    font-weight: bold;
    font-size: 15px;
    padding: 12px 24px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.35);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 20px rgba(124, 58, 237, 0.65);
}

.btn:active {
    transform: translateY(1px);
}

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

.btn-restart:hover {
    box-shadow: 0 0 20px rgba(255, 0, 127, 0.65);
}

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

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

.btn-back {
    background: rgba(255, 255, 255, 0.04);
    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.1);
    border-color: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.gameover-title {
    font-family: var(--font-pixel);
    font-size: 22px;
    color: var(--neon-pink);
    text-shadow: 0 0 12px rgba(255, 0, 127, 0.5);
    letter-spacing: 1px;
}

.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.35);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
}

.score-card span {
    color: var(--text-muted);
}

.score-card strong {
    font-family: var(--font-pixel);
    font-size: 15px;
    color: #fff;
}

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

/* Mobile Virtual Gamepad (Diagonal d-pad) */
#virtual-gamepad {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 15;
    display: flex;
    justify-content: center;
    width: auto;
}

#virtual-gamepad.hidden {
    display: none !important;
}

.diagonal-dpad {
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: auto;
}

.dpad-row {
    display: flex;
    gap: 15px;
}

.gamepad-btn {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: rgba(10, 11, 19, 0.7);
    border: 2px solid var(--border-color);
    color: var(--neon-cyan);
    font-family: var(--font-sans);
    font-size: 22px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6), 0 0 10px rgba(0, 243, 255, 0.2);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: transform 0.1s, border-color 0.1s, box-shadow 0.1s, background-color 0.1s, color 0.1s;
}

.gamepad-btn:active {
    transform: scale(0.9);
    background-color: rgba(0, 243, 255, 0.2);
    border-color: var(--neon-cyan);
    color: #fff;
    box-shadow: 0 0 18px rgba(0, 243, 255, 0.5);
}

/* Fallback Mobile responsive scaling overrides */
@media (max-width: 550px) {
    .logo {
        font-size: 20px;
    }
    .tagline {
        letter-spacing: 2px;
    }
    .hud-value {
        font-size: 11px;
    }
    .hud-item {
        padding: 6px 10px;
    }
    .card {
        padding: 20px;
        gap: 12px;
    }
    .gamepad-btn {
        width: 52px;
        height: 52px;
        font-size: 18px;
    }
}

/* Portrait aspect ratio overrides for mobile browsers */
@media (max-aspect-ratio: 1/1) {
    #game-container {
        width: 94vw;
        height: auto;
        aspect-ratio: 9 / 16;
        max-height: 82vh;
        max-height: 82dvh;
        max-width: min(460px, calc(82vh * 9 / 16));
        max-width: min(460px, calc(82dvh * 9 / 16));
    }
    #hud {
        padding: 0 15px;
        top: 10px;
    }
    .hud-item {
        padding: 4px 8px;
    }
    .hud-value {
        font-size: 10px;
    }
    .hud-label {
        font-size: 6px;
    }
    .card {
        padding: 18px;
        gap: 10px;
        max-height: 95%;
        overflow-y: auto;
    }
    .story-box {
        font-size: 11px;
        padding: 8px 12px;
        line-height: 1.4;
    }
    .logo {
        font-size: 18px;
    }
    .tagline {
        font-size: 8px;
    }
    .controls-card {
        font-size: 11px;
        padding: 8px;
        gap: 4px;
    }
    .control-row {
        gap: 4px;
    }
    #virtual-gamepad {
        bottom: 25px;
    }
    .gamepad-btn {
        width: 55px;
        height: 55px;
        font-size: 20px;
    }
}
