/* ============================================================
   ORBIT — Stylesheet
   Mobile-first. Built and tested down to 280px wide so it works
   on foldable cover screens.

   Sections:
     1. Tokens & reset
     2. Ambient background
     3. Homepage
     4. Search box
     5. Footer
     6. Hidden settings launcher
     7. Access modal
     8. Join card
     9. Chat shell & header
    10. Messages
    11. Composer & emoji tray
    12. Toasts
    13. Animations
    14. Responsive — tablets
    15. Responsive — phones
    16. Responsive — foldable cover screens
   ============================================================ */

/* ------------------------------------------------------------
   1. TOKENS & RESET
   ------------------------------------------------------------ */
:root {
  --bg: #05070f;
  --bg-raise: #0b1020;

  /* Glass surfaces (homepage / modal / join card) */
  --glass: rgba(255, 255, 255, 0.055);
  --glass-hi: rgba(255, 255, 255, 0.09);
  --stroke: rgba(255, 255, 255, 0.11);
  --stroke-soft: rgba(255, 255, 255, 0.06);
  --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.08);

  --text: #eef1f8;
  --text-dim: #9ba6bd;
  --text-faint: #6a7489;

  --indigo: #7c8cff;
  --violet: #b06bff;
  --teal: #2dd4bf;
  --green: #25d366;
  --amber: #fbbf24;
  --rose: #fb7185;

  --grad: linear-gradient(135deg, #7c8cff 0%, #b06bff 100%);
  --grad-soft: linear-gradient(135deg, rgba(124, 140, 255, 0.16), rgba(176, 107, 255, 0.16));

  /* Messenger palette — near-black with two bubble greys */
  --chat-bg: #000000;
  --chat-surface: #17181a;
  --chat-surface-hi: #202124;
  --bub-out: #2f3033;
  --bub-in: #1b1c1e;
  --chat-text: #f2f2f3;
  --chat-dim: #8e8e93;

  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 26px;
  --r-pill: 999px;

  --sh-sm: 0 4px 14px rgba(0, 0, 0, 0.3);
  --sh-md: 0 12px 32px rgba(0, 0, 0, 0.38);
  --sh-lg: 0 28px 70px rgba(0, 0, 0, 0.55);
  --glow: 0 10px 34px rgba(124, 140, 255, 0.4);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Safe areas for notches and rounded phone corners */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  /* Live viewport height; JS keeps this in sync with the keyboard */
  --app-h: 100dvh;
}

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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

button,
input,
textarea {
  font-family: inherit;
}

h1, h2, p, span, a, button {
  overflow-wrap: break-word;
}

::selection {
  background: rgba(124, 140, 255, 0.4);
}

:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: var(--r-pill);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.26);
}

/* ------------------------------------------------------------
   2. AMBIENT BACKGROUND (homepage only)
   ------------------------------------------------------------ */
.bg-orbs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background: var(--bg);
}

.bg-orbs span {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
  will-change: transform;
}

.orb-1 {
  width: 46vmax;
  height: 46vmax;
  top: -16vmax;
  left: -12vmax;
  background: radial-gradient(circle, #4f5bd5 0%, transparent 70%);
  animation: drift1 24s var(--ease) infinite alternate;
}

.orb-2 {
  width: 40vmax;
  height: 40vmax;
  top: -8vmax;
  right: -14vmax;
  background: radial-gradient(circle, #9333ea 0%, transparent 70%);
  animation: drift2 30s var(--ease) infinite alternate;
}

.orb-3 {
  width: 38vmax;
  height: 38vmax;
  bottom: -18vmax;
  left: 28%;
  background: radial-gradient(circle, #0d9488 0%, transparent 70%);
  animation: drift3 27s var(--ease) infinite alternate;
  opacity: 0.4;
}

/* ------------------------------------------------------------
   3. HOMEPAGE
   ------------------------------------------------------------ */
.home-page {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: var(--app-h);
  padding-left: var(--sal);
  padding-right: var(--sar);
  animation: fadeIn 0.5s var(--ease) both;
}

.home-topbar {
  display: flex;
  justify-content: flex-end;
  padding: calc(14px + var(--sat)) 18px 8px;
}

.topbar-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 6px 2px;
  transition: color 0.2s var(--ease);
}
.topbar-link:hover {
  color: var(--text);
}

.btn-signin {
  background: var(--grad);
  border: 0;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--r-pill);
  padding: 0.44rem 1.1rem;
  box-shadow: var(--glow);
  transition: transform 0.2s var(--spring), filter 0.2s var(--ease);
}
.btn-signin:hover,
.btn-signin:focus {
  color: #fff;
  filter: brightness(1.1);
  transform: translateY(-2px);
}
.btn-signin:active {
  transform: scale(0.96);
}

.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 18px 40px;
  text-align: center;
}

