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

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface-2: #232331;
  --border: #2a2a3a;
  --primary: #6366f1;
  --accept: #22c55e;
  --danger: #ef4444;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  overflow: hidden; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
button:disabled { opacity: .4; cursor: default; }
svg { width: 24px; height: 24px; fill: currentColor; flex-shrink: 0; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

.btn { padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 15px; white-space: nowrap; }
.btn-primary { background: var(--primary); color: white; }

/* ── Avatar ── */
.avatar {
  position: relative; width: var(--size); height: var(--size); border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #7c3aed); overflow: hidden;
  display: grid; place-items: center; flex-shrink: 0;
  font-weight: 700; font-size: calc(var(--size) * .42); color: white;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ── Sign-in ── */
.signin { align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; }
.signin-logo { width: 96px; height: 96px; border-radius: 24px; margin-bottom: 8px; }
.signin h1 { font-size: 28px; }
.signin .subtitle { color: var(--text-dim); margin-bottom: 20px; }
#google-button { min-height: 44px; }
.error { color: var(--danger); max-width: 320px; font-size: 14px; }

/* ── Lobby ── */
.lobby-header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.lobby-greeting { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lobby-greeting strong { font-size: 17px; }
.lobby-greeting span { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { padding: 10px; border-radius: 50%; color: var(--text-dim); }

.lobby-body {
  flex: 1; overflow-y: auto; padding: 8px 16px calc(24px + var(--safe-bottom));
  width: 100%; max-width: 640px; margin: 0 auto;
}
.lobby-body h2 {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); margin: 22px 4px 8px;
}
.empty { color: var(--text-dim); padding: 12px 4px; line-height: 1.5; }

.banner {
  display: flex; align-items: center; gap: 12px; margin-top: 12px;
  padding: 14px; border-radius: var(--radius);
  background: rgba(99, 102, 241, .14); border: 1px solid rgba(99, 102, 241, .4);
}
.banner > div { flex: 1; }
.banner p { font-size: 13px; color: var(--text-dim); margin-top: 2px; line-height: 1.4; }
.banner > svg { color: var(--primary); }
.banner-warn { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .4); }
.banner-warn > svg { color: var(--danger); }
.link-btn { display: block; margin: 12px 4px 0; color: var(--text-dim); font-size: 13px; text-decoration: underline; }

.contacts, .recent { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.contact, .recent-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: var(--radius); padding: 12px;
}
.contact.unreachable { opacity: .6; }
.contact-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.contact-text strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-text span { font-size: 13px; color: var(--text-dim); }

.presence { position: relative; }
.presence.online::after {
  content: ''; position: absolute; right: 1px; bottom: 1px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--accept); border: 3px solid var(--surface);
}

.round-btn {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text);
}
.round-btn.primary { background: var(--primary); color: white; }

