html, body {
    margin: 0;
    padding: 0;
    background: #faf8ef;
    color: #776e65;
    font-family: "Helvetica Neue", Arial, sans-serif;
    font-size: 18px;
}

body {
    margin: 80px 0;
}

.container {
    width: 500px;
    margin: 0 auto;
}

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

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

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

.score-container, .best-container {
    background: #bbada0;
    padding: 10px 15px;
    border-radius: 6px;
    min-width: 80px;
    text-align: center;
}

.score-title, .best-title {
    font-size: 14px;
    font-weight: bold;
    text-transform: uppercase;
    line-height: 1.2;
}

.score, .best-score {
    font-size: 24px;
    font-weight: bold;
    line-height: 1.2;
}

.game-intro {
    margin-bottom: 20px;
    text-align: center;
}

.game-container {
    position: relative;
    padding: 15px;
    background: #bbada0;
    border-radius: 6px;
    width: 500px;
    height: 500px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(238, 228, 218, 0.5);
    z-index: 100;
    text-align: center;
    -webkit-animation: fade-in 800ms ease 1200ms;
    -moz-animation: fade-in 800ms ease 1200ms;
    animation: fade-in 800ms ease 1200ms;
    -webkit-animation-fill-mode: both;
    -moz-animation-fill-mode: both;
    animation-fill-mode: both;
}

.game-message p {
    font-size: 60px;
    font-weight: bold;
    height: 60px;
    line-height: 60px;
    margin-top: 222px;
}

.game-message .lower {
    display: block;
    margin-top: 59px;
}

.game-message a {
    display: inline-block;
    background: #8f7a66;
    border-radius: 3px;
    padding: 0 20px;
    text-decoration: none;
    color: #f9f6f2;
    height: 40px;
    line-height: 42px;
    margin-left: 9px;
}

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

.grid-row {
    display: flex;
}

.grid-cell {
    width: 107px;
    height: 107px;
    margin-right: 15px;
    margin-bottom: 15px;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 3px;
    -webkit-animation: appear 200ms ease 100ms;
    -moz-animation: appear 200ms ease 100ms;
    animation: appear 200ms ease 100ms;
    -webkit-animation-fill-mode: backwards;
    -moz-animation-fill-mode: backwards;
    animation-fill-mode: backwards;
}

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

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

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

.tile, .tile .tile-inner {
    width: 107px;
    height: 107px;
    line-height: 107px;
}

.tile {
    position: absolute;
    -webkit-animation: appear 200ms ease 100ms;
    -moz-animation: appear 200ms ease 100ms;
    animation: appear 200ms ease 100ms;
    -webkit-animation-fill-mode: backwards;
    -moz-animation-fill-mode: backwards;
    animation-fill-mode: backwards;
}

.tile .tile-inner {
    border-radius: 3px;
    background: #eee4da;
    text-align: center;
    font-weight: bold;
    z-index: 10;
    font-size: 55px;
}

.tile.tile-2 .tile-inner {
    background: #eee4da;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0), inset 0 0 0 1px rgba(255, 255, 255, 0);
}

.tile.tile-4 .tile-inner {
    background: #ede0c8;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0), inset 0 0 0 1px rgba(255, 255, 255, 0);
}

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

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

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

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

.tile.tile-128 .tile-inner {
    color: #f9f6f2;
    background: #edcf72;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.2381), inset 0 0 0 1px rgba(255, 255, 255, 0.14286);
    font-size: 45px;
}

.tile.tile-256 .tile-inner {
    color: #f9f6f2;
    background: #edcc61;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.31746), inset 0 0 0 1px rgba(255, 255, 255, 0.19048);
    font-size: 45px;
}

.tile.tile-512 .tile-inner {
    color: #f9f6f2;
    background: #edc850;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.39683), inset 0 0 0 1px rgba(255, 255, 255, 0.2381);
    font-size: 45px;
}

.tile.tile-1024 .tile-inner {
    color: #f9f6f2;
    background: #edc53f;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.47619), inset 0 0 0 1px rgba(255, 255, 255, 0.28571);
    font-size: 35px;
}

.tile.tile-2048 .tile-inner {
    color: #f9f6f2;
    background: #edc22e;
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.55556), inset 0 0 0 1px rgba(255, 255, 255, 0.33333);
    font-size: 35px;
}

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

@-webkit-keyframes appear {
    0% {
        opacity: 0;
        -webkit-transform: scale(0);
        -moz-transform: scale(0);
        transform: scale(0);
    }

    100% {
        opacity: 1;
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        transform: scale(1);
    }
}

@-moz-keyframes appear {
    0% {
        opacity: 0;
        -webkit-transform: scale(0);
        -moz-transform: scale(0);
        transform: scale(0);
    }

    100% {
        opacity: 1;
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        transform: scale(1);
    }
}

@keyframes appear {
    0% {
        opacity: 0;
        -webkit-transform: scale(0);
        -moz-transform: scale(0);
        transform: scale(0);
    }

    100% {
        opacity: 1;
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        transform: scale(1);
    }
}

.tile.merged .tile-inner {
    z-index: 20;
    -webkit-animation: pop 200ms ease 100ms;
    -moz-animation: pop 200ms ease 100ms;
    animation: pop 200ms ease 100ms;
    -webkit-animation-fill-mode: backwards;
    -moz-animation-fill-mode: backwards;
    animation-fill-mode: backwards;
}

