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

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

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

h1 {
    font-size: 80px;
    font-weight: bold;
    margin: 0;
    display: block;
    float: left;
}

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

.score-container, .best-container {
    position: relative;
    display: inline-block;
    background: #bbada0;
    padding: 15px 25px;
    font-size: 25px;
    height: 60px;
    line-height: 47px;
    font-weight: bold;
    border-radius: 3px;
    color: white;
    text-align: center;
    margin-top: 8px;
}

.score-title, .best-title {
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    text-transform: uppercase;
    font-size: 13px;
    line-height: 13px;
    text-align: center;
    color: #eee4da;
}

.game-intro {
    clear: both;
    margin-bottom: 20px;
    line-height: 1.65;
}

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

.grid-container {
    position: absolute;
    z-index: 1;
    width: calc(100% - 30px);
    height: calc(100% - 30px);
}

.grid-row {
    display: flex;
    margin-bottom: 15px;
    height: calc(25% - 11.25px);
}

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

.grid-cell {
    width: 25%;
    height: 100%;
    margin-right: 15px;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 3px;
}

.grid-cell:last-child {
    margin-right: 0;
}

.tile-container {
    position: absolute;
    z-index: 2;
    width: calc(100% - 30px);
    height: calc(100% - 30px);
}

.tile {
    position: absolute;
    width: calc(25% - 11.25px);
    height: calc(25% - 11.25px);
    border-radius: 3px;
    background: #eee4da;
    text-align: center;
    font-weight: bold;
    z-index: 10;
    font-size: 55px;
    line-height: 107px;
    transition: all 0.1s ease-in-out;
    animation: appear 0.2s;
}

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

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

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

/* Tile colors */
.tile-2 {
    background: #eee4da;
    color: #776e65;
}

.tile-4 {
    background: #ede0c8;
    color: #776e65;
}

.tile-8 {
    background: #f2b179;
    color: white;
}

.tile-16 {
    background: #f59563;
    color: white;
}

.tile-32 {
    background: #f67c5f;
    color: white;
}

.tile-64 {
    background: #f65e3b;
    color: white;
}

.tile-128 {
    background: #edcf72;
    color: white;
    font-size: 45px;
}

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

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

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

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

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(238, 228, 218, 0.73);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    animation: fade-in 0.8s ease;
}

.game-message.game-won {
    background: rgba(237, 194, 46, 0.5);
    color: #f9f6f2;
}

.game-message.game-over {
    background: rgba(238, 228, 218, 0.73);
}

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

.game-message .lower {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 30px;
}

.retry-button, #new-game-button {
    background: #8f7a66;
    border-radius: 3px;
    padding: 10px 20px;
    text-decoration: none;
    color: #f9f6f2;
    font-weight: bold;
    border: none;
    cursor: pointer;
    font-size: 18px;
    margin-bottom: 10px;
}

.retry-button:hover, #new-game-button:hover {
    background: #9f8b77;
}

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

@keyframes fade-in {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

/* Responsive adjustments */
@media screen and (max-width: 520px) {
    .container {
        padding: 10px;
        margin: 10px;
    }

    h1 {
        font-size: 50px;
    }

    .score-container, .best-container {
        padding: 10px 15px;
        font-size: 18px;
        height: 45px;
        line-height: 35px;
    }

    .game-container {
        height: 400px;
    }

    .tile {
        font-size: 40px;
        line-height: 85px;
    }

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

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

    .game-message p {
        font-size: 40px;
    }
}