/**
 * 贪吃蛇游戏样式表
 * 响应式设计，支持桌面端和移动端
 */

/* ========================================
   CSS 变量定义
   ======================================== */
:root {
    --primary-color: #4CAF50;
    --primary-dark: #388E3C;
    --secondary-color: #FF9800;
    --danger-color: #f44336;
    --bg-color: #1a1a2e;
    --bg-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --canvas-bg: #0f0f23;
    --text-color: #ffffff;
    --text-muted: #a0a0a0;
    --border-color: #2a2a4e;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --snake-color: #4CAF50;
    --snake-head-color: #66BB6A;
    --food-color: #FF5252;
    --grid-line-color: rgba(255, 255, 255, 0.05);
}

/* ========================================
   基础样式重置
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* ========================================
   游戏主容器
   ======================================== */
.game-container {
    max-width: 640px;
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px var(--shadow-color);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
}

/* ========================================
   游戏标题
   ======================================== */
.game-header {
    text-align: center;
    margin-bottom: 25px;
}

.game-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 5px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.game-header .subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 300;
}

/* ========================================
   信息面板（分数显示）
   ======================================== */
.info-panel {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.score-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
}

.score-board .label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.score-board .score {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
}

.score-board .high-score {
    color: var(--secondary-color);
}

/* ========================================
   画布容器
   ======================================== */
.canvas-wrapper {
    position: relative;
    margin: 0 auto 20px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 30px var(--shadow-color);
    border: 3px solid var(--border-color);
}

#gameCanvas {
    display: block;
    background: var(--canvas-bg);
    width: 100%;
    height: auto;
    max-width: 600px;
}

/* ========================================
   游戏覆盖层（开始/暂停/结束界面）
   ======================================== */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.game-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    padding: 30px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.overlay-content::-webkit-scrollbar {
    width: 6px;
}

.overlay-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.overlay-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.overlay-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 15px;
    color: var(--primary-color);
}

.overlay-content p {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 25px;
    line-height: 1.8;
}

/* ========================================
   固定底部按钮栏
   ======================================== */
.overlay-buttons {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px 30px;
    background: rgba(0, 0, 0, 0.6);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(10px);
}

.overlay-buttons .btn {
    margin: 0 5px;
    min-width: 140px;
}

/* ========================================
   难度选择界面样式
   ======================================== */
.difficulty-selector {
    margin-bottom: 20px;
    max-height: 280px;
    overflow-y: auto;
    padding: 10px;
}

.difficulty-selector::-webkit-scrollbar {
    width: 6px;
}

.difficulty-selector::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.difficulty-selector::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.difficulty-title,
.skin-title {
    font-size: 1.3rem;
    color: var(--text-color);
    margin-bottom: 15px;
    font-weight: 600;
}

.difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ========================================
   皮肤选择界面样式
   ======================================== */
.skin-selector {
    margin-bottom: 20px;
}

.skin-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
    max-height: 240px;
    overflow-y: auto;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.skin-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.skin-option:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-3px);
}

.skin-option.selected {
    border-color: var(--primary-color);
    background: rgba(76, 175, 80, 0.15);
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.3);
}

.skin-option.locked {
    opacity: 0.6;
    cursor: not-allowed;
    filter: grayscale(0.5);
}

.skin-option.locked:hover {
    transform: none;
}

.skin-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.skin-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-color);
    text-align: center;
    margin-bottom: 4px;
}

.skin-description {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 6px;
}

.skin-lock {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 1rem;
    opacity: 0.8;
}

.skin-progress {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 5px;
}

.skin-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s ease;
}

.skin-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
}

/* 皮肤选择器内的返回按钮（独立于底部按钮栏） */
#backToDifficultyBtn {
    margin-top: 10px;
    padding: 8px 20px;
    font-size: 0.95rem;
}

.preview-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

#previewCanvas {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

/* 皮肤选择器的滚动条样式 */
.skin-options::-webkit-scrollbar {
    width: 8px;
}

.skin-options::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.skin-options::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.skin-options::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

.difficulty-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    text-align: left;
    gap: 12px;
}

.difficulty-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(5px);
}

.difficulty-btn.selected {
    border-color: var(--primary-color);
    background: rgba(76, 175, 80, 0.15);
}

