/* ============================================
   SNAKE GAME - STYLES
   A modern, responsive snake game
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --color-bg-primary: #0f0f23;
    --color-bg-secondary: #1a1a2e;
    --color-bg-tertiary: #16213e;

    --color-accent-primary: #00ff88;
    --color-accent-secondary: #00cc6a;
    --color-accent-glow: rgba(0, 255, 136, 0.4);

    --color-food: #ff6b6b;
    --color-food-glow: rgba(255, 107, 107, 0.5);

    --color-text-primary: #ffffff;
    --color-text-secondary: #888888;
    --color-score: #ffcc00;
    --color-highscore: #ff6b6b;

    --font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    --border-radius: 12px;
    --transition-fast: 0.2s ease;
    --transition-medium: 0.3s ease;
}

/* ---------- Reset & Base ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--color-bg-primary) 0%, var(--color-bg-secondary) 50%, var(--color-bg-tertiary) 100%);
    font-family: var(--font-family);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

/* ---------- Game Container ---------- */
.game-container {
    text-align: center;
    padding: 20px;
    position: relative;
    max-width: 100vw;
}

/* ---------- Title ---------- */
.game-title {
    color: var(--color-accent-primary);
    font-size: clamp(2rem, 8vw, 3.5rem);
    font-weight: 800;
    margin-bottom: 15px;
    text-shadow:
        0 0 20px var(--color-accent-glow),
        0 0 40px var(--color-accent-glow),
        0 0 60px var(--color-accent-glow);
    letter-spacing: 8px;
    animation: titlePulse 2s ease-in-out infinite;
}

@keyframes titlePulse {
    0%, 100% { text-shadow: 0 0 20px var(--color-accent-glow), 0 0 40px var(--color-accent-glow); }
    50% { text-shadow: 0 0 30px var(--color-accent-glow), 0 0 60px var(--color-accent-glow), 0 0 80px var(--color-accent-glow); }
}

/* ---------- Score Board ---------- */
.score-board {
    display: flex;
    justify-content: center;
    gap: clamp(15px, 5vw, 40px);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.score-item {
    color: var(--color-text-primary);
    font-size: clamp(1rem, 4vw, 1.3rem);
    padding: 12px 25px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 30px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform var(--transition-fast);
}

.score-item:hover {
    transform: scale(1.05);
}

.score-item--current .score-value {
    color: var(--color-score);
    font-weight: 700;
}

.score-item--high .score-value {
    color: var(--color-highscore);
    font-weight: 700;
}

/* New high score animation */
.score-item--new-high {
    animation: newHighScore 0.5s ease;
}

@keyframes newHighScore {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ---------- Canvas Container ---------- */
.canvas-container {
    position: relative;
    display: inline-block;
    margin: 0 auto;
}

#gameCanvas {
    display: block;
    border: 4px solid var(--color-accent-primary);
    border-radius: var(--border-radius);
    box-shadow:
        0 0 30px var(--color-accent-glow),
        0 0 60px rgba(0, 255, 136, 0.2),
        inset 0 0 50px rgba(0, 0, 0, 0.5);
    background: var(--color-bg-primary);
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 350px);
    touch-action: none;
}

/* ---------- Instructions ---------- */
.instructions {
    color: var(--color-text-secondary);
    margin-top: 20px;
    font-size: clamp(0.8rem, 3vw, 1rem);
    line-height: 1.6;
}

.instructions kbd {
    background: rgba(255, 255, 255, 0.12);
    padding: 4px 10px;
    border-radius: 6px;
    margin: 0 2px;
    color: var(--color-text-primary);
    font-family: inherit;
    font-size: 0.9em;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

/* Hide keyboard instructions on mobile */
.instructions--desktop {
    display: block;
}

.instructions--mobile {
    display: none;
}

/* ---------- Game Over Overlay ---------- */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
    animation: fadeIn var(--transition-medium);
}

.game-over-overlay.visible {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.game-over-content {
    background: linear-gradient(145deg, var(--color-bg-secondary), var(--color-bg-primary));
    padding: clamp(30px, 8vw, 50px);
    border-radius: 20px;
    border: 3px solid var(--color-food);
    text-align: center;
    animation: slideUp 0.4s ease;
    max-width: 90vw;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-over-content h2 {
    color: var(--color-food);
    font-size: clamp(2rem, 8vw, 3rem);
    margin-bottom: 10px;
    text-shadow: 0 0 20px var(--color-food-glow);
}

.game-over-content .final-score {
    color: var(--color-text-primary);
    font-size: clamp(1.2rem, 5vw, 1.5rem);
    margin-bottom: 10px;
}

.game-over-content .final-score span {
    color: var(--color-score);
    font-weight: 700;
    font-size: 1.2em;
}

.game-over-content .new-record {
    color: var(--color-accent-primary);
    font-size: 1.1rem;
    margin-bottom: 20px;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.btn {
    background: linear-gradient(135deg, var(--color-accent-primary), var(--color-accent-secondary));
    border: none;
    padding: 15px 45px;
    font-size: clamp(1rem, 4vw, 1.2rem);
    font-weight: 700;
    border-radius: 30px;
    cursor: pointer;
    color: var(--color-bg-primary);
    transition: all var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px var(--color-accent-glow);
}

.btn:active {
    transform: scale(0.98);
}

/* ---------- Mobile Touch Controls ---------- */
.touch-controls {
    display: none;
    margin-top: 20px;
    gap: 10px;
}

.touch-controls-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.touch-btn {
    width: clamp(60px, 15vw, 70px);
    height: clamp(60px, 15vw, 70px);
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid var(--color-accent-primary);
    border-radius: 15px;
    color: var(--color-accent-primary);
    font-size: clamp(1.5rem, 5vw, 2rem);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
    background: var(--color-accent-primary);
    color: var(--color-bg-primary);
    transform: scale(0.95);
}

.touch-btn--placeholder {
    visibility: hidden;
}

.touch-btn--pause {
    width: auto;
    padding: 0 25px;
    font-size: clamp(0.9rem, 3vw, 1rem);
    letter-spacing: 2px;
    margin-top: 10px;
}

/* ---------- Speed Indicator ---------- */
.speed-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 15px;
    border-radius: 20px;
    color: var(--color-text-primary);
    font-size: 0.85rem;
}

.speed-indicator span {
    color: var(--color-accent-primary);
    font-weight: 700;
}

/* ---------- Responsive Design ---------- */
@media (max-width: 600px) {
    body {
        align-items: flex-start;
        padding-top: 10px;
    }

    .game-container {
        padding: 10px;
    }

    .game-title {
        margin-bottom: 10px;
        letter-spacing: 4px;
    }

    .score-board {
        margin-bottom: 15px;
    }

    .score-item {
        padding: 8px 18px;
    }

    .instructions--desktop {
        display: none;
    }

    .instructions--mobile {
        display: block;
    }

    .touch-controls {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    #gameCanvas {
        max-height: calc(100vh - 400px);
    }
}

@media (max-width: 400px) {
    .score-board {
        gap: 10px;
    }

    .score-item {
        padding: 6px 14px;
        font-size: 0.9rem;
    }

    .touch-btn {
        width: 55px;
        height: 55px;
    }
}

/* ---------- Prefers Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
