/* ============================================
   Snake 3D - Playful Cartoon Styles
   ============================================ */

/* CSS Variables for Theme Customization */
:root {
    /* Classic Theme (Default) */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: rgba(255, 255, 255, 0.95);
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a6a;
    --accent-primary: #4ade80;
    --accent-secondary: #60a5fa;
    --accent-tertiary: #f472b6;
    --board-color: #2d3748;
    --grid-line: rgba(255, 255, 255, 0.1);
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.2);
    --shadow-bounce: 0 4px 0 rgba(0, 0, 0, 0.2);
    --border-radius: 20px;
    --border-radius-sm: 12px;
    --transition-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Candy Theme */
[data-theme="candy"] {
    --bg-primary: #fce7f3;
    --bg-secondary: #fbcfe8;
    --bg-card: rgba(255, 255, 255, 0.98);
    --text-primary: #831843;
    --text-secondary: #9d174d;
    --accent-primary: #f472b6;
    --accent-secondary: #a78bfa;
    --accent-tertiary: #fbbf24;
    --board-color: #fdf2f8;
    --grid-line: rgba(131, 24, 67, 0.1);
}

/* Neon Theme */
[data-theme="neon"] {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a3e;
    --bg-card: rgba(20, 20, 40, 0.95);
    --text-primary: #e0e0ff;
    --text-secondary: #a0a0d0;
    --accent-primary: #00ff88;
    --accent-secondary: #00ccff;
    --accent-tertiary: #ff00ff;
    --board-color: #0a0a1a;
    --grid-line: rgba(0, 255, 136, 0.15);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Nunito', sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

/* Game Container */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ============================================
   Screen Overlays
   ============================================ */

.screen-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s var(--transition-smooth), visibility 0.4s;
    z-index: 100;
}

.screen-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Menu Cards */
.menu-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 40px 50px;
    min-width: 400px;
    max-width: 500px;
    box-shadow: var(--shadow-soft), 0 0 0 4px rgba(255, 255, 255, 0.1);
    text-align: center;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.5s var(--transition-bounce);
}

.screen-overlay.active .menu-card {
    transform: scale(1) translateY(0);
}

/* Title Styles */
.game-title {
    font-family: 'Fredoka One', cursive;
    font-size: 3.5rem;
    color: var(--accent-primary);
    text-shadow: 3px 3px 0 var(--text-primary), -1px -1px 0 var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: 2px;
    animation: titleBounce 2s ease-in-out infinite;
}

.game-subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 30px;
}

.screen-title {
    font-family: 'Fredoka One', cursive;
    font-size: 2.5rem;
    color: var(--text-primary);
    margin-bottom: 25px;
}

@keyframes titleBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* ============================================
   Buttons
   ============================================ */

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 25px;
}

.menu-btn {
    font-family: 'Nunito', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 16px 28px;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s var(--transition-bounce);
    position: relative;
    overflow: hidden;
}

.menu-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s;
}

.menu-btn:hover::before {
    left: 100%;
}

.menu-btn:hover {
    transform: translateY(-3px) scale(1.02);
}

.menu-btn:active {
    transform: translateY(0) scale(0.98);
}

.btn-icon {
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon svg {
    width: 24px;
    height: 24px;
    display: block;
}

.title-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    vertical-align: middle;
    margin-right: 8px;
}

.title-icon svg {
    width: 32px;
    height: 32px;
}

.screen-title .title-icon,
.error-title .title-icon {
    color: var(--accent-primary);
}

.pause-title .title-icon {
    color: var(--accent-secondary);
}

.error-title .title-icon {
    color: #ef4444;
}

/* Ensure hidden class works with SVG */
.hidden svg,
svg.hidden {
    display: none !important;
}

/* Title icon specific sizing */
.title-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    vertical-align: middle;
    margin-right: 8px;
}

.title-icon svg {
    width: 32px;
    height: 32px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary) 0%, #22c55e 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(74, 222, 128, 0.4), var(--shadow-bounce);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(74, 222, 128, 0.5), var(--shadow-bounce);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--accent-secondary) 0%, #3b82f6 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(96, 165, 250, 0.4), var(--shadow-bounce);
}

.btn-secondary:hover {
    box-shadow: 0 6px 20px rgba(96, 165, 250, 0.5), var(--shadow-bounce);
}

.btn-tertiary {
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    color: var(--text-primary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1), var(--shadow-bounce);
}

