:root {
    --bg: #fff;
    --text: #1a1a1b;
    --border: #d3d6da;
    --border-active: #878a8c;
    --green: #6aaa64;
    --yellow: #c9b458;
    --gray: #787c7e;
    --key: #d3d6da;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0
}

html,
body {
    height: 100%;
    overflow: hidden
}

body {
    height: 100dvh
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Helvetica Neue", Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    -webkit-user-select: none;
    user-select: none
}

header {
    width: 100%;
    max-width: 500px;
    border-bottom: 1px solid var(--border);
    padding: clamp(8px, 2vh, 14px) 0;
    text-align: center;
    font: 700 clamp(1.3rem, 5vw, 2rem)/1 Georgia, "Times New Roman", serif;
    letter-spacing: .04em
}

#toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: #fff;
    padding: 12px 18px;
    border-radius: 4px;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
    z-index: 5
}

#toast.show {
    opacity: 1
}

main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom))
}

#boardwrap {
    flex: 1;
    min-height: 0;
    width: 100%;
    container-type: size;
    display: flex;
    align-items: center;
    justify-content: center
}

#board {
    --bs: min(100cqw, 100cqh*5/6);
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: calc(var(--bs)*.015);
    width: var(--bs);
    height: calc(var(--bs)*6/5)
}

#bottom {
    width: 100%;
    flex: none
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: calc(var(--bs)*.015)
}

.tile {
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--bs)*.1);
    font-weight: 700;
    text-transform: uppercase;
    transition: transform .1s
}

.tile.filled {
    border-color: var(--border-active);
    transform: scale(1.04)
}

.tile.correct,
.tile.present,
.tile.absent {
    color: #fff;
    border-color: transparent
}

.tile.correct {
    background: var(--green)
}

.tile.present {
    background: var(--yellow)
}

.tile.absent {
    background: var(--gray)
}

.tile.flip {
    animation: flip .5s ease both
}

@keyframes flip {
    0% {
        transform: rotateX(0)
    }

    50% {
        transform: rotateX(90deg)
    }

    100% {
        transform: rotateX(0)
    }
}

.row.shake {
    animation: shake .4s
}

@keyframes shake {

    20%,
    60% {
        transform: translateX(-5px)
    }

    40%,
    80% {
        transform: translateX(5px)
    }
}

#result {
    min-height: clamp(52px, 9vh, 76px);
    padding: 4px 0;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    justify-content: center
}

#result .msg {
    font-size: 1rem
}

#result .word {
    font: 700 clamp(1.2rem, 4vw, 1.6rem) Georgia, serif;
    letter-spacing: .2em;
    text-transform: uppercase
}

button {
    font: inherit;
    cursor: pointer;
    border: 0
}

#next {
    background: var(--text);
    color: #fff;
    border-radius: 999px;
    padding: 10px 26px;
    font-weight: 700
}

#next:focus-visible,
.key:focus-visible {
    outline: 3px solid #4a90d9;
    outline-offset: 2px
}

#kb {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 1vh, 6px)
}

.krow {
    display: flex;
    justify-content: center;
    gap: clamp(3px, 1vw, 6px)
}

.key {
    flex: 1;
    min-width: 0;
    max-width: 43px;
    height: clamp(40px, 7.5vh, 58px);
    padding: 0;
    border-radius: 4px;
    background: var(--key);
    color: var(--text);
    font-weight: 700;
    font-size: clamp(.7rem, 3.4vw, .9rem);
    touch-action: manipulation;
    text-transform: uppercase
}

.key.wide {
    flex: 1.5;
    max-width: 66px;
    font-size: clamp(.6rem, 2.8vw, .75rem)
}

.key.correct {
    background: var(--green);
    color: #fff
}

.key.present {
    background: var(--yellow);
    color: #fff
}

.key.absent {
    background: var(--gray);
    color: #fff
}

#stats {
    font-size: .8rem;
    color: var(--gray);
    padding: 6px 0;
    text-align: center
}

#loader {
    font-size: .75rem;
    color: var(--gray);
    text-align: center;
    padding: 4px
}

#loader label {
    text-decoration: underline;
    cursor: pointer
}

#loader input {
    display: none
}

@media (max-height:560px) {
    #loader {
        display: none
    }

    #stats {
        padding: 2px 0;
        font-size: .7rem
    }

    header {
        padding: 4px 0
    }

    #result {
        flex-direction: row;
        gap: 12px;
        min-height: 40px
    }

    #result .msg {
        font-size: .85rem
    }
}

@media (max-width:360px) {
    #next {
        padding: 8px 18px
    }
}

@media (prefers-reduced-motion:reduce) {

    .tile,
    .tile.flip,
    .row.shake {
        animation: none;
        transition: none
    }
}