:root {
  --bg: #f4f5fb;
  --panel: #ffffff;
  --panel-2: #f7f7fc;
  --text: #16172b;
  --muted: #6b6f86;
  --border: #e8e9f3;
  --primary: #6d5dfc;
  --primary-2: #a855f7;
  --grad: linear-gradient(135deg, #6d5dfc 0%, #a855f7 100%);
  --theirs: #ffffff;
  --theirs-text: #16172b;
  --danger: #f43f5e;
  --success: #22c55e;
  --shadow-sm: 0 1px 2px rgba(22, 23, 43, 0.06);
  --shadow: 0 10px 30px rgba(52, 44, 140, 0.12);
  --chat-bg: #eef0fa;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1020;
    --panel: #171830;
    --panel-2: #1e2040;
    --text: #eceefe;
    --muted: #9a9dc0;
    --border: #272a4d;
    --theirs: #23264a;
    --theirs-text: #eceefe;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    --chat-bg: #12132a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden; /* the app scrolls inside its own panels, never the page */
  overscroll-behavior: none;
  font-family: "Prompt", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

svg { width: 22px; height: 22px; flex-shrink: 0; }

button {
  font: inherit;
  border: none;
  cursor: pointer;
  color: inherit;
  background: none;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}
button:active:not(:disabled) { transform: scale(0.95); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

input {
  font: inherit;
  color: var(--text);
  outline: none;
}

.hidden { display: none !important; }
.sprite { position: absolute; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.captcha { display: flex; justify-content: center; min-height: 65px; }
.error { color: var(--danger); min-height: 1.3em; margin: 0; font-size: 0.9rem; text-align: center; }

.btn-primary {
  background: var(--grad);
  color: #fff;
  font-weight: 600;
  padding: 14px 18px;
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(109, 93, 252, 0.35);
}
.btn-primary:hover { box-shadow: 0 10px 26px rgba(109, 93, 252, 0.5); }

/* ---------------- Avatars ---------------- */
.avatar {
  --size: 44px;
  width: var(--size);
  height: var(--size);
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: calc(var(--size) * 0.4);
  color: #fff;
  background: var(--grad);
  position: relative;
  user-select: none;
}
.avatar.online::after {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--success);
  border: 2.5px solid var(--panel);
}
.avatar.xl { --size: 96px; }
.avatar.xxl { --size: 128px; }

.status-online { color: var(--success); font-size: 0.8rem; }

/* ---------------- Login ---------------- */
.login {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top, 0px);
  height: var(--vv-height, 100dvh);
  overflow-y: auto;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow: hidden;
  background: radial-gradient(1200px 600px at 10% -10%, #c7bfff 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #f0c3ff 0%, transparent 60%), var(--bg);
}
@media (prefers-color-scheme: dark) {
  .login {
    background: radial-gradient(1200px 600px at 10% -10%, #2c2470 0%, transparent 60%),
      radial-gradient(900px 500px at 110% 110%, #4a1d6b 0%, transparent 60%), var(--bg);
  }
}
.login-bg span {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.5;
  background: var(--grad);
  animation: float 12s ease-in-out infinite;
}
.login-bg span:nth-child(1) { width: 260px; height: 260px; top: 8%; left: 6%; }
.login-bg span:nth-child(2) { width: 180px; height: 180px; bottom: 10%; right: 8%; animation-delay: -4s; }
.login-bg span:nth-child(3) { width: 120px; height: 120px; top: 60%; left: 20%; animation-delay: -8s; opacity: 0.3; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(20px, -30px) scale(1.08); }
}

.login-card {
  position: relative;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 36px 28px 28px;
  border-radius: 24px;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

.logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 4px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--grad);
  box-shadow: 0 10px 24px rgba(109, 93, 252, 0.4);
}
.logo svg { width: 34px; height: 34px; }
.login-card h1 { margin: 0; text-align: center; font-size: 1.9rem; letter-spacing: -0.02em; }
.tagline { margin: 0 0 8px; text-align: center; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.field input {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--panel);
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(109, 93, 252, 0.15); }

.lang-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.lang-switch button {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.lang-switch button.active { background: var(--grad); color: #fff; }
.lang-switch.small button { padding: 3px 8px; font-size: 0.7rem; }
.login-lang { position: absolute; top: 16px; right: 16px; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border-radius: 14px;
  background: var(--panel-2);
}
.tab {
  padding: 10px;
  border-radius: 11px;
  font-weight: 500;
  color: var(--muted);
}
.tab.active { background: var(--panel); color: var(--primary); box-shadow: var(--shadow-sm); }

.password-wrap { position: relative; display: flex; }
.password-wrap input { flex: 1; min-width: 0; padding-right: 48px; }
.eye-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.eye-btn:active:not(:disabled) { transform: translateY(-50%) scale(0.95); }
.eye-btn.on { color: var(--primary); }
.eye-btn svg { width: 20px; height: 20px; }

.meter { height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin-top: -6px; }
.meter span { display: block; height: 100%; width: 0; border-radius: inherit; transition: width 0.25s, background 0.25s; }
.note { margin: 0; text-align: center; font-size: 0.78rem; color: var(--muted); }

.features {
  list-style: none;
  margin: 4px 0 0;
  padding: 16px 0 0;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}
.features li { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.features svg { width: 20px; height: 20px; color: var(--primary); }

/* ---------------- Layout ---------------- */
/* Sized to the visible viewport, so the on-screen keyboard never covers the composer. */
.app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top, 0px);
  height: var(--vv-height, 100dvh);
  display: flex;
}

.sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 14px;
}
.me-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.me-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--grad);
}
.brand svg { width: 20px; height: 20px; }

.push-banner {
  margin: 0 16px 12px;
  padding: 12px;
  border-radius: 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  align-items: start;
  background: color-mix(in srgb, var(--primary) 10%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
  animation: rise 0.3s ease both;
}
.push-banner > svg { color: var(--primary); width: 22px; height: 22px; margin-top: 2px; }
.push-banner p { margin: 0; font-size: 0.82rem; line-height: 1.45; }
.push-close { width: 30px; height: 30px; margin: -6px -6px 0 0; color: var(--muted); }
.push-close svg { width: 18px; height: 18px; }
.push-enable { grid-column: 2 / -1; justify-self: end; margin-top: 6px; }

.sidebar-tools { display: flex; gap: 8px; margin: 0 16px 6px; }
.sidebar-tools .search { flex: 1; margin: 0; min-width: 0; }
.add-friend-btn {
  width: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--grad);
  box-shadow: 0 6px 14px rgba(109, 93, 252, 0.3);
}
.sidebar-scroll { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 12px; }
.sidebar-scroll .user-list { overflow: visible; flex: none; padding-bottom: 4px; }

.my-id {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.my-id span:first-child { font-weight: 600; color: var(--primary); }
.my-id svg { width: 13px; height: 13px; opacity: 0.7; }
.my-id:hover { color: var(--text); }
.my-id.big {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  justify-content: center;
  gap: 10px;
}
.my-id.big span:first-child { color: var(--text); font-weight: 600; }
.my-id.big svg { width: 18px; height: 18px; color: var(--primary); opacity: 1; }

.count.alert { background: var(--danger); color: #fff; }
.count:empty { display: none; }
.avatar.offline::after {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #a1a4bd;
  border: 2.5px solid var(--panel);
}
.user-list li.is-offline .name { color: var(--muted); }
.user-sub { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mini-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
}
.mini-btn svg { width: 18px; height: 18px; }
.mini-btn.accept { background: var(--success); }
.mini-btn.decline { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.text-btn { padding: 6px 10px; border-radius: 10px; font-size: 0.8rem; color: var(--muted); border: 1px solid var(--border); }
.text-btn:hover { color: var(--danger); border-color: var(--danger); }
.requests li { cursor: default; }
.btn-primary.small { padding: 9px 14px; font-size: 0.85rem; border-radius: 12px; box-shadow: none; }
.empty small { display: block; }
.empty .btn-primary.small { margin-top: 14px; }
.muted-btn { color: var(--muted); }
.muted-btn:hover:not(:disabled) { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* Add-friend sheet */
.sheet {
  width: min(420px, 100%);
  max-height: calc(var(--vv-height, 100dvh) - 32px);
  overflow-y: auto;
  padding: 20px;
  border-radius: 24px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: rise 0.25s ease both;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h3 { margin: 0; font-size: 1.2rem; }
.sheet-hint { margin: 0; font-size: 0.85rem; color: var(--muted); }
.find-form { display: flex; gap: 8px; }
.find-form input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--panel-2);
}
.find-form input:focus { border-color: var(--primary); }
.find-form .btn-primary { padding: 12px 16px; box-shadow: none; }
.find-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 16px;
  background: var(--panel-2);
  animation: pop 0.2s ease both;
}
.find-result .user-meta small { color: var(--muted); font-variant-numeric: tabular-nums; }
.find-result .btn-primary:disabled { background: var(--border); color: var(--muted); opacity: 1; }
.share-id {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.search {
  margin: 0 16px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1.5px solid transparent;
  transition: border-color 0.2s;
}
.search:focus-within { border-color: var(--primary); }
.search svg { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: none; background: transparent; padding: 11px 0; }

.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 14px 20px 6px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.count {
  background: var(--panel-2);
  color: var(--primary);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.72rem;
}

.user-list { list-style: none; margin: 0; padding: 0 10px 10px; overflow-y: auto; flex: 1; }
.user-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s;
  animation: rise 0.25s ease both;
}
.user-list li:hover { background: var(--panel-2); }
.user-list li.active { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.user-row { display: flex; align-items: baseline; gap: 8px; }
.user-row .name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row time { font-size: 0.72rem; color: var(--muted); }
.preview-row { display: flex; align-items: center; gap: 8px; }
.preview { flex: 1; font-size: 0.83rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview.typing { color: var(--primary); font-style: italic; }
.user-list li.unread .preview { color: var(--text); font-weight: 500; }
.badge {
  background: var(--grad);
  color: #fff;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: grid;
  place-items: center;
}

.empty { padding: 30px 24px; text-align: center; color: var(--muted); }
.empty p { margin: 12px 0 4px; font-weight: 500; color: var(--text); }
.empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}
.empty-icon.big { width: 88px; height: 88px; border-radius: 28px; }
.empty-icon.big svg { width: 44px; height: 44px; }

/* ---------------- Chat ---------------- */
.chat { flex: 1; display: flex; min-width: 0; background: var(--chat-bg); }
.chat-empty { margin: auto; text-align: center; padding: 24px; color: var(--muted); max-width: 360px; }
.chat-empty h2 { color: var(--text); margin: 18px 0 6px; font-size: 1.3rem; }
.chat-empty p { margin: 0; }

.chat-panel { position: relative; flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 1;
}
.peer-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.peer-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-info small.typing { color: var(--primary); }
.peer-info small.offline { color: var(--muted); }

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--primary);
}
.icon-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.back-btn { display: none; color: var(--text); }
.back-btn svg { width: 28px; height: 28px; }

.messages {
  flex: 1;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 20px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.jump-btn {
  position: absolute;
  right: 16px;
  bottom: calc(80px + env(safe-area-inset-bottom));
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: pop 0.2s ease both;
}
.jump-btn.has-new::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--panel);
}
.keyboard-open .jump-btn { bottom: 80px; }
.messages li.msg {
  max-width: min(70%, 520px);
  padding: 9px 14px 7px;
  border-radius: 20px;
  background: var(--theirs);
  color: var(--theirs-text);
  align-self: flex-start;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.45;
  box-shadow: var(--shadow-sm);
  animation: pop 0.2s ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
.messages li.msg.mine {
  background: var(--grad);
  color: #fff;
  align-self: flex-end;
  box-shadow: 0 4px 12px rgba(109, 93, 252, 0.25);
}
/* Bubble grouping: consecutive messages from the same sender */
.messages li.msg:not(.mine).cont { border-top-left-radius: 6px; }
.messages li.msg:not(.mine).has-next { border-bottom-left-radius: 6px; }
.messages li.msg.mine.cont { border-top-right-radius: 6px; }
.messages li.msg.mine.has-next { border-bottom-right-radius: 6px; }
.messages li.msg:not(.cont) { margin-top: 10px; }
.messages li.msg time { display: block; text-align: right; font-size: 0.68rem; opacity: 0.65; margin-top: 2px; }

.messages li.system {
  align-self: center;
  margin: 12px 0;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
}
.messages li.day {
  align-self: center;
  margin: 14px 0 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.composer input {
  flex: 1;
  min-width: 0;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--panel-2);
  transition: border-color 0.2s, box-shadow 0.2s;
}
/* The home-indicator gap is covered by the keyboard, so drop it while typing. */
.keyboard-open .composer { padding-bottom: 10px; }
.chat-header { flex-shrink: 0; }

.composer input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(109, 93, 252, 0.12); }
.send-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--grad);
  box-shadow: 0 6px 16px rgba(109, 93, 252, 0.35);
}
.send-btn svg { width: 20px; height: 20px; margin-left: 3px; }

