/* ==========================================================================
   Theme tokens — light by default, dark via system preference or toggle.
   [data-theme] on <html> (set by the toggle) overrides the system setting.
   ========================================================================== */
/* Colour themes (Settings → Appearance): every brand colour above is derived from these,
   so a theme is just a hue pair (+ saturation / lightness shift) and works in light and dark. */
/* Not limited to :root, so a swatch with data-palette previews its theme (each sets all four). */
:root, [data-palette='violet'] { --p-h: 240; --a-h: 276; --sat: 1; --p-l: 0%; }
[data-palette='ocean'] { --p-h: 204; --a-h: 178; --sat: 1; --p-l: 0%; }
[data-palette='forest'] { --p-h: 152; --a-h: 92; --sat: 1; --p-l: -14%; }
[data-palette='sunset'] { --p-h: 16; --a-h: 336; --sat: 1; --p-l: -6%; }
[data-palette='rose'] { --p-h: 336; --a-h: 286; --sat: 1; --p-l: -4%; }
[data-palette='graphite'] { --p-h: 222; --a-h: 222; --sat: 0.14; --p-l: -24%; }
/* Larger text for comfort: everything sized in rem grows with it. */
:root[data-text='large'] { font-size: 112.5%; }

:root {
  --bg: #f3f5fb;
  --bg-elev: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.72);
  --bg-input: #f6f7fc;
  --bg-hover: #eef0f9;
  --surface-2: #eceef7;
  --surface-2-hover: #e0e3f1;
  --border: #e2e5f0;
  --border-strong: #cfd3e4;
  --text: #151a30;
  --muted: #646b88;
  --primary: hsl(var(--p-h) calc(90% * var(--sat)) calc(66% + var(--p-l)));
  --primary-hover: hsl(var(--p-h) calc(78% * var(--sat)) calc(60% + var(--p-l)));
  --accent: hsl(var(--a-h) calc(90% * var(--sat)) calc(63% + var(--p-l)));
  --primary-soft: hsl(var(--p-h) calc(90% * var(--sat)) calc(66% + var(--p-l)) / 0.12);
  --on-primary: #ffffff;
  --success: #16a34a;
  --danger: #e5484d;
  --danger-hover: #d63c41;
  --warning: #e08a00;
  --error-bg: rgba(229, 72, 77, 0.08);
  --error-border: rgba(229, 72, 77, 0.35);
  --error-text: #b4232a;
  --author: hsl(var(--p-h) calc(75% * var(--sat)) calc(52% + var(--p-l)));
  --stage-bg: #0c0f1d;
  --tile-bg: #181c33;
  --overlay: rgba(10, 12, 24, 0.6);
  --backdrop: rgba(20, 24, 45, 0.45);
  --blob-1: hsl(var(--p-h) calc(90% * var(--sat)) calc(66% + var(--p-l)) / 0.22);
  --blob-2: hsl(var(--a-h) calc(90% * var(--sat)) calc(63% + var(--p-l)) / 0.18);
  --blob-3: rgba(34, 197, 158, 0.14);
  --shadow-sm: 0 1px 2px rgba(20, 26, 60, 0.06);
  --shadow: 0 1px 2px rgba(20, 26, 60, 0.05), 0 8px 24px rgba(20, 26, 60, 0.08);
  --shadow-lg: 0 20px 50px rgba(20, 26, 60, 0.18);
  --gradient: linear-gradient(135deg, var(--primary), var(--accent));
  --radius: 16px;
  --tabbar-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b0e1a;
    --bg-elev: #141829;
    --bg-glass: rgba(20, 24, 41, 0.72);
    --bg-input: #0f1222;
    --bg-hover: #1c2137;
    --surface-2: #222842;
    --surface-2-hover: #2c3352;
    --border: #232945;
    --border-strong: #323a5c;
    --text: #e8eaf5;
    --muted: #9095b2;
    --primary: hsl(var(--p-h) calc(100% * var(--sat)) calc(72% + var(--p-l)));
    --primary-hover: hsl(var(--p-h) calc(100% * var(--sat)) calc(76% + var(--p-l)));
    --accent: hsl(var(--a-h) calc(100% * var(--sat)) calc(70% + var(--p-l)));
    --primary-soft: hsl(var(--p-h) calc(100% * var(--sat)) calc(72% + var(--p-l)) / 0.16);
    --success: #22c55e;
    --danger: #ef4c52;
    --danger-hover: #f26368;
    --warning: #f5a524;
    --error-bg: rgba(239, 76, 82, 0.12);
    --error-border: rgba(239, 76, 82, 0.4);
    --error-text: #fca5a8;
    --author: hsl(var(--p-h) calc(84% * var(--sat)) calc(85% + var(--p-l)));
    --stage-bg: #070914;
    --tile-bg: #151a30;
    --backdrop: rgba(4, 6, 14, 0.7);
    --blob-1: hsl(var(--p-h) calc(100% * var(--sat)) calc(72% + var(--p-l)) / 0.28);
    --blob-2: hsl(var(--a-h) calc(100% * var(--sat)) calc(70% + var(--p-l)) / 0.22);
    --blob-3: rgba(34, 197, 158, 0.12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #0b0e1a;
  --bg-elev: #141829;
  --bg-glass: rgba(20, 24, 41, 0.72);
  --bg-input: #0f1222;
  --bg-hover: #1c2137;
  --surface-2: #222842;
  --surface-2-hover: #2c3352;
  --border: #232945;
  --border-strong: #323a5c;
  --text: #e8eaf5;
  --muted: #9095b2;
  --primary: hsl(var(--p-h) calc(100% * var(--sat)) calc(72% + var(--p-l)));
  --primary-hover: hsl(var(--p-h) calc(100% * var(--sat)) calc(76% + var(--p-l)));
  --accent: hsl(var(--a-h) calc(100% * var(--sat)) calc(70% + var(--p-l)));
  --primary-soft: hsl(var(--p-h) calc(100% * var(--sat)) calc(72% + var(--p-l)) / 0.16);
  --success: #22c55e;
  --danger: #ef4c52;
  --danger-hover: #f26368;
  --warning: #f5a524;
  --error-bg: rgba(239, 76, 82, 0.12);
  --error-border: rgba(239, 76, 82, 0.4);
  --error-text: #fca5a8;
  --author: hsl(var(--p-h) calc(84% * var(--sat)) calc(85% + var(--p-l)));
  --stage-bg: #070914;
  --tile-bg: #151a30;
  --backdrop: rgba(4, 6, 14, 0.7);
  --blob-1: hsl(var(--p-h) calc(100% * var(--sat)) calc(72% + var(--p-l)) / 0.28);
  --blob-2: hsl(var(--a-h) calc(100% * var(--sat)) calc(70% + var(--p-l)) / 0.22);
  --blob-3: rgba(34, 197, 158, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9375rem; /* 15px; rem so "Large text" (Settings) scales it */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.25s, color 0.25s;
}

h1, h2 { margin: 0; }
h2 { font-size: 0.95rem; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
[hidden] { display: none !important; }
svg { fill: currentColor; }
::selection { background: var(--primary-soft); }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ==========================================================================
   Controls
   ========================================================================== */
input[type='text'],
input[type='password'] {
  width: 100%;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
input::placeholder { color: var(--muted); opacity: 0.8; }
input:focus { border-color: var(--primary); background: var(--bg-elev); box-shadow: 0 0 0 4px var(--primary-soft); }
input:disabled { opacity: 0.5; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  transition: background 0.15s, box-shadow 0.15s, opacity 0.15s, transform 0.08s, filter 0.15s;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, .ctrl-btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary {
  background: var(--gradient);
  color: var(--on-primary);
  box-shadow: 0 4px 14px -4px var(--primary);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 6px 18px -4px var(--primary); }
.btn-secondary { background: var(--surface-2); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-hover); }
.btn-small { padding: 5px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.icon-btn[data-status='on'] { color: var(--on-primary); background: var(--gradient); border-color: transparent; }
.icon-btn[data-status='denied'] { opacity: 0.5; }

/* Theme toggle: show the icon of the theme you would switch to. */
.theme-btn .icon-sun { display: none; }
.theme-btn.is-dark .icon-sun { display: block; }
.theme-btn.is-dark .icon-moon { display: none; }

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
  padding: 1px 8px;
  border-radius: 999px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 18px;
  background: var(--gradient);
  color: #fff;
  font-weight: 800;
  font-size: 1.7rem;
  box-shadow: 0 10px 30px -8px var(--primary);
}
.brand-mark.small { width: 30px; height: 30px; border-radius: 9px; font-size: 0.95rem; box-shadow: none; }
.brand-name {
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.avatar {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  position: relative;
}
.avatar[data-hue] { background: linear-gradient(135deg, hsl(var(--h) 75% 62%), hsl(calc(var(--h) + 40) 70% 55%)); }
/* Profile pictures cover the initial (presence/status dots stay on top). */
.avatar-img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.has-img { color: transparent; }
.tile-avatar { position: relative; overflow: visible; }

/* Settings → Profile */
.profile-row { display: flex; align-items: center; gap: 12px; padding: 4px 10px 8px; }
.profile-avatar { width: 52px; height: 52px; font-size: 1.2rem; }
.profile-actions { display: grid; gap: 6px; justify-items: start; }
.settings-menu .profile-actions .btn { display: inline-flex; padding: 5px 12px; }
.menu-note { margin: 2px 10px 6px; font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.menu-note strong { color: var(--text); }
.menu-link { display: grid; padding: 9px 10px; border-radius: 10px; color: var(--text); font-weight: 500; text-decoration: none; }
.menu-link:hover { background: var(--bg-hover); }
.menu-link small { color: var(--muted); font-weight: 400; font-size: 0.75rem; }
button.menu-link { width: 100%; border: none; background: none; font: inherit; text-align: left; cursor: pointer; }
.recovery-form { display: grid; gap: 12px; }
.recovery-field { display: grid; gap: 6px; }
.recovery-field[hidden] { display: none; }
.recovery-field label { font-size: 0.85rem; font-weight: 600; }
.recovery-form .hint:empty { display: none; }
.recovery-form .dialog-actions .btn { min-height: 44px; }
/* Settings → "Scan QR to sign in a device": a real, easy-to-hit button. */
.settings-menu .link-device-btn { margin: 2px 4px 6px; width: auto; min-height: 44px; }
.link-device-btn svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

/* ==========================================================================
   Landing
   ========================================================================== */
body.landing {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow-x: hidden;
}
.bg-blobs { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bg-blobs span {
  position: absolute;
  width: 46vmax;
  height: 46vmax;
  border-radius: 50%;
  filter: blur(60px);
  animation: drift 22s ease-in-out infinite alternate;
}
.bg-blobs span:nth-child(1) { background: var(--blob-1); top: -18vmax; left: -12vmax; }
.bg-blobs span:nth-child(2) { background: var(--blob-2); bottom: -20vmax; right: -14vmax; animation-delay: -7s; }
.bg-blobs span:nth-child(3) { background: var(--blob-3); top: 40%; left: 55%; width: 28vmax; height: 28vmax; animation-delay: -14s; }

.landing-theme { position: fixed; top: max(16px, env(safe-area-inset-top)); right: 16px; z-index: 2; }
.landing-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  padding: 40px 34px 34px;
  background: var(--bg-glass);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.landing-card h1 { margin-top: 18px; font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; }
.tagline { color: var(--muted); margin: 6px 0 26px; }
.feature-pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: -10px 0 26px; }
.feature-pills span {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}
#id-form { text-align: left; display: grid; gap: 6px; }
#id-form label { font-weight: 600; font-size: 0.9rem; }
#id-form input { font-size: 1.05rem; padding: 13px 15px; }
#id-form .pin-input { letter-spacing: 0.7em; text-align: center; font-size: 1.4rem; font-weight: 700; padding-left: calc(15px + 0.35em); }
#id-form .btn-block { margin-top: 6px; padding: 13px; font-size: 1rem; }
.hint { margin: 0 0 8px; font-size: 0.82rem; color: var(--muted); min-height: 1.5em; }

/* ---------- Continue with Google ---------- */
.btn-google {
  margin-top: 22px;
  background: #fff;
  color: #1f1f1f;
  border-color: #dadce0;
  text-decoration: none;
  gap: 10px;
}
.btn-google:hover { background: #f8f9fa; border-color: #c6c9cf; }
.btn-google svg { width: 20px; height: 20px; }
.or-divider { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; color: var(--muted); font-size: 0.8rem; }
.or-divider::before, .or-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* Sign in with a QR code */
.qr-signin { margin-top: 12px; }
.android-get { margin-top: 12px; }
/* /get-app: Android browsers are sent here (Call9me on Android is the app) */
.get-app h1 { font-size: 1.7rem; }
.get-app .btn svg { width: 20px; height: 20px; }
.get-app-meta { margin: 8px 0 14px; color: var(--muted); font-size: 0.8rem; }
.get-app-steps { margin: 20px 0 0; padding-left: 22px; text-align: left; font-size: 0.9rem; line-height: 1.6; }
.get-app-steps li + li { margin-top: 6px; }
.get-app-steps strong, .get-app-help strong { color: var(--primary); }
.get-app-help { margin-top: 18px; text-align: left; font-size: 0.85rem; line-height: 1.55; color: var(--muted); }
.get-app-help summary { cursor: pointer; color: var(--text); font-weight: 600; text-align: center; }
.get-app-help ul { margin: 10px 0 0; padding-left: 18px; }
.get-app-help li + li { margin-top: 8px; }
.android-get svg { width: 20px; height: 20px; color: #3ddc84; }
.qr-panel { display: grid; gap: 8px; justify-items: center; text-align: center; }
.qr-panel[hidden] { display: none; }
/* Always dark on white: cameras can't read a dark-mode code. */
.qr-code { width: min(240px, 70vw); aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: #fff; box-shadow: var(--shadow-lg); transition: opacity 0.2s; }
.qr-code svg { display: block; width: 100%; height: 100%; }
.qr-code.is-expired { opacity: 0.25; }
.qr-code-text { margin: 4px 0 0; font: 700 1.35rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.12em; }
.google-form { margin-top: 20px; text-align: left; }
.google-signed { margin: 0 0 14px; font-size: 0.9rem; color: var(--muted); text-align: center; }
.google-signed strong { color: var(--text); }
.google-form details { margin: 4px 0 10px; }
.google-form summary { cursor: pointer; color: var(--primary); font-size: 0.88rem; font-weight: 600; margin-bottom: 8px; }
.google-cancel { display: block; margin-top: 12px; text-align: center; font-size: 0.85rem; color: var(--muted); }
.link-btn { padding: 0; border: none; background: none; font: inherit; color: var(--primary); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.forgot-link { display: block; margin: 12px auto 0; font-size: 0.85rem; font-weight: 600; }
#forgot-form[hidden], #id-form[hidden], #qr-signin[hidden] { display: none; }
#forgot-form .btn-ghost { margin-top: 8px; }
.hint[data-state='ok'] { color: var(--success); }
.hint[data-state='error'] { color: var(--danger); }
.error-banner {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  font-size: 0.9rem;
}

/* ==========================================================================
   App layout
   ========================================================================== */
body.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at -10% -20%, var(--blob-1), transparent 60%),
    radial-gradient(900px 500px at 110% 120%, var(--blob-2), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--border);
  background: var(--bg-glass);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; letter-spacing: -0.02em; }
.topbar-user { display: flex; align-items: center; gap: 8px; color: var(--muted); min-width: 0; }
.me-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 12px 3px 3px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  min-width: 0;
}
.me-chip .avatar { width: 30px; height: 30px; font-size: 0.8rem; }
.topbar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 600; }
.conn-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg-elev);
  background: var(--warning);
}
.conn-dot[data-state='online'] { background: var(--success); }
.conn-dot[data-state='offline'] { background: var(--danger); }
/* While connected, the dot shows your chosen status (Settings). */
.conn-dot[data-state='online'][data-status='idle'] { background: var(--warning); }
.conn-dot[data-state='online'][data-status='dnd'] { background: var(--danger); }
.conn-dot[data-state='online'][data-status='invisible'] { background: var(--bg-elev); box-shadow: inset 0 0 0 2px var(--muted); }

/* Your chip in the top bar opens Settings. */
button.me-chip { font: inherit; color: inherit; cursor: pointer; text-align: left; transition: background 0.15s, border-color 0.15s; }
button.me-chip:hover { background: var(--bg-hover); border-color: var(--border-strong); }
button.me-chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.me-text { display: grid; min-width: 0; line-height: 1.15; }
.me-status { font-size: 0.7rem; color: var(--muted); white-space: nowrap; }
.settings-menu { left: 0; right: auto; min-width: 260px; }
.menu-heading { margin: 4px 10px 4px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.settings-menu button[role^='menuitem'] { display: flex; align-items: center; gap: 10px; }
.settings-menu button[role^='menuitem'] span:last-child { display: grid; line-height: 1.25; }
.settings-menu small { color: var(--muted); font-weight: 400; font-size: 0.75rem; }
.settings-menu button[aria-checked='true'] { background: var(--primary-soft); }
/* Settings → Appearance */
.settings-menu { max-height: calc(100dvh - 90px); overflow-y: auto; overscroll-behavior: contain; }
.palette-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 2px 6px 8px; }
.swatch {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 8px 4px 6px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.swatch:hover { border-color: var(--border-strong); }
.swatch[aria-checked='true'] { border-color: var(--primary); background: var(--primary-soft); }
.swatch-color {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    hsl(var(--p-h) calc(90% * var(--sat)) calc(62% + var(--p-l))),
    hsl(var(--a-h) calc(90% * var(--sat)) calc(60% + var(--p-l)))
  );
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.text-size-switch { margin: 0 6px 8px; }
.text-size-switch button[aria-checked='true'] { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }

.status-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--success); }
.status-dot[data-status='idle'] { background: var(--warning); }
.status-dot[data-status='dnd'] { background: var(--danger); }
.status-dot[data-status='invisible'] { background: transparent; box-shadow: inset 0 0 0 2px var(--muted); }

.topbar-user { position: relative; }
.notify-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  display: grid;
  min-width: 220px;
  padding: 6px;
  border-radius: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: fade-in 0.15s ease-out;
}
.notify-menu button[role^='menuitem'] {
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.notify-menu button[role^='menuitem']:hover { background: var(--bg-hover); }
#notify-off-btn { color: var(--danger); }

.notify-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: rise 0.3s ease-out;
}
.notify-banner p { flex: 1; min-width: 200px; margin: 0; font-size: 0.88rem; color: var(--muted); }
.notify-banner strong { color: var(--text); }
.notify-banner-actions { display: flex; gap: 8px; margin-left: auto; }

/* Shown while the socket is down: calls can't start and chat can't send until it's back. */
.conn-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 16px 0;
  padding: 8px 10px 8px 14px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 500;
  animation: rise 0.3s ease-out;
}
.conn-banner #conn-banner-text { flex: 1; min-width: 0; }