.btn-tertiary:hover {
    background: linear-gradient(135deg, #e5e7eb 0%, #d1d5db 100%);
}

.btn-back {
    background: transparent;
    border: 2px solid var(--text-secondary);
    color: var(--text-secondary);
    margin-top: 20px;
}

.btn-back:hover {
    background: var(--text-secondary);
    color: white;
}

/* ============================================
   High Score Preview
   ============================================ */

.high-score-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: var(--border-radius-sm);
    font-weight: 700;
}

.high-score-preview .label {
    color: #92400e;
}

.high-score-preview .score {
    color: #b45309;
    font-size: 1.3rem;
}

/* ============================================
   Settings Screen
   ============================================ */

.settings-section {
    margin-bottom: 25px;
    text-align: left;
}

.setting-label {
    display: block;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    font-size: 1rem;
}

/* Theme Selector */
.theme-selector {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.theme-btn {
    flex: 1;
    padding: 12px 8px;
    border: 3px solid transparent;
    border-radius: var(--border-radius-sm);
    background: #f3f4f6;
    cursor: pointer;
    transition: all 0.2s var(--transition-bounce);
}

.theme-btn:hover {
    transform: translateY(-2px);
}

.theme-btn.active {
    border-color: var(--accent-primary);
    background: white;
}

.theme-preview {
    width: 50px;
    height: 35px;
    border-radius: 8px;
    margin: 0 auto 8px;
}

.classic-preview {
    background: linear-gradient(135deg, #1a1a2e 50%, #4ade80 50%);
}

.candy-preview {
    background: linear-gradient(135deg, #fce7f3 50%, #f472b6 50%);
}

.neon-preview {
    background: linear-gradient(135deg, #0f0f23 50%, #00ff88 50%);
    box-shadow: 0 0 10px #00ff88;
}

.theme-btn span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Volume Control */
.volume-control {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f3f4f6;
    padding: 12px 16px;
    border-radius: var(--border-radius-sm);
}

.mute-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.mute-btn svg {
    width: 24px;
    height: 24px;
    display: block;
}

.mute-btn:hover {
    transform: scale(1.1);
}

#volume-slider {
    flex: 1;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: #d1d5db;
    border-radius: 4px;
    outline: none;
}

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

#volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

#volume-value {
    font-weight: 700;
    color: var(--text-secondary);
    min-width: 45px;
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    width: 50px;
    height: 26px;
    background: #d1d5db;
    border-radius: 13px;
    position: relative;
    transition: background 0.3s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s var(--transition-bounce);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-primary);
}

.toggle-switch input:checked + .toggle-slider::after {
    transform: translateX(24px);
}

.toggle-label {
    font-weight: 600;
    color: var(--text-secondary);
}

/* ============================================
   High Scores Screen
   ============================================ */

.scores-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    border: 2px solid #e5e7eb;
    border-radius: var(--border-radius-sm);
    background: white;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.scores-list {
    background: #f3f4f6;
    border-radius: var(--border-radius-sm);
    padding: 16px;
    min-height: 200px;
    max-height: 300px;
    overflow-y: auto;
}

.score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-radius: 10px;
    margin-bottom: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
}

.score-item:hover {
    transform: translateX(5px);
}

.score-item.empty {
    background: transparent;
    box-shadow: none;
    justify-content: center;
}

.no-scores {
    color: var(--text-secondary);
    font-style: italic;
}

.score-rank {
    font-family: 'Fredoka One', cursive;
    font-size: 1.3rem;
    color: var(--accent-secondary);
    width: 40px;
}

.score-name {
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
    text-align: left;
    padding-left: 12px;
}

.score-points {
    font-family: 'Fredoka One', cursive;
    font-size: 1.2rem;
    color: var(--accent-primary);
}

/* ============================================
   HUD (Heads Up Display)
   ============================================ */

.hud-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    opacity: 0;
    transition: opacity 0.3s;
}

.hud-overlay.visible {
    opacity: 1;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 30px;
}

.score-panel {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.6);
    padding: 12px 20px;
    border-radius: var(--border-radius-sm);
    backdrop-filter: blur(10px);
}

.score-panel.hidden {
    display: none;
}

.player-indicator {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    box-shadow: 0 0 10px currentColor;
}

.score-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.score-panel:last-child .score-info {
    align-items: flex-end;
}

.player-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    font-family: 'Fredoka One', cursive;
    font-size: 2rem;
    color: white;
    line-height: 1;
}