/* ---------------- Round buttons ---------------- */
.round-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
}
.round-btn svg { width: 28px; height: 28px; }
.round-btn.danger { background: var(--danger); box-shadow: 0 8px 22px rgba(244, 63, 94, 0.45); }
.round-btn.success { background: var(--success); box-shadow: 0 8px 22px rgba(34, 197, 94, 0.45); }
.round-btn.glass {
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.round-btn.glass:hover { background: rgba(255, 255, 255, 0.26); }
.round-btn .off-icon { display: none; }
.round-btn.off { background: #fff; color: #16172b; }
.round-btn.off .on { display: none; }
.round-btn.off .off-icon { display: block; }
.round-btn.ring { animation: ring 1.2s ease-in-out infinite; }
@keyframes ring {
  0%, 100% { transform: rotate(0); }
  10%, 30% { transform: rotate(-14deg); }
  20%, 40% { transform: rotate(14deg); }
  50% { transform: rotate(0); }
}

.pulse { position: relative; display: inline-grid; }
.pulse::before, .pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.5;
  animation: pulse 2s ease-out infinite;
  z-index: -1;
}
.pulse::after { animation-delay: 1s; }
@keyframes pulse { to { transform: scale(1.7); opacity: 0; } }

/* ---------------- Incoming call ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 10, 30, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade 0.2s ease both;
}
@keyframes fade { from { opacity: 0; } }
.incoming-card {
  width: min(340px, 100%);
  padding: 40px 24px 28px;
  border-radius: 28px;
  text-align: center;
  color: #fff;
  background: linear-gradient(160deg, #2a2266 0%, #4c1d95 100%);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.4);
  animation: rise 0.3s ease both;
  isolation: isolate;
}
.incoming-card h3 { margin: 26px 0 4px; font-size: 1.4rem; }
.incoming-card p { margin: 0; opacity: 0.8; }
.incoming-actions { display: flex; justify-content: space-around; margin-top: 32px; }
.incoming-actions > div { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 0.85rem; opacity: 0.95; }

/* ---------------- Active call ---------------- */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  color: #fff;
  background: radial-gradient(900px 600px at 50% 0%, #3b2f8f 0%, #140f33 70%);
  animation: fade 0.25s ease both;
  isolation: isolate;
}
#remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  z-index: -1;
}
#local-video {
  position: absolute;
  right: 16px;
  top: calc(76px + env(safe-area-inset-top));
  width: min(28vw, 200px);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 16px;
  background: #222;
  transform: scaleX(-1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.25);
}
.call-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(18px + env(safe-area-inset-top)) 20px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent);
}
.call-top strong { font-size: 1.1rem; }
.call-top span { font-size: 0.85rem; opacity: 0.8; font-variant-numeric: tabular-nums; }

.call-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  pointer-events: none;
}
.call-status { font-size: 1.05rem; opacity: 0.9; text-align: center; padding: 0 16px; }

/* Video call once connected: hide avatar, show remote video */
.call-overlay.video.connected .call-center .pulse { display: none; }
.call-overlay:not(.video) video,
.call-overlay.video:not(.connected) #remote-video { visibility: hidden; }
.call-overlay.connected .pulse::before,
.call-overlay.connected .pulse::after { animation: none; opacity: 0; }

.call-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 40px 16px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 22px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent);
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  border-radius: 14px;
  background: #16172b;
  color: #fff;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease both;
}

/* During a call keep toasts clear of the call buttons. */
.call-overlay:not(.hidden) ~ .toast { bottom: calc(130px + env(safe-area-inset-bottom)); }

/* ---------------- Mobile ---------------- */
@media (max-width: 760px) {
  .sidebar { width: 100%; border-right: none; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .chat { display: none; }
  .back-btn { display: grid; }
  .chat-header { padding: 10px 8px; gap: 8px; }
  .messages { padding: 16px 12px; }
  .messages li.msg { max-width: 82%; }
  .composer { padding-left: 12px; padding-right: 12px; }
}
