:root {
  --bg: #0a0d14;
  --panel: #111623;
  --panel-2: #171e2f;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef2ff;
  --muted: #8b96b0;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --cyan: #06b6d4;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --green: #22c55e;
  --amber: #f59e0b;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
  user-select: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
}

/* Top Bar */
.topbar {
  height: 54px;
  min-height: 54px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-title {
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.channel-pill, .meta-pill, .conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}

.channel-pill {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-pill .hash {
  color: var(--cyan);
  font-weight: 700;
}

.dot-online, .conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

.conn-dot.warn { background: var(--amber); }
.conn-dot.err { background: var(--danger); }

.conn-pill {
  color: var(--muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  color: var(--text);
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-xs { padding: 4px 10px; font-size: 12px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  border-color: rgba(255, 255, 255, 0.12);
}

.btn-primary:hover { background: linear-gradient(135deg, var(--accent-hover), #4f46e5); }

.btn-danger {
  background: var(--danger);
}

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

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }
.btn-ghost.active { border-color: var(--cyan); color: var(--cyan); background: rgba(6, 182, 212, 0.12); }

.live-dot-sm {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
}

.btn-danger .live-dot-sm {
  animation: pulse 1.2s infinite;
}

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

/* Channel switch banner */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(124, 58, 237, 0.16);
  border-bottom: 1px solid rgba(124, 58, 237, 0.35);
  font-size: 12.5px;
}

.banner-actions {
  display: flex;
  gap: 8px;
}

/* Stage */
.stage-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at top, #12182b 0%, #07090f 70%);
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.empty-card {
  max-width: 440px;
  width: 100%;
  text-align: center;
  background: rgba(17, 22, 35, 0.85);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.empty-icon-wrap {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.22), rgba(6, 182, 212, 0.18));
  border: 1px solid rgba(139, 92, 246, 0.35);
  color: #c4b5fd;
}

.empty-card h2 {
  font-size: 18px;
  margin-bottom: 8px;
}

.empty-card p {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
}

.empty-actions {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* Streams Stage */
.streams-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 10px;
}

.focus-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.video-viewport {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-viewport.zoomed {
  cursor: grab;
}

.video-viewport.zoomed.dragging {
  cursor: grabbing;
}

#main-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center center;
  transition: transform 0.06s linear;
  background: #000;
}

.stage-overlay-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
  gap: 12px;
}

.streamer-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  border-radius: 10px;
  background: rgba(10, 13, 20, 0.78);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 13px;
  font-weight: 600;
}

.badge-live {
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 5px;
}

.quality-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--cyan);
}

.stats-hud {
  display: flex;
  gap: 10px;
  padding: 6px 11px;
  border-radius: 10px;
  background: rgba(10, 13, 20, 0.82);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 11.5px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  color: #cbd5e1;
}

.zoom-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.75);
  font-size: 15px;
  font-weight: 700;
  pointer-events: none;
}

.stage-controls {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(10, 13, 20, 0.82);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  opacity: 0.96;
  transition: opacity 0.2s ease;
}

.controls-left, .controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.volume-slider {
  width: 96px;
  accent-color: var(--cyan);
  cursor: pointer;
}

.volume-pct {
  font-size: 11.5px;
  color: var(--muted);
  min-width: 34px;
}

.zoom-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.zoom-label {
  min-width: 48px;
  font-size: 12px;
}

/* Stream Strip (thumbnails) */
.stream-strip {
  height: 112px;
  min-height: 112px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.stream-thumb {
  position: relative;
  width: 192px;
  min-width: 192px;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.stream-thumb.active {
  border-color: var(--cyan);
}

.stream-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.stream-thumb-label {
  position: absolute;
  left: 6px;
  bottom: 6px;
  right: 6px;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.72);
  font-size: 11.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Multi-Live Grid */
.grid-container {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 10px;
}

.grid-tile {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
}

.grid-tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.grid-tile-bar {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(10, 13, 20, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 12, 0.74);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 16px;
  margin-bottom: 4px;
}

.modal-sub {
  font-size: 12.5px;
  color: var(--muted);
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preset-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 11px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.preset-card:hover { border-color: var(--border-strong); }

.preset-card.active {
  border-color: var(--cyan);
  background: rgba(6, 182, 212, 0.12);
}

.preset-title {
  font-size: 13px;
  font-weight: 700;
}

.preset-meta {
  font-size: 11.5px;
  color: var(--muted);
}

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  cursor: pointer;
}

.toggle-row input {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.toggle-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.toggle-sub {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

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

/* Toasts */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(17, 22, 35, 0.96);
  border: 1px solid var(--border-strong);
  font-size: 12.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  max-width: 340px;
}

.toast.err { border-color: rgba(239, 68, 68, 0.5); color: #fecaca; }
.toast.ok { border-color: rgba(34, 197, 94, 0.45); color: #dcfce7; }
