body {
    align-items: center;
    background-image: url("../images/squiggle-background.svg");
    background-position: center center;
    background-size: 1920px 1080px;
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

.startup-loading {
    align-items: center;
    background: var(--blue-dark) url('../images/squiggle-background.svg') center / 1920px 1080px;
    display: flex;
    flex-direction: column;
    gap: 36px;
    inset: 0;
    justify-content: center;
    opacity: 1;
    position: fixed;
    transition: opacity .4s ease;
    z-index: 10002;

    &.is-finished {
        opacity: 0;
    }

    @media (prefers-reduced-motion: reduce) {
        transition: none;
    }
}

.startup-loading__logo {
    max-width: 320px;
    width: min(70vw, 320px);
}

html.is-startup-transitioning:has(#startup-loading:not([hidden])) .startup-loading__logo,
html.is-startup-transitioning:has(#startup-loading[hidden]) .login__logo {
    view-transition-name: startup-logo;
}

::view-transition-old(startup-logo),
::view-transition-new(startup-logo) {
    animation-duration: .4s;
}

.host-waiting {
    background: var(--blue-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 24px rgba(0, 0, 0, .5);
    left: 50%;
    padding: 24px;
    position: fixed;
    text-align: center;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
}

.visually-hidden {
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
}

.overlay-warning {
    background: var(--yellow);
    color: var(--blue-dark);
    left: 0;
    padding: 10px 16px;
    position: fixed;
    right: 0;
    text-align: center;
    top: 0;
    z-index: 10;

    & button {
        background: transparent;
        border: 0;
        color: inherit;
        cursor: pointer;
        text-decoration: underline;
    }
}

.game-nav__logo {
    display: block;
    flex: 0 0 auto;
    width: 190px;
}

.game-nav__identity {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.settings-page,
.game-dialog,
.winner-dialog {
    background: var(--blue-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;

    & input,
    & select {
        background: #06152c;
        border: 1px solid var(--border);
        border-radius: 8px;
        box-sizing: border-box;
        color: white;
        padding: 10px;
        width: 100%;
    }

}

.settings-page {
    max-width: min(90vw, 600px);
    width: 100%;

    &::backdrop {
        background: rgba(0, 0, 0, .7);
    }

    & input {
        margin: 8px 0 16px;
    }
}

.winner-dialog {
    isolation: isolate;
    max-width: min(90vw, 560px);
    overflow: hidden;
    text-align: center;
    width: 100%;

    &::backdrop {
        background: rgba(0, 0, 0, .85);
    }
}

.dialog__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    position: relative;

    &.dialog__actions--winner {
        justify-content: center;

        & button {
            flex: 1 1 0;
        }
    }

}

.game-dialog {
    box-sizing: border-box;
    max-height: 90vh;
    max-width: min(90vw, 600px);
    width: 100%;

    &::backdrop {
        background: rgba(0, 0, 0, .7);
    }

    & form {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    & label {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    & input,
    & select {
        height: 46px;
        line-height: 24px;
    }
}

.game-dialog__logo {
    display: block;
    margin: 0 auto 24px;
    max-width: 400px;
    width: 100%;
}

.game-dialog__heading {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;

    & h2 {
        margin: 0;
    }

    & .stream-switcher__panel {
        left: auto;
        max-width: min(300px, calc(90vw - 48px));
        right: 0;
    }
}

.word-mode,
.word-generator__row {
    display: flex;
    gap: 12px;
}

.word-mode {
    gap: 0;
    margin-bottom: -1px;
    position: relative;
}

.word-picker__panel {
    border: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
}

.button.word-mode__choice {
    background: var(--blue);
    border-color: var(--border);
    border-radius: 8px 8px 0 0;
    color: white;
    flex: 1;

    &.is-selected {
        background: var(--blue-dark);
        border-color: var(--border);
        border-bottom-color: var(--blue-dark);
        z-index: 1;
    }

    & svg {
        flex-basis: 26px;
        height: 26px;
        width: 26px;
    }

    &.is-selected svg {
        color: var(--primary);
    }
}

.chat-vote {
    & input {
        margin: 0;
    }
}

.chat-vote__content,
.chat-vote__options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-vote__content {
    padding: 0;
}

.chat-vote__row {
    align-items: center;
    display: flex;
    gap: 8px;
}

.chat-vote__row output {
    color: var(--primary);
    flex: 0 0 40px;
    text-align: center;
}

.chat-vote__remove {
    flex: 0 0 40px;
    font-size: 24px;
    height: 40px;
    padding: 0;
}

.chat-vote__timer input {
    max-width: 100px;
}

.chat-vote .dialog__actions > button {
    flex: 1;
}

.word-generator,
.word-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.word-generator__row select {
    min-width: 0;
}

.game-dialog .help-text {
    margin: 0;
}

dialog {
    box-shadow: 0 12px 24px rgba(0, 0, 0, .5);

    &::backdrop {
        backdrop-filter: blur(8px);
    }
}

.settings-page button[data-state] {
    color: transparent;
    position: relative;
    transition: background-color .25s, color .25s;

    &::after {
        color: white;
        left: 50%;
        position: absolute;
        top: 50%;
        transform: translate(-50%, -50%);
    }

    &[data-state='loading'] {
        background: var(--blue-light);

        &::after {
            animation: button-spin .8s linear infinite;
            border: 2px solid rgba(255, 255, 255, .35);
            border-radius: 50%;
            border-top-color: white;
            content: '';
            height: 16px;
            width: 16px;
        }
    }

    &[data-state='success'] {
        background: #a467ed;

        &::after {
            content: '✓';
        }
    }

    &[data-state='resetting'] {
        background: var(--primary);
        color: var(--blue-dark);
    }
}

@keyframes button-spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

#login-step,
#setup-step,
#game-step {
    display: none;
}

.step {
    box-sizing: border-box;
    max-width: 1650px;
}

.login__logo {
    margin: 0 auto 36px;
    max-width: 320px;
    width: 100%;
}

.button {
    align-items: center;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    gap: 8px;
    justify-content: center;
    padding: 10px 16px;

    & svg {
        fill: currentColor;
        flex: 0 0 20px;
        height: 20px;
        width: 20px;
    }

    &:disabled {
        cursor: not-allowed;
        filter: brightness(.65) saturate(.5);
    }

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

    &.button--primary {
        background: var(--primary);
        color: var(--blue-dark);
    }

    &.button--leaderboard-hide {
        background: var(--red);
        color: var(--blue-dark);
    }

    &.button--secondary {
        background: var(--blue);
        border-color: var(--border);
        color: white;
    }

    &.button--ghost {
        background: transparent;
        color: white;
    }

    &.button--link {
        background: transparent;
        color: inherit;
        text-decoration: underline;
    }

    &.button--new-game {
        background: var(--button-new-game);
        color: white;
    }

    &.button--modifier {
        background: var(--yellow);
        color: var(--blue-dark);

        &.is-voting {
            background: var(--red);

            & svg {
                transform: rotate(45deg);
            }
        }
    }

    &.button--small {
        font-size: 12px;
        gap: 4px;
        padding: 4px 8px;

        & svg {
            flex-basis: 14px;
            height: 14px;
            width: 14px;
        }
    }

    &.button--account {
        background: var(--twitch-purple);
        border: 2px solid white;
        border-radius: 50%;
        height: 40px;
        padding: 0;
        width: 40px;

        &:has(img:not([hidden])) {
            background: transparent;
            border-color: transparent;
        }

        & img {
            border-radius: 50%;
            height: 100%;
            object-fit: cover;
            width: 100%;
        }
    }
}

body[data-step="login"] #login-step,
body[data-step="setup"] #setup-step {
    display: flex;
    flex-direction: column;
}

body[data-step="game"] #game-step {
    align-items: start;
    box-sizing: border-box;
    display: grid;
    gap: 20px;
    grid-template-areas: "navigation" "game";
    grid-template-columns: minmax(0, 1fr);
    min-height: 600px;
    min-width: 0;
    padding: 24px;
    width: 100%;
}

.game-nav {
    align-items: center;
    background-color: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    gap: 16px;
    grid-area: navigation;
    isolation: isolate;
    justify-content: space-between;
    padding: 12px 16px;
    position: relative;
    z-index: 3;

    &::before {
        backdrop-filter: blur(10px);
        border-radius: inherit;
        content: '';
        inset: 0;
        pointer-events: none;
        position: absolute;
        z-index: -1;
    }
}

.game-nav__toggle {
    display: none;
}

.game-nav__links {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: flex-end;
}

.game-nav__item {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    text-align: left;

    svg {
        fill: currentColor;
        flex: 0 0 24px;
        height: 24px;
        width: 24px;
    }

    &.active {
        background: url('../images/paint-stripe.svg') center / 100% 100% no-repeat;
        color: var(--blue-dark);
    }
}

.game-nav__item--source {
    background: var(--blue);
    border: 1px solid var(--border);
}

.game-nav__item:focus-visible,
.game-nav__toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

.game {
    align-items: start;
    background-color: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: grid;
    gap: 16px;
    grid-area: game;
    grid-template-areas: "controls word chat" "controls canvas chat";
    grid-template-columns: 175px minmax(0, 1fr) 315px;
    grid-template-rows: auto 1fr;
    min-width: 0;
    padding: 16px;
    position: relative;
    isolation: isolate;

    &::before {
        backdrop-filter: blur(10px);
        border-radius: inherit;
        content: '';
        inset: 0;
        pointer-events: none;
        position: absolute;
        z-index: -1;
    }
}

.game__sidebar {
    background-color: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-sizing: border-box;
    padding: 16px;
}

.game__word {
    align-items: start;
    background: var(--blue-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: grid;
    gap: 6px 12px;
    grid-area: word;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) 270px;
    min-width: 0;
    padding: 16px;
    position: relative;
    z-index: 2;
}

.game__status-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    overflow-wrap: anywhere;

    & span {
        color: var(--blue-light);
        font-size: 14px;
    }

    & strong {
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        display: -webkit-box;
        font-size: 20px;
        overflow: hidden;
        overflow-wrap: anywhere;
    }

    &.game__status-item--word strong {
        -webkit-line-clamp: 2;
        color: var(--primary);
        font-size: 24px;
    }

    &.game__status-item--modifier {
        position: relative;
    }
}

#current-category,
#current-modifier {
    -webkit-line-clamp: 2;
}

.game__status-heading {
    align-items: center;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    min-height: 26px;

    & > span,
    & button {
        white-space: nowrap;
    }

    & button span {
        color: inherit;
        font-size: inherit;
    }
}

#current-modifier {
    &.is-active,
    &.is-voting {
        color: var(--red);
    }
}