.difficulty-btn.easy:hover,
.difficulty-btn.easy.selected {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.2);
}

.difficulty-btn.hard:hover,
.difficulty-btn.hard.selected {
    border-color: #FF9800;
    background: rgba(255, 152, 0, 0.2);
}

.difficulty-btn.hell:hover,
.difficulty-btn.hell.selected {
    border-color: #f44336;
    background: rgba(244, 67, 54, 0.2);
}

.difficulty-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.difficulty-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    min-width: 60px;
}

.difficulty-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* ========================================
   难度显示（游戏进行中）
   ======================================== */
.difficulty-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 15px;
    padding: 8px 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.difficulty-label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.difficulty-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-color);
}

.difficulty-value.easy { color: #4CAF50; }
.difficulty-value.hard { color: #FF9800; }
.difficulty-value.hell { color: #f44336; }

/* ========================================
   按钮样式
   ======================================== */
.btn {
    padding: 12px 30px;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #F57C00;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 152, 0, 0.4);
}

.btn:active {
    transform: translateY(0);
}

/* ========================================
   移动端控制按钮
   ======================================== */
.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
    gap: 10px;
}

.control-row {
    display: flex;
    gap: 10px;
}

.control-btn {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--primary-color);
}

.control-btn:active {
    background: var(--primary-color);
    transform: scale(0.95);
}

/* ========================================
   游戏说明
   ======================================== */
.game-instructions {
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.game-instructions h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--primary-color);
}

.game-instructions ul {
    list-style: none;
    padding-left: 0;
}

.game-instructions li {
    margin-bottom: 10px;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.game-instructions li strong {
    color: var(--text-color);
}

/* ========================================
   键盘按键样式
   ======================================== */
kbd {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 8px;
    font-family: monospace;
    font-size: 0.9rem;
}

/* ========================================
   页脚
   ======================================== */
.game-footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

/* ========================================
   响应式设计 - 平板设备
   ======================================== */
@media screen and (max-width: 768px) {
    .game-container {
        padding: 20px;
    }

    .game-header h1 {
        font-size: 2rem;
    }

    #gameCanvas {
        max-width: 100%;
        height: auto;
    }

    .info-panel {
        padding: 10px;
    }

    .score-board .score {
        font-size: 1.5rem;
    }
}

/* ========================================
   响应式设计 - 移动设备
   ======================================== */
@media screen and (max-width: 480px) {
    body {
        padding: 10px;
    }

    .game-container {
        padding: 15px;
        border-radius: 15px;
    }

    .game-header h1 {
        font-size: 1.8rem;
    }

    .game-header .subtitle {
        font-size: 0.9rem;
    }

    .info-panel {
        flex-direction: row;
        justify-content: space-between;
    }

    .score-board {
        min-width: 80px;
    }

    .score-board .score {
        font-size: 1.3rem;
    }

    /* 显示移动端控制按钮 */
    .mobile-controls {
        display: flex;
    }

    .control-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    .overlay-content {
        padding: 20px;
        max-height: calc(100vh - 140px);
    }

    .overlay-content h2 {
        font-size: 1.5rem;
    }

    .overlay-content p {
        font-size: 0.9rem;
    }
    
    /* 移动端底部按钮栏优化 */
    .overlay-buttons {
        padding: 15px 20px;
    }
    
    .overlay-buttons .btn {
        min-width: 120px;
        padding: 10px 15px;
        font-size: 0.95rem;
    }

    .difficulty-btn {
        padding: 10px 15px;
    }

    .difficulty-icon {
        font-size: 1.2rem;
    }

    .difficulty-name {
        font-size: 1rem;
    }

    .difficulty-desc {
        font-size: 0.75rem;
    }

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

    .game-instructions {
        padding: 15px;
    }

    .game-instructions h3 {
        font-size: 1rem;
    }

    .game-instructions li {
        font-size: 0.85rem;
    }
}

/* ========================================
   动画效果
   ======================================== */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.btn-primary:hover {
    animation: pulse 0.6s ease-in-out;
}

/* ========================================
   无障碍辅助
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* 焦点样式（键盘导航） */
.btn:focus,
.control-btn:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    :root {
        --border-color: #ffffff;
        --text-muted: #ffffff;
    }
}