.brand-logo {
  margin: 0;
  font-size: clamp(2.8rem, 15vw, 6rem);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1;
  user-select: none;
  animation: popIn 0.7s var(--spring) both;
}
.brand-logo span {
  display: inline-block;
  transition: transform 0.35s var(--spring);
}
.brand-logo:hover span {
  transform: translateY(-7px);
}
.brand-logo .c1 { color: #7c8cff; }
.brand-logo .c2 { color: #fb7185; transition-delay: 0.04s; }
.brand-logo .c3 { color: #fbbf24; transition-delay: 0.08s; }
.brand-logo .c4 { color: #2dd4bf; transition-delay: 0.12s; }
.brand-logo .c5 { color: #b06bff; transition-delay: 0.16s; }

.brand-tagline {
  margin: 14px 0 30px;
  color: var(--text-faint);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  animation: fadeUp 0.7s var(--ease) 0.1s both;
}

/* ------------------------------------------------------------
   4. SEARCH BOX
   ------------------------------------------------------------ */
.search-wrap {
  width: 100%;
  max-width: 600px;
  animation: fadeUp 0.7s var(--ease) 0.18s both;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 54px;
  padding: 0 8px 0 18px;
  background: var(--glass);
  border: 1px solid var(--stroke);
  border-radius: var(--r-pill);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--sh-md), var(--highlight);
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease), background 0.25s var(--ease);
}
.search-box:hover {
  background: var(--glass-hi);
}
.search-box:focus-within {
  border-color: rgba(124, 140, 255, 0.75);
  box-shadow: 0 0 0 4px rgba(124, 140, 255, 0.15), var(--sh-md);
}

.search-icon {
  flex-shrink: 0;
  color: var(--text-faint);
  font-size: 1rem;
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  /* 16px minimum stops iOS from zooming the page on focus */
  font-size: 1rem;
}
.search-input::placeholder {
  color: var(--text-faint);
}

.icon-btn {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.95rem;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.search-divider {
  flex-shrink: 0;
  width: 1px;
  height: 20px;
  background: var(--stroke);
}

.search-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.btn-search {
  flex: 0 1 auto;
  background: var(--glass);
  border: 1px solid var(--stroke-soft);
  color: var(--text-dim);
  font-size: 0.875rem;
  padding: 0.65rem 1.3rem;
  border-radius: var(--r-sm);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--highlight);
  transition: all 0.22s var(--ease);
}
.btn-search:hover {
  color: var(--text);
  background: var(--glass-hi);
  border-color: var(--stroke);
  transform: translateY(-2px);
  box-shadow: var(--sh-sm);
}
.btn-search:active {
  transform: translateY(0) scale(0.98);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 30px;
  animation: fadeUp 0.7s var(--ease) 0.26s both;
}

.chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke-soft);
  color: var(--text-faint);
  font-size: 0.78rem;
  padding: 0.36rem 0.85rem;
  border-radius: var(--r-pill);
  transition: all 0.2s var(--ease);
}
.chip:hover {
  color: var(--text);
  background: rgba(124, 140, 255, 0.14);
  border-color: rgba(124, 140, 255, 0.45);
}

/* ------------------------------------------------------------
   5. FOOTER
   ------------------------------------------------------------ */
.home-footer {
  border-top: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 0.82rem;
  color: var(--text-faint);
  padding-bottom: var(--sab);
}

.footer-top {
  padding: 12px 20px;
  border-bottom: 1px solid var(--stroke-soft);
}

.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 20px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}
.footer-links a {
  color: var(--text-faint);
  text-decoration: none;
  transition: color 0.2s var(--ease);
}
.footer-links a:hover {
  color: var(--text);
}

