/* ==========================================================================
   Cog — Monolith Carbon & Studio Paper Design System
   Precision acoustic/video instrument: simple at first glance, engineered deep.
   ========================================================================== */

@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-wght.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root,
body.theme-dark {
  --bg-canvas: #090a0d;
  --bg-nav: rgba(9, 10, 13, 0.78);
  --bg-surface: #111318;
  --bg-surface-glass: rgba(17, 19, 24, 0.86);
  --bg-elevated: #181b22;
  --bg-elevated-hover: #20242d;
  --bg-input: #0e1015;
  --bg-rail: #0d0f13;
  --bg-dock: rgba(15, 17, 22, 0.86);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --inner-rim: inset 0 1px 0 rgba(255, 255, 255, 0.06);

  /* High-Contrast Monochrome Action + Signal Instrumentation Accents */
  --cta-bg: #f4f3ef;
  --cta-bg-hover: #ffffff;
  --cta-fg: #090a0d;

  --color-primary: #e5e4df;
  --color-primary-light: #f4f3ef;
  --color-primary-soft: rgba(244, 243, 239, 0.11);

  --color-emerald: #34d399;
  --color-emerald-soft: rgba(52, 211, 153, 0.13);
  --color-emerald-glow: rgba(52, 211, 153, 0.42);

  --color-amber: #f59e0b;
  --color-amber-soft: rgba(245, 158, 11, 0.14);

  --color-cyan: #38bdf8;
  --color-cyan-soft: rgba(56, 189, 248, 0.14);

  --color-rose: #ef4444;
  --color-rose-hover: #dc2626;
  --color-rose-soft: rgba(239, 68, 68, 0.14);

  /* Typography */
  --text-main: #f4f3ef;
  --text-secondary: #b8bcc7;
  --text-muted: #7e8494;
  --text-subtle: #565c6b;

  --shadow-viewfinder: 0 32px 80px -24px rgba(0, 0, 0, 0.85), 0 0 0 1px var(--border-subtle);
  --shadow-dock: 0 22px 48px -12px rgba(0, 0, 0, 0.8), 0 0 0 1px var(--border-strong), var(--inner-rim);
  --backdrop-modal: rgba(5, 6, 8, 0.78);
}

body.theme-light {
  --bg-canvas: #f2f1ed;
  --bg-nav: rgba(242, 241, 237, 0.84);
  --bg-surface: #ffffff;
  --bg-surface-glass: rgba(255, 255, 255, 0.9);
  --bg-elevated: #eceae4;
  --bg-elevated-hover: #e2dfd7;
  --bg-input: #ffffff;
  --bg-rail: #e7e5df;
  --bg-dock: rgba(255, 255, 255, 0.9);

  --border-subtle: rgba(17, 19, 24, 0.09);
  --border-strong: rgba(17, 19, 24, 0.18);
  --inner-rim: inset 0 1px 0 rgba(255, 255, 255, 0.85);

  --cta-bg: #121419;
  --cta-bg-hover: #242832;
  --cta-fg: #f7f6f2;

  --color-primary: #121419;
  --color-primary-light: #121419;
  --color-primary-soft: rgba(18, 20, 25, 0.08);

  --color-emerald: #059669;
  --color-emerald-soft: rgba(5, 150, 105, 0.12);
  --color-emerald-glow: rgba(5, 150, 105, 0.3);

  --color-amber: #d97706;
  --color-amber-soft: rgba(217, 119, 6, 0.12);

  --color-cyan: #0284c7;
  --color-cyan-soft: rgba(2, 132, 199, 0.12);

  --color-rose: #dc2626;
  --color-rose-hover: #b91c1c;
  --color-rose-soft: rgba(220, 38, 38, 0.11);

  --text-main: #121419;
  --text-secondary: #434856;
  --text-muted: #6c7282;
  --text-subtle: #8f95a3;

  --shadow-viewfinder: 0 28px 70px -24px rgba(17, 19, 24, 0.22), 0 0 0 1px var(--border-subtle);
  --shadow-dock: 0 18px 40px -12px rgba(17, 19, 24, 0.18), 0 0 0 1px var(--border-strong);
  --backdrop-modal: rgba(18, 20, 25, 0.42);
}

:root {
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 13px;
  --radius-lg: 18px;
  --radius-xl: 22px;
  --radius-full: 9999px;

  --transition-fast: 0.16s cubic-bezier(0.22, 1, 0.36, 1);
  --transition-normal: 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

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

html {
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(128, 134, 150, 0.28) transparent;
}

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(128, 134, 150, 0.28) transparent;
}

body {
  font-family: 'Vazirmatn', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
  background-color: var(--bg-canvas);
  color: var(--text-main);
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  line-height: 1.55;
  transition: background-color 0.24s ease, color 0.24s ease;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

.mono-num {
  font-family: 'JetBrains Mono', 'Vazirmatn', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128, 134, 150, 0.25); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: rgba(128, 134, 150, 0.42); }

/* ==========================================================================
   Architectural Backdrop (Zero Neon Glow Blobs)
   ========================================================================== */
.studio-backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.studio-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.025), transparent 55%);
}

body.theme-light .studio-vignette {
  background: radial-gradient(circle at 30% 25%, rgba(0, 0, 0, 0.02), transparent 55%);
}

