/* ============================================================
   Hootenanny — random video hangouts
   Dark party theme: charcoal base, pink→orange→purple accents.
   ============================================================ */

:root {
  --bg: #0a0a12;
  --bg-2: #12111f;
  --tile: #17152a;
  --text: #f3f2f9;
  --muted: #9b98b4;
  --panel: rgba(255, 255, 255, 0.055);
  --panel-strong: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.09);
  --pink: #ff4d8d;
  --orange: #ff9a3d;
  --purple: #8a5cff;
  --danger: #ff5a5f;
  --ok: #3ddc84;
  --warn: #ffcc4d;
  --grad: linear-gradient(120deg, var(--pink), var(--orange));
  --radius: 18px;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  z-index: 1;
}
.screen.active { display: flex; }
#screen-room.active, #screen-searching.active { overflow: hidden; }

/* ---------- animated background blobs ---------- */
.blobs {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: -1;
  pointer-events: none;
}
.blobs.dim { opacity: 0.5; }
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(95px);
  opacity: 0.32;
}
.b1 { width: 520px; height: 520px; background: var(--pink);   top: -180px;  left: -120px;  animation: drift1 18s ease-in-out infinite alternate; }
.b2 { width: 470px; height: 470px; background: var(--orange); bottom: -170px; right: -110px; animation: drift2 22s ease-in-out infinite alternate; }
.b3 { width: 380px; height: 380px; background: var(--purple); top: 32%;     right: 18%;   animation: drift3 26s ease-in-out infinite alternate; }

@keyframes drift1 { to { transform: translate(130px, 90px) scale(1.18); } }
@keyframes drift2 { to { transform: translate(-110px, -70px) scale(1.12); } }
@keyframes drift3 { to { transform: translate(-90px, 110px) scale(0.9); } }

@media (prefers-reduced-motion: reduce) {
  .blob, .pulse-dot, .spinner { animation: none !important; }
}

/* ---------- shared bits ---------- */
.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -0.4px;
  user-select: none;
}
.logo.small { font-size: 17px; }
.logo-emoji { font-size: 1.25em; filter: drop-shadow(0 2px 6px rgba(255, 77, 141, 0.45)); }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 13px;
  padding: 13px 24px;
  font-size: 15.5px;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); background: rgba(255, 255, 255, 0.13); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: var(--grad);
  border: none;
  color: #fff;
  box-shadow: 0 6px 22px rgba(255, 77, 141, 0.35);
}
.btn.primary:hover { box-shadow: 0 8px 28px rgba(255, 154, 61, 0.45); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 9px 16px; font-size: 14px; border-radius: 11px; }

.grad {
  font-style: normal;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ---------- round control buttons ---------- */
.ctl {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease, color 0.15s ease;
}
.ctl svg { width: 21px; height: 21px; }
.ctl:hover { background: var(--panel-strong); transform: translateY(-1px); }
.ctl.off { color: var(--danger); background: rgba(255, 90, 95, 0.14); }
.ctl.off::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 2px;
  background: var(--danger);
  border-radius: 2px;
  transform: rotate(-45deg);
}
.ctl.disabled { opacity: 0.35; pointer-events: none; }
.ctl.warn:hover { color: var(--warn); background: rgba(255, 204, 77, 0.12); }
.ctl.leave:hover { color: var(--danger); background: rgba(255, 90, 95, 0.12); }

/* ---------- video tiles ---------- */
.tile {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: var(--tile);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: box-shadow 0.18s ease;
  container-type: inline-size; /* nameplates scale with tile size (cqi units) */
}
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(1); /* remote & preview */
}
.tile.self video { transform: scaleX(-1); } /* mirror yourself */

.tile-fallback {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(120% 120% at 30% 20%, rgba(255, 77, 141, 0.18), transparent 55%),
    radial-gradient(120% 120% at 75% 80%, rgba(138, 92, 255, 0.16), transparent 55%),
    var(--tile);
}
.tile.no-video .tile-fallback { display: flex; }
.tile.no-video video { visibility: hidden; }

.avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--grad);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 30px;
  color: #fff;
  letter-spacing: 1px;
  box-shadow: 0 8px 30px rgba(255, 77, 141, 0.35);
  user-select: none;
}

