* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: #faf8ef;
    color: #776e65;
}

.container {
    width: 468px;
    margin: 0 auto;
    padding-top: 40px;
}

/* 响应式设计 */
@media screen and (max-width: 500px) {
    .container {
        width: 90vw;
        padding-top: 20px;
    }
    
    h1 {
        font-size: 60px;
        text-align: center;
    }
    
    .score-container {
        justify-content: center;
        gap: 20px;
    }
    
    .game-container {
        width: 90vw;
        height: 90vw;
        max-width: 468px;
        max-height: 468px;
        margin: 0 auto;
    }
    
    .grid-container {
        width: calc(90vw - 30px);
        height: calc(90vw - 30px);
        max-width: 438px;
        max-height: 438px;
    }
    
    .tile-container {
        width: calc(90vw - 30px);
        height: calc(90vw - 30px);
        max-width: 438px;
        max-height: 438px;
    }
    
    .grid-cell {
        width: calc((90vw - 30px - 36px) / 4);
        height: calc((90vw - 30px - 36px) / 4);
        max-width: 100px;
        max-height: 100px;
        margin: 4.5px;
    }
    
    .tile {
        width: calc((90vw - 30px - 36px) / 4);
        height: calc((90vw - 30px - 36px) / 4);
        max-width: 100px;
        max-height: 100px;
        font-size: 14px;
    }
    
    .grid-cell:nth-child(1) { top: 0; left: 0; }
    .grid-cell:nth-child(2) { top: 0; left: calc((90vw - 30px - 36px) / 4 + 9px); }
    .grid-cell:nth-child(3) { top: 0; left: calc(((90vw - 30px - 36px) / 4 + 9px) * 2); }
    .grid-cell:nth-child(4) { top: 0; left: calc(((90vw - 30px - 36px) / 4 + 9px) * 3); }
    
    .grid-cell:nth-child(5) { top: calc((90vw - 30px - 36px) / 4 + 9px); left: 0; }
    .grid-cell:nth-child(6) { top: calc((90vw - 30px - 36px) / 4 + 9px); left: calc((90vw - 30px - 36px) / 4 + 9px); }
    .grid-cell:nth-child(7) { top: calc((90vw - 30px - 36px) / 4 + 9px); left: calc(((90vw - 30px - 36px) / 4 + 9px) * 2); }
    .grid-cell:nth-child(8) { top: calc((90vw - 30px - 36px) / 4 + 9px); left: calc(((90vw - 30px - 36px) / 4 + 9px) * 3); }
    
    .grid-cell:nth-child(9) { top: calc(((90vw - 30px - 36px) / 4 + 9px) * 2); left: 0; }
    .grid-cell:nth-child(10) { top: calc(((90vw - 30px - 36px) / 4 + 9px) * 2); left: calc((90vw - 30px - 36px) / 4 + 9px); }
    .grid-cell:nth-child(11) { top: calc(((90vw - 30px - 36px) / 4 + 9px) * 2); left: calc(((90vw - 30px - 36px) / 4 + 9px) * 2); }
    .grid-cell:nth-child(12) { top: calc(((90vw - 30px - 36px) / 4 + 9px) * 2); left: calc(((90vw - 30px - 36px) / 4 + 9px) * 3); }
    
    .grid-cell:nth-child(13) { top: calc(((90vw - 30px - 36px) / 4 + 9px) * 3); left: 0; }
    .grid-cell:nth-child(14) { top: calc(((90vw - 30px - 36px) / 4 + 9px) * 3); left: calc((90vw - 30px - 36px) / 4 + 9px); }
    .grid-cell:nth-child(15) { top: calc(((90vw - 30px - 36px) / 4 + 9px) * 3); left: calc(((90vw - 30px - 36px) / 4 + 9px) * 2); }
    .grid-cell:nth-child(16) { top: calc(((90vw - 30px - 36px) / 4 + 9px) * 3); left: calc(((90vw - 30px - 36px) / 4 + 9px) * 3); }
}

