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

:root {
  /* Knox-inspired palette: dark UI with Samsung blue accent */
  --bg: #0f1115;
  --bg-elev: #1a1d24;
  --bg-elev-2: #242830;
  --bg-elev-3: #2d3139;
  --border: #2d3139;
  --border-strong: #3d424c;
  --text: #e8e9ea;
  --text-muted: #9aa0aa;
  --text-dim: #6b7280;
  --accent: #1976ff;
  --accent-hover: #3a8aff;
  --accent-2: #0c4dab;
  --danger: #e24b4a;
  --success: #1d9e75;
  --warning: #f2a623;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

/* Make hidden attribute always win over display: flex/grid/etc. */
[hidden] { display: none !important; }

.brand { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; color: var(--text); }

.screen {
  display: none;
  height: 100vh;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* ============== Auth ============== */
#screen-auth { align-items: center; justify-content: center; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}
.card h2 {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 14px;
  color: var(--text-muted);
}
.auth-card { min-width: 380px; }
.auth-card .brand { display: block; text-align: center; margin-bottom: 24px; font-size: 22px; }

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.tabs .tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs .tab.active { color: var(--text); border-bottom-color: var(--accent); }

.auth-form { display: none; flex-direction: column; gap: 10px; }
.auth-form.active { display: flex; }

input[type="text"], input[type="email"], input[type="password"], select {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }

button {
  font-family: inherit;
  cursor: pointer;
  font-size: 14px;
}
.btn-primary {
  background: var(--accent);
  border: none;
  color: white;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 500;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary.btn-sm { padding: 8px 14px; font-size: 13px; }

.btn-danger {
  background: var(--danger);
  border: none;
  color: white;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 500;
}
.btn-danger:hover { background: #c43d3c; }

.btn-text {
  background: none;
  color: var(--text-muted);
  padding: 4px 8px;
  border: none;
  border-radius: 4px;
}
.btn-text:hover { color: var(--text); background: var(--bg-elev-2); }

.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

/* ============== Lobby ============== */
.topbar {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.lobby form { display: flex; flex-direction: column; gap: 10px; }

/* ============== Lobby (refined) ============== */
.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.user-greet {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  background: var(--bg-elev-2);
  border-radius: 20px;
}
.user-greet .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}
.user-greet #user-name {
  color: var(--text);
  font-weight: 500;
}

.btn-icon {
  cursor: pointer;
}

.lobby {
  flex: 1;
  padding: 40px 32px 60px;
  overflow-y: auto;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: relative;
  z-index: 1;
}

/* Decorative wave background — sits behind all lobby content */
#screen-lobby { position: relative; overflow: hidden; }
.lobby-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.lobby-bg-waves {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  /* Cover the lower 70% of the lobby; flows naturally at all sizes */
  width: 100%;
  height: 70%;
  display: block;
  /* The viewBox is 0..1440 but each wave path actually extends to 2880
     (twice as wide). We let the SVG render the full content via overflow,
     and animate each <g> by translating along x. */
  overflow: visible;
}

/* Each wave-layer pans its 2× path across the viewport. We give each layer
   a unique speed and direction so the waves read as a flowing scene rather
   than a single rigid background. The drift cycle is the same length as
   one viewport-width of motion (1440 units), so the loop is seamless. */
.wave-layer {
  /* Default GPU-friendly transform — overridden by per-layer keyframes */
  transform-origin: 0 0;
  will-change: transform;
}
.wave-layer path {
  /* SVG paths re-rasterize on each frame at their fill region; with a
     gradient fill this is cheap on modern GPUs. */
  shape-rendering: geometricPrecision;
}

/* Layer-specific drift + breathing. Each layer pairs:
     1) drift-X: horizontal pan of -1440 user units (= half the 2880-wide
        path). For SVG <g> elements, CSS px units are interpreted as
        user-units in the local coordinate system, so this stays correctly
        aligned regardless of how the SVG is scaled visually.
     2) breathe-X: tiny vertical sway via the `translate` property, on a
        different cadence so layers don't pulse in sync.
   Animations are layered with the comma-separated animation shorthand. */
@keyframes wave-drift-lr {
  from { transform: translateX(0); }
  to   { transform: translateX(-1440px); }
}
@keyframes wave-drift-rl {
  from { transform: translateX(-1440px); }
  to   { transform: translateX(0); }
}
@keyframes wave-breathe-a {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 -8px; }
}
@keyframes wave-breathe-b {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 6px; }
}

.wave-1 { animation: wave-drift-lr 60s linear infinite, wave-breathe-a 11s ease-in-out infinite; }
.wave-2 { animation: wave-drift-rl 80s linear infinite, wave-breathe-b 13s ease-in-out infinite; }
.wave-3 { animation: wave-drift-lr 45s linear infinite, wave-breathe-a 9s ease-in-out infinite; }
.wave-4 { animation: wave-drift-rl 100s linear infinite, wave-breathe-b 17s ease-in-out infinite; }
.wave-5 { animation: wave-drift-lr 35s linear infinite, wave-breathe-a 7s ease-in-out infinite; }

/* Glow orbs — soft pulsing highlights. Each orb fades in and out and
   drifts a tiny amount. Different cadences keep them from blinking in
   sync. SVG circles fill is a radial gradient that already fades cleanly
   to transparent at the edge, so we only animate opacity (cheap on GPU). */
.glow {
  opacity: 0;
  transform-origin: center;
  filter: blur(2px);
  will-change: opacity, transform;
}
@keyframes glow-pulse {
  0%, 100% { opacity: 0;    transform: scale(0.85); }
  50%      { opacity: 0.55; transform: scale(1.05); }
}
@keyframes glow-pulse-soft {
  0%, 100% { opacity: 0;    transform: scale(0.9); }
  50%      { opacity: 0.35; transform: scale(1.0); }
}
.glow-1 { animation: glow-pulse 9s ease-in-out infinite; animation-delay: 0s; }
.glow-2 { animation: glow-pulse-soft 14s ease-in-out infinite; animation-delay: 3s; }
.glow-3 { animation: glow-pulse 11s ease-in-out infinite; animation-delay: 5s; }
.glow-4 { animation: glow-pulse-soft 8s ease-in-out infinite; animation-delay: 1.5s; }
.glow-5 { animation: glow-pulse 13s ease-in-out infinite; animation-delay: 7s; }
.glow-6 { animation: glow-pulse-soft 10s ease-in-out infinite; animation-delay: 4s; }

/* Respect reduced-motion preference — keep the visuals but hold them still. */
@media (prefers-reduced-motion: reduce) {
  .wave-layer, .glow { animation: none !important; }
}

/* Topbar must sit above the background */
.lobby-topbar { position: relative; z-index: 2; }

/* Hero section */
.hero {
  margin-top: 12px;
}
.hero-title {
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}
.hero-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}
.hero-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.hero-btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
  font-family: inherit;
}
.hero-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-elev-2);
}
.hero-btn:active { transform: translateY(1px); }
.hero-btn-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--bg-elev-2);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.hero-btn.primary {
  background: linear-gradient(135deg, #1976ff 0%, #0c4dab 100%);
  border-color: transparent;
  color: white;
}
.hero-btn.primary:hover {
  background: linear-gradient(135deg, #2483ff 0%, #0e57c0 100%);
}
.hero-btn.primary .hero-btn-icon {
  background: rgba(255, 255, 255, 0.18);
  color: white;
}
.hero-btn-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.hero-btn-label strong {
  font-weight: 500;
  font-size: 14px;
  letter-spacing: -0.1px;
}
.hero-btn-label small {
  font-size: 12px;
  opacity: 0.8;
}

/* Lobby cards */
.lobby-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
}
.lobby-card-header {
  padding: 18px 20px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.lobby-card-header h2 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin: 0;
}
.lobby-card-header .btn-text {
  width: 28px;
  height: 28px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.lobby-form {
  padding: 4px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lobby-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  margin-bottom: -4px;
}
.lobby-form-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

.schedule-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.schedule-row input[type="datetime-local"] {
  flex: 1;
  color-scheme: dark;
}
.lobby-form .hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: -2px;
}

.meetings-card .room-list {
  padding: 4px 12px 16px;
}
.room-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}
.room-list li {
  background: transparent;
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.room-list li:last-child { border-bottom: none; }
.room-list li:hover { background: var(--bg-elev-2); }
.room-list .room-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
}
.room-list .room-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
  font-family: ui-monospace, "Menlo", monospace;
}
.room-list .room-actions { display: flex; gap: 6px; align-items: center; }
.room-list .btn-join {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.room-list .btn-join:hover { background: var(--accent-hover); }
.room-list .btn-delete {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
}
.room-list .btn-delete:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.room-list .btn-info-icon {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 6px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.room-list .btn-info-icon:hover {
  background: var(--bg-elev-3);
  color: var(--text);
}
.room-list .empty-row {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 28px 0;
  border: none;
}

/* Schedule / waiter badges (kept compact) */
.schedule-badge,
.waiter-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  margin-top: 4px;
  margin-right: 6px;
}
.schedule-badge.upcoming {
  background: rgba(25, 118, 255, 0.12);
  color: #6790ff;
  border: 1px solid rgba(25, 118, 255, 0.25);
}
.schedule-badge.live {
  background: rgba(29, 158, 117, 0.15);
  color: var(--success);
  border: 1px solid rgba(29, 158, 117, 0.3);
}
.schedule-badge.live::before {
  content: '●';
  margin-right: 4px;
  animation: pulse 1.5s infinite;
}
.waiter-badge {
  background: rgba(242, 166, 35, 0.15);
  color: var(--warning);
  border: 1px solid rgba(242, 166, 35, 0.35);
  cursor: pointer;
}
.waiter-badge:hover { background: rgba(242, 166, 35, 0.28); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Hide deprecated old card classes (keep inheriting elsewhere) */
.lobby .card:not(.auth-card) { padding: 0; }

/* ============== Room ============== */
.room-topbar {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  flex-shrink: 0;
  gap: 12px;
}
.room-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.room-info .room-id {
  color: var(--text-muted);
  font-size: 11px;
  font-family: monospace;
  background: var(--bg-elev-2);
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.room-meta {
  color: var(--text-muted);
  font-size: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-family: monospace;
  flex-shrink: 0;
}
.room-meta .meta-sep { color: var(--border-strong); }

.room-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}
.topbar-btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 12px;
}
.topbar-btn:hover { background: var(--bg-elev-3); }
.topbar-btn .icon { font-size: 14px; }
.topbar-btn-label { font-weight: 500; }
.topbar-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

.room-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.stage {
  flex: 1;
  position: relative;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ----- Gallery layout ----- */
.gallery {
  flex: 1;
  padding: 12px;
  display: grid;
  gap: 8px;
  align-content: center;
  justify-content: center;
  overflow: auto;
}

/* ----- Speaker layout ----- */
.speaker-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  min-height: 0;
}
.speaker-main {
  flex: 1;
  background: var(--bg-elev);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Screen share tile renders the captured display, which can be any
   aspect ratio — use object-fit: contain so it isn't cropped. */
.speaker-main .screenshare-tile {
  background: #000;
}
.speaker-main .screenshare-tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.speaker-main .screenshare-tile .name-tag {
  background: rgba(25, 118, 255, 0.85);
}
.speaker-main .screen-tag {
  margin-left: 8px;
  font-size: 10px;
  opacity: 0.95;
}
.thumb-strip {
  height: 100px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  padding: 2px;
}
.thumb-strip .video-tile {
  flex-shrink: 0;
  width: 150px;
  height: 90px;
  aspect-ratio: auto;
  cursor: pointer;
}

/* ----- Video tile (shared) ----- */
.video-tile {
  background: var(--bg-elev);
  border: 2px solid var(--border);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  min-height: 0;
  transition: border-color 0.15s;
}
.video-tile.speaking { border-color: var(--success); }
.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--bg-elev-2);
  display: block;
}
.video-tile .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: var(--text-muted);
  background: var(--bg-elev-2);
  font-weight: 500;
  letter-spacing: 0;
}
.video-tile .name-tag {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.65);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}
.video-tile .indicators {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  font-size: 11px;
}
.video-tile .indicators .badge {
  background: rgba(0, 0, 0, 0.65);
  padding: 3px 6px;
  border-radius: 4px;
}
.video-tile .indicators .badge.muted { background: var(--danger); }
.video-tile .indicators .badge.hand { background: var(--warning); }
.video-tile .indicators .badge.signal { background: rgba(0, 0, 0, 0.65); padding: 2px 4px; }
.video-tile .indicators .badge.signal.poor { background: rgba(242, 166, 35, 0.85); color: white; }
.video-tile .indicators .badge.signal.lost { background: rgba(226, 75, 74, 0.85); color: white; }
.video-tile .indicators .badge.stream-paused {
  background: rgba(154, 160, 170, 0.85);
  color: white;
}

