/* ===== 贪吃蛇专属样式 ===== */
.snake-section {
    padding: 120px 0 80px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.section-title {
    text-align: center;
    margin-bottom: 3rem;
}

.section-title h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.section-title p {
    font-size: 1rem;
    color: var(--text-gray);
}

.game-stats {
    display: flex;
    gap: 3rem;
    margin-bottom: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    color: var(--text-gray);
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-light);
}

.game-board {
    display: grid;
    gap: 1px;
    background: var(--border-color);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 2rem;
    padding: 0;
}

.cell {
    width: 20px;
    height: 20px;
    background: var(--darker-bg);
    position: relative;
    will-change: transform;
}

/* 蛇头转向动画 */
.snake-head.moving-up    { transform: translateY(-20%) scale(1.05); }
.snake-head.moving-down  { transform: translateY(20%) scale(1.05); }
.snake-head.moving-left  { transform: translateX(-20%) scale(1.05); }
.snake-head.moving-right { transform: translateX(20%) scale(1.05); }


.snake-body {
    background: var(--gradient-primary);
}

.snake-head {
    background: var(--gradient-accent);
    box-shadow: 0 0 10px var(--accent-color);
}

.food {
    background: #ff4d4d;
    border-radius: 50%;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.9); }
}

.game-controls {
    display: flex;
    gap: 1rem;
}

.btn-secondary {
    background: transparent;
    color: var(--accent-color);
    border: 2px solid var(--accent-color);
}

.btn-secondary:hover {
    background: var(--accent-color);
    color: var(--dark-bg);
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 198, 255, 0.3);
}

.game-message {
    margin-top: 1rem;
    font-size: 1.1rem;
    text-align: center;
    min-height: 1.5em;
    color: var(--text-gray);
}

/* ==================== 排行榜样式 ==================== */
.leaderboard {
    margin-top: 2rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    padding: 1.5rem;
    width: 100%;
    max-width: 400px;
}

.leaderboard-title {
    text-align: center;
    font-size: 1.3rem;
    margin-bottom: 1rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    background: var(--darker-bg);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.leaderboard-item:hover {
    transform: translateX(5px);
    border-left: 2px solid var(--accent-color);
}

.leaderboard-rank {
    font-size: 1.2rem;
    font-weight: bold;
    margin-right: 1rem;
    width: 30px;
    text-align: center;
}

.leaderboard-rank.top3 {
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.leaderboard-info {
    flex: 1;
}

.leaderboard-name {
    color: var(--text-light);
    font-weight: 500;
}

.leaderboard-score {
    color: var(--text-gray);
    font-size: 0.9rem;
}

.leaderboard-date {
    color: var(--text-gray);
    font-size: 0.8rem;
}

/* ==================== 模态框样式 ==================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    /* ✅ 修改：使用 opacity 和 visibility 代替 display */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--darker-bg);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    padding: 2rem;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    opacity: 1;
}

.modal-title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-subtitle {
    color: var(--text-gray);
    margin-bottom: 1.5rem;
}

.modal-input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text-light);
    font-size: 1rem;
    margin-bottom: 0.5rem;
    transition: border-color 0.3s ease;
}

.modal-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(0, 198, 255, 0.2);
}

.char-counter {
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-gray);
    margin-bottom: 1rem;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.modal-error {
    color: #ff4d4d;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    min-height: 1.2em;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .game-stats {
        gap: 2rem;
    }

    .cell {
        width: 18px;
        height: 18px;
    }

    .leaderboard {
        margin-top: 1.5rem;
    }
}

@media (max-width: 480px) {
    .cell {
        width: 16px;
        height: 16px;
    }

    .game-stats {
        flex-direction: column;
        gap: 1rem;
    }
}

/* 高亮当前用户的条目 */
.leaderboard-item.current-user {
    border: 1px solid var(--accent-color);
    background: rgba(0, 198, 255, 0.1);
}

/* 在文件末尾追加移动端样式 */

/* ==================== 移动端控制按钮 ==================== */
.mobile-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 8px;
    z-index: 100;
    pointer-events: none;
}

