:root {
  --bg-base: #080a0f;
  --bg-surface: #10141e;
  --bg-elevated: #171d2b;
  --bg-glass: rgba(16, 20, 30, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-cyan: #22d3ee;
  --live: #ef4444;
  --good: #10b981;
  --warn: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --font-sans: 'Segoe UI Variable', 'Segoe UI', 'Noto Sans Thai', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Mono', 'Consolas', monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* Inputs & Buttons */
input, select {
  background: rgba(8, 10, 15, 0.85);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-main);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}
.btn:hover:not(:disabled) {
  background: #20283a;
  border-color: var(--border-strong);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  border-color: rgba(255, 255, 255, 0.15);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #7477f5, #5b52eb);
  transform: translateY(-1px);
}
.btn-secondary {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  border-color: rgba(255, 255, 255, 0.15);
  color: #fff;
}
.btn-secondary:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
}
.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}
.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.28);
  color: #fff;
}
.btn-lg {
  padding: 12px 18px;
  font-size: 14.5px;
  width: 100%;
}
.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
}
.btn-mini {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.btn-mini:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(23, 29, 43, 0.96);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent-cyan);
  color: var(--text-main);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  animation: toastIn 0.2s ease;
}
.toast.error { border-left-color: var(--live); }
.toast.success { border-left-color: var(--good); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ================= LANDING VIEW ================= */
.landing-view {
  min-height: 100vh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 18px;
}
.landing-bg-glow {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 18% 15%, rgba(99, 102, 241, 0.16), transparent 45%),
    radial-gradient(circle at 82% 80%, rgba(34, 211, 238, 0.12), transparent 45%);
  pointer-events: none;
}
.landing-container {
  width: 100%;
  max-width: 1040px;
  position: relative;
  z-index: 1;
}
.landing-header {
  text-align: center;
  margin-bottom: 28px;
}
.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
}
.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-cyan));
  box-shadow: 0 0 10px var(--accent-cyan);
}
.badge-tag {
  background: rgba(99, 102, 241, 0.22);
  color: #c7d2fe;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
}
.landing-header h1 {
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 10px;
}
.gradient-text {
  background: linear-gradient(90deg, #a5b4fc, #22d3ee);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.landing-sub {
  color: var(--text-muted);
  max-width: 640px;
  margin: 0 auto 16px;
}
.server-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 12.5px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 8px var(--good);
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}
.role-card {
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}
.role-card-icon {
  font-size: 28px;
  margin-bottom: 8px;
}
.role-card h2 {
  font-size: 19px;
  margin-bottom: 6px;
}
.role-card p {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 18px;
}
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.field-row {
  display: flex;
  gap: 10px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}
.field-sm {
  max-width: 150px;
}
.field label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.active-rooms-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
}
.active-rooms-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.active-rooms-head h3 {
  font-size: 14px;
  color: var(--text-muted);
}
.active-rooms-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.room-item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  gap: 10px;
}
.room-item-meta strong {
  display: block;
  font-size: 14px;
}
.room-item-meta small {
  color: var(--text-muted);
  font-size: 12px;
}
.empty-rooms {
  color: var(--text-dim);
  font-size: 13px;
}

/* ================= HOST STUDIO ================= */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.studio-topbar, .viewer-topbar {
  height: 54px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-left, .topbar-right, .topbar-center {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 13.5px;
}
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
}
.live-badge.standby {
  background: rgba(148, 163, 184, 0.14);
  color: var(--text-muted);
}
.live-badge.live {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.45);
}
.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.live-badge.live .pulse-dot {
  background: var(--live);
  box-shadow: 0 0 8px var(--live);
  animation: pulseLive 1.4s infinite;
}
@keyframes pulseLive {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.25); }
}
.room-pill {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pin-badge {
  color: #fbbf24;
  font-weight: 700;
}

.telemetry-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(8, 10, 15, 0.7);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 99px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-main);
}
.telemetry-pill.clickable {
  cursor: pointer;
}
.telemetry-pill.clickable:hover {
  border-color: var(--accent-cyan);
}
.telemetry-pill .sep {
  color: var(--text-dim);
}
.rtt-good { color: var(--good); }
.rtt-warn { color: var(--warn); }
.rtt-bad { color: var(--live); }

