:root {
    /* Colors */
    --bg: #111;
    --bg-input: #1a1a1a;
    --bg-raised: #222;
    --bg-hover: #252525;
    --border: #333;
    --border-light: #555;
    --text: #e0e0e0;
    --text-bright: #fff;
    --text-label: #aaa;
    --text-muted: #888;
    --text-dim: #666;
    --accent: #3498db;
    --accent-light: #7eb8da;
    --success: #2ecc71;
    --danger: #c0392b;
    --error: #e74c3c;
    --warning: #f1c40f;

    /* Radii */
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;

    /* Border */
    --border-w: 2px;

    /* Font sizes — consolidated scale */
    --font-xs: 0.7rem;
    --font-sm: 0.85rem;
    --font-base: 1rem;
    --font-lg: 1.1rem;
    --font-xl: 1.2rem;
    --font-2xl: 1.5rem;
    --font-3xl: 2rem;

    /* Spacing */
    --pad-input: 0.75rem;
    --pad-section: 1rem;
    --gap: 0.5rem;
}

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

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 2rem;
}

body.vr-active {
    padding: 0;
    overflow: hidden;
}

.hidden { display: none !important; }

/* --- Reusable: inputs & controls --- */
.input {
    font-size: var(--font-base);
    padding: var(--pad-input);
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-bright);
    font-family: inherit;
}

.input-lg {
    font-size: var(--font-lg);
    padding: 0.75rem;
}

select.input {
    cursor: pointer;
}

/* --- Reusable: buttons --- */
.btn {
    border: var(--border-w) solid var(--border-light);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-bright);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--font-base);
    padding: var(--pad-input);
}

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

.btn-primary {
    display: block;
    width: 100%;
    padding: var(--pad-input);
    font-size: var(--font-lg);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-weight: 600;
    background: var(--accent);
    color: var(--text-bright);
    margin-top: var(--pad-section);
}

.btn-primary:disabled {
    background: var(--border);
    color: var(--text-dim);
    cursor: not-allowed;
}

.btn-toggle {
    padding: var(--pad-input);
    font-size: var(--font-base);
    border: var(--border-w) solid var(--border-light);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-bright);
    cursor: pointer;
}

.btn-toggle.active {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--text-bright);
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: var(--font-sm);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: transparent;
    color: #ccc;
    cursor: pointer;
}

/* --- Reusable: status --- */
.status {
    margin-top: var(--gap);
    font-size: var(--font-sm);
}

.status.waiting { color: var(--warning); }
.status.connected { color: var(--success); }
.status.error { color: var(--error); }

/* --- Join Screen --- */
#join-screen {
    text-align: center;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

#join-screen h1 {
    font-size: var(--font-3xl);
    margin-bottom: var(--gap);
}

#join-screen p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.form-group {
    text-align: left;
    margin-bottom: var(--pad-section);
}

.form-group label {
    display: block;
    font-size: var(--font-sm);
    color: var(--text-label);
    margin-bottom: 0.25rem;
}

.form-group input, .form-group select {
    width: 100%;
    font-size: var(--font-lg);
    padding: var(--pad-input);
    border: var(--border-w) solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-bright);
    font-family: inherit;
}

.form-group select {
    cursor: pointer;
}

/* Combo input (input + button side by side) */
.combo-input {
    display: flex;
}

.combo-input input {
    border-radius: var(--radius) 0 0 var(--radius);
    border-right: none;
    flex: 1;
}

.combo-input button {
    border: var(--border-w) solid var(--border);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--bg-raised);
    color: var(--text-muted);
    padding: 0 0.75rem;
    font-size: var(--font-sm);
    cursor: pointer;
}

/* Room history dropdown */
#room-history {
    background: var(--bg-input);
    border: var(--border-w) solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 150px;
    overflow-y: auto;
}

.room-history-item {
    padding: var(--pad-input);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.room-history-item:hover {
    background: var(--bg-hover);
}

.room-history-item .room-name { color: var(--text-bright); }
.room-history-item .room-date { color: var(--text-dim); font-size: var(--font-xs); }

/* --- Lobby --- */
#lobby {
    width: 100%;
    max-width: 500px;
    padding: var(--pad-section);
}

#lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--pad-section);
    padding-bottom: var(--gap);
    border-bottom: 1px solid var(--border);
}