/* ------------------------------------------------------------
   6. HIDDEN SETTINGS LAUNCHER
   ------------------------------------------------------------ */
.hidden-settings {
  position: fixed;
  right: calc(6px + var(--sar));
  bottom: calc(6px + var(--sab));
  z-index: 1040;
}

.btn-hidden-settings {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(255, 255, 255, 0.13);
  font-size: 10px;
  line-height: 1;
  transition: color 0.25s var(--ease), transform 0.4s var(--spring);
}
.btn-hidden-settings::after {
  display: none;
}
.btn-hidden-settings:hover,
.btn-hidden-settings:focus-visible,
.btn-hidden-settings.show {
  color: var(--indigo);
  transform: rotate(90deg);
}

.mini-menu {
  min-width: 180px;
  padding: 6px;
  background: rgba(24, 25, 28, 0.97);
  border: 1px solid var(--stroke);
  border-radius: var(--r-md);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--sh-lg);
}
.mini-menu .dropdown-item {
  color: var(--text-dim);
  font-size: 0.875rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--r-sm);
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.mini-menu .dropdown-item:hover,
.mini-menu .dropdown-item:focus,
.mini-menu .dropdown-item:active {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}
.mini-menu .dropdown-divider {
  margin: 4px 0;
  border-color: var(--stroke-soft);
}

/* ------------------------------------------------------------
   7. ACCESS MODAL
   ------------------------------------------------------------ */
.glass-modal {
  background: rgba(11, 16, 32, 0.9);
  border: 1px solid var(--stroke);
  border-radius: var(--r-lg);
  backdrop-filter: blur(26px) saturate(150%);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
  box-shadow: var(--sh-lg), var(--highlight);
  color: var(--text);
}

.glass-modal .modal-title {
  font-size: 1.05rem;
  font-weight: 650;
}

.modal-hint {
  margin-bottom: 1.2rem;
  color: var(--text-dim);
  font-size: 0.875rem;
}

.glass-modal .form-label {
  color: var(--text-faint);
  font-size: 0.7rem;
  letter-spacing: 0.09em;
}

.key-group .input-group-text,
.key-group .form-control,
.key-group .btn {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--stroke);
  color: var(--text);
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}
.key-group .form-control {
  font-size: 1rem;
  letter-spacing: 0.1em;
}
.key-group .form-control::placeholder {
  color: var(--text-faint);
}
.key-group .form-control:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(124, 140, 255, 0.75);
  box-shadow: 0 0 0 4px rgba(124, 140, 255, 0.15);
  color: var(--text);
}
.key-group .btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.access-error {
  margin-top: 0.7rem;
  color: var(--rose);
  font-size: 0.85rem;
  animation: fadeIn 0.25s var(--ease) both;
}

.is-invalid-shake {
  animation: shake 0.4s var(--ease);
}
.key-group.is-invalid-shake .form-control,
.key-group.is-invalid-shake .input-group-text {
  border-color: var(--rose);
}

.btn-unlock {
  width: 100%;
  padding: 0.8rem 1rem;
  background: var(--grad);
  border: 0;
  border-radius: var(--r-sm);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 650;
  box-shadow: var(--glow);
  transition: transform 0.2s var(--spring), filter 0.2s var(--ease);
}
.btn-unlock:hover,
.btn-unlock:focus {
  color: #fff;
  filter: brightness(1.08);
  transform: translateY(-2px);
}
.btn-unlock:active {
  transform: scale(0.98);
}

/* ------------------------------------------------------------
   8. JOIN CARD
   ------------------------------------------------------------ */
.join-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 42px 26px 28px;
  text-align: center;
  background: var(--glass);
  border: 1px solid var(--stroke);
  border-radius: var(--r-lg);
  backdrop-filter: blur(26px) saturate(150%);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
  box-shadow: var(--sh-lg), var(--highlight);
  animation: shellIn 0.45s var(--spring) both;
}
.join-card[hidden] {
  display: none;
}

.join-back {
  position: absolute;
  top: 12px;
  left: 12px;
}

.join-icon {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--grad);
  color: #fff;
  font-size: 1.7rem;
  box-shadow: var(--glow);
  animation: pulseGlow 3s ease-in-out infinite;
}

.join-title {
  margin: 0 0 6px;
  font-size: 1.4rem;
  font-weight: 700;
}

