:root {
    /* Dark Mode Colors */
    --bg-dark: #0a0a12;
    --primary-dark: #00f3ff;
    --secondary-dark: #ff00ff;
    --tertiary-dark: #00ff9d;
    --accent-dark: #ff3d81;
    --text-dark: #ffffff;
    --panel-dark: rgba(30, 30, 50, 0.7);
    --grid-dark: rgba(30, 40, 80, 0.2);
    --grid-line-dark: rgba(0, 243, 255, 0.2);

    /* Light Mode Colors */
    --bg-light: #f0f2f5;
    --primary-light: #3d9bff;
    --secondary-light: #ff6b9d;
    --tertiary-light: #4dd0c9;
    --accent-light: #9d7aff;
    --text-light: #2a2a3a;
    --panel-light: rgba(255, 255, 255, 0.85);
    --grid-light: rgba(220, 230, 250, 0.7);
    --grid-line-light: rgba(61, 155, 255, 0.2);

    /* Default to Dark Mode */
    --bg: var(--bg-dark);
    --primary: var(--primary-dark);
    --secondary: var(--secondary-dark);
    --tertiary: var(--tertiary-dark);
    --accent: var(--accent-dark);
    --text: var(--text-dark);
    --panel: var(--panel-dark);
    --grid: var(--grid-dark);
    --grid-line: var(--grid-line-dark);
}

.light-mode {
    --bg: var(--bg-light);
    --primary: var(--primary-light);
    --secondary: var(--secondary-light);
    --tertiary: var(--tertiary-light);
    --accent: var(--accent-light);
    --text: var(--text-light);
    --panel: var(--panel-light);
    --grid: var(--grid-light);
    --grid-line: var(--grid-line-light);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: background-color 0.5s, color 0.5s, border-color 0.5s, box-shadow 0.5s;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.light-mode body {
    font-family: 'Nunito', sans-serif;
}

/* .grid-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 400px 40px;
    z-index: -1;
    perspective: 1000px;
    transform-style: preserve-3d;
    animation: gridPulse 8s infinite alternate;
}

@keyframes gridPulse {
    0% {
        background-size: 40px 40px;
    }

    100% {
        background-size: 42px 42px;
    }
} */

.container {
    width: 100%;
    max-width: 1200px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 10px 20px;
    border-radius: 15px;
    background: var(--panel);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.title {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.3);
    letter-spacing: 2px;
}

.light-mode .title {
    text-shadow: 0 0 10px rgba(61, 155, 255, 0.3);
}

.toggle-container {
    position: relative;
    width: 80px;
    height: 40px;
}

.toggle-checkbox {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-label {
    position: absolute;
    top: 0;
    left: 0;
    width: 80px;
    height: 40px;
    border-radius: 20px;
    background: linear-gradient(to right, var(--tertiary), var(--primary));
    cursor: pointer;
    transition: 0.3s;
}

.toggle-label:after {
    content: '☾';
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 5px;
    left: 5px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--bg);
    transition: 0.3s;
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.5);
    color: var(--primary);
    font-size: 18px;
}

.toggle-checkbox:checked+.toggle-label {
    background: linear-gradient(to right, var(--accent-light), var(--tertiary-light));
}

.toggle-checkbox:checked+.toggle-label:after {
    left: calc(100% - 35px);
    content: '☀';
    color: var(--accent-light);
    box-shadow: 0 0 10px rgba(157, 122, 255, 0.5);
}

.game-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1/1;
    margin: 0 auto;
    border-radius: 10px;
    overflow: hidden;
    background: var(--grid);
    backdrop-filter: blur(5px);
    box-shadow: 0 0 30px rgba(0, 243, 255, 0.2),
        inset 0 0 20px rgba(0, 243, 255, 0.1);
    border: 1px solid rgba(0, 243, 255, 0.3);
}

.light-mode .game-container {
    box-shadow: 0 0 30px rgba(61, 155, 255, 0.2),
        inset 0 0 20px rgba(61, 155, 255, 0.1);
    border: 1px solid rgba(61, 155, 255, 0.3);
}

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

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 18, 0.7);
    backdrop-filter: blur(5px);
    z-index: 10;
    opacity: 1;
    transition: opacity 0.5s;
}

