/* SPDX-License-Identifier: AGPL-3.0-only */
/* ---------- Lobby ---------- */

.lobby {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 16px 24px;
    gap: 16px;
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, 0.25), transparent),
        radial-gradient(900px 500px at 110% 110%, rgba(34, 211, 238, 0.15), transparent), var(--bg);
}

/* Top bar with page-wide preferences; the card is centred in the space below it. */
.lobby-header {
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.lobby-card {
    width: 100%;
    max-width: 440px;
    margin-block: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 20px 60px var(--shadow-soft);
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
}

.brand h1 {
    margin: 0;
    font-size: 22px;
}

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

.brand p {
    margin: 2px 0 0;
    font-size: 14px;
}

.preview {
    position: relative;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
}

.preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview video:not(.back-camera) {
    transform: scaleX(-1);
}

/* The screen picked to share on joining takes the preview; the camera moves to a small window in the corner. */
.preview video.preview-screen {
    position: absolute;
    inset: 0;
    object-fit: contain;
    transform: none;
    background: #000;
}

.preview.sharing #preview-video {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1;
    width: 28%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* With the camera off there's nothing to show in the corner. */
.preview.sharing:has(> .preview-placeholder:not([hidden])) #preview-video {
    display: none;
}

.preview-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    background: var(--surface-2);
}

.preview-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 12px;
    display: flex;
    justify-content: center;
    gap: 12px;
}

.round-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 0;
    display: grid;
    place-items: center;
    /* Dark scrim + light ring so the buttons stay visible over both bright and dark camera feeds. */
    background: rgba(0, 0, 0, 0.45);
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.25),
        0 2px 8px rgba(0, 0, 0, 0.35);
    color: #fff;
    backdrop-filter: blur(8px);
    transition: background 0.15s;
}

.round-btn svg {
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}

.round-btn:not(.on):not(.neutral) {
    background: var(--danger-fill);
}

.round-btn.on:hover:not(:disabled),
.round-btn.neutral:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.6);
}

.round-btn.neutral.active,
.round-btn.neutral.active:hover {
    background: var(--primary);
    color: var(--on-primary);
}

.round-btn:disabled {
    opacity: 0.5;
}

/* The lobby's microphone check: the mic's capsule fills up green with the level the microphone hears (--mic-level,
   0 to 1). Clipping from the top keeps the capsule's rounded bottom at every level. */
.mic-meter .mic-level-fill {
    fill: var(--success);
    clip-path: inset(calc((1 - var(--mic-level, 0)) * 100%) 0 0 0);
    transition: clip-path 0.1s linear;
}

.round-btn .icon-off,
.round-btn.on .icon-on,
.ctrl-btn .icon-off,
.ctrl-btn.on .icon-on {
    display: block;
}

.round-btn .icon-on,
.round-btn.on .icon-off,
.ctrl-btn .icon-on,
.ctrl-btn.on .icon-off {
    display: none;
}

.join-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.join-form label > span {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}

.optional {
    font-style: normal;
    opacity: 0.75;
}

.lobby-security {
    border: 1px solid var(--border);
    border-radius: 10px;
}

.lobby-security summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    list-style: none;
}

.lobby-security summary::-webkit-details-marker {
    display: none;
}

.lobby-security summary:hover {
    background: var(--surface-2);
}

.lobby-security summary svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    fill: currentColor;
}

.lobby-security-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.lobby-security-text small {
    font-size: 12px;
}

/* Open, the fields say it themselves. */
.lobby-security[open] .lobby-security-text small {
    display: none;
}

.lobby-security-chevron {
    color: var(--muted);
    transition: transform 0.15s;
}

.lobby-security[open] .lobby-security-chevron {
    transform: rotate(180deg);
}

.lobby-security .icon-locked,
.lobby-security:has(#password-input:not(:placeholder-shown), #e2ee-toggle:checked) .icon-unlocked {
    display: none;
}

.lobby-security:has(#password-input:not(:placeholder-shown), #e2ee-toggle:checked) .icon-locked {
    display: block;
    color: var(--success);
}

.lobby-security-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 12px 12px;
}

.input-row {
    display: flex;
    gap: 8px;
}

.input-row .ghost-btn {
    display: grid;
    place-items: center;
}

.input-row .ghost-btn svg {
    width: 20px;
    height: 20px;
}

