/* share.black, design tokens.
   The theme is dark-only by design: one look, no light-mode flash, and less light
   from the screen in a private moment. */
:root {
  --bg: #000;
  --text: #f5f5f7;
  --text-2: rgba(235, 235, 245, 0.62);
  --text-3: rgba(235, 235, 245, 0.55);
  --glass: rgba(255, 255, 255, 0.055);
  --glass-hi: rgba(255, 255, 255, 0.1);
  --hairline: rgba(255, 255, 255, 0.09);
  --hairline-hi: rgba(255, 255, 255, 0.16);
  --blue: #0a84ff;
  --blue-2: #0066e0;
  /* Fills behind white text: at least 4.5:1 with #fff (WCAG AA). --blue stays for rings and accents. */
  --accent-fill: #0a6fe0;       /* 4.81:1 */
  --accent-fill-hover: #1673e3; /* 4.57:1 */
  --green: #30d158;
  --orange: #ff9f0a;
  --red: #ff453a;
  --bubble-them: #1f1f22;
  --bubble-me: linear-gradient(180deg, #0a6fe0, #0058c4); /* 4.81:1 to 6.58:1 with #fff */
  --radius-xl: 32px;
  --spring: cubic-bezier(0.32, 0.72, 0, 1);
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui,
          "Segoe UI Variable", "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Roboto Mono", monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 17px/1.4 var(--font);
  letter-spacing: -0.012em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; }

/* Focus rings for keyboard focus (:focus-visible is in every browser the boot gate admits) */
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, [tabindex]:focus-visible:not(h1) {
  outline: 2px solid var(--blue); outline-offset: 3px;
}
h1[tabindex]:focus { outline: none; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

.ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round;
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0; }

/* ---------------------------------------------------------------- ambient light */
.aurora {
  position: fixed; inset: 0;
  z-index: 0; pointer-events: none; overflow: hidden;
  transition: opacity 1s var(--ease);
}
.aurora i {
  position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.55;
  will-change: transform; animation: drift 26s var(--ease) infinite alternate;
}
.aurora i:nth-child(1) { width: 60vmax; height: 60vmax; left: -20vmax; top: -25vmax;
  background: radial-gradient(circle, rgba(10, 132, 255, 0.35), transparent 65%); }
.aurora i:nth-child(2) { width: 50vmax; height: 50vmax; right: -18vmax; top: 10vmax;
  background: radial-gradient(circle, rgba(94, 92, 230, 0.28), transparent 65%); animation-delay: -9s; }
.aurora i:nth-child(3) { width: 55vmax; height: 55vmax; left: 10vmax; bottom: -35vmax;
  background: radial-gradient(circle, rgba(191, 90, 242, 0.16), transparent 65%); animation-delay: -17s; }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(6vmax, 4vmax, 0) scale(1.12); }
}
body[data-screen="chat"] .aurora { opacity: 0.35; }

/* ---------------------------------------------------------------- screens */
#app { display: block; }
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--safe-t) + 20px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 20px);
  opacity: 0; visibility: hidden; transform: scale(0.98); pointer-events: none;
  transition: opacity 0.45s var(--ease), transform 0.6s var(--spring), visibility 0s linear 0.45s;
}
body[data-screen="host"] .screen-host,
body[data-screen="join"] .screen-join,
body[data-screen="connecting"] .screen-connecting,
body[data-screen="chat"] .screen-chat,
body[data-screen="ended"] .screen-ended,
body[data-screen="inapp"] .screen-inapp {
  opacity: 1; visibility: visible; transform: none; pointer-events: auto; z-index: 2;
  transition: opacity 0.45s var(--ease), transform 0.6s var(--spring), visibility 0s;
}
/* Centered, but tall content starts at the top instead of being clipped */
.screen-host, .screen-join, .screen-ended, .screen-inapp {
  justify-content: center; justify-content: safe center;
  overflow-y: auto; overscroll-behavior: contain;
}
.screen-inner {
  width: 100%; margin-top: auto; margin-bottom: auto; flex: none;
  display: flex; flex-direction: column; align-items: center;
}

/* Pause work nobody can see */
body:not([data-screen="host"]) .screen-host *,
body:not([data-screen="host"]) .screen-host *::before,
body:not([data-screen="host"]) .screen-host *::after,
body:not([data-screen="join"]) .screen-join *,
body:not([data-screen="connecting"]) .screen-connecting *,
body:not([data-screen="chat"]) .screen-chat *,
body:not([data-screen="ended"]) .screen-ended *,
body:not([data-screen="inapp"]) .screen-inapp *,
body[data-screen="chat"] .aurora i,
html.sb-hidden *, html.sb-hidden *::before, html.sb-hidden *::after {
  animation-play-state: paused !important;
}
/* App switcher snapshot: hide anything private */
html.sb-hidden .messages, html.sb-hidden .qr-wrap, html.sb-hidden .link-pill,
html.sb-hidden .lightbox, html.sb-hidden .sheet, html.sb-hidden .typing,
html.sb-hidden .composer, html.sb-hidden .toast, html.sb-hidden .join, html.sb-hidden .gate,
html.sb-hidden .screen-join .screen-inner, html.sb-hidden .screen-inapp .screen-inner,
html.sb-hidden .tray, html.sb-hidden #typed-wrap, html.sb-hidden #sheet-save {
  visibility: hidden !important;
}