.floating-panel {
    background: var(--blue-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 24px rgba(0, 0, 0, .5);
    box-sizing: border-box;
    max-height: 280px;
    max-width: min(320px, 80vw);
    overflow-y: auto;
    padding: 12px;
    position: absolute;
    right: 0;
    top: calc(100% + 12px);
    width: 280px;
    z-index: 3;
}

.account-menu {
    position: relative;
}

.account-menu__panel {
    & p:first-child {
        margin: 0;
    }

    & .dialog__actions {
        gap: 12px;
    }
}

.vote-progress {
    align-self: start;
    background: linear-gradient(to bottom, transparent 6px, var(--blue) 6px, var(--blue) 18px, transparent 18px);
    border: 0;
    height: 24px;
    margin-top: 3px;
    max-width: 180px;
    padding: 6px 0;
    width: 100%;
}

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

    & li {
        align-items: center;
        background: var(--blue);
        border-radius: 8px;
        display: flex;
        gap: 12px;
        justify-content: space-between;
        padding: 8px 10px;
    }

    & li span {
        color: white;
        font-size: 14px;
        min-width: 0;
    }

    & li strong {
        background: var(--twitch-purple);
        border-radius: 20px;
        color: white;
        flex: 0 0 auto;
        font-size: 14px;
        min-width: 20px;
        padding: 4px 6px;
        text-align: center;
    }
}