.light-mode .game-overlay {
    background: rgba(240, 242, 245, 0.7);
}

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

.menu-panel {
    width: 80%;
    max-width: 400px;
    padding: 30px;
    border-radius: 15px;
    background: var(--panel);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    transform: translateY(0);
    animation: floatPanel 3s ease-in-out infinite;
}

@keyframes floatPanel {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.menu-title {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-align: center;
}

.btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 8px;
    font-family: 'Poppins', sans-serif;
    font-size: 1.2rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    color: var(--bg);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.light-mode .btn {
    font-family: 'Nunito', sans-serif;
}

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

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

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

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

.btn-secondary {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-secondary:hover {
    background: rgba(0, 243, 255, 0.1);
}

.light-mode .btn-secondary:hover {
    background: rgba(61, 155, 255, 0.1);
}

.score-display {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 10px 20px;
    border-radius: 10px;
    background: var(--panel);
    backdrop-filter: blur(10px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 1.2rem;
    z-index: 5;
}

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

.controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 5;
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--panel);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary);
    font-size: 1.5rem;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s;
}

.control-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

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

.game-over-panel {
    text-align: center;
}

.game-over-score {
    font-size: 3rem;
    font-weight: 700;
    margin: 20px 0;
    background: linear-gradient(to right, var(--accent), var(--tertiary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.high-scores {
    width: 100%;
    margin-top: 20px;
}

.high-scores-title {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: var(--primary);
}

.scores-list {
    list-style: none;
    width: 100%;
}

.score-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.light-mode .score-item {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.mobile-controls {
    display: none;
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
}

.mobile-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--panel);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1.5rem;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.mobile-btn-up {
    margin: 0 auto 10px;
}

.mobile-btn-row {
    display: flex;
    gap: 10px;
}

.pause-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--panel);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary);
    font-size: 1.2rem;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    z-index: 5;
    transition: all 0.3s;
}

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

@media (max-width: 768px) {
    .title {
        font-size: 1.8rem;
    }

    .toggle-container {
        width: 60px;
        height: 30px;
    }

    .toggle-label {
        width: 60px;
        height: 30px;
    }

    .toggle-label:after {
        width: 22px;
        height: 22px;
        font-size: 14px;
    }

    .toggle-checkbox:checked+.toggle-label:after {
        left: calc(100% - 27px);
    }

    .game-container {
        max-width: 90vw;
    }

    .mobile-controls {
        display: block;
    }

    .controls {
        display: none;
    }

    .menu-panel {
        width: 90%;
        padding: 20px;
    }

    .menu-title {
        font-size: 1.8rem;
    }

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

/* Animations */
@keyframes glow {

    0%,
    100% {
        filter: drop-shadow(0 0 5px var(--primary));
    }

    50% {
        filter: drop-shadow(0 0 15px var(--primary));
    }
}

@keyframes pulse {

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

    50% {
        transform: scale(1.05);
    }
}

.glow-effect {
    animation: glow 2s infinite;
}

.pulse-effect {
    animation: pulse 2s infinite;
}

/* Game elements styling */
.snake-segment {
    position: absolute;
    border-radius: 3px;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    box-shadow: 0 0 10px var(--primary);
    transition: all 0.1s linear;
}

.snake-head {
    border-radius: 5px;
    background: linear-gradient(45deg, var(--secondary), var(--accent));
    box-shadow: 0 0 15px var(--secondary);
}

.food {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(var(--tertiary), var(--accent));
    box-shadow: 0 0 15px var(--tertiary);
    animation: pulse 1.5s infinite;
}

.light-mode .snake-segment {
    box-shadow: 0 0 10px rgba(61, 155, 255, 0.7);
}

.light-mode .snake-head {
    box-shadow: 0 0 15px rgba(255, 107, 157, 0.7);
}

.light-mode .food {
    box-shadow: 0 0 15px rgba(77, 208, 201, 0.7);
}