/* CSS Variables */
:root {
    --arcade-cyan: #00f0ff;
    --arcade-magenta: #ff006e;
    --arcade-yellow: #ffbe0b;
    --arcade-green: #00ff41;
    --dark-bg: #0a0e27;
    --darker-bg: #050714;
    --panel-bg: rgba(20, 28, 50, 0.85);
    --border-glow: rgba(0, 240, 255, 0.5);
    --text-primary: #ffffff;
    --text-secondary: #a0aec0;
}

/* Reset & Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: linear-gradient(135deg, var(--darker-bg) 0%, #1a1f3a 100%);
    color: var(--text-primary);
    font-family: 'Orbitron', sans-serif;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Animated Background Grid */
body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 240, 255, 0.03) 2px, rgba(0, 240, 255, 0.03) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0, 240, 255, 0.03) 2px, rgba(0, 240, 255, 0.03) 4px);
    pointer-events: none;
    z-index: 0;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1;
}

/* Header Section */
.game-header {
    margin-bottom: 20px;
    text-align: center;
}

.game-title {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    color: var(--arcade-cyan);
    text-shadow:
        0 0 10px var(--arcade-cyan),
        0 0 20px var(--arcade-cyan);
    letter-spacing: 4px;
    animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {

    0%,
    100% {
        opacity: 1;
        text-shadow: 0 0 10px var(--arcade-cyan);
    }

    50% {
        opacity: 0.8;
        text-shadow: 0 0 25px var(--arcade-cyan);
    }
}

/* Score HUD */
.score-panel {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
}

.score-item {
    background: var(--panel-bg);
    padding: 10px 20px;
    border-radius: 8px;
    border: 2px solid var(--arcade-cyan);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
    text-align: center;
    min-width: 120px;
}

.score-label {
    font-size: 0.6rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.score-value {
    font-family: 'Press Start 2P', cursive;
    font-size: 1.2rem;
    color: var(--arcade-cyan);
}

/* Game Board */
#game-board {
    background: var(--darker-bg);
    background-image:
        linear-gradient(rgba(0, 240, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 240, 255, 0.05) 1px, transparent 1px);
    display: grid;
    border: 4px solid var(--arcade-cyan);
    border-radius: 4px;
    box-shadow: 0 0 40px rgba(0, 240, 255, 0.3);
    position: relative;
    overflow: visible;
    /* Allow particles to fly out */
}

/* Overlay System */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 7, 20, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.4s ease;
}

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

/* Menu Card */
.menu-card {
    background: linear-gradient(145deg, rgba(20, 28, 50, 0.98) 0%, rgba(10, 14, 39, 0.98) 100%);
    border: 3px solid var(--arcade-cyan);
    padding: 50px 40px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 0 60px rgba(0, 240, 255, 0.4);
    max-width: 450px;
    width: 90%;
}

.menu-card h1 {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(1.5rem, 8vw, 2.5rem);
    color: var(--arcade-cyan);
    text-shadow: 0 0 20px var(--arcade-cyan);
    margin-bottom: 20px;
}

/* Buttons */
.btn {
    padding: 15px 30px;
    border-radius: 8px;
    border: 2px solid var(--arcade-cyan);
    background: transparent;
    color: var(--arcade-cyan);
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    margin-bottom: 10px;
}

.btn:hover {
    background: rgba(0, 240, 255, 0.1);
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.4);
    transform: translateY(-2px);
}

.btn.active {
    background: var(--arcade-cyan);
    color: var(--darker-bg);
    box-shadow: 0 0 25px var(--arcade-cyan);
}

.btn-primary {
    background: var(--arcade-cyan);
    color: var(--darker-bg);
    font-size: 1.1rem;
    margin-top: 15px;
    padding: 20px;
}

.mode-selector {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
}

/* Snake & Game Elements */
.snake-head {
    background: radial-gradient(circle at 30% 30%, var(--arcade-green), #00a020);
    border-radius: 50%;
    box-shadow: 0 0 15px var(--arcade-green);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.snake {
    background: linear-gradient(135deg, #00ff41 0%, #00cc35 100%);
    border-radius: 35%;
    transform: scale(0.9);
}

.food {
    background: radial-gradient(circle at 30% 30%, #ff4d79, var(--arcade-magenta));
    border-radius: 50%;
    box-shadow: 0 0 15px var(--arcade-magenta);
    animation: foodPulse 1s ease-in-out infinite;
}

.food-gold {
    background: radial-gradient(circle at 30% 30%, #ffd700, var(--arcade-yellow));
    border-radius: 50%;
    box-shadow: 0 0 25px var(--arcade-yellow);
    animation: goldPulse 0.5s ease-in-out infinite;
}

@keyframes foodPulse {

    0%,
    100% {
        transform: scale(0.85);
        box-shadow: 0 0 10px var(--arcade-magenta);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px var(--arcade-magenta);
    }
}

@keyframes goldPulse {

    0%,
    100% {
        transform: scale(0.9);
        brightness: 1;
    }

    50% {
        transform: scale(1.1);
        filter: brightness(1.5);
    }
}

.obstacle {
    background: #4a5568;
    border: 2px solid #718096;
    border-radius: 4px;
}

/* Mobile Adjustments */
@media (max-width: 480px) {
    .score-panel {
        gap: 10px;
    }

    .score-item {
        min-width: 100px;
        padding: 8px;
    }

    .score-value {
        font-size: 1rem;
    }

    .menu-card {
        padding: 30px 20px;
    }

    .btn {
        padding: 12px 20px;
        font-size: 0.8rem;
    }
}