:root {
    --text: #d7dadc;
    --text-flipped: #ffffff;
    --background: #121213;
    --tile-background: rgb(79, 79, 79);
    --letter-correct: #6aaa64;
    --letter-present: #c9b458;
    --letter-absent: #3a3a3c;
    --border-inactive: #3a3a3c;
    --border-active: #565758;
    --key-background: #818181;
}

html {
    height: 100%
}

body {
    font-family: sans-serif;
    background-color: var(--background);
    color: var(--text);
    display: flex;
    justify-content: center;
    height: 100%;
    margin: 0;
}

.wrapper {
    max-width: 500px;
    width: 100%;
    display: flex;
    flex: 1;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    height: 100%;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    height: 50px;
    line-height: 50px;
    border-bottom: 1px solid var(--border-inactive);
}

h1 {
    width: 400px;
    user-select: none;
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 3px;
    color: var(--text);
    margin: 0px;
}

.board {
    display: grid;
    grid-gap: 5px;
    grid-template-rows: repeat(6, 1fr);
    padding: 10px;
    box-sizing: border-box;
    width: 100%;
    height: 420px;
    max-width: 350px;
}

.board .row {
    display: grid;
    grid-gap: 5px;
    grid-template-columns: repeat(5, 1fr);
}

.tile {
    display: inline-block;
    font-size: 2rem;
    line-height: 2rem;
    font-weight: bold;
    vertical-align: middle;
    display: inline-flex;
    justify-content: center;
    text-transform: uppercase;
    align-items: center;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    user-select: none;
}


/**
 * Keyboard
 */

#keyboard {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 5px;
}

.key {
    aspect-ratio: 1;
    justify-content: center;
    align-items: center;
    display: flex;

    font-weight: bold;

    border-radius: 5px;
    background-color: var(--key-background);
}


/**
 * States
 */
.board .row[data-state="invalid"] {
    animation: shake 600ms;
}

.tile[data-state="initial"] {
    border: solid 2px var(--border-inactive);
}

.tile[data-state="enter"] {
    animation: enter 100ms 1;
    border: solid 2px var(--border-active);
}

.key[data-state="absent"] {
    background-color: var(--letter-absent);
}

.key[data-state="present"] {
    background-color: var(--letter-present);
}

.key[data-state="correct"] {
    background-color: var(--letter-correct);
}

.tile[data-state="absent"] {
    border: solid 2px var(--border-active);
}

.row[data-state="valid"] .tile[data-state="absent"] {
    animation: flip-absent 500ms ease-in forwards;
}

.row[data-state="valid"] .tile:nth-child(2)[data-state="absent"] {
    animation-delay: 0.1s;
}

.row[data-state="valid"] .tile:nth-child(3)[data-state="absent"] {
    animation-delay: 0.2s;
}

.row[data-state="valid"] .tile:nth-child(4)[data-state="absent"] {
    animation-delay: 0.3s;
}

.row[data-state="valid"] .tile:nth-child(5)[data-state="absent"] {
    animation-delay: 0.4s;
}

.tile[data-state="present"] {
    border: solid 2px var(--border-active);
}

.row[data-state="valid"] .tile[data-state="present"] {
    animation: flip-present 500ms ease-in forwards;
}

.row[data-state="valid"] .tile:nth-child(2)[data-state="present"] {
    animation-delay: 0.1s;
}

.row[data-state="valid"] .tile:nth-child(3)[data-state="present"] {
    animation-delay: 0.2s;
}

.row[data-state="valid"] .tile:nth-child(4)[data-state="present"] {
    animation-delay: 0.3s;
}

.row[data-state="valid"] .tile:nth-child(5)[data-state="present"] {
    animation-delay: 0.4s;
}

.tile[data-state="correct"] {
    border: solid 2px var(--border-active);
}

.row[data-state="valid"] .tile[data-state="correct"] {
    animation: flip-correct 500ms ease-in forwards;
}

.row[data-state="valid"] .tile:nth-child(2)[data-state="correct"] {
    animation-delay: 0.1s;
}