/* Connection quality border tint */
.video-tile.quality-poor { box-shadow: inset 0 0 0 2px rgba(242, 166, 35, 0.6); }
.video-tile.quality-lost { box-shadow: inset 0 0 0 2px rgba(226, 75, 74, 0.7); }

/* In speaker view, thumbnail tiles are smaller */
.thumb-strip .video-tile .placeholder { font-size: 22px; }
.thumb-strip .video-tile .name-tag { font-size: 10px; padding: 2px 5px; }
.thumb-strip .video-tile .indicators { font-size: 9px; }

/* ----- Self-view PIP ----- */
.self-pip {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 220px;
  height: 124px;
  background: var(--bg-elev);
  border: 2px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  z-index: 10;
  cursor: move;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.self-pip video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--bg-elev-2);
  display: block;
}
.self-pip .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--text-muted);
  background: var(--bg-elev-2);
  font-weight: 500;
}
.self-pip .self-pip-label {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0,0,0,0.65);
  color: white;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  pointer-events: none;
}

/* ----- Sidebar ----- */
.sidebar {
  width: 320px;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.sidebar-tabs .tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 12px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
}
.sidebar-tabs .tab.active { color: var(--text); border-bottom: 2px solid var(--accent); }
.sidebar-tabs .count {
  background: var(--bg-elev-3);
  color: var(--text);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 11px;
  margin-left: 4px;
}

.panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  flex-direction: column;
  min-height: 0;
}
.panel.active { display: flex; }

#participant-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#participant-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border-radius: 6px;
  font-size: 13px;
  gap: 8px;
}
#participant-list .pname { display: flex; align-items: center; gap: 8px; min-width: 0; }
#participant-list .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}
#participant-list .status-icons { display: flex; gap: 4px; font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 6px;
}
.chat-message {
  background: var(--bg-elev-2);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  word-break: break-word;
}
.chat-message .author {
  color: var(--accent);
  font-weight: 500;
  font-size: 11px;
  margin-bottom: 2px;
}
.chat-message.self .author { color: var(--success); }
.chat-message.private .author::after {
  content: ' · ' attr(data-private-label);
  color: var(--warning);
  font-weight: 400;
}
.chat-message .file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg-elev-3);
  border-radius: 6px;
}
.chat-message .file-icon {
  width: 28px;
  height: 28px;
  background: var(--accent-2);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}
.chat-message .file-meta { min-width: 0; flex: 1; }
.chat-message .file-name {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-message .file-size { font-size: 11px; color: var(--text-muted); }
.chat-message .file-progress {
  height: 3px;
  background: var(--bg-elev-2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.chat-message .file-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s linear;
}
.chat-message .file-download {
  background: var(--accent);
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}
.chat-message .file-download:hover { background: var(--accent-hover); }

/* Chat composer (recipient + form) */
.chat-composer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.chat-to-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.chat-to-row select {
  flex: 1;
  font-size: 12px;
  padding: 4px 6px;
  background: var(--bg-elev-2);
  color: var(--text);
}
#form-chat {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 0;
}
#form-chat input[name="text"] { flex: 1; }
.chat-attach-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.chat-attach-btn:hover { background: var(--bg-elev-2); color: var(--text); }

/* ----- Controls ----- */
.controls {
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  display: flex;
  justify-content: center;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.controls .divider {
  width: 1px;
  height: 32px;
  background: var(--border);
  margin: 0 4px;
}
.control-btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 64px;
  font-family: inherit;
  transition: background 0.1s;
}
.control-btn:hover { background: var(--bg-elev-3); }
.control-btn.active { background: var(--accent); border-color: var(--accent); color: white; }
.control-btn.off {
  background: rgba(226, 75, 74, 0.12);
  border-color: rgba(226, 75, 74, 0.45);
  color: var(--text);
}
.control-btn.off:hover { background: rgba(226, 75, 74, 0.22); }
.control-btn.off .label { color: var(--danger); font-weight: 500; }

/* Unread badge on sidebar button */
.unread-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  background: var(--danger);
  color: white;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.control-btn { position: relative; }

/* File send status pill below progress bar */
.chat-message .file-status {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 500;
}
.chat-message .file-status.sent { color: var(--success); }
.chat-message .file-status.failed { color: var(--danger); }

/* Drag-drop overlay over chat panel */
.chat-drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(25, 118, 255, 0.16);
  border: 2px dashed var(--accent);
  border-radius: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
}
.chat-drop-overlay.visible { display: flex; }
#panel-chat { position: relative; }

/* Audio meter (bars next to mic icon on local tile) */
.audio-meter {
  position: absolute;
  bottom: 6px;
  right: 6px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
  padding: 2px 4px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
}
.audio-meter span {
  width: 2px;
  background: var(--success);
  border-radius: 1px;
  transition: height 0.06s linear;
  height: 2px;
}

