:root {
    color-scheme: dark;
    --bg: #101316;
    --panel: #181d21;
    --panel-2: #20262b;
    --line: #323b42;
    --text: #f3f7f8;
    --muted: #9aa7ad;
    --snake: #42d392;
    --snake-dark: #229866;
    --food: #ff5c5c;
    --accent: #ffd166;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    display: grid;
    place-items: center;
    background:
            radial-gradient(circle at 20% 20%, rgba(66, 211, 146, 0.12), transparent 32rem),
            linear-gradient(135deg, #111518, #16191c 48%, #0e1114);
    color: var(--text);
    font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

.game-shell {
    width: min(94vw, 720px);
    display: grid;
    gap: 16px;
    padding: 18px;
}

.hud {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.hud > div {
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(24, 29, 33, 0.86);
}

.label {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 13px;
}

.hud strong {
    display: block;
    font-size: clamp(22px, 5vw, 34px);
    line-height: 1;
}

.speed-control {
    display: grid;
    gap: 8px;
}

.speed-control strong {
    font-size: clamp(20px, 4vw, 30px);
}

input[type="range"] {
    width: 100%;
    height: 18px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.board-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
    background: rgba(16, 19, 22, 0.78);
    backdrop-filter: blur(8px);
}

.overlay.hidden {
    display: none;
}

h1 {
    margin: 0;
    font-size: clamp(42px, 10vw, 78px);
    letter-spacing: 0;
}

.overlay p {
    max-width: 30rem;
    margin: 0 auto;
    color: var(--muted);
    line-height: 1.7;
}

button {
    border: 0;
    border-radius: 8px;
    color: #141414;
    background: var(--accent);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

#startButton {
    justify-self: center;
    min-width: 132px;
    padding: 12px 18px;
}

.actions {
    display: flex;
    justify-content: center;
}

#restartButton {
    min-width: 132px;
    padding: 11px 18px;
}

.controls {
    display: none;
    grid-template-columns: repeat(3, 64px);
    justify-content: center;
    gap: 8px;
}

.direction {
    width: 64px;
    height: 52px;
    font-size: 24px;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
    touch-action: manipulation;
}

.direction:active,
#restartButton:active,
#startButton:active {
    transform: translateY(1px);
}

.ghost {
    visibility: hidden;
}

@media (max-width: 720px) {
    body {
        align-items: start;
    }

    .game-shell {
        padding: 12px;
    }

    .controls {
        display: grid;
    }
}