/* "A new version is available" (see lib/updates.ts); floats above the content and tab bar. */
.update-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 90;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  width: fit-content;
  max-width: 560px;
  margin-inline: auto;
  padding: 10px 10px 10px 16px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  font-weight: 500;
  animation: rise 0.3s ease-out;
}
.update-banner-text { flex: 1 1 200px; }
.update-banner-actions { display: flex; gap: 8px; margin-left: auto; }
/* Clear of the phone tab bar (portrait and landscape); on desktop it just floats a little higher. */
body.app .update-banner { bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); }

/* "Add to Home Screen" invitation (see lib/installHint.ts) */
.install-hint {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 95;
  max-width: 420px;
  margin-inline: auto;
  padding: 16px;
  border-radius: calc(var(--radius) + 4px);
  background:
    linear-gradient(var(--bg-elev), var(--bg-elev)) padding-box,
    var(--gradient) border-box;
  border: 1.5px solid transparent;
  color: var(--text);
  box-shadow: var(--shadow-lg), 0 12px 40px -12px var(--primary);
  animation: rise 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  transition: opacity 0.25s, transform 0.25s;
}
.install-hint.is-leaving { opacity: 0; transform: translateY(12px); }
body.app .install-hint { bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); }
.install-hint-head { display: flex; gap: 14px; align-items: flex-start; }
.install-hint-icon { flex: none; width: 46px; height: 46px; border-radius: 14px; font-size: 1.35rem; }
.install-hint-body { min-width: 0; }
.install-hint-title { margin: 0 0 4px; font-size: 1rem; font-weight: 750; line-height: 1.3; }
.install-hint-text { margin: 0; color: var(--muted); font-size: 0.87rem; line-height: 1.45; }
.install-hint-steps { margin: 10px 0 0; padding-left: 20px; font-size: 0.85rem; line-height: 1.7; }
.install-hint-steps strong { color: var(--primary); }
.install-hint-glyph { width: 16px; height: 16px; vertical-align: -3px; color: var(--primary); }
.install-hint-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.install-hint-go, .install-hint-ok { background: var(--gradient); border: none; }

