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

body {
    font-family: 'Arial', sans-serif;
    background: #faf8ef;
    color: #776e65;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.container {
    text-align: center;
    max-width: 500px;
    width: 100%;
    padding: 20px;
}

h1 {
    font-size: 48px;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 20px;
}

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

.score, .best {
    background: #bbada0;
    padding: 10px 20px;
    border-radius: 6px;
    color: white;
    min-width: 80px;
}

.score span, .best span {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    font-weight: bold;
}

.score div, .best div {
    font-size: 24px;
    font-weight: bold;
    margin-top: 5px;
}

.game-container {
    position: relative;
    margin: 0 auto 20px;
    width: 340px;
    height: 340px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    background: #bbada0;
    border-radius: 6px;
    padding: 10px;
    width: 100%;
    height: 100%;
}

.tile {
    background: #cdc1b4;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: bold;
    transition: all 0.15s ease-in-out;
}

.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: 28px; }
.tile-256 { background: #edcc61; color: #f9f6f2; font-size: 28px; }
.tile-512 { background: #edc850; color: #f9f6f2; font-size: 28px; }
.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: 24px; }
.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 24px; }

.game-over {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.game-over-text {
    text-align: center;
}

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

.hidden {
    display: none !important;
}

.restart-btn, .new-game-btn {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 6px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.15s ease-in-out;
}

.restart-btn:hover, .new-game-btn:hover {
    background: #9f8a76;
}

.instructions {
    margin-top: 20px;
}

.instructions p {
    margin-bottom: 15px;
    font-size: 14px;
    line-height: 1.4;
}

/* Game Mode Toggle */
.game-mode-toggle {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-btn {
    background: #bbada0;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
}

.mode-btn:hover {
    background: #9f8a76;
}

.mode-btn.active {
    background: #8f7a66;
}

/* Game Mode Sections */
.game-mode {
    width: 100%;
}

/* Race Mode Styles */
.race-container {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: nowrap;
}

.player-section, .cpu-section {
    flex: 1;
    min-width: 180px;
    text-align: center;
}

.player-section h3, .cpu-section h3 {
    font-size: 20px;
    color: #776e65;
    margin-bottom: 10px;
}

.vs-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    position: relative;
}

.vs-text {
    font-size: 24px;
    font-weight: bold;
    color: #776e65;
    background: #bbada0;
    color: white;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.race-winner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 10;
    min-width: 200px;
}

.race-winner h2 {
    font-size: 24px;
    color: #776e65;
    margin-bottom: 15px;
}

/* Small game containers for race mode */
.game-container.small {
    width: 180px;
    height: 180px;
    margin: 10px auto;
}

.grid.small {
    gap: 5px;
    padding: 5px;
}

.grid.small .tile {
    font-size: 18px;
}

.grid.small .tile-128,
.grid.small .tile-256,
.grid.small .tile-512 {
    font-size: 16px;
}

.grid.small .tile-1024,
.grid.small .tile-2048 {
    font-size: 14px;
}

/* Score styling for race mode */
.player-section .score,
.cpu-section .score {
    background: #bbada0;
    padding: 8px 15px;
    border-radius: 6px;
    color: white;
    margin: 0 auto 10px;
    max-width: 120px;
}

.player-section .score span,
.cpu-section .score span {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    font-weight: bold;
}

.player-section .score div,
.cpu-section .score div {
    font-size: 18px;
    font-weight: bold;
    margin-top: 3px;
}

@media (max-width: 768px) {
    .race-container {
        gap: 10px;
    }
    
    .game-container.small {
        width: 140px;
        height: 140px;
    }
    
    .player-section, .cpu-section {
        min-width: 140px;
    }
    
    .player-section h3, .cpu-section h3 {
        font-size: 16px;
    }
    
    .vs-section {
        min-width: 60px;
    }
    
    .vs-text {
        width: 50px;
        height: 50px;
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 5px;
    }
    
    h1 {
        font-size: 32px;
        margin-bottom: 15px;
    }
    
    .game-container {
        width: 280px;
        height: 280px;
    }
    
    .game-container.small {
        width: 110px;
        height: 110px;
    }
    
    .race-container {
        gap: 8px;
    }
    
    .player-section, .cpu-section {
        min-width: 110px;
    }
    
    .player-section h3, .cpu-section h3 {
        font-size: 14px;
        margin-bottom: 5px;
    }
    
    .vs-section {
        min-width: 40px;
    }
    
    .vs-text {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }
    
    .tile {
        font-size: 24px;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 20px;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 18px;
    }
    
    .grid.small .tile {
        font-size: 12px;
    }
    
    .grid.small .tile-128,
    .grid.small .tile-256,
    .grid.small .tile-512 {
        font-size: 10px;
    }
    
    .grid.small .tile-1024,
    .grid.small .tile-2048 {
        font-size: 8px;
    }
    
    .mode-btn {
        padding: 8px 12px;
        font-size: 11px;
    }
    
    .player-section .score,
    .cpu-section .score {
        padding: 5px 10px;
        max-width: 100px;
    }
    
    .player-section .score div,
    .cpu-section .score div {
        font-size: 14px;
    }
    
    .race-winner {
        min-width: 180px;
        padding: 15px;
    }
    
    .race-winner h2 {
        font-size: 18px;
        margin-bottom: 10px;
    }
}