.room-label {
    font-weight: 700;
    font-size: var(--font-lg);
    font-family: monospace;
}

.name-label {
    color: var(--text-muted);
    margin-left: 0.75rem;
    font-size: var(--font-sm);
}

/* Section headers */
#lobby h3 {
    font-size: 1.05rem;
    color: var(--accent-light);
    margin-top: 1.7rem;
    margin-bottom: var(--gap);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3rem;
}

#lobby h4 {
    font-size: var(--font-sm);
    color: var(--text-muted);
    margin-top: var(--gap);
    margin-bottom: 0.3rem;
}

/* Camera controls */
#camera-controls {
    display: flex;
    gap: var(--gap);
    align-items: center;
    margin-bottom: var(--gap);
}

#camera-select {
    flex: 1;
    font-size: var(--font-base);
    padding: var(--pad-input);
    border: var(--border-w) solid var(--border-light);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-bright);
    cursor: pointer;
    font-family: inherit;
    line-height: 1.2;
}

#camera-preview, #stream-preview {
    width: 100%;
    max-height: 200px;
    border-radius: var(--radius);
    background: #000;
    object-fit: cover;
    margin-bottom: var(--pad-section);
}

/* External stream controls */
#stream-controls {
    margin-bottom: var(--gap);
}

#stream-controls .combo-input input {
    font-size: var(--font-base);
    padding: var(--pad-input);
}

#stream-controls .combo-input button {
    padding: 0 var(--pad-section);
    font-size: var(--font-sm);
    white-space: nowrap;
}

#btn-connect-stream.active {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--text-bright);
}

#stream-status {
    font-size: var(--font-sm);
    margin-top: 0.25rem;
}

/* QR code */
#lobby-qr {
    text-align: center;
    margin-bottom: var(--pad-section);
}

.qr-hint {
    font-size: var(--font-sm);
    color: var(--text-dim);
    margin-bottom: var(--gap);
    text-align: center;
}

/* Peer list */
#peer-list {
    margin-bottom: var(--pad-section);
}

.peer-item {
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: 0.4rem 0;
}

.peer-name { flex: 1; }
.peer-status {
    font-size: var(--font-xs);
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-sm);
}

.peer-status.sharing { background: var(--success); color: var(--bg); }
.peer-status.not-sharing { background: var(--border); color: var(--text-muted); }

.peer-thumb {
    width: 48px;
    height: 36px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: #000;
}

/* View setup */
#view-setup {
    margin-bottom: var(--pad-section);
}

.corner-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--radius-sm);
    width: 80px;
    margin-top: 0.25rem;
}

.corner-btn {
    padding: 0.3rem;
    font-size: var(--font-xs);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.corner-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text-bright);
}

/* --- VR View --- */
#vr-view {
    position: fixed;
    inset: 0;
    background: #000;
    overflow: hidden;
}

#vr-main {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
}

#vr-main video {
    width: 50%;
    height: 100%;
    object-fit: cover;
}

/* PIP */
.vr-pip {
    position: absolute;
    width: 12.5%;
    z-index: 5;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

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

/* VR overlay (stream lost message) */
#vr-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.85);
    z-index: 15;
}

#vr-overlay-msg {
    font-size: var(--font-2xl);
    color: var(--error);
    text-align: center;
    padding: 2rem;
}

/* VR controls — fixed position, outside vr-view to stay above fullscreen */
#vr-controls {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2147483647;
}

/* Exit zone */
#vr-exit-zone {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-bright);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: var(--font-xl);
    cursor: pointer;
}

/* Scale controls */
#vr-scale-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 16px;
    border-radius: var(--radius-lg);
}

#vr-scale-slider {
    width: 200px;
    height: 30px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* Debug panel */
#debug-toggle {
    position: fixed;
    top: 4px;
    right: 4px;
    z-index: 9999;
    background: rgba(255, 0, 0, 0.5);
    color: var(--text-bright);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: var(--font-xs);
    cursor: pointer;
}

#debug-panel {
    position: fixed;
    top: 28px;
    right: 4px;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.9);
    color: #0f0;
    font-size: 0.6rem;
    max-width: 90vw;
    max-height: 60vh;
    overflow: auto;
    padding: 8px;
    border-radius: var(--radius);
}

#debug-panel button {
    font-size: var(--font-xs);
    margin-right: 4px;
    margin-bottom: 4px;
}

#debug-log {
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}
