@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap');
@import "../font/clear-sans.css";

:root {
    --background-color: #B5FED9;
    --text-color: #474935;
    --tile-color-2: #ede0c8;
    --tile-color-4: #f2b179;
    --tile-color-8: #f59563;
    --tile-color-16: #f67c5f;
    --tile-color-32: #f65e3b;
    --tile-color-64: #edcf72;
    --tile-color-128: #edcc61;
    --tile-color-256: #edc850;
    --tile-color-512: #edc53f;
    --tile-color-1024: #edc22e;
    --tile-color-2048: #edc22e;
    --tile-shadow: rgba(243, 215, 116, 0.55556);
    --container-width: 450px;
    --container-height: 450px;
    --tile-size: 23.5%;
    --tile-font-size: 53px;
    --large-tile-font-size: 45px;
    --larger-tile-font-size: 33px;
    --padding-small: 3px 20px;
    --padding-medium: 0 8px;
    --border-radius: 3px;
    --background-light: rgba(238, 228, 218, 0.35);
    --background-medium: #98CBB4;
    --background-dark: #a1b382;
    --winning-animation: 1.5s infinite;
    --failure-animation: 5s infinite;
}

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

html, body {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 18px;
    color: var(--text-color);
    background: var(--background-color);
    height: 100%;
    overflow: hidden;
}

a {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.container {
    position: relative;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    width: var(--container-width);
    height: 100vh;
}

.heading {
    margin: 20px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

h1.title {
    font-size: 74px;
    line-height: 66px;
    font-weight: bold;
}

.scores-container {
    float: right;
}

.score-container,
.best-container {
    float: left;
    padding: var(--padding-small);
    background: var(--background-dark);
    border-radius: var(--border-radius);
    font-size: 25px;
    font-weight: bold;
    color: white;
    text-align: center;
}

.score-container {
    position: relative;
    margin-right: 15px;
    margin-bottom: 5px;
}

.score-container .title,
.best-container .title {
    font-size: 13px;
    color: #eee4da;
}

.score-addition {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    color: var(--background-medium);
    z-index: 100;
    opacity: 0;
    font-size: 1rem;
    animation: 2s moveup;
}

.above-game {
    font-size: 0.9rem;
}

.restart-btn {
    margin: 5px 0 0 5px;
    float: right;
    padding: var(--padding-medium);
    background: var(--background-medium);
    color: white;
    height: 40px;
    line-height: 40px;
    border-radius: var(--border-radius);
    font-weight: bold;
}

h2.subtitle {
    font-size: 0.7em;
}

.game-container {
    position: relative;
    margin-top: 15px;
    width: var(--container-width);
    height: var(--container-height);
    background: #7BA098;
    border-radius: 6px;
    touch-action: none;
}

.grid-container,
.tile-container,
.pop-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    width: calc(var(--container-width) - 24px);
    height: calc(var(--container-height) - 24px);
}

.grid-row {
    display: flex;
    margin-bottom: 2%;
}

.grid-row,
.tile {
    height: var(--tile-size);
}

.grid-cell,
.tile {
    width: var(--tile-size);
    border-radius: var(--border-radius);
}

.grid-cell {
    margin-right: 2%;
    background: var(--background-light);
}

.grid-cell:nth-of-type(4n) {
    margin-right: 0;
}

.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--tile-font-size);
    font-weight: bold;
    background: #eee4da;
    transition: all 0.15s ease;
}

.tile.new-tile {
    animation: 0.5s appear;
}

.tile.addition {
    animation: 0.3s add;
}

.tile[data-val] {
    color: #f9f6f2;
}

.tile[data-val="2"] { background: var(--tile-color-2); color: #776e65; }
.tile[data-val="4"] { background: var(--tile-color-4); color: #776e65; }
.tile[data-val="8"] { background: var(--tile-color-8); }
.tile[data-val="16"] { background: var(--tile-color-16); }
.tile[data-val="32"] { background: var(--tile-color-32); }
.tile[data-val="64"] { background: var(--tile-color-64); }
.tile[data-val="128"] { background: var(--tile-color-128); font-size: var(--large-tile-font-size); }
.tile[data-val="256"] { background: var(--tile-color-256); font-size: var(--large-tile-font-size); box-shadow: 0 0 30px 10px var(--tile-shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.19048); }
.tile[data-val="512"] { background: var(--tile-color-512); font-size: var(--large-tile-font-size); box-shadow: 0 0 30px 10px var(--tile-shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.2381); }
.tile[data-val="1024"] { background: var(--tile-color-1024); font-size: var(--larger-tile-font-size); box-shadow: 0 0 30px 10px var(--tile-shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.28571); }
.tile[data-val="2048"] { background: var(--tile-color-2048); font-size: var(--larger-tile-font-size); box-shadow: 0 0 30px 10px var(--tile-shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.33333); }

.pop-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: rgba(238, 228, 218, 0.8);
    z-index: 100;
    opacity: 0;
    transition: all 1s ease;
}

.pop-container.action {
    opacity: 1;
}

.pop-container p {
    font-size: 60px;
    font-weight: bold;
}

.winning-container p:nth-child(1) {
    transform: rotate(90deg);
}

.winning-container.action p:nth-child(1) {
    transform-origin: center;
    animation: winning var(--winning-animation);
}

.failure-container.action p:nth-child(1) {
    transform-origin: center;
    animation: failure var(--failure-animation);
}

@keyframes winning {
    0%, 25%, 50%, 75%, 100% { transform: rotate(90deg) translateX(-5px); }
    12.5% { transform: rotate(80deg); }
    37.5% { transform: rotate(70deg); }
    62.5% { transform: rotate(100deg); }
    87.5% { transform: rotate(120deg); }
}

@keyframes failure {
    0%, 25%, 50%, 75%, 100% { transform: rotate(90deg) scale(0.7, 1) rotateX(40deg); }
    12.5% { transform: rotate(90deg); }
    37.5% { transform: rotate(90deg); }
    62.5% { transform: rotate(90deg); }
    87.5% { transform: rotate(90deg); }
}