.studio-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.studio-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  gap: 10px;
  min-width: 0;
  overflow-y: auto;
}

/* Preview Stage */
.preview-stage {
  position: relative;
  flex: 1;
  min-height: 240px;
  background: #040508;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-stage.drag-over {
  border-color: var(--accent-cyan);
  box-shadow: inset 0 0 0 2px var(--accent-cyan);
}
#hostPreview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #040508;
}
.stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(16, 20, 30, 0.78), rgba(4, 5, 8, 0.94));
  z-index: 3;
  padding: 20px;
}
.standby-card {
  text-align: center;
  max-width: 420px;
}
.standby-icon {
  font-size: 36px;
  margin-bottom: 10px;
}
.standby-card h3 {
  font-size: 18px;
  margin-bottom: 6px;
}
.standby-card p {
  color: var(--text-muted);
  font-size: 13px;
}
.stage-top-badges {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 8px;
  z-index: 4;
}
.stage-tag {
  background: rgba(8, 10, 15, 0.75);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(8px);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
}
.stage-tag.accent {
  color: var(--accent-cyan);
  border-color: rgba(34, 211, 238, 0.35);
}

.privacy-banner {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.55);
  backdrop-filter: blur(12px);
  padding: 8px 16px;
  border-radius: 10px;
  color: #fde68a;
}
.privacy-banner strong { display: block; font-size: 13px; }
.privacy-banner small { font-size: 11.5px; opacity: 0.9; }

/* Stats HUD */
.stats-hud {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 304px;
  background: rgba(8, 10, 15, 0.88);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(14px);
  z-index: 8;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
}
.stats-hud-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}
.hud-chip {
  background: rgba(34, 211, 238, 0.15);
  color: var(--accent-cyan);
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 11px;
  font-family: var(--font-mono);
}
.stats-hud-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 10px;
  margin-bottom: 8px;
}
.stats-hud-grid label {
  display: block;
  font-size: 10.5px;
  color: var(--text-dim);
}
.stats-hud-grid strong {
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.stats-hud canvas {
  width: 100%;
  height: 64px;
  display: block;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}

/* Video File Bar */
.video-file-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.file-bar-top, .file-bar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.file-name {
  flex: 1;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mono-time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}
#fileSeekSlider {
  flex: 1;
  padding: 0;
  accent-color: var(--accent-cyan);
}
.monitor-control {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 120px;
}
.btn-icon-sm {
  background: transparent;
  color: var(--text-main);
  font-size: 15px;
}

/* Control Deck */
.control-deck {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.deck-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.deck-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.flex-1 { flex: 1; }
.deck-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
}
.source-strip, .preset-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.source-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.source-btn:hover {
  border-color: var(--border-strong);
  background: #1f273a;
}
.source-btn.active {
  background: rgba(99, 102, 241, 0.22);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.4);
}
.source-btn.shield-btn.active {
  background: rgba(245, 158, 11, 0.22);
  border-color: var(--warn);
  color: #fde68a;
}
.source-btn.mic-btn.mic-on {
  background: rgba(16, 185, 129, 0.18);
  border-color: var(--good);
  color: #6ee7b7;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 14px;
  min-width: 78px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-main);
  transition: all 0.15s;
}
.preset-btn strong { font-size: 13.5px; }
.preset-btn small { font-size: 10.5px; color: var(--text-muted); }
.preset-btn:hover { border-color: var(--border-strong); }
.preset-btn.active {
  background: rgba(34, 211, 238, 0.14);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.15);
}
.preset-btn.active strong { color: var(--accent-cyan); }