.conn-spinner {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--warning);
  animation: spin 0.9s linear infinite;
}

.layout {
  flex: 1;
  min-height: 0;
  height: calc(100dvh - 60px);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 350px;
  gap: 16px;
  padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary);
}
.panel-icon svg { width: 16px; height: 16px; }
.panel-hint { margin: -6px 0 0; font-size: 0.8rem; color: var(--muted); }
.empty-state { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 20px 8px; margin: 0; }
.tabbar { display: none; }

/* ---------- Users ---------- */
.users-list { list-style: none; margin: 0 -6px; padding: 0; overflow-y: auto; display: grid; gap: 2px; align-content: start; }
.user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
  animation: fade-in 0.25s ease-out;
}
.user-item:hover, .user-item:focus-visible { background: var(--bg-hover); outline: none; }
.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg-elev);
  background: var(--success);
}
.user-item.busy .presence-dot { background: var(--warning); }
.user-item.idle .presence-dot { background: var(--warning); box-shadow: inset 4px -3px 0 0 var(--bg-elev); }
.user-item.dnd .presence-dot { background: var(--danger); }
.user-item.dnd .user-presence { color: var(--danger); }
.user-item.offline .presence-dot { background: var(--muted); }
.user-item.offline .avatar { opacity: 0.6; }
.user-meta { display: grid; min-width: 0; line-height: 1.25; }
.user-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-presence { font-size: 0.75rem; color: var(--muted); }
.user-item.busy .user-presence { color: var(--warning); }
.user-call-btn { margin-left: auto; }
.users-list { flex: 1 1 0; min-height: 0; }

