/* 2048 - 简洁白色布局 + 暗色模式 */

/* ========== CSS 变量 ========== */
:root {
    /* 亮色主题 (默认) */
    --bg-body: #faf8ef;
    --bg-container: #ffffff;
    --bg-board: #bbada0;
    --bg-cell-empty: rgba(238, 228, 218, 0.35);
    --text-primary: #776e65;
    --text-secondary: #f9f6f2;
    --text-muted: #8f7a66;
    --accent: #8f7a66;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --button-bg: #8f7a66;
    --button-text: #f9f6f2;
    --button-hover-bg: #9f8b77;
    --toggle-bg: #ede0c8;
    --toggle-color: #776e65;
    --toggle-hover-bg: #e0d4bc;
    --border-color: #e0d8cc;
    --score-bg: #bbada0;
    --score-text: #ffffff;
}

[data-theme="dark"] {
    /* 暗色主题 */
    --bg-body: #1a1a2e;
    --bg-container: #22223a;
    --bg-board: #2d2d50;
    --bg-cell-empty: rgba(255, 255, 255, 0.06);
    --text-primary: #e0e0e0;
    --text-secondary: #ffffff;
    --text-muted: #a0a0c0;
    --accent: #7eb8ff;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --button-bg: #3a6fd8;
    --button-text: #ffffff;
    --button-hover-bg: #4d82e8;
    --toggle-bg: #2d2d50;
    --toggle-color: #ffd700;
    --toggle-hover-bg: #3a3a60;
    --border-color: #3a3a60;
    --score-bg: #2d2d50;
    --score-text: #ffffff;
}

/* ========== 全局过渡 ========== */
*,
*::before,
*::after {
    transition: background-color 0.4s ease, color 0.35s ease,
                box-shadow 0.4s ease, border-color 0.4s ease,
                fill 0.4s ease, stroke 0.4s ease;
}

/* ========== 基础样式 ========== */
body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: var(--bg-body);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Microsoft YaHei", Arial, sans-serif;
    color: var(--text-primary);
    padding: 20px;
    box-sizing: border-box;
}

/* ========== 主容器 ========== */
.container {
    position: relative;
    max-width: 520px;
    width: 100%;
    text-align: center;
    padding: 32px 28px 28px;
    background-color: var(--bg-container);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
}

/* ========== 语言切换按钮 ========== */
.lang-toggle {
    position: absolute;
    top: 16px;
    left: 16px;
    height: 40px;
    padding: 0 14px;
    border: none;
    border-radius: 20px;
    background: var(--toggle-bg);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    line-height: 1;
    z-index: 10;
    letter-spacing: 0.5px;
}

.lang-toggle:hover {
    background: var(--toggle-hover-bg);
    transform: scale(1.05);
}

.lang-toggle:active {
    transform: scale(0.95);
}

/* ========== 右上角按钮组 ========== */
.top-actions {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

/* ========== 音乐控制 ========== */
.music-control {
    position: relative;
    display: flex;
    align-items: center;
}

.music-toggle {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--toggle-bg);
    color: var(--toggle-color);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    line-height: 1;
}

.music-toggle:hover {
    background: var(--toggle-hover-bg);
    transform: scale(1.08);
}

.music-toggle:active {
    transform: scale(0.95);
}

/* 音量滑块 */
.volume-slider {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    opacity: 0;
    pointer-events: none;
    background: var(--bg-container);
    border-radius: 20px;
    padding: 10px 6px;
    box-shadow: var(--shadow-md);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.music-control:hover .volume-slider,
.volume-slider:hover {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.volume-slider input[type="range"] {
    writing-mode: vertical-lr;
    direction: rtl;
    appearance: slider-vertical;
    height: 100px;
    width: 24px;
    cursor: pointer;
    accent-color: var(--accent);
    background: transparent;
    border: none;
    outline: none;
}

.volume-label {
    display: block;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 6px;
    letter-spacing: 0.5px;
}

/* ========== 主题切换按钮 ========== */
.theme-toggle {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--toggle-bg);
    color: var(--toggle-color);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    line-height: 1;
}

.theme-toggle:hover {
    background: var(--toggle-hover-bg);
    transform: scale(1.08);
}

.theme-toggle:active {
    transform: scale(0.95);
}

/* ========== 标题 ========== */
h1 {
    color: var(--text-primary);
    font-size: 42px;
    font-weight: 800;
    margin: 0 0 8px;
    letter-spacing: 2px;
}

/* ========== 游戏描述 ========== */
.game-description {
    font-size: 14px;
    line-height: 1.6;
    margin: 0 auto 24px;
    color: var(--text-muted);
    max-width: 420px;
}

/* ========== 游戏面板 ========== */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* ========== 分数面板 ========== */
.score-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 340px;
}

