/* 颜色变量 */
:root {
    /* 背景颜色 */
    --bg-main: #faf8ef;
    --bg-board: #bbada0;
    --bg-cell: rgba(238, 228, 218, 0.35);
    --bg-message: rgba(238, 228, 218, 0.73);
    --bg-message-win: rgba(237, 194, 46, 0.5);
    
    /* 文本颜色 */
    --text-main: #776e65;
    --text-light: white;
    --text-tile-light: #f9f6f2;
    --theme-toggle-color: #ffa500;
    
    /* 按钮颜色 */
    --btn-bg: #8f7a66;
    --btn-hover: #9f8b77;
    
    /* 方块颜色 */
    --tile-2: #eee4da;
    --tile-4: #ede0c8;
    --tile-8: #f2b179;
    --tile-16: #f59563;
    --tile-32: #f67c5f;
    --tile-64: #f65e3b;
    --tile-128: #edcf72;
    --tile-256: #edcc61;
    --tile-512: #edc850;
    --tile-1024: #edc53f;
    --tile-2048: #edc22e;
    --tile-super: #3c3a32;
}

/* 深色模式颜色变量 */
[data-theme="dark"] {
    /* 背景颜色 */
    --bg-main: #1a1a1a;
    --bg-board: #2c2c2c;
    --bg-cell: rgba(50, 50, 50, 0.35);
    --bg-message: rgba(50, 50, 50, 0.73);
    --bg-message-win: rgba(237, 194, 46, 0.3);
    
    /* 文本颜色 */
    --text-main: #e0e0e0;
    --text-light: #ffffff;
    --text-tile-light: #f9f6f2;
    --theme-toggle-color: #f1c40f;
    
    /* 按钮颜色 */
    --btn-bg: #4a4a4a;
    --btn-hover: #5a5a5a;
    
    /* 方块颜色 */
    --tile-2: #3d3d3d;
    --tile-4: #4d4d4d;
    --tile-8: #b35900;
    --tile-16: #cc5200;
    --tile-32: #e64d00;
    --tile-64: #ff471a;
    --tile-128: #ccad00;
    --tile-256: #e6c200;
    --tile-512: #ffd700;
    --tile-1024: #ffdb1a;
    --tile-2048: #ffdf33;
    --tile-super: #1a1a1a;
}

/* 全局样式 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    touch-action: none;
}

/* 控制按钮共用样式 */
.control-button {
    position: fixed;
    top: 20px;
    background: var(--btn-bg);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 20px;
    z-index: 1000;
    transition: background-color 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.control-button:hover {
    background: var(--btn-hover);
}

/* 返回按钮 */
#back-button {
    left: 20px;
    color: var(--text-light);
}

/* 主题切换按钮 */
#theme-button {
    right: 20px;
    color: var(--theme-toggle-color);
}

.game-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 5px;
}

/* 标题和分数区域 */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

h1 {
    font-size: 60px;
    font-weight: bold;
    margin: 0;
    color: var(--text-main);
}

.scores-container {
    display: flex;
    gap: 10px;
}

.score-container, .best-container {
    position: relative;
    background: var(--bg-board);
    padding: 10px 15px;
    border-radius: 3px;
    color: var(--text-light);
    text-align: center;
    min-width: 80px;
}

.score-label {
    font-size: 14px;
    text-transform: uppercase;
}

#score, #best-score {
    font-size: 20px;
    font-weight: bold;
}

/* 默认隐藏所有指南 */
.pc-instruction, .mobile-instruction {
    display: none;
}

/* 媒体查询：在PC端显示PC指南 */
@media (hover: hover) and (pointer: fine) {
    .pc-instruction {
        display: block;
    }
}

/* 媒体查询：在移动端显示移动端指南 */
@media (hover: none) and (pointer: coarse) {
    .mobile-instruction {
        display: block;
    }
}

/* 控制按钮 */
.controls {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.button {
    background: var(--btn-bg);
    border-radius: 3px;
    padding: 10px 20px;
    color: var(--text-light);
    border: none;
    font-weight: bold;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
}

.button:hover {
    background: var(--btn-hover);
}

/* 游戏板 */
.game-board {
    position: relative;
    background: var(--bg-board);
    border-radius: 6px;
    width: 100%;
    aspect-ratio: 1 / 1;
    padding: 15px;
    margin-bottom: 0px;
    margin-left: auto;
    margin-right: auto;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 15px;
}

.grid-cell {
    background: var(--bg-cell);
    border-radius: 3px;
    width: 100%;
    height: 100%;
    position: relative;
}

.tile {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 3px;
    font-weight: bold;
    font-size: 35px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.1s ease-in-out;
}

/* 不同数值的方块颜色 */
.tile-2 {
    background: var(--tile-2);
    color: var(--text-main);
}

.tile-4 {
    background: var(--tile-4);
    color: var(--text-main);
}

.tile-8 {
    background: var(--tile-8);
    color: var(--text-tile-light);
}

.tile-16 {
    background: var(--tile-16);
    color: var(--text-tile-light);
}

.tile-32 {
    background: var(--tile-32);
    color: var(--text-tile-light);
}

.tile-64 {
    background: var(--tile-64);
    color: var(--text-tile-light);
}

.tile-128 {
    background: var(--tile-128);
    color: var(--text-tile-light);
    font-size: 30px;
}

.tile-256 {
    background: var(--tile-256);
    color: var(--text-tile-light);
    font-size: 30px;
}

.tile-512 {
    background: var(--tile-512);
    color: var(--text-tile-light);
    font-size: 30px;
}

.tile-1024 {
    background: var(--tile-1024);
    color: var(--text-tile-light);
    font-size: 25px;
}

.tile-2048 {
    background: var(--tile-2048);
    color: var(--text-tile-light);
    font-size: 25px;
}

.tile-super {
    background: var(--tile-super);
    color: var(--text-tile-light);
    font-size: 20px;
}

/* 游戏介绍 */
.game-intro {
    margin-top: 12px;
    text-align: center;
}

.game-intro p {
    line-height: 1.5;
}

/* 游戏消息 */
.game-message {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-message);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 6px;
}

.game-message p {
    font-size: 30px;
    font-weight: bold;
    margin-bottom: 20px;
}

.game-message-buttons {
    display: flex;
    gap: 10px;
}

.game-message.game-won {
    background: var(--bg-message-win);
    color: var(--text-tile-light);
    display: flex;
}

.game-message.game-over {
    background: var(--bg-message);
    color: var(--text-main);
    display: flex;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .game-container {
        padding: 10px;
        max-width: 768px;
        width: 100%;
        margin: 0 auto;
    }

    h1 {
        font-size: 40px;
    }

    .game-board {
        padding: 10px;
        gap: 10px;
    }

    .tile {
        font-size: 25px;
    }

    .tile-128, .tile-256, .tile-512 {
        font-size: 20px;
    }

    .tile-1024, .tile-2048 {
        font-size: 18px;
    }

    .tile-super {
        font-size: 16px;
    }
}

/* 动画效果 */
@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.tile-new {
    animation: appear 200ms ease-in-out;
}

@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

.tile-merged {
    animation: pop 200ms ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.tile-new {
    animation: fadeIn 200ms ease-in-out;
}