:root {
  color-scheme: dark;
  --bg: #0a0d1a;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #e6e9f2;
  --text-dim: #94a3b8;
  --text-mute: #64748b;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --accent-3: #f472b6;
  --danger: #f43f5e;
  --success: #34d399;
  --shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius-lg: 1.5rem;
  --radius-md: 1rem;
  --radius-sm: 0.75rem;
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(34, 211, 238, 0.14), transparent 55%),
    radial-gradient(800px 600px at 50% 110%, rgba(244, 114, 182, 0.12), transparent 60%),
    var(--bg);
}

/* Decorative orbs */
.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
  animation: float 18s ease-in-out infinite;
}
.orb-1 { width: 420px; height: 420px; left: -120px; top: -80px; background: #7c5cff; }
.orb-2 { width: 360px; height: 360px; right: -100px; top: 20%; background: #22d3ee; animation-delay: -6s; }
.orb-3 { width: 320px; height: 320px; left: 30%; bottom: -120px; background: #f472b6; animation-delay: -12s; }

@keyframes float {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50%      { transform: translate3d(20px, -30px, 0) scale(1.05); }
}

/* Layout */
.shell {
  position: relative;
  z-index: 1;
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.75rem 0 4rem;
  transition: width 200ms ease, padding 200ms ease;
}

body.in-party .shell {
  width: calc(100% - 1rem);
  max-width: none;
  padding: 0.5rem 0 0.75rem;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 2rem;
}
body.in-party .topbar {
  padding-bottom: 0.6rem;
}
.party-controls {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}
.party-controls .btn {
  padding: 0.55rem 0.85rem;
}
.party-controls .icon-btn {
  padding: 0.55rem 0.7rem;
}
body.in-party #badge { display: none; }
@media (max-width: 640px) {
  body.in-party .brand-name { display: none; }
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(124, 92, 255, 0.35);
}
.brand-name { font-size: 1.05rem; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  backdrop-filter: blur(10px);
}
.badge .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.18);
}

/* Landing */
.landing {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 2.5rem;
  align-items: center;
  padding: 1rem 0 2rem;
}
@media (max-width: 880px) {
  .landing { grid-template-columns: 1fr; gap: 1.75rem; }
}

.hero { max-width: 620px; }
.eyebrow {
  display: inline-block;
  margin: 0 0 0.9rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: rgba(124, 92, 255, 0.14);
  border: 1px solid rgba(124, 92, 255, 0.35);
  color: #c4b5fd;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
h1 {
  font-size: clamp(2.6rem, 7vw, 5.25rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
  margin: 0.2rem 0 1rem;
  font-weight: 900;
}
h1 .grad {
  background: linear-gradient(90deg, #a78bfa, #22d3ee 60%, #f472b6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lede {
  font-size: 1.075rem;
  color: var(--text-dim);
  margin: 0 0 1.5rem;
  max-width: 52ch;
  line-height: 1.55;
}
.features {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.5rem;
  color: var(--text-dim);
  font-size: 0.95rem;
}
.features li { display: flex; align-items: center; gap: 0.6rem; }
.tick {
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.15);
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 800;
}

/* Card */
.card {
  position: relative;
  display: grid;
  gap: 1rem;
  padding: 1.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(30, 35, 60, 0.55), rgba(15, 18, 36, 0.7));
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.6), rgba(34, 211, 238, 0.35) 50%, transparent 70%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}
.card-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.card-sub {
  margin: -0.4rem 0 0.5rem;
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* Form fields */
.field { display: grid; gap: 0.45rem; }
.field-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
input {
  width: 100%;
  font: inherit;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  background: rgba(10, 13, 26, 0.7);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
input::placeholder { color: var(--text-mute); }
input:hover { border-color: rgba(148, 163, 184, 0.4); }
input:focus {
  outline: none;
  border-color: rgba(124, 92, 255, 0.7);
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.18);
  background: rgba(10, 13, 26, 0.9);
}
.hint {
  color: var(--text-mute);
  font-size: 0.8rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font: inherit;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.8rem 1.15rem;
  cursor: pointer;
  transition: transform 120ms ease, background 150ms ease, border-color 150ms ease, box-shadow 150ms ease, color 150ms ease, filter 150ms ease;
  user-select: none;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.35);
}

.btn-primary {
  color: #0b0f1f;
  background: linear-gradient(135deg, #a78bfa, #22d3ee);
  box-shadow: 0 10px 28px rgba(124, 92, 255, 0.35);
}
.btn-primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 14px 36px rgba(124, 92, 255, 0.45);
}

.btn-ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-strong);
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(148, 163, 184, 0.4);
}
.btn-ghost[aria-pressed="false"] {
  color: #fda4af;
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.35);
}