.join-sub {
  margin-bottom: 24px;
  color: var(--text-dim);
  font-size: 0.875rem;
}

.join-input {
  width: 100%;
  padding: 13px 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.join-input::placeholder {
  color: var(--text-faint);
}
.join-input:focus {
  border-color: rgba(124, 140, 255, 0.75);
  box-shadow: 0 0 0 4px rgba(124, 140, 255, 0.15);
}
.join-input.is-invalid-shake {
  border-color: var(--rose);
}

.join-warning {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding: 11px 14px;
  text-align: left;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--amber);
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.28);
  border-radius: var(--r-sm);
}
.join-warning[hidden] {
  display: none;
}
.join-warning code {
  padding: 1px 5px;
  color: #fde68a;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 5px;
  font-size: 0.95em;
}

/* ============================================================
   9. CHAT SHELL & HEADER
   Messenger look: pure black canvas with a floating header card
   and a floating composer bar.
   ============================================================ */
.chat-page {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--app-h);
  /*
     Pinned to the visual viewport, not the layout viewport. Mobile browsers
     scroll the layout viewport to reveal a focused input, which would drag
     the header off the top; translating by the offset cancels that out.
  */
  transform: translateY(var(--vv-top, 0px));
  background: var(--chat-bg);
}
.chat-page[hidden] {
  display: none;
}

/* Freezes the page behind the chat so nothing can scroll underneath it. */
body.scroll-locked {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

.chat-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  height: 100%;
  overflow: hidden;
  background: var(--chat-bg);
  color: var(--chat-text);
}
.chat-shell[hidden] {
  display: none;
}

/* Faint doodle wallpaper behind the messages */
.chat-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='0.045' stroke-width='1.6'%3E%3Ccircle cx='26' cy='30' r='9'/%3E%3Ccircle cx='23' cy='27' r='1'/%3E%3Ccircle cx='29' cy='27' r='1'/%3E%3Cpath d='M22 33c2 2.4 6 2.4 8 0'/%3E%3Cpath d='M104 26c-2.6-2.6-6.6-.6-6.6 2.4 0 3.4 4.6 6.2 6.6 7.6 2-1.4 6.6-4.2 6.6-7.6 0-3-4-5-6.6-2.4z'/%3E%3Cpath d='M60 96l4 4 8-9'/%3E%3Ccircle cx='128' cy='104' r='9'/%3E%3Cpath d='M124 101h.01M132 101h.01M124 107c2 2.4 6 2.4 8 0'/%3E%3Cpath d='M36 122l5-10 5 10z'/%3E%3Cpath d='M92 132c-1.8-1.8-4.6-.4-4.6 1.7 0 2.4 3.2 4.3 4.6 5.3 1.4-1 4.6-2.9 4.6-5.3 0-2.1-2.8-3.5-4.6-1.7z'/%3E%3Cpath d='M140 52l3 6 6 .9-4.3 4.2 1 6-5.7-3-5.7 3 1-6-4.3-4.2 6-.9z'/%3E%3Cpath d='M66 52h14M66 58h9'/%3E%3C/g%3E%3C/svg%3E");
  background-repeat: repeat;
}

/* Floating header card */
.chat-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin: calc(10px + var(--sat)) 10px 4px;
  padding: 9px 8px 9px 6px;
  background: var(--chat-surface);
  border-radius: var(--r-lg);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

.header-btn {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--chat-text);
  font-size: 1.15rem;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.header-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}
.header-btn:active {
  transform: scale(0.92);
}
.header-btn::after {
  display: none; /* strip Bootstrap's dropdown caret */
}

.avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #2b3a3a;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 650;
}

.online-dot {
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: transparent;
  border: 2.5px solid var(--chat-surface);
  transition: background 0.3s var(--ease);
}
.online-dot.is-online {
  background: var(--green);
}

.peer-info {
  flex: 1;
  min-width: 0;
}

.peer-name {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.25;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.peer-status {
  display: block;
  font-size: 0.78rem;
  color: var(--chat-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s var(--ease);
}
.peer-status.is-online {
  color: var(--green);
}
.peer-status.is-typing {
  color: var(--green);
}

.header-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0;
}

.conn-banner {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  margin: 0 10px 4px;
  padding: 8px 14px;
  text-align: center;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--amber);
  background: rgba(251, 191, 36, 0.12);
  border-radius: var(--r-md);
  animation: fadeIn 0.25s var(--ease) both;
}
.conn-banner[hidden] {
  display: none;
}