.studio-hairlines {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, var(--border-subtle) 1px, transparent 1px),
    linear-gradient(to bottom, var(--border-subtle) 1px, transparent 1px);
  background-size: 96px 96px;
  opacity: 0.28;
  mask-image: radial-gradient(ellipse at 50% 45%, black 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 45%, black 20%, transparent 78%);
}

/* ==========================================================================
   Minimalist Studio Header (56px)
   ========================================================================== */
.top-nav {
  position: relative;
  height: 56px;
  flex-shrink: 0;
  background: var(--bg-nav);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 22px;
  padding-top: max(0px, env(safe-area-inset-top));
  padding-inline-start: max(18px, env(safe-area-inset-right));
  padding-inline-end: max(18px, env(safe-area-inset-left));
  z-index: 50;
  user-select: none;
  max-width: 100%;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-width: 0;
}

.logo-mark {
  width: 30px;
  height: 30px;
  background: var(--cta-bg);
  color: var(--cta-fg);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand-name {
  font-weight: 800;
  font-size: 1.08rem;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-family: 'JetBrains Mono', 'Vazirmatn', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.nav-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.active-room-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  max-width: 100%;
  min-width: 0;
}

.active-room-pill,
.nav-telemetry-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 0.76rem;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  transition: var(--transition-fast);
}

.nav-telemetry-pill {
  cursor: pointer;
}

.nav-telemetry-pill:hover {
  border-color: var(--border-strong);
  color: var(--text-main);
  background: var(--bg-elevated);
}

.pill-divider {
  width: 1px;
  height: 12px;
  background: var(--border-subtle);
}

.telemetry-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.telemetry-dot.healthy { background: var(--color-emerald); box-shadow: 0 0 8px var(--color-emerald-glow); }
.telemetry-dot.warn { background: var(--color-amber); }
.telemetry-dot.poor { background: var(--color-rose); }

.pill-mode-tag {
  font-weight: 700;
  color: var(--text-main);
  font-size: 0.74rem;
}

.pill-mode-tag.gaming {
  color: var(--color-amber);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-emerald);
  animation: pulse-live 2.2s infinite;
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.room-slug {
  font-weight: 700;
  color: var(--text-main);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-meta-chip {
  color: var(--text-muted);
}

.room-flag-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-size: 0.67rem;
  font-weight: 700;
  line-height: 1.2;
}

.room-flag-badge.owner {
  background: var(--color-amber-soft);
  color: var(--color-amber);
  border: 1px solid rgba(245, 158, 11, 0.32);
}

.room-flag-badge.lock {
  background: var(--color-rose-soft);
  color: var(--color-rose);
  border: 1px solid rgba(239, 68, 68, 0.32);
}

.peer-owner-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: rgba(245, 158, 11, 0.22);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fbbf24;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.3;
}

.btn-copy-invite {
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 11px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-copy-invite:hover {
  border-color: var(--border-strong);
  color: var(--text-main);
  background: var(--bg-elevated);
}

.btn-copy-invite.copied {
  border-color: rgba(52, 211, 153, 0.45);
  background: var(--color-emerald-soft);
  color: var(--color-emerald);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.connection-pill {
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
}

.status-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-amber);
}

.connection-pill.status-ready .status-indicator {
  background: var(--color-emerald);
  box-shadow: 0 0 8px var(--color-emerald-glow);
}

.connection-pill.status-ready {
  color: var(--text-secondary);
}

.connection-pill.status-error .status-indicator {
  background: var(--color-rose);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.icon-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-main);
}

.icon-btn.mini {
  width: 30px;
  height: 30px;
}

body.theme-light #btn-theme-toggle .icon-sun { display: none; }
body.theme-light #btn-theme-toggle .icon-moon { display: block !important; }

/* ==========================================================================
   Main Container & View Transitions
   ========================================================================== */
.main-container {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.view-panel {
  display: none;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.view-panel.active-view {
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Lobby — Minimalist Console + Cinema Viewfinder Architecture
   ========================================================================== */
#view-lobby {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 28px 32px;
}

.lobby-shell {
  width: 100%;
  max-width: 1180px;
  margin: auto;
}

.lobby-workspace {
  display: grid;
  grid-template-columns: minmax(340px, 410px) minmax(0, 1fr);
  gap: 44px;
  align-items: center;
}

/* Right Console — Unboxed Calm Controls */
.lobby-console {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  max-width: 100%;
}

.console-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.console-title {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.25;
  color: var(--text-main);
}

.console-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.55;
}

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

.console-fields {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.input-with-action {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.flex-grow {
  flex: 1;
  min-width: 0;
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.input-with-icon svg {
  position: absolute;
  inset-inline-start: 13px;
  color: var(--text-subtle);
  pointer-events: none;
  transition: color var(--transition-fast);
}

.input-with-icon input {
  width: 100%;
  min-width: 0;
  height: 44px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding-block: 0;
  padding-inline: 40px 14px;
  font-size: 0.9rem;
  color: var(--text-main);
  outline: none;
  transition: var(--transition-fast);
}

.input-with-icon input::placeholder {
  color: var(--text-subtle);
}

.input-with-icon input:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.input-with-icon:focus-within svg {
  color: var(--text-main);
}

.room-link-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  min-width: 0;
  max-width: 100%;
}

.room-link-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.room-link-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-width: 0;
  padding: 4px 9px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.74rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.room-link-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-link-chip svg {
  flex-shrink: 0;
  opacity: 0.78;
}

.room-link-chip:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-main);
}

.room-link-chip.copied {
  border-color: rgba(52, 211, 153, 0.45);
  background: var(--color-emerald-soft);
  color: var(--color-emerald);
}

.room-link-chip:disabled {
  opacity: 0.55;
  cursor: default;
}

.form-select {
  width: 100%;
  height: 42px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: 0.85rem;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
}

.form-select:focus {
  border-color: var(--border-strong);
}

.form-row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-secondary {
  height: 44px;
  padding: 0 15px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-main);
}