/* Virtual background option grid */
.vbg-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.vbg-option {
  background: var(--bg-elev-2);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: var(--text);
  font-family: inherit;
}
.vbg-option:hover { border-color: var(--border-strong); }
.vbg-option.active { border-color: var(--accent); }
.vbg-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  background: var(--bg-elev-3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.vbg-thumb-none { color: var(--danger); }
.vbg-thumb-blur {
  background: linear-gradient(135deg, #6a8caf 0%, #c4b5a0 100%);
  filter: blur(3px);
}

/* Recordings list table */
.rec-row {
  display: grid;
  grid-template-columns: 1fr 110px 80px 130px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
}
.rec-row .rec-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rec-row .rec-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
}
.rec-row .rec-status.complete { background: rgba(29, 158, 117, 0.15); color: var(--success); }
.rec-row .rec-status.active, .rec-row .rec-status.starting { background: rgba(242, 166, 35, 0.18); color: var(--warning); }
.rec-row .rec-status.failed { background: rgba(226, 75, 74, 0.18); color: var(--danger); }
.rec-row .rec-meta { color: var(--text-muted); font-size: 11px; }
.rec-row .rec-actions { display: flex; gap: 6px; justify-content: flex-end; }
.rec-row .rec-download {
  background: var(--accent);
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 11px;
  text-decoration: none;
  font-weight: 500;
}
.rec-row .rec-download:hover { background: var(--accent-hover); }
.rec-row .rec-delete {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}
.rec-row .rec-delete:hover { background: var(--danger); color: white; border-color: var(--danger); }

@media (max-width: 640px) {
  .rec-row { grid-template-columns: 1fr; }
  .rec-row .rec-actions { justify-content: flex-start; }
}
.control-btn.danger { background: var(--danger); border-color: var(--danger); color: white; }
.control-btn.danger:hover { background: #c43d3c; }
.control-btn .icon { font-size: 16px; line-height: 1.2; }
.control-btn .label { font-size: 10px; line-height: 1.2; }

/* ============== Modals ============== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 520px;
  width: 90%;
  max-height: 86vh;
  overflow-y: auto;
}
.modal h2 {
  margin-bottom: 14px;
  font-size: 16px;
  font-weight: 600;
}
.modal label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 4px;
}
.modal select, .modal input[type="text"] {
  width: 100%;
}
.modal-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.modal-row input { flex: 1; }
.modal-actions {
  margin-top: 18px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.modal-close {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--bg-elev-3); }

.info-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.info-row:last-child { border-bottom: none; }
.info-row .label { color: var(--text-muted); font-size: 12px; }
.info-row .value {
  font-family: monospace;
  word-break: keep-all;
  white-space: nowrap;
  overflow-x: auto;       /* horizontal scroll if very narrow viewport */
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
}
.info-row .value::-webkit-scrollbar { height: 2px; }
.info-copyable {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}
.info-copy-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.info-copy-btn:hover { background: var(--bg-elev-3); color: var(--text); }

/* ============== Toast ============== */
#toast-container {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}
.toast {
  background: var(--bg-elev-3);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  animation: toast-in 0.2s ease-out, toast-out 0.3s ease-in 2.7s forwards;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-10px); }
}

/* ============== Settings ============== */
.settings-main {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}
.settings-nav {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
}
.settings-nav-item:hover { background: var(--bg-elev-2); }
.settings-nav-item.active { background: var(--bg-elev-3); color: var(--text); }
.settings-nav-icon { font-size: 16px; width: 20px; text-align: center; }

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  max-width: 720px;
}
.settings-section { display: none; }
.settings-section.active { display: block; }
.settings-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row label {
  flex-shrink: 0;
  width: 140px;
  color: var(--text-muted);
  font-size: 13px;
}
.settings-row select,
.settings-row .settings-value {
  flex: 1;
  font-size: 14px;
}
.settings-row .settings-value { color: var(--text); }
.settings-hint {
  color: var(--text-dim);
  font-size: 12px;
  margin: 8px 0 16px;
}
.settings-status {
  font-size: 12px;
  margin-top: 8px;
}
.settings-status.success { color: var(--success); }
.settings-status.error { color: var(--danger); }

.settings-row-toggle { justify-content: space-between; }
.settings-row-toggle label:first-child {
  flex: 1;
  width: auto;
  color: var(--text);
  font-size: 14px;
}
.settings-row-radio {
  border-bottom: none;
  padding: 4px 0;
}
.settings-row-radio label {
  width: auto;
  flex: 0 0 auto;
  color: var(--text);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.settings-row-radio input[type="radio"] { accent-color: var(--accent); }

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--bg-elev-3);
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.15s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch input:checked + .slider {
  background: var(--accent);
}
.switch input:checked + .slider::before {
  transform: translateX(18px);
}

/* Icon button (gear) */
.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--bg-elev-2); color: var(--text); }

/* Recording indicator badge in topbar */
.recording-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(226, 75, 74, 0.18);
  color: var(--danger);
  border: 1px solid rgba(226, 75, 74, 0.4);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}
.rec-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: rec-pulse 1.5s infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Recordings list inside info modal */
.recordings-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.recording-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border-radius: 6px;
  font-size: 12px;
  gap: 8px;
}
.recording-row .rec-meta { color: var(--text-muted); font-size: 11px; }

/* Mobile adjustments */
@media (max-width: 640px) {
  .settings-main { flex-direction: column; }
  .settings-nav {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding: 8px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .settings-nav-item {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 13px;
  }
  .settings-nav-item span:not(.settings-nav-icon) { display: none; }
  .settings-content { padding: 16px; }
  .settings-row { flex-wrap: wrap; }
  .settings-row label { width: 100%; }
}

/* ============== Diagnostics ============== */
.diag-main {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  justify-content: center;
}
.diag-card {
  max-width: 640px;
  width: 100%;
}
.diag-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}
.diag-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.diag-item {
  background: var(--bg-elev-2);
  border-radius: 6px;
  padding: 12px 14px;
}
.diag-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.diag-name { font-weight: 500; }
.diag-status {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.diag-status.pending {
  background: rgba(154, 160, 170, 0.15);
  color: var(--text-muted);
}
.diag-status.pass {
  background: rgba(29, 158, 117, 0.18);
  color: var(--success);
}
.diag-status.fail {
  background: rgba(226, 75, 74, 0.18);
  color: var(--danger);
}
.diag-status.warn {
  background: rgba(242, 166, 35, 0.18);
  color: var(--warning);
}
.diag-status.skipped {
  background: rgba(154, 160, 170, 0.1);
  color: var(--text-dim);
}
.diag-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  font-family: monospace;
  word-break: break-all;
}
.diag-summary {
  background: var(--bg-elev-2);
  padding: 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  border-left: 3px solid var(--accent);
}
.diag-summary.pass { border-left-color: var(--success); }
.diag-summary.fail { border-left-color: var(--danger); }
.diag-actions {
  display: flex;
  justify-content: center;
}