/* ---------- People panel: Online / Friends / Rooms / Recent ---------- */
.mode-switch.people-switch { grid-template-columns: repeat(4, 1fr); }
/* Room ID on its own line; visibility + Create below (the panel is narrow). */
#room-create-form { flex-wrap: wrap; }
#room-create-id { flex: 1 1 100%; }
#room-create-form .btn { flex: 1; }
.mode-switch.people-switch { gap: 2px; }
.mode-switch.people-switch button { padding: 7px 2px; font-size: 0.78rem; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 3px; white-space: nowrap; }
.seg-count { font-size: 0.7rem; font-weight: 700; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.seg-count.seg-alert { background: var(--danger); color: #fff; }
.people-view { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
.people-view[hidden] { display: none; }
.list-heading { padding: 8px 8px 2px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); list-style: none; }
.person-row { cursor: default; }
.row-actions { display: flex; gap: 6px; margin-left: auto; flex: none; }
.btn.icon-only { padding: 5px 9px; min-width: 32px; font-size: 1rem; line-height: 1; }
.person-row.away .presence-dot { background: var(--border-strong); }
.person-row.friend-request { background: var(--primary-soft); }
.person-row .user-meta { min-width: 0; }
.request-note { display: block; margin-top: 3px; font-size: 0.82rem; font-style: italic; color: var(--text); overflow-wrap: anywhere; white-space: pre-line; }
.request-form { display: grid; gap: 10px; }
.request-message { width: 100%; box-sizing: border-box; resize: vertical; min-height: 90px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-input); color: var(--text); font: inherit; }
.request-message:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.request-count { justify-self: end; color: var(--muted); font-size: 0.75rem; }
/* "Auto-block friend requests" toggle */
.switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.switch-row > span { display: grid; flex: 1; min-width: 0; font-size: 0.88rem; }
.switch-row small { color: var(--muted); font-size: 0.75rem; }
.switch { appearance: none; flex: none; position: relative; width: 42px; height: 24px; margin: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform 0.2s; }
.switch:checked { background: var(--danger); }
.switch:checked::after { transform: translateX(18px); }
.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.person-row.friend-request .presence-dot, .person-row.friend-pending .presence-dot { display: none; }
.room-avatar { font-weight: 800; }
.room-name { display: inline-flex; align-items: center; gap: 5px; }
.room-lock svg { width: 13px; height: 13px; fill: var(--warning); display: block; }
.visibility-toggle[data-visibility='private'] { color: var(--warning); border-color: currentColor; }
.room-row .row-actions .btn { padding-inline: 9px; }
/* Room rows: name on top, actions on their own line (the panel is narrow). */
.room-row { flex-wrap: wrap; }
.room-row .row-actions { flex-basis: 100%; justify-content: flex-end; }
.room-lock.link svg { fill: var(--primary); }
.visibility-toggle[data-visibility='link'] { color: var(--primary); border-color: currentColor; }
.room-header-actions { display: flex; gap: 6px; }
.room-row .row-actions { flex-wrap: wrap; }
.btn-delete { color: var(--danger); }
.btn-delete:hover { color: var(--danger); border-color: currentColor; }

/* ---------- Share dialog ---------- */
.share-dialog {
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.share-dialog[open] { display: flex; flex-direction: column; gap: 8px; animation: rise 0.25s ease-out; }
.share-dialog::backdrop { background: var(--backdrop); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.share-title { margin: 0 0 4px; font-size: 1.05rem; }
.share-section { margin: 6px 0 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.share-friends { list-style: none; margin: 0 -6px; padding: 0; max-height: 240px; overflow-y: auto; display: grid; gap: 2px; }
.share-friend { cursor: pointer; }
.share-friend input { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.share-link-row { display: flex; gap: 8px; }
.share-link-row input { font-size: 0.85rem; }
.share-copy-status { margin: 0; font-size: 0.82rem; color: var(--muted); min-height: 1.2em; }
.share-copy-status[data-state='ok'] { color: var(--success); }
.share-copy-status[data-state='error'] { color: var(--error-text); }
.share-dialog .dialog-actions { margin-top: 8px; }

/* ---------- Join preview, room options, room members ---------- */
.join-meta { margin: 0; font-size: 0.85rem; color: var(--muted); }
.join-note { margin: 0; font-size: 0.82rem; color: var(--muted); }
.join-messages { list-style: none; margin: 0; padding: 8px 10px; max-height: 260px; overflow-y: auto; display: grid; gap: 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.join-messages[hidden] { display: none; }
.join-message { display: flex; gap: 6px; align-items: baseline; min-width: 0; font-size: 0.85rem; }
.join-message-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.join-message time { flex: none; font-size: 0.72rem; color: var(--muted); }
.room-actions-list { display: grid; gap: 14px; }
.settings-section { display: grid; gap: 8px; }
.settings-heading { margin: 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.settings-field { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; }
.settings-label { font-size: 0.85rem; font-weight: 600; }
.settings-hint { margin: 0; font-size: 0.78rem; color: var(--muted); }
.visibility-segment { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 3px; border-radius: 10px; background: var(--surface-2); }
.visibility-segment .btn { min-height: 34px; border: none; background: transparent; color: var(--muted); justify-content: center; }
.visibility-segment .btn[aria-checked='true'] { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }
.visibility-segment .btn[aria-checked='true'][data-visibility='private'] { color: var(--warning); }
.visibility-segment .btn[aria-checked='true'][data-visibility='link'] { color: var(--primary); }
.room-settings-btn { display: inline-flex; align-items: center; gap: 6px; }
.room-settings-btn svg { width: 16px; height: 16px; fill: currentColor; }
/* Room rows now carry just Chat + Call: keep them on the same line as the name. */
.room-row { flex-wrap: nowrap; }
.room-row .row-actions { flex-basis: auto; }
.room-actions-list .btn { justify-content: flex-start; min-height: 44px; }
.link-step { display: grid; gap: 8px; }
.link-step[hidden] { display: none; }
.link-camera { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: #000; }
.link-video { width: 100%; height: 100%; object-fit: cover; }
/* Where to hold the code: the middle 75% (the JS decoder looks there first). */
.link-viewfinder { position: absolute; inset: 12.5%; border: 3px solid rgba(255, 255, 255, 0.9); border-radius: 16px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35); pointer-events: none; }
.link-camera-note { min-height: 1.2em; }
.link-confirm { margin: 0; line-height: 1.45; }
.link-warning { color: var(--error-text); }
.link-dialog input { text-transform: uppercase; letter-spacing: 0.08em; }

/* ---------- Invites from friends ("X shared #room with you") ---------- */
.invite-stack {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 56px);
  left: 16px;
  right: 16px;
  z-index: 95;
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
}
.invite-card {
  pointer-events: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  width: min(440px, 100%);
  padding: 10px 10px 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-lg);
  animation: slide-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.invite-text { flex: 1 1 180px; font-size: 0.9rem; font-weight: 500; }
.invite-detail {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
  font-weight: 400;
  font-size: 0.82rem;
  color: var(--muted);
}
.invite-actions { display: flex; gap: 6px; margin-left: auto; }

/* ---------- Call history ---------- */
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-head h2 { margin: 0; }
.history-list { list-style: none; margin: 0 -6px; padding: 0; flex: 1 1 0; min-height: 0; overflow-y: auto; display: grid; gap: 2px; align-content: start; }
.history-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 12px; animation: fade-in 0.25s ease-out; }
.history-item:hover { background: var(--bg-hover); }
.history-detail { font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-arrow { display: inline-block; width: 1em; text-align: center; font-weight: 700; color: var(--success); }
.history-arrow.dir-outgoing { color: var(--primary); }
.history-arrow.dir-room { color: var(--muted); }
.outcome-missed .user-name, .outcome-missed .history-detail, .outcome-missed .history-arrow { color: var(--danger); }
.outcome-declined .history-arrow, .outcome-unanswered .history-arrow, .outcome-cancelled .history-arrow { color: var(--muted); }
.history-call-btn { margin-left: auto; flex: none; }

/* ---------- Call ---------- */
.dial-form { display: flex; gap: 8px; }
/* Camera on/off for the next call (one Call button; this picks video or audio only). */
.cam-pref { flex: none; padding: 10px 12px; }
.cam-pref svg { width: 20px; height: 20px; fill: currentColor; }
.cam-pref[aria-pressed='true'] { color: var(--primary); }
.cam-pref[aria-pressed='false'] { color: var(--muted); }
.cam-pref[aria-pressed='true'] .cam-off, .cam-pref[aria-pressed='false'] .cam-on { display: none; }
.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}
.mode-switch button {
  border: 0;
  border-radius: 9px;
  padding: 7px 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.mode-switch button.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }
.room-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 8px 8px 12px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  animation: fade-in 0.2s ease-out;
}
.room-banner-label { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-banner-label svg { width: 18px; height: 18px; flex-shrink: 0; }
.room-banner .btn-ghost { color: var(--primary); border-color: currentColor; background: var(--bg-elev); }
.call-status {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  text-align: right;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
}
body.in-call .call-status { background: var(--primary-soft); color: var(--primary); }
.stage {
  position: relative;
  flex: 1;
  min-height: 260px;
  border-radius: 14px;
  background:
    radial-gradient(600px 300px at 50% 0%, hsl(var(--p-h) calc(100% * var(--sat)) 72% / 0.18), transparent 70%),
    var(--stage-bg);
  overflow: hidden;
  isolation: isolate;
}
.stage-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  color: #a4a9c6;
}
.stage-placeholder::before {
  content: '';
  width: 72px;
  height: 72px;
  border-radius: 22px;
  background: var(--gradient) center / cover;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17 10.5V7a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-3.5l4 4v-11l-4 4Z'/%3E%3C/svg%3E") center / 60% no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17 10.5V7a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-3.5l4 4v-11l-4 4Z'/%3E%3C/svg%3E") center / 60% no-repeat;
  opacity: 0.9;
}
.stage[data-state='in-call'] .stage-placeholder { animation: pulse 1.6s ease-in-out infinite; }
.call-timer {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--overlay);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.call-timer::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); animation: pulse 1.6s ease-in-out infinite; }

/* Everyone in the call (us included) gets an equal tile: two people split the stage in halves. */
.remote-grid {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}
.remote-grid[data-count='0'] { display: none; }
.remote-grid[data-count='2'] { --cols: 2; }
.remote-grid[data-count='3'], .remote-grid[data-count='4'] { --cols: 2; }
.remote-grid[data-count='5'], .remote-grid[data-count='6'],
.remote-grid[data-count='7'], .remote-grid[data-count='8'], .remote-grid[data-count='9'] { --cols: 3; }
/* A tall screen (a phone held upright): two people one above the other. */
@media (orientation: portrait) {
  .remote-grid[data-count='2'] { --cols: 1; }
}

.tile {
  position: relative;
  min-height: 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--tile-bg);
  display: grid;
  place-items: center;
  color: #fff;
  cursor: pointer;
  animation: pop-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tile[hidden] { display: none; }
.tile:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
/* Videos ignore taps/clicks so nothing can pause them; the tile handles its own controls. */
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.25s; pointer-events: none; }
.tile:fullscreen { border-radius: 0; background: #000; }
.tile:fullscreen video { object-fit: contain; }
.tile.has-video video { opacity: 1; }
.tile.has-video .tile-avatar { visibility: hidden; }
/* Our own front camera is shown like a mirror. */
.self-tile.is-mirrored video { transform: scaleX(-1); }
.tile-avatar {
  width: clamp(52px, 28%, 104px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(1.3rem, 4vw, 2.4rem);
  font-weight: 800;
  background: linear-gradient(135deg, hsl(var(--h, 240) 75% 62%), hsl(calc(var(--h, 240) + 40) 70% 55%));
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.06), 0 0 0 12px rgba(255, 255, 255, 0.03);
}
.tile-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  gap: 6px;
  align-items: center;
  max-width: calc(100% - 58px);
  padding: 3px 10px;
  border-radius: 8px;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 0.8rem;
}
.tile-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-status { color: #fbbf24; white-space: nowrap; }
.tile-status:empty { display: none; }
/* Bottom right, clear of the stage's own buttons at the top. */
.tile-fullscreen {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: var(--overlay);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.tile:hover .tile-fullscreen, .tile.is-focused .tile-fullscreen { opacity: 1; }

/* Ringing, nobody else here yet: our camera fills the stage behind "Calling…". */
.stage.solo .remote-grid:not([data-count='0']) ~ .stage-placeholder { background: rgba(7, 9, 20, 0.45); color: #fff; }

/*
 * Maximized (tap a tile, or its ⤢ for full screen): it takes the stage and everyone else
 * shrinks to small tiles along the right side, like Discord (along the bottom on an upright
 * phone). Tap it again, or the grid button, to go back to equal tiles.
 */
.stage { --side: clamp(128px, 19%, 240px); --strip: 96px; }
.stage.has-focus .remote-grid {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
}
.stage.has-focus .tile.is-focused {
  position: absolute;
  top: 8px;
  left: 8px;
  bottom: 8px;
  right: calc(var(--side) + 16px);
  background: #000;
}
.stage.has-focus .tile:not(.is-focused) {
  flex: 0 1 auto;
  width: var(--side);
  aspect-ratio: 16 / 9;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}
/* Only the maximized tile: it gets the whole stage. */
.stage.has-focus .remote-grid[data-count='1'] .tile.is-focused { right: 8px; }
.stage.has-focus .remote-grid[data-count='1'] { display: block; }
@media (orientation: portrait) {
  .stage.has-focus .remote-grid { flex-direction: row; align-items: flex-end; justify-content: center; }
  .stage.has-focus .tile.is-focused { right: 8px; bottom: calc(var(--strip) + 16px); }
  .stage.has-focus .tile:not(.is-focused) { width: auto; height: var(--strip); aspect-ratio: 3 / 4; flex: 0 1 auto; min-width: 0; }
}
.tile.is-focused video { object-fit: contain; }

/* The whole call full screen (with its controls): a little more room for the side tiles. */
.call-panel:fullscreen { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--bg); }
.stage.is-fullscreen { --side: clamp(150px, 16%, 280px); --strip: 120px; }
.stage-btn .fs-exit, .stage.is-fullscreen .stage-btn .fs-enter { display: none; }
.stage.is-fullscreen .stage-btn .fs-exit { display: block; }
.stage.has-focus .tile:not(.is-focused) .tile-avatar { width: auto; height: 56%; font-size: 1rem; box-shadow: none; }
.stage.has-focus .tile:not(.is-focused) .tile-fullscreen { display: none; }
.stage.has-focus .tile:not(.is-focused) .tile-label { left: 4px; bottom: 4px; max-width: calc(100% - 8px); padding: 1px 6px; font-size: 0.7rem; }

/* A screen share is a tile of its own (next to the sharer's camera), watched by choice. */
.screen-tile { background: #000; }
.screen-tile video { object-fit: contain; }
.screen-tile::after {
  content: 'Live';
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--danger);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.screen-card {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 12px;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, hsl(var(--h, 240) 45% 30%), #0b0d18 75%);
}
.screen-card p { margin: 0; font-weight: 600; }
.screen-tile.is-watching .screen-card { display: none; }
.stage.has-focus .tile:not(.is-focused) .screen-card p { display: none; }
.stage.has-focus .tile:not(.is-focused) .screen-watch { min-height: 0; padding: 4px 10px; font-size: 0.75rem; }
/* "Stop watching", top middle of a share we're watching. */
.tile-screen-toggle {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: none;
  padding: 6px 12px;
  border: 0;
  border-radius: 9px;
  background: var(--overlay);
  color: #fff;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.screen-tile.is-watching .tile-screen-toggle { display: block; }
.tile-screen-toggle:hover { background: rgba(255, 255, 255, 0.28); }
.stage.has-focus .tile:not(.is-focused) .tile-screen-toggle { display: none; }

/* Layout and minimize buttons, top right of the call. */
.stage-actions { position: absolute; top: 10px; right: 10px; z-index: 4; display: flex; gap: 6px; }
.stage-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 11px;
  background: var(--overlay);
  color: #fff;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.stage-btn[hidden] { display: none; }
.stage-btn svg { width: 22px; height: 22px; fill: currentColor; }
.stage-btn:hover, .stage-btn.active { background: rgba(255, 255, 255, 0.28); }

/* ---------- Full-screen call ---------- */
/* In a call the call covers the whole app; "minimize" (⌄) goes back to the app while it goes on. */
body.in-call:not(.call-minimized) .call-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex !important;
  flex-direction: column;
  gap: 8px;
  height: auto;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: var(--bg);
  animation: none;
}
body.in-call:not(.call-minimized) .call-panel .stage { flex: 1; min-height: 0; }
body.in-call:not(.call-minimized) { overflow: hidden; }

/* Floating pill: back to a minimized call, rejoin one we just left, or move one here from another device. */
.call-return {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 45;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--success, #16a34a);
  color: #fff;
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  animation: rise 0.25s ease-out;
}
.call-return[hidden] { display: none; }
.call-return.is-elsewhere { background: var(--primary); color: var(--on-primary); }
.call-return-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; animation: pulse 1.6s ease-in-out infinite; }
.call-elsewhere { background: var(--primary-soft); }

.call-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 6px;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--surface-2);
  animation: rise 0.25s ease-out;
}
.ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 0;
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, transform 0.08s, color 0.15s;
  touch-action: manipulation;
}
.ctrl-btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.ctrl-btn:hover:not(:disabled) { background: var(--bg-hover); }
.ctrl-btn:active:not(:disabled) { transform: scale(0.96); }
.ctrl-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ctrl-btn.active { background: var(--text); color: var(--bg-elev); }
.ctrl-icon { display: inline-grid; place-items: center; flex-shrink: 0; }
/* Toggles carry an "on" and a slashed "off" icon; aria-pressed="true" means muted / camera off. */
.ctrl-btn .icon-off, .ctrl-btn[aria-pressed='true'] .icon-on { display: none; }
.ctrl-btn[aria-pressed='true'] .icon-off { display: block; }
#mic-btn.active, #cam-btn.active,
#mic-btn.active:hover:not(:disabled), #cam-btn.active:hover:not(:disabled) { background: var(--danger); color: #fff; }
.ctrl-danger, .ctrl-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.ctrl-danger:hover:not(:disabled) { background: var(--danger-hover); }

