:root {
    --primary-color: #4CAF50;
    --primary-hover: #45a049;
    --background-color: #f0f4f8;
    --snake-head: #2E7D32;
    --snake-body: #66BB6A;
    --food-color: #FF5252;
    --text-color: #333;
    --canvas-bg: #2c3e50;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px 0;
    color: var(--text-color);
    overflow-y: auto;
}

.game-container {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    text-align: center;
    max-width: 500px;
    width: 90%;
    margin: auto;
}

h1 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    display: flex;
    flex-direction: column;
    align-items: center;
}

h1 small {
    font-size: 0.9rem;
    color: #888;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.score-board {
    display: flex;
    justify-content: space-around;
    margin-bottom: 1.5rem;
}

.score-board p {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
    color: #666;
}

.score-board span {
    font-size: 1.5rem;
    color: var(--text-color);
}

.game-area {
    position: relative;
    margin: 0 auto 1.5rem;
    width: min(400px, 100%);
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    overflow: hidden;
    background-color: var(--canvas-bg);
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
}

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

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.screen {
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.screen h2 {
    margin-bottom: 1.5rem;
    font-size: 2rem;
}

.screen p {
    margin-bottom: 2rem;
    font-size: 1.2rem;
    opacity: 0.9;
    font-weight: 500;
}

#final-score {
    font-size: 2rem;
    color: var(--primary-color);
    display: block;
    margin-top: 0.5rem;
}

.hidden {
    display: none !important;
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 1.1rem;
    border-radius: 25px;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.1s;
}

button:hover {
    background-color: var(--primary-hover);
}

button:active {
    transform: scale(0.95);
}

.controls-info {
    font-size: 0.9rem;
    color: #666;
}

@media (max-width: 500px) {
    .game-container {
        padding: 1rem;
        width: 95%;
    }

    h1 {
        font-size: 1.5rem;
    }

    h1 small {
        font-size: 0.7rem;
    }

    .score-board p {
        font-size: 0.8rem;
    }

    .score-board span {
        font-size: 1.2rem;
    }

    .screen h2 {
        font-size: 1.5rem;
    }

    .screen p {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }

    #final-score {
        font-size: 1.5rem;
    }

    button {
        padding: 10px 20px;
        font-size: 1rem;
    }
}

/* 禁止游戏区域的触摸默认行为，防止滑动时页面滚动 */
.game-area {
    touch-action: none;
}

/* 允许页面在非游戏区域滚动 */
html, body {
    overflow-x: hidden;
    overflow-y: auto;
}