.score {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--score-bg);
    border-radius: 8px;
    padding: 6px 18px;
    min-width: 70px;
}

.score p:first-child {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0;
    color: rgba(255, 255, 255, 0.7);
}

.score p:last-child {
    font-size: 22px;
    font-weight: 700;
    margin: 0;
    color: var(--score-text);
}

/* ========== 新游戏按钮 ========== */
#newGameBtn {
    margin-top: 16px;
    padding: 10px 24px;
    background: var(--button-bg);
    border: none;
    border-radius: 8px;
    color: var(--button-text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.5px;
}

#newGameBtn:hover {
    background: var(--button-hover-bg);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

#newGameBtn:active {
    transform: translateY(0);
}

/* ========== 游戏棋盘 ========== */
#gameBoard {
    display: grid;
    grid-template-columns: repeat(4, 70px);
    grid-template-rows: repeat(4, 70px);
    grid-gap: 10px;
    padding: 10px;
    background: var(--bg-board);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

/* ========== 单元格基础样式 ========== */
.cell {
    width: 70px;
    height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 26px;
    font-weight: 700;
    background: var(--bg-cell-empty);
    border-radius: 6px;
    color: var(--text-primary);
    animation: cellAppear 0.2s ease-out;
}

/* ========== 单元格数值颜色 (经典2048配色) ========== */
.cell[data-value="0"] {
    background: var(--bg-cell-empty);
    color: transparent;
}

.cell[data-value="2"]    { background: #eee4da; color: #776e65; }
.cell[data-value="4"]    { background: #ede0c8; color: #776e65; }
.cell[data-value="8"]    { background: #f2b179; color: #f9f6f2; }
.cell[data-value="16"]   { background: #f59563; color: #f9f6f2; }
.cell[data-value="32"]   { background: #f67c5f; color: #f9f6f2; }
.cell[data-value="64"]   { background: #f65e3b; color: #f9f6f2; }
.cell[data-value="128"]  { background: #edcf72; color: #f9f6f2; font-size: 22px; }
.cell[data-value="256"]  { background: #edcc61; color: #f9f6f2; font-size: 22px; }
.cell[data-value="512"]  { background: #edc850; color: #f9f6f2; font-size: 22px; }
.cell[data-value="1024"] { background: #edc53f; color: #f9f6f2; font-size: 20px; }
.cell[data-value="2048"] { background: #edc22e; color: #f9f6f2; font-size: 20px; }

/* 超大数值 */
.cell[data-value]:not([data-value="0"]):not([data-value="2"]):not([data-value="4"]):not([data-value="8"]):not([data-value="16"]):not([data-value="32"]):not([data-value="64"]):not([data-value="128"]):not([data-value="256"]):not([data-value="512"]):not([data-value="1024"]):not([data-value="2048"]) {
    background: #3c3a32;
    color: #f9f6f2;
    font-size: 18px;
    box-shadow: 0 0 20px rgba(237, 194, 46, 0.5);
}

/* ========== 动画 ========== */
@keyframes cellAppear {
    0%   { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes cellMerge {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ========== 响应式 ========== */
@media (max-width: 480px) {
    .container {
        padding: 20px 12px 16px;
    }

    h1 {
        font-size: 32px;
    }

    #gameBoard {
        grid-template-columns: repeat(4, 60px);
        grid-template-rows: repeat(4, 60px);
        grid-gap: 8px;
        padding: 8px;
    }

    .cell {
        width: 60px;
        height: 60px;
        font-size: 22px;
    }

    .cell[data-value="128"],
    .cell[data-value="256"],
    .cell[data-value="512"] { font-size: 18px; }
    .cell[data-value="1024"],
    .cell[data-value="2048"] { font-size: 16px; }

    .score-panel {
        justify-content: center;
    }

    #newGameBtn {
        margin-top: 12px;
        padding: 8px 20px;
        font-size: 13px;
    }
}
