/* ---------- base ---------- */
:root {
  --bg: #070b14;
  --bg-soft: #0b1220;
  --panel: #0f172a;
  --card: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.09);
  --txt: #e8eefb;
  --muted: #93a3bd;
  --accent: #38bdf8;
  --accent-2: #8b5cf6;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background-image:
    radial-gradient(1100px 600px at 15% -10%, rgba(56, 189, 248, 0.16), transparent 60%),
    radial-gradient(900px 520px at 95% 0%, rgba(139, 92, 246, 0.16), transparent 55%),
    radial-gradient(700px 500px at 50% 110%, rgba(52, 211, 153, 0.07), transparent 60%);
  background-attachment: fixed;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.grad { background: linear-gradient(90deg, #38bdf8, #a78bfa 60%, #34d399); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  max-width: 1120px;
  margin: 0 auto;
  width: 100%;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 17px;
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.45);
}
.spacer { flex: 1; }
.ghost-link { color: var(--muted); font-size: 14px; }

/* ---------- home ---------- */
.home { max-width: 980px; margin: 0 auto; padding: 10px 20px 40px; }
.hero { padding: 28px 0 22px; }
.badge {
  display: inline-block;
  font-size: 12.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #bfe7ff;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.28);
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: 18px;
}
.hero h1 {
  font-size: clamp(30px, 5.4vw, 54px);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
}
.lead { color: var(--muted); font-size: clamp(15px, 2vw, 18px); line-height: 1.6; max-width: 640px; margin: 0; }

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(14px);
}
.start-card { margin-top: 26px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.2px; }

input[type="text"], select {
  width: 100%;
  padding: 13px 15px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(7, 11, 20, 0.65);
  color: var(--txt);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}
input[type="text"]:focus, select:focus {
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
}
input::placeholder { color: #5d6b83; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 12px 18px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--txt);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.btn:hover { background: rgba(255, 255, 255, 0.1); }
.btn:active { transform: scale(0.985); }
.btn.primary {
  border: none;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  box-shadow: 0 10px 28px rgba(56, 189, 248, 0.28);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { padding: 15px 20px; font-size: 16px; }
.btn.ghost { background: transparent; }
.btn svg { width: 20px; height: 20px; }
.btn[disabled] { opacity: 0.55; cursor: default; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; text-transform: lowercase; letter-spacing: 0.08em; }
.hint { color: var(--warn); font-size: 13.5px; min-height: 1em; margin: 2px 0 0; }
.install-btn { align-self: flex-start; }

.feature-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-top: 22px; }
.feature {
  padding: 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--card);
}
.feature-icon {
  width: 30px; height: 30px; border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  background: rgba(56, 189, 248, 0.16);
  color: #a5e8ff;
  margin-bottom: 12px;
}
.feature h3 { margin: 0 0 6px; font-size: 15.5px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }

.trust-card { margin-top: 22px; }
.trust-card h2 { font-size: 19px; margin: 0 0 10px; }
.trust-card details { border-top: 1px solid var(--line); padding: 12px 0; }
.trust-card summary { cursor: pointer; font-weight: 600; }
.trust-card ol { margin: 10px 0 0; padding-left: 20px; color: var(--muted); line-height: 1.65; font-size: 14.5px; }
.trust-card p { line-height: 1.6; }
.footer {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center;
  color: #5d6b83;
  font-size: 13px;
  padding: 8px 20px calc(28px + var(--safe-bottom));
}
.footer a { color: #5d6b83; }
.sep { opacity: 0.5; }

/* ---------- room layout ---------- */
.page-room {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.room-topbar { padding-bottom: 8px; }
.room-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 10px 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
  font-size: 14px;
}
.room-label { color: var(--muted); font-size: 12.5px; }
.room-chip code { letter-spacing: 0.12em; font-weight: 700; color: #bfe7ff; text-transform: lowercase; }
.icon-btn {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border-radius: 9px;
  border: none;
  background: rgba(255, 255, 255, 0.07);
  color: var(--txt);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.14); }
.icon-btn svg { width: 16px; height: 16px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  white-space: nowrap;
}
.status-pill i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.7);
}
.status-pill.ok i { background: var(--ok); box-shadow: 0 0 10px rgba(52, 211, 153, 0.7); }
.status-pill.bad i { background: var(--danger); box-shadow: 0 0 10px rgba(248, 113, 113, 0.7); }