.game-controls-hint {
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 600;
}

/* ============================================
   Pause Overlay
   ============================================ */

.pause-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 50px 60px;
    box-shadow: var(--shadow-soft);
    text-align: center;
}

.pause-title {
    font-family: 'Fredoka One', cursive;
    font-size: 4rem;
    color: var(--accent-secondary);
    margin-bottom: 15px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

.pause-hint {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 25px;
}

/* ============================================
   Game Over Overlay
   ============================================ */

.game-over-title {
    color: #ef4444;
}

.winner-display {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    padding: 15px 30px;
    border-radius: var(--border-radius-sm);
    margin-bottom: 20px;
}

.winner-text {
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    color: #92400e;
}

.final-scores {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
}

.final-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.final-score.hidden {
    display: none;
}

.final-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.final-value {
    font-family: 'Fredoka One', cursive;
    font-size: 3rem;
    color: var(--text-primary);
}

.high-score-badge {
    background: linear-gradient(135deg, #fef3c7 0%, #fbbf24 100%);
    color: #92400e;
    padding: 12px 24px;
    border-radius: var(--border-radius-sm);
    font-weight: 800;
    font-size: 1.1rem;
    margin-bottom: 20px;
    animation: badgeBounce 0.6s var(--transition-bounce);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.badge-icon {
    width: 24px;
    height: 24px;
    display: inline-flex;
    vertical-align: middle;
}

.badge-icon svg {
    width: 24px;
    height: 24px;
}

.high-score-badge.hidden {
    display: none;
}

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

.game-over-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================
   Countdown Overlay
   ============================================ */

.countdown-display {
    font-family: 'Fredoka One', cursive;
    font-size: 15rem;
    color: white;
    text-shadow: 0 0 40px rgba(255, 255, 255, 0.5), 4px 4px 0 rgba(0, 0, 0, 0.3);
    animation: countdownPulse 1s ease-out;
}

@keyframes countdownPulse {
    0% { transform: scale(2); opacity: 0; }
    50% { transform: scale(0.9); }
    100% { transform: scale(1); opacity: 1; }
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 600px) {
    .menu-card {
        min-width: 90%;
        padding: 30px 25px;
    }

    .game-title {
        font-size: 2.5rem;
    }

    .screen-title {
        font-size: 2rem;
    }

    .menu-btn {
        padding: 14px 22px;
        font-size: 1rem;
    }

    .theme-selector {
        flex-direction: column;
    }

    .theme-btn {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 16px;
    }

    .theme-preview {
        width: 35px;
        height: 25px;
        margin: 0;
    }

    .hud-top {
        padding: 15px;
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .score-panel {
        padding: 10px 16px;
    }

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

    .countdown-display {
        font-size: 10rem;
    }

    .final-scores {
        flex-direction: column;
        gap: 15px;
    }

    .pause-title {
        font-size: 3rem;
    }
}

/* Hidden class for JavaScript toggling */
.hidden {
    display: none !important;
}

/* ============================================
   Loading Overlay
   ============================================ */

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 20px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    color: white;
    animation: pulse-text 1.5s ease-in-out infinite;
}

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

/* ============================================
   Error Overlay
   ============================================ */

.error-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.error-overlay.active {
    opacity: 1;
    visibility: visible;
}

.error-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 40px 50px;
    max-width: 450px;
    text-align: center;
    box-shadow: var(--shadow-soft);
    border-left: 5px solid #ef4444;
}

.error-title {
    font-family: 'Fredoka One', cursive;
    font-size: 2rem;
    color: #ef4444;
    margin-bottom: 15px;
}

.error-message {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 25px;
    line-height: 1.5;
}

/* ============================================
   No WebGL Warning
   ============================================ */

.no-webgl-notice {
    background: rgba(239, 68, 68, 0.1);
    border: 2px solid #ef4444;
    border-radius: var(--border-radius-sm);
    padding: 15px 20px;
    margin: 20px auto;
    max-width: 350px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.no-webgl-notice strong {
    color: #ef4444;
}

/* ============================================
   Audio Disabled Notice
   ============================================ */

.audio-notice {
    background: rgba(251, 191, 36, 0.1);
    border: 2px solid #fbbf24;
    border-radius: var(--border-radius-sm);
    padding: 10px 15px;
    margin: 10px auto;
    max-width: 300px;
    color: var(--text-primary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