.btn-danger {
  color: #fff;
  background: linear-gradient(135deg, #f43f5e, #fb7185);
  box-shadow: 0 10px 24px rgba(244, 63, 94, 0.35);
}
.btn-danger:hover { filter: brightness(1.05); }

.btn-block { width: 100%; }

.icon-btn .btn-label { font-weight: 600; }
.icon-btn .icon-off { display: none; }
.icon-btn[aria-pressed="false"] .icon-on { display: none; }
.icon-btn[aria-pressed="false"] .icon-off { display: inline-block; }

/* Party */
.party {
  margin-top: 1.5rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(20, 24, 44, 0.6), rgba(10, 13, 26, 0.7));
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}
body.in-party .party {
  margin-top: 0.5rem;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  border-radius: 0;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.controls {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}
.camera-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.6);
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  backdrop-filter: blur(10px);
  max-width: 220px;
}
.camera-picker:hover { color: var(--text); border-color: rgba(148, 163, 184, 0.45); }
.camera-picker select {
  appearance: none;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  outline: none;
  cursor: pointer;
  max-width: 170px;
  text-overflow: ellipsis;
}
.camera-picker select option { background: #0f1224; color: var(--text); }
.room-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(10, 13, 26, 0.6);
}
.room-pill .dot.live {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.45); }
  50%      { box-shadow: 0 0 0 8px rgba(244, 63, 94, 0); }
}

/* Video grid */
.videos {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.85rem;
}
body.in-party .videos {
  /* Default: many tiles fall back to auto-fit. Specific counts get explicit
     row/column layouts (below) so 2–9 participants always fill the viewport. */
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  grid-auto-rows: 1fr;
  gap: 0.6rem;
  height: calc(100vh - 5rem);
  align-content: stretch;
}
/* Count-aware layouts: pick rows × cols that fill the screen for small groups. */
body.in-party .videos:has(.tile:nth-child(1):last-child) {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
body.in-party .videos:has(.tile:nth-child(2):last-child) {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: 1fr;
}
body.in-party .videos:has(.tile:nth-child(3):last-child),
body.in-party .videos:has(.tile:nth-child(4):last-child) {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
body.in-party .videos:has(.tile:nth-child(5):last-child),
body.in-party .videos:has(.tile:nth-child(6):last-child) {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
body.in-party .videos:has(.tile:nth-child(7):last-child),
body.in-party .videos:has(.tile:nth-child(8):last-child),
body.in-party .videos:has(.tile:nth-child(9):last-child) {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
@media (max-aspect-ratio: 1/1) {
  /* On portrait/narrow screens, prefer stacking vertically for 2–3 tiles. */
  body.in-party .videos:has(.tile:nth-child(2):last-child) {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, 1fr);
  }
  body.in-party .videos:has(.tile:nth-child(3):last-child) {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, 1fr);
  }
}
.tile {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  min-height: 200px;
  border-radius: var(--radius-md);
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(120% 80% at 100% 100%, rgba(34, 211, 238, 0.14), transparent 60%),
    #06080f;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transition: transform 200ms ease, border-color 200ms ease;
}
body.in-party .tile {
  /* Let the grid size tiles to fill the viewport instead of locking to 16:10. */
  aspect-ratio: auto;
  min-height: 0;
  height: 100%;
  width: 100%;
}
.tile:hover { transform: translateY(-2px); border-color: var(--border-strong); }

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile.is-self video {
  transform: scaleX(-1);
}

.name {
  position: absolute;
  left: 0.7rem;
  bottom: 0.7rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  background: rgba(2, 6, 23, 0.65);
  color: #f8fafc;
  font-weight: 700;
  font-size: 0.85rem;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* Status */
.status {
  margin-top: 1rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  min-height: 1.25rem;
}

.hidden { display: none !important; }

/* Toasts */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
  pointer-events: none;
  align-items: center;
}
.toast {
  pointer-events: auto;
  background: rgba(15, 18, 35, 0.92);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.1rem;
  box-shadow: var(--shadow-md);
  font-size: 0.95rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  backdrop-filter: blur(8px);
  animation: toast-in 180ms ease-out;
  max-width: min(90vw, 28rem);
}
.toast.is-leaving { animation: toast-out 220ms ease-in forwards; }
.toast .toast-icon {
  display: inline-flex;
  width: 1.5rem;
  height: 1.5rem;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(244, 63, 94, 0.18);
  color: var(--danger);
  flex: none;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px); }
}