/* ------------------------------------------------------------
   10. MESSAGES
   ------------------------------------------------------------ */
.chat-body {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px 4px;
  scroll-behavior: smooth;
}

/* "Messages auto-delete after 24 hours" pill */
.session-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  margin: 6px auto 12px;
  padding: 9px 18px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--chat-dim);
  background: var(--chat-surface);
  border-radius: var(--r-pill);
}

/* Empty state */
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  padding: 20px 24px;
  text-align: center;
  animation: fadeUp 0.5s var(--ease) both;
}
.chat-empty[hidden] {
  display: none;
}

.chat-empty-icon {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin-bottom: 14px;
  border-radius: 50%;
  background: var(--chat-surface);
  color: var(--chat-dim);
  font-size: 1.45rem;
}

.chat-empty-title {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--chat-dim);
}

.chat-empty-sub {
  margin: 0;
  max-width: 250px;
  font-size: 0.8rem;
  line-height: 1.5;
  color: #6a6a6f;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* "Today" chip */
.day-sep {
  align-self: center;
  margin: 8px 0 12px;
  padding: 5px 14px;
  font-size: 0.75rem;
  font-weight: 500;
  color: #d1d1d6;
  background: var(--chat-surface-hi);
  border-radius: var(--r-pill);
}

.msg-row {
  display: flex;
  animation: bubbleIn 0.3s var(--spring) both;
}
.msg-row.out {
  justify-content: flex-end;
}
.msg-row.in {
  justify-content: flex-start;
}
.msg-row.msg-fade-out {
  animation: msgOut 0.28s var(--ease) both;
  pointer-events: none;
}

@keyframes msgOut {
  to {
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
  }
}

.bubble {
  position: relative;
  max-width: 78%;
  padding: 8px 12px 6px;
  font-size: 0.98rem;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 16px;
}

/* Outgoing — lighter grey, tail on the bottom right */
.bubble-out {
  background: var(--bub-out);
  color: #fff;
}
.msg-row.out.start .bubble {
  border-bottom-right-radius: 4px;
}
.msg-row.out.start .bubble::after {
  content: "";
  position: absolute;
  right: -7px;
  bottom: 0;
  width: 0;
  height: 0;
  border-left: 9px solid var(--bub-out);
  border-bottom: 9px solid transparent;
}

/* Incoming — darker grey, tail on the bottom left */
.bubble-in {
  background: var(--bub-in);
  color: var(--chat-text);
}
.msg-row.in.start .bubble {
  border-bottom-left-radius: 4px;
}
.msg-row.in.start .bubble::after {
  content: "";
  position: absolute;
  left: -7px;
  bottom: 0;
  width: 0;
  height: 0;
  border-right: 9px solid var(--bub-in);
  border-bottom: 9px solid transparent;
}

.bubble-author {
  display: block;
  margin-bottom: 2px;
  font-size: 0.76rem;
  font-weight: 650;
  color: #7fd1b9;
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  font-size: 0.72rem;
  line-height: 1.2;
  color: var(--chat-dim);
}
/* Read ticks sit hard right, the timestamp stays left */
.bubble-meta .bi {
  margin-left: auto;
  font-size: 0.85rem;
  color: #a8b0b8;
}
.bubble-meta .msg-tick.tick-read {
  color: #53bdeb;
}

/* Typing dots */
.typing-indicator {
  margin-top: 10px;
  animation: bubbleIn 0.3s var(--spring) both;
}
.typing-indicator[hidden] {
  display: none;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 14px 16px;
  border-bottom-left-radius: 4px;
}
.typing-bubble::after {
  content: "";
  position: absolute;
  left: -7px;
  bottom: 0;
  width: 0;
  height: 0;
  border-right: 9px solid var(--bub-in);
  border-bottom: 9px solid transparent;
}
.typing-bubble .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8e8e93;
  animation: blink 1.3s infinite ease-in-out;
}
.typing-bubble .dot:nth-child(2) { animation-delay: 0.18s; }
.typing-bubble .dot:nth-child(3) { animation-delay: 0.36s; }

