:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1b1f24;
    --muted: #5d6673;
    --border: #d5d9df;
    --accent: #3b5bdb;
    --ok: #1f9d55;
    --warn: #c77700;
    --danger: #c92a2a;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171b;
        --surface: #1d2127;
        --text: #e8eaed;
        --muted: #9aa3ae;
        --border: #323841;
        --accent: #748ffc;
        --ok: #51cf66;
        --warn: #fcc419;
        --danger: #ff8787;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1, h2 {
    margin: 0 0 8px;
    font-weight: 600;
}

h1 {
    font-size: 20px;
}

h2 {
    font-size: 14px;
}

button, input, select {
    font: inherit;
    color: inherit;
}

button {
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}

button:hover {
    border-color: var(--accent);
}

button[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

button.danger {
    color: var(--danger);
}

input[type="text"], input[type="password"], select {
    padding: 6px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.card {
    max-width: 380px;
    margin: 12vh auto 0;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.card label {
    display: block;
    margin: 12px 0;
}

.card input[type="password"], .card input[type="text"] {
    display: block;
    width: 100%;
    margin-top: 4px;
}

.card button {
    width: 100%;
    margin-top: 8px;
}

.inline {
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.small {
    font-size: 12px;
}

.error {
    min-height: 1.2em;
    margin: 8px 0 0;
    color: var(--danger);
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.grow {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pill {
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
}

.pill::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--muted);
}

.pill.ok::before {
    background: var(--ok);
}

.pill.warn::before {
    background: var(--warn);
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 16px;
    padding: 16px;
}

@media (max-width: 960px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }
}

#stage {
    position: relative;
    background: #000;
    border-radius: 8px;
    outline: none;
    aspect-ratio: 16 / 9;
    overflow: hidden;
}

#stage:focus-visible {
    box-shadow: 0 0 0 2px var(--accent);
}

#stage.controlling {
    box-shadow: 0 0 0 2px var(--danger);
    cursor: crosshair;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

#overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    text-align: center;
}

#overlay[hidden] {
    display: none;
}

.stage-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel section {
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

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

.row select, .row input[type="text"], .row input[type="range"] {
    flex: 1;
    min-width: 0;
}

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

#mic-meter {
    display: block;
    width: 100%;
    height: 8px;
    margin-bottom: 8px;
    background: var(--border);
    border-radius: 4px;
}

#cam-preview {
    display: block;
    width: 100%;
    background: #000;
    border-radius: 6px;
}

#cam-preview:not([srcObject]) {
    min-height: 0;
}
