:root {
    --bg-page: #faf8ef;
    --bg-grid: #bbada0;
    --bg-cell: #cdc1b4;
    --bg-cell-empty: rgba(238, 228, 218, 0.35);
    --text-dark: #776e65;
    --text-light: #f9f6f2;
    --btn-bg: #8f7a66;
    --btn-hover: #9f8b77;
    --color-2: #eee4da;
    --color-4: #ede0c8;
    --color-8: #f2b179;
    --color-16: #f59563;
    --color-32: #f67c5f;
    --color-64: #f65e3b;
    --color-128: #edcf72;
    --color-256: #edcc61;
    --color-512: #edc850;
    --color-1024: #edc53f;
    --color-2048: #edc22e;
    --color-4096: #3c3a32;
    --color-8192: #3c3a32;
}

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

body {
    background: var(--bg-page);
    font-family: Arial, sans-serif;
    color: var(--text-dark);
    overflow: hidden;
    touch-action: none;
}

header {
    display: block;
    margin: 20px auto;
    width: 100%;
    max-width: 500px;
    text-align: center;
    padding: 0 10px;
}

header h1 {
    font-size: 60px;
    font-weight: bold;
    margin: 0;
}

header #newgamebutton {
    display: inline-block;
    margin: 10px auto;
    padding: 10px 20px;
    background: var(--btn-bg);
    color: var(--text-light);
    border-radius: 6px;
    text-decoration: none;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    border: none;
}

header #newgamebutton:hover {
    background: var(--btn-hover);
}

.scores {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
}

.scores p {
    font-size: 16px;
    font-weight: bold;
}

#grid-container {
    width: 460px;
    height: 460px;
    padding: 15px;
    margin: 0 auto;
    background: var(--bg-grid);
    border-radius: 10px;
    position: relative;
}

.grid-cell {
    width: 100px;
    height: 100px;
    border-radius: 6px;
    background: var(--bg-cell);
    position: absolute;
    z-index: 1;
}

.number-cell {
    position: absolute;
    border-radius: 6px;
    text-align: center;
    font-size: 50px;
    font-family: Arial, sans-serif;
    font-weight: bold;
    line-height: 100px;
    z-index: 2;
    transition: top 0.15s ease, left 0.15s ease, width 0.1s ease, height 0.1s ease;
}

.number-cell.new {
    animation: popIn 0.2s ease;
}

.number-cell.merge {
    animation: mergePulse 0.2s ease;
}

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

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

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(238, 228, 218, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-page);
    padding: 40px 60px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.modal-content h2 {
    font-size: 40px;
    margin-bottom: 15px;
    color: var(--text-dark);
}

.modal-content p {
    font-size: 20px;
    margin-bottom: 25px;
    color: var(--text-dark);
}

.modal-content button {
    padding: 12px 30px;
    font-size: 18px;
    background: var(--btn-bg);
    color: var(--text-light);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

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

@media screen and (max-width: 520px) {
    header {
        margin: 10px auto;
    }

    header h1 {
        font-size: 40px;
    }

    #grid-container {
        width: 92vw;
        height: 92vw;
        padding: 2vw;
    }

    .grid-cell,
    .number-cell {
        width: 20vw;
        height: 20vw;
        line-height: 20vw;
        font-size: 8vw;
    }
}
