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

body {
    font-family: 'Arial', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    background: #faf8ef;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 100%;
}

.header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.header h1 {
    font-size: 60px;
    font-weight: bold;
    color: #776e65;
    margin-right: auto;
}

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

.score-box {
    background: #bbada0;
    border-radius: 5px;
    padding: 10px 20px;
    text-align: center;
    min-width: 80px;
}

.score-label {
    color: #eee4da;
    font-size: 12px;
    text-transform: uppercase;
    font-weight: bold;
}

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

.new-game-btn {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.new-game-btn:hover {
    background: #9f8b77;
}

.game-container {
    position: relative;
    width: 100%;
    padding-bottom: 100%;
    margin-bottom: 20px;
}

.game-board {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #bbada0;
    border-radius: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    padding: 10px;
}

.grid-cell {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 5px;
}

.tile-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 35px;
    font-weight: bold;
    border-radius: 5px;
    transition: transform 0.15s ease;
    z-index: 10;
}

.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-super { background: #3c3a32; color: #f9f6f2; font-size: 25px; }

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

.tile-merged {
    animation: tile-pop 0.2s ease;
}

@keyframes tile-appear {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

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

.instructions {
    text-align: center;
    color: #776e65;
    margin-bottom: 20px;
    line-height: 1.6;
}

.leaderboard {
    background: #faf8ef;
    border: 2px solid #bbada0;
    border-radius: 10px;
    padding: 15px;
}

.leaderboard h2 {
    text-align: center;
    color: #776e65;
    margin-bottom: 15px;
}

.leaderboard-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#player-name {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #bbada0;
    border-radius: 5px;
    font-size: 14px;
}

#player-name:focus {
    outline: none;
    border-color: #8f7a66;
}

.leaderboard-controls button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 5px;
    padding: 8px 16px;
    cursor: pointer;
    font-weight: bold;
}

.leaderboard-controls button:hover {
    background: #9f8b77;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee4da;
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-rank {
    font-weight: bold;
    color: #8f7a66;
    min-width: 30px;
}

.leaderboard-name {
    flex: 1;
    color: #776e65;
}

.leaderboard-score {
    font-weight: bold;
    color: #f65e3b;
}

.loading {
    text-align: center;
    color: #776e65;
}

.game-over-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(238, 228, 218, 0.73);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.game-over-overlay.active {
    display: flex;
}

.game-over-content {
    text-align: center;
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.game-over-content h2 {
    font-size: 48px;
    color: #776e65;
    margin-bottom: 20px;
}

.game-over-content button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 5px;
    padding: 15px 30px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
}

.game-over-content button:hover {
    background: #9f8b77;
}

@media (max-width: 520px) {
    .header h1 {
        font-size: 40px;
    }
    
    .tile {
        font-size: 25px;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 20px;
    }
    
    .tile-1024, .tile-2048, .tile-super {
        font-size: 16px;
    }
}