/* Auth footer */
.auth-footer {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  gap: 12px;
  font-size: 12px;
}

/* Sidebar close button (mobile) */
.sidebar-close {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  z-index: 1;
}
.sidebar-close:hover { background: var(--bg-elev-2); color: var(--text); }

/* ============== Mobile responsive ============== */

/* Tablets: sidebar slightly narrower */
@media (max-width: 900px) {
  .sidebar { width: 280px; }
  .self-pip { width: 160px; height: 90px; }
}

/* Phones: major layout shift */
@media (max-width: 640px) {
  .topbar, .room-topbar {
    padding: 8px 10px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .topbar h1, .room-topbar strong { font-size: 14px; }
  .user-info { gap: 4px; flex-wrap: wrap; }
  .user-info button { font-size: 12px; padding: 4px 6px; }
  .room-meta { font-size: 11px; gap: 6px; }
  .room-actions { gap: 4px; }
  .topbar-btn { padding: 0 8px; height: 30px; }
  .topbar-btn-label { display: none; }     /* keep icon-only on small screens */

  .lobby {
    padding: 12px;
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .card { padding: 16px; border-radius: 8px; }
  /* On phones, the auth card was rendering too narrow because flex
     centering plus min-width:auto sized it to its content, leaving
     huge gutters either side. Force it to claim almost the full
     viewport width so the form actually fills the card.
     The `min-width: 0` overrides the desktop `min-width: 380px`
     which would otherwise blow past the screen on small phones. */
  .auth-card {
    width: calc(100vw - 24px);   /* ~12px gutter each side */
    max-width: 420px;            /* desktop-look on tablets/large phones */
    min-width: 0;
    padding: 24px 18px;
    box-sizing: border-box;
  }
  /* Make sure the parent flex column doesn't add its own margin */
  #screen-auth { padding: 0 12px; }

  /* Sidebar becomes a slide-in overlay */
  .sidebar {
    position: fixed;
    top: 0; right: 0;
    width: 100%;
    max-width: 360px;
    height: 100%;
    z-index: 50;
    box-shadow: -8px 0 24px rgba(0,0,0,0.5);
    border-left: none;
    transform: translateX(0);
    transition: transform 0.2s ease-out;
  }
  .sidebar-close { display: flex; align-items: center; justify-content: center; }

  /* Self-PIP smaller and draggable position adjusts */
  .self-pip {
    width: 110px;
    height: 64px;
    bottom: 12px;
    right: 12px;
  }

  /* Controls: scale down, hide labels, more compact */
  .controls {
    padding: 6px 4px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    justify-content: flex-start;
    scrollbar-width: thin;
  }
  .controls::-webkit-scrollbar { height: 3px; }
  .controls .divider { display: none; }
  .control-btn {
    min-width: 44px;
    padding: 6px 6px;
    flex-shrink: 0;
  }
  .control-btn .label { display: none; }
  .control-btn .icon { font-size: 18px; }

  /* Gallery: portrait-aware tile sizing.
     The native CSS Grid behaviour is to make square-ish cells; in portrait
     a 16:9 video tile inside a 2-column grid ends up tiny and centered.
     We unset aspect-ratio on small screens and let tiles fill row height
     so 4 people in portrait look like a 2x2 of half-screen tiles. */
  .gallery { padding: 6px; gap: 4px; align-content: stretch; }
  .gallery .video-tile { aspect-ratio: auto; min-height: 0; }

  .speaker-view { padding: 6px; gap: 6px; }
  .thumb-strip { height: 70px; }
  .thumb-strip .video-tile { width: 110px; height: 65px; }

  /* Schedule badge wraps to next line */
  .room-list .room-actions { flex-direction: row; }
  .room-list li { flex-wrap: wrap; }

  /* Modals fill the screen */
  .modal { width: 96%; padding: 18px; max-height: 92vh; }
  .modal h2 { font-size: 15px; }

  /* Chat input bigger touch target */
  #form-chat input { padding: 12px; font-size: 16px; /* prevents iOS zoom */ }

  /* Diagnostics */
  .diag-main { padding: 12px; }
  .diag-card { padding: 18px; }
  .diag-row { flex-wrap: wrap; }

  /* Waiting room compact */
  .waiting-card { padding: 32px 20px; }
  .waiting-icon { font-size: 44px; }
  .waiting-card h2 { font-size: 18px; }
  .waiting-countdown { font-size: 30px; }

  /* Host banner: stack vertically on narrow screens */
  .host-banner {
    flex-wrap: wrap;
    padding: 8px 12px;
    font-size: 12px;
    gap: 6px;
  }
  .host-banner-action { padding: 5px 10px; font-size: 12px; }
}

/* Portrait phones especially: arrange video grid to fill viewport */
@media (max-width: 640px) and (orientation: portrait) {
  .stage { display: flex; flex-direction: column; min-height: 0; }

  /* Reset our default aspect-ratio for portrait — let cells fill the
     available stage height equally. The video element inside uses
     object-fit: cover so it crops cleanly to whatever shape the cell has. */
  .gallery {
    flex: 1;
    display: grid;
    /* Default: 2 columns, rows determined by participant count */
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    /* Force the grid to fill the stage exactly — no overflow scroll */
    overflow: hidden;
    /* IMPORTANT: rows distribute equally across the full stage height */
    grid-auto-rows: 1fr;
  }
  .gallery .video-tile {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;     /* override our 16:9 default */
    min-height: 0;
    min-width: 0;
  }
  /* On mobile, preserve the camera's native aspect ratio so the user
     doesn't see a cropped face. The tile may have black bars top/bottom
     or left/right depending on camera orientation — that's intentional. */
  .gallery .video-tile video,
  .speaker-main video {
    object-fit: contain;
    background: #000;
  }

  /* 1 participant — full screen */
  .gallery:has(> .video-tile:nth-child(1):last-child) {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }
  /* 2 participants — stacked vertically (each gets full width, half height) */
  .gallery:has(> .video-tile:nth-child(2):last-child) {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  /* 3 participants — 2 on top, 1 on bottom (centered via implicit auto rows) */
  .gallery:has(> .video-tile:nth-child(3):last-child) {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
  }
  /* 4 participants — perfect 2x2 (this is the user's case) */
  .gallery:has(> .video-tile:nth-child(4):last-child) {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
  }
  /* 5-6 — 2 columns, 3 rows */
  .gallery:has(> .video-tile:nth-child(5)) {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
  }
  /* 7-9 — 3 columns, 3 rows */
  .gallery:has(> .video-tile:nth-child(7)) {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .control-btn { min-width: 40px; padding: 6px 4px; }
  .self-pip { width: 90px; height: 54px; }
  /* Squeeze the auth card a bit more — viewport is < 380px, so the
     12px gutters from the 640px breakpoint still leave too little. */
  .auth-card {
    width: calc(100vw - 16px);
    padding: 18px 14px;
  }
  #screen-auth { padding: 0 8px; }
}

/* ============== Waiting room ============== */
.waiting-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.waiting-card {
  max-width: 480px;
  width: 100%;
  text-align: center;
  padding: 48px 40px;
}
.waiting-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.85;
}
.waiting-card h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 18px;
  color: var(--text);
}
.waiting-info {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 18px;
}
.waiting-time {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.waiting-countdown {
  font-size: 38px;
  font-weight: 600;
  color: var(--accent);
  margin: 6px 0 18px;
  font-variant-numeric: tabular-nums;
}
.waiting-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 24px;
}
.waiting-actions {
  display: flex;
  justify-content: center;
}

/* ============== Host preview banner ============== */
.host-banner {
  background: linear-gradient(90deg, rgba(242, 166, 35, 0.18), rgba(242, 166, 35, 0.05));
  border-bottom: 1px solid rgba(242, 166, 35, 0.4);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text);
  flex-shrink: 0;
}
.host-banner-icon {
  font-size: 18px;
}
.host-banner-text {
  flex: 1;
}
.host-banner-text strong {
  color: var(--warning);
  font-weight: 600;
}
.host-banner-action {
  background: var(--warning);
  color: #1f1300;
  border: none;
  padding: 6px 14px;
  border-radius: 5px;
  font-weight: 600;
  font-size: 13px;
}
.host-banner-action:hover { background: #ffb733; }

/* Waiter count badge in lobby */
.waiter-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  margin-top: 4px;
  margin-left: 6px;
  background: rgba(242, 166, 35, 0.18);
  color: var(--warning);
  border: 1px solid rgba(242, 166, 35, 0.4);
  cursor: pointer;
}
.waiter-badge:hover { background: rgba(242, 166, 35, 0.3); }

/* Waiter list inside modal */
.waiter-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  margin: 12px 0;
}
.waiter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  border-radius: 6px;
  font-size: 13px;
}
.waiter-row .waiter-info { display: flex; align-items: center; gap: 10px; }
.waiter-row .waiter-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
}
.waiter-row .waiter-time { color: var(--text-muted); font-size: 11px; margin-left: 4px; }
.waiter-row .btn-admit {
  background: var(--success);
  color: white;
  border: none;
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}
.waiter-row .btn-admit:hover { background: #259070; }

.waiter-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 30px 0;
}