.error {
    color: var(--danger-text);
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    padding: 10px 12px;
    border-radius: 10px;
    margin: 0;
    font-size: 14px;
}

.lobby-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px 16px;
    font-size: 13px;
}

.language-picker {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
}

.language-picker svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.language-picker select {
    width: auto;
    padding-block: 6px;
    padding-inline: 10px 30px;
    border-radius: 8px;
    font-size: 14px;
    background-color: transparent;
}

.join-wait {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    font-size: 14px;
}

.spinner {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

.host-auth {
    margin: 0;
    font-size: 13px;
    text-align: center;
}

.lobby-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 8px;
}

.lobby-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    transition:
        background 0.15s,
        color 0.15s;
}

.lobby-action:hover {
    background: var(--surface-2);
    color: var(--text);
}

.lobby-action svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: currentColor;
}

.link-btn {
    padding: 0;
    border: 0;
    background: none;
    color: var(--link);
    font-size: inherit;
    text-decoration: underline;
}

/* ---------- Network check dialog ---------- */

.netcheck-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.netcheck-steps li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.netcheck-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    font-size: 14px;
}

.netcheck-text strong {
    font-weight: 500;
}

.netcheck-detail {
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.netcheck-detail:empty {
    display: none;
}

.netcheck-icon {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    border: 2px solid var(--border);
    border-radius: 50%;
}

[data-status='running'] > .netcheck-icon {
    border-top-color: var(--primary);
    animation: spin 0.9s linear infinite;
}

[data-status='ok'] > .netcheck-icon {
    border-color: var(--success);
    color: var(--success);
}

[data-status='ok'] > .netcheck-icon::before,
[data-status='warn'] > .netcheck-icon::before,
[data-status='failed'] > .netcheck-icon::before,
[data-status='skipped'] > .netcheck-icon::before {
    content: '';
    width: 12px;
    height: 12px;
    background: currentColor;
    mask: var(--status-icon) center / contain no-repeat;
}

[data-status='ok'] > .netcheck-icon::before {
    --status-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17Z'/%3E%3C/svg%3E");
}

[data-status='warn'] > .netcheck-icon {
    border-color: var(--warning-text);
    color: var(--warning-text);
}

[data-status='warn'] > .netcheck-icon::before {
    --status-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 3h4v12h-4V3Zm0 15h4v3h-4v-3Z'/%3E%3C/svg%3E");
}

[data-status='failed'] > .netcheck-icon {
    border-color: var(--danger);
    color: var(--danger);
}

[data-status='failed'] > .netcheck-icon::before {
    --status-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z'/%3E%3C/svg%3E");
}

[data-status='skipped'] > .netcheck-icon {
    color: var(--muted);
}

[data-status='skipped'] > .netcheck-icon::before {
    --status-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 11h14v2H5v-2Z'/%3E%3C/svg%3E");
}

[data-status='idle'],
[data-status='skipped'] {
    opacity: 0.7;
}

.netcheck-result {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--success);
    border-radius: 10px;
    background: var(--surface-2);
    font-size: 14px;
}

.netcheck-result[hidden] {
    display: none;
}

.netcheck-result[data-verdict='fair'] {
    border-inline-start-color: var(--warning-text);
}

.netcheck-result[data-verdict='poor'],
.netcheck-result[data-verdict='failed'],
.netcheck-result[data-verdict='error'] {
    border-inline-start-color: var(--danger);
}

.netcheck-hints {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding-inline-start: 18px;
    color: var(--muted);
}

.netcheck-hints:empty {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    [data-status='running'] > .netcheck-icon {
        animation: none;
    }

    .mic-meter .mic-level-fill,
    .lobby-security-chevron {
        transition: none;
    }
}

@media (min-width: 860px) {
    .lobby-card {
        max-width: 900px;
        display: grid;
        grid-template-columns: 1.4fr 1fr;
        grid-template-areas:
            'brand brand'
            'preview form';
        grid-template-rows: auto auto;
        align-items: center;
        column-gap: 28px;
        padding: 28px;
    }

    .brand {
        grid-area: brand;
        margin-bottom: 24px;
    }

    .preview {
        grid-area: preview;
        margin-bottom: 0;
        align-self: center;
    }

    .join-form {
        grid-area: form;
        justify-content: center;
    }
}
