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

:root {
    --bg-color: #faf8ef;
    --text-color: #776e65;
    --grid-bg: #bbada0;
    --cell-bg: #cdc1b4;
    --btn-bg: #8f7a66;
    --btn-hover: #9f8b77;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

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

h1 {
    font-size: 4rem;
    font-weight: bold;
    color: #776e65;
}

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

.score-box {
    background: var(--grid-bg);
    border-radius: 6px;
    padding: 10px 20px;
    text-align: center;
    min-width: 80px;
}

.score-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #eee4da;
    font-weight: bold;
}

.score-value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
}

.controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.btn {
    background: var(--btn-bg);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn:hover {
    background: var(--btn-hover);
}

.btn:active {
    transform: scale(0.98);
}

.game-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--grid-bg);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 20px;
}

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

.grid-cell {
    background: var(--cell-bg);
    border-radius: 6px;
}

.tile-container {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
}

.tile {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    border-radius: 6px;
    transition: transform 0.15s ease-in-out, opacity 0.15s ease-in-out;
}

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

.tile.merged {
    animation: pop 0.2s ease-in-out;
}

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

/* Tile colors */
.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;
}

.tile-256 {
    background: #edcc61;
    color: #f9f6f2;
}

.tile-512 {
    background: #edc850;
    color: #f9f6f2;
}

.tile-1024 {
    background: #edc53f;
    color: #f9f6f2;
}

.tile-2048 {
    background: #edc22e;
    color: #f9f6f2;
}

.tile-super {
    background: #3c3a32;
    color: #f9f6f2;
}

/* Game over / win message */
.game-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.73);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.game-message.active {
    opacity: 1;
    pointer-events: auto;
}

.game-message p {
    font-size: 2rem;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 20px;
    text-align: center;
}

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

.game-message.won p {
    color: #f9f6f2;
}

.instructions {
    background: #cdc1b4;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 20px;
}

.instructions p {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #776e65;
}

footer {
    background: var(--grid-bg);
    padding: 15px;
    text-align: center;
}

footer p {
    color: #eee4da;
    font-size: 0.9rem;
}

footer a {
    color: white;
    text-decoration: none;
    font-weight: bold;
}

footer a:hover {
    text-decoration: underline;
}

/* Responsive design */
@media (max-width: 520px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 2.5rem;
    }

    .score-box {
        padding: 8px 12px;
        min-width: 60px;
    }

    .score-label {
        font-size: 0.65rem;
    }

    .score-value {
        font-size: 1.2rem;
    }

    .controls {
        gap: 8px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .game-container {
        padding: 8px;
    }

    .grid-background {
        gap: 8px;
    }

    .tile-container {
        top: 8px;
        left: 8px;
        right: 8px;
        bottom: 8px;
    }

    .game-message p {
        font-size: 1.5rem;
    }

    .instructions {
        padding: 12px;
    }

    .instructions p {
        font-size: 0.85rem;
    }
}

@media (max-width: 380px) {
    h1 {
        font-size: 2rem;
    }

    .score-box {
        padding: 6px 10px;
        min-width: 50px;
    }

    .score-value {
        font-size: 1rem;
    }

    .btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .game-container {
        padding: 6px;
    }

    .grid-background {
        gap: 6px;
    }

    .tile-container {
        top: 6px;
        left: 6px;
        right: 6px;
        bottom: 6px;
    }
}
