:root {
    --bg-color: #fcf8f5;
    --text-color: #776e65;
    --grid-color: #bbada0;
    --cell-color: rgba(238, 228, 218, 0.35);
    --tile-2-bg: #eee4da;
    --tile-2-color: #776e65;
    --tile-4-bg: #ede0c8;
    --tile-4-color: #776e65;
    --tile-8-bg: #f2b179;
    --tile-8-color: #f9f6f2;
    --tile-16-bg: #f59563;
    --tile-16-color: #f9f6f2;
    --tile-32-bg: #f67c5f;
    --tile-32-color: #f9f6f2;
    --tile-64-bg: #f65e3b;
    --tile-64-color: #f9f6f2;
    --tile-128-bg: #edcf72;
    --tile-128-color: #f9f6f2;
    --tile-256-bg: #edcc61;
    --tile-256-color: #f9f6f2;
    --tile-512-bg: #edc850;
    --tile-512-color: #f9f6f2;
    --tile-1024-bg: #edc53f;
    --tile-1024-color: #f9f6f2;
    --tile-2048-bg: #edc22e;
    --tile-2048-color: #f9f6f2;
    --tile-super-bg: #3c3a32;
    --tile-super-color: #f9f6f2;
    --font-family: 'Outfit', sans-serif;
}
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}
.container {
    width: 500px;
    margin: 0 auto;
    padding: 20px;
}
/* Header */
header {
    margin-bottom: 30px;
}
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
h1 {
    font-size: 80px;
    font-weight: 800;
    margin: 0;
    line-height: 1;
    color: #776e65;
}
.scores {
    display: flex;
    gap: 10px;
}
.score-box {
    background: #bbada0;
    padding: 10px 20px;
    border-radius: 6px;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
    position: relative;
}
.score-label {
    font-size: 13px;
    text-transform: uppercase;
    font-weight: 600;
    color: #eee4da;
}
#score,
#best-score {
    font-size: 25px;
    font-weight: 800;
}
.header-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.description {
    font-size: 18px;
    line-height: 1.5;
}
#new-game-btn {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    padding: 10px 20px;
    font-size: 18px;
    font-weight: 800;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-family);
    transition: background 0.2s;
}
#new-game-btn:hover {
    background: #776e65;
}
/* Game Container */
.game-container {
    position: relative;
    padding: 15px;
    background: var(--grid-color);
    border-radius: 10px;
    width: 500px;
    height: 500px;
    touch-action: none;
    margin-bottom: 30px;
}
.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 15px;
    width: 100%;
    height: 100%;
}
.grid-cell {
    background: var(--cell-color);
    border-radius: 6px;
    width: 100%;
    height: 100%;
}
.tile-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 15px;
    z-index: 2;
    pointer-events: none;
    /* Let clicks pass through to grid if needed */
}
.tile {
    position: absolute;
    width: 106.25px;
    height: 106.25px;
    transition: transform 100ms ease-in-out;
    z-index: 10;
}
.tile-inner {
    width: 100%;
    height: 100%;
    border-radius: 6px;
    background: #eee4da;
    color: #776e65;
    font-weight: 800;
    font-size: 55px;
    display: flex;
    justify-content: center;
    align-items: center;
}
/* Tile Colors - Apply to tile-inner */
.tile-2 .tile-inner {
    background: var(--tile-2-bg);
    color: var(--tile-2-color);
}
.tile-4 .tile-inner {
    background: var(--tile-4-bg);
    color: var(--tile-4-color);
}
.tile-8 .tile-inner {
    background: var(--tile-8-bg);
    color: var(--tile-8-color);
}
.tile-16 .tile-inner {
    background: var(--tile-16-bg);
    color: var(--tile-16-color);
}
.tile-32 .tile-inner {
    background: var(--tile-32-bg);
    color: var(--tile-32-color);
}
.tile-64 .tile-inner {
    background: var(--tile-64-bg);
    color: var(--tile-64-color);
}
.tile-128 .tile-inner {
    background: var(--tile-128-bg);
    color: var(--tile-128-color);
    font-size: 45px;
}
.tile-256 .tile-inner {
    background: var(--tile-256-bg);
    color: var(--tile-256-color);
    font-size: 45px;
}
.tile-512 .tile-inner {
    background: var(--tile-512-bg);
    color: var(--tile-512-color);
    font-size: 45px;
}
.tile-1024 .tile-inner {
    background: var(--tile-1024-bg);
    color: var(--tile-1024-color);
    font-size: 35px;
}
.tile-2048 .tile-inner {
    background: var(--tile-2048-bg);
    color: var(--tile-2048-color);
    font-size: 35px;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.23815), inset 0 0 0 1px rgba(255, 255, 255, 0.190476);
}
.tile-super .tile-inner {
    background: var(--tile-super-bg);
    color: var(--tile-super-color);
    font-size: 30px;
}
/* Animations - Apply to tile-inner */
.tile-new .tile-inner {
    animation: appear 200ms ease;
}
.tile-merged .tile-inner {
    animation: pop 200ms ease;
}
@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}
@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}
/* Game Over / Win Message */
.game-message {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 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 800ms ease 1200ms;
    animation-fill-mode: both;
}
.game-message.game-won {
    background: rgba(237, 194, 46, 0.5);
    color: #f9f6f2;
}
.game-message.game-over {
    background: rgba(238, 228, 218, 0.73);
    color: #776e65;
}
.game-message p {
    font-size: 60px;
    font-weight: 800;
    margin-bottom: 20px;
}
.game-message .lower {
    display: block;
    margin-top: 20px;
}
.game-message a {
    display: inline-block;
    background: #8f7a66;
    border-radius: 3px;
    padding: 0 20px;
    text-decoration: none;
    color: #f9f6f2;
    height: 40px;
    line-height: 42px;
    cursor: pointer;
    margin-left: 9px;
    font-weight: 800;
}
.game-message.game-won a {
    background: #f9f6f2;
    color: #776e65;
}
/* Footer */
footer {
    margin-top: 20px;
    text-align: center;
    font-size: 16px;
    color: #776e65;
}
/* Responsive */
@media screen and (max-width: 520px) {
    .container {
        width: 100%;
        padding: 10px;
    }
    h1 {
        font-size: 50px;
    }
    .game-container {
        width: 100%;
        height: auto;
        aspect-ratio: 1;
        padding: 10px;
        margin-bottom: 20px;
    }
    .grid-container {
        gap: 10px;
    }
    .tile {
        width: calc((100% - 30px) / 4);
        /* (100% - gap*3) / 4 */
        height: calc((100% - 30px) / 4);
    }
    .tile-inner {
        font-size: 35px;
    }
    .tile-128 .tile-inner,
    .tile-256 .tile-inner,
    .tile-512 .tile-inner {
        font-size: 25px;
    }
    .tile-1024 .tile-inner,
    .tile-2048 .tile-inner {
        font-size: 20px;
    }
}