.stage { position: relative; flex: 1; min-height: 0; padding: 8px 14px 4px; display: flex; }
.tiles {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: minmax(180px, 1fr);
  align-content: stretch;
}
.tiles[data-count="1"] { grid-template-columns: minmax(0, 1fr); grid-auto-rows: 1fr; }
.tiles[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tiles[data-count="3"], .tiles[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.tile {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(160deg, #0d1524, #0a0f1a);
  border: 1px solid var(--line);
  min-height: 0;
  isolation: isolate;
}
.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #05080f;
  transform: translateZ(0);
}
.tile.self video { transform: scaleX(-1); }
.tile.speaking { box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.65), 0 0 24px rgba(52, 211, 153, 0.22); }
.tile-label {
  position: absolute;
  left: 12px; right: 12px; bottom: 10px;
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px;
  color: #eaf2ff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}
.tile-label .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-label .sub { color: #a9b9d4; font-size: 12px; margin-left: auto; white-space: nowrap; }
.tile::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 46%;
  background: linear-gradient(to top, rgba(4, 7, 13, 0.78), transparent);
  pointer-events: none;
}
.badge-mute {
  position: absolute; top: 10px; right: 10px;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(4, 7, 13, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--danger);
  z-index: 1;
  transition: opacity 0.15s;
}
.badge-mute svg { width: 15px; height: 15px; }
.badge-mute[hidden] { display: none; }
.conn-dot {
  position: absolute; top: 12px; left: 12px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.8);
  z-index: 1;
}
.conn-dot.ok { background: var(--ok); box-shadow: 0 0 10px rgba(52, 211, 153, 0.8); }
.conn-dot.bad { background: var(--danger); box-shadow: 0 0 10px rgba(248, 113, 113, 0.8); }
.tile-avatar {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: clamp(40px, 8vw, 84px);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  background: radial-gradient(circle at 50% 40%, #16233b, #0a0f1a 70%);
  z-index: 0;
}
.tile.no-video video { opacity: 0; }
.tile.no-video .tile-avatar { opacity: 1; }
.tile.has-video .tile-avatar { opacity: 0; }

/* ---------- waiting ---------- */
.waiting {
  position: absolute; inset: 0;
  margin: 8px 14px 4px;
  border-radius: 20px;
  border: 1px dashed rgba(255, 255, 255, 0.13);
  background: rgba(8, 13, 23, 0.55);
  backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
  z-index: 2;
}
.waiting[hidden] { display: none; }
.waiting h2 { margin: 6px 0 0; font-size: 22px; }
.waiting p { margin: 0; color: var(--muted); max-width: 420px; line-height: 1.55; }
.pulse-ring { position: relative; width: 74px; height: 74px; display: grid; place-items: center; }
.pulse-ring span {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(56, 189, 248, 0.55);
  animation: pulse 2.2s ease-out infinite;
}
.pulse-ring::before {
  content: "";
  width: 46px; height: 46px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  opacity: 0.85;
}
@keyframes pulse {
  0% { transform: scale(0.55); opacity: 0.9; }
  100% { transform: scale(1.25); opacity: 0; }
}
.link-box {
  margin-top: 4px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  max-width: min(560px, 90%);
  overflow: hidden;
}
.link-box code { font-size: 13px; color: #bfe7ff; word-break: break-all; }

/* ---------- controls ---------- */
.controls {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px calc(14px + var(--safe-bottom));
  margin-top: auto;
}
.controls-group {
  display: flex; align-items: center; gap: 10px;
  margin: 0 auto;
  padding: 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(12, 19, 32, 0.72);
  backdrop-filter: blur(16px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
}
.ctl {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.06);
  color: var(--txt);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s, color 0.15s;
}
.ctl svg { width: 23px; height: 23px; }
.ctl:hover { background: rgba(255, 255, 255, 0.12); }
.ctl:active { transform: scale(0.94); }
.ctl.off { background: rgba(248, 113, 113, 0.16); color: #ffb4b4; border-color: rgba(248, 113, 113, 0.35); }
.ctl.danger {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border: none;
  color: #fff;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.35);
}
.mic-meter {
  width: 78px; height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
  flex: none;
}
.mic-meter i {
  display: block; height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #34d399, #38bdf8);
  transition: width 0.08s linear;
}

/* ---------- devices sheet ---------- */
.devices {
  position: fixed;
  right: 16px;
  bottom: calc(96px + var(--safe-bottom));
  width: min(330px, calc(100vw - 32px));
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(11, 18, 31, 0.96);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  display: flex; flex-direction: column; gap: 14px;
  z-index: 30;
}
.devices[hidden] { display: none; }
.devices-head { display: flex; align-items: center; justify-content: space-between; }
.devices-head h3 { margin: 0; font-size: 16px; }
.devices select { font-size: 14.5px; padding: 11px 13px; }

/* ---------- gate ---------- */
.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(5, 8, 14, 0.72);
  backdrop-filter: blur(18px);
  z-index: 40;
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(420px, 100%);
  padding: 26px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(22, 32, 51, 0.92), rgba(10, 15, 25, 0.96));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  display: flex; flex-direction: column; gap: 14px;
}
.gate-brand { margin-bottom: 4px; }
.gate-card h2 { margin: 0; font-size: 20px; }
.gate-card h2 code { color: #bfe7ff; letter-spacing: 0.1em; }
.gate-card p { margin: 0; font-size: 14px; line-height: 1.55; }

/* ---------- diagnostics ---------- */
.diag {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: #cfe3ff;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
  text-align: left;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.diag[hidden] { display: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(104px + var(--safe-bottom));
  transform: translateX(-50%);
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--line);
  color: var(--txt);
  font-size: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  z-index: 50;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.err { border-color: rgba(248, 113, 113, 0.5); color: #ffc9c9; }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .tiles { grid-template-columns: 1fr; grid-auto-rows: minmax(150px, 1fr); gap: 10px; }
  .tiles[data-count="2"] { grid-template-columns: 1fr; }
  .tiles[data-count="3"], .tiles[data-count="4"] { grid-template-columns: 1fr; }
  .stage { padding: 6px 10px 2px; }
  .topbar { padding-left: 14px; padding-right: 14px; }
  .room-topbar .room-label { display: none; }
  .status-pill { padding: 6px 10px; font-size: 12px; }
  .ctl { width: 48px; height: 48px; }
  .mic-meter { width: 54px; }
  .controls { padding: 10px 12px calc(12px + var(--safe-bottom)); gap: 8px; }
}
@media (max-width: 420px) {
  .room-chip { font-size: 12.5px; padding: 6px 8px 6px 10px; }
  .brand span:not(.brand-mark) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .pulse-ring span { animation: none; }
}