:root {
    --theme-js: #f7df1e;
    --theme-js-darker: #c4ac00;
    --theme-py: #5ca1ff;
    --theme-py-darker: #3e7dd3;

    --theme: #ffffff;
    --theme-darker: #8b8b8b;
}

@property --left {
    syntax: '<percentage>';
    initial-value: 0%;
    inherits: false;
}

@property --right {
    syntax: '<percentage>';
    initial-value: 0%;
    inherits: false;
}

.bee {
    display: block;
    image-rendering: pixelated;
    position: fixed;
    user-select: none;
    pointer-events: none;
    z-index: 1;
}

*, *::before, *::after {
    box-sizing: inherit;
}

html {
    box-sizing: border-box;
    background: #000000;
    color: #ffffff;
    font-family: 'Inconsolata', monospace;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100dvh;
}

input, button {
    display: block;
    width: 100%;
    padding: 16px;
    font-family: inherit;
    font-size: inherit;
    border: none;
    outline: none;
    color: inherit;
    text-align: inherit;

    &:focus-visible {
        outline: 2px solid var(--theme-darker);
        outline-offset: 2px;
    }
}

input {
    background: #222222;
}

button {
    background: var(--theme);
    color: #000000;
    font-weight: bold;
    cursor: pointer;
    user-select: none;

    &:hover {
        background: var(--theme-darker);
    }
}

.join-container {
    width: 100%;
    padding: 20px;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 1.25rem;

    h1 {
        margin: 0;
        font-size: 2.5rem;

        .brand {
            color: var(--theme);
        }
    }

    p {
        margin: 0;
        font-size: 1rem;
        margin-bottom: 10px;
        line-height: 1.5;
        color: #8b8b8b;

        a {
            text-decoration: none;
            outline-offset: 2px;

            &.pybee {
                color: var(--theme-py);

                &:focus-visible {
                    outline: 2px solid var(--theme-py-darker);
                }
            }

            &.jsbee {
                color: var(--theme-js);

                &:focus-visible {
                    outline: 2px solid var(--theme-js-darker);
                }
            }

            &:hover {
                text-decoration: underline;
            }
        }
    }

    label {
        display: block;
    }
}

.mode-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;

    label {
        display: inline-flex;
        flex-direction: row;
        justify-content: space-between;
        padding: 10px;
        border: 2px solid #222222;
        cursor: pointer;
        position: relative;

        p.title {
            font-size: 1rem;
            line-height: 1.5;
            font-weight: bold;
        }

        p.description {
            margin: 0;
            font-size: 1rem;
            margin-bottom: 10px;
            line-height: 1.5;
            color: #8b8b8b;
        }

        input[type='radio'] {
            height: 1px;
            width: 1px;
            opacity: 0;
            position: absolute;
            cursor: pointer;
        }

        &:has(:checked) {
            border-color: var(--theme);
        }

        &:has(:focus-visible) {
            border-color: #222222;
            outline: 2px solid var(--theme);
            outline-offset: 2px;
        }
    }
}

.game-status {
    width: 100%;
    padding: 40px;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    font-size: 1.25rem;
    background: #111111;

    h1 {
        margin: 0;
        font-size: 1.75rem;
    }

    p {
        margin: 0;
        line-height: 1.5;
        word-wrap: break-word;
    }

    button {
        width: fit-content;
    }

    pre {
        word-wrap: break-word;
        tab-size: 4;
        margin: 0;
        font-size: 1rem;
        color: #8b8b8b;
        margin-top: 16px;
        white-space: pre-wrap;
    }
}