/* ------------------------------------------------------------
   11. COMPOSER & EMOJI TRAY
   ------------------------------------------------------------ */
.chat-composer {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  padding: 6px 10px calc(6px + var(--sab));
}

.composer-bar {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 5px 5px 5px 6px;
  background: var(--chat-surface);
  border-radius: var(--r-lg);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

.composer-btn {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--chat-dim);
  font-size: 1.25rem;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.composer-btn:hover,
.composer-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
/* These use display:grid, so [hidden] needs an explicit override */
.composer-btn[hidden],
.send-btn[hidden] {
  display: none;
}

.composer-input {
  flex: 1;
  min-width: 0;
  /* min-height is a hard floor so a bad measurement can't collapse the box */
  min-height: 40px;
  height: 40px;
  max-height: 110px;
  padding: 9px 8px;
  resize: none;
  overflow-y: auto;
  background: transparent;
  border: 0;
  color: var(--chat-text);
  /* 16px keeps mobile browsers from zooming when focused */
  font-size: 1rem;
  line-height: 1.4;
  outline: none;
}
/* Hide the scrollbar until the message is long enough to actually need it */
.composer-input::-webkit-scrollbar {
  width: 0;
}
.composer-input::placeholder {
  color: #6a6a6f;
}

.send-btn {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--chat-surface-hi);
  color: #fff;
  font-size: 1.05rem;
  transition: transform 0.2s var(--spring), background 0.2s var(--ease), opacity 0.2s var(--ease);
}
.send-btn:hover {
  background: #34363a;
}
.send-btn:active {
  transform: scale(0.9);
}
/* Dimmed rather than [disabled]: a disabled button swallows pointer events,
   which on mobile made taps land on nothing. */
.send-btn.is-empty {
  opacity: 0.45;
}
.send-btn.is-empty:active {
  transform: none;
}

.privacy-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 8px 0 2px;
  font-size: 0.76rem;
  color: #6a6a6f;
}
.privacy-note .bi {
  font-size: 0.72rem;
}

.emoji-tray {
  position: absolute;
  left: 50%;
  bottom: calc(72px + var(--sab));
  width: min(100% - 20px, 500px);
  transform: translateX(-50%);
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  padding: 10px;
  background: var(--chat-surface);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  animation: fadeUp 0.22s var(--spring) both;
}
.emoji-tray[hidden] {
  display: none;
}

.emoji {
  display: grid;
  place-items: center;
  width: 100%;
  height: 42px;
  font-size: 1.25rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.15s var(--ease), transform 0.15s var(--spring);
}
.emoji:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: scale(1.15);
}

/* ------------------------------------------------------------
   12. TOASTS
   ------------------------------------------------------------ */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--sab));
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: calc(100% - 32px);
  max-width: 420px;
  transform: translateX(-50%);
  pointer-events: none;
}

.mini-toast {
  padding: 10px 18px;
  font-size: 0.82rem;
  text-align: center;
  color: #fff;
  background: rgba(32, 33, 36, 0.97);
  border-radius: var(--r-pill);
  box-shadow: var(--sh-md);
  animation: fadeUp 0.25s var(--spring) both;
}
.mini-toast.hide {
  animation: fadeOut 0.3s var(--ease) both;
}

/* ------------------------------------------------------------
   13. ANIMATIONS
   ------------------------------------------------------------ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(8px); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.88); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes shellIn {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes blink {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 10px 30px rgba(124, 140, 255, 0.35); }
  50% { box-shadow: 0 10px 44px rgba(176, 107, 255, 0.6); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes drift1 {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(12vmax, 8vmax) scale(1.15); }
}
@keyframes drift2 {
  from { transform: translate(0, 0) scale(1.1); }
  to { transform: translate(-10vmax, 12vmax) scale(1); }
}
@keyframes drift3 {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8vmax, -10vmax) scale(1.2); }
}

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

/* ------------------------------------------------------------
   14. RESPONSIVE — TABLETS (<= 900px)
   ------------------------------------------------------------ */
@media (max-width: 900px) {
  .chat-shell {
    max-width: none;
  }
  .bubble {
    max-width: 82%;
  }
}

/* ------------------------------------------------------------
   15. RESPONSIVE — PHONES (<= 600px)
   ------------------------------------------------------------ */
