:root {
  --bg: #0b0e12;
  --panel: #151a21;
  --panel-2: #1c232c;
  --line: rgba(255,255,255,0.12);
  --line-strong: rgba(255,255,255,0.2);
  --text: #f3f6f8;
  --muted: #a6b3c2;
  --accent: #2dd4bf;
  --accent-2: #f5b14c;
  --danger: #ff5d6c;
  --shadow: 0 18px 42px rgba(0,0,0,0.34);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: linear-gradient(180deg, #0b0e12 0%, #11171e 100%);
  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;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(13,17,22,0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; font-weight: 750; }
.logo { width: 28px; height: 28px; display: inline-grid; place-items: center; font-size: 19px; }
.logo-img { width: 28px; height: 28px; display: block; }
.name { letter-spacing: 0; white-space: nowrap; }
.actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; min-width: 0; }

.connection-badge {
  min-width: 104px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.connection-badge::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: currentColor;
}
.connection-badge.is-connected { color: var(--accent); border-color: rgba(45,212,191,0.45); background: rgba(45,212,191,0.1); }
.connection-badge.is-connecting,
.connection-badge.is-waiting { color: var(--accent-2); border-color: rgba(245,177,76,0.38); background: rgba(245,177,76,0.1); }
.connection-badge.is-reconnecting,
.connection-badge.is-offline { color: var(--danger); border-color: rgba(255,93,108,0.45); background: rgba(255,93,108,0.1); }

.stage { position: relative; min-height: 60vh; padding: 12px; }
.spotlight {
  position: relative;
  width: 100%;
  height: calc(100vh - 154px);
  min-height: 320px;
  background: #050607;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.spotlight video,
.tile video,
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,
.tile.self video { transform: scaleX(-1); }
video.screen-share-video,
.self video.screen-share-video,
.tile.self video.screen-share-video {
  transform: none;
  object-fit: contain !important;
  background: #000;
}

.overlays {
  position: fixed;
  right: 14px;
  bottom: 96px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}
.tile {
  position: relative;
  width: 210px;
  aspect-ratio: 16 / 9;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(0,0,0,0.32);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.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 .avatar { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: var(--panel-2); }
.tile .avatar .bubble { width: 48px; height: 48px; border-radius: 50%; background: rgba(45,212,191,0.16); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--text); }
.nameplate {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(5,6,7,0.72);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
}
.tile .hide {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: rgba(5,6,7,0.72);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
}
.tile.dragging { cursor: grabbing; opacity: 0.96; }

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

.hidden-tray {
  position: fixed;
  left: 14px;
  bottom: 96px;
  max-width: min(520px, calc(100vw - 28px));
  background: rgba(13,17,22,0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  z-index: 12;
}
.chip { background: rgba(255,255,255,0.08); border: 1px solid var(--line-strong); color: var(--text); border-radius: 999px; padding: 5px 10px; font-size: 12px; cursor: pointer; }

.video-wrap {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  min-height: 180px;
}

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

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 8px;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 10px;
  z-index: 20;
  background: rgba(13,17,22,0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 28px rgba(0,0,0,0.32);
}

button,
select {
  appearance: none;
  background: rgba(255,255,255,0.055);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  min-height: 38px;
  font-size: 14px;
  line-height: 1.2;
}
button { cursor: pointer; }
select { max-width: 230px; }
button:hover,
select:hover { border-color: var(--line-strong); background: rgba(255,255,255,0.08); }
button:active { transform: translateY(1px); }
button:disabled,
select:disabled { cursor: not-allowed; opacity: 0.45; }
button.control { border-color: rgba(45,212,191,0.42); }
button.control.active { background: rgba(45,212,191,0.14); }
button.danger { background: rgba(255,93,108,0.14); border-color: rgba(255,93,108,0.68); }
button.secondary { background: transparent; border-color: var(--line); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(420px, calc(100vw - 28px));
  background: rgba(13,17,22,0.96);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 40;
  text-align: center;
}
.toast.show { opacity: 1; }

@media (max-width: 900px) {
  .spotlight { height: calc(100vh - 210px); }
  .tile { width: 164px; }
  .overlays { right: 10px; bottom: 112px; }
  .hidden-tray { left: 10px; bottom: 112px; }
}

@media (max-width: 640px) {
  .topbar { align-items: flex-start; padding: 10px; }
  .actions { gap: 6px; }
  .connection-badge { order: -1; min-width: 96px; padding: 7px 9px; }
  .stage { padding: 8px; }
  .spotlight { height: calc(100vh - 244px); min-height: 280px; }
  .overlays {
    left: 8px;
    right: 8px;
    bottom: 116px;
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .tile { width: 150px; flex: 0 0 auto; }
  .controls { width: calc(100vw - 16px); bottom: 8px; }
  .controls button { flex: 1 1 30%; min-width: 0; padding-inline: 8px; }
  select { max-width: 154px; }
}
