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

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

.container {
    width: 100%;
    max-width: 500px;
}

.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-container {
    background: #bbada0;
    padding: 10px 25px;
    border-radius: 3px;
    text-align: center;
    min-width: 70px;
}

.score-label {
    font-size: 13px;
    color: #eee4da;
    font-weight: bold;
    margin-bottom: 5px;
}

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

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

.game-intro {
    color: #776e65;
    font-size: 18px;
}

.restart-button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    padding: 10px 20px;
    font-size: 18px;
    font-weight: bold;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.2s;
}

.restart-button:hover {
    background: #9f8a76;
}

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

.grid-container {
    position: absolute;
    z-index: 1;
}

.grid-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

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

.tile-container {
    position: absolute;
    z-index: 2;
}

.tile {
    position: absolute;
    top: 0;
    left: 0;
    width: 106.25px;
    height: 106.25px;
    border-radius: 3px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 55px;
    font-weight: bold;
    will-change: transform;
    transition: transform 0.15s ease-in-out;
}

.tile-inner {
    width: 100%;
    height: 100%;
    border-radius: 3px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: inherit;
    color: inherit;
    font-size: inherit;
}

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

.tile-merged .tile-inner {
    animation: pop 0.2s ease-in-out;
    z-index: 5;
}

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

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

.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: 45px;
}

.tile-256 {
    background: #edcc61;
    color: #f9f6f2;
    font-size: 45px;
}

.tile-512 {
    background: #edc850;
    color: #f9f6f2;
    font-size: 45px;
}

.tile-1024 {
    background: #edc53f;
    color: #f9f6f2;
    font-size: 35px;
}

.tile-2048 {
    background: #edc22e;
    color: #f9f6f2;
    font-size: 35px;
}

.tile-super {
    background: #3c3a32;
    color: #f9f6f2;
    font-size: 30px;
}

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

.game-message.game-over,
.game-message.game-won {
    display: flex;
}

.game-message p {
    font-size: 60px;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 30px;
}

.retry-button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    padding: 15px 30px;
    font-size: 20px;
    font-weight: bold;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.2s;
}

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

@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.game-explanation {
    color: #776e65;
    font-size: 18px;
    line-height: 1.65;
}

.important {
    font-weight: bold;
}

@media screen and (max-width: 520px) {
    .container {
        max-width: 280px;
    }

    h1 {
        font-size: 50px;
    }

    .game-container {
        width: 280px;
        height: 280px;
        padding: 10px;
    }

    .grid-cell,
    .tile {
        width: 57.5px;
        height: 57.5px;
    }

    .grid-row {
        gap: 10px;
        margin-bottom: 10px;
    }

    .tile {
        font-size: 35px;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 25px;
    }

    .tile-1024,
    .tile-2048 {
        font-size: 20px;
    }

    .tile-super {
        font-size: 18px;
    }
}
