/* ============================================================
   OG — dark, privacy-first design system
   ============================================================ */

:root {
  --bg: #07090f;
  --bg-elev: #121826;
  --bg-elev-2: #1a2235;
  --line: rgba(148, 163, 184, 0.14);
  --line-strong: rgba(148, 163, 184, 0.28);
  --text: #e7ecf5;
  --text-muted: #8b98ad;
  --accent: #2dd4bf;
  --accent-bright: #5eead4;
  --accent-ink: #04211c;
  --danger: #ef4444;
  --danger-bright: #f87171;
  --warn: #fbbf24;
  --radius: 18px;
  --radius-sm: 12px;
  --font-sans: "DM Sans", -apple-system, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

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

/* the hidden attribute must always win, even over display rules below */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- ambient background ---------- */
.ambient { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.35; }
.orb-a {
  width: 55vmax; height: 55vmax; top: -20vmax; right: -18vmax;
  background: radial-gradient(circle, rgba(45, 212, 191, 0.35), transparent 65%);
}
.orb-b {
  width: 50vmax; height: 50vmax; bottom: -22vmax; left: -16vmax;
  background: radial-gradient(circle, rgba(56, 122, 223, 0.28), transparent 65%);
}
.bg-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 30%, black 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 90% 70% at 50% 30%, black 30%, transparent 75%);
}

/* ---------- views ---------- */
.view { position: relative; z-index: 1; min-height: 100dvh; }

/* ---------- buttons ---------- */
.btn {
  font-family: inherit; font-size: 1rem; font-weight: 600;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.15rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.55rem;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn svg { width: 1.25em; height: 1.25em; flex: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-bright));
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: 0 8px 30px rgba(45, 212, 191, 0.28);
}
.btn-primary:hover { filter: brightness(1.06); }

.btn-ghost { background: rgba(18, 24, 38, 0.72); }
.btn-ghost:hover { border-color: var(--line-strong); }

.btn-lg { font-size: 1.06rem; padding: 0.95rem 1.6rem; border-radius: 14px; }
.btn-block { width: 100%; }

.btn-link {
  background: none; border: none; color: var(--accent-bright);
  padding: 0.4rem 0.6rem; font-weight: 600;
  text-decoration: underline; text-underline-offset: 4px; text-decoration-color: rgba(94, 234, 212, 0.4);
}

.btn-back {
  background: none; border: none; color: var(--text-muted);
  padding: 0.3rem 0.4rem; margin-left: -0.4rem; font-weight: 600;
}
.btn-back:hover { color: var(--text); }

.btn-round {
  width: 46px; height: 46px; padding: 0; border-radius: 50%;
  background: rgba(10, 13, 20, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn-chip {
  font-size: 0.82rem; padding: 0.32rem 0.65rem; border-radius: 999px;
  background: rgba(45, 212, 191, 0.1); border-color: rgba(45, 212, 191, 0.25);
  color: var(--accent-bright);
}
.btn-chip:hover { background: rgba(45, 212, 191, 0.18); }

/* toggle buttons: on/off icon swap */
.btn .ic-off { display: none; }
.btn.off .ic-on { display: none; }
.btn.off .ic-off { display: inline; }
.btn-round.off, .btn-ctl.off { color: var(--danger-bright); border-color: rgba(239, 68, 68, 0.4); }

/* ============================================================
   Landing
   ============================================================ */
#view-landing {
  display: flex; flex-direction: column;
  padding: calc(1.2rem + var(--sat)) clamp(1.2rem, 5vw, 3rem) calc(1.4rem + var(--sab));
  max-width: 1060px; margin: 0 auto;
}

.landing-header { padding-bottom: clamp(1.5rem, 5vh, 3rem); }
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-mark { width: 34px; height: 34px; }
.brand-mark.sm { width: 24px; height: 24px; }
.brand-name { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }

.hero { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: 0.5rem;
  color: var(--accent-bright); font-weight: 600; font-size: 0.92rem;
  letter-spacing: 0.06em; text-transform: uppercase;
  margin-bottom: 1rem;
}
.hero-eyebrow .dot, .pill .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.hero h1 {
  font-size: clamp(2.3rem, 6.5vw, 4.2rem);
  font-weight: 700; letter-spacing: -0.03em; line-height: 1.04;
  max-width: 15ch;
}
.hero-sub {
  margin-top: 1.1rem; max-width: 52ch;
  color: var(--text-muted); font-size: clamp(1rem, 2.2vw, 1.15rem); line-height: 1.55;
}
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-top: 1.8rem; }