.btn-live-go {
  padding: 10px 22px;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  border: none;
  font-size: 14px;
  min-width: 150px;
}
.btn-live-go.is-live {
  background: #272f42;
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}
.go-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}
.btn-live-go.is-live .go-dot {
  background: var(--live);
  animation: pulseLive 1.4s infinite;
}

/* Advanced Drawer */
.advanced-drawer {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.adv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.adv-card {
  background: rgba(8, 10, 15, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.adv-card h4 { font-size: 13px; }
.audio-mode-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.mode-pill {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}
.mode-pill.active {
  background: rgba(99, 102, 241, 0.25);
  border-color: var(--accent);
  color: #fff;
}
.compact-field label { font-size: 11.5px; }
.compact-field input, .compact-field select { padding: 6px 10px; font-size: 12.5px; }
.input-with-btn {
  display: flex;
  gap: 6px;
}
.vu-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.vu-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.vu-head {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}
.vu-item input[type="range"] { padding: 0; accent-color: var(--accent); }
.vu-meter {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
}
.vu-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--good), var(--warn), var(--live));
  transition: width 0.06s linear;
}
.vu-fill.cyan {
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent));
}
.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.inline-check input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}
.adv-form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.adv-tip {
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.45;
}

/* Host Sidebar */
.studio-sidebar {
  width: 330px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: transparent;
  color: var(--text-muted);
  padding: 11px 6px;
  font-size: 12.5px;
  font-weight: 700;
  border-bottom: 2px solid transparent;
  position: relative;
}
.tab-btn.active {
  color: var(--text-main);
  border-bottom-color: var(--accent-cyan);
  background: rgba(255, 255, 255, 0.03);
}
.unread-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live);
  margin-left: 4px;
}
.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
  gap: 10px;
  overflow-y: auto;
}
.tab-panel.active {
  display: flex;
}
.room-settings-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.viewer-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}
.viewer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.viewer-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.viewer-item-info strong {
  display: block;
  font-size: 13px;
}
.viewer-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.net-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  margin-right: 4px;
}
.net-pill.lan { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.net-pill.ext { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 24px 10px;
  font-size: 13px;
}

/* Chat */
.chat-feed {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}
.chat-msg {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  word-break: break-word;
}
.chat-msg.host {
  background: rgba(99, 102, 241, 0.14);
  border-left: 3px solid var(--accent);
}
.chat-msg-head {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  margin-bottom: 2px;
}
.chat-sender { font-weight: 700; color: var(--accent-cyan); }
.chat-msg.host .chat-sender { color: #a5b4fc; }
.chat-time { color: var(--text-dim); font-size: 10.5px; }
.quick-reactions {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}
.react-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 15px;
  transition: transform 0.1s;
}
.react-btn:hover { transform: scale(1.15); background: rgba(255, 255, 255, 0.14); }
.chat-form {
  display: flex;
  gap: 6px;
}

/* Share & QR */
.qr-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}
.qr-card img {
  width: 170px;
  height: 170px;
  border-radius: 10px;
  background: #fff;
  padding: 6px;
}
.qr-caption {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}
.share-links {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.public-pill {
  margin-top: 8px;
  border-color: rgba(34, 211, 238, 0.45);
  background: rgba(16, 20, 30, 0.92);
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.14);
}
.public-share-box {
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.public-share-box label {
  color: var(--accent-cyan);
}
.qr-mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.qr-switch-btn {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-weight: 700;
}
.qr-switch-btn.active {
  background: rgba(34, 211, 238, 0.16);
  border-color: var(--accent-cyan);
  color: #fff;
}
.network-guide-box {
  background: rgba(8, 10, 15, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.network-guide-box h4 { color: var(--text-main); margin-bottom: 6px; }
.network-guide-box ul { padding-left: 16px; display: flex; flex-direction: column; gap: 5px; }

/* ================= VIEWER VIEW ================= */
.viewer-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  background: #040508;
  overflow: hidden;
}
.viewer-title {
  font-size: 14px;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.viewer-workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}
.viewer-stage {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}
#viewerVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
#viewerVideo.fill-mode {
  object-fit: cover;
}
.hud-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.exit-fs-pill {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 15;
  background: rgba(8, 10, 15, 0.8);
  color: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 99px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  backdrop-filter: blur(8px);
  transition: opacity 0.25s ease;
}
.viewer-stage.idle-controls .exit-fs-pill {
  opacity: 0;
  pointer-events: none;
}

/* Native & Pseudo Fullscreen */
#viewerStage:fullscreen,
#viewerStage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #000;
}
#viewerStage:fullscreen .player-controls,
#viewerStage:-webkit-full-screen .player-controls {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.viewer-shell.pseudo-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 9999;
  padding: 0;
  background: #000;
}
.viewer-shell.pseudo-fullscreen .viewer-topbar,
.viewer-shell.pseudo-fullscreen .viewer-chat-sidebar {
  display: none !important;
}
.viewer-shell.pseudo-fullscreen .viewer-workspace,
.viewer-shell.pseudo-fullscreen .viewer-stage {
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
  flex: 1;
}
.viewer-shell.pseudo-fullscreen .player-controls {
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.unmute-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 5, 8, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 12;
  backdrop-filter: blur(6px);
}
.unmute-overlay .btn {
  width: auto;
  padding: 14px 28px;
}