/* ==================== 增强方向键可见性 ==================== */
.control-btn {
    pointer-events: all;
    background: rgba(30, 30, 46, 0.9); /* ✅ 更不透明的深色背景 */
    border: 2px solid var(--accent-color); /* ✅ 使用亮蓝色边框 */
    border-radius: 12px;
    color: var(--accent-color); /* ✅ 亮蓝色图标 */
    font-size: 1.8rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    /* ✅ 新增：发光效果 */
    box-shadow: 0 0 10px rgba(0, 198, 255, 0.3);
}

/* ✅ 增强按下状态 */
.control-btn:active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--dark-bg);
    transform: scale(0.95);
    /* ✅ 新增：按下时更强的发光 */
    box-shadow: 0 0 20px rgba(0, 198, 255, 0.6);
}

/* ✅ 新增：悬停效果（适用于触摸设备） */
@media (hover: hover) {
    .control-btn:hover {
        background: rgba(0, 198, 255, 0.1);
        box-shadow: 0 0 15px rgba(0, 198, 255, 0.5);
    }
}

/* ✅ 新增：按钮中心点高亮 */
.control-btn::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--accent-color);
    border-radius: 50%;
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

.control-btn:active::before {
    opacity: 1;
}

@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.game-board.dead {
    animation: flash 0.3s ease 3;
}

/* 按钮布局：十字形 */
.control-btn[data-direction="up"] {
    grid-column: 2;
    grid-row: 1;
}

.control-btn[data-direction="left"] {
    grid-column: 1;
    grid-row: 2;
}

.control-btn[data-direction="down"] {
    grid-column: 2;
    grid-row: 2;
}

.control-btn[data-direction="right"] {
    grid-column: 3;
    grid-row: 2;
}

/* ==================== 响应式适配 ==================== */
@media (max-width: 768px) {
    /* 缩小格子尺寸 */
    .cell {
        width: 16px;
        height: 16px;
    }

    /* 调整统计信息布局 */
    .game-stats {
        gap: 2rem;
        margin-bottom: 1.5rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    /* 调整游戏板大小 */
    .game-board {
        margin-bottom: 1.5rem;
    }

    /* 移动端显示控制按钮 */
    .mobile-controls {
        display: grid !important;
    }

    /* 隐藏桌面端提示文字 */
    .section-title p {
        display: none;
    }

    /* 按钮尺寸适配小屏幕 */
    .btn {
        padding: 0.6rem 1.5rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .cell {
        width: 14px;
        height: 14px;
    }

    .mobile-controls {
        grid-template-columns: repeat(3, 50px);
        grid-template-rows: repeat(3, 50px);
        gap: 6px;
        bottom: 15px;
        right: 15px;
    }

    .control-btn {
        font-size: 1.5rem;
    }

    .game-stats {
        flex-direction: column;
        gap: 1rem;
    }

    .leaderboard {
        max-width: 100%;
        margin-top: 1rem;
    }
}
@media (max-width: 768px) {
    .mobile-controls {
        gap: 12px; /* ✅ 增大按钮间距，避免误触 */
        bottom: 30px; /* ✅ 提高位置，更易于拇指操作 */
        right: 30px;
    }
}

@media (max-width: 480px) {
    .mobile-controls {
        gap: 10px;
        bottom: 20px;
        right: 20px;
    }
}

/* 防止页面滚动 */
body {
    overflow-x: hidden;
    overscroll-behavior-y: none;
}

/* 游戏区域触摸优化 */
.game-board {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 2.5rem;
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
}

.back-link:hover {
    gap: 0.8rem;
    color: #00a8e8;
}

/* ==================== 玩家统计信息 ==================== */
.player-stats {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    gap: 1rem;
}

/* 高亮当前用户条目 */
.leaderboard-item.current-user {
    border: 1px solid var(--accent-color);
    background: rgba(0, 198, 255, 0.1);
    position: relative;
}

.leaderboard-item.current-user::after {
    content: "我";
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent-color);
    font-weight: bold;
    font-size: 0.8rem;
}

/* 统计项样式微调 */
.player-stats .stat-item {
    margin-bottom: 0;
}

.player-stats .stat-label {
    font-size: 0.8rem;
}

.player-stats .stat-value {
    font-size: 1.5rem;
}

/* 移动端适配 */
@media (max-width: 480px) {
    .player-stats {
        flex-direction: column;
        gap: 0.5rem;
    }

    .player-stats .stat-value {
        font-size: 1.2rem;
    }
}