.vote-panel__outcome {
    font-size: 14px;
    margin: 0;
}

.is-flashing {
    animation: flash 1s ease-out;
}

@keyframes flash {
    0%, 50% {
        filter: drop-shadow(0 0 8px var(--flash-colour, var(--primary)));
    }

    100% {
        filter: drop-shadow(0 0 0 transparent);
    }
}

#current-modifier {
    --flash-colour: var(--red);
}

@media (prefers-reduced-motion: reduce) {
    .is-flashing {
        animation: none;
    }
}

.game__sidebar {
    align-self: stretch;
    display: flex;
    grid-area: chat;
    min-height: 320px;
    min-width: 0;
}

.controls {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 6px;
    grid-area: controls;

    & button {
        background: var(--blue);
        border: 1px solid var(--border);
        border-radius: 8px;
        color: white;
        cursor: pointer;
        min-height: 36px;
        min-width: 36px;

        &:disabled {
            cursor: default;
            opacity: .45;
        }

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

        &.is-selected {
            outline: 2px solid var(--primary);
            outline-offset: 2px;
        }

        &.tool {
            align-items: center;
            background: transparent;
            border-color: transparent;
            display: flex;
            gap: 10px;
            padding: 10px;
            text-align: left;
            width: 100%;

            & svg {
                flex: 0 0 24px;
            }

            &.is-selected {
                background: var(--primary);
                border-color: var(--primary);
                box-shadow: 0 0 0 3px rgba(67, 240, 217, .2);
                color: var(--blue-dark);
                outline: none;
            }
        }
    }

    & svg {
        fill: currentColor;
        vertical-align: middle;
    }

    & .colour[data-colour] {
        border-radius: 50%;
        height: 36px;
        width: 36px;
    }
}

