/* 基础样式 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Helvetica Neue", Arial, sans-serif;
    background-color: #faf8ef;
    color: #776e65;
    margin: 0;
    padding: 0;
    font-size: 18px;
}

.container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
}

/* 标题和分数区域 */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

h1 {
    font-size: 80px;
    font-weight: bold;
    margin: 0;
    color: #776e65;
}

.scores-container {
    display: flex;
    gap: 10px;
}

.score-container, .best-container {
    position: relative;
    background: #bbada0;
    padding: 10px 15px;
    border-radius: 3px;
    color: white;
    text-align: center;
    min-width: 80px;
}

.score-label {
    font-size: 14px;
    text-transform: uppercase;
}

#score, #best-score {
    font-size: 24px;
    font-weight: bold;
}

/* 游戏介绍区域 */
.game-intro {
    margin-bottom: 20px;
}

button {
    background: #8f7a66;
    border-radius: 3px;
    padding: 10px 20px;
    font-size: 18px;
    font-weight: bold;
    color: white;
    border: none;
    cursor: pointer;
    margin-top: 10px;
    transition: all 0.2s ease;
}

button:hover {
    background: #9f8b77;
}

/* 游戏容器 */
.game-container {
    position: relative;
    background: #bbada0;
    border-radius: 6px;
    width: 100%;
    height: 0;
    padding-bottom: 100%; /* 保持正方形 */
    margin-bottom: 20px;
}

/* 游戏消息 */
.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(238, 228, 218, 0.73);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    animation: fade-in 800ms ease;
}

.game-message p {
    font-size: 60px;
    font-weight: bold;
    margin-bottom: 20px;
}

.game-message.game-won {
    background: rgba(237, 194, 46, 0.5);
    color: #f9f6f2;
    display: flex;
}

.game-message.game-over {
    background: rgba(238, 228, 218, 0.73);
    display: flex;
}

/* 网格容器 */
.grid-container {
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    display: flex;
    flex-direction: column;
}

.grid-row {
    display: flex;
    flex: 1;
    margin-bottom: 15px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: calc(25% - 15px);
    height: 100%;
    margin-right: 15px;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 3px;
}

.grid-cell:last-child {
    margin-right: 0;
}

/* 方块容器 */
.tile-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    padding: 15px;
}

/* 方块样式 */
.tile {
    position: absolute;
    width: calc(25% - 15px);
    height: calc(25% - 15px);
    border-radius: 3px;
    background: #eee4da;
    text-align: center;
    font-weight: bold;
    z-index: 10;
    transition: top 100ms ease, left 100ms ease, opacity 100ms ease;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 35px;
    margin: 0;
    padding: 0;
}

/* 不同数值方块的颜色 */
.tile-2 {
    background: #eee4da;
    color: #776e65;
}

.tile-4 {
    background: #ede0c8;
    color: #776e65;
}

.tile-8 {
    background: #f2b179;
    color: #f9f6f2;
}

.tile-16 {
    background: #f59563;
    color: #f9f6f2;
}

.tile-32 {
    background: #f67c5f;
    color: #f9f6f2;
}

.tile-64 {
    background: #f65e3b;
    color: #f9f6f2;
}

.tile-128 {
    background: #edcf72;
    color: #f9f6f2;
    font-size: 30px;
}

.tile-256 {
    background: #edcc61;
    color: #f9f6f2;
    font-size: 30px;
}

.tile-512 {
    background: #edc850;
    color: #f9f6f2;
    font-size: 30px;
}

.tile-1024 {
    background: #edc53f;
    color: #f9f6f2;
    font-size: 25px;
}

.tile-2048 {
    background: #edc22e;
    color: #f9f6f2;
    font-size: 25px;
}

/* 新方块动画 */
.tile-new {
    animation: appear 200ms ease;
}

/* 合并方块动画 */
.tile-merged {
    z-index: 20;
    animation: pop 200ms ease;
}

/* 游戏说明 */
.game-explanation {
    margin-top: 20px;
    line-height: 1.5;
}

/* 动画效果 */
@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pop {
    0% {
        transform: scale(0.8);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes fade-in {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

/* 响应式设计 */
@media screen and (max-width: 520px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 50px;
    }

    .game-container {
        margin-bottom: 10px;
    }

    .tile {
        font-size: 25px;
    }

    .tile-128, .tile-256, .tile-512 {
        font-size: 20px;
    }

    .tile-1024, .tile-2048 {
        font-size: 15px;
    }
}