@media (max-width: 600px) {
  .home-topbar {
    padding: calc(12px + var(--sat)) 14px 4px;
  }
  .home-main {
    padding: 16px 16px 32px;
  }
  .brand-tagline {
    margin-bottom: 26px;
  }

  /* Stack the two search buttons so neither gets squeezed */
  .search-actions {
    flex-direction: column;
    gap: 8px;
    margin-top: 20px;
  }
  .btn-search {
    width: 100%;
  }

  .footer-bottom {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .footer-links {
    justify-content: center;
    gap: 14px;
  }
  .footer-top {
    text-align: center;
  }

  .join-card {
    margin: 14px;
    padding: 38px 20px 24px;
  }

  .bubble {
    max-width: 84%;
  }
}

/* ------------------------------------------------------------
   16. RESPONSIVE — FOLDABLE COVER SCREENS (<= 400px)
   ------------------------------------------------------------ */
@media (max-width: 400px) {
  .home-topbar nav {
    gap: 0.6rem !important;
  }
  .topbar-link {
    font-size: 0.8rem;
  }
  .btn-signin {
    font-size: 0.78rem;
    padding: 0.38rem 0.85rem;
  }

  .brand-logo {
    font-size: clamp(2.4rem, 17vw, 3.6rem);
  }
  .brand-tagline {
    font-size: 0.82rem;
    margin: 10px 0 20px;
  }

  .search-box {
    height: 50px;
    gap: 6px;
    padding: 0 6px 0 14px;
  }
  .icon-btn {
    width: 34px;
    height: 34px;
  }
  /* Drop the mic and its divider — no room for decoration here */
  .search-divider,
  .search-box .icon-btn:last-child {
    display: none;
  }

  .chip-row {
    margin-top: 22px;
    gap: 6px;
  }
  .chip {
    font-size: 0.72rem;
    padding: 0.3rem 0.7rem;
  }

  .footer-links {
    gap: 10px;
    font-size: 0.75rem;
  }

  /* Chat header has to survive ~280px of width */
  .chat-header {
    gap: 7px;
    margin-left: 8px;
    margin-right: 8px;
    padding: 7px 5px 7px 4px;
  }
  .header-btn {
    width: 34px;
    height: 34px;
    font-size: 1.05rem;
  }
  .avatar {
    width: 40px;
    height: 40px;
    font-size: 0.95rem;
  }
  .peer-name {
    font-size: 0.95rem;
  }
  .peer-status {
    font-size: 0.73rem;
  }

  .bubble {
    max-width: 88%;
    font-size: 0.94rem;
  }

  .chat-body {
    padding-left: 9px;
    padding-right: 9px;
  }

  /* Composer on a foldable cover screen: drop the non-functional attach
     button and tighten everything so the text field keeps real width. */
  .chat-composer {
    padding: 4px 7px calc(4px + var(--sab));
  }
  .composer-bar {
    padding: 4px 4px 4px 5px;
    gap: 0;
  }
  .composer-btn.optional {
    display: none;
  }
  .composer-btn {
    width: 36px;
    height: 36px;
    font-size: 1.12rem;
  }
  .composer-input {
    min-height: 38px;
    height: 38px;
    padding: 9px 6px;
    font-size: 1rem;
  }
  .send-btn {
    width: 38px;
    height: 38px;
    font-size: 1rem;
  }
  .privacy-note {
    margin: 5px 0 1px;
    font-size: 0.7rem;
  }

  .join-card {
    margin: 10px;
    padding: 34px 16px 20px;
  }
  .join-icon {
    width: 58px;
    height: 58px;
    font-size: 1.45rem;
  }
  .join-title {
    font-size: 1.2rem;
  }

  .emoji {
    height: 38px;
    font-size: 1.12rem;
  }
}

/* Very narrow (older Fold covers, ~280px): strip back to the essentials */
@media (max-width: 340px) {
  .bubble {
    max-width: 92%;
  }
  .header-actions #callBtn {
    display: none;
  }
  .composer-btn {
    width: 33px;
    height: 33px;
    font-size: 1.05rem;
  }
  .send-btn {
    width: 36px;
    height: 36px;
  }
  .privacy-note {
    display: none;
  }
}