#drawing-area {
    aspect-ratio: 16 / 9;
    grid-area: canvas;
    height: auto;
    width: 100%;
}

.controls__section {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 9px;

    &::before {
        color: var(--blue-light);
        content: attr(data-heading);
        font-size: 14px;
        width: 100%;
    }
}

.controls__section--clear {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.controls__section--colours {
    justify-content: space-between;
}

.controls__section--history {
    margin-bottom: 12px;
}

.colour {
    &[data-colour='#000000'] {
        background: #000;
    }

    &[data-colour='#ffffff'] {
        background: #fff;
    }

    &[data-colour='#626b76'] {
        background: #626b76;
    }

    &[data-colour='#8b5a3c'] {
        background: #8b5a3c;
    }

    &[data-colour='#f08bb8'] {
        background: #f08bb8;
    }

    &[data-colour='#43f0d9'] {
        background: #43f0d9;
    }

    &[data-colour='#ff6b68'] {
        background: #ff6b68;
    }

    &[data-colour='#ff804b'] {
        background: #ff804b;
    }

    &[data-colour='#ffda55'] {
        background: #ffda55;
    }

    &[data-colour='#24b77e'] {
        background: #24b77e;
    }

    &[data-colour='#55a4f5'] {
        background: #55a4f5;
    }

    &[data-colour='#b260ef'] {
        background: #b260ef;
    }
}

.controls__size {
    align-items: center;
    display: flex;
    gap: 8px;
    width: 100%;
}

.controls__size-dot {
    background: white;
    border-radius: 50%;
    display: block;
    flex: none;

    &.controls__size-dot--small {
        height: 5px;
        width: 5px;
    }

    &.controls__size-dot--large {
        height: var(--max-brush-display-size, 50px);
        width: var(--max-brush-display-size, 50px);
    }
}

#pen-size {
    accent-color: var(--primary);
    cursor: pointer;
    min-width: 0;
    width: 100%;
}

.controls__custom-colour {
    color: var(--blue-light);
    display: flex;
    flex-direction: column;
    font-size: 14px;
    gap: 4px;
    width: 100%;
}

#custom-colour {
    background: var(--blue);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-sizing: border-box;
    cursor: pointer;
    height: 36px;
    padding: 2px;
    width: 100%;

    &.is-selected {
        outline: 2px solid var(--primary);
        outline-offset: 2px;
    }

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

#clear {
    align-items: center;
    display: flex;
    gap: 8px;
    padding: 8px;
    text-align: left;
    width: 100%;
}

#chat-messages {
    list-style: none;
    max-height: 500px;
    overflow-wrap: anywhere;
    overflow-y: auto;
    padding-left: 0;
}

.live-chat__heading {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;

    & h3 {
        margin: 0;
    }
}

#live-chat-status {
    color: var(--yellow);
    font-size: 12px;

    &[data-state='connected'] {
        color: var(--primary);
    }

    &[data-state='disconnected'] {
        color: var(--red);
    }
}

#twitch-chat-embed {
    border: 0;
    flex: 1;
    margin-top: 12px;
    min-height: 300px;
    width: 100%;
}