.trust-grid {
  list-style: none;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 0.8rem; margin-top: clamp(2rem, 6vh, 3.4rem);
}
.trust-grid li {
  background: rgba(18, 24, 38, 0.72);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex; flex-direction: column; gap: 0.3rem;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.trust-icon { font-size: 1.3rem; }
.trust-grid strong { font-size: 0.98rem; }
.trust-grid li > span:last-child { color: var(--text-muted); font-size: 0.87rem; line-height: 1.45; }

.landing-footer {
  margin-top: clamp(2rem, 6vh, 3rem);
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.8rem;
}
.landing-footer p { color: var(--text-muted); font-size: 0.88rem; line-height: 1.5; max-width: 62ch; }

/* ============================================================
   Lobby
   ============================================================ */
#view-lobby {
  display: flex; align-items: flex-start; justify-content: center;
  padding: calc(1.2rem + var(--sat)) 1rem calc(2.2rem + var(--sab));
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}
.lobby-card {
  width: 100%; max-width: 480px;
  padding: 1.3rem 1.35rem 1.5rem;
  display: flex; flex-direction: column; gap: 1.05rem;
}
.lobby-card h2 { font-size: 1.45rem; letter-spacing: -0.02em; margin-top: 0.2rem; }
.lobby-sub { color: var(--text-muted); font-size: 0.95rem; margin-top: -0.75rem; }

.preview-wrap {
  position: relative; overflow: hidden;
  border-radius: var(--radius);
  background: #0a0d14;
  border: 1px solid var(--line);
  aspect-ratio: 16 / 10;
  display: flex; align-items: center; justify-content: center;
}
#preview-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
#preview-video.no-video { display: none; }
.preview-note {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0.5rem 0.8rem;
  background: linear-gradient(transparent, rgba(7, 9, 15, 0.85));
  color: var(--text-muted); font-size: 0.82rem; text-align: center;
}
.preview-toggles {
  position: absolute; top: 0.65rem; right: 0.65rem;
  display: flex; gap: 0.5rem;
}

.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field label { font-size: 0.88rem; font-weight: 600; color: var(--text-muted); }
.field input, .field select {
  font-family: inherit; font-size: 1rem; color: var(--text);
  background: rgba(7, 9, 15, 0.6);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' stroke='%238b98ad' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.8rem center; background-size: 1.1em;
  padding-right: 2.6rem;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.18);
}
.field input.mono { font-family: var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; }
.field-hint { color: var(--text-muted); font-size: 0.8rem; line-height: 1.4; }

.wont-list {
  list-style: none;
  border: 1px dashed rgba(45, 212, 191, 0.3);
  background: rgba(45, 212, 191, 0.05);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex; flex-direction: column; gap: 0.45rem;
}
.wont-list li {
  font-size: 0.87rem; color: var(--text-muted); line-height: 1.4;
  padding-left: 1.5em; position: relative;
}
.wont-list li::before {
  content: "✕"; position: absolute; left: 0.15em;
  color: var(--accent); font-weight: 700;
}

.error-line { color: var(--danger-bright); font-size: 0.92rem; line-height: 1.45; }

/* ============================================================
   Call
   ============================================================ */
.view-call {
  display: flex; flex-direction: column;
  height: 100dvh;
  padding: calc(0.6rem + var(--sat)) calc(0.6rem + var(--sar)) calc(0.6rem + var(--sab)) calc(0.6rem + var(--sal));
  gap: 0.6rem;
}

.call-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem;
  background: rgba(18, 24, 38, 0.78);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.85rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.call-room { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.room-code {
  font-family: var(--font-mono); font-size: 1.02rem; font-weight: 600;
  letter-spacing: 0.12em; color: var(--accent-bright);
}
.call-meta { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }

.pill {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: 0.78rem; font-weight: 600;
  color: var(--accent-bright);
  background: rgba(45, 212, 191, 0.1);
  border: 1px solid rgba(45, 212, 191, 0.28);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  white-space: nowrap;
}
.conn-status { color: var(--text-muted); font-size: 0.85rem; }
.peer-count {
  display: inline-flex; align-items: center; gap: 0.35rem;
  color: var(--text-muted); font-size: 0.9rem; font-weight: 600;
}
.peer-count svg { width: 1.15em; height: 1.15em; }

/* ---------- video grid ---------- */
.grid {
  flex: 1; min-height: 0;
  display: grid; gap: 0.6rem;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
  align-items: stretch;
}
.grid[data-count="2"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-count="5"], .grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); }
.grid[data-count="7"], .grid[data-count="8"] { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 640px) and (orientation: portrait) {
  .grid[data-count="2"] { grid-template-columns: 1fr; }
  .grid[data-count="5"], .grid[data-count="6"],
  .grid[data-count="7"], .grid[data-count="8"] { grid-template-columns: repeat(2, 1fr); }
}