.tile-badges {
  position: absolute;
  bottom: clamp(6px, 1.6cqi, 14px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.4em;
  z-index: 2;
  width: max-content;
  max-width: calc(100cqi - 24px);
  /* one font-size drives the whole plate: text, padding, gap and icons
     all use em units, so the nameplate scales proportionally with the tile */
  font-size: 13px; /* fallback for browsers without container queries */
  font-size: clamp(11px, 4.6cqi, 18px);
}
.pill {
  border-radius: 999px;
  background: rgba(6, 6, 14, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.42em 0.95em;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
}
.pill.mic-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  flex: 0 0 auto;
}
.pill.name-pill {
  display: block;
  min-width: 0;
  text-align: center;
  text-overflow: ellipsis; /* last resort for absurdly long names */
}
.pill svg { width: 1.05em; height: 1.05em; color: var(--danger); flex: 0 0 auto; }

.status-dot {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #565468;
  z-index: 2;
  box-shadow: 0 0 0 3px rgba(6, 6, 14, 0.5);
}
.status-dot[data-state="connected"] { background: var(--ok); }
.status-dot[data-state="connecting"], .status-dot[data-state="new"] { background: var(--warn); animation: pulse 1.1s ease-in-out infinite; }
.status-dot[data-state="failed"], .status-dot[data-state="disconnected"] { background: var(--danger); }
.status-dot[data-state="self"] { background: var(--purple); }

@keyframes pulse { 50% { opacity: 0.35; } }

.tile.speaking {
  box-shadow: 0 0 0 3px var(--pink), 0 0 26px rgba(255, 77, 141, 0.55);
  border-color: transparent;
}

/* floating reactions */
.reaction-float {
  position: absolute;
  bottom: 34px;
  font-size: 34px;
  z-index: 3;
  pointer-events: none;
  animation: floatUp 1.8s ease-out forwards;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}
@keyframes floatUp {
  0%   { transform: translateY(0) scale(0.6); opacity: 0; }
  15%  { transform: translateY(-12px) scale(1.25); opacity: 1; }
  100% { transform: translateY(-150px) scale(1); opacity: 0; }
}

/* ============================================================
   LANDING
   ============================================================ */
.landing-wrap {
  width: min(1140px, 100% - 40px);
  margin: 0 auto;
  padding: 26px 0 34px;
  display: flex;
  flex-direction: column;
  gap: 40px;
  flex: 1;
}

.landing-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
}
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 1.6s ease-in-out infinite;
}

.hero {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 56px;
  align-items: center;
}

.hero-copy h1 {
  font-size: clamp(38px, 5.2vw, 62px);
  line-height: 1.04;
  font-weight: 800;
  letter-spacing: -1.6px;
  margin-bottom: 18px;
}

.tagline {
  font-size: 17.5px;
  line-height: 1.55;
  color: var(--muted);
  max-width: 52ch;
}

/* preview card */
.preview-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.preview-tile {
  aspect-ratio: 16 / 10;
  height: auto;
  border: none;
}

.preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#nameInput, #codeInput, #chatInput {
  background: rgba(8, 8, 16, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#nameInput:focus, #codeInput:focus, #chatInput:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(255, 77, 141, 0.18);
}
#nameInput { flex: 1; min-width: 0; }

.preview-toggles { display: flex; gap: 8px; }
.preview-toggles .ctl { width: 44px; height: 44px; }
.preview-toggles .ctl svg { width: 19px; height: 19px; }

.media-note {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  min-height: 1.2em;
}

/* mode cards */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.mode-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 26px 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.mode-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 77, 141, 0.4);
  box-shadow: 0 14px 40px rgba(255, 77, 141, 0.12);
}
.mode-card.highlight {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(255, 77, 141, 0.25);
}

.mode-emoji {
  font-size: 34px;
  line-height: 1;
  margin-bottom: 4px;
}

.mode-card h2 { font-size: 21px; font-weight: 700; letter-spacing: -0.4px; }

.mode-card p {
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.5;
  flex: 1;
}

.mode-card .btn { width: 100%; }

.code-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
#codeInput {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 700;
  text-align: center;
}

.landing-foot {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  padding-bottom: 8px;
}

/* ============================================================
   SEARCHING
   ============================================================ */
.search-wrap {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  padding: 20px;
}

.spinner {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 300deg, var(--pink) 330deg, var(--orange) 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 9px), #000 calc(100% - 8px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 9px), #000 calc(100% - 8px));
  animation: spin 1.1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#searchTitle { font-size: 30px; font-weight: 800; letter-spacing: -0.6px; }
.search-sub { color: var(--muted); font-size: 15px; min-height: 1.4em; }
.search-actions { display: flex; gap: 10px; margin-top: 8px; }

/* ============================================================
   ROOM
   ============================================================ */
