:root {
    --bg: #141618;
    --surface: #1c1f24;
    --surface-2: #262a31;
    --border: rgba(255, 255, 255, 0.1);
    --text: #eceff4;
    --text-dim: #9aa3b2;
    --accent: #c9a227;
    --accent-hover: #dbb42e;
    --accent-soft: rgba(201, 162, 39, 0.18);
    --danger: #c53030;
    --success: #3d8f5f;
    --font: "DM Sans", system-ui, sans-serif;
    --mono: "JetBrains Mono", monospace;
    --radius: 10px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
}

.view { display: none; flex-direction: column; flex: 1; min-height: 0; }
.view.active { display: flex; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: clamp(0.45rem, 1.2vmin, 0.65rem) clamp(0.75rem, 2vw, 1.25rem);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; flex-wrap: wrap; }
.topbar-controls { display: flex; align-items: center; gap: 0.45rem; }

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    font-size: clamp(0.95rem, 1.8vw, 1.05rem);
    white-space: nowrap;
}
.brand.static { cursor: default; }
.brand:hover:not(.static) { color: var(--accent); }
.brand svg { color: var(--accent); flex-shrink: 0; }

.badge-live {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    padding: 0.2rem 0.45rem;
    border-radius: 4px;
    background: var(--danger);
    color: #fff;
}
.badge-guest {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    padding: 0.2rem 0.45rem;
    border-radius: 4px;
    background: var(--accent);
    color: #1a1a1a;
}
.ntp-clock {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--text-dim);
}
.ntp-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
}
.status-chip {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-dim);
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    white-space: nowrap;
}
.status-chip.live {
    color: #fca5a5;
    border-color: var(--danger);
    background: rgba(197, 48, 48, 0.15);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    font-family: var(--font);
    font-size: clamp(0.78rem, 1.4vw, 0.85rem);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, transform 0.08s;
    white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; width: 100%; }
.btn-primary { background: var(--accent); color: #1a1a1a; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #323842; }
.btn-danger { background: var(--danger); color: #fff; font-weight: 700; }
.btn-danger:hover { background: #a82828; }
.btn-ghost {
    background: var(--surface-2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 0.45rem 0.65rem;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.22); }
.btn-toggle.active,
.btn-ghost[aria-pressed="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}
.btn-toggle[aria-pressed="false"].is-off {
    border-color: var(--danger);
    color: #fca5a5;
}
.btn-icon {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
}

.regie-body {
    flex: 1;
    display: flex;
    min-height: 0;
}
.stage {
    flex: 1;
    min-width: 0;
    padding: clamp(0.65rem, 1.5vmin, 1rem);
    display: flex;
}
.side-panel {
    width: clamp(220px, 26vw, 300px);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.85rem;
    background: var(--surface);
    border-left: 1px solid var(--border);
    overflow-y: auto;
}
.panel-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
}

.video-frame {
    position: relative;
    flex: 1;
    background: #000;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    min-height: 0;
}
.video-frame video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    display: block;
}
.video-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.5rem;
    text-align: center;
    background: radial-gradient(ellipse at center, #1a1d22 0%, #0a0b0d 70%);
    color: var(--text-dim);
}
.video-placeholder p:first-child {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}
.video-frame.has-stream .video-placeholder { display: none; }
.video-meta {
    position: absolute;
    left: 0.65rem;
    bottom: 0.65rem;
    right: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    pointer-events: none;
}
.video-meta span {
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
}
.vu-wrap {
    width: 72px;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.15);
    overflow: hidden;
}
.vu-bar {
    display: block;
    height: 100%;
    width: 0%;
    background: var(--success);
    transition: width 0.06s linear;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field span { font-size: 0.72rem; color: var(--text-dim); font-weight: 500; }
.input, .select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    outline: none;
    width: 100%;
}
.input:focus, .select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}
.check-field {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    cursor: pointer;
}
.check-field input { accent-color: var(--accent); }
.hint { font-size: 0.82rem; color: var(--text-dim); }
.hint.err { color: #fca5a5; }
.mono-hint { font-family: var(--mono); font-size: 0.72rem; }
.tb-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.return-preview {
    position: relative;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #000;
}
.return-preview video { width: 100%; height: 100%; object-fit: cover; }
.pip-label {
    position: absolute;
    left: 0.4rem;
    bottom: 0.4rem;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.7);
}

/* Guest */
.guest-lobby {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background:
        radial-gradient(ellipse 70% 50% at 50% 0%, rgba(201, 162, 39, 0.12), transparent 55%),
        var(--bg);
}
.lobby-card {
    width: min(100%, 400px);
    padding: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.lobby-card h1 {
    font-size: 1.35rem;
    font-weight: 800;
}

.guest-stage {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    gap: 0.65rem;
    padding: 0.65rem;
    min-height: 0;
}
.guest-stage.has-return {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr auto;
}
.guest-stage.has-return .guest-dock { grid-column: 1 / -1; }
.self-frame video.mirror { transform: scaleX(-1); }
.guest-dock {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
}
.talkback-chip {
    position: fixed;
    top: max(3.5rem, calc(env(safe-area-inset-top, 0px) + 3rem));
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    color: var(--accent);
}
.talkback-chip[hidden] { display: none !important; }
#returnAudio { display: none; }

.edit-modal {
    border: none;
    border-radius: 12px;
    padding: 0;
    margin: auto;
    position: fixed;
    inset: 0;
    width: calc(100% - 1.5rem);
    max-width: 380px;
    height: fit-content;
    background: #181b20;
    color: var(--text);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
    overflow: hidden;
}
.edit-modal::backdrop { background: rgba(0, 0, 0, 0.75); }
.edit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.edit-header h2 { font-size: 1rem; font-weight: 700; }
.edit-body { padding: 0.85rem 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.edit-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.share-body { text-align: center; }
.qr-wrap {
    display: flex;
    justify-content: center;
    min-height: 150px;
}
.qr-wrap img {
    border: 2px solid var(--border);
    border-radius: 8px;
    background: #fff;
}
.copy-feedback { color: var(--success); font-size: 0.85rem; font-weight: 600; }

.toast-host {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    pointer-events: none;
}
.toast {
    padding: 0.65rem 0.95rem;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.toast.ok { border-color: var(--success); }
.toast.err { border-color: var(--danger); color: #fca5a5; }

@media (max-width: 720px) {
    .regie-body { flex-direction: column; }
    .side-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 42%;
    }
    .guest-stage.has-return {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 0.7fr auto;
    }
}
