:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #222;
  --surface3: #2a2a2a;
  --border: rgba(255,255,255,0.07);
  --text: #f1f1f1;
  --text-muted: #888;
  --text-dim: #555;
  --accent: #ff4444;
  --accent-soft: rgba(255,68,68,0.15);
  --live-green: #00e676;
  --blue: #3ea6ff;
  --radius: 10px;
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* TOP NAV */
.topbar {
  height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s;
}
.connection-dot.connected { background: var(--live-green); box-shadow: 0 0 6px var(--live-green); }
.connection-dot.error { background: var(--accent); }

.topbar-status {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
}

/* MAIN LAYOUT */
.layout {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* LEFT - MAIN PLAYER */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 20px 24px;
}

.main-content::-webkit-scrollbar { width: 4px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }

.player-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.player-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.player-wrap video::-webkit-media-controls { display: none !important; }
.player-wrap video::-webkit-media-controls-enclosure { display: none !important; }

canvas#noiseCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
}
.player-overlay.hidden { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.overlay-text {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  font-family: 'DM Mono', monospace;
}

/* LIVE BADGE */
.live-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
  display: none;
  align-items: center;
  gap: 5px;
  z-index: 10;
}
.live-badge.visible { display: flex; }
.live-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ROOM LABEL (current) */
.room-label-bar {
  margin-top: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.current-room-info h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
  line-height: 1.3;
  color: var(--text);
}
.current-room-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 6px;
}
.meta-chip {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: 'DM Mono', monospace;
}
.meta-chip .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--live-green);
}

/* RIGHT SIDEBAR */
.sidebar {
  width: 340px;
  min-width: 300px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.sidebar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}
.sidebar-count {
  font-size: 12px;
  background: var(--surface3);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 20px;
  font-family: 'DM Mono', monospace;
}

.refresh-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.15s;
}
.refresh-btn:hover {
  background: var(--surface3);
  color: var(--text);
  border-color: rgba(255,255,255,0.15);
}
.refresh-btn.spinning { animation: spin 0.5s linear; }

.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
}
.room-list::-webkit-scrollbar { width: 4px; }
.room-list::-webkit-scrollbar-track { background: transparent; }
.room-list::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }

/* ROOM CARD */
.room-card {
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
  position: relative;
}
.room-card:hover { background: var(--surface2); }
.room-card.active { background: var(--surface3); }
.room-card.active::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.room-thumb {
  width: 120px;
  min-width: 120px;
  aspect-ratio: 16/9;
  background: var(--surface3);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}
.room-thumb canvas {
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0.4;
}
.room-thumb .thumb-live {
  position: absolute;
  top: 4px;
  left: 4px;
  background: var(--accent);
  color: white;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  padding: 1px 5px;
  border-radius: 3px;
}
.room-thumb .thumb-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  opacity: 0.5;
}

.room-info {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}
.room-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
  letter-spacing: -0.1px;
}
.room-stats {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.8;
  font-family: 'DM Mono', monospace;
}
.room-stats span {
  display: block;
}
.stat-live {
  color: var(--live-green) !important;
  font-weight: 500;
}

.cameraman-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 7px;
  padding: 4px 9px;
  background: rgba(62, 166, 255, 0.1);
  color: var(--blue);
  border: 1px solid rgba(62, 166, 255, 0.25);
  border-radius: 5px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.cameraman-btn:hover {
  background: rgba(62, 166, 255, 0.2);
  border-color: rgba(62, 166, 255, 0.5);
}

/* EMPTY STATE */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 10px;
  color: var(--text-dim);
  text-align: center;
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 4px; }
.empty-state p { font-size: 13px; line-height: 1.5; }
.empty-state small { font-size: 11px; color: var(--text-dim); font-family: 'DM Mono', monospace; }

/* IDLE PLAYER STATE */
.idle-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: rgba(255,255,255,0.3);
  text-align: center;
}
.idle-state .idle-icon { font-size: 48px; margin-bottom: 4px; }
.idle-state p { font-size: 14px; }
.idle-state small { font-size: 11px; font-family: 'DM Mono', monospace; }

/* NO STREAM PLACEHOLDER */
#streamPlaceholder {
  position: absolute;
  inset: 0;
}

.noise-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* SWITCHING OVERLAY */
#switchingOverlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 20;
}
#switchingOverlay.visible { display: flex; }

@media (max-width: 900px) {
  .layout { flex-direction: column; height: auto; overflow: auto; }
  .sidebar { width: 100%; border-left: none; border-top: 1px solid var(--border); height: 400px; }
  .main-content { overflow: visible; }
}