* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Arial', sans-serif;
}

body {
    background-color: #faf8ef;
    color: #776e65;
    line-height: 1.4;
}

.container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

h1 {
    font-size: 80px;
    font-weight: bold;
    color: #776e65;
    margin: 0;
}

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

.score-box {
    background: #bbada0;
    color: white;
    padding: 5px 15px;
    border-radius: 3px;
    text-align: center;
    min-width: 80px;
}

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

#score, #best-score {
    font-size: 20px;
    font-weight: bold;
}

.game-intro {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

button {
    background: #8f7a66;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 10px 20px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s ease;
}

button:hover {
    background: #9f8b77;
}

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

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 15px;
    position: relative;
    z-index: 1;
}

.grid-cell {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 3px;
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 36px;
    font-weight: bold;
    color: #776e65;
    position: relative;
    overflow: hidden;
}

.tile {
    position: absolute;
    width: calc(25% - 15px);
    height: calc(25% - 15px);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 36px;
    font-weight: bold;
    border-radius: 3px;
    transition: all 0.1s ease-in-out;
    z-index: 2;
}

.tile-2 { background: #eee4da; }
.tile-4 { background: #ede0c8; }
.tile-8 { color: #f9f6f2; background: #f2b179; }
.tile-16 { color: #f9f6f2; background: #f59563; }
.tile-32 { color: #f9f6f2; background: #f67c5f; }
.tile-64 { color: #f9f6f2; background: #f65e3b; }
.tile-128 { 
    color: #f9f6f2; 
    background: #edcf72;
    font-size: 30px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.2), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.tile-256 { 
    color: #f9f6f2; 
    background: #edcc61;
    font-size: 30px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.3), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.tile-512 { 
    color: #f9f6f2; 
    background: #edc850;
    font-size: 30px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.tile-1024 { 
    color: #f9f6f2; 
    background: #edc53f;
    font-size: 25px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.tile-2048 { 
    color: #f9f6f2; 
    background: #edc22e;
    font-size: 25px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

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

@keyframes pop {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

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

.merged-tile {
    animation: pop 0.15s ease;
    z-index: 10;
}

.game-over, .game-won {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(238, 228, 218, 0.73);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.game-over p, .game-won p {
    font-size: 60px;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 20px;
}

.game-over.show, .game-won.show {
    opacity: 1;
    visibility: visible;
}

.game-explanation {
    text-align: center;
    color: #776e65;
    font-size: 18px;
    line-height: 1.5;
}

@media (max-width: 520px) {
    .container {
        padding: 10px;
    }
    
    h1 {
        font-size: 60px;
    }
    
    .tile {
        font-size: 24px;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 22px;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 18px;
    }
    
    .game-over p, .game-won p {
        font-size: 40px;
    }
}