.btn-icon-only {
  width: 44px;
  padding: 0;
  flex-shrink: 0;
}

/* Tactile 4-Way Hardware Mode Rail */
.mode-rail-wrap {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.mode-rail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.mode-rail-hint {
  font-size: 0.7rem;
  color: var(--text-subtle);
  font-weight: 500;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--bg-rail);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.mode-chip {
  height: 36px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.mode-chip:hover {
  color: var(--text-main);
}

.mode-chip.active {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-main);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.mode-chip[data-quality-mode="gaming"].active {
  background: var(--color-amber-soft);
  border-color: rgba(245, 158, 11, 0.45);
  color: var(--color-amber);
}

.mode-description {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
  min-height: 22px;
}

/* High-Contrast Authoritative Primary CTA */
.btn-primary {
  width: 100%;
  height: 48px;
  padding: 0 20px;
  background: var(--cta-bg);
  color: var(--cta-fg);
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.94rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: var(--transition-fast);
}

.btn-primary:hover {
  background: var(--cta-bg-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

/* Inline Active Rooms List */
.active-rooms-section {
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.active-rooms-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.active-rooms-header h3 {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.btn-refresh {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-refresh:hover {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.active-rooms-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.empty-rooms {
  font-size: 0.77rem;
  color: var(--text-subtle);
}

.room-item-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 0.78rem;
  transition: var(--transition-fast);
}

.room-item-row:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}

.room-item-name {
  font-weight: 700;
  color: var(--text-main);
}

.room-item-count {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Left Hero Stage — Cinema Viewfinder Frame */
.lobby-stage-col {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.viewfinder-frame {
  --vu-level: 0;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 300px;
  max-height: min(520px, calc(100dvh - 140px));
  background: #0d0f14;
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-viewfinder);
  transition: box-shadow 0.25s ease;
}

.viewfinder-frame.speaking {
  box-shadow: 0 32px 80px -24px rgba(0, 0, 0, 0.85), 0 0 0 1.5px var(--color-emerald);
}

/* Precision Optical Corner Reticles */
.vf-reticle {
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
  z-index: 6;
  border-color: rgba(255, 255, 255, 0.26);
  border-style: solid;
  border-width: 0;
}

.vf-reticle.tl { top: 12px; left: 12px; border-top-width: 1.5px; border-left-width: 1.5px; border-top-left-radius: 4px; }
.vf-reticle.tr { top: 12px; right: 12px; border-top-width: 1.5px; border-right-width: 1.5px; border-top-right-radius: 4px; }
.vf-reticle.bl { bottom: 12px; left: 12px; border-bottom-width: 1.5px; border-left-width: 1.5px; border-bottom-left-radius: 4px; }
.vf-reticle.br { bottom: 12px; right: 12px; border-bottom-width: 1.5px; border-right-width: 1.5px; border-bottom-right-radius: 4px; }

#preview-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#preview-video.mirrored,
#local-video.mirrored {
  transform: scaleX(-1);
}

.preview-avatar-fallback {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: radial-gradient(circle at 50% 42%, #181b23 0%, #0b0d11 100%);
  color: #f4f3ef;
}

.preview-avatar-ring {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: #1b1f29;
  border: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 800;
  color: #f4f3ef;
}

.preview-cam-off-hint {
  font-size: 0.78rem;
  color: rgba(244, 243, 239, 0.55);
}

/* Viewfinder Top Overlay */
.vf-top-bar {
  position: absolute;
  top: 18px;
  inset-inline: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 5;
  pointer-events: none;
}

.vf-top-bar > * {
  pointer-events: auto;
}

.preview-chip {
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(244, 243, 239, 0.92);
  background: rgba(9, 10, 13, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 5px 11px;
  border-radius: var(--radius-full);
}

.btn-ghost-sm {
  height: 30px;
  padding: 0 11px;
  background: rgba(9, 10, 13, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-full);
  color: rgba(244, 243, 239, 0.9);
  font-size: 0.74rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-ghost-sm:hover {
  background: rgba(244, 243, 239, 0.16);
  border-color: rgba(255, 255, 255, 0.28);
}

/* Viewfinder Integrated Bottom Instrument Console */
.vf-bottom-dock {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  padding: 36px 18px 16px;
  background: linear-gradient(to top, rgba(9, 10, 13, 0.94) 38%, rgba(9, 10, 13, 0.55) 75%, transparent 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 5;
}

.preview-overlay {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.vu-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: rgba(17, 19, 24, 0.78);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: var(--radius-full);
}

.vu-eq {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 14px;
}

.vu-eq i {
  display: block;
  width: 2.5px;
  border-radius: 2px;
  background: var(--color-emerald);
  height: calc(4px + var(--vu-level, 0) * 10px);
  transition: height 0.08s ease;
}

.vu-eq i:nth-child(2) { height: calc(6px + var(--vu-level, 0) * 12px); }
.vu-eq i:nth-child(3) { height: calc(8px + var(--vu-level, 0) * 14px); }
.vu-eq i:nth-child(4) { height: calc(5px + var(--vu-level, 0) * 11px); }

.audio-vu-meter {
  width: 68px;
  height: 4px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.vu-bar {
  height: 100%;
  width: 0%;
  background: var(--color-emerald);
  border-radius: var(--radius-full);
  transition: width 0.08s linear;
}

.preview-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-btn.mini {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(24, 27, 34, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #f4f3ef;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.control-btn.mini:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.28);
}

.control-btn.mini.active {
  background: #f4f3ef;
  color: #090a0d;
  border-color: #f4f3ef;
}

.control-btn.mini.muted {
  background: rgba(239, 68, 68, 0.22);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

.control-btn.mini.muted .icon-unmuted { display: none; }
.control-btn.mini.muted .icon-muted { display: block !important; }

/* Integrated Telemetry Strip Inside Viewfinder */
.vf-telemetry-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 14px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.11);
  color: #f4f3ef;
}

.readiness-metrics {
  display: flex;
  align-items: center;
  gap: 18px;
}

.readiness-metric {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.metric-label {
  font-size: 0.7rem;
  color: rgba(244, 243, 239, 0.56);
}

.metric-value {
  font-size: 0.8rem;
  font-weight: 700;
  color: #f4f3ef;
}

.vf-telemetry-right {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 1 1 260px;
  min-width: 0;
}

.readiness-recommendation {
  font-size: 0.72rem;
  color: rgba(244, 243, 239, 0.76);
  white-space: normal;
  line-height: 1.45;
}

.btn-retest {
  height: 28px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-full);
  color: #f4f3ef;
  font-size: 0.71rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.btn-retest:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-retest.spinning svg {
  animation: spin 0.9s linear infinite;
}

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

/* ==========================================================================
   Call Stage — Cinema Precision Grid & Spotlight
   ========================================================================== */
.call-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}

.call-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.stage-adaptive-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.banner-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-amber);
}

.stage-content {
  flex: 1;
  min-height: 0;
  padding: 14px 18px 92px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.video-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 12px;
  align-content: center;
  justify-content: center;
}

.video-grid.count-1 {
  grid-template-columns: minmax(0, 940px);
  grid-template-rows: minmax(0, 1fr);
}

.video-grid.count-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
}

.video-grid.count-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.video-grid.count-6 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.video-grid.count-many {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.video-tile {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 150px;
  background: #0d0f14;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.video-tile.speaking {
  border-color: var(--color-emerald);
  box-shadow: 0 0 0 1px var(--color-emerald);
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-tile.back-camera #local-video {
  transform: none;
}

.avatar-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 42%, #181b23 0%, #0b0d11 100%);
}

.avatar-ring {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: #1b1f29;
  border: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.85rem;
  font-weight: 800;
  color: #f4f3ef;
}

.tile-top-actions {
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transform: translateY(-4px);
  transition: var(--transition-fast);
  z-index: 6;
}

.video-tile:hover .tile-top-actions,
.tile-top-actions.open {
  opacity: 1;
  transform: translateY(0);
}

.tile-action-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(9, 10, 13, 0.74);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f4f3ef;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.tile-action-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.tile-action-btn.danger:hover {
  background: var(--color-rose);
  border-color: var(--color-rose);
  color: #fff;
}

.tile-action-btn.host-transfer:hover {
  background: var(--color-amber);
  border-color: var(--color-amber);
  color: #111;
}

.tile-host-actions {
  display: none;
  align-items: center;
  gap: 5px;
  padding-inline-end: 2px;
  border-inline-end: 1px solid rgba(255, 255, 255, 0.14);
}

.video-grid.is-room-owner .tile-host-actions {
  display: flex;
}

.tile-volume-popover {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: rgba(9, 10, 13, 0.86);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-full);
  color: #f4f3ef;
}

.tile-volume-popover.open {
  display: flex;
}

.tile-volume-slider {
  width: 72px;
  accent-color: #f4f3ef;
}

.tile-volume-val {
  font-size: 0.7rem;
  min-width: 34px;
}

.tile-overlay {
  position: absolute;
  inset-inline: 10px;
  bottom: 10px;
  display: flex;
  justify-content: flex-start;
  pointer-events: none;
  z-index: 5;
}

.tile-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px;
  background: rgba(9, 10, 13, 0.72);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-full);
  font-size: 0.76rem;
  font-weight: 600;
  color: #f4f3ef;
}

.status-icons {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.status-icon {
  display: inline-flex;
  color: rgba(244, 243, 239, 0.75);
}

.status-icon.muted {
  color: #f87171;
}

.peer-stats-badge {
  font-size: 0.69rem;
  color: rgba(244, 243, 239, 0.65);
}

.signal-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 1.5px;
  height: 11px;
}

.signal-bars i {
  width: 2.5px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.22);
}

.signal-bars i:nth-child(1) { height: 3px; }
.signal-bars i:nth-child(2) { height: 5px; }
.signal-bars i:nth-child(3) { height: 8px; }
.signal-bars i:nth-child(4) { height: 11px; }

.signal-bars.lvl-4 i { background: var(--color-emerald); }
.signal-bars.lvl-3 i:nth-child(-n+3) { background: var(--color-emerald); }
.signal-bars.lvl-2 i:nth-child(-n+2) { background: var(--color-amber); }
.signal-bars.lvl-1 i:nth-child(1) { background: var(--color-rose); }

/* Screen Share / Spotlight + Filmstrip */
.screen-spotlight {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #07080b;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

.stage-content.spotlight-active .video-grid {
  flex: 0 0 132px;
  height: 132px;
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  justify-content: flex-start;
  gap: 10px;
}

.stage-content.spotlight-active .video-tile {
  flex: 0 0 210px;
  height: 100%;
  min-height: 0;
}

.spotlight-bar {
  position: absolute;
  top: 12px;
  inset-inline: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.spotlight-bar > * {
  pointer-events: auto;
}

.spotlight-info,
.spotlight-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: rgba(9, 10, 13, 0.78);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-full);
  color: #f4f3ef;
  font-size: 0.76rem;
  font-weight: 600;
}

.spotlight-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-rose);
}

.spotlight-quality-badge {
  font-size: 0.7rem;
  color: rgba(244, 243, 239, 0.65);
}

.btn-mini-neutral {
  background: rgba(255, 255, 255, 0.1);
  color: #f4f3ef;
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-mini-neutral:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-mini-danger {
  background: var(--color-rose);
  color: #fff;
  border: none;
  padding: 4px 11px;
  border-radius: var(--radius-full);
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
}

/* ==========================================================================
   Floating Hardware Capsule Dock & Mode Popover
   ========================================================================== */
.mode-popover {
  position: absolute;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  width: 286px;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 9px;
  z-index: 45;
  box-shadow: var(--shadow-dock);
  animation: modal-enter 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}

.popover-title {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 8px 8px;
}

.popover-item {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: start;
  cursor: pointer;
  transition: var(--transition-fast);
}

.popover-item:hover {
  background: var(--color-primary-soft);
}

.popover-item.active {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.popover-item[data-quality-mode="gaming"].active {
  background: var(--color-amber-soft);
  border-color: rgba(245, 158, 11, 0.45);
}

.popover-item strong {
  display: block;
  font-size: 0.81rem;
  color: var(--text-main);
}

.popover-item span {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.popover-check {
  opacity: 0;
  color: var(--color-emerald);
  font-weight: 800;
}

.popover-item.active .popover-check {
  opacity: 1;
}

.host-popover {
  position: absolute;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  width: 318px;
  max-width: calc(100vw - 24px);
  background: var(--bg-surface-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 10px;
  z-index: 46;
  box-shadow: var(--shadow-dock);
  animation: modal-enter 0.16s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.host-popover-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px;
}

.host-popover-sub {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-subtle);
}

.host-toggle-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.switch-row.compact-switch {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.host-toggle-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.host-toggle-copy strong {
  font-size: 0.79rem;
  font-weight: 700;
  color: var(--text-main);
}

.host-toggle-copy span {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.host-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding-top: 2px;
}

.btn-host-action {
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 0.74rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-host-action:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.btn-host-action.danger {
  background: var(--color-rose-soft);
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--color-rose);
}

.btn-host-action.danger:hover,
.btn-host-action.danger.armed {
  background: var(--color-rose);
  border-color: var(--color-rose);
  color: #fff;
}

.dock-btn.host-btn {
  color: var(--color-amber);
}

.dock-btn.host-btn.active {
  background: var(--color-amber-soft);
  border-color: rgba(245, 158, 11, 0.48);
  color: var(--color-amber);
}

.dock-btn.restricted {
  opacity: 0.45;
  cursor: not-allowed;
}

.call-dock {
  position: absolute;
  bottom: 16px;
  inset-inline: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 35;
}

.dock-container {
  pointer-events: auto;
  background: var(--bg-dock);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-radius: var(--radius-full);
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: var(--shadow-dock);
}

.dock-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 6px 11px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: var(--transition-fast);
  min-width: 56px;
}

.dock-btn:hover {
  background: var(--color-primary-soft);
  color: var(--text-main);
}

.dock-btn.active {
  background: var(--cta-bg);
  color: var(--cta-fg);
}

.dock-btn.gaming-active {
  background: var(--color-amber-soft);
  border-color: rgba(245, 158, 11, 0.45);
  color: var(--color-amber);
}

.dock-btn.muted {
  background: var(--color-rose-soft);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--color-rose);
}

.dock-btn.muted .icon-on { display: none; }
.dock-btn.muted .icon-off { display: block !important; }

.dock-btn.danger {
  background: var(--color-rose);
  color: #fff;
  padding: 6px 15px;
}

.dock-btn.danger:hover {
  background: var(--color-rose-hover);
}

.dock-label {
  font-size: 0.67rem;
  font-weight: 600;
  white-space: nowrap;
}

.dock-divider {
  width: 1px;
  height: 24px;
  background: var(--border-subtle);
  margin: 0 3px;
}

.mobile-only-btn {
  display: none !important;
}

.badge-target {
  position: relative;
}

.unread-badge {
  position: absolute;
  top: -4px;
  inset-inline-end: -7px;
  background: var(--color-rose);
  color: white;
  font-size: 0.62rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dock-health-dot {
  position: absolute;
  top: -1px;
  inset-inline-end: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-emerald);
}

/* ==========================================================================
   Docked Chat Drawer
   ========================================================================== */
.chat-sidebar {
  width: 0;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-inline-start: 0 solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transition: width var(--transition-normal), opacity 0.2s ease;
  z-index: 40;
}

.chat-sidebar.open {
  width: 330px;
  opacity: 1;
  border-inline-start-width: 1px;
}

.chat-header {
  height: 54px;
  flex-shrink: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.88rem;
}

.chat-messages {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-system-msg {
  font-size: 0.74rem;
  color: var(--text-muted);
  text-align: center;
  padding: 7px 11px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.chat-msg-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 88%;
  align-self: flex-start;
}

.chat-msg-row.is-self {
  align-self: flex-end;
}

.chat-msg-header {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.chat-msg-row.is-self .chat-msg-header {
  flex-direction: row-reverse;
}

.chat-msg-author {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.chat-msg-time {
  font-size: 0.66rem;
  color: var(--text-subtle);
}

.chat-msg-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 8px 12px;
  border-radius: 13px 13px 4px 13px;
  font-size: 0.84rem;
  color: var(--text-main);
  line-height: 1.5;
  word-break: break-word;
}

.chat-msg-row.is-self .chat-msg-bubble {
  background: var(--cta-bg);
  color: var(--cta-fg);
  border-color: transparent;
  border-radius: 13px 13px 13px 4px;
}

.chat-input-bar {
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 8px;
}

.chat-input-bar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-size: 0.85rem;
  outline: none;
}

.chat-input-bar input:focus {
  border-color: var(--border-strong);
}

.btn-chat-send {
  background: var(--cta-bg);
  color: var(--cta-fg);
  border: none;
  border-radius: var(--radius-md);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ==========================================================================
   Modals (Settings & Network HUD)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop-modal);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-dock);
  overflow: hidden;
  animation: modal-enter 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-card.wide {
  max-width: 700px;
}

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.97) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.hud-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-title svg {
  color: var(--color-emerald);
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 800;
}

.modal-subtitle {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.modal-body {
  padding: 18px 20px;
  max-height: 74vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 13px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-footer .btn-primary {
  width: auto;
  min-width: 136px;
  height: 40px;
}

.modal-footer .btn-secondary {
  height: 40px;
}

.settings-section {
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.settings-section:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}

.settings-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.label-with-action {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-inline-test {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 0.71rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  cursor: pointer;
}

.settings-toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-size: 0.84rem;
  padding: 9px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.switch-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-surface);
  top: 3px;
  inset-inline-start: 3px;
  transition: var(--transition-fast);
}

.switch-input:checked + .switch-slider {
  background: var(--color-emerald);
}

.switch-input:checked + .switch-slider::before {
  transform: translateX(-18px);
}

/* HUD Banner & Cards */
.hud-engine-banner {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.hud-banner-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.hud-mode-pill {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--cta-fg);
  background: var(--cta-bg);
  padding: 3px 10px;
  border-radius: var(--radius-full);
}

.hud-health-score {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--color-emerald);
}

.hud-engine-reason {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 12px;
}

.hud-quick-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hud-mode-pills {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.hud-mode-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  cursor: pointer;
}

.hud-mode-btn.active {
  background: var(--cta-bg);
  border-color: var(--cta-bg);
  color: var(--cta-fg);
}

.hud-mode-btn[data-quality-mode="gaming"].active {
  background: var(--color-amber);
  border-color: var(--color-amber);
  color: #090a0d;
}

.hud-engine-banner .btn-retest {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.stats-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-elevated);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-label {
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-val {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text-main);
}

.stat-val.emerald { color: var(--color-emerald); }
.stat-val.amber { color: var(--color-amber); }
.stat-val.rose { color: var(--color-rose); }

.stat-sub {
  font-size: 0.71rem;
  color: var(--text-subtle);
}

.section-subtitle {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stats-peer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.peer-stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.peer-stat-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.peer-stat-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.76rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-container {
  position: fixed;
  top: 68px;
  inset-inline-end: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-dock);
  border-radius: var(--radius-md);
  padding: 10px 15px;
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text-main);
  animation: toast-slide 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 230px;
  max-width: 350px;
}

.toast.toast-success { border-inline-start: 3px solid var(--color-emerald); }
.toast.toast-error { border-inline-start: 3px solid var(--color-rose); }
.toast.toast-warning { border-inline-start: 3px solid var(--color-amber); }
.toast.toast-info { border-inline-start: 3px solid var(--text-main); }

@keyframes toast-slide {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 1180px) {
  #view-lobby {
    padding: 20px 24px;
  }

  .lobby-workspace {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    gap: 28px;
  }

  .console-title {
    font-size: 1.52rem;
  }

  .viewfinder-frame {
    min-height: 270px;
  }
}

@media (min-width: 981px) and (max-height: 760px) {
  #view-lobby {
    padding: 16px 26px;
  }

  .lobby-workspace {
    gap: 30px;
  }

  .lobby-console {
    gap: 14px;
  }

  .console-header {
    gap: 4px;
  }

  .console-title {
    font-size: 1.48rem;
  }

  .console-subtitle {
    font-size: 0.82rem;
  }

  .join-form {
    gap: 12px;
  }

  .console-fields {
    gap: 10px;
  }

  .input-with-icon input {
    height: 40px;
  }

  .form-select {
    height: 38px;
  }

  .btn-secondary,
  .btn-icon-only {
    height: 40px;
  }

  .viewfinder-frame {
    min-height: 250px;
    max-height: calc(100dvh - 112px);
  }

  .stage-content {
    padding: 10px 14px 82px;
    gap: 10px;
  }

  .video-tile {
    min-height: 110px;
  }

  .mode-popover,
  .host-popover {
    max-height: calc(100dvh - 132px);
    overflow-y: auto;
  }
}