h1 {
    font-size: 80px;
    font-weight: bold;
    margin-bottom: 20px;
}

.score-container {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.score-box {
    background-color: #bbada0;
    color: white;
    padding: 10px 20px;
    border-radius: 3px;
    text-align: center;
    min-width: 100px;
}

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

.score {
    font-size: 24px;
    font-weight: bold;
}

.game-container {
    position: relative;
    width: 468px;
    height: 468px;
    background-color: #bbada0;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 20px;
}

.grid-container {
    position: absolute;
    width: 438px;
    height: 438px;
    z-index: 1;
}

.grid-cell {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 3px;
    background-color: #cdc1b4;
    margin: 9px;
}

/* 默认网格单元格位置 */
.grid-cell:nth-child(1) { top: 0; left: 0; }
.grid-cell:nth-child(2) { top: 0; left: 118px; }
.grid-cell:nth-child(3) { top: 0; left: 236px; }
.grid-cell:nth-child(4) { top: 0; left: 354px; }

.grid-cell:nth-child(5) { top: 118px; left: 0; }
.grid-cell:nth-child(6) { top: 118px; left: 118px; }
.grid-cell:nth-child(7) { top: 118px; left: 236px; }
.grid-cell:nth-child(8) { top: 118px; left: 354px; }

.grid-cell:nth-child(9) { top: 236px; left: 0; }
.grid-cell:nth-child(10) { top: 236px; left: 118px; }
.grid-cell:nth-child(11) { top: 236px; left: 236px; }
.grid-cell:nth-child(12) { top: 236px; left: 354px; }

.grid-cell:nth-child(13) { top: 354px; left: 0; }
.grid-cell:nth-child(14) { top: 354px; left: 118px; }
.grid-cell:nth-child(15) { top: 354px; left: 236px; }
.grid-cell:nth-child(16) { top: 354px; left: 354px; }

.tile-container {
    position: absolute;
    z-index: 2;
    width: 438px;
    height: 438px;
}

.tile {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 3px;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.15s ease;
    text-align: center;
    word-wrap: break-word;
    padding: 5px;
}

.tile-2 {
    background-color: #eee4da;
    color: #776e65;
}

.tile-4 {
    background-color: #ede0c8;
    color: #776e65;
}

.tile-8 {
    background-color: #f2b179;
    color: white;
}

.tile-16 {
    background-color: #f59563;
    color: white;
}

.tile-32 {
    background-color: #f67c5f;
    color: white;
}

.tile-64 {
    background-color: #f65e3b;
    color: white;
}

.tile-128 {
    background-color: #edcf72;
    color: white;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.31746), inset 0 0 0 1px rgba(255, 255, 255, 0.19048);
}

.tile-256 {
    background-color: #edcc61;
    color: white;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.39683), inset 0 0 0 1px rgba(255, 255, 255, 0.2381);
}

.tile-512 {
    background-color: #edc850;
    color: white;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.47619), inset 0 0 0 1px rgba(255, 255, 255, 0.28571);
}

.tile-1024 {
    background-color: #edc53f;
    color: white;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.55556), inset 0 0 0 1px rgba(255, 255, 255, 0.33333);
}

.tile-2048 {
    background-color: #edc22e;
    color: white;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.63492), inset 0 0 0 1px rgba(255, 255, 255, 0.38095);
}

.game-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.73);
    z-index: 100;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    text-align: center;
    border-radius: 6px;
}

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

.retry-button {
    background-color: #8f7a66;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    border-radius: 3px;
    cursor: pointer;
}

.retry-button:hover {
    background-color: #9f8b77;
}

.game-intro {
    margin-top: 20px;
    font-size: 14px;
    line-height: 1.5;
}

.tile-new {
    animation: appear 0.2s ease-in-out;
}

.tile-merged {
    animation: merge 0.2s ease-in-out;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

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