:root {
    --bg: #f2f4f8;
    --bg-elevated: #ffffff;
    --bg-sunken: #e7eaf0;
    --bg-hover: #eef1f6;
    --text: #14181f;
    --text-muted: #5a6472;
    --border: #d4d9e3;
    --border-strong: #b6bdcb;
    --accent: #2f6fd0;
    --accent-hover: #2760b8;
    --accent-contrast: #ffffff;
    --danger: #c8324a;
    --warning: #b7791f;
    --success: #2f8f4e;
    --focus: #2f6fd0;

    --radius-sm: 6px;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow: 0 8px 28px rgba(16, 22, 34, 0.14);
    --topbar-height: 60px;
    --content-max: 1180px;

    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #11151c;
    --bg-elevated: #1a2029;
    --bg-sunken: #0c1016;
    --bg-hover: #222a35;
    --text: #eef1f6;
    --text-muted: #9aa6b6;
    --border: #2b3441;
    --border-strong: #3a4553;
    --accent: #5b9bf3;
    --accent-hover: #79aeff;
    --accent-contrast: #0b0f14;
    --danger: #f0617a;
    --warning: #e2b047;
    --success: #4fc27a;
    --focus: #79aeff;

    --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);

    color-scheme: dark;
}

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

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
    margin: 0;
}

a {
    color: var(--accent);
}

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

/* ---------------------------------------------------------------- primitives */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background-color: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn--primary {
    background-color: var(--accent);
    color: var(--accent-contrast);
}

.btn--primary:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

.btn--secondary {
    background-color: var(--bg-sunken);
    border-color: var(--border);
}

.btn--secondary:hover:not(:disabled),
.btn--ghost:hover:not(:disabled) {
    background-color: var(--bg-hover);
}

.btn--ghost {
    border-color: transparent;
}

.card {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background-color: var(--bg-sunken);
    color: var(--text-muted);
}

.badge--locked {
    background-color: var(--warning);
    color: #1a1200;
}

.badge--live {
    background-color: var(--success);
    color: #04160b;
}

.badge--idle {
    background-color: var(--bg-sunken);
}

.field__label {
    display: block;
    margin-bottom: 4px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.field__input {
    width: 100%;
    min-height: 38px;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background-color: var(--bg);
    color: var(--text);
    font: inherit;
}

.field__check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    cursor: pointer;
}

.field__error {
    margin-top: 12px;
    color: var(--danger);
    font-size: 0.85rem;
}

.banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    padding: 14px 16px;
    border-left: 4px solid var(--border-strong);
}

.banner--error {
    border-left-color: var(--danger);
}

.banner--warning {
    border-left-color: var(--warning);
}

.banner__body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.banner__title {
    font-weight: 700;
}

.banner__text {
    color: var(--text-muted);
}

.avatar {
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    letter-spacing: 0.02em;
    flex: 0 0 auto;
}

/* A stored avatar sits over the deterministic initials disc; the disc stays visible as the fallback. */
.avatar__image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

.avatar--sm {
    width: 28px;
    height: 28px;
    font-size: 0.72rem;
}

.avatar--md {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
}

.avatar--lg {
    width: 56px;
    height: 56px;
    font-size: 1.15rem;
}

/* ------------------------------------------------------------------ toasts */

.toast-stack {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, calc(100vw - 36px));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    background-color: var(--bg-elevated);
    color: var(--text);
    box-shadow: var(--shadow);
    pointer-events: auto;
}

.toast--info {
    border-left-color: var(--accent);
}

.toast--success {
    border-left-color: var(--success);
}

.toast--warning {
    border-left-color: var(--warning);
}

.toast--error {
    border-left-color: var(--danger);
}

.toast__text {
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-word;
}

.toast__dismiss {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background-color: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
}

.toast__dismiss:hover {
    background-color: var(--bg-hover);
    color: var(--text);
}

/*
    Toasts enter with a short fade/slide and, when the player dismisses one by hand, leave with the same
    motion before NotificationHost removes it. Purely decorative: the colours, position and ARIA of the
    stack are unchanged, and both animations are disabled for reduced-motion users.
*/
@media (prefers-reduced-motion: no-preference) {
    .toast {
        animation: toast-in 0.22s ease-out;
    }

    .toast--leaving {
        animation: toast-out 0.16s ease-in forwards;
        pointer-events: none;
    }
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: none;
    }

    to {
        opacity: 0;
        transform: translateY(6px) scale(0.98);
    }
}

@media (prefers-reduced-motion: reduce) {
    .toast,
    .toast--leaving {
        animation: none;
    }
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba(6, 9, 14, 0.6);
}

.modal__card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 440px;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background-color: var(--bg-elevated);
    box-shadow: var(--shadow);
}

.modal__title {
    margin-bottom: 12px;
    font-size: 1.2rem;
}

.modal__text {
    margin-bottom: 14px;
    color: var(--text-muted);
}

.modal__hint {
    margin-bottom: 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.avatar-dialog__preview {
    display: flex;
    justify-content: center;
    margin: 10px 0 16px;
}

.avatar-dialog__actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.avatar-dialog__upload {
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.avatar-dialog__input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.modal__busy {
    margin-right: auto;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.modal__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 720px) {
    body {
        font-size: 14px;
    }

    .modal__actions {
        flex-wrap: wrap;
    }

    .toast-stack {
        right: 10px;
        bottom: 10px;
        left: 10px;
        max-width: none;
    }
}