#live-chat {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

@media (hover: hover) {
    .button.word-mode__choice:not(.is-selected):hover {
        background: var(--blue-light);
    }

    .button:not(:disabled) {
        &.button--ghost:hover {
            background: var(--blue);
        }

        &.button--primary:hover {
            background: #78f4e4;
        }

        &.button--leaderboard-hide:hover {
            background: #db6255;
        }

        &.button--new-game:hover {
            background: #772ce8;
        }

        &.button--modifier:hover {
            background: #e8c33e;

            &.is-voting {
                background: #db6255;
            }
        }

        &.button--secondary:hover {
            background: var(--blue-light);
            border-color: var(--primary);
        }
    }

    .controls {
        & button:not(:disabled):not(.tool):not(.colour):hover {
            background-color: var(--blue-light);
            border-color: var(--primary);
        }

        & button {
            &.tool:not(.is-selected):hover {
                background-color: rgba(67, 240, 217, .12);
                border-color: transparent;
            }

            &.tool.is-selected:hover {
                background-color: #78f4e4;
            }

            &.colour:hover {
                box-shadow: 0 0 0 2px var(--blue-dark), 0 0 0 4px var(--primary);
            }
        }
    }

    #custom-colour:hover {
        border-color: var(--primary);
    }
}

@media (max-width: 1000px) {
    body[data-step="game"] #game-step {
        padding: 12px;
    }

    .game-nav__links {
        flex-wrap: wrap;
    }

    .game {
        grid-template-areas: "word" "controls" "canvas" "chat";
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto;
    }

    .controls {
        align-self: start;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .game__sidebar {
        align-self: start;
        min-height: 240px;
    }
}

@media (max-width: 600px) {
    .game-nav {
        align-items: flex-start;
        flex-direction: column;
    }

    .game__word {
        grid-template-columns: minmax(0, 1fr);
    }
}

.trusted-hosts {
    border-top: 1px solid var(--border);
    margin-bottom: 24px;
    margin-top: 24px;
    padding-top: 24px;

    & h3 {
        margin: 0 0 12px;
    }

    & label {
        display: block;
        margin-bottom: 6px;
    }
}

.trusted-hosts__add {
    align-items: center;
    display: flex;
    gap: 12px;

    & input {
        flex: 1;
        margin: 0;
        min-width: 0;
    }
}

.trusted-hosts__status {
    margin: 12px 0 6px;
    min-height: 1.5em;
}

.trusted-hosts__list {
    display: grid;
    font-family: var(--clean-font);
    font-size: 16px;
    gap: 12px;
    list-style: none;
    margin: 0;
    max-height: 240px;
    overflow-y: auto;
    padding: 0;

    & li {
        align-items: center;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        display: flex;
        gap: 12px;
        justify-content: space-between;
        padding: 12px;
    }

    & strong {
        min-width: 0;
        overflow-wrap: anywhere;
    }
}

.button {
    &.button--logout,
    &.button--remove-option,
    &.button--remove-host {
        background: var(--red);
        border-color: var(--red);
        color: var(--blue-dark);
        flex-shrink: 0;
        &:hover:not(:disabled) {
            background: color-mix(in srgb, var(--red), black 15%);
        }
    }
}

.settings-page__url-help {
    margin-top: 12px;
}

.getting-started {
    & .getting-started__presence {
        align-items: center;
        display: flex;
        gap: 8px;
        margin: 24px 0;

        &::before {
            background: var(--yellow);
            border-radius: 50%;
            content: '';
            flex: 0 0 8px;
            height: 8px;
        }

        &[data-state='connected']::before {
            background: var(--green);
        }
    }

    & #getting-started-finish {
        width: 100%;
    }
}

.stream-switcher {
    position: relative;
}

.stream-switcher__panel {
    left: 0;
    right: auto;
    width: 300px;

    & ul {
        display: grid;
        gap: 12px;
        list-style: none;
        margin: 12px 0 0;
        padding: 0;
    }

    & button {
        justify-content: flex-start;
        width: 100%;
    }
}

.host-waiting__return {
    bottom: 24px;
    left: 50%;
    position: fixed;
    transform: translateX(-50%);
    z-index: 10001;
}
