:root {
    --bg-dark: #080202;
    --card-bg: rgba(18, 5, 5, 0.88);
    --border-color: rgba(255, 50, 50, 0.15);
    --neon-red: #ff3333;
    --neon-orange: #ff6600;
    --neon-purple: #a824e6;
    --text-color: #f3e9e9;
    --text-muted: #9a8b8b;
    --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;
}

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

#game-container {
    position: relative;
    width: 95vw;
    height: auto;
    max-height: 85vh;
    max-height: 85dvh;
    aspect-ratio: 16 / 9;
    max-width: min(1100px, calc(85vh * 16 / 9));
    max-width: min(1100px, calc(85dvh * 16 / 9));
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 20px 80px rgba(0, 0, 0, 0.9),
                0 0 40px rgba(255, 51, 51, 0.15);
    border: 1px solid rgba(255, 51, 51, 0.1);
    touch-action: none;
    background-color: #000;
}

#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;
}

#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* HUD Top Controls Overlay */
#hud-top {
    position: absolute;
    top: 12px;
    left: 0;
    width: 100%;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 10;
}

.top-item {
    background: rgba(10, 5, 5, 0.7);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.top-label {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.top-value {
    font-family: var(--font-pixel);
    font-size: 11px;
    color: var(--neon-red);
    text-shadow: 0 0 5px rgba(255, 51, 51, 0.5);
}

.top-group {
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.top-btn {
    background: rgba(10, 5, 5, 0.7);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 36px;
    height: 36px;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.top-btn:hover {
    background: rgba(255, 51, 51, 0.25);
    border-color: var(--neon-red);
    color: #fff;
}

.top-btn:active {
    transform: scale(0.95);
}

.hidden {
    display: none !important;
}

/* Mobile Touch Controls */
#mobile-controls {
    position: absolute;
    bottom: 95px; /* Sits above the classic canvas HUD */
    left: 0;
    width: 100%;
    height: 160px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 24px;
    pointer-events: none;
    z-index: 9;
}

#joystick-container {
    width: 120px;
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
}

#joystick-ring {
    width: 100px;
    height: 100px;
    background: rgba(15, 5, 5, 0.5);
    border: 2px solid rgba(255, 51, 51, 0.35);
    border-radius: 50%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

#joystick-dot {
    width: 44px;
    height: 44px;
    background: var(--neon-red);
    background: radial-gradient(circle, #ff6666 0%, #cc0000 100%);
    border-radius: 50%;
    position: absolute;
    box-shadow: 0 4px 10px rgba(0,0,0,0.6), 0 0 10px var(--neon-red);
    cursor: pointer;
    touch-action: none;
}

#action-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-end;
    pointer-events: auto;
}

.action-row {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.circle-btn {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: rgba(15, 5, 5, 0.65);
    border: 2px solid rgba(255, 51, 51, 0.35);
    color: #fff;
    font-family: var(--font-pixel);
    font-size: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.6);
    transition: transform 0.1s, background-color 0.1s;
}

.circle-btn:active {
    transform: scale(0.9);
    background: rgba(255, 51, 51, 0.35);
    border-color: var(--neon-red);
}

.small-btn {
    width: 42px;
    height: 42px;
    font-size: 10px;
}

.fire-btn {
    width: 76px;
    height: 54px;
    border-radius: 27px;
    background: radial-gradient(circle at center, #ff5500 0%, #aa0000 100%);
    border: 2px solid #ff6600;
    color: #fff;
    font-family: var(--font-pixel);
    font-size: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.6), 0 0 8px rgba(255, 85, 0, 0.5);
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    transition: transform 0.1s;
}

.fire-btn:active {
    transform: scale(0.9);
    background: radial-gradient(circle at center, #ff8800 0%, #d40000 100%);
    box-shadow: 0 2px 4px rgba(0,0,0,0.6), 0 0 15px rgba(255, 85, 0, 0.9);
}

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

.menu-card {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    width: 90%;
    max-width: 680px;
    padding: 24px 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8),
                0 0 25px rgba(255, 51, 51, 0.1);
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    text-align: center;
    animation: zoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.border-crimson {
    border-color: var(--neon-red);
    box-shadow: 0 10px 40px rgba(0,0,0,0.8),
                0 0 35px rgba(255, 0, 0, 0.25);
}

.menu-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.title-logo {
    font-family: var(--font-pixel);
    font-size: 44px;
    color: var(--neon-red);
    letter-spacing: 4px;
    text-shadow: 0 0 15px rgba(255, 0, 0, 0.8),
                 0 5px 0 #660000;
    margin-bottom: 2px;
    animation: titlePulse 2s infinite ease-in-out;
}

.subtitle {
    font-family: var(--font-pixel);
    font-size: 11px;
    color: var(--neon-orange);
    letter-spacing: 3px;
    text-shadow: 0 0 8px rgba(255, 102, 0, 0.6);
}

.menu-story {
    font-size: 13.5px;
    line-height: 1.6;
    color: #e2d7d7;
    max-width: 560px;
    background: rgba(0, 0, 0, 0.4);
    padding: 12px 18px;
    border-radius: 4px;
    border-left: 3px solid var(--neon-red);
    text-align: justify;
}

.menu-controls-guide {
    display: flex;
    width: 100%;
    gap: 20px;
    margin-top: 5px;
}

.control-column {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.03);
    text-align: left;
}

.control-column h3 {
    font-family: var(--font-pixel);
    font-size: 9px;
    color: var(--neon-orange);
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-bottom: 4px;
}

.control-column p {
    font-size: 11.5px;
    margin-bottom: 6px;
    color: #cdc1c1;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.key-cap {
    background: #2a2020;
    border: 1px solid #4a3838;
    border-bottom: 2px solid #5a4040;
    border-radius: 3px;
    padding: 1px 5px;
    font-family: var(--font-pixel);
    font-size: 7.5px;
    color: #fff;
    margin-right: 2px;
    display: inline-block;
}

.glow-button {
    font-family: var(--font-pixel);
    font-size: 14px;
    color: #fff;
    background: radial-gradient(circle, #ff3333 0%, #aa0000 100%);
    border: 2px solid #ff5555;
    border-radius: 4px;
    padding: 12px 36px;
    cursor: pointer;
    outline: none;
    box-shadow: 0 0 15px rgba(255, 51, 51, 0.4), 0 4px 8px rgba(0,0,0,0.5);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
    transition: transform 0.15s, box-shadow 0.15s;
    letter-spacing: 1px;
}

.glow-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(255, 51, 51, 0.7), 0 6px 12px rgba(0,0,0,0.6);
}

.glow-button:active {
    transform: translateY(1px);
    box-shadow: 0 0 10px rgba(255, 51, 51, 0.5), 0 2px 4px rgba(0,0,0,0.6);
}

.crimson-button {
    background: radial-gradient(circle, #db0a0a 0%, #7d0000 100%);
    border-color: var(--neon-red);
}

.gray-button {
    background: radial-gradient(circle, #4b5563 0%, #1f2937 100%);
    border-color: #6b7280;
    box-shadow: 0 0 10px rgba(75, 85, 99, 0.3), 0 4px 8px rgba(0,0,0,0.5);
}
.gray-button:hover {
    box-shadow: 0 0 20px rgba(75, 85, 99, 0.6), 0 6px 12px rgba(0,0,0,0.6);
}

.menu-footer {
    font-family: var(--font-pixel);
    font-size: 7.5px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* Game Over Overlay Specifics */
.gameover-title {
    font-family: var(--font-pixel);
    font-size: 38px;
    color: var(--neon-red);
    letter-spacing: 3px;
    text-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
    margin-bottom: 2px;
}

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

.scores-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 460px;
    margin: 8px 0;
}

.stat-box {
    background: rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 4px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-label {
    font-family: var(--font-pixel);
    font-size: 7.5px;
    color: var(--text-muted);
}

.stat-val {
    font-family: var(--font-pixel);
    font-size: 16px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.text-yellow { color: #ffcc00; text-shadow: 0 0 8px rgba(255,204,0,0.3); }
.text-red { color: var(--neon-red); text-shadow: 0 0 8px rgba(255,51,51,0.3); }
.text-purple { color: #cc66ff; text-shadow: 0 0 8px rgba(204,102,255,0.3); }
.text-blue { color: #00d2ff; text-shadow: 0 0 8px rgba(0,210,255,0.3); }

/* Animations */
@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.85);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes titlePulse {
    0%, 100% {
        text-shadow: 0 0 15px rgba(255, 0, 0, 0.8), 0 5px 0 #660000;
    }
    50% {
        text-shadow: 0 0 28px rgba(255, 0, 0, 1.0), 0 5px 0 #880000;
        color: #ff5555;
    }
}

/* Responsiveness adjustments for smaller devices */
@media (max-width: 600px) {
    .menu-card {
        padding: 16px 20px;
        gap: 12px;
    }
    
    .title-logo {
        font-size: 30px;
    }
    
    .menu-story {
        font-size: 12px;
        padding: 8px 12px;
    }
    
    .menu-controls-guide {
        flex-direction: column;
        gap: 10px;
    }
    
    .control-column {
        padding: 8px;
    }
    
    .scores-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .stat-val {
        font-size: 13px;
    }
    
    .glow-button {
        padding: 10px 24px;
        font-size: 11px;
    }
    
    #mobile-controls {
        padding: 0 12px;
        bottom: 80px;
    }
}
