:root {
    --bg-color: #0d0d0d;
    --container-bg: rgba(22, 64, 77, 0.3);
    --border-color: rgba(251, 245, 221, 0.1);
    --accent-glow: rgba(221, 168, 83, 0.4);
    --snake-color: #DDA853;
    --snake-head: #FBF5DD;
    --food-color: #A6CDC6;
    --text-main: #FBF5DD;
    --text-muted: rgba(251, 245, 221, 0.6);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at 50% 0%, #16404D 0%, transparent 70%);
    color: var(--text-main);
    font-family: 'Space Grotesk', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

.game-container {
    background: var(--container-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 32px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 40px var(--accent-glow);
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 90vw;
    max-width: 450px;
    box-sizing: border-box;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-family: 'Playfair Display', serif;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 2px;
    background: linear-gradient(to right, #DDA853, var(--snake-head));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 30px var(--accent-glow);
}

.score-board {
    display: flex;
    gap: 16px;
}

.score-box {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.canvas-wrapper {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    border: 1px solid var(--border-color);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
    width: 100%;
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1/1;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 5% 5%;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

#overlay-title {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
    text-shadow: 0 0 20px var(--accent-glow);
    text-transform: uppercase;
    letter-spacing: 2px;
}

#overlay-subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: 24px;
}

.controls-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

.key {
    background: rgba(251, 245, 221, 0.1);
    border: 1px solid rgba(251, 245, 221, 0.2);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-main);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

/* Mobile Controls */
.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}

.dpad-row {
    display: flex;
    gap: 12px;
}

.dpad-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--container-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: background 0.2s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.dpad-btn svg {
    width: 28px;
    height: 28px;
}

.dpad-btn:active {
    background: rgba(221, 168, 83, 0.3);
    transform: scale(0.92);
}

@media (max-width: 600px) {
    .mobile-controls {
        display: flex;
        transform: scale(0.9);
        margin-top: 0;
    }

    .game-container {
        padding: 20px 16px;
        width: 100%;
        height: 100%;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        border: none;
        gap: 12px;
        justify-content: center;
        overflow: hidden;
        /* Prevents stretching wider than screen */
        box-sizing: border-box;
    }

    .header {
        width: 100%;
    }

    h1 {
        font-size: 1.8rem;
    }

    .score-box {
        min-width: 60px;
        padding: 6px 10px;
    }

    .value {
        font-size: 1rem;
    }

    .canvas-wrapper {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        max-width: 100%;
        max-height: 45vh;
        /* Prevent it from getting too tall */
        margin: 0 auto;
        min-width: 0;
        min-height: 0;
        flex-shrink: 1;
    }

    canvas {
        max-width: 100%;
        max-height: 100%;
        width: 100%;
        height: 100%;
        aspect-ratio: 1/1;
        object-fit: contain;
    }

    #overlay-title {
        font-size: 1.3rem;
    }

    .controls-hint {
        text-align: center;
        font-size: 0.7rem;
        padding: 0 5px;
        white-space: normal;
    }
}