@media (max-width: 980px) {
  #view-lobby {
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  }

  .lobby-shell {
    margin: 0 auto;
  }

  .lobby-workspace {
    grid-template-columns: 1fr;
    gap: 18px;
    max-width: 580px;
    margin: 0 auto;
  }

  .lobby-console {
    gap: 16px;
  }

  .viewfinder-frame {
    aspect-ratio: 16 / 9;
    min-height: 210px;
    max-height: 300px;
  }

  .chat-sidebar {
    width: 100% !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 95 !important;
    border-inline-start: none !important;
    transform: translateY(100%);
    opacity: 1;
    transition: transform var(--transition-normal);
  }

  .chat-sidebar.open {
    transform: translateY(0);
  }

  .video-grid.count-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
  }

  .video-grid.count-many {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(130px, 1fr);
    overflow-y: auto;
    align-content: start;
  }

  .video-tile {
    min-height: 0;
  }
}

@media (max-width: 960px) {
  .brand-sub,
  #connection-text,
  #copy-invite-label,
  #btn-stage-quality-pill {
    display: none;
  }

  .connection-pill {
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
  }

  .btn-copy-invite {
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
    flex-shrink: 0;
  }
}

@media (max-width: 640px) {
  .top-nav {
    height: 48px;
    padding-top: max(0px, env(safe-area-inset-top));
    padding-inline-start: max(12px, env(safe-area-inset-right));
    padding-inline-end: max(12px, env(safe-area-inset-left));
    gap: 6px;
  }

  .logo-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
  }

  .brand-name {
    font-size: 0.98rem;
  }

  #nav-lobby-status {
    display: none;
  }

  .nav-actions {
    gap: 6px;
  }

  .connection-pill,
  .icon-btn {
    width: 30px;
    height: 30px;
  }

  .active-room-group {
    gap: 5px;
  }

  .active-room-pill {
    height: 28px;
    padding: 0 9px;
    gap: 5px;
    font-size: 0.72rem;
  }

  .room-slug {
    max-width: 96px;
  }

  .btn-copy-invite {
    width: 28px;
    height: 28px;
  }

  #view-lobby {
    padding: 12px 12px calc(22px + env(safe-area-inset-bottom));
  }

  .lobby-workspace {
    gap: 14px;
  }

  .lobby-console {
    gap: 14px;
  }

  .console-header {
    gap: 4px;
  }

  .console-title {
    font-size: 1.24rem;
    line-height: 1.3;
  }

  .console-subtitle {
    font-size: 0.79rem;
    line-height: 1.45;
  }

  .join-form {
    gap: 12px;
  }

  .console-fields {
    gap: 10px;
  }

  .input-with-icon input {
    height: 42px;
    font-size: 16px;
  }

  .form-select {
    height: 40px;
    font-size: 16px;
  }

  .btn-secondary {
    height: 40px;
  }

  .btn-icon-only {
    width: 40px;
    height: 40px;
  }

  .form-row-grid {
    gap: 8px;
  }

  .viewfinder-frame {
    aspect-ratio: 16 / 9;
    min-height: 175px;
    max-height: 220px;
    border-radius: var(--radius-lg);
  }

  .preview-avatar-fallback {
    padding-bottom: 54px;
    gap: 6px;
  }

  .preview-avatar-ring {
    width: 52px;
    height: 52px;
    font-size: 1.35rem;
  }

  .preview-cam-off-hint {
    font-size: 0.72rem;
  }

  .vf-top-bar {
    top: 10px;
    inset-inline: 10px;
    gap: 6px;
  }

  .preview-chip {
    font-size: 0.68rem;
    padding: 4px 8px;
  }

  .btn-ghost-sm {
    height: 26px;
    padding: 0 9px;
    font-size: 0.69rem;
  }

  .vf-bottom-dock {
    padding: 20px 10px 10px;
    gap: 6px;
  }

  .vu-pill {
    padding: 4px 9px;
    gap: 7px;
  }

  .audio-vu-meter {
    width: 48px;
  }

  .control-btn.mini {
    width: 34px;
    height: 34px;
  }

  .vf-telemetry-strip {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 6px;
  }

  .vf-telemetry-right {
    flex: 0 0 auto;
  }

  .readiness-recommendation {
    display: none;
  }

  .readiness-metrics {
    justify-content: flex-start;
    gap: 10px;
    min-width: 0;
  }

  .metric-label {
    font-size: 0.66rem;
  }

  .metric-value {
    font-size: 0.74rem;
  }

  .btn-retest {
    height: 26px;
    padding: 0 8px;
    font-size: 0.67rem;
  }

  .mobile-only-btn {
    display: flex !important;
  }

  .stage-content {
    padding: 8px 8px calc(68px + env(safe-area-inset-bottom));
    gap: 6px;
  }

  .video-grid {
    gap: 6px;
  }

  .video-grid.count-1 {
    grid-template-columns: minmax(0, 1fr);
  }

  .video-grid.count-2 {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .video-grid.count-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .video-grid.count-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
  }

  .video-grid.count-many {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(120px, 1fr);
    overflow-y: auto;
    align-content: start;
  }

  .video-tile {
    min-height: 0;
    border-radius: var(--radius-md);
  }

  .avatar-ring {
    width: 54px;
    height: 54px;
    font-size: 1.35rem;
  }

  .stage-content.spotlight-active .video-grid {
    flex: 0 0 88px;
    height: 88px;
  }

  .stage-content.spotlight-active .video-tile {
    flex: 0 0 132px;
  }

  .tile-overlay {
    inset-inline: 6px;
    bottom: 6px;
    max-width: calc(100% - 12px);
  }

  .tile-badge {
    gap: 5px;
    padding: 3px 8px;
    font-size: 0.68rem;
    max-width: 100%;
    overflow: hidden;
  }

  .tile-badge.name-badge > span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  .tile-top-actions {
    top: 6px;
    inset-inline-end: 6px;
    opacity: 1;
    transform: none;
    gap: 4px;
  }

  .tile-action-btn {
    width: 26px;
    height: 26px;
  }

  .tile-volume-popover.open {
    position: absolute;
    top: 32px;
    inset-inline-end: 0;
  }

  .call-dock {
    bottom: max(8px, env(safe-area-inset-bottom));
    padding: 0 6px;
  }

  .dock-container {
    padding: 4px 6px;
    gap: 3px;
    max-width: calc(100vw - 12px);
    overflow-x: auto;
    scrollbar-width: none;
    border-radius: var(--radius-full);
  }

  .dock-container::-webkit-scrollbar { display: none; }

  .dock-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 4px 6px;
    border-radius: var(--radius-full);
  }

  .dock-btn.danger {
    padding: 4px 11px;
  }

  .dock-label { font-size: 0.59rem; }
  .dock-divider { display: none; }

  .mode-popover,
  .host-popover {
    bottom: 68px;
    width: calc(100vw - 20px);
    max-width: 328px;
    max-height: calc(100dvh - 130px);
    overflow-y: auto;
  }

  .stats-summary-grid {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .modal-card {
    display: flex;
    flex-direction: column;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    max-height: 88dvh;
    max-width: 100%;
  }

  .modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    max-height: calc(88dvh - 124px);
    padding: 16px;
  }

  .toast-container {
    inset-inline: 12px;
    top: 56px;
  }

  .toast { max-width: 100%; }
}