.row[data-state="valid"] .tile:nth-child(3)[data-state="correct"] {
    animation-delay: 0.2s;
}

.row[data-state="valid"] .tile:nth-child(4)[data-state="correct"] {
    animation-delay: 0.3s;
}

.row[data-state="valid"] .tile:nth-child(5)[data-state="correct"] {
    animation-delay: 0.4s;
}

.row[data-state="correct"] .tile[data-state="correct"] {
    border: solid 2px var(--letter-correct);
}

.row[data-state="correct"] .tile {
    animation: bounce 500ms forwards;
    background-color: var(--letter-correct);
    color: var(--text-flipped);
}

.row[data-state="correct"] .tile:nth-child(2) {
    animation-delay: 0.2s;
}

.row[data-state="correct"] .tile:nth-child(3) {
    animation-delay: 0.1s;
}

.row[data-state="correct"] .tile:nth-child(4) {
    animation-delay: 0.4s;
}

.row[data-state="correct"] .tile:nth-child(5) {
    animation-delay: 0.3s;
}

.modal[data-state="win"] header.win {
    display: block;
}

.modal[data-state="lose"] header.lose {
    display: block;
}


/**
 * Animations
*/

@keyframes flip-absent {
    0% {
        transform: rotateX(0deg);
        background-color: var(--tile-background);
        border: solid 2px var(--border-active);
    }

    49% {
        background-color: var(--tile-background);
        border: solid 2px var(--border-active);
    }

    50% {
        transform: rotateX(-90deg);
        background-color: var(--letter-absent);
        border: solid 2px var(--letter-absent);
        color: var(--text-flipped);
    }

    100% {
        transform: rotateX(0deg);
        background-color: var(--letter-absent);
        border: solid 2px var(--letter-absent);
        color: var(--text-flipped);
    }
}

@keyframes flip-present {
    0% {
        transform: rotateX(0deg);
        background-color: var(--tile-background);
        border: solid 2px var(--border-active);
    }

    49% {
        background-color: var(--tile-background);
        border: solid 2px var(--border-active);
    }

    50% {
        transform: rotateX(-90deg);
        background-color: var(--letter-present);
        border: solid 2px var(--letter-present);
        color: var(--text-flipped);
    }

    100% {
        transform: rotateX(0deg);
        background-color: var(--letter-present);
        border: solid 2px var(--letter-present);
        color: var(--text-flipped);
    }
}

@keyframes flip-correct {
    0% {
        transform: rotateX(0deg);
        background-color: var(--tile-background);
        border: solid 2px var(--border-active);
    }

    49% {
        background-color: var(--tile-background);
        border: solid 2px var(--border-active);
    }

    50% {
        transform: rotateX(-90deg);
        background-color: var(--letter-correct);
        border: solid 2px var(--letter-correct);
        color: var(--text-flipped);
    }

    100% {
        transform: rotateX(0deg);
        background-color: var(--letter-correct);
        border: solid 2px var(--letter-correct);
        color: var(--text-flipped);
    }
}

@keyframes enter {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    40% {
        transform: scale(1.1);
        opacity: 1;
    }
}

@keyframes shake {

    10%,
    90% {
        transform: translateX(-1px);
    }

    20%,
    80% {
        transform: translateX(2px);
    }

    30%,
    50%,
    70% {
        transform: translateX(-4px);
    }

    40%,
    60% {
        transform: translateX(4px);
    }
}

@keyframes bounce {

    0%,
    20% {
        background-color: var(--letter-correct);
        transform: translateY(0);
    }

    40% {
        transform: translateY(-30px);
    }

    50% {
        transform: translateY(5px);
    }

    60% {
        transform: translateY(-15px);
    }

    80% {
        transform: translateY(2px);
    }

    100% {
        transform: translateY(0);
        background-color: var(--letter-correct);
    }
}

@media (max-width: 500px) {
    h1 {
        font-size: 1.5em;
    }

    header button {
        margin: 0px 10px;
    }
}

@media (max-width: 350px) {
    h1 {
        font-size: 1.2em;
    }
}

@media (max-width: 300px) {
    h1 {
        font-size: 0.6em;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}