/* ============== Whiteboard ============== */
.whiteboard {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(15, 17, 21, 0.92);
  display: flex;
  flex-direction: column;
}
.whiteboard.mode-fullscreen {
  background: #ffffff;
}
.whiteboard.mode-fullscreen canvas {
  background: #ffffff;
}
.whiteboard canvas {
  flex: 1;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  display: block;
}
.wb-toolbar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.wb-title {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.wb-spacer {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}
.wb-tool {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s;
}
.wb-tool:hover { transform: scale(1.1); }
.wb-tool.active { border-color: var(--text); }
.wb-action {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 12px;
  border-radius: 5px;
  font-size: 12px;
}
.wb-action:hover { background: var(--bg-elev-3); }
.wb-action.danger {
  background: rgba(226, 75, 74, 0.15);
  border-color: rgba(226, 75, 74, 0.45);
  color: var(--danger);
}
.wb-action.danger:hover { background: var(--danger); color: white; }

/* ============== Host indicator + context menu ============== */
.host-badge {
  display: inline-block;
  background: var(--accent);
  color: white;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  font-weight: 500;
  vertical-align: middle;
}
.host-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  margin-left: 6px;
}
.host-action-btn:hover { background: var(--bg-elev-3); color: var(--text); }

.context-menu {
  position: fixed;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 4px;
  z-index: 1500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  min-width: 140px;
}
.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
}
.context-menu button:hover { background: var(--bg-elev-2); }
.context-menu button.danger { color: var(--danger); }
.context-menu button.danger:hover { background: var(--danger); color: white; }

/* Section label inside context menus */
.context-menu .ctx-section-label {
  font-size: 11px;
  color: var(--text-dim);
  padding: 6px 12px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.context-menu .ctx-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.context-menu .ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}
.context-menu .ctx-item:hover { background: var(--bg-elev-2); }
.context-menu .ctx-item.selected { background: rgba(25, 118, 255, 0.15); color: var(--accent); }
.context-menu .ctx-item.selected::after { content: '✓'; margin-left: auto; }
.context-menu .ctx-icon {
  width: 18px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}
.context-menu .ctx-item.selected .ctx-icon { color: var(--accent); }

/* Layout menu specifically — bottom-anchored above the layout button */
.layout-menu {
  min-width: 200px;
}