/* ---------------------------------------------------------------- host */
.host-inner { gap: 22px; }
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 19px; letter-spacing: -0.02em;
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(145deg, #2a2a2e, #050505);
  box-shadow: inset 0 0 0 1px var(--hairline-hi), 0 0 18px rgba(10, 132, 255, 0.35);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 6px; border-radius: 3px;
  background: linear-gradient(145deg, #fff, #9ab);
}
.brand-name span { color: var(--text-3); font-weight: 500; }

.card {
  width: min(420px, 100%);
  background: var(--glass);
  border-radius: var(--radius-xl);
  box-shadow: inset 0 0 0 1px var(--hairline), 0 30px 80px -20px rgba(0, 0, 0, 0.8);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  backdrop-filter: blur(40px) saturate(180%);
}
.host-card {
  padding: 34px 28px 24px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
/* Tied to the screen so they replay each time the host screen comes back */
body[data-screen="host"] .host-card { animation: rise 0.9s var(--spring) both; }
body[data-screen="host"] .join { animation: rise 0.9s 0.08s var(--spring) both; }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(0.97); } }

.title {
  margin: 0; font-size: clamp(28px, 7vw, 34px); line-height: 1.1;
  font-weight: 700; letter-spacing: -0.035em;
  background: linear-gradient(180deg, #fff 30%, rgba(255, 255, 255, 0.6));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.subtitle { margin: 10px 0 0; color: var(--text-2); font-size: 15px; line-height: 1.45; max-width: 32ch; }

.qr-wrap {
  position: relative; margin: 26px 0 20px;
  width: min(232px, 64vw); aspect-ratio: 1;
  border-radius: 28px; padding: 6px; /* JS draws the 4-module quiet zone */
  background: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4), 0 20px 60px -10px rgba(10, 132, 255, 0.45);
  overflow: hidden;
  transition: transform 0.5s var(--spring), filter 0.5s var(--ease);
}
#qr-wrap.failed { display: none; }
.qr-wrap.loading .qr { opacity: 0; }
.qr-wrap.loading .qr-shimmer { opacity: 1; }
.qr { width: 100%; height: 100%; transition: opacity 0.5s var(--ease); }
.qr svg { display: block; width: 100%; height: 100%; }
.qr-shimmer {
  position: absolute; inset: 0; opacity: 0; transition: opacity 0.4s;
  background: linear-gradient(110deg, #f2f2f4 30%, #fff 50%, #f2f2f4 70%);
  background-size: 250% 100%; animation: shimmer 1.4s linear infinite;
}
.qr-wrap:not(.loading) .qr-shimmer { animation: none; }
@keyframes shimmer { to { background-position: -150% 0; } }
/* Covered by default: the code is never painted until the host asks for it */
.qr-wrap.covered {
  background: var(--glass-hi);
  box-shadow: inset 0 0 0 1px var(--hairline-hi), 0 20px 60px -10px rgba(10, 132, 255, 0.25);
}
.qr-wrap.covered .qr, .qr-wrap.covered .qr-shimmer { visibility: hidden; }
.qr-cover {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  width: 100%; border-radius: inherit;
  font-size: 15px; font-weight: 600; color: var(--text);
  transition: background 0.2s;
}
.qr-cover .ic { width: 28px; height: 28px; color: var(--text-2); }
.qr-cover:focus-visible { outline-offset: -4px; }
.qr-wrap:not(.covered) .qr-cover { display: none; }
.qr-note { margin: -8px 0 0; max-width: 34ch; font-size: 13px; line-height: 1.4; color: var(--text-2); }

.link-pill {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 11px 16px 11px 18px; border-radius: 999px;
  background: var(--glass-hi); box-shadow: inset 0 0 0 1px var(--hairline);
  font-size: clamp(14px, 4.3vw, 19px); font-weight: 500; letter-spacing: -0.01em;
  max-width: 100%; min-height: 44px; white-space: nowrap; overflow: hidden;
  transition: transform 0.25s var(--spring), background 0.2s, opacity 0.2s;
}
.link-pill:active:not(:disabled) { transform: scale(0.96); }
.link-code { font-weight: 600; letter-spacing: 0; color: #fff; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.link-pill .ic { margin-left: 10px; width: 18px; height: 18px; color: var(--text-3); }
.link-pill.no-icon .ic { display: none; }

.host-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; justify-content: center; width: 100%; }
/* Equal halves when they fit, content width when one label is longer, and two full-width rows
   (never a cut label) when they can't share a row. Basis 0 + fit-content minimum gives all three. */
.host-actions .btn {
  flex: 1 1 0; min-width: -webkit-fit-content; min-width: fit-content;
  padding: 0 14px; white-space: nowrap;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 20px; border-radius: 999px;
  font-size: 16px; font-weight: 600; letter-spacing: -0.01em;
  transition: transform 0.25s var(--spring), background 0.2s, opacity 0.2s;
  user-select: none; -webkit-user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn .ic { width: 18px; height: 18px; }
.btn-glass { background: var(--glass-hi); box-shadow: inset 0 0 0 1px var(--hairline); }
.btn-primary { background: var(--accent-fill); color: #fff; box-shadow: 0 8px 30px -8px rgba(10, 111, 224, 0.7); }
.btn-danger { background: var(--red); color: #fff; }
.btn:disabled, .link-pill:disabled { opacity: 0.45; cursor: default; }

.status {
  display: flex; align-items: center; gap: 8px; margin-top: 22px;
  flex-wrap: wrap; justify-content: center; text-align: center;
  font-size: 13px; color: var(--text-2);
}
.dot-sep { color: var(--text-3); }
/* Keep "Waiting for someone to join · 14:59" on one line at 320px */
@media (max-width: 359px) {
  .host-card { padding-left: 20px; padding-right: 20px; }
  .status { gap: 6px; }
  .host-actions .btn { padding: 0 12px; }
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--green); position: relative; flex: none;
}
.pulse::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--green); opacity: 0; animation: ping 2s var(--ease) infinite;
}
@keyframes ping { 0% { transform: scale(0.4); opacity: 0.8; } 100% { transform: scale(1.6); opacity: 0; } }
.host-hint { margin: 10px 0 0; font-size: 13px; color: var(--text-2); }
.link-warn {
  margin: 12px 0 0; max-width: 36ch; padding: 10px 14px; border-radius: 16px;
  font-size: 13px; line-height: 1.4; color: var(--orange);
  background: rgba(255, 159, 10, 0.1); box-shadow: inset 0 0 0 1px rgba(255, 159, 10, 0.25);
}
.btn-typed { margin-top: 12px; height: 40px; font-size: 14px; font-weight: 500; color: var(--text-2); }
.typed-wrap {
  width: 100%; margin-top: 14px; padding-top: 14px; box-shadow: 0 -1px 0 var(--hairline);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.typed-note { margin: 0; max-width: 36ch; font-size: 13px; line-height: 1.4; color: var(--orange); }
.host-notice {
  margin: 12px 0 0; max-width: 36ch; font-size: 13px; line-height: 1.4; color: var(--orange);
  overflow-wrap: anywhere;
}
.private-tip { margin: 16px 0 0; max-width: 36ch; font-size: 12px; line-height: 1.4; color: var(--text-3); }
.join-tip { margin-top: 22px; }
.join-mode { margin: -18px 0 24px; max-width: 34ch; font-size: 14px; line-height: 1.4; color: var(--text-2); }

.join {
  width: min(420px, 100%); display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 8px 8px 22px; border-radius: 999px;
  background: var(--glass); box-shadow: inset 0 0 0 1px var(--hairline);
  -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px);
  transition: box-shadow 0.2s;
}
.join:focus-within { box-shadow: inset 0 0 0 1px var(--hairline), 0 0 0 2px var(--blue); }
.join label { font-size: 15px; color: var(--text-2); white-space: nowrap; flex: none; }
.label-short { display: none; }
.join-field { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex: 1; min-width: 0; }
.join input {
  flex: 1; min-width: 0; width: auto; height: 40px; border: 0; outline: 0; background: transparent;
  font-size: 18px; font-weight: 600; letter-spacing: 0;
  text-align: right; text-transform: lowercase;
}
.join input:focus-visible, .field textarea:focus-visible { outline: 0; } /* wrappers show focus */
.join input::placeholder { color: var(--text-3); font-weight: 500; }
.btn-round {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--glass-hi); transition: transform 0.25s var(--spring), background 0.2s;
  position: relative;
}
.btn-round::before { content: ""; position: absolute; top: -2px; right: -2px; bottom: -2px; left: -2px; }
.btn-round:active { transform: scale(0.9); }
.join.ready .btn-round { background: var(--accent-fill); color: #fff; }
.join-hint { margin: -10px 0 0; max-width: 420px; font-size: 13px; color: var(--text-2); text-align: center; }
.join:has(input[aria-invalid="true"]) + .join-hint { color: var(--orange); }

.fine { font-size: 12px; color: var(--text-2); text-align: center; letter-spacing: 0; }

/* ---------------------------------------------------------------- join landing + ended */
.screen-join, .screen-ended, .screen-inapp { text-align: center; }
.join-icon, .ended-icon {
  --tone-rgb: 48, 209, 88; --tone: var(--green);
  width: 84px; height: 84px; border-radius: 26px; display: grid; place-items: center; margin-bottom: 26px;
  background: linear-gradient(160deg, rgba(var(--tone-rgb), 0.22), rgba(var(--tone-rgb), 0.05));
  box-shadow: inset 0 0 0 1px rgba(var(--tone-rgb), 0.3), 0 20px 60px -10px rgba(var(--tone-rgb), 0.35);
  transition: background 0.3s, box-shadow 0.3s;
}
.join-icon { --tone-rgb: 10, 132, 255; --tone: var(--blue); }
.ended-icon[data-tone="warn"], .inapp-icon { --tone-rgb: 255, 159, 10; --tone: var(--orange); }
.ended-icon[data-tone="bad"] { --tone-rgb: 255, 69, 58; --tone: var(--red); }
.join-icon svg, .ended-icon svg {
  width: 40px; height: 40px; fill: none; stroke: var(--tone); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.ended-icon .ended-warn { display: none; }
.ended-icon[data-tone="warn"] .ended-ok, .ended-icon[data-tone="bad"] .ended-ok { display: none; }
.ended-icon[data-tone="warn"] .ended-warn, .ended-icon[data-tone="bad"] .ended-warn { display: block; }
body[data-screen="ended"] .ended-icon, body[data-screen="join"] .join-icon, body[data-screen="inapp"] .inapp-icon { animation: rise 0.8s var(--spring) both; }
.screen-ended .subtitle, .screen-join .subtitle, .screen-inapp .subtitle { margin-bottom: 30px; }
.ended-actions, .join-actions { display: flex; flex-direction: column; gap: 10px; width: min(320px, 100%); }
.ended-actions .btn, .join-actions .btn { width: 100%; }
#btn-retry:not([hidden]) + #btn-new { background: var(--glass-hi); color: var(--text); box-shadow: inset 0 0 0 1px var(--hairline); }

/* ---------------------------------------------------------------- connecting */
.screen-connecting { justify-content: center; gap: 22px; }
.spinner { width: 54px; height: 54px; position: relative; }
.spinner i {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.1); border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.connecting-text { margin: 0; color: var(--text-2); font-size: 15px; font-weight: 400; line-height: 1.4; letter-spacing: inherit; text-align: center; }
#btn-cancel { min-width: 140px; }

/* ---------------------------------------------------------------- chat */
.screen-chat {
  padding: 0; align-items: stretch;
  top: var(--vv-top, 0px); bottom: auto; height: var(--vvh, 100%);
}
.chat-head {
  position: relative; z-index: 3;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 16px) 10px calc(var(--safe-l) + 16px);
  background: rgba(10, 10, 12, 0.72);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  box-shadow: 0 1px 0 var(--hairline);
}
.peer { display: flex; align-items: center; gap: 12px; min-width: 0; }
.orb {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: conic-gradient(from 210deg, #0a84ff, #5e5ce6, #bf5af2, #0a84ff);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25), 0 0 20px rgba(94, 92, 230, 0.4);
  animation: spin 14s linear infinite;
}
.peer-meta { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; }
.peer-name {
  margin: 0; font-weight: 600; font-size: 16px; line-height: 1.4; letter-spacing: inherit;
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.verify-pill {
  position: relative;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500; color: var(--text-2);
  padding: 2px 0; transition: color 0.2s;
}
.verify-pill::before { content: ""; position: absolute; top: -12px; right: -10px; bottom: -12px; left: -10px; } /* 44px hit area */
.verify-pill .ic { width: 12px; height: 12px; stroke-width: 2.4; }
.verify-pill[data-state="verified"] { color: var(--green); }
.verify-pill[data-state="link"] { color: #ffd60a; }
.verify-pill[data-state="unverified"] { color: var(--orange); }
.btn-end {
  position: relative; flex: none;
  height: 36px; min-height: 36px; padding: 0 16px; border-radius: 999px;
  font-size: 15px; font-weight: 600; color: var(--red);
  background: rgba(255, 69, 58, 0.14);
  transition: transform 0.25s var(--spring), background 0.2s;
}
.btn-end::before { content: ""; position: absolute; top: -4px; right: 0; bottom: -4px; left: 0; }
.btn-end:active { transform: scale(0.94); }

.messages {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 18px calc(var(--safe-r) + 14px) 10px calc(var(--safe-l) + 14px);
  display: flex; flex-direction: column; gap: 3px;
  overscroll-behavior: contain;
}
.messages > :first-child { margin-top: auto; }
.system-note {
  align-self: center; display: flex; gap: 10px; align-items: flex-start;
  max-width: 420px; margin: 4px auto 18px; padding: 12px 16px;
  border-radius: 18px; background: var(--glass); box-shadow: inset 0 0 0 1px var(--hairline);
  font-size: 13px; line-height: 1.45; color: var(--text-2);
  overflow: hidden; overflow: clip; overflow-wrap: anywhere;
}
.system-note .ic { width: 16px; height: 16px; margin-top: 1px; color: var(--text-2); transition: color 0.3s; }
#intro-note .ic { color: var(--text-2); }
#intro-note.verified .ic { color: var(--green); }
.system-note.small { margin: 10px auto; padding: 6px 12px; border-radius: 999px; font-size: 12px; }

.msg {
  max-width: min(76%, 520px); display: flex; flex-direction: column;
  animation: pop 0.42s var(--spring) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.92); } }
.msg.me { align-self: flex-end; align-items: flex-end; transform-origin: bottom right; }
.msg.them { align-self: flex-start; align-items: flex-start; transform-origin: bottom left; }
.msg + .msg.me:not(.prev-me), .msg + .msg.them:not(.prev-them) { margin-top: 8px; }

.bubble {
  position: relative; padding: 9px 14px; border-radius: 20px;
  font-size: 16.5px; line-height: 1.36;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  user-select: text; -webkit-user-select: text;
  overflow: hidden; overflow: clip; contain: paint; /* stacked combining marks stay inside */
}
.me .bubble { color: #fff; background: var(--bubble-me); }
.them .bubble { background: var(--bubble-them); }
.me.tail .bubble { border-bottom-right-radius: 6px; }
.them.tail .bubble { border-bottom-left-radius: 6px; }
.bubble.emoji-only { background: none !important; font-size: 44px; line-height: 1.1; padding: 2px 0; }

.media {
  display: block; border-radius: 20px; overflow: hidden; background: #111;
  box-shadow: inset 0 0 0 1px var(--hairline); cursor: auto; position: relative; max-width: 100%;
}
.media img, .media video { display: block; max-width: min(300px, 68vw); max-height: 380px; width: auto; height: auto; min-width: 72px; min-height: 72px; object-fit: contain; }
.media.placeholder { width: 220px; height: 160px; max-width: 100%; }
.media-open {
  display: block; width: 100%; margin: 0; padding: 0; border: 0; border-radius: inherit;
  background: none; color: inherit; font: inherit; cursor: zoom-in;
}
.media-open:focus-visible { outline-offset: -3px; }
.media video:focus-visible { outline: 2px solid var(--blue); outline-offset: -3px; }
.media-reveal {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  height: 44px; padding: 0 18px; border-radius: 999px; white-space: nowrap;
  font-size: 14px; font-weight: 600; color: #fff;
  background: rgba(255, 255, 255, 0.14); box-shadow: inset 0 0 0 1px var(--hairline-hi);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  transition: background 0.2s;
}
/* Saves are <button>s now: drop the native look */
.file-save, .media-save, .lightbox-save {
  -webkit-appearance: none; appearance: none; margin: 0; padding: 0; border: 0;
  font: inherit; line-height: 1; cursor: pointer;
}
/* No long-press save, drag-out or Live Text from media; saving goes through the app's own flow */
.media img, .media video, #lightbox-img, .file-save, .media-save, .lightbox-save {
  -webkit-touch-callout: none; -webkit-user-drag: none; user-select: none; -webkit-user-select: none;
}
.media .media-save, .media .xfer-cancel {
  position: absolute; z-index: 2; top: 8px; right: 8px;
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.media .media-save::before, .media .xfer-cancel::before { content: ""; position: absolute; top: -5px; right: -5px; bottom: -5px; left: -5px; }
.media .media-save .ic, .media .xfer-cancel .ic { width: 17px; height: 17px; }
/* Videos: buttons sit below the player so they never cover its native controls */
.media-actions { display: flex; gap: 8px; margin-top: 6px; }
.me .media-actions { justify-content: flex-end; }
.media-actions .media-save, .media-actions .xfer-cancel {
  position: relative; flex: none;
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--glass-hi); color: #fff;
  transition: transform 0.2s var(--spring), background 0.2s;
}
.media-actions .media-save::before, .media-actions .xfer-cancel::before { content: ""; position: absolute; top: -5px; right: -5px; bottom: -5px; left: -5px; }
.media-actions .media-save:active, .media-actions .xfer-cancel:active { transform: scale(0.9); }
.media-actions .media-save .ic, .media-actions .xfer-cancel .ic { width: 17px; height: 17px; }

.file-card {
  display: flex; align-items: center; gap: 12px; min-width: min(230px, 100%); max-width: 320px;
  padding: 12px 14px; border-radius: 20px;
}
.me .file-card { background: var(--bubble-me); color: #fff; }
.them .file-card { background: var(--bubble-them); }
.file-icon {
  width: 40px; height: 40px; border-radius: 11px; flex: none; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.16); font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase;
}
.file-info { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.file-name { display: flex; min-width: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; overflow: clip; }
.file-stem { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.file-ext { flex: none; font-weight: 800; }
.file-card.risky { box-shadow: inset 0 0 0 2px var(--orange); }
.file-flag {
  align-self: flex-start; margin-top: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.01em;
  color: #1c1c1e; background: var(--orange);
}
.file-size { font-size: 12.5px; opacity: 0.7; }
.me .file-size { opacity: 1; color: rgba(255, 255, 255, 0.96); } /* >= 4.5:1 even on the lightest bubble stop */
.file-save {
  position: relative;
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.18); color: inherit; transition: transform 0.2s var(--spring);
}
.file-save::before { content: ""; position: absolute; top: -5px; right: -5px; bottom: -5px; left: -5px; }
.file-save:active { transform: scale(0.9); }
.file-save .ic { width: 17px; height: 17px; }
.file-card .xfer-cancel {
  position: relative; flex: none;
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.18); color: inherit;
}
.file-card .xfer-cancel::before { content: ""; position: absolute; top: -7px; right: -7px; bottom: -7px; left: -7px; }
.file-card .xfer-cancel .ic { width: 15px; height: 15px; }

.progress {
  height: 3px; border-radius: 3px; margin-top: 7px; overflow: hidden;
  background: rgba(255, 255, 255, 0.18);
}
.progress > i {
  display: block; height: 100%; width: 0; border-radius: inherit; background: #fff;
  transition: width 0.2s linear;
}
/* Over photos: dark pill so the bar shows on light images too */
.media .progress {
  position: absolute; left: 12px; right: 12px; bottom: 12px; margin: 0;
  height: 12px; padding: 4px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.media .progress > i { height: 4px; border-radius: 2px; }

.meta { font-size: 11.5px; color: var(--text-2); margin: 3px 6px 0; min-height: 0; }
.meta:empty { display: none; }
.meta.warn { color: var(--orange); }

.chat-float { position: relative; height: 0; z-index: 4; }
.new-msg {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  height: 36px; padding: 0 16px; border-radius: 999px; white-space: nowrap;
  font-size: 14px; font-weight: 600; color: #fff; background: var(--accent-fill);
  box-shadow: 0 10px 28px -8px rgba(0, 0, 0, 0.7), 0 6px 20px -8px rgba(10, 111, 224, 0.8);
  animation: float-in 0.4s var(--spring) both;
  transition: transform 0.25s var(--spring);
}
.new-msg::before { content: ""; position: absolute; top: -4px; right: 0; bottom: -4px; left: 0; }
.new-msg:active { transform: translateX(-50%) scale(0.95); }
@keyframes float-in { from { opacity: 0; transform: translate(-50%, 8px) scale(0.9); } }

/* Grid rows animate height without measuring, so no snap and no leftover gap */
.typing {
  display: grid; grid-template-rows: 0fr; margin: 0; opacity: 0;
  transition: grid-template-rows 0.3s var(--spring), opacity 0.25s;
}
.typing.on { grid-template-rows: 1fr; opacity: 1; }
.typing-inner { overflow: hidden; min-height: 0; }
.typing-bubble {
  display: flex; gap: 4px; width: -webkit-fit-content; width: fit-content;
  margin: 0 calc(var(--safe-l) + 14px) 6px;
  padding: 12px 14px; border-radius: 20px; border-bottom-left-radius: 6px;
  background: var(--bubble-them);
  transform: translateY(8px) scale(0.9); transform-origin: bottom left;
  transition: transform 0.35s var(--spring);
}
.typing.on .typing-bubble { transform: none; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-2); animation: blink 1.3s infinite; }
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
.typing:not(.on) i { animation-play-state: paused; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes blink-fade { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

.gate {
  position: relative; z-index: 3; flex: none;
  margin: 0 calc(var(--safe-r) + 12px) 10px calc(var(--safe-l) + 12px);
  max-height: 60%; overflow-y: auto;
  padding: 16px 18px; border-radius: 24px; text-align: center;
  background: rgba(28, 28, 30, 0.9);
  -webkit-backdrop-filter: blur(40px) saturate(180%); backdrop-filter: blur(40px) saturate(180%);
  box-shadow: inset 0 0 0 1px var(--hairline-hi), 0 20px 60px -10px rgba(0, 0, 0, 0.7);
  animation: rise 0.5s var(--spring) both;
}
.gate-title { margin: 0 0 4px; font-size: 16px; font-weight: 700; color: var(--orange); letter-spacing: -0.015em; }
.gate-text { margin: 0 auto 14px; font-size: 14px; line-height: 1.4; color: var(--text-2); max-width: 40ch; }
.gate-actions { display: flex; flex-direction: column; gap: 8px; }
.gate-actions .btn { width: 100%; height: 44px; font-size: 15px; }
@media (min-width: 640px) {
  .gate { align-self: center; width: min(560px, 100% - 24px); margin-left: 0; margin-right: 0; }
}

.composer {
  position: relative; z-index: 3;
  display: flex; align-items: flex-end; gap: 10px;
  padding: 8px calc(var(--safe-r) + 12px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 12px);
  background: rgba(10, 10, 12, 0.72);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  box-shadow: 0 -1px 0 var(--hairline);
  transition: opacity 0.2s;
}
html.kb-open .composer { padding-bottom: 10px; }
.composer.locked { opacity: 0.45; }
.btn-attach {
  position: relative;
  width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--glass-hi); color: var(--text-2); margin-bottom: 2px;
  transition: transform 0.25s var(--spring), background 0.2s, color 0.2s;
}
.btn-attach::before { content: ""; position: absolute; top: -4px; right: -4px; bottom: -4px; left: -4px; }
.btn-attach:active { transform: scale(0.9) rotate(90deg); }
.field {
  flex: 1; display: flex; align-items: flex-end; min-width: 0;
  border-radius: 20px; box-shadow: inset 0 0 0 1px var(--hairline-hi);
  background: rgba(255, 255, 255, 0.04);
  transition: box-shadow 0.2s;
}
.field:focus-within { box-shadow: inset 0 0 0 1.5px var(--blue); }
.field textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent;
  padding: 8px 6px 8px 15px; max-height: 140px;
  font-size: 16.5px; line-height: 1.32; /* >= 16px prevents iOS zoom */
}
.field textarea::placeholder { color: var(--text-3); }
.btn-send {
  position: relative;
  width: 30px; height: 30px; margin: 4px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--blue); color: #fff;
  transition: transform 0.3s var(--spring), opacity 0.2s, background 0.2s;
}
.btn-send::before { content: ""; position: absolute; top: -7px; right: -7px; bottom: -7px; left: -7px; }
.btn-send .ic { width: 18px; height: 18px; stroke-width: 2.4; }
.btn-send:disabled { opacity: 0; transform: scale(0.5); pointer-events: none; }
.btn-send:active { transform: scale(0.88); }

.tray {
  position: relative; z-index: 3; flex: none;
  margin: 0 calc(var(--safe-r) + 12px) 10px calc(var(--safe-l) + 12px);
  max-height: 50%; overflow-y: auto; overscroll-behavior: contain;
  padding: 12px 14px; border-radius: 24px;
  background: rgba(28, 28, 30, 0.9);
  -webkit-backdrop-filter: blur(40px) saturate(180%); backdrop-filter: blur(40px) saturate(180%);
  box-shadow: inset 0 0 0 1px var(--hairline-hi), 0 20px 60px -10px rgba(0, 0, 0, 0.7);
  animation: rise 0.4s var(--spring) both;
}
.tray-list { display: flex; flex-direction: column; gap: 8px; }
.tray-item { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tray-thumb {
  width: 48px; height: 48px; flex: none; border-radius: 10px; object-fit: cover;
  background: var(--glass-hi); box-shadow: inset 0 0 0 1px var(--hairline);
  -webkit-touch-callout: none; -webkit-user-drag: none; user-select: none;
}
.tray-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tray-size { flex: none; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.tray-note { margin: 10px 0 0; font-size: 13px; line-height: 1.4; color: var(--text-2); overflow-wrap: anywhere; }
.tray-note:empty { display: none; }
.tray-actions { display: flex; gap: 8px; margin-top: 12px; }
.tray-actions .btn { flex: 1 1 0; min-width: 0; height: 44px; font-size: 15px; }
@media (min-width: 640px) {
  .tray { align-self: center; width: min(560px, 100% - 24px); margin-left: 0; margin-right: 0; }
}

.drop {
  position: absolute; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.drop div {
  padding: 40px 54px; border-radius: 28px; border: 2px dashed rgba(255, 255, 255, 0.35);
  font-size: 19px; font-weight: 600;
}
.drop.on { opacity: 1; }

/* ---------------------------------------------------------------- sheets */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: fade 0.3s var(--ease) both;
}
@keyframes fade { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
.sheet {
  position: fixed; z-index: 21; left: 50%; bottom: 0; bottom: var(--kb, 0px);
  width: min(440px, 100%); transform: translateX(-50%);
  max-height: calc(100vh - var(--safe-t) - 12px);
  max-height: calc(100dvh - var(--safe-t) - 12px);
  overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 24px calc(var(--safe-b) + 22px);
  border-radius: 30px 30px 0 0;
  background: rgba(28, 28, 30, 0.88);
  -webkit-backdrop-filter: blur(40px) saturate(180%); backdrop-filter: blur(40px) saturate(180%);
  box-shadow: inset 0 1px 0 var(--hairline-hi), 0 -20px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: sheet-up 0.5s var(--spring) both;
}
html.kb-open .sheet { max-height: calc(var(--vvh, 100vh) - 12px); padding-bottom: 16px; }
/* Once open (JS adds .settled), the open animation must not replay or hold the transform,
   so drags and snaps move the sheet from where it is. Closing still wins. */
.sheet.settled { animation: none; }
.sheet.closing, .sheet.settled.closing { animation: sheet-down 0.3s var(--ease) both; pointer-events: none; }
.sheet-backdrop.closing, .lightbox.closing { animation: fade-out 0.22s var(--ease) both; pointer-events: none; }
.sheet.dragging { animation: none !important; transition: none !important; }
.sheet.snap { transition: transform 0.3s var(--spring); }
@media (min-width: 640px) {
  .sheet { bottom: 50%; border-radius: 30px; transform: translate(-50%, 50%); animation: sheet-pop 0.45s var(--spring) both; }
  .sheet.settled { animation: none; }
  .sheet.closing, .sheet.settled.closing { animation: sheet-pop-out 0.2s var(--ease) both; }
}
@keyframes sheet-up { from { transform: translate(-50%, 100%); } }
/* Starts from the drag offset (JS sets --drag in px), so a swipe dismiss doesn't jump back first */
@keyframes sheet-down { from { transform: translate(-50%, var(--drag, 0px)); } to { transform: translate(-50%, 100%); } }
@keyframes sheet-pop { from { opacity: 0; transform: translate(-50%, 50%) scale(0.92); } }
@keyframes sheet-pop-out { to { opacity: 0; transform: translate(-50%, 50%) scale(0.92); } }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.25); margin: 0 auto 18px; touch-action: none; }
/* Hit strip the full width of the sheet: the grabber stays static, so this is placed against the
   sheet itself (position: fixed) and never overflows sideways into a horizontal scroll */
.grabber::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 32px; touch-action: none; }
@media (min-width: 640px) { .grabber { visibility: hidden; margin-bottom: 8px; } }
.sheet h2 { margin: 0 0 8px; font-size: 21px; font-weight: 700; letter-spacing: -0.02em; }
.sheet-text { margin: 0 auto 22px; color: var(--text-2); font-size: 15px; max-width: 34ch; }
.sheet-warn { margin-top: -12px; color: var(--orange); }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; }
.sheet-actions .btn { width: 100%; height: 52px; font-size: 17px; }

#sas { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 16px 0 18px; }
.sas-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0;
  padding: 10px 4px; border-radius: 18px;
  background: var(--glass-hi); box-shadow: inset 0 0 0 1px var(--hairline);
  animation: pop 0.5s var(--spring) both;
}
.sas-item:nth-child(2) { animation-delay: 0.04s; }
.sas-item:nth-child(3) { animation-delay: 0.08s; }
.sas-item:nth-child(4) { animation-delay: 0.12s; }
.sas-item:nth-child(5) { animation-delay: 0.16s; }
.sas-item:nth-child(6) { animation-delay: 0.2s; }
.sas-emoji { font-size: 32px; line-height: 1; }
.sas-word { font-size: 12px; line-height: 1.2; color: var(--text-2); max-width: 100%; overflow-wrap: anywhere; }