/* ------------------------------------------------------------
   Short-and-wide screens (small laptops, landscape phones)
   ------------------------------------------------------------ */
@media (max-height: 620px) and (min-width: 601px) {
  .chip-row {
    display: none;
  }
  .brand-tagline {
    margin-bottom: 20px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .chip-row,
  .brand-tagline {
    display: none;
  }
  .brand-logo {
    font-size: 2.4rem;
  }
  .home-main {
    padding-top: 8px;
    padding-bottom: 16px;
  }
}

/* ============================================================
   17. AUDIO / VIDEO CALLS
   ============================================================ */
.call-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: calc(30px + var(--sat)) 24px calc(28px + var(--sab));
  color: #fff;
  background:
    radial-gradient(circle at 50% 28%, rgba(59, 77, 75, 0.82), transparent 38%),
    linear-gradient(180deg, #141719 0%, #050505 72%);
  animation: fadeIn 0.24s var(--ease) both;
}
.call-layer[hidden] {
  display: none;
}
.call-layer.is-video {
  background: #000;
}

.remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  opacity: 0;
  transition: opacity 0.35s var(--ease);
}
.call-layer.is-video .remote-video.has-video {
  opacity: 1;
}

.local-video {
  position: absolute;
  top: calc(18px + var(--sat));
  right: 16px;
  z-index: 2;
  width: min(28vw, 132px);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 18px;
  background: #1b1c1e;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  transform: scaleX(-1);
}
.local-video[hidden] {
  display: none;
}

.call-avatar-wrap {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  margin-bottom: 28px;
}
.call-layer.is-video .call-avatar-wrap {
  opacity: 0.72;
}

.call-avatar {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: linear-gradient(145deg, #344746, #1c2929);
  color: #fff;
  font-size: 2.25rem;
  font-weight: 650;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.call-rings,
.call-rings::before,
.call-rings::after {
  position: absolute;
  inset: -12px;
  content: "";
  border: 1px solid rgba(37, 211, 102, 0.35);
  border-radius: 50%;
  animation: callRing 2.4s ease-out infinite;
}
.call-rings::before {
  inset: -1px;
  animation-delay: 0.8s;
}
.call-rings::after {
  inset: -1px;
  animation-delay: 1.6s;
}
.call-layer.is-active .call-rings,
.call-layer.is-active .call-rings::before,
.call-layer.is-active .call-rings::after {
  animation: none;
  opacity: 0;
}

.call-info {
  position: relative;
  z-index: 2;
  text-align: center;
}
.call-info h2 {
  margin: 0 0 4px;
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  font-weight: 700;
}
.call-info p {
  margin: 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.92rem;
}
.call-info time {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.75);
  font-variant-numeric: tabular-nums;
}
.call-info time[hidden] {
  display: none;
}

.incoming-actions,
.call-controls {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: calc(34px + var(--sab));
  display: flex;
  justify-content: center;
  gap: clamp(28px, 14vw, 70px);
  padding: 0 20px;
}
.incoming-actions[hidden],
.call-controls[hidden] {
  display: none;
}

.call-action,
.call-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-width: 64px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 0.76rem;
}
.call-action .bi,
.call-control .bi {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  font-size: 1.3rem;
  transition: transform 0.18s var(--spring), background 0.18s var(--ease);
}
.call-action:active .bi,
.call-control:active .bi {
  transform: scale(0.9);
}
.call-decline .bi,
.end-call .bi {
  background: #ed4245;
}
.call-accept .bi {
  background: var(--green);
}
.call-control.is-off .bi {
  background: #fff;
  color: #111;
}

.call-layer.is-video .call-info {
  position: absolute;
  top: calc(24px + var(--sat));
  left: 18px;
  right: 160px;
  text-align: left;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

@keyframes callRing {
  0% { opacity: 0.65; transform: scale(0.9); }
  100% { opacity: 0; transform: scale(1.55); }
}

@media (max-width: 400px) {
  .call-avatar {
    width: 92px;
    height: 92px;
    font-size: 1.85rem;
  }
  .call-action .bi,
  .call-control .bi {
    width: 52px;
    height: 52px;
  }
  .call-controls {
    gap: 18px;
  }
  .call-layer.is-video .call-info {
    right: 115px;
  }
  .local-video {
    right: 10px;
    width: 100px;
  }
}