/* ---------- Chat ---------- */
.room-form, .message-form { display: flex; gap: 8px; }

/* ---------- Emoji ---------- */
.message-form { position: relative; }
.emoji-toggle { flex: none; padding: 8px 10px; }
.emoji-toggle svg { width: 20px; height: 20px; fill: currentColor; display: block; }
.emoji-toggle.active { color: var(--primary); }
.emoji-picker {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 30;
  width: min(340px, 100%);
  max-height: min(360px, 55dvh);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.15s ease-out;
}
.emoji-picker[hidden] { display: none; }
.emoji-tabs { flex: none; }
.mode-switch.emoji-tabs { grid-template-columns: repeat(3, 1fr); }
.emoji-view { overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.emoji-view[hidden] { display: none; }
.emoji-group { margin: 6px 2px 4px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 2px; }
.emoji-btn {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.emoji-btn:hover, .emoji-btn:focus-visible { background: var(--bg-hover); outline: none; }
.emoji-btn img { width: 28px; height: 28px; object-fit: contain; }
.emoji-own { position: relative; display: grid; }
.emoji-remove {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.emoji-own:hover .emoji-remove, .emoji-remove:focus-visible { opacity: 1; }
@media (pointer: coarse) { .emoji-remove { opacity: 1; } }
.emoji-empty { grid-column: 1 / -1; margin: 6px 2px; font-size: 0.85rem; color: var(--muted); }
.emoji-add { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); display: grid; gap: 8px; }
.emoji-add .emoji-group { margin: 0 2px; }
.emoji-add-row { display: flex; align-items: center; gap: 8px; }
.emoji-add-row input[type='text'] { padding: 7px 10px; }
.emoji-preview { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; background: var(--surface-2); }
.emoji-preview[hidden] { display: none; }
/* Stickers: our own collection in the picker, and big pictures in chat */
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.sticker-btn { display: grid; place-items: center; aspect-ratio: 1; padding: 4px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; }
.sticker-btn:hover, .sticker-btn:focus-visible { background: var(--bg-hover); outline: none; }
.sticker-btn img { width: 100%; height: 100%; object-fit: contain; }
.msg-sticker { display: block; width: min(160px, 45vw); height: auto; max-height: 180px; object-fit: contain; margin-top: 2px; }
.msg-mine .msg-sticker { margin-left: auto; }
.msg-sticker-gone { font-style: italic; color: var(--muted); }

/* ---------- @mentions ---------- */
.mention { font-weight: 600; color: var(--primary); }
.mention-me { padding: 0 3px; border-radius: 5px; background: var(--primary-soft); }
.msg-mine .mention { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg-mine .mention-me { background: rgba(255, 255, 255, 0.22); }
/* A message that tags you: highlighted bubble */
.msg-text.msg-mentions-me { border-color: var(--warning); box-shadow: inset 3px 0 0 var(--warning); }
.mention-list {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 31;
  width: min(260px, 100%);
  margin: 0;
  padding: 4px;
  list-style: none;
  border-radius: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.mention-list[hidden] { display: none; }
.mention-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.mention-list li .avatar { width: 26px; height: 26px; font-size: 0.7rem; }
.mention-list li.active, .mention-list li:hover { background: var(--primary-soft); }
/* In messages */
.emoji-custom { width: 1.5em; height: 1.5em; object-fit: contain; vertical-align: -0.4em; margin: 0 1px; }
.msg-text.msg-jumbo { font-size: 2.2rem; line-height: 1.15; background: transparent; border-color: transparent; padding: 2px 4px; }
.msg-mine .msg-text.msg-jumbo { background: transparent; color: inherit; }
.msg-jumbo .emoji-custom { width: 1.4em; height: 1.4em; vertical-align: -0.25em; }
.room-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#room-title { font-size: 1rem; }
.room-members { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.78rem; align-items: center; }
.members-label { color: var(--muted); }
.chip { background: var(--surface-2); padding: 2px 9px; border-radius: 999px; font-weight: 500; }
.chip-self { background: var(--primary-soft); color: var(--primary); }
.chip { display: inline-flex; align-items: center; gap: 5px; padding-left: 3px; }
.chip .avatar { width: 18px; height: 18px; font-size: 0.6rem; }

/* ---------- Chats: list of joined rooms ↔ open conversation ---------- */
.chat-view { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }
.chat-view[hidden] { display: none; }
.chat-list { list-style: none; margin: 0 -6px; padding: 0; flex: 1; min-height: 0; overflow-y: auto; display: grid; gap: 2px; align-content: start; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.12s;
}
.chat-item:hover, .chat-item:focus-visible { background: var(--bg-hover); outline: none; }
.chat-item .avatar { width: 42px; height: 42px; font-size: 1rem; }
.chat-public-icon { background: var(--primary-soft) !important; font-size: 1.2rem !important; }
.chat-item.is-public { background: var(--surface-2); margin-bottom: 4px; }
.chat-item.is-public:hover { background: var(--surface-2-hover); }
.chat-item-main { display: grid; gap: 2px; min-width: 0; flex: 1; }
.chat-item-top, .chat-item-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-item-top .user-name { flex: 1; min-width: 0; }
.chat-item-time { flex: none; font-size: 0.72rem; color: var(--muted); }
.chat-item-preview { flex: 1; min-width: 0; font-size: 0.82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.has-unread .chat-item-preview { color: var(--text); font-weight: 500; }
.chat-item-preview.is-typing, .chat-item.has-unread .chat-item-preview.is-typing { color: var(--primary); font-style: italic; font-weight: 500; }

/* "Alice is typing…" above the message box */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 20px;
  margin: -4px 0 2px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.8rem;
  animation: rise 0.2s ease-out;
}
.typing-indicator[hidden] { display: none; }
.typing-text { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.typing-dots { display: inline-flex; gap: 3px; flex: none; }
.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce { 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.chat-item.has-unread .chat-item-time { color: var(--primary); font-weight: 600; }
.chat-unread {
  flex: none;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}
.chat-item.is-muted .chat-unread { background: var(--muted); }
.chat-flag { flex: none; font-size: 0.75rem; line-height: 1; }
.chat-item-more { flex: none; opacity: 0.6; }
.chat-item:hover .chat-item-more, .chat-item-more:focus-visible { opacity: 1; }
.chat-archived { list-style: none; }
.chat-archived-toggle { display: block; width: 100%; margin-top: 6px; border: 0; background: none; text-align: left; cursor: pointer; font-family: inherit; }
.chat-archived-toggle:hover { color: var(--text); }
.chat-back { font-size: 1.1rem; }
.room-header #room-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-readonly {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
.messages {
  flex: 1;
  min-height: 160px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  margin: 0 -4px;
  border-radius: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
}
.msg { max-width: 85%; align-self: flex-start; animation: fade-in 0.2s ease-out; }
.msg-mine { align-self: flex-end; }
.msg-meta { display: flex; gap: 8px; font-size: 0.72rem; color: var(--muted); padding: 0 6px 2px; }
.msg-mine .msg-meta { justify-content: flex-end; }
.msg-author { font-weight: 700; color: var(--author); }
.msg-text {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 16px 16px 16px 6px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}
.msg-mine .msg-text { background: var(--gradient); color: #fff; border-color: transparent; border-radius: 16px 16px 6px 16px; }
.msg-system {
  align-self: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin: 2px 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
}
.messages .empty-state { margin: auto; }

/* ---------- Incoming call dialog ---------- */
.incoming-dialog {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-elev);
  color: var(--text);
  padding: 30px 32px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  width: min(380px, calc(100vw - 32px));
}
.incoming-dialog[open] { animation: rise 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); }
.incoming-dialog::backdrop { background: var(--backdrop); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
#incoming-text { font-size: 1.15rem; font-weight: 700; margin: 18px 0 4px; }
.incoming-sub { color: var(--muted); font-size: 0.9rem; margin: 0 0 22px; min-height: 1em; }
.dialog-actions { display: flex; gap: 12px; justify-content: center; }
.dialog-actions .btn { flex: 1; min-height: 50px; border-radius: 14px; }
/* The caller's picture, ringing, with a small phone badge in its corner. */
.incoming-caller { position: relative; width: 96px; height: 96px; margin: 0 auto; }
.avatar.incoming-avatar {
  width: 96px;
  height: 96px;
  font-size: 2.2rem;
  animation: ring 1.2s ease-out infinite;
}
.ring-icon {
  position: absolute;
  right: -4px;
  bottom: -4px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--bg-elev);
  background: var(--success);
  color: #fff;
}
.ring-icon svg { width: 18px; height: 18px; fill: currentColor; animation: wiggle 1.2s ease-in-out infinite; }

/* Calling someone: their picture (replacing the camera icon) while it rings. */
.avatar.stage-callee { width: 112px; height: 112px; font-size: 2.6rem; animation: ring 1.2s ease-out infinite; }
.stage-callee[hidden] { display: none; }
.stage-placeholder.has-callee::before { display: none; }
.stage[data-state='in-call'] .stage-placeholder.has-callee { animation: none; }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 56px);
  right: 16px;
  display: grid;
  gap: 8px;
  z-index: 100;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  padding: 11px 14px 11px 16px;
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 500;
  max-width: 360px;
  transition: opacity 0.3s, transform 0.3s;
  animation: slide-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-leave { opacity: 0; transform: translateX(20px); }
.toast { pointer-events: auto; cursor: pointer; } /* tap to dismiss */

/* ---------- Motion ---------- */
@keyframes pulse { 50% { opacity: 0.55; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ring {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  100% { box-shadow: 0 0 0 26px rgba(34, 197, 94, 0); }
}
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(-14deg); } 30% { transform: rotate(12deg); } 45% { transform: rotate(-8deg); } 60% { transform: rotate(0); } }
@keyframes slide-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes drift { to { transform: translate(6vmax, 4vmax) scale(1.1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   Installed PWA: feel like a native app (no zoom, no text-selection callouts,
   no pull-to-refresh). `.standalone` is set by src/client/lib/zoom.ts.
   ========================================================================== */
html.standalone, html.standalone body {
  touch-action: pan-x pan-y; /* scrolling only: no pinch or double-tap zoom */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html.standalone body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html.standalone :is(input, textarea, .msg-text, .room-banner-label) { -webkit-user-select: text; user-select: text; }
/* iOS zooms into inputs smaller than 16px on focus. */
@media (pointer: coarse) {
  input[type='text'], input[type='password'] { font-size: max(16px, 1em); }
}

/* ==========================================================================
   Tablet
   ========================================================================== */
@media (max-width: 1100px) and (min-width: 721px) {
  .layout { grid-template-columns: 280px minmax(0, 1fr); grid-template-rows: minmax(440px, 1fr) minmax(400px, auto); height: auto; }
  .chat-panel { grid-column: 1 / -1; }
}

/* ==========================================================================
   Phone (portrait, and landscape with little height).
   Must match PHONE_QUERY in src/client/lib/MobileTabs.ts.
   ========================================================================== */
@media (max-width: 720px), (max-height: 520px) and (orientation: landscape) {
  body.app { height: 100dvh; min-height: 0; overflow: hidden; }

  .topbar { padding: max(8px, env(safe-area-inset-top)) 12px 8px; gap: 8px; }
  .topbar-brand > span:last-child { display: none; }
  .me-chip { padding-right: 10px; }
  .topbar-name { max-width: 30vw; }

  .layout {
    display: block;
    height: auto;
    flex: 1;
    min-height: 0;
    padding: 10px max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left));
  }
  .layout > .panel { display: none; height: 100%; padding: 14px; animation: fade-in 0.2s ease-out; }
  body[data-tab='users'] .users-panel,
  body[data-tab='call'] .call-panel,
  body[data-tab='chat'] .chat-panel { display: flex; }

  /* Comfortable touch targets; 16px inputs stop iOS from zooming on focus. */
  input[type='text'], input[type='password'] { font-size: 16px; padding: 11px 13px; }
  .btn { min-height: 44px; }
  .btn-small { min-height: 36px; }
  .user-item { padding: 10px 8px; }
  .avatar { width: 40px; height: 40px; }
  .users-panel .panel-hint { display: none; }

  .dial-form .btn { padding: 10px 12px; }
  .stage { min-height: 0; border-radius: 14px; }
  .call-panel .panel-head h2 { display: none; }
  .call-panel .panel-head { justify-content: center; }
  .call-status { text-align: center; }

  .remote-grid[data-count='5'], .remote-grid[data-count='6'] { --cols: 2; }
  .stage { --side: clamp(96px, 22%, 160px); --strip: 80px; }

  .tile-fullscreen { opacity: 1; }

  /* Phone call controls: big round icons with a caption underneath, so mute/camera state is obvious. */
  .call-controls { gap: 10px; flex-wrap: nowrap; align-items: flex-start; background: transparent; padding: 0; }
  .call-controls .ctrl-btn,
  .call-controls .ctrl-btn:hover:not(:disabled) {
    flex-direction: column;
    gap: 5px;
    min-width: 64px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--muted);
    font-size: 0.72rem;
  }
  .ctrl-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text);
    box-shadow: var(--shadow-sm);
    transition: background 0.15s, color 0.15s, transform 0.08s;
  }
  .ctrl-btn svg { width: 26px; height: 26px; }
  .ctrl-btn:active:not(:disabled) { transform: none; }
  .ctrl-btn:active:not(:disabled) .ctrl-icon { transform: scale(0.92); }
  .call-controls .ctrl-btn.active .ctrl-icon { background: var(--text); color: var(--bg-elev); }
  .call-controls #mic-btn.active .ctrl-icon, .call-controls #cam-btn.active .ctrl-icon { background: var(--danger); color: #fff; }
  /* Only the round icon turns red on phones (the desktop rule colors the whole pill). */
  .call-controls #mic-btn.active, .call-controls #cam-btn.active,
  .call-controls #mic-btn.active:hover:not(:disabled), .call-controls #cam-btn.active:hover:not(:disabled) {
    background: transparent;
    color: var(--danger);
  }
  .ctrl-danger .ctrl-icon { width: 72px; border-radius: 28px; background: var(--danger); color: #fff; }
  .ctrl-label { white-space: nowrap; line-height: 1.2; }

  .messages { min-height: 0; }

  .tabbar {
    display: flex;
    flex-shrink: 0;
    gap: 4px;
    padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    border-top: 1px solid var(--border);
    background: var(--bg-glass);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
  }
  .tabbar button {
    position: relative;
    flex: 1;
    height: calc(var(--tabbar-h) - 12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 0;
    border-radius: 14px;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    touch-action: manipulation;
  }
  .tabbar button svg { width: 22px; height: 22px; }
  .tabbar button.active { color: var(--primary); background: var(--primary-soft); }
  .tab-badge {
    position: absolute;
    top: 3px;
    left: calc(50% + 6px);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    border: 2px solid var(--bg-elev);
    box-sizing: content-box;
  }
  .tab-badge-dot { background: var(--success); min-width: 8px; height: 8px; padding: 0; font-size: 0; top: 7px; }

  .incoming-dialog {
    margin: auto auto 0;
    width: 100%;
    max-width: 100%;
    border-radius: 26px 26px 0 0;
    padding: 28px 20px max(24px, env(safe-area-inset-bottom));
  }

  #toasts { left: 12px; right: 12px; max-width: none; justify-items: center; top: calc(max(8px, env(safe-area-inset-top)) + 56px); }
  .toast { max-width: 100%; }

  .landing-card { padding: 32px 22px 26px; border-radius: 22px; }
}

/* Landscape phones: slimmer chrome so the video gets the height. */
/*
 * Landscape phones: height is what's scarce (~390px). The tab bar becomes a slim rail on
 * the left (clear of the notch), the top bar shrinks, and paddings tighten so chats and
 * call video get the height.
 */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --tabbar-h: 0px; --rail-w: 68px; }
  body.app { padding-left: calc(var(--rail-w) + env(safe-area-inset-left)); }

  .tabbar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 15;
    width: calc(var(--rail-w) + env(safe-area-inset-left));
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) 6px max(8px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    border-top: 0;
    border-right: 1px solid var(--border);
  }
  .tabbar button { flex: 0 0 auto; height: 58px; padding: 0; gap: 2px; font-size: 0.66rem; }
  .tabbar button svg { width: 22px; height: 22px; }
  .tab-badge { top: 2px; left: calc(50% + 4px); }

  /* Compact top bar */
  .topbar { padding: max(4px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 4px 12px; gap: 6px; }
  .topbar .icon-btn { width: 34px; height: 34px; border-radius: 10px; }
  .topbar .btn-small { min-height: 34px; padding: 4px 10px; }
  .me-chip { padding: 2px 10px 2px 2px; }
  .me-chip .avatar { width: 28px; height: 28px; }
  .notify-banner, .conn-banner { margin: 6px 10px 0; padding: 6px 10px; }

  /* Tighter panels and controls */
  .layout { padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) 8px; }
  .layout > .panel { padding: 10px 12px; gap: 8px; border-radius: 14px; }
  .btn { min-height: 36px; padding-block: 6px; }
  .btn-small { min-height: 30px; }
  input[type='text'], input[type='password'] { padding-block: 7px; }
  .mode-switch button { padding-block: 5px; }
  .panel-hint { display: none; }
  .user-item, .chat-item { padding-block: 5px; }
  .avatar, .chat-item .avatar { width: 34px; height: 34px; }

  /* Chats: the conversation gets the height ("here now" is in the header's member count instead). */
  .chat-panel #room-members { display: none; }
  .chat-panel h2 { display: none; }
  .messages { min-height: 0; padding: 8px; }
  .chat-view { gap: 8px; }

  /* Calls: hide everything but the stage while in a call */
  body.in-call .dial-form, body.in-call .room-banner, .call-panel .panel-head { display: none; }
  .call-panel { gap: 8px; }
  .ctrl-icon { width: 46px; height: 46px; }
  .ctrl-danger .ctrl-icon { width: 60px; }
  .ctrl-label { display: none; }

  /* Floating things clear the rail */
  .update-banner, body.app .update-banner, body.app .install-hint { left: calc(var(--rail-w) + env(safe-area-inset-left) + 12px); bottom: 12px; }
  .invite-stack, #toasts { left: calc(var(--rail-w) + env(safe-area-inset-left) + 12px); top: 52px; }
  .emoji-picker { max-height: min(260px, 70dvh); }
}

/* ==========================================================================
   Admin dashboard (/admin)
   ========================================================================== */
body.admin-page { min-height: 100dvh; background: var(--bg); }
.admin-tag { margin-left: 4px; padding: 2px 8px; border-radius: 6px; background: var(--danger); color: #fff; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.admin-who { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin { width: min(1100px, 100%); margin: 0 auto; padding: 16px; box-sizing: border-box; }
.admin-card { padding: 24px; border: 1px solid var(--border); border-radius: 18px; background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.admin-unlock { max-width: 440px; margin: 10vh auto 0; }
.admin-unlock h1 { margin: 0 0 6px; font-size: 1.3rem; }
.admin-unlock-form { display: flex; gap: 8px; margin-top: 14px; }
.admin-unlock-form input { flex: 1; min-width: 0; }
.admin-code { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); overflow-x: auto; font-size: 0.85rem; }
.admin-muted { margin: 0; color: var(--muted); font-size: 0.85rem; }
.admin-dash { display: grid; gap: 14px; }
.admin-tabs { justify-self: start; max-width: 100%; overflow-x: auto; }
.admin-view { display: grid; gap: 10px; }
.admin-view[hidden] { display: none; }
.admin-h2 { margin: 8px 0 0; font-size: 1rem; }
.admin-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.admin-stat { display: grid; gap: 2px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--bg-elev); color: var(--muted); font-size: 0.82rem; }
.admin-stat-value { color: var(--text); font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.admin-stat.is-good .admin-stat-value { color: var(--success); }
.admin-stat.is-warn .admin-stat-value { color: var(--danger); }
.admin-toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-toolbar input { flex: 1; min-width: 180px; }
.admin-toolbar select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-input); color: var(--text); font: inherit; }
.admin-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.admin-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--bg-elev); }
.admin-row.is-warn { border-color: var(--danger); }
.admin-row-main { display: grid; gap: 4px; flex: 1; min-width: 0; }
.admin-row-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.admin-row .admin-muted { overflow-wrap: anywhere; }
.admin-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex: none; max-width: 52%; }
.admin-badge { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 0.72rem; font-weight: 600; }
.admin-badge.is-good { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.admin-badge.is-bad { background: var(--danger); color: #fff; }
.admin-badge.is-warn { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.admin-badge.is-admin { background: var(--primary-soft); color: var(--primary); }
.admin-people summary { cursor: pointer; color: var(--primary); font-size: 0.85rem; font-weight: 600; }
.admin-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.admin-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--surface-2); font-size: 0.85rem; }
.admin-chip.is-banned { text-decoration: line-through; color: var(--muted); }
.admin-chip.is-banned .btn { text-decoration: none; }
.admin-chip .btn-small { min-height: 0; padding: 2px 8px; font-size: 0.75rem; }
.admin-edit { width: min(460px, calc(100vw - 32px)); }
.admin-fields { display: grid; gap: 14px; margin: 12px 0; }
.admin-field { display: grid; gap: 5px; }
.admin-field label { font-size: 0.85rem; font-weight: 600; }
.admin-field input, .admin-field select { padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-input); color: var(--text); font: inherit; }
.admin-field small { font-size: 0.75rem; }
.admin-edit-extra { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
.admin-edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
@media (max-width: 720px) {
  .admin { padding: 10px; }
  .admin-who { display: none; }
  .admin-row { flex-direction: column; align-items: stretch; }
  .admin-actions { max-width: none; justify-content: flex-start; }
}
