:root {
    --color-main: #020202;
    --color-panel: #08080c;
    --color-soft: #040404;
    --color-gold: #d8b449;
    --color-cream: #f3e8c9;
    --glow: rgba(2, 2, 2, 0.88);
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top, #040404 0%, #020202 55%, #010101 100%);
    color: var(--color-cream);
    font-family: "Inter", sans-serif;
}

.game-app {
    width: min(1280px, 100% - 32px);
    margin: 0 auto;
    padding: 40px 16px 60px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.game-header {
    text-align: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}

.game-header h1 {
    margin: 0;
    font-family: 'VT323', monospace;
    font-size: clamp(36px, 5vw, 60px);
    color: var(--color-gold);
    text-shadow: 0 0 20px rgba(216, 180, 73, 0.4);
}

.game-subtitle {
    margin: 0 auto;
    max-width: 620px;
    color: var(--color-cream);
    font-size: 1rem;
}

.sound-toggle {
    border: none;
    border-radius: 999px;
    padding: 10px 28px;
    font-family: 'VT323', monospace;
    font-size: 1rem;
    color: #020202;
    background: linear-gradient(90deg, var(--color-gold), var(--color-cream));
    cursor: pointer;
    box-shadow: 0 12px 30px var(--glow);
    transition: transform 120ms ease, box-shadow 200ms ease;
}

.sound-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 35px rgba(216, 180, 73, 0.5);
}

.game-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.game-panel {
    background: rgba(8, 8, 12, 0.95);
    border: 1px solid rgba(216, 180, 73, 0.35);
    position: relative;
    padding: 16px;
    border-radius: 28px;
    box-shadow: 0 20px 60px var(--glow);
    width: min(760px, 100%);
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    box-sizing: border-box;
}
.game-header.game-panel {
    padding: 20px 24px;
}

.game-panel::before {
    content: '';
    position: absolute;
    inset: 8px;
    border-radius: inherit;
    border: 1px solid rgba(243, 232, 201, 0.05);
    pointer-events: none;
}

.game-container {
    padding: clamp(16px, 3vw, 24px);
}

.game-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: min(92vw, 640px);
    background: var(--color-soft);
    border-radius: 18px;
    padding: clamp(8px, 1.5vw, 14px);
    box-shadow: 0 15px 45px var(--glow);
}

.game-border-1 {
    padding: 4px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: center;
}

.game-border-2 {
    border: 4px solid rgba(216, 180, 73, 0.25);
    border-radius: 20px;
    padding: 4px;
    width: 100%;
    display: flex;
    justify-content: center;
}

.game-border-3 {
    border: 3px solid var(--color-soft);
    background: var(--color-soft);
    border-radius: 14px;
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

#game-board {
    background-color: var(--color-cream);
    display: grid;
    grid-template-columns: repeat(20, 1fr);
    grid-template-rows: repeat(20, 1fr);
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    margin: 0;
    box-shadow:
        inset 0 0 35px rgba(2, 2, 2, 0.35),
        0 10px 35px rgba(2, 2, 2, 0.6);
    caret-color: transparent;
    user-select: none;
}

#game-board.board-crash {
    animation: boardShake 550ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.crash-explosion {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle, rgba(255, 250, 230, 0.95) 0%, rgba(216, 180, 73, 0.65) 35%, rgba(8, 8, 12, 0) 70%);
    box-shadow: 0 0 25px rgba(249, 231, 171, 0.75), 0 0 8px rgba(216, 180, 73, 0.75);
    animation: crashBurst 520ms ease-out forwards;
}

.snake {
    background-color: var(--color-gold);
    border-radius: 4px;
    box-shadow: inset 0 0 6px rgba(2, 2, 2, 0.4);
}

.snake-head,
.food {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 4px 10px rgba(2, 2, 2, 0.55));
}

.food {
    animation: foodPulse 1.4s ease-in-out infinite;
}

.game-over-screen {
    position: absolute;
    inset: 0;
    background: rgba(4, 4, 4, 0.98);
    border-radius: 16px;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
    z-index: 6;
    overflow-y: auto;
}

.game-over-box {
    width: min(360px, 100%);
    text-align: center;
    font-family: 'VT323', monospace;
}