#screen-room { background: var(--bg); }

.room-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 18, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  flex: 0 0 auto;
}

.room-info {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.4px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
}

.room-actions { display: flex; gap: 8px; }
.room-actions .ctl { width: 42px; height: 42px; }
.room-actions .ctl svg { width: 18px; height: 18px; }

.room-body {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}

/* adaptive grid by headcount */
#videoGrid {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  gap: 12px;
  padding: 12px;
  grid-auto-rows: minmax(140px, 1fr);
  max-width: 1640px;
  width: 100%;
  margin: 0 auto;
}
#videoGrid[data-count="0"] { grid-template-columns: 1fr; }
#videoGrid[data-count="1"] { grid-template-columns: 1fr; }
#videoGrid[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#videoGrid[data-count="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#videoGrid[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#videoGrid[data-count="5"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#videoGrid[data-count="6"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ---------- chat panel ---------- */
#chatPanel {
  width: 0;
  flex: 0 0 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: rgba(13, 12, 24, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: width 0.22s ease;
}
#chatPanel.open { width: 330px; }

.chat-head {
  padding: 14px 16px;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#chatMessages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 92%;
  gap: 2px;
}
.msg .msg-name { font-size: 12px; font-weight: 700; color: var(--muted); padding-left: 4px; }
.msg .msg-text {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 4px;
  padding: 8px 12px;
  font-size: 14.5px;
  line-height: 1.45;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.mine .msg-text {
  background: linear-gradient(120deg, rgba(255, 77, 141, 0.32), rgba(255, 154, 61, 0.28));
  border: 1px solid rgba(255, 154, 61, 0.35);
  border-radius: 14px 14px 4px 14px;
}
.msg.system {
  align-self: center;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  font-style: italic;
  max-width: 100%;
  padding: 2px 6px;
}

#chatForm {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
#chatForm.open { display: flex; }
#chatInput { flex: 1; min-width: 0; }
#chatForm .btn { padding: 10px 14px; }
#chatForm .btn svg { width: 17px; height: 17px; display: block; }

/* ---------- controls bar ---------- */
.controls-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px 16px;
  background: linear-gradient(transparent, rgba(10, 10, 18, 0.9) 55%);
}

.btn.next {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--grad);
  border: none;
  color: #fff;
  border-radius: 999px;
  padding: 13px 22px;
  box-shadow: 0 6px 22px rgba(255, 77, 141, 0.35);
  font-size: 15px;
  font-weight: 700;
}
.btn.next svg { width: 17px; height: 17px; }
.btn.next:hover { box-shadow: 0 8px 28px rgba(255, 154, 61, 0.5); }

/* reaction popover */
.ctl-wrap { position: relative; display: inline-flex; }
#reactionPop {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  transform-origin: bottom center;
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(16, 15, 30, 0.95);
  border: 1px solid var(--border);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
#reactionPop.open { opacity: 1; pointer-events: auto; transform: translateX(-50%) scale(1); }
.reaction-btn {
  border: none;
  background: transparent;
  font-size: 22px;
  padding: 4px 6px;
  border-radius: 10px;
  transition: transform 0.12s ease, background 0.12s ease;
}
.reaction-btn:hover { transform: scale(1.25) rotate(-6deg); background: var(--panel-strong); }

/* unread badge */
.unread {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(255, 90, 95, 0.5);
}

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: rgba(18, 17, 32, 0.95);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toastIn 0.22s ease;
  transition: opacity 0.35s ease, transform 0.35s ease;
  max-width: min(88vw, 480px);
  text-align: center;
}
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; gap: 28px; }
  .mode-grid { grid-template-columns: 1fr; }
  .landing-wrap { gap: 26px; }
}

@media (max-width: 640px) {
  #videoGrid[data-count="3"], #videoGrid[data-count="5"], #videoGrid[data-count="6"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #videoGrid[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .controls-bar { gap: 7px; padding: 10px 8px 12px; }
  .ctl { width: 44px; height: 44px; }
  .btn.next { padding: 12px 16px; font-size: 14px; }
  .btn.next svg { display: none; }

  #chatPanel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(86vw, 330px) !important;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    z-index: 6;
    box-shadow: -18px 0 40px rgba(0, 0, 0, 0.4);
  }
  #chatPanel.open { transform: translateX(0); }

  .room-info { font-size: 13px; padding: 6px 12px; }
  .logo.small .logo-word { display: none; }
  .hero-copy h1 { letter-spacing: -1px; }
}