.game {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;

    .header {
        border-bottom: 10px solid #222222;
        padding: 20px;
        font-size: 1.25rem;
        display: flex;
        flex-direction: row;
        gap: 20px;

        .question {
            padding-top: 3px;
            flex: 1;
        }

        .timer {
            min-width: 6ch;
            font-size: 1.75rem;
            text-align: right;
        }
    }

    .players {
        flex: 1;
        width: 100%;
        display: flex;
        flex-direction: row;

        .player {
            flex: 1;
            font-size: 16rem;
            text-align: center;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            user-select: none;

            .fg {
                --left: 100%;
                --right: 100%;
                --speed: 0ms;
                --easing: ease;
                will-change: clip-path;
                position: absolute;
                width: 100%;
                height: 100%;
                left: 0;
                top: 0;
                display: flex;
                align-items: center;
                justify-content: center;
                clip-path: polygon(var(--left) 0%, var(--right) 0%, var(--right) 100%, var(--left) 100%);
                background: #222222;
                pointer-events: none;
                animation: slide-out var(--speed) var(--easing);

                .cursor {
                    position: absolute;
                    margin-top: 1em;
                    height: 14px;
                    width: 1ch;
                    background: currentColor;
                    opacity: 0.5;
                    animation: 1.25s blink infinite linear;
                }
            }

            .you {
                font-size: 2rem;
                position: absolute;
                top: 20px;
                color: var(--theme);
            }

            &.is-you .fg {
                background: var(--theme);
                color: #000000;

                .you {
                    color: #000000;
                }
            }

            &.is-current .fg {
                --left: 0%;
                --right: 100%;
                animation: slide-in var(--speed) var(--easing);
            }

            &.animate .fg {
                --speed: 200ms;
            }

            .submit {
                font-size: 1.25rem;
                background: #000000;
                color: #ffffff;
                width: fit-content;
                position: absolute;
                bottom: 20px;

                &:hover {
                    background: #222222;
                }

                &:focus-visible {
                    outline-color: #000000;
                }
            }
        }
    }
}

@keyframes slide-in {
    0% {
        --left: 0%;
        --right: 0%;
    }
    100% {
        --left: 0%;
        --right: 100%;
    }
}

@keyframes slide-out {
    0% {
        --left: 0%;
        --right: 100%;
    }
    100% {
        --left: 100%;
        --right: 100%;
    }
}

@keyframes blink {
    0% { opacity: 0; }
    10% { opacity: 0.5; }
    60% { opacity: 0.5; }
    70% { opacity: 0; }
    100% { opacity: 0; }
}

.keyboard {
    display: none;

    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    background: #000000;
    touch-action: pinch-zoom;
    user-select: none;
    /* display: flex; */
    flex-direction: column;
    padding: 2.5px;
    -webkit-tap-highlight-color: transparent;
    isolation: isolate;

    .row {
        display: flex;
        flex-direction: row;
        position: relative;

        .key {
            box-sizing: border-box;
            height: 12vw;
            max-height: 60px;
            min-height: 40px;
            padding: 2.5px;
            flex: 1;

            &.key-enter {
                flex: unset;
                min-width: 50px;
            }

            &.key-alt, &.key-default {
                flex: unset;
                min-width: 60px;
            }

            &.key-tab {
                flex: unset;
                min-width: 50px;
            }

            &.key-space {
                flex: 8;
            }

            .inner {
                box-sizing: border-box;
                cursor: pointer;
                background: #222222;
                width: 100%;
                height: 100%;
                border-radius: 5px;
                border-bottom: 1px solid #363636;
                box-shadow: 0 0 3px -1px rgba(255, 255, 255, .4);
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 18px;
                color: #eeeeee;

                .preview {
                    --size: 55px;
                    pointer-events: none;
                    font-size: 26px;
                    position: absolute;
                    top: calc(var(--size) * -1 - 1.5px);
                    width: var(--size);
                    height: var(--size);
                    border-radius: 100%;
                    background: #222222;
                    box-shadow: 0 0 10px -2px rgba(0, 0, 0, .6);
                    z-index: 1;
                    color: #eeeeee;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                }
            }

            &.is-active {
                .inner {
                    background: #333333;

                    &:has(.preview) {
                        box-shadow: none;
                        background: #111111;
                        border-color: #222222;
                        color: #5e5e5e;
                    }
                }
            }

            &.is-uppercase-letter .display {
                position: relative;
                top: 1px;
            }
        }
    }
}

@media (pointer: coarse) and (hover: none) {
    .keyboard {
        display: flex;
    }

    .bee {
        display: none;
    }
}

@media (max-width: 500px) {
    .game {
        .header {
            font-size: 1rem;
        }

        .players {
            .player {
                font-size: 12rem;
            }
        }
    }

    .game-status {
        background: #000000;
        padding: 20px;
    }
}

::selection {
    background: var(--theme);
    background: color-mix(in srgb, var(--theme), transparent 0.00001%); /* fix for Safari */
    color: #000000;
}