.recent-item { padding: 10px 12px; cursor: pointer; }
.recent-icon { color: var(--accept); display: grid; }
.recent-item.missed .recent-icon, .recent-item.missed strong { color: var(--danger); }
.recent-item time { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

/* ── Call ── */
.call { background: #000; overflow: hidden; }

.remote-video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  background: #000; opacity: 0; transition: opacity .3s;
}
.call.remote-video-on .remote-video { opacity: 1; }
.call.remote-screen .remote-video { object-fit: contain; }

.call-backdrop {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center;
  background: radial-gradient(circle at 50% 35%, #2b2b4a, #0f0f13 70%);
  transition: opacity .3s;
}
.call-backdrop h1 { font-size: 28px; margin-top: 12px; }
.call-status { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.call-note { color: var(--text-dim); font-size: 14px; }
.call.remote-video-on .call-backdrop { opacity: 0; pointer-events: none; }

/* Local camera: full-screen preview before connecting, picture-in-picture in a call. */
.local-video {
  position: absolute; object-fit: cover; background: #111;
  opacity: 0; pointer-events: none; transition: all .3s ease;
  inset: 0; width: 100%; height: 100%;
}
.call.mirror .local-video { transform: scaleX(-1); }
.call.local-video-on .local-video { opacity: 1; pointer-events: auto; }
.call.local-video-on:not(.in-call) .call-backdrop {
  background: rgba(0, 0, 0, .45); z-index: 2; text-shadow: 0 1px 6px rgba(0, 0, 0, .6);
}
.call.in-call .local-video {
  inset: auto; top: calc(64px + var(--safe-top)); right: 12px;
  width: 28vw; max-width: 180px; height: auto; aspect-ratio: 3 / 4;
  border-radius: 12px; box-shadow: 0 4px 20px rgba(0, 0, 0, .5); z-index: 3;
}
@media (orientation: landscape) {
  .call.in-call .local-video { width: 22vh; max-width: 200px; aspect-ratio: 4 / 3; }
}
.call.ended .local-video { opacity: 0; }

/* Tap the picture-in-picture to swap it with the big view. */
.call.in-call.swap.local-video-on .local-video {
  inset: 0; width: 100%; height: 100%; max-width: none; border-radius: 0; z-index: 0;
  aspect-ratio: auto; transform: none;
}
.call.in-call.swap.local-video-on.mirror .local-video { transform: scaleX(-1); }
.call.in-call.swap.local-video-on .remote-video {
  inset: auto; top: calc(64px + var(--safe-top)); right: 12px; z-index: 3;
  width: 28vw; max-width: 180px; height: auto; aspect-ratio: 3 / 4; border-radius: 12px;
}

.call-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 4;
  display: none; align-items: center; gap: 10px;
  padding: calc(14px + var(--safe-top)) 16px 24px;
  background: linear-gradient(rgba(0, 0, 0, .55), transparent);
  transition: opacity .3s;
}
.call.in-call.remote-video-on .call-top { display: flex; }
.call-top strong { font-size: 17px; }
.muted-badge { color: var(--danger); display: grid; }
.muted-badge svg { width: 18px; height: 18px; }

.call-controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; justify-content: center; align-items: center; gap: 16px;
  padding: 28px 16px calc(28px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
  transition: opacity .3s, transform .3s;
}
.call.controls-hidden .call-controls,
.call.controls-hidden .call-top { opacity: 0; pointer-events: none; }
.call.controls-hidden .call-controls { transform: translateY(20px); }

.ctl {
  width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, .16); backdrop-filter: blur(8px); color: white;
}
.ctl svg { width: 26px; height: 26px; }
.ctl.off { background: white; color: #111; }
.ctl.active { background: var(--primary); }
.ctl.danger { background: var(--danger); }
.ctl.accept { background: var(--accept); }

.call-controls.incoming { gap: 72px; padding-bottom: calc(56px + var(--safe-bottom)); }
.call-controls.incoming .ctl { width: 72px; height: 72px; }
.call-controls.incoming .ctl svg { width: 32px; height: 32px; }
.call-controls.incoming .ctl.accept { animation: pulse 1.4s infinite; }
.labeled { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 14px; color: var(--text-dim); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); }
  70% { box-shadow: 0 0 0 18px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.unmute-hint {
  position: absolute; z-index: 5; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: white; color: #111; padding: 14px 22px; border-radius: 999px; font-weight: 600;
}

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--surface-2); padding: 12px 18px; border-radius: 999px; z-index: 10;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .4); font-size: 14px;
}

/* ── Connectivity ── */
.conn { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.conn-online .conn-dot { background: var(--accept); }
.conn-connecting .conn-dot { background: #f59e0b; animation: blink 1s infinite alternate; }
.conn-offline { color: var(--danger); }
.conn-offline .conn-dot { background: var(--danger); }
@keyframes blink { to { opacity: .3; } }

.route {
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, .14); color: white; white-space: nowrap;
}
.call-backdrop .route { margin-top: 4px; }
.route-local, .route-direct { background: rgba(34, 197, 94, .25); }
.route-relay { background: rgba(99, 102, 241, .35); }
.route-bad { background: rgba(245, 158, 11, .35); }

.version { margin: 28px 4px 0; text-align: center; font-size: 12px; color: var(--text-dim); opacity: .6; }