.sl-text {
  display: block; width: 100%; margin: 0 0 18px; padding: 12px 14px; min-height: calc(1.4em * 3 + 24px);
  font: 400 16px/1.4 var(--mono); letter-spacing: 0; text-align: left;
  color: var(--text); background: var(--glass-hi); border: 0; border-radius: 14px;
  box-shadow: inset 0 0 0 1px var(--hairline); word-break: break-all; overflow-wrap: anywhere;
  white-space: pre-wrap; cursor: text;
  user-select: all; -webkit-user-select: all;
}

/* ---------------------------------------------------------------- lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
  background: rgba(0, 0, 0, 0.92);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  animation: fade 0.25s var(--ease) both; cursor: zoom-out;
  padding: calc(var(--safe-t) + 20px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 12px);
}
.lightbox img {
  min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; width: auto; height: auto;
  object-fit: contain; justify-self: center; align-self: center; border-radius: 12px;
  animation: pop 0.45s var(--spring) both;
  -webkit-user-drag: none; user-select: none;
}
.lightbox-close, .lightbox-save {
  position: absolute; z-index: 1; top: calc(var(--safe-t) + 14px);
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--glass-hi); color: #fff; cursor: pointer;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border: 0; padding: 0;
}
.lightbox-close { right: calc(var(--safe-r) + 14px); }
.lightbox-save { left: calc(var(--safe-l) + 14px); }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; z-index: 40; left: 50%; top: calc(var(--vv-top, 0px) + var(--safe-t) + 16px);
  transform: translate(-50%, -140%); opacity: 0; visibility: hidden; /* hidden: out of the a11y tree */
  width: -webkit-max-content; width: max-content; max-width: calc(100vw - 32px);
  padding: 11px 18px; border-radius: 18px;
  background: rgba(44, 44, 46, 0.92);
  -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px);
  box-shadow: inset 0 0 0 1px var(--hairline-hi), 0 12px 40px rgba(0, 0, 0, 0.5);
  font-size: 14px; font-weight: 500; text-align: center;
  white-space: normal; overflow-wrap: anywhere; pointer-events: none;
  transition: transform 0.5s var(--spring), opacity 0.3s, visibility 0s linear 0.5s;
}
.toast.on { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition-delay: 0s; }

