body {
    margin: 0;
    padding: 0;
    background-color: #faf8ef;
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px;
    box-sizing: border-box;
}

.game-container {
    text-align: center;
    padding: 10px;
    max-width: 500px;
    width: 100%;
}

header {
    margin-bottom: 15px;
}

h1 {
    font-size: 3rem;
    font-weight: bold;
    color: #776e65;
    margin: 0 0 15px 0;
}

.score-container {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.score-box {
    background-color: #bbada0;
    padding: 8px 16px;
    border-radius: 3px;
    color: white;
    min-width: 60px;
    flex: 1;
    max-width: 120px;
}

.score-label {
    font-size: 11px;
    text-transform: uppercase;
    margin-bottom: 3px;
}

#score, #best-score {
    font-size: 18px;
    font-weight: bold;
}

.grid-container {
    background-color: #bbada0;
    border-radius: 5px;
    position: relative;
    padding: 8px;
    margin: 0 auto;
    width: 90vw;
    max-width: 320px;
    height: 90vw;
    max-height: 320px;
    box-sizing: border-box;
}

.grid-cell {
    width: calc(22.5% - 4px);
    height: calc(22.5% - 4px);
    background-color: #cdc1b4;
    border-radius: 3px;
    position: absolute;
    margin: 2px;
}

.tile {
    position: absolute;
    width: calc(22.5% - 4px);
    height: calc(22.5% - 4px);
    background-color: #eee4da;
    border-radius: 3px;
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.15s ease-in-out;
    line-height: 1;
    margin: 2px;
    box-sizing: border-box;
}

/* 根据屏幕宽度调整网格位置 */
@media (max-width: 480px) {
    .grid-cell:nth-child(1) { left: 2px; top: 2px; }
    .grid-cell:nth-child(2) { left: calc(25% + 2px); top: 2px; }
    .grid-cell:nth-child(3) { left: calc(50% + 2px); top: 2px; }
    .grid-cell:nth-child(4) { left: calc(75% + 2px); top: 2px; }
    .grid-cell:nth-child(5) { left: 2px; top: calc(25% + 2px); }
    .grid-cell:nth-child(6) { left: calc(25% + 2px); top: calc(25% + 2px); }
    .grid-cell:nth-child(7) { left: calc(50% + 2px); top: calc(25% + 2px); }
    .grid-cell:nth-child(8) { left: calc(75% + 2px); top: calc(25% + 2px); }
    .grid-cell:nth-child(9) { left: 2px; top: calc(50% + 2px); }
    .grid-cell:nth-child(10) { left: calc(25% + 2px); top: calc(50% + 2px); }
    .grid-cell:nth-child(11) { left: calc(50% + 2px); top: calc(50% + 2px); }
    .grid-cell:nth-child(12) { left: calc(75% + 2px); top: calc(50% + 2px); }
    .grid-cell:nth-child(13) { left: 2px; top: calc(75% + 2px); }
    .grid-cell:nth-child(14) { left: calc(25% + 2px); top: calc(75% + 2px); }
    .grid-cell:nth-child(15) { left: calc(50% + 2px); top: calc(75% + 2px); }
    .grid-cell:nth-child(16) { left: calc(75% + 2px); top: calc(75% + 2px); }
}

.tile-2 { background-color: #eee4da; color: #776e65; }
.tile-4 { background-color: #ede0c8; color: #776e65; }
.tile-8 { background-color: #f2b179; color: #f9f6f2; }
.tile-16 { background-color: #f59563; color: #f9f6f2; }
.tile-32 { background-color: #f67c5f; color: #f9f6f2; }
.tile-64 { background-color: #f65e3b; color: #f9f6f2; }
.tile-128 { background-color: #edcf72; color: #f9f6f2; font-size: 1.3rem; }
.tile-256 { background-color: #edcc61; color: #f9f6f2; font-size: 1.3rem; }
.tile-512 { background-color: #edc850; color: #f9f6f2; font-size: 1.3rem; }
.tile-1024 { background-color: #edc53f; color: #f9f6f2; font-size: 1.1rem; }
.tile-2048 { background-color: #edc22e; color: #f9f6f2; font-size: 1.1rem; }

.tile-new {
    animation: appear 0.2s ease-in-out;
}

.tile-merged {
    animation: pop 0.2s ease-in-out;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.instructions {
    margin-top: 20px;
    color: #776e65;
    font-size: 14px;
}

.instructions p {
    margin-bottom: 8px;
}

button {
    background-color: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 3px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.3s;
    margin: 5px;
    touch-action: manipulation;
}

button:hover {
    background-color: #9f8a76;
}

button:active {
    transform: scale(0.95);
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 100;
    text-align: center;
    padding-top: 40%;
    box-sizing: border-box;
}

.game-message p {
    font-size: 2rem;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 15px;
}

.game-message.game-won p {
    color: #f9f6f2;
    background-color: #edc22e;
    display: inline-block;
    padding: 10px 20px;
    border-radius: 5px;
}

.game-message.game-over p {
    color: #776e65;
}

.back-link {
    margin-top: 15px;
}

.back-link a {
    color: #776e65;
    text-decoration: none;
    font-size: 14px;
    transition: color 0.3s;
}

.back-link a:hover {
    color: #8f7a66;
}

.ad-container {
    margin-top: 20px;
    min-height: 60px;
    background-color: #f0f0f0;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px dashed #ddd;
}

/* 移动端优化 */
@media (max-width: 480px) {
    .game-container {
        padding: 5px;
    }
    
    h1 {
        font-size: 2.5rem;
    }
    
    .score-container {
        gap: 8px;
        margin-bottom: 10px;
    }
    
    .score-box {
        padding: 6px 12px;
        min-width: 50px;
    }
    
    .score-label {
        font-size: 10px;
    }
    
    #score, #best-score {
        font-size: 16px;
    }
    
    .grid-container {
        width: 85vw;
        height: 85vw;
        max-width: 300px;
        max-height: 300px;
        padding: 6px;
    }
    
    .tile {
        font-size: 1.2rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 0.9rem;
    }
    
    .instructions {
        font-size: 12px;
        margin-top: 15px;
    }
    
    button {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .game-message p {
        font-size: 1.5rem;
    }
}

/* 极小屏幕优化 */
@media (max-width: 320px) {
    h1 {
        font-size: 2rem;
    }
    
    .grid-container {
        width: 90vw;
        height: 90vw;
        max-width: 280px;
        max-height: 280px;
        padding: 4px;
    }
    
    .tile {
        font-size: 1rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 0.9rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 0.8rem;
    }
}

/* 横屏优化 */
@media (orientation: landscape) and (max-height: 500px) {
    body {
        padding: 5px;
    }
    
    .game-container {
        padding: 5px;
    }
    
    h1 {
        font-size: 2rem;
        margin-bottom: 10px;
    }
    
    .score-container {
        margin-bottom: 10px;
    }
    
    .grid-container {
        width: 60vw;
        height: 60vw;
        max-width: 250px;
        max-height: 250px;
    }
    
    .instructions {
        margin-top: 10px;
        font-size: 11px;
    }
} 