:root {
  --bg: #0f1218;
  --panel: #141a22;
  --text: #e9eef7;
  --muted: #9fb0c8;
  --accent: #6aa9ff;
  --accent-2: #8a6aff;
  --danger: #ff5d6c;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 80% -10%, rgba(106,169,255,0.25), transparent 60%),
              radial-gradient(1000px 700px at -10% 120%, rgba(138,106,255,0.28), transparent 60%),
              var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(20,26,34,0.75);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.logo { font-size: 20px; }
.name { letter-spacing: .4px; }
.actions { display: flex; gap: 8px; align-items: center; }

.stage { position: relative; min-height: 60vh; padding: 12px; }
.spotlight { position: relative; width: 100%; height: calc(100vh - 170px); background: var(--panel); border: 1px solid rgba(255,255,255,0.06); border-radius: 16px; overflow: hidden; }
.spotlight video { width: 100%; height: 100%; object-fit: cover; background: #000; display: block; }
.overlays { position: fixed; right: 12px; bottom: 96px; display: flex; flex-direction: column; gap: 10px; z-index: 10; }
.tile { position: relative; width: 200px; height: 120px; background: var(--panel); border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; overflow: hidden; box-shadow: 0 6px 20px rgba(0,0,0,0.25); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; display: block; }
.tile-annotation-layer { position: absolute; inset: 0; pointer-events: none; z-index: 3; opacity: 0; transition: opacity 0.15s ease; }
.tile-annotation-layer.active { opacity: 1; }
.tile-annotation-layer canvas { width: 100%; height: 100%; }
.tile.self video { transform: scaleX(-1); }
.tile .avatar { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02)); }
.tile .avatar .bubble { width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,0.15); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--text); }
.nameplate { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,0.5); border-radius: 8px; padding: 3px 8px; font-size: 12px; color: var(--muted); }
.tile .hide { position: absolute; right: 6px; top: 6px; background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.2); color: var(--text); font-size: 12px; border-radius: 6px; padding: 2px 6px; cursor: pointer; }
.tile.dragging { cursor: grabbing; opacity: 0.95; }

.status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.45); padding: 8px 12px; border-radius: 10px; font-size: 13px; color: var(--text); display: none; align-items: center; gap: 8px; }
.status.show { display: inline-flex; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hidden-tray { position: fixed; left: 12px; bottom: 96px; background: rgba(20,26,34,0.9); border: 1px solid rgba(255,255,255,0.12); border-radius: 12px; padding: 8px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 12; max-width: 50vw; }
.chip { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.18); color: var(--text); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; }

.video-wrap {
  position: relative;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  overflow: hidden;
  min-height: 180px;
}

video { width: 100%; height: 100%; object-fit: cover; background: #000; display: block; }
.fit-cover { object-fit: cover !important; }
.fit-contain { object-fit: contain !important; background: #000; }
.self video { transform: scaleX(-1); }

.nameplate { position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,0.45); border-radius: 8px; padding: 4px 8px; font-size: 12px; color: var(--muted); }

.badge {
  position: absolute; left: 10px; top: 10px;
  background: rgba(0,0,0,0.5);
  padding: 4px 8px; border-radius: 8px;
  font-size: 12px; color: var(--muted);
}

.controls {
  display: flex; gap: 10px; align-items: center; justify-content: center;
  padding: 10px 12px calc(16px + env(safe-area-inset-bottom));
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 8px; z-index: 20;
  background: rgba(20,26,34,0.6);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  backdrop-filter: blur(8px);
}

button, select {
  appearance: none;
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
}

button.control { border-color: rgba(106,169,255,0.45); }
button.danger { background: linear-gradient(180deg, rgba(255,93,108,0.3), rgba(255,93,108,0.15)); border-color: rgba(255,93,108,0.75); }
button.secondary { background: transparent; border-color: rgba(255,255,255,0.18); }

button:active { transform: translateY(1px); }

.toast {
  position: fixed;
  left: 50%; bottom: 16px; transform: translateX(-50%);
  background: rgba(20,26,34,0.9);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.toast.show { opacity: 1; }

@media (max-width: 900px) {
  .spotlight { height: calc(100vh - 210px); }
  .tile { width: 150px; height: 100px; }
}