@-webkit-keyframes pop {
    0% {
        -webkit-transform: scale(0);
        -moz-transform: scale(0);
        transform: scale(0);
    }

    50% {
        -webkit-transform: scale(1.2);
        -moz-transform: scale(1.2);
        transform: scale(1.2);
    }

    100% {
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        transform: scale(1);
    }
}

@-moz-keyframes pop {
    0% {
        -webkit-transform: scale(0);
        -moz-transform: scale(0);
        transform: scale(0);
    }

    50% {
        -webkit-transform: scale(1.2);
        -moz-transform: scale(1.2);
        transform: scale(1.2);
    }

    100% {
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        transform: scale(1);
    }
}

@keyframes pop {
    0% {
        -webkit-transform: scale(0);
        -moz-transform: scale(0);
        transform: scale(0);
    }

    50% {
        -webkit-transform: scale(1.2);
        -moz-transform: scale(1.2);
        transform: scale(1.2);
    }

    100% {
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        transform: scale(1);
    }
}

.tile.move-up {
    -webkit-animation: move-up 100ms ease-in-out;
    -moz-animation: move-up 100ms ease-in-out;
    animation: move-up 100ms ease-in-out;
}

.tile.move-right {
    -webkit-animation: move-right 100ms ease-in-out;
    -moz-animation: move-right 100ms ease-in-out;
    animation: move-right 100ms ease-in-out;
}

.tile.move-down {
    -webkit-animation: move-down 100ms ease-in-out;
    -moz-animation: move-down 100ms ease-in-out;
    animation: move-down 100ms ease-in-out;
}

.tile.move-left {
    -webkit-animation: move-left 100ms ease-in-out;
    -moz-animation: move-left 100ms ease-in-out;
    animation: move-left 100ms ease-in-out;
}

@-webkit-keyframes move-up {
    0% {
        top: 0px;
    }

    100% {
        top: -122px;
    }
}

@-moz-keyframes move-up {
    0% {
        top: 0px;
    }

    100% {
        top: -122px;
    }
}

@keyframes move-up {
    0% {
        top: 0px;
    }

    100% {
        top: -122px;
    }
}

@-webkit-keyframes move-right {
    0% {
        left: 0px;
    }

    100% {
        left: 122px;
    }
}

@-moz-keyframes move-right {
    0% {
        left: 0px;
    }

    100% {
        left: 122px;
    }
}

@keyframes move-right {
    0% {
        left: 0px;
    }

    100% {
        left: 122px;
    }
}

@-webkit-keyframes move-down {
    0% {
        top: 0px;
    }

    100% {
        top: 122px;
    }
}

@-moz-keyframes move-down {
    0% {
        top: 0px;
    }

    100% {
        top: 122px;
    }
}

@keyframes move-down {
    0% {
        top: 0px;
    }

    100% {
        top: 122px;
    }
}

@-webkit-keyframes move-left {
    0% {
        left: 0px;
    }

    100% {
        left: -122px;
    }
}

@-moz-keyframes move-left {
    0% {
        left: 0px;
    }

    100% {
        left: -122px;
    }
}

@keyframes move-left {
    0% {
        left: 0px;
    }

    100% {
        left: -122px;
    }
}

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

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

.reset-button:hover, .undo-button:hover {
    background: #9f8a76;
}

@media screen and (max-width: 520px) {
    html, body {
        font-size: 15px;
    }

    body {
        margin: 20px 0;
    }

    .container {
        width: 280px;
        margin: 0 auto;
    }

    .header {
        margin-bottom: 10px;
    }

    .title {
        font-size: 40px;
    }

    .score-container, .best-container {
        min-width: 60px;
        padding: 10px 5px;
    }

    .score-title, .best-title {
        font-size: 12px;
    }

    .score, .best-score {
        font-size: 18px;
    }

    .game-intro {
        margin-bottom: 10px;
    }

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

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

    .grid-cell {
        margin-right: 10px;
        margin-bottom: 10px;
    }

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

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

    .tile.tile-super .tile-inner {
        font-size: 16px;
    }

    @-webkit-keyframes move-up {
        0% {
            top: 0px;
        }

        100% {
            top: -67.5px;
        }
    }

    @-moz-keyframes move-up {
        0% {
            top: 0px;
        }

        100% {
            top: -67.5px;
        }
    }

    @keyframes move-up {
        0% {
            top: 0px;
        }

        100% {
            top: -67.5px;
        }
    }

    @-webkit-keyframes move-right {
        0% {
            left: 0px;
        }

        100% {
            left: 67.5px;
        }
    }

    @-moz-keyframes move-right {
        0% {
            left: 0px;
        }

        100% {
            left: 67.5px;
        }
    }

    @keyframes move-right {
        0% {
            left: 0px;
        }

        100% {
            left: 67.5px;
        }
    }

    @-webkit-keyframes move-down {
        0% {
            top: 0px;
        }

        100% {
            top: 67.5px;
        }
    }

    @-moz-keyframes move-down {
        0% {
            top: 0px;
        }

        100% {
            top: 67.5px;
        }
    }

    @keyframes move-down {
        0% {
            top: 0px;
        }

        100% {
            top: 67.5px;
        }
    }

    @-webkit-keyframes move-left {
        0% {
            left: 0px;
        }

        100% {
            left: -67.5px;
        }
    }

    @-moz-keyframes move-left {
        0% {
            left: 0px;
        }

        100% {
            left: -67.5px;
        }
    }

    @keyframes move-left {
        0% {
            left: 0px;
        }

        100% {
            left: -67.5px;
        }
    }
}