@media (max-width: 480px) {
  body.in-call .brand-text-group {
    display: none;
  }

  #call-peer-count,
  #call-peer-count + .pill-divider,
  #btn-dock-settings {
    display: none;
  }

  .room-slug {
    max-width: 78px;
  }

  .room-flag-badge {
    padding: 1px 5px;
    font-size: 0.6rem;
  }

  .peer-stats-badge {
    display: none;
  }

  .dock-container {
    gap: 3px;
    padding: 4px 6px;
  }

  .dock-label {
    display: none;
  }

  .dock-btn {
    min-width: 34px;
    width: 34px;
    height: 36px;
    min-height: 36px;
    padding: 0;
  }

  .dock-btn.danger {
    width: auto;
    min-width: 42px;
    padding: 0 10px;
  }
}

@media (max-width: 380px) {
  .top-nav {
    padding-inline-start: max(8px, env(safe-area-inset-right));
    padding-inline-end: max(8px, env(safe-area-inset-left));
    gap: 4px;
  }

  .nav-actions {
    gap: 4px;
  }

  .connection-pill,
  .icon-btn,
  .btn-copy-invite {
    width: 28px;
    height: 28px;
  }

  .active-room-pill {
    height: 26px;
    padding: 0 7px;
    gap: 4px;
    font-size: 0.68rem;
  }

  .active-room-pill .pulse-dot {
    display: none;
  }

  .room-slug {
    max-width: 68px;
  }

  .form-row-grid {
    grid-template-columns: 1fr;
  }

  .mode-chip {
    height: 34px;
    font-size: 0.72rem;
  }

  .room-link-bar {
    flex-wrap: wrap;
  }

  .dock-container {
    gap: 2px;
    padding: 4px 5px;
  }

  .dock-btn {
    min-width: 29px;
    width: 29px;
    height: 34px;
    min-height: 34px;
  }

  .dock-btn.danger {
    min-width: 36px;
    padding: 0 8px;
  }
}