/* Gallery pager */
.gallery-pager {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  z-index: 8;
}
.gallery-pager .pager-btn {
  background: transparent;
  border: none;
  color: var(--text);
  width: 26px;
  height: 26px;
  border-radius: 13px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.gallery-pager .pager-btn:hover { background: var(--bg-elev-3); }
.gallery-pager .pager-label {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  min-width: 36px;
  text-align: center;
}

/* ============================================================
 * MEDIA PLAYBACK (Phase 10)
 * ============================================================ */

/* Picker overlay — sits on top of the meeting UI when host browses
 * the lecture library. */
.media-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
}
.media-picker {
  background: var(--bg-elev-2);
  border-radius: 12px;
  width: min(720px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.media-picker-head {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.media-picker-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.media-picker-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.media-picker-item {
  background: var(--bg-elev-1);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 0;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s;
  color: inherit;
}
.media-picker-item:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.media-picker-item img,
.media-picker-thumb-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: linear-gradient(135deg, #1a3a6e 0%, #0c2447 100%);
}
.media-picker-meta {
  padding: 8px 10px 10px;
}
.media-picker-title {
  font-weight: 500;
  font-size: 13px;
  line-height: 1.3;
  margin-bottom: 2px;
  /* Clamp to 2 lines so cards don't get jagged heights */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Lecture-video stage. When a meeting has an active media playback this
 * overlay sits over the gallery. The host's camera floats in the corner
 * as PIP (or vice versa, when state.focus === 'pip'). */
.media-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  z-index: 100;
}
.media-stage video.media-main {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.media-stage .media-pip {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: clamp(140px, 18vw, 240px);
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elev-2);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.15);
}
.media-stage .media-pip video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Host-only control bar */
.media-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  background: rgba(0, 0, 0, 0.6);
  padding: 8px 12px;
  border-radius: 30px;
  backdrop-filter: blur(8px);
  z-index: 110;
}
.media-controls button {
  background: transparent;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.media-controls button:hover { background: rgba(255, 255, 255, 0.12); }
.media-controls .media-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  color: white;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 240px;
}
.media-controls input[type=range] {
  flex: 1;
  accent-color: var(--accent);
}

/* ============================================================
 * LECTURE-VIDEO PLAYBACK (Phase 10)
 * ============================================================ */

/* Content tile in the speaker-view main area when a lecture video is
 * playing. Same backdrop as screenshare; we just swap the source. */
.content-tile {
  background: #000;
  position: relative;
}
.content-tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.content-tile .content-pip-corner {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: clamp(140px, 18vw, 240px);
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elev-2);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.18);
}
.content-tile .content-pip-corner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Floating host control panel — pause/seek/mode/stop */
.content-host-panel {
  position: fixed;
  left: 50%;
  bottom: 96px;        /* above the main toolbar */
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 20, 30, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px 14px;
  border-radius: 28px;
  z-index: 1100;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  color: #e6ecf5;
}
.cp-btn {
  background: transparent;
  border: none;
  color: #e6ecf5;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
  font-size: 18px;
  padding: 0;
}
.cp-btn:hover  { background: rgba(255, 255, 255, 0.10); }
.cp-btn.active { background: rgba(70, 130, 220, 0.30); color: #cfe1ff; }
.cp-btn.cp-stop { color: #ff8a8a; }
.cp-btn.cp-stop:hover { background: rgba(255, 80, 80, 0.18); }
.cp-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 280px;
}
.cp-progress input[type=range] {
  flex: 1;
  accent-color: #4682dc;
  /* Hide the default thumb shadow that defaults look bad on dark bg */
  height: 4px;
  cursor: pointer;
}
.cp-time {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: rgba(230, 236, 245, 0.75);
  min-width: 36px;
  text-align: center;
}
.cp-mode-toggle {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 20px;
  padding: 2px;
}

/* Picker modal — content list grid */
.content-picker-overlay { z-index: 5000; }
.content-picker-modal {
  width: min(720px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.content-picker-head {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.content-picker-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 500;
}
.content-picker-head .btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted, #aab);
  font-size: 24px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.content-picker-body {
  padding: 16px 18px;
  overflow-y: auto;
}
.content-picker-loading {
  text-align: center;
  color: var(--text-muted, #aab);
  padding: 40px 0;
}
.content-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.content-picker-card {
  background: var(--bg-elev-1, rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 0;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s;
  color: inherit;
  font: inherit;
}
.content-picker-card:hover {
  border-color: #4682dc;
  transform: translateY(-2px);
}
.content-picker-card img,
.content-picker-card .content-picker-thumb-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: linear-gradient(135deg, #1a3a6e 0%, #0c2447 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.4);
  font-size: 28px;
}
.content-picker-card-body {
  padding: 8px 10px 10px;
}
.content-picker-card-title {
  font-weight: 500;
  font-size: 13px;
  line-height: 1.3;
  margin-bottom: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.content-picker-card-meta {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
}
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted, #aab);
}

/* ============================================================
 * MODE SELECTOR + PREFETCH UI (Phase 10b)
 * ============================================================ */
.content-mode-modal {
  width: min(560px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.mode-summary {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.mode-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mode-option {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px;
  background: var(--bg-elev-1, rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: border-color 0.12s, transform 0.12s;
}
.mode-option:hover {
  border-color: #4682dc;
  transform: translateY(-1px);
}
.mode-icon {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}
.mode-text { flex: 1; }
.mode-title {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 4px;
}
.mode-desc {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.65);
  line-height: 1.4;
}
.mode-cache-status {
  margin-top: 6px;
  font-size: 11px;
}

/* Prefetch banner — appears for viewers when host requests a download */
.prefetch-banner {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 320px;
  background: rgba(15, 20, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 10px;
  padding: 14px 16px;
  z-index: 6000;
  font-size: 13px;
  color: #e6ecf5;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.prefetch-title {
  font-weight: 500;
  margin-bottom: 8px;
  font-size: 13px;
}
.prefetch-progress {
  height: 4px;
  background: rgba(255, 255, 255, 0.10);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}
.prefetch-bar {
  height: 100%;
  background: #4682dc;
  width: 0;
  transition: width 0.2s;
}
.prefetch-percent {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.65);
  text-align: right;
}

/* Spinner used by 'preparing' placeholder */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: #4682dc;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
 * PREFETCH WAITING ROOM (Phase 10c — host-side)
 * ============================================================ */
.prefetch-waiting-room {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, 92vw);
  background: rgba(15, 20, 30, 0.96);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 12px;
  padding: 22px 24px;
  z-index: 6500;
  color: #e6ecf5;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}
.pwr-title {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}
.pwr-subtitle {
  font-size: 13px;
  color: rgba(230, 236, 245, 0.65);
  margin-bottom: 16px;
}
.pwr-progress {
  height: 6px;
  background: rgba(255, 255, 255, 0.10);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}
.pwr-bar {
  height: 100%;
  background: linear-gradient(90deg, #4682dc, #6aa6ff);
  width: 0;
  transition: width 0.3s;
}
.pwr-counts {
  font-size: 12px;
  color: rgba(230, 236, 245, 0.70);
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
}
.pwr-failed { color: #ff8a8a; }
.pwr-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Viewer-side progress display */
.content-host-panel.viewer-only {
  /* Read-only mini panel — narrower, no controls */
  padding: 6px 12px;
}
.cp-mode-badge {
  font-size: 16px;
  margin-right: 6px;
  opacity: 0.85;
}
.cp-status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-right: 6px;
  color: rgba(230, 236, 245, 0.85);
}
.cp-progress-readonly {
  min-width: 240px;
}
.cp-progress-bar {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  overflow: hidden;
}
.cp-progress-fill {
  height: 100%;
  background: #4682dc;
  width: 0;
  transition: width 0.5s linear;
}

/* Play-mode switcher in the host control panel */
.cp-playmode-toggle {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 20px;
  padding: 2px;
  gap: 2px;
}
.cp-playmode-toggle .cp-btn {
  font-size: 14px;
  width: 30px;
  height: 30px;
}

/* ============================================================
 * UTILITY CLASSES (Phase 12 — strict CSP migration)
 * ============================================================
 * These replace inline style="..." attributes so the page can run
 * under script-src + style-src strict CSP without 'unsafe-inline'
 * on either. Where a value is genuinely dynamic (a percentage that
 * changes per frame, a user-picked color), the code now uses
 * element.style.* JS calls — those are CSP-compatible because
 * they're not inline-attribute injections.
 */
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.mt-18 { margin-top: 18px; }
.mt-24 { margin-top: 24px; }
.mt-32 { margin-top: 32px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.flex-1 { flex: 1; }
.flex-1-min0 { flex: 1; min-width: 0; }
.flex-1-min0-mono { flex: 1; min-width: 0; font-family: inherit; }
.flex-1-mono { flex: 1; min-width: 24px; font-family: monospace; text-align: right; }
.flex-1-small { flex: 1; font-size: 12px; }
.maxw-380 { max-width: 380px; }
.maxw-420 { max-width: 420px; }
.maxw-480 { max-width: 480px; }
.va-middle { vertical-align: middle; }

/* Color helpers (use existing CSS variables) */
.text-warning { color: var(--warning); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted-13 { color: var(--text-muted); font-size: 13px; }
.text-muted-12 { color: var(--text-muted); font-size: 12px; }
.text-muted-block { color: var(--text-muted); font-size: 13px;
                    text-align: center; padding: 30px 0; }
.text-danger-block { color: var(--danger); font-size: 13px;
                    text-align: center; padding: 30px 0; }
.muted-mt6 { color: var(--text-muted); margin-top: 6px; }

.indent-muted { padding-left: 20px; color: var(--text-muted); }
.note-muted    { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.note-pre      { font-size: 14px; color: var(--text-muted); margin-bottom: 16px;
                 white-space: pre-line; }
.note-tiny     { font-size: 12px; color: var(--text-muted); margin-top: 14px; }
.note-13       { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }

.code-block {
  font-size: 12px; font-family: monospace;
  background: var(--bg-elev-2); padding: 10px;
  border-radius: 6px; margin-bottom: 12px;
  max-height: 120px; overflow: auto;
}

/* Diagnostics page — preview thumbnails */
.diag-thumb {
  width: 100%; background: #000; border-radius: 6px;
  aspect-ratio: 16 / 9;
}

/* Sky gradient backgrounds for the lobby orb glow */
.bg-sky-warm  { background: linear-gradient(180deg, #7ec8e3 0%, #f4d35e 60%, #ee964b 100%); }
.bg-sky-cool  { background: linear-gradient(180deg, #3a4a5e 0%, #6a7a8e 100%); }
.bg-brand     { background: linear-gradient(135deg, #1976ff 0%, #7f77dd 100%); }
.bg-white     { background: #ffffff; }
.bg-amber     { background: #f2a623; }
.bg-red       { background: #e24b4a; }
.bg-green     { background: #1d9e75; }
.bg-blue      { background: #1976ff; }

/* Layout helpers */
.center-stack {
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
}

/* Progress fill width is set via element.style.width — base style here */
.progress-fill { transition: width 0.3s; }
.text-13 { font-size: 13px; }

/* Virtual-bg custom thumbnail with user-uploaded image */
.vbg-thumb-cover {
  background-size: cover;
  background-position: center;
}

/* ============================================================
 * AUTH-SCREEN LANGUAGE PICKER (Phase 13)
 * ============================================================
 * Dropdown showing BOTH languages with the active one marked.
 * Replaces the previous "single button that flips" UI which was
 * confusing — users couldn't tell whether 'English' was the current
 * state or the action.
 */
.lang-picker {
  position: relative;
  display: inline-block;
}
.lang-picker-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.lang-picker-current {
  font-weight: 500;
}
.lang-picker-menu {
  position: absolute;
  bottom: calc(100% + 6px);   /* opens UPWARD because picker is at bottom of card */
  left: 50%;
  transform: translateX(-50%);
  min-width: 130px;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 100;
}
.lang-picker-menu li { margin: 0; }
.lang-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
}
.lang-picker-item:hover {
  background: var(--bg-elev-3);
}
.lang-picker-check {
  width: 14px;
  display: inline-block;
  text-align: center;
  color: var(--accent);
  visibility: hidden;     /* shown only on the active item via .active */
}
.lang-picker-item.active {
  font-weight: 500;
}
.lang-picker-item.active .lang-picker-check {
  visibility: visible;
}