.tile {
  position: relative; overflow: hidden;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
}
.tile video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; background: #0a0d14;
}
.tile.mirror video { transform: scaleX(-1); }
.tile.cam-off video { visibility: hidden; }
.tile.screen video { object-fit: contain; }
.tile.screen.mirror video { transform: none; }

.avatar {
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 700; color: var(--accent-ink);
  background: linear-gradient(135deg, var(--accent), var(--accent-bright));
  z-index: 1;
}
.avatar-lg { width: 88px; height: 88px; font-size: 2rem; }
.tile .avatar { display: none; }
.tile.cam-off .avatar { display: flex; }

.tile-name {
  position: absolute; left: 0.6rem; bottom: 0.55rem; z-index: 2;
  display: inline-flex; align-items: center; gap: 0.4rem;
  max-width: calc(100% - 1.2rem);
  background: rgba(7, 9, 15, 0.72);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.83rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.tile-flags {
  position: absolute; top: 0.55rem; right: 0.55rem; z-index: 2;
  display: flex; gap: 0.35rem;
}
.flag {
  width: 28px; height: 28px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  background: rgba(7, 9, 15, 0.72);
  color: var(--danger-bright);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.flag svg { width: 16px; height: 16px; }
.flag-share { color: var(--accent-bright); }
.tile.mic-off .flag-mic { display: flex; }
.tile.cam-off .flag-cam { display: flex; }
.tile.sharing .flag-share { display: flex; }

.tile-connecting {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 0.9rem;
}
.tile-connecting::after {
  content: ""; width: 16px; height: 16px; margin-left: 0.55rem;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- controls ---------- */
.call-controls {
  display: flex; justify-content: center; gap: clamp(0.5rem, 3vw, 1rem);
  padding: 0.25rem 0 0.15rem;
}
.btn-ctl {
  flex-direction: column; gap: 0.28rem;
  min-width: 76px;
  padding: 0.6rem 0.9rem;
  border-radius: 16px;
  background: rgba(18, 24, 38, 0.85);
  font-size: 0.78rem;
}
.btn-ctl svg { width: 24px; height: 24px; }
.ctl-label { font-weight: 600; }
.btn-ctl[aria-pressed="true"].sharing-active {
  background: rgba(45, 212, 191, 0.16);
  border-color: rgba(45, 212, 191, 0.45);
  color: var(--accent-bright);
}
.btn-danger {
  background: linear-gradient(135deg, #dc2626, var(--danger));
  border-color: transparent; color: #fff;
  box-shadow: 0 8px 26px rgba(239, 68, 68, 0.3);
}
.btn-danger:hover { filter: brightness(1.08); }

/* ============================================================
   Toasts
   ============================================================ */
.toasts {
  position: fixed; z-index: 60;
  left: 50%; transform: translateX(-50%);
  bottom: calc(6.2rem + var(--sab));
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 0.6rem;
  background: rgba(26, 34, 53, 0.95);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  font-size: 0.9rem; font-weight: 500;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.22s ease;
  max-width: 100%;
}
.toast.leaving { animation: toast-out 0.25s ease forwards; }
.toast-ok { border-color: rgba(45, 212, 191, 0.45); }
.toast-err { border-color: rgba(239, 68, 68, 0.5); }
.toast .btn { font-size: 0.82rem; padding: 0.35rem 0.7rem; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.97); } }

/* ============================================================
   Privacy dialog
   ============================================================ */
.privacy-dialog {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  padding: 0;
  width: min(92vw, 620px);
  max-height: min(86dvh, 780px);
  margin: auto;
}
.privacy-dialog::backdrop { background: rgba(4, 6, 10, 0.7); backdrop-filter: blur(4px); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1.15rem 1.3rem 0.9rem;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
  background: var(--bg-elev);
}
.dialog-head h2 { font-size: 1.22rem; letter-spacing: -0.01em; }
.dialog-body {
  padding: 1.1rem 1.3rem 1.4rem;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 1.15rem;
}
.dialog-body h3 { font-size: 0.98rem; color: var(--accent-bright); margin-bottom: 0.35rem; }
.dialog-body p, .dialog-body li { color: var(--text-muted); font-size: 0.92rem; line-height: 1.6; }
.dialog-body ul { padding-left: 1.2rem; display: flex; flex-direction: column; gap: 0.4rem; }

/* ============================================================
   Small screens / large controls
   ============================================================ */
@media (max-width: 640px) {
  .btn-ctl { min-width: 68px; padding: 0.55rem 0.6rem; }
  .call-header { padding: 0.5rem 0.65rem; }
  .conn-status { display: none; }
  .hero-actions .btn { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