.player-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 28px 16px 12px;
  background: linear-gradient(to top, rgba(4, 5, 8, 0.92), transparent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: opacity 0.25s ease;
}
.viewer-stage.idle-controls .player-controls {
  opacity: 0;
  pointer-events: none;
}
.controls-left, .controls-center, .controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ctrl-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
}
.ctrl-btn:hover { background: rgba(255, 255, 255, 0.2); }
.ctrl-select {
  width: auto;
  max-width: 128px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.ctrl-select option {
  background: #10141e;
  color: #f1f5f9;
}
.volume-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
#viewerVolumeSlider {
  width: 96px;
  padding: 0;
  accent-color: var(--accent-cyan);
}
.vol-pct {
  font-family: var(--font-mono);
  font-size: 11.5px;
  min-width: 38px;
}
.vol-pct.boosted {
  color: var(--accent-cyan);
  font-weight: 700;
}
.viewer-react {
  padding: 4px 7px;
  font-size: 14px;
}

.viewer-chat-sidebar {
  width: 310px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  flex-shrink: 0;
}
.chat-sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 13.5px;
}

/* Theater Mode */
.viewer-shell.theater .viewer-topbar { display: none; }
.viewer-shell.theater .viewer-chat-sidebar { display: none; }

/* Floating Reactions */
.reaction-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9;
}
.floating-emoji {
  position: absolute;
  bottom: 50px;
  font-size: 28px;
  animation: floatUp 2.2s ease-out forwards;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
}
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(0) scale(0.7); }
  15% { opacity: 1; transform: translateY(-20px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-240px) scale(0.95); }
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.78);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}
.modal-sub { color: var(--text-muted); font-size: 13px; margin: 4px 0 14px; }
.modal-head-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}
.error-banner {
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

.mobile-only { display: none; }

.pwa-install-wrap {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}
.modal-picker {
  max-width: 760px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.picker-audio-box {
  padding: 8px 10px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 8px;
}
.picker-card-tag {
  font-size: 10.5px !important;
  color: var(--accent-cyan);
  font-weight: 700 !important;
}
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  overflow-y: auto;
  max-height: 58vh;
  padding-right: 4px;
}
.picker-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  color: var(--text-main);
  transition: border-color 0.15s, transform 0.12s;
}
.picker-card:hover {
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
}
.picker-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: #040508;
}
.picker-card span {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Responsive */
@media (max-width: 960px) {
  .role-grid, .adv-grid { grid-template-columns: 1fr; }
  .studio-workspace, .viewer-workspace { flex-direction: column; }
  .studio-sidebar {
    width: 100%;
    height: 290px;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .viewer-stage {
    flex: 0 0 auto;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 52dvh;
  }
  .viewer-workspace:has(.viewer-chat-sidebar.hidden) .viewer-stage,
  .viewer-shell.theater .viewer-stage {
    flex: 1;
    aspect-ratio: auto;
    max-height: none;
    height: 100%;
  }
  .viewer-chat-sidebar {
    width: 100%;
    flex: 1;
    height: auto;
    min-height: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .topbar-center { display: none; }
  .controls-center { display: none; }
  .mobile-only { display: inline-flex; }
}

@media (max-width: 768px) {
  input:not([type="range"]):not([type="checkbox"]),
  select {
    font-size: 16px;
  }
  .desktop-only {
    display: none !important;
  }
  .app-shell {
    height: 100vh;
    height: 100dvh;
  }
  .landing-view {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 18px 12px;
  }
  .viewer-topbar,
  .studio-topbar {
    height: auto;
    min-height: 46px;
    padding: 6px 10px;
    gap: 6px;
    flex-wrap: wrap;
  }
  .topbar-left,
  .topbar-right {
    gap: 6px;
    min-width: 0;
  }
  .viewer-title {
    max-width: 110px;
    font-size: 13px;
  }
  .telemetry-pill {
    padding: 4px 8px;
    font-size: 11px;
    gap: 5px;
  }
}

@media (max-width: 640px) {
  .role-card {
    padding: 16px;
  }
  .field-row {
    flex-direction: column;
  }
  .field-sm {
    max-width: none;
  }
  .server-pill {
    flex-wrap: wrap;
    justify-content: center;
    border-radius: 12px;
    padding: 8px 12px;
  }
  .hide-xs {
    display: none !important;
  }
  .btn-label {
    display: none;
  }
  .player-controls {
    padding: 20px 8px max(8px, env(safe-area-inset-bottom));
    gap: 6px;
  }
  .controls-left,
  .controls-right {
    gap: 5px;
  }
  .ctrl-btn {
    padding: 7px 9px;
    font-size: 13px;
    min-width: 34px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .ctrl-select {
    max-width: 92px;
    padding: 5px 6px;
    font-size: 11.5px;
    min-height: 34px;
  }
  #viewerVolumeSlider {
    width: 58px;
  }
  .vol-pct {
    font-size: 10.5px;
    min-width: 32px;
  }
  .stats-hud {
    width: calc(100% - 16px);
    max-width: 300px;
    top: 8px;
    right: 8px;
    padding: 9px;
  }
  .stats-hud canvas {
    height: 48px;
  }
  .vu-row,
  .adv-form-grid {
    grid-template-columns: 1fr;
  }
  .preset-btn {
    flex: 1 1 calc(33.33% - 6px);
    min-width: 0;
    padding: 6px 8px;
  }
  .unmute-overlay .btn {
    padding: 12px 18px;
    font-size: 13.5px;
    max-width: 90%;
  }
}

@media (max-width: 420px) {
  .viewer-title {
    max-width: 82px;
  }
  .volume-wrap {
    gap: 4px;
  }
  #viewerVolumeSlider {
    width: 52px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .viewer-topbar {
    min-height: 38px;
    padding: 4px 10px;
  }
  .viewer-workspace {
    flex-direction: row;
  }
  .viewer-stage {
    flex: 1;
    aspect-ratio: auto;
    max-height: none;
    height: 100%;
  }
  .viewer-chat-sidebar {
    width: 240px;
    height: 100%;
    flex: 0 0 240px;
    border-top: none;
    border-left: 1px solid var(--border);
  }
}