@media (max-width: 980px) and (max-height: 520px) {
  .top-nav {
    height: 42px;
  }

  #view-lobby {
    padding: 8px 14px calc(14px + env(safe-area-inset-bottom));
  }

  .lobby-workspace {
    grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
    gap: 16px;
    max-width: 100%;
    align-items: start;
  }

  .lobby-console {
    gap: 8px;
  }

  .console-header,
  .mode-description {
    display: none;
  }

  .join-form {
    gap: 8px;
  }

  .console-fields {
    gap: 6px;
  }

  .form-group {
    gap: 3px;
  }

  .form-group label {
    font-size: 0.72rem;
  }

  .input-with-icon input {
    height: 36px;
    font-size: 0.86rem;
  }

  .btn-secondary,
  .btn-icon-only {
    height: 36px;
  }

  .btn-icon-only {
    width: 36px;
  }

  .mode-chip {
    height: 30px;
    font-size: 0.74rem;
  }

  .btn-join {
    height: 40px;
    padding: 0 14px;
    font-size: 0.88rem;
  }

  .viewfinder-frame {
    min-height: 170px;
    max-height: calc(100dvh - 76px);
  }

  .readiness-recommendation {
    display: none;
  }

  .stage-content {
    padding: 6px 10px calc(58px + env(safe-area-inset-bottom));
    gap: 6px;
  }

  .video-grid.count-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
  }

  .call-dock {
    bottom: max(6px, env(safe-area-inset-bottom));
  }

  .dock-label {
    display: none;
  }

  .dock-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 0 8px;
  }

  .mode-popover,
  .host-popover {
    bottom: 56px;
    max-height: calc(100dvh - 104px);
  }
}
