:root {
    /* Palette */

    --blue: #0C2E52;
    --blue-dark: #041C37;
    --blue-light: #516D92;
    --green: #43F0D9;
    --red: #F97262;
    --twitch-purple: #9147ff;
    --yellow: #FFDA45;

    /* Context colours */
    --bg: var(--blue-dark);
    --border: var(--blue-light);
    --button-new-game: var(--twitch-purple);
    --primary: var(--green);

    --font-body: 'DynaPuff', sans-serif;
    --font-heading: 'Unkempt', sans-serif;
    --clean-font: 'Karla', sans-serif;

    --radius: 12px;
}

.help-text {
    color: #bdcde3;
    font-family: var(--clean-font);
    font-size: 15px;
    line-height: 1.4;
}

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

body {
    background-color: var(--bg);
    color: white;
    font-family: var(--font-body);
    font-size: 21px;
    margin: 0;
}

input, textarea, select, button {
    font-family: var(--font-body);
    font-size: 18px;
}

dialog {
    color: inherit;
}

:root {
    --modal-motion-duration: .5s;
}

.vote-progress {
    background: var(--blue);
    border: 1px solid var(--border);
    border-radius: 999px;
    height: 12px;
    overflow: hidden;
}

.vote-progress__fill {
    background: var(--twitch-purple);
    display: block;
    height: 100%;
    transform-origin: left;
    width: 100%;

    &.is-running {
        animation: vote-progress-drain linear forwards;
    }
}