.game-over-text {
    margin: 16px 0;
    color: var(--color-gold);
    font-size: clamp(42px, 6vw, 64px);
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.8);
}

.blinking-cursor {
    animation: blink 1s steps(1, end) infinite;
}

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

.restart-button {
    width: 100%;
    padding: 12px 18px;
    font-family: 'VT323', monospace;
    font-size: 20px;
    color: #fff;
    background: var(--color-gold);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    letter-spacing: 2px;
    box-shadow: 0 10px 25px rgba(2, 2, 2, 0.65);
    transition: transform 130ms ease, box-shadow 130ms ease;
}

.restart-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 30px rgba(216, 180, 73, 0.4);
}

@media (max-width: 960px) {
    .game-border-1 {
        padding-top: 0;
    }
}

body.game-playing {
    overflow: hidden;
    overscroll-behavior: contain;
}

.score-panel {
    width: min(760px, 100%);
    max-width: 760px;
    margin: 0 auto;
    background: rgba(8, 8, 12, 0.95);
    border-radius: 24px;
    border: 1px solid rgba(216, 180, 73, 0.35);
    box-shadow: 0 12px 30px var(--glow);
    position: relative;
    overflow: hidden;
    padding: 20px 24px;
    box-sizing: border-box;
}

#score-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    font-family: 'VT323', monospace;
    text-align: center;
}

.score-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(8, 8, 12, 0.97);
    border-radius: inherit;
    font-family: 'VT323', monospace;
    text-align: center;
    padding: 24px 12px;
    z-index: 2;
    cursor: pointer;
    opacity: 1;
    transition: opacity 200ms ease;
}

.score-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    padding: 0;
    font-family: 'VT323', monospace;
    width: 100%;
    gap: 16px;
    position: relative;
    z-index: 1;
}

.score-block {
    min-width: 120px;
    padding: 0 12px;
}

.score-block:first-child {
    text-align: left;
}

.score-block:last-child {
    text-align: right;
}

.score-label {
    font-size: 16px;
    letter-spacing: 2px;
    color: var(--color-gold);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

#score,
#highScore {
    margin: 0;
    font-size: 40px;
    color: var(--color-cream);
    text-shadow: 0 8px 20px var(--glow);
}

.splash-image-layer {
    position: absolute;
    inset: 0;
    background-image: url('assets/snek_hunter.png');
    background-size: cover;
    background-position: center;
    border-radius: inherit;
    z-index: 4;
    cursor: pointer;
    background-color: rgba(8, 8, 12, 0.95);
    opacity: 1;
    transition: opacity 220ms ease;
}

.score-overlay.hidden,
.splash-image-layer.hidden {
    opacity: 0;
    pointer-events: none;
}
@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}
.score-overlay .ready-text {
    color: #d8b449;
    font-size: clamp(32px, 8vw, 56px);
    animation: flash 1s infinite;
    text-shadow: 0 0 20px rgba(216, 180, 73, 0.45);
}

.score-overlay .instruction-text {
    color: #fff;
    font-size: 20px;
}

@keyframes foodPulse {
    0% { transform: scale(0.95); opacity: 0.9; }
    50% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.9; }
}

@keyframes boardShake {
    0% { transform: translate(0, 0); }
    15% { transform: translate(-6px, -3px); }
    30% { transform: translate(8px, 2px); }
    45% { transform: translate(-5px, 4px); }
    60% { transform: translate(4px, -2px); }
    100% { transform: translate(0, 0); }
}

@keyframes crashBurst {
    0% {
        transform: scale(0.2);
        opacity: 0.9;
        filter: blur(2px);
    }
    60% {
        transform: scale(1.3);
        opacity: 1;
        filter: blur(0);
    }
    100% {
        transform: scale(1.8);
        opacity: 0;
        filter: blur(4px);
    }
}

@media (max-width: 800px) {
    .game-panel,
    .score-panel {
        padding: 16px;
    }

    .game-header.game-panel {
        padding: 16px;
    }
}

@media (max-width: 600px) {
    .game-panel,
    .score-panel {
        border-radius: 20px;
    }

    #game-board {
        width: min(92vw, 480px);
    }
}
