/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #05070d;
  --panel: rgba(9, 14, 26, 0.72);
  --surface: rgba(148, 163, 184, 0.08);
  --surface-hover: rgba(34, 211, 238, 0.14);
  --border: rgba(148, 163, 184, 0.18);
  --border-strong: rgba(34, 211, 238, 0.38);
  --text: #f4f7fb;
  --text-secondary: #91a0b5;
  --primary: #22d3ee;
  --primary-hover: #67e8f9;
  --accent: #a3e635;
  --danger: #ff3b5c;
  --danger-hover: #ff5f7b;
  --success: #39ff88;
  --radius: 10px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background:
    linear-gradient(135deg, rgba(34, 211, 238, 0.08) 0%, transparent 28%),
    linear-gradient(225deg, rgba(163, 230, 53, 0.06) 0%, transparent 24%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(34, 211, 238, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, 0.08) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), transparent 82%);
  pointer-events: none;
  z-index: 0;
}

/* ===== Landing ===== */
#landing {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  position: relative;
  z-index: 1;
}

.landing-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(34, 211, 238, 0.14), transparent 42%),
    linear-gradient(240deg, rgba(163, 230, 53, 0.1), transparent 36%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 80px);
  pointer-events: none;
}

.landing-card {
  position: relative;
  width: 400px;
  max-width: 90vw;
  padding: 40px 36px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.86), rgba(3, 7, 18, 0.76));
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: fadeUp 0.5s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--primary);
  text-shadow: 0 0 24px rgba(34, 211, 238, 0.34);
}

.logo svg { width: 36px; height: 36px; }

.logo h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.subtitle { font-size: 14px; color: var(--text-secondary); margin-top: -8px; }

.input-group { width: 100%; }

.input-group input,
.join-row input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(2, 6, 23, 0.62);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border var(--transition);
}

.input-group input:focus,
.join-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}

.input-group input::placeholder,
.join-row input::placeholder { color: var(--text-secondary); }

.btn-primary {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, #06b6d4, #2563eb);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--transition), transform var(--transition);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #22d3ee, #3b82f6);
  box-shadow: 0 12px 34px rgba(34, 211, 238, 0.2);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary svg { width: 18px; height: 18px; }
.btn-primary:disabled,
.join-row button:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 13px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row { display: flex; gap: 8px; width: 100%; }
.join-row input { flex: 1; }

.join-row button {
  padding: 12px 20px;
  background: rgba(15, 23, 42, 0.74);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}

.join-row button:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.join-row button:disabled:hover { background: rgba(255, 255, 255, 0.08); }

/* ===== Room ===== */
#room {
  display: flex;
  flex-direction: column;
  height: 100%;
  background:
    linear-gradient(180deg, rgba(8, 13, 28, 0.72), rgba(2, 6, 23, 0.98)),
  var(--bg);
  position: relative;
  z-index: 1;
}

#room.hidden,
#landing.hidden { display: none; }

/* ----- Join notification bar ----- */
#join-notice {
  position: fixed;
  top: 0; left: 50%;
  transform: translateX(-50%);
  padding: 8px 20px;
  background: rgba(34, 211, 238, 0.92);
  color: #06111f;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 10px 34px rgba(34, 211, 238, 0.22);
  z-index: 200;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
}

.join-notice-hidden {
  transform: translateX(-50%) translateY(-100%) !important;
  opacity: 0;
}

/* ----- Header ----- */
#room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(3, 7, 18, 0.72);
  border-bottom: 1px solid rgba(34, 211, 238, 0.16);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  flex-shrink: 0;
  z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 10px; }

.room-label { font-size: 13px; color: var(--text-secondary); }

#room-id-label {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--primary);
  text-shadow: 0 0 18px rgba(34, 211, 238, 0.38);
  font-family: "SF Mono", "Fira Code", monospace;
}

.btn-ghost {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all var(--transition);
}

.btn-ghost:hover {
  color: var(--primary);
  border-color: var(--border-strong);
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.14);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 14px rgba(57, 255, 136, 0.72);
  animation: pulse 2s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* ----- Main Stage ----- */
#main-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 0;
  position: relative;
}

#main-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
  background: #020617;
  border: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow: inset 0 0 0 1px rgba(34, 211, 238, 0.06), 0 24px 80px rgba(0, 0, 0, 0.36);
}

#main-stage .stage-label {
  position: absolute;
  bottom: 24px;
  left: 24px;
  padding: 6px 14px;
  background: rgba(3, 7, 18, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(34, 211, 238, 0.2);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  pointer-events: none;
}

#main-stage .stage-unpin {
  position: absolute;
  top: 24px;
  right: 24px;
  padding: 6px 14px;
  background: rgba(3, 7, 18, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  font-size: 12px;
  color: #fff;
  cursor: pointer;
  display: none;
  transition: background var(--transition);
}

#main-stage .stage-unpin:hover {
  background: rgba(34, 211, 238, 0.16);
  border-color: var(--border-strong);
}
#main-stage.pinned .stage-unpin { display: block; }