@keyframes vote-progress-drain {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

dialog:not(.overlay-dialog),
.overlay-modal {
    opacity: 0;
    transform: translateY(-50%);
    transition: opacity var(--modal-motion-duration) ease, transform var(--modal-motion-duration) ease, display var(--modal-motion-duration) allow-discrete, overlay var(--modal-motion-duration) allow-discrete;

    &[open],
    &:not([hidden]).overlay-modal {
        opacity: 1;
        transform: translateY(0);

        @starting-style {
            opacity: 0;
            transform: translateY(50%);
        }
    }

}

dialog:not(.overlay-dialog) {
    &.is-replacing {
        opacity: 0;
        transform: translateY(-50%);
    }

    &.is-backdrop-held::backdrop {
        opacity: 1;
        transition: none;

        @starting-style {
            opacity: 1;
        }
    }

    &.is-replaced::backdrop {
        display: none;
    }

    &::backdrop {
        opacity: 0;
        transition: opacity var(--modal-motion-duration) ease, display var(--modal-motion-duration) allow-discrete, overlay var(--modal-motion-duration) allow-discrete;
    }

    &[open]::backdrop {
        opacity: 1;

        @starting-style {
            opacity: 0;
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    dialog:not(.overlay-dialog),
    dialog:not(.overlay-dialog)::backdrop,
    .overlay-modal,
    .round-countdown { transition: none; }
}

h1, h2, h3, h4, h5, h6, label {
    color: var(--font-heading);
    margin-bottom: 12px;
    margin-top: 0;
}
p {
    margin-top: 0;
}

label {
    margin-bottom: 0;
}

[hidden]:not(.overlay-modal):not(.overlay__backdrop):not(.round-countdown) {
    display: none !important;
}

.winner-dialog__avatar {
    display: inline-block;
    margin-top: 24px;
    position: relative;
}

.winner-confetti {
    height: 100%;
    inset: 0;
    object-fit: fill;
    pointer-events: none;
    position: absolute;
    width: 100%;
    z-index: -1;
}

.winner-dialog__picture {
    border: 3px solid var(--yellow);
    border-radius: 50%;
    display: block;
    height: 100px;
    width: 100px;
}

.winner-dialog__crown {
    left: 50%;
    position: absolute;
    top: -24px;
    transform: translateX(-50%) rotate(-10deg);
    width: 45px;
}

.winner-dialog__name {
    font-size: 26px;
    margin-top: 0;
    overflow-wrap: anywhere;
}

.winner-dialog__runners {
    font-size: 16px;
    margin: 0 0 20px;

    & p {
        color: var(--blue-light);
        margin: 0 0 8px;
    }

    & ol {
        display: flex;
        flex-wrap: wrap;
        gap: 8px 20px;
        justify-content: center;
        list-style: none;
        margin: 0;
        padding: 0;
    }

    & li {
        overflow-wrap: anywhere;
    }

    & li:nth-child(1) { color: #ffda45; }
    & li:nth-child(2) { color: #c5d0df; }
    & li:nth-child(3) { color: #e8a36b; }
}

.round-countdown {
    background: var(--blue-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .4);
    display: flex;
    flex-direction: column;
    font-size: 16px;
    gap: 4px;
    padding: 12px 18px;
    pointer-events: none;
    position: absolute;
    right: 12px;
    text-align: center;
    top: 12px;
    z-index: 5;

    opacity: 1;
    transform: translateX(0);
    transition: opacity var(--modal-motion-duration) ease, transform var(--modal-motion-duration) ease, display var(--modal-motion-duration) allow-discrete;

    @starting-style {
        opacity: 0;
        transform: translateX(30%);
    }

    &[hidden] {
        display: none;
        opacity: 0;
        transform: translateX(30%);
    }

    & span { font-family: var(--clean-font); font-size: 14px; }
    & .round-countdown__number { color: var(--yellow); font-size: 36px; line-height: 1; }
}

.loading-spinner {
    animation: loading-spin .8s linear infinite;
    border: 4px solid var(--blue-light);
    border-radius: 50%;
    border-top-color: var(--green);
    height: 48px;
    width: 48px;
}

@keyframes loading-spin {
    to {
        transform: rotate(360deg);
    }
}

.leaderboard {
    position: relative;

    &[aria-busy='true'] .leaderboard__list {
        visibility: hidden;
    }
}

.leaderboard__loading {
    align-items: center;
    display: flex;
    inset: 0;
    justify-content: center;
    position: absolute;
}

.leaderboard__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    list-style: none;
    margin: 20px 0;
    padding: 0;

    & li {
        align-items: center;
        background: var(--blue);
        border: 1px solid var(--border);
        border-radius: 8px;
        display: flex;
        gap: 12px;
        padding: 10px 14px;
    }

    & li:nth-child(1) .leaderboard__rank { color: var(--yellow); }
    & li:nth-child(2) .leaderboard__rank { color: #c5d0df; }
    & li:nth-child(3) .leaderboard__rank { color: #e8a36b; }

    & li strong { color: var(--blue-light); }
    & li:nth-child(-n+3) strong { color: white; }
    & li:nth-child(1) { font-size: 1.2em; }
    & li:nth-child(2) { font-size: 1.1em; }
    & li:nth-child(-n+3) .leaderboard__rank { min-height: 28px; }
    & li:nth-child(-n+3):not(.leaderboard__empty) .leaderboard__rank::before {
        background: currentColor;
        mask: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTcgM2gxMHYyaDR2M2E1IDUgMCAwIDEtNSA1aC0uMUE1IDUgMCAwIDEgMTMgMTUuOVYxOWg0djJIN3YtMmg0di0zLjFBNSA1IDAgMCAxIDguMSAxM0g4YTUgNSAwIDAgMS01LTVWNWg0em0wIDRINXYxYTMgMyAwIDAgMCAyIDIuODN6bTEyIDBoLTJ2My44M0EzIDMgMCAwIDAgMTkgOHoiLz48L3N2Zz4=') center / 20px no-repeat;
    }
    & li:nth-child(1) .leaderboard__rank::before { mask-size: 28px; }
    & li:nth-child(2) .leaderboard__rank::before { mask-size: 24px; }
}

.leaderboard__rank {
    align-items: center;
    display: grid;
    flex: 0 0 58px;
    gap: 6px;
    grid-template-columns: 28px 1fr;
    text-align: center;

    &::before {
        content: '';
        height: 28px;
        width: 28px;
    }
}

.leaderboard__name {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
    text-align: left;
}