.noscript { position: fixed; inset: auto 0 40px; text-align: center; color: var(--text-2); z-index: 50; }

/* ---------------------------------------------------------------- hover (real pointers only, so taps don't stick) */
@media (hover: hover) and (pointer: fine) {
  .link-pill:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
  .btn-glass:hover:not(:disabled) { background: rgba(255, 255, 255, 0.15); }
  .btn-primary:hover:not(:disabled) { background: var(--accent-fill-hover); }
  #btn-retry:not([hidden]) + #btn-new:hover { background: rgba(255, 255, 255, 0.15); }
  .btn-end:hover { background: rgba(255, 69, 58, 0.22); }
  .btn-attach:hover { color: #fff; background: rgba(255, 255, 255, 0.15); }
  .btn-round:hover { background: rgba(255, 255, 255, 0.15); }
  .join.ready .btn-round:hover { background: var(--accent-fill-hover); }
  .new-msg:hover { background: var(--accent-fill-hover); }
  .media-reveal:hover { background: rgba(255, 255, 255, 0.22); }
  .media-actions .media-save:hover, .media-actions .xfer-cancel:hover { background: rgba(255, 255, 255, 0.18); }
  .lightbox-close:hover, .lightbox-save:hover { background: rgba(255, 255, 255, 0.18); }
  .verify-pill:hover { color: var(--text); }
  .qr-cover:hover { background: rgba(255, 255, 255, 0.06); }
  .file-save:hover { background: rgba(255, 255, 255, 0.26); }
}

/* ---------------------------------------------------------------- responsiveness */
@media (max-height: 700px) {
  .host-card { padding: 24px 22px 18px; }
  .qr-wrap { width: min(190px, 56vw); margin: 18px 0 16px; }
  .host-inner { gap: 14px; }
  .join-hint { margin-top: -6px; }
}
@media (max-height: 500px) {
  .sheet { padding: 6px 20px calc(var(--safe-b) + 12px); }
  .grabber { margin-bottom: 8px; }
  .grabber::before { height: 18px; }
  .sheet h2 { font-size: 18px; margin-bottom: 4px; }
  .sheet-text { margin-bottom: 12px; font-size: 14px; }
  .sheet-warn { margin-top: -6px; }
  .sheet-actions { flex-direction: row; }
  .sheet-actions .btn { flex: 1 1 0; min-width: 0; height: 44px; font-size: 16px; }
  #sas { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin: 8px 0 10px; }
  .sas-item { padding: 6px 2px; border-radius: 14px; }
  .sas-emoji { font-size: 24px; }
  .sas-word { font-size: 11px; }
  .sl-text { margin-bottom: 10px; }
  .gate { padding: 10px 14px; }
  .gate-text { margin-bottom: 8px; }
  .gate-actions { flex-direction: row; }
  .gate-actions .btn { flex: 1 1 0; min-width: 0; padding: 0 10px; font-size: 14px; }
  .tray { padding: 8px 12px; }
  .tray-actions { margin-top: 8px; }
  .join-icon, .ended-icon { width: 64px; height: 64px; border-radius: 20px; margin-bottom: 16px; }
  .screen-ended .subtitle, .screen-join .subtitle { margin-bottom: 18px; }
}
@media (max-width: 400px) {
  .label-long { display: none; }
  .label-short { display: inline; }
  .join { padding-left: 18px; }
}
@media (max-width: 360px) {
  .msg { max-width: 86%; }
}
@media (min-width: 900px) {
  .messages, .chat-head, .composer {
    padding-left: max(calc(var(--safe-l) + 16px), calc((100% - 820px) / 2));
    padding-right: max(calc(var(--safe-r) + 16px), calc((100% - 820px) / 2));
  }
  .typing-bubble { margin-left: max(calc(var(--safe-l) + 16px), calc((100% - 820px) / 2)); }
}

/* ---------------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
  .aurora i, .orb { animation: none !important; }
  .typing i, .spinner i {
    animation: blink-fade 1.6s infinite !important;
    animation-duration: 1.6s !important; animation-iteration-count: infinite !important;
  }
  .typing, .typing-bubble { transition: none !important; }
  /* The shorthand above resets play-state to running, so pause what nobody can see again */
  .typing:not(.on) i, html.sb-hidden .typing i, html.sb-hidden .spinner i,
  body:not([data-screen="connecting"]) .spinner i { animation-play-state: paused !important; }
}

/* ---------------------------------------------------------------- forced colors */
@media (forced-colors: active) {
  .btn, .link-pill, .join, .field, .verify-pill, .btn-end, .btn-attach, .btn-round, .btn-send,
  .sheet, .card, .file-card, .bubble, .gate, .new-msg, .sas-item, .toast, .system-note,
  .lightbox-close, .lightbox-save, .media-reveal, .file-save, .xfer-cancel, .sl-text,
  .tray, .qr-cover, .link-warn, .file-flag {
    border: 1px solid ButtonBorder;
  }
  .title { background: none; color: CanvasText; -webkit-text-fill-color: CanvasText; }
  .qr-wrap { forced-color-adjust: none; background: #fff; }
  .qr-wrap.covered { forced-color-adjust: auto; background: Canvas; }
  .qr svg path, .qr svg rect { forced-color-adjust: none; }
  button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, [tabindex]:focus-visible:not(h1) {
    outline-color: Highlight;
  }
  .join:focus-within, .field:focus-within { outline: 2px solid Highlight; outline-offset: 2px; }
  .progress > i { background: Highlight; }
}

@media print { body { display: none !important; } }