/* Stage avatar fallback */
#main-stage .stage-avatar {
  display: none;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, #22d3ee, #2563eb 58%, #a3e635);
  box-shadow: 0 0 42px rgba(34, 211, 238, 0.28);
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: 700;
  color: #fff;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
}

/* Placeholder when no other participant */
.stage-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-secondary);
  text-align: center;
}

.stage-placeholder-icon {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(34, 211, 238, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.stage-placeholder p {
  font-size: 15px;
}

/* ----- Filmstrip ----- */
#filmstrip-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 14px 10px;
  flex-shrink: 0;
}

#filmstrip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-behavior: smooth;
  flex: 1;
  padding: 4px 0;
  scrollbar-width: none;
}

#filmstrip::-webkit-scrollbar { display: none; }

.filmstrip-arrow {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.72);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  line-height: 1;
}

.filmstrip-arrow:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.filmstrip-arrow:disabled { opacity: 0.3; cursor: default; }

/* Filmstrip tile */
.filmstrip-tile {
  flex-shrink: 0;
  width: 200px;
  height: 120px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: rgba(2, 6, 23, 0.92);
  position: relative;
  cursor: pointer;
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  animation: tileIn 0.3s ease;
}

@keyframes tileIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.filmstrip-tile:hover {
  border-color: rgba(34, 211, 238, 0.38);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
  transform: translateY(-2px);
}

.filmstrip-tile.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.56), 0 0 28px rgba(34, 211, 238, 0.18);
}

.filmstrip-tile.self-tile {
  border-color: rgba(163, 230, 53, 0.38);
}

.filmstrip-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.filmstrip-tile .tile-label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  padding: 2px 8px;
  background: rgba(3, 7, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  pointer-events: none;
}

.filmstrip-tile .tile-muted {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(255, 59, 92, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.filmstrip-tile .tile-muted svg {
  width: 10px; height: 10px;
  color: #fff;
}

.filmstrip-tile.no-video .tile-avatar {
  display: flex;
}

.filmstrip-tile.no-video video {
  opacity: 0;
}

.filmstrip-tile .tile-avatar {
  display: none;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #22d3ee, #2563eb 58%, #a3e635);
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.24);
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  pointer-events: none;
  z-index: 2;
}

/* Only show filmstrip when there's more than self */
#filmstrip-wrapper.no-peers { display: none; }

/* ----- Controls ----- */
#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: fit-content;
  max-width: calc(100% - 28px);
  margin: 0 auto 18px;
  padding: 10px;
  background: rgba(3, 7, 18, 0.78);
  border: 1px solid rgba(34, 211, 238, 0.18);
  border-radius: 999px;
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  flex-shrink: 0;
}

.ctrl-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.86);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.ctrl-btn svg { width: 22px; height: 22px; }

.ctrl-btn:hover {
  background: rgba(34, 211, 238, 0.14);
  border-color: var(--border-strong);
  color: var(--primary-hover);
  box-shadow: 0 0 22px rgba(34, 211, 238, 0.14);
  transform: translateY(-2px);
}

.ctrl-btn:disabled {
  cursor: wait;
  opacity: 0.55;
  transform: none;
}

.hidden-control {
  display: none !important;
}

.ctrl-btn.off {
  background: rgba(255, 59, 92, 0.16);
  border-color: rgba(255, 59, 92, 0.46);
  color: var(--danger);
}

.ctrl-leave {
  width: auto;
  min-width: 92px;
  padding: 0 18px;
  gap: 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff3b5c, #b91c1c) !important;
  border-color: rgba(255, 132, 152, 0.72) !important;
  color: #fff !important;
  box-shadow: 0 14px 34px rgba(255, 59, 92, 0.22);
}

.ctrl-leave span {
  font-size: 14px;
  font-weight: 700;
}

.ctrl-leave:hover {
  background: linear-gradient(135deg, #ff5f7b, #dc2626) !important;
  box-shadow: 0 18px 42px rgba(255, 59, 92, 0.32);
}

/* ----- Toast ----- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  background: rgba(3, 7, 18, 0.86);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(34, 211, 238, 0.2);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px) !important;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .landing-card { padding: 28px 20px; }

  .filmstrip-tile {
    width: 140px;
    height: 88px;
  }

  .filmstrip-arrow { display: none; }

  #controls { gap: 10px; margin-bottom: 14px; padding: 8px; }
  .ctrl-btn { width: 44px; height: 44px; }
  .ctrl-btn svg { width: 20px; height: 20px; }
  .ctrl-leave {
    min-width: 76px;
    padding: 0 14px;
  }
  .ctrl-leave span { font-size: 13px; }

  #main-stage .stage-label { bottom: 16px; left: 16px; font-size: 12px; }
}

@media (max-width: 480px) {
  .filmstrip-tile {
    width: 110px;
    height: 72px;
  }

  #controls {
    gap: 6px;
    max-width: calc(100% - 12px);
  }
  #main-stage { padding: 6px; }
  .ctrl-leave span { display: none; }
  .ctrl-leave {
    min-width: 48px;
    padding: 0;
  }
}
