* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #faf8ef 0%, #f4f1e8 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    touch-action: none;
}

.header {
    text-align: center;
    margin-bottom: 20px;
}

h1 {
    color: #776e65;
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.score-container {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-bottom: 20px;
}

.score-box {
    background: #bbada0;
    padding: 10px 20px;
    border-radius: 6px;
    color: white;
    min-width: 100px;
}

.score-label {
    font-size: 12px;
    text-transform: uppercase;
    color: #eee4da;
    margin-bottom: 5px;
}

.score-value {
    font-size: 24px;
    font-weight: bold;
    color: white;
}

.controls {
    margin-bottom: 20px;
}

button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

button:hover {
    background: #9f8a76;
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

button:active {
    transform: translateY(0);
}

.game-container {
    position: relative;
    background: #bbada0;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    user-select: none;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 100px);
    grid-template-rows: repeat(4, 100px);
    gap: 10px;
    position: relative;
}

.grid-cell {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 6px;
    width: 100px;
    height: 100px;
}

.tile-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 10px;
    pointer-events: none;
}

.tile {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 35px;
    font-weight: bold;
    z-index: 10;
    transition: transform 0.15s ease-in-out;
    will-change: transform;
}

.tile-inner {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    background: #eee4da;
    color: #776e65;
    transition: all 0.15s ease;
}

/* 新方块出现的缩放动画 */
@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.tile-new .tile-inner {
    animation: appear 0.2s ease-in-out backwards;
}

/* 合并时的弹跳动画 */
@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.tile-merged .tile-inner {
    animation: pop 0.2s ease-in-out;
    z-index: 20;
}

/* 不同数字的颜色 */
.tile-2 .tile-inner {
    background: #eee4da;
    color: #776e65;
}

.tile-4 .tile-inner {
    background: #ede0c8;
    color: #776e65;
}

.tile-8 .tile-inner {
    background: #f2b179;
    color: #f9f6f2;
}

.tile-16 .tile-inner {
    background: #f59563;
    color: #f9f6f2;
}

.tile-32 .tile-inner {
    background: #f67c5f;
    color: #f9f6f2;
}

.tile-64 .tile-inner {
    background: #f65e3b;
    color: #f9f6f2;
}

.tile-128 .tile-inner {
    background: #edcf72;
    color: #f9f6f2;
    font-size: 30px;
    box-shadow: 0 0 10px rgba(243, 215, 116, 0.3);
}

.tile-256 .tile-inner {
    background: #edcc61;
    color: #f9f6f2;
    font-size: 30px;
    box-shadow: 0 0 15px rgba(243, 215, 116, 0.4);
}

.tile-512 .tile-inner {
    background: #edc850;
    color: #f9f6f2;
    font-size: 30px;
    box-shadow: 0 0 20px rgba(243, 215, 116, 0.5);
}

.tile-1024 .tile-inner {
    background: #edc53f;
    color: #f9f6f2;
    font-size: 25px;
    box-shadow: 0 0 25px rgba(243, 215, 116, 0.6);
}

.tile-2048 .tile-inner {
    background: #edc22e;
    color: #f9f6f2;
    font-size: 25px;
    box-shadow: 0 0 30px rgba(243, 215, 116, 0.7);
    animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 30px rgba(243, 215, 116, 0.7);
    }
    50% {
        box-shadow: 0 0 50px rgba(243, 215, 116, 1);
    }
}

.game-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.9);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.game-message.visible {
    opacity: 1;
    visibility: visible;
}

.game-message p {
    font-size: 48px;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 20px;
}

.game-message.game-won p {
    color: #edc22e;
}

.instructions {
    margin-top: 20px;
    color: #776e65;
    text-align: center;
    line-height: 1.6;
}

.instructions strong {
    color: #8f7a66;
}

/* 移动端适配 */
@media (max-width: 500px) {
    .grid-container {
        grid-template-columns: repeat(4, 70px);
        grid-template-rows: repeat(4, 70px);
        gap: 8px;
    }

    .grid-cell, .tile {
        width: 70px;
        height: 70px;
    }

    .tile {
        font-size: 25px;
    }

    .tile-128 .tile-inner, .tile-256 .tile-inner, .tile-512 .tile-inner {
        font-size: 22px;
    }

    .tile-1024 .tile-inner, .tile-2048 .tile-inner {
        font-size: 18px;
    }

    h1 {
        font-size: 36px;
    }
}

.animating {
    pointer-events: none;
}