/*
 * MiniChat "Aurora" theme: frosted-glass islands over a slowly drifting aurora.
 * Interaction model:
 *   - Pointer devices (hover + fine pointer): hover lifts, flowing gradients, shimmer, pulse.
 *   - Touch devices (iPhone / Android): press feedback, page transitions, static gradients.
 * Everything animated honors prefers-reduced-motion (see the end of this file).
 */
:root {
  --color-primary: #6366f1;
  --color-primary-hover: #5558e6;
  --color-primary-ink: #4b4fc9;
  --color-accent: #6366f1;
  --color-accent-hover: #5558e6;
  --color-text: #1b1740;
  --color-muted: #5f5b86;
  --color-subtle: #7a7699;
  --color-border: rgb(60 50 160 / 12%);
  --color-strong-border: rgb(99 102 241 / 40%);
  --color-surface: #fff;
  --color-tint: #eef0ff;
  --color-background: #f1efff;
  --color-focus: #6366f1;
  --color-danger: #b13a42;
  --color-positive: #1c7048;
  --color-positive-soft: #e7f7ed;
  --color-negative: #b13a42;
  --color-negative-soft: #fff0f1;
  --color-unread: #e5484d;
  --field-bg: rgb(255 255 255 / 88%);
  --field-border: rgb(99 102 241 / 26%);
  --gradient: linear-gradient(120deg, #6366f1, #a855f7, #ec4899);
  --gradient-hover: linear-gradient(120deg, #5558e6, #9b46ee, #e03d8f);
  --gradient-soft: linear-gradient(90deg, rgb(99 102 241 / 12%), rgb(236 72 153 / 10%));
  --panel: rgb(255 255 255 / 58%);
  --panel-solid: rgb(255 255 255 / 92%);
  --shadow-panel: inset 0 0 0 1px rgb(255 255 255 / 80%), 0 10px 40px rgb(80 70 180 / 12%);
  --shadow-soft: 0 14px 40px rgb(80 70 180 / 22%);
  --shadow-accent: 0 8px 22px rgb(139 92 246 / 36%);
  --ring: 0 0 0 3px rgb(99 102 241 / 22%);
  --blur: blur(24px) saturate(1.5);
  --radius-control: 16px;
  --radius-card: 24px;
  --radius-island: 24px;
  --gap-island: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  color: var(--color-text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "PingFang SC",
    sans-serif;
  font-synthesis: none;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: rgb(99 102 241 / 28%) transparent;
}
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--color-background);
}
/* Aurora layers: fixed gradients moved with transforms only (GPU friendly, no blur filters). */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: -25%;
  z-index: -1;
  pointer-events: none;
  will-change: transform;
}
body::before {
  background:
    radial-gradient(38% 38% at 22% 18%, rgb(124 131 255 / 55%), transparent 70%),
    radial-gradient(34% 34% at 82% 62%, rgb(255 154 213 / 45%), transparent 70%);
  animation: aurora-a 26s ease-in-out infinite alternate;
}
body::after {
  background:
    radial-gradient(40% 40% at 70% 12%, rgb(168 85 247 / 28%), transparent 70%),
    radial-gradient(36% 36% at 18% 85%, rgb(111 214 255 / 50%), transparent 70%);
  animation: aurora-b 32s ease-in-out infinite alternate-reverse;
}
/* Status bar blend. In an iOS home-screen app the status bar is painted with the page background color and the
   page starts right below it; fading the aurora into that same color removes the visible seam on every page. */
html::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: -1;
  height: 72px;
  background: linear-gradient(var(--color-background), rgb(241 239 255 / 0%));
  pointer-events: none;
}
[hidden] {
  display: none !important;
}
button,
input,
textarea {
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}
button,
a,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}
button,
a,
label,
.chat-item {
  touch-action: manipulation;
}
button {
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--color-primary) var(--btn-bg, var(--gradient));
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button:focus-visible,
a:focus-visible,
dialog:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}
/* Elements that only ever receive focus from script (headings, the profile sheet) are focus-management targets,
   not controls, so they never draw a ring. */
[tabindex="-1"]:focus,
[tabindex="-1"]:focus-visible {
  outline: none;
}
/* Mobile Safari decides :focus-visible for script-initiated focus from loose heuristics, so a ring could appear on a
   control the user merely tapped. When the last input was a touch or pointer (see input-modality.js) rings are off;
   pressing any key brings them back for keyboard users. */
html[data-input="pointer"] :focus-visible {
  outline: none;
}
input,
textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-control);
  background: var(--field-bg);
  box-shadow:
    inset 0 1px 2px rgb(60 64 140 / 7%),
    0 1px 0 rgb(255 255 255 / 70%);
  color: var(--color-text);
  font-size: 16px;
}
input::placeholder,
textarea::placeholder {
  color: var(--color-subtle);
}
input {
  min-height: 46px;
}
textarea {
  resize: none;
}
label {
  font-size: 13px;
  font-weight: 600;
}
form {
  display: grid;
  gap: 10px;
}
form button[type="submit"] {
  margin-top: 8px;
  box-shadow: var(--shadow-accent);
}
p,
h1,
h2 {
  margin: 0;
}
h1 {
  font-size: 24px;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.2px;
}
h2 {
  font-size: 17px;
  font-weight: 650;
}
a {
  color: var(--color-primary-ink);
  text-underline-offset: 3px;
}
small,
.muted {
  font-size: 13px;
  color: var(--color-muted);
}
.secondary {
  background: var(--color-tint);
  color: var(--color-primary-ink);
  box-shadow: none !important;
}
.icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  flex: none;
  background: transparent;
  color: var(--color-muted);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -0.5px;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: var(--color-primary) var(--gradient);
  color: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow-accent);
  font-family: Georgia, serif;
  font-size: 24px;
  font-style: italic;
  padding-bottom: 5px;
}
.eyebrow {
  font-size: 12px;
  letter-spacing: 0.4px;
  color: var(--color-muted);
}

/* ---------- Auth ---------- */
.auth-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  gap: 24px;
  padding: 40px 24px;
}
.auth-panel {
  position: relative;
  width: min(100%, 400px);
  align-self: center;
  padding: 36px 32px 30px;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow-panel);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  animation: fade-up 0.6s var(--ease) backwards;
}
.auth-panel .brand {
  margin-bottom: 34px;
}
.auth-panel h1 {
  margin-bottom: 8px;
}
.auth-panel > .muted {
  margin-bottom: 4px;
}
.tabs {
  position: relative;
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 22px 0 20px;
  border-radius: var(--radius-control);
  background: rgb(99 102 241 / 10%);
}
.tabs button {
  position: relative;
  flex: 1;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 12px;
  background: transparent;
  color: var(--color-muted);
}
.tabs [aria-selected="true"] {
  background: #fff;
  color: var(--color-text);
  box-shadow: 0 2px 8px rgb(60 64 140 / 14%);
}
.field-action {
  display: flex;
  align-items: stretch;
  gap: 10px;
}
.field-action input {
  flex: 1 1 auto;
}
.field-action button {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 13px;
  padding: 8px 14px;
  min-height: 46px;
}
.notice {
  font-size: 13px;
  min-height: 20px;
  margin: 12px 0;
  color: var(--color-text);
}
.auth-note {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 18px;
  text-align: center;
}
.request-entry {
  display: grid;
  gap: 12px;
  padding-top: 8px;
  box-shadow: 0 -1px 0 rgb(60 50 160 / 8%);
}
.request-entry .auth-note {
  margin: 16px 0 0;
}
.request-entry > button {
  width: 100%;
}
#request-invite-dialog form {
  display: grid;
  gap: 10px;
}
#request-invite-dialog form input {
  min-width: 0;
}
#invite-request-status {
  min-height: 22px;
  color: var(--color-text);
}
.icp-footer {
  font-size: 12px;
  text-align: center;
}
.icp-footer a {
  color: var(--color-muted);
  text-decoration: none;
}

/* ---------- App shell (desktop: frosted islands) ---------- */
.app-shell {
  height: 100vh;
  height: 100dvh;
  max-width: 1640px;
  margin: auto;
  padding: 0 var(--gap-island) var(--gap-island);
  gap: 0 var(--gap-island);
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  grid-template-rows: 60px minmax(0, 1fr);
  overflow: hidden;
}
.app-header {
  grid-column: 1/-1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
}
.connection {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  color: var(--color-muted);
  border-radius: 999px;
  padding: 5px 12px;
  background: rgb(255 255 255 / 70%);
}
.connection[data-state="connected"] {
  color: var(--color-positive);
  background: var(--color-positive-soft);
}
.connection[data-state="disconnected"] {
  color: var(--color-negative);
  background: var(--color-negative-soft);
}
.connection::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a4a8c2;
  margin-right: 8px;
}
.connection[data-state="connected"]::before {
  background: #4daf79;
}
.connection[data-state="disconnected"]::before {
  background: #d46068;
}
.main-nav {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 14px;
  gap: 8px;
  border-radius: var(--radius-island);
  background: var(--panel);
  box-shadow: var(--shadow-panel);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.main-nav button {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  background: transparent;
  color: var(--color-muted);
  width: 62px;
  min-height: 58px;
  padding: 8px 4px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 500;
}
.main-nav button[aria-current] {
  color: #fff;
  background: var(--color-primary) var(--gradient);
  box-shadow: var(--shadow-accent);
}
.main-nav .icon {
  width: 23px;
  height: 23px;
}
/* Sliding selection pill (progressive enhancement; falls back to per-button fill). */
@supports selector(:has(*)) {
  .main-nav button[aria-current] {
    background: transparent;
    box-shadow: none;
  }
  .main-nav::before {
    content: "";
    position: absolute;
    top: 14px;
    left: 9px;
    width: 62px;
    height: 58px;
    border-radius: 18px;
    background: var(--color-primary) var(--gradient);
    box-shadow: var(--shadow-accent);
    transition: transform 0.5s var(--spring);
  }
  .main-nav:has(button:nth-child(2)[aria-current])::before {
    transform: translateY(66px);
  }
  .tabs::before {
    content: "";
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 4px;
    width: calc((100% - 12px) / 2);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 2px 8px rgb(60 64 140 / 14%);
    transition: transform 0.45s var(--spring);
  }
  .tabs:has(button:nth-child(2)[aria-selected="true"])::before {
    transform: translateX(calc(100% + 4px));
  }
  .tabs [aria-selected="true"] {
    background: transparent;
    box-shadow: none;
  }
}
#main-content {
  min-width: 0;
  min-height: 0;
}
.chat-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: var(--gap-island);
  height: 100%;
  animation: fade-in 0.45s ease backwards;
}
.chat-sidebar {
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 10px 10px;
  border-radius: var(--radius-island);
  background: var(--panel);
  box-shadow: var(--shadow-panel);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.section-heading {
  padding: 24px 12px 14px;
}
.section-heading h1 {
  margin-bottom: 4px;
}
.chat-item {
  display: flex;
  gap: 12px;
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 2px;
  align-items: center;
  border-radius: 18px;
  background: transparent;
  color: var(--color-text);
  text-align: left;
  font-weight: 400;
  animation: rise 0.6s var(--ease) backwards;
}
.chat-item:nth-child(2) {
  animation-delay: 70ms;
}
.chat-item:nth-child(3) {
  animation-delay: 140ms;
}
.chat-item:nth-child(4) {
  animation-delay: 210ms;
}
.chat-item:nth-child(5) {
  animation-delay: 280ms;
}
.chat-item:nth-child(n + 6) {
  animation-delay: 350ms;
}
.chat-item[aria-current] {
  background: rgb(255 255 255 / 86%);
  box-shadow:
    0 6px 18px rgb(80 70 180 / 12%),
    inset 0 0 0 1px rgb(255 255 255 / 90%);
}
.chat-avatar-wrap {
  position: relative;
  width: 44px;
  height: 44px;
  flex: none;
}
.presence-dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 13px;
  height: 13px;
  border: 2px solid #fff;
  border-radius: 50%;
}
.presence-dot.online {
  background: #4daf79;
}
.presence-dot.offline {
  background: #d46068;
}
.chat-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
  flex: 1;
}
.chat-copy strong {
  font-size: 14px;
  font-weight: 600;
}
.chat-copy small {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  font-size: 12px;
}
.avatar {
  width: 44px;
  height: 44px;
  object-fit: cover;
  display: inline-grid;
  place-items: center;
  flex: none;
  border-radius: 16px;
  background: linear-gradient(135deg, #e1e4ff, #efe3ff);
  color: var(--color-primary-ink);
  font-size: 17px;
  font-weight: 500;
}
.tone-1 {
  background: linear-gradient(135deg, #d9f1ff, #e1ecff);
  color: #1f5f94;
}
.tone-2 {
  background: linear-gradient(135deg, #ffe3f1, #ffe9d9);
  color: #b0316f;
}
.conversation {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius-island);
  background: rgb(255 255 255 / 46%);
  box-shadow: var(--shadow-panel);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  color: var(--color-muted);
}
.empty-state .icon {
  width: 84px;
  height: 84px;
  padding: 20px;
  margin-bottom: 8px;
  border-radius: 28px;
  background: linear-gradient(135deg, #e4e7ff, #f5e6ff);
  color: var(--color-primary);
  stroke-width: 1.5;
}
.empty-state h2 {
  font-size: 18px;
  color: var(--color-text);
}
.empty-state p {
  font-size: 13px;
}
.chat-detail {
  height: 100%;
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr) auto 64px;
  animation: fade-in 0.35s ease backwards;
}
.conversation-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: rgb(255 255 255 / 55%);
  box-shadow: 0 1px 0 rgb(255 255 255 / 70%);
}
.conversation-header h2 {
  font-size: 16px;
}
.conversation-header .muted {
  font-size: 11px;
  margin-top: 2px;
}
.conversation-header .avatar {
  width: 40px;
  height: 40px;
  font-size: 16px;
}
.conversation-header-copy {
  min-width: 0;
  flex: 1;
}
.danger-icon {
  color: var(--color-negative);
}
.mobile-back {
  display: none;
}
#peer-status[data-state="online"] {
  color: var(--color-positive);
}
#peer-status[data-state="offline"] {
  color: var(--color-negative);
}
.history {
  grid-row: 2;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 28px;
  overscroll-behavior: contain;
}
.time-separator {
  text-align: center;
  margin: 9px 0 7px;
  color: var(--color-subtle);
  font-size: 11px;
  line-height: 18px;
}
.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 0 10px;
}
.message.enter {
  transform-origin: 0 100%;
  animation: msg-in 0.5s var(--spring) backwards;
}
.message.mine.enter {
  transform-origin: 100% 100%;
}
.message .avatar {
  width: 32px;
  height: 32px;
  font-size: 13px;
  border-radius: 12px;
}
.message.mine {
  flex-direction: row-reverse;
}
.bubble {
  max-width: min(75%, 520px);
  padding: 8px 13px;
  border-radius: 18px 18px 18px 6px;
  background: rgb(255 255 255 / 88%);
  box-shadow: 0 4px 14px rgb(80 70 180 / 10%);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
}
.mine .bubble {
  border-radius: 18px 18px 6px 18px;
  background: var(--color-primary) var(--gradient);
  color: #fff;
  box-shadow: 0 8px 20px rgb(139 92 246 / 30%);
}
.mine .bubble button {
  background: rgb(255 255 255 / 22%);
  color: #fff;
  box-shadow: none;
}
.mine .bubble a {
  color: #fff;
}
.sticker-bubble,
.mine .sticker-bubble {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.sticker-image {
  display: block;
  width: 72px;
  height: 72px;
  object-fit: contain;
}
/* Meme stickers carry captions, so they stay larger and keep a soft frame. */
.sticker-image.sticker-meme {
  width: 120px;
  height: 120px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 4px 14px rgb(80 70 180 / 14%);
}

/* ---------- Composer (fixed 64px: floating pill) ---------- */
.composer {
  position: relative;
  grid-row: 4;
  height: 64px;
  min-width: 0;
  border: 0;
  padding: 6px 16px;
  background: transparent;
  gap: 0;
}
.composer-row {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  height: 52px;
  gap: 4px;
  padding: 4px;
  border-radius: 26px;
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 10px 30px rgb(80 70 180 / 16%);
}
.composer-row:focus-within {
  box-shadow:
    0 10px 30px rgb(80 70 180 / 16%),
    0 0 0 2px rgb(99 102 241 / 55%);
}
.composer-row textarea {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  margin-right: 2px;
  padding: 10px 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  line-height: 22px;
  overflow-y: auto;
}
.composer-row textarea:focus,
.composer-row textarea:focus-visible {
  outline: none;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}
.composer-row .icon-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  border-radius: 50%;
}
.composer-row .icon {
  width: 20px;
  height: 20px;
}
.composer-row [data-mode-icon] {
  display: flex;
}
.composer-row .send {
  width: 44px;
  min-width: 44px;
  border-radius: 50%;
}
.composer-row button[type="submit"] {
  margin: 0;
}
.send {
  position: relative;
  overflow: hidden;
  background: var(--color-primary) var(--gradient);
  color: #fff;
  box-shadow: var(--shadow-accent);
}
.hold-to-talk {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 8px 12px;
  border-radius: 22px;
  background: rgb(99 102 241 / 9%);
  color: var(--color-text);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.hold-to-talk:active:not(:disabled) {
  transform: none;
}
.hold-to-talk[data-state="recording"],
.hold-to-talk[data-state="cancel"] {
  background: var(--color-primary) var(--gradient);
  color: #fff;
}
.composer-actions {
  position: absolute;
  z-index: 6;
  right: 16px;
  bottom: calc(100% + 8px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  width: min(290px, calc(100vw - 20px));
  padding: 8px;
  border-radius: 22px;
  background: var(--panel-solid);
  box-shadow: var(--shadow-soft);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  transform-origin: 100% 100%;
  animation: pop-up 0.38s var(--spring) backwards;
}
.composer-actions button {
  display: grid;
  place-items: center;
  gap: 4px;
  min-width: 0;
  min-height: 66px;
  padding: 8px 4px;
  border-radius: 16px;
  background: transparent;
  color: var(--color-text);
  font-size: 12px;
}
.composer-actions button .icon {
  width: 20px;
  height: 20px;
  color: var(--color-primary);
}
.composer-actions button:disabled {
  color: var(--color-subtle);
}
.composer-actions button:disabled .icon {
  color: inherit;
}
.composer-actions button:focus-visible {
  outline-offset: -2px;
}
.composer-action-note {
  grid-column: 1 / -1;
  padding: 0 4px 2px;
  color: var(--color-muted);
  font-size: 11px;
  line-height: 1.35;
}
.sticker-picker {
  position: absolute;
  z-index: 5;
  right: 16px;
  bottom: calc(100% + 8px);
  width: min(440px, calc(100vw - 20px));
  max-height: min(430px, 60dvh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px;
  border-radius: 24px;
  background: var(--panel-solid);
  box-shadow: var(--shadow-soft);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  transform-origin: 100% 100%;
  animation: pop-up 0.38s var(--spring) backwards;
}
.sticker-picker[hidden] {
  display: none;
}
.sticker-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: rgb(99 102 241 / 10%);
}
.sticker-tabs button {
  min-height: 40px;
  padding: 8px;
  background: transparent;
  color: var(--color-muted);
  border-radius: 12px;
  font-size: 13px;
}
.sticker-tabs button[aria-selected="true"] {
  background: #fff;
  color: var(--color-primary-ink);
  box-shadow: 0 2px 8px rgb(60 64 140 / 14%);
}
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
  min-height: 80px;
  align-content: start;
  color: var(--color-muted);
  font-size: 13px;
}
.sticker-grid[data-category="popular"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.sticker-option {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  padding: 4px;
  border-radius: 12px;
  background: transparent;
}
.sticker-grid[data-category="popular"] .sticker-option {
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgb(80 70 180 / 12%);
}
.sticker-option:focus-visible {
  background: var(--color-tint);
}
.sticker-option img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.sticker-grid[data-category="popular"] .sticker-option img {
  object-fit: cover;
}
.list-empty {
  padding: 24px 12px;
  color: var(--color-muted);
  font-size: 13px;
}

/* ---------- Video call ---------- */
.call-overlay {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgb(27 23 64 / 80%);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: white;
  animation: fade-in 0.3s ease backwards;
}
.call-overlay[hidden] {
  display: none;
}
.call-surface {
  position: relative;
  width: min(100%, 960px);
  height: min(100%, 720px);
  min-height: 320px;
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 28px;
  background: #1c1a36;
  box-shadow: 0 24px 70px rgb(0 0 0 / 40%);
}
.call-remote {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #28264a;
}
.call-local {
  position: absolute;
  top: 20px;
  right: 20px;
  width: min(28%, 180px);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border: 1px solid rgb(255 255 255 / 30%);
  border-radius: 18px;
  background: #3a3860;
  transform: scaleX(-1);
}
.call-heading {
  position: absolute;
  top: 24px;
  left: 24px;
  display: grid;
  gap: 5px;
  text-shadow: 0 1px 8px #000;
}
.call-heading strong {
  font-size: 19px;
}
.call-heading span {
  font-size: 13px;
  color: #e8e6f6;
}
.call-audio-tip {
  position: absolute;
  right: 16px;
  bottom: 88px;
  left: 16px;
  color: #f4f3fb;
  font-size: 12px;
  text-align: center;
  text-shadow: 0 1px 6px #000;
}
.call-controls {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px max(24px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgb(12 10 32 / 72%));
}
.call-controls button {
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 999px;
  background: rgb(255 255 255 / 18%);
  color: white;
  font-size: 13px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.call-controls button[hidden] {
  display: none;
}
.call-controls #call-accept {
  background: #2fa56b;
  border-color: #2fa56b;
}
.call-controls .call-danger {
  background: #e5484d;
  border-color: #e5484d;
}

/* ---------- Account ---------- */
.account-view {
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 32px 40px 60px;
  border-radius: var(--radius-island);
  background: var(--panel);
  box-shadow: var(--shadow-panel);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  animation: fade-up 0.5s var(--ease) backwards;
}
.account-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  max-width: 1080px;
}
.account-content {
  width: min(100%, 620px);
}
.account-identity {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 0;
  padding: 18px;
  margin-bottom: 18px;
  color: var(--color-text);
  font-weight: 400;
  text-align: left;
  border-radius: 22px;
  background: linear-gradient(135deg, rgb(99 102 241 / 14%), rgb(236 72 153 / 12%));
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 70%);
}
.account-identity .avatar {
  width: 62px;
  height: 62px;
  border-radius: 22px;
  font-size: 25px;
  background: #fff;
}
.account-identity strong {
  display: block;
  font-size: 17px;
}
.identity-copy {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
}
.account-identity > .icon {
  color: var(--color-subtle);
  width: 18px;
  height: 18px;
}
.account-menu {
  overflow: hidden;
  border-radius: 22px;
  background: rgb(255 255 255 / 80%);
  box-shadow:
    inset 0 0 0 1px rgb(255 255 255 / 80%),
    0 4px 18px rgb(80 70 180 / 8%);
}
.account-menu-row {
  width: 100%;
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 0;
  background: transparent;
  color: var(--color-text);
  text-align: left;
  font-weight: 400;
}
.account-menu-row + .account-menu-row {
  box-shadow: inset 0 1px 0 rgb(60 50 160 / 8%);
}
.account-menu-row > .icon:first-child {
  width: 40px;
  height: 40px;
  padding: 9px;
  border-radius: 13px;
  background: rgb(99 102 241 / 12%);
  color: var(--color-primary);
}
.account-menu-row > .icon:last-child {
  width: 18px;
  height: 18px;
  color: var(--color-subtle);
}
.menu-copy {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}
.menu-copy strong {
  font-size: 14px;
  font-weight: 620;
}
.menu-copy small {
  overflow-wrap: anywhere;
}
.logout-row {
  color: var(--color-negative);
}
.logout-row > .icon:first-child {
  background: var(--color-negative-soft);
  color: var(--color-negative);
}
.identity {
  display: flex;
  align-items: center;
  gap: 14px;
}
.identity .avatar {
  width: 56px;
  height: 56px;
  border-radius: 20px;
  font-size: 24px;
}
.identity p {
  margin-top: 4px;
}
.people-list,
.invitation-list {
  padding: 0;
  margin: 0;
  list-style: none;
}
.people-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 0 rgb(60 50 160 / 8%);
  min-height: 68px;
  padding: 10px 0;
}
.people-list li > .secondary {
  margin-left: auto;
  font-size: 12px;
  min-height: 36px;
}
.friend-button {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  color: var(--color-text);
  padding: 4px;
  flex: 1;
  min-width: 0;
  text-align: left;
}
.friend-remove {
  flex: none;
  color: var(--color-negative);
  background: var(--color-negative-soft);
}
.invitation-list li {
  padding: 14px 0;
  box-shadow: 0 1px 0 rgb(60 50 160 / 8%);
  font-size: 13px;
}
.invitation-list small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
}
.invitation-request-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  overflow-wrap: anywhere;
  padding: 12px 0;
  box-shadow: 0 1px 0 rgb(60 50 160 / 8%);
}
.invitation-request-actions {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}
.invitation-request-actions button {
  min-width: 52px;
}
#new-invite {
  display: grid;
  gap: 8px;
  padding: 20px 0;
}

/* ---------- Dialogs ---------- */
.account-dialog,
.confirm-dialog {
  width: min(92vw, 520px);
  max-height: 82vh;
  max-height: min(82dvh, 720px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 24px 70px rgb(50 40 130 / 30%);
  overflow: hidden;
}
.account-dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.account-dialog[open],
.confirm-dialog[open] {
  animation: dialog-in 0.4s var(--spring) backwards;
}
.account-dialog::backdrop,
.confirm-dialog::backdrop {
  background: rgb(27 23 64 / 38%);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in 0.3s ease backwards;
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  min-height: 72px;
  padding: 12px 16px 12px 24px;
  background: var(--color-surface);
  box-shadow: 0 1px 0 rgb(60 50 160 / 8%);
}
.dialog-header h2 {
  min-width: 0;
  overflow-wrap: anywhere;
}
.dialog-header .icon-button {
  border-radius: 14px;
  background: rgb(99 102 241 / 9%);
}
.dialog-body {
  min-height: 0;
  max-height: calc(min(82dvh, 720px) - 72px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 22px 24px 30px;
  overscroll-behavior: contain;
}
.dialog-body form {
  margin-top: 18px;
}
.dialog-intro {
  margin-bottom: 16px;
}
.confirm-dialog {
  width: min(90vw, 420px);
}
.confirm-dialog .dialog-body {
  max-height: min(82dvh, 520px);
}
.confirm-dialog h2 {
  margin-bottom: 12px;
}
.confirm-dialog p {
  color: var(--color-muted);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}
.danger-button {
  background: var(--color-negative);
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 8px 0;
}
.setting-row > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}
.setting-row p {
  margin-top: 4px;
}
.setting-row strong {
  display: block;
  font-size: 16px;
  line-height: 1.35;
}
.switch {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 52px;
  min-width: 52px;
  height: 44px;
  min-height: 44px;
  cursor: pointer;
}
.switch input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch > span[aria-hidden] {
  display: block;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  background: #c9c8e0;
  transition: background-color 0.3s ease;
}
.switch > span[aria-hidden]::after {
  content: "";
  display: block;
  width: 26px;
  height: 26px;
  margin: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgb(50 40 130 / 22%);
  transition: transform 0.45s var(--spring);
}
.switch input:checked + span {
  background: var(--color-primary) var(--gradient);
}
.switch input:checked + span::after {
  transform: translateX(20px);
}
.switch input:focus-visible + span {
  outline: 2px solid var(--color-focus);
  outline-offset: 3px;
}
.app-notice {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  margin: 0;
  background: rgb(27 23 64 / 92%);
  color: #fff;
  box-shadow: var(--shadow-soft);
  border-radius: var(--radius-control);
  max-width: calc(100% - 32px);
  z-index: 40;
  /* A status toast must never block the control underneath it. */
  pointer-events: none;
  animation: toast-in 0.45s var(--spring) backwards;
}
.app-notice:empty {
  display: none;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Unread, media, misc ---------- */
.unread {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--color-unread);
  color: white;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
}
.nav-unread {
  position: absolute;
  top: 2px;
  left: calc(50% + 6px);
  border: 2px solid #fff;
}
.message-meta {
  display: block;
  font-size: 10px;
  color: var(--color-subtle);
  margin-top: 6px;
}
.mine .message-meta {
  color: rgb(255 255 255 / 85%);
}
.retry {
  display: block;
  min-height: 32px;
  font-size: 12px;
  margin-top: 8px;
  padding: 4px 12px;
}
.chat-image {
  display: block;
  max-width: 100%;
  width: 280px;
  max-height: 320px;
  object-fit: contain;
  border-radius: 14px;
}
.chat-image-trigger,
.mine .bubble .chat-image-trigger {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  cursor: zoom-in;
}
.chat-image-dialog {
  width: min(100vw, 900px);
  max-width: 100vw;
  height: min(100dvh, 900px);
  max-height: 100dvh;
  padding: 16px;
  border: 0;
  background: transparent;
  color: #fff;
  overflow: visible;
}
.chat-image-dialog[open] {
  display: grid;
  place-items: center;
}
.chat-image-dialog::backdrop {
  background: rgb(10 12 18 / 92%);
}
.chat-image-dialog img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 48px);
  object-fit: contain;
  border-radius: 6px;
  cursor: zoom-out;
}
.chat-image-dialog .chat-image-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 1;
  color: #fff;
  background: rgb(0 0 0 / 55%);
}
.voice-player {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 180px;
}
.voice-player button {
  font-size: 13px;
  white-space: nowrap;
}
.voice-player audio {
  display: none;
}
#media-preview {
  grid-row: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-height: min(30dvh, 180px);
  overflow: auto;
  padding: 10px 16px;
  background: rgb(255 255 255 / 75%);
  box-shadow: 0 -1px 0 rgb(60 50 160 / 8%);
  font-size: 13px;
}
#media-preview > img {
  width: 90px;
  height: 68px;
  object-fit: cover;
  border-radius: 12px;
}
#media-preview button {
  font-size: 12px;
  min-height: 44px;
  padding: 6px 12px;
}
#load-older {
  display: block;
  margin: 0 auto 20px;
  font-size: 12px;
  min-height: 34px;
  border-radius: 999px;
}
.avatar-picker {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.avatar-picker button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: fit-content;
}
.avatar-picker p {
  overflow-wrap: anywhere;
}
.auth-panel,
.account-content {
  min-width: 0;
}

/* ---------- Shared interaction: transitions, press feedback, focus ---------- */
button,
a,
input,
textarea,
label,
.account-menu-row,
.chat-item,
.friend-button,
.icon-button {
  transition:
    background-color 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease,
    box-shadow 0.25s ease,
    opacity 0.25s ease,
    transform 0.35s var(--spring);
}
/* Press feedback works on touch and mouse alike. */
button:active:not(:disabled),
.chat-item:active,
.account-menu-row:active,
.friend-button:active {
  transform: scale(0.97);
}
.account-menu-row:active,
.chat-item:active {
  transform: scale(0.985);
  background-color: rgb(99 102 241 / 8%);
}
input:focus,
textarea:focus {
  background: #fff;
  border-color: var(--color-primary);
  outline: none;
  box-shadow: var(--ring);
}
input:focus-visible,
textarea:focus-visible {
  outline: none;
}
.composer-row textarea:focus {
  box-shadow: none;
}

/* ---------- Pointer devices only: hover, flowing gradients, ambient motion ---------- */
@media (hover: hover) and (pointer: fine) {
  /* Only buttons that use the default gradient read --btn-bg, so this never fights class styles. */
  button:hover:not(:disabled) {
    --btn-bg: var(--gradient-hover);
  }
  .danger-button:hover {
    background: #922e36;
  }
  .secondary:hover {
    background: #e2e5ff;
  }
  .icon-button:hover {
    background: rgb(99 102 241 / 10%);
    color: var(--color-primary-ink);
    transform: scale(1.08);
  }
  .danger-icon:hover {
    color: var(--color-negative);
    background: var(--color-negative-soft);
  }
  .friend-remove:hover {
    color: #922e36;
    background: #ffe2e4;
  }
  .composer-actions button:hover {
    background: var(--color-tint);
    color: var(--color-primary-ink);
  }
  .sticker-option:hover {
    background: var(--color-tint);
  }
  .sticker-tabs button:hover:not([aria-selected="true"]),
  .tabs button:hover:not([aria-selected="true"]) {
    background: rgb(255 255 255 / 55%);
  }
  .main-nav button:hover:not([aria-current]) {
    background: rgb(99 102 241 / 9%);
    color: var(--color-primary-ink);
  }
  .friend-button:hover {
    background: rgb(99 102 241 / 7%);
  }
  .hold-to-talk:hover:not([data-state]) {
    background: rgb(99 102 241 / 15%);
  }
  .hold-to-talk[data-state]:hover {
    background: var(--color-primary) var(--gradient);
  }
  .account-menu-row:hover {
    background: rgb(255 255 255 / 65%);
  }
  .logout-row:hover {
    background: var(--color-negative-soft);
  }
  .chat-item:hover:not([aria-current]) {
    background: rgb(255 255 255 / 55%);
    transform: translateX(3px);
  }
  .mine .bubble button:hover {
    background: rgb(255 255 255 / 32%);
  }
  .icp-footer a:hover {
    color: var(--color-primary-ink);
    text-decoration: underline;
  }
  input:hover,
  textarea:hover {
    border-color: var(--color-strong-border);
  }
  .composer-row textarea:hover {
    border-color: transparent;
  }
  .composer-row:hover {
    box-shadow:
      0 12px 34px rgb(80 70 180 / 20%),
      0 0 0 1.5px rgb(139 92 246 / 40%);
  }
  .send:hover {
    background: var(--color-primary-hover) var(--gradient-hover);
    transform: scale(1.1) rotate(-8deg);
  }
  .send:active:not(:disabled) {
    transform: scale(0.9);
  }
  /* Gradients that slowly flow. Static on touch devices to save battery. */
  .mine .bubble,
  .send,
  .brand-mark,
  .main-nav::before,
  .main-nav button[aria-current],
  .switch input:checked + span {
    background-size: 200% 200%;
    animation: gradient-flow 9s ease-in-out infinite;
  }
  .send::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -60%;
    width: 40%;
    background: linear-gradient(100deg, transparent, rgb(255 255 255 / 55%), transparent);
    animation: shimmer 4.5s ease-in-out infinite;
    pointer-events: none;
  }
  .presence-dot.online {
    animation: pulse 2.4s ease-out infinite;
  }
}

@media (max-width: 900px) {
  .chat-layout {
    grid-template-columns: 270px minmax(0, 1fr);
  }
  .account-view {
    padding: 28px;
  }
}
@media (max-width: 430px) {
  #invitation-request-dialog .dialog-actions {
    flex-wrap: wrap;
  }
  #invitation-request-dialog .dialog-actions button {
    flex: 1 1 100px;
  }
}

/* ---------- Mobile: compact type, floating pill nav & composer ---------- */
@media (max-width: 650px) {
  .app-shell {
    padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
    gap: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 54px minmax(0, 1fr) auto;
  }
  .app-header {
    grid-row: 1;
    padding: 0 16px;
  }
  .app-header .brand {
    font-size: 16px;
  }
  .app-header .brand-mark {
    height: 28px;
    width: 28px;
    font-size: 21px;
    border-radius: 10px;
  }
  #main-content {
    grid-row: 2;
    grid-column: 1;
  }
  .main-nav {
    grid-row: 3;
    grid-column: 1;
    flex-direction: row;
    justify-content: space-around;
    gap: 4px;
    margin: 0 16px max(10px, env(safe-area-inset-bottom));
    padding: 4px;
    border-radius: 30px;
    background: rgb(255 255 255 / 80%);
    box-shadow:
      inset 0 0 0 1px rgb(255 255 255 / 80%),
      0 12px 30px rgb(80 70 180 / 20%);
  }
  .main-nav button {
    flex: 1;
    width: auto;
    min-height: 50px;
    gap: 2px;
    padding: 6px 12px;
    border-radius: 26px;
    font-size: 10px;
  }
  .main-nav .icon {
    height: 20px;
    width: 20px;
  }
  @supports selector(:has(*)) {
    .main-nav::before {
      top: 4px;
      bottom: 4px;
      left: 4px;
      width: calc((100% - 12px) / 2);
      height: auto;
      border-radius: 26px;
    }
    .main-nav:has(button:nth-child(2)[aria-current])::before {
      transform: translateX(calc(100% + 4px));
    }
  }
  .chat-layout {
    display: block;
    position: relative;
  }
  .chat-sidebar {
    height: 100%;
    padding: 0 8px 8px;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    animation: fade-in 0.35s ease backwards;
  }
  .section-heading {
    padding: 14px 14px 10px;
  }
  .section-heading h1 {
    margin: 0;
    font-size: 20px;
  }
  .chat-item {
    gap: 11px;
    min-height: 64px;
    padding: 10px 12px;
  }
  .chat-copy {
    gap: 2px;
  }
  .chat-avatar-wrap,
  .chat-item .avatar {
    width: 40px;
    height: 40px;
  }
  .empty-state {
    gap: 7px;
  }
  .empty-state h2 {
    margin-top: 3px;
    font-size: 16px;
  }
  .empty-state .icon {
    width: 72px;
    height: 72px;
    padding: 18px;
  }
  .conversation {
    display: none;
    height: 100%;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .chat-open .chat-sidebar {
    display: none;
  }
  .chat-open .conversation {
    display: block;
    animation: screen-in 0.45s var(--ease) backwards;
  }
  .chat-open .app-header {
    display: none;
  }
  .chat-open:not(.account-active) {
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .chat-open:not(.account-active) #main-content {
    grid-row: 1;
  }
  .chat-open:not(.account-active) .main-nav {
    grid-row: 2;
  }
  .account-active .app-header {
    display: flex;
  }
  .chat-detail {
    grid-template-rows: 60px minmax(0, 1fr) auto 64px;
  }
  .conversation-header {
    padding: 8px 12px 8px 6px;
    gap: 8px;
    /* Starts in the status-bar color and settles into the frosted white, so the bar has no hard top edge. */
    background: linear-gradient(var(--color-background), rgb(255 255 255 / 62%) 85%);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
  }
  .conversation-header .avatar {
    width: 34px;
    height: 34px;
  }
  .conversation-header h2 {
    font-size: 15px;
  }
  .conversation-header .muted {
    margin-top: 1px;
  }
  .conversation-header .danger-icon {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }
  .mobile-back {
    display: inline-grid;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }
  .history {
    padding: 12px 14px;
  }
  .message {
    gap: 8px;
    margin-bottom: 8px;
  }
  .bubble {
    max-width: calc(100% - 52px);
    font-size: 14px;
    padding: 7px 12px;
  }
  .composer {
    padding: 6px 12px;
  }
  .composer-row {
    gap: 2px;
  }
  .composer-row #composer-more[aria-expanded="true"] {
    color: var(--color-primary-ink);
    background: var(--color-tint);
  }
  .composer-actions,
  .sticker-picker {
    right: 12px;
    bottom: calc(100% + 6px);
  }
  /* Phones: span the viewport (8px margins) so seven official stickers fit a row even at 320px. */
  .sticker-picker {
    right: 8px;
    left: 8px;
    width: auto;
    padding: 8px;
    /* Overlay-style scrolling like iOS: the scrollbar must not eat a column's worth of width. */
    scrollbar-width: none;
  }
  .sticker-picker::-webkit-scrollbar {
    display: none;
  }
  .account-view {
    padding: 14px 16px max(24px, env(safe-area-inset-bottom));
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .account-heading {
    margin-bottom: 10px;
  }
  .account-heading h1 {
    margin: 0;
    font-size: 20px;
    line-height: 1.25;
  }
  .account-identity {
    gap: 12px;
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 20px;
  }
  .account-identity .avatar {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    font-size: 20px;
  }
  .account-identity strong {
    font-size: 15px;
  }
  .account-identity .muted,
  .account-identity small {
    font-size: 11px;
  }
  .account-menu {
    border-radius: 20px;
  }
  .account-menu-row {
    min-height: 56px;
    gap: 11px;
    padding: 7px 12px;
  }
  .account-menu-row > .icon:first-child {
    width: 36px;
    height: 36px;
    padding: 8px;
    border-radius: 12px;
  }
  .account-menu-row > .icon:last-child {
    width: 16px;
    height: 16px;
  }
  .menu-copy {
    gap: 0;
  }
  .menu-copy strong {
    font-size: 13px;
  }
  .menu-copy small {
    font-size: 11px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .account-dialog,
  .confirm-dialog {
    width: 100%;
    max-width: none;
    max-height: 86vh;
    max-height: 86dvh;
    margin: auto 0 0;
    border-radius: 24px 24px 0 0;
  }
  /* Bottom sheet reveal uses clip-path so the layout box never moves. */
  .account-dialog[open],
  .confirm-dialog[open] {
    animation: sheet-in 0.5s var(--ease) backwards;
  }
  .dialog-body {
    max-height: none;
    padding: 18px 20px max(28px, calc(24px + env(safe-area-inset-bottom)));
  }
  .app-notice {
    bottom: calc(84px + env(safe-area-inset-bottom));
  }
  .auth-shell {
    padding: 30px max(24px, env(safe-area-inset-right)) 30px max(24px, env(safe-area-inset-left));
  }
  .auth-panel {
    padding: 8px 4px;
    background: transparent;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .auth-panel .brand {
    margin-bottom: 30px;
  }
  .field-action {
    gap: 8px;
  }
  .field-action button {
    padding-inline: 12px;
  }
  .dialog-header {
    min-height: 68px;
    padding-inline: 20px 12px;
  }
  .dialog-header h2 {
    font-size: 16px;
  }
  .call-overlay {
    padding: 0;
  }
  .call-surface {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }
  .call-heading {
    top: max(20px, env(safe-area-inset-top));
    left: 20px;
  }
  .call-local {
    top: max(20px, env(safe-area-inset-top));
    right: 16px;
    width: 100px;
  }
  .call-controls {
    gap: 8px;
  }
  .call-controls button {
    padding-inline: 12px;
  }
  /* Less blur on phones keeps scrolling smooth and the battery cool. */
  body::before,
  body::after {
    inset: -15%;
  }
}

/* Browsers without backdrop-filter get a more opaque glass instead of unreadable text. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root {
    --panel: rgb(255 255 255 / 88%);
  }
  .conversation {
    background: rgb(255 255 255 / 74%);
  }
}

@keyframes aurora-a {
  to {
    transform: translate3d(6%, 5%, 0) scale(1.08);
  }
}
@keyframes aurora-b {
  to {
    transform: translate3d(-6%, -4%, 0) scale(1.1);
  }
}
@keyframes gradient-flow {
  50% {
    background-position: 100% 50%;
  }
}
@keyframes shimmer {
  0%,
  60% {
    left: -60%;
  }
  100% {
    left: 130%;
  }
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgb(77 175 121 / 50%);
  }
  70%,
  100% {
    box-shadow: 0 0 0 8px rgb(77 175 121 / 0%);
  }
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}
@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.85);
  }
}
@keyframes pop-up {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.9);
  }
}
@keyframes dialog-in {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
}
@keyframes sheet-in {
  from {
    opacity: 0.4;
    clip-path: inset(100% 0 0 0 round 24px);
  }
  to {
    opacity: 1;
    clip-path: inset(0 0 0 0 round 24px);
  }
}
@keyframes screen-in {
  from {
    opacity: 0.3;
    clip-path: inset(0 0 0 100%);
  }
  to {
    opacity: 1;
    clip-path: inset(0 0 0 0);
  }
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 12px) scale(0.95);
  }
}

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

/* ---------- Profile page (second-level page: hides the tab bar by covering it) ---------- */
.peer-hit,
.conversation-header-copy,
.profile-hit {
  cursor: pointer;
}
.profile-page {
  position: fixed;
  inset: 0;
  z-index: 25;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background:
    radial-gradient(60% 40% at 90% 0%, rgb(168 85 247 / 16%), transparent 70%),
    linear-gradient(var(--color-background), #eef2ff);
  transform: translateX(100%);
  transition: transform 0.45s var(--ease);
}
.profile-page.open {
  transform: none;
}
.profile-page.closing {
  transform: translateX(100%);
}
.profile-bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  /* Zero layout height: with border-box any padding here would push the cover down and leave a gap above it. */
  height: 0;
  padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}
.profile-bar > * {
  margin-top: max(10px, env(safe-area-inset-top));
}
.profile-back,
.profile-edit-button {
  background: rgb(255 255 255 / 62%);
  color: var(--color-text);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 4px 14px rgb(40 30 110 / 18%);
}
.profile-back {
  border-radius: 50%;
}
.profile-edit-button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 22px;
  color: var(--color-primary-ink);
  font-size: 14px;
}
.profile-cover {
  position: relative;
  height: calc(150px + env(safe-area-inset-top));
  border-radius: 0 0 32px 32px;
  background:
    radial-gradient(120px 90px at 80% 20%, rgb(255 255 255 / 40%), transparent 70%),
    linear-gradient(135deg, #7c83ff, #c084fc 55%, #f9a8d4);
  background-position: center;
  background-size: cover;
}
.profile-cover.has-photo {
  background-color: #7c83ff;
  background-size: cover;
}
/* iOS home-screen apps keep the status bar opaque and start the page below it, so the cover's top edge
   melts into the status-bar color instead of meeting it as a hard line. */
.profile-cover::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  z-index: 1;
  height: 56px;
  border-radius: inherit;
  background: linear-gradient(var(--color-background), rgb(241 239 255 / 0%));
  pointer-events: none;
}
.profile-cover.has-photo::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(rgb(20 14 60 / 38%), transparent 45%, rgb(20 14 60 / 12%));
}
.profile-avatar {
  position: relative;
  z-index: 1;
  width: 70px;
  height: 70px;
  margin: -35px auto 0;
  border: 3px solid rgb(255 255 255 / 95%);
  border-radius: 25px;
  box-shadow: 0 10px 26px rgb(80 70 180 / 28%);
  background: #fff;
}
.profile-avatar .avatar {
  display: grid;
  width: 100%;
  height: 100%;
  border-radius: 22px;
  font-size: 28px;
}
.profile-avatar.zoomable {
  cursor: zoom-in;
}
.profile-avatar-change {
  position: absolute;
  right: -6px;
  bottom: -6px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  min-height: 0;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-accent);
}
.profile-avatar-change .icon {
  width: 16px;
  height: 16px;
}
.profile-identity {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 12px 20px 0;
  text-align: center;
}
.profile-name {
  font-size: 22px;
  overflow-wrap: anywhere;
}
.profile-username {
  font-size: 12px;
  color: var(--color-muted);
}
.profile-bio-text {
  width: 100%;
  margin-top: 8px;
  padding: 11px 14px;
  border-radius: 18px;
  background: rgb(255 255 255 / 70%);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 80%);
  color: #3a3566;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.profile-bio-text.empty {
  color: var(--color-muted);
}
.profile-message {
  width: 100%;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-accent);
}
.profile-form {
  width: 100%;
  gap: 12px;
  text-align: left;
}
.profile-field {
  display: grid;
  gap: 6px;
}
.profile-field select,
.profile-field textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--field-border);
  border-radius: var(--radius-control);
  background: var(--field-bg);
  color: var(--color-text);
  font: inherit;
  font-size: 16px;
}
.profile-field select {
  min-height: 46px;
  height: 46px;
  -webkit-appearance: none;
  appearance: none;
  padding-right: 36px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a7699' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") right 12px center / 16px no-repeat,
    var(--field-bg);
}
.profile-field textarea {
  resize: none;
}
.profile-birthday {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.profile-counter {
  margin-top: -8px;
  text-align: right;
  font-size: 11px;
}
.profile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.profile-actions button {
  margin-top: 0 !important;
}
.profile-card {
  margin: 16px 16px 0;
  padding: 4px 16px 14px;
  border-radius: 22px;
  background: rgb(255 255 255 / 72%);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 80%), 0 8px 30px rgb(80 70 180 / 10%);
}
.profile-card h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 6px;
  color: var(--color-muted);
  font-size: 13px;
  font-weight: 600;
}
.profile-count {
  font-weight: 400;
  font-size: 12px;
}
.profile-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}
.profile-row + .profile-row {
  box-shadow: inset 0 1px 0 rgb(60 50 160 / 8%);
}
.profile-row .icon {
  width: 34px;
  height: 34px;
  padding: 8px;
  border-radius: 11px;
  background: rgb(99 102 241 / 12%);
  color: var(--color-primary);
}
.profile-row small {
  display: block;
  font-size: 11px;
  line-height: 1.2;
}
.profile-row strong {
  display: block;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding-bottom: 2px;
}
.profile-photo {
  position: relative;
  aspect-ratio: 1;
}
.profile-photo > button:first-child {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 14px;
  background: var(--color-tint);
}
.profile-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile-photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 28px;
  min-height: 0;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  background: rgb(27 23 64 / 62%);
}
.profile-photo-remove .icon {
  width: 14px;
  height: 14px;
}
.profile-photo-add {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  border: 1.5px dashed rgb(99 102 241 / 50%);
  border-radius: 14px;
  background: rgb(99 102 241 / 7%);
  color: var(--color-primary);
}
.profile-empty {
  grid-column: 1 / -1;
  padding: 10px 0 4px;
  color: var(--color-muted);
  font-size: 13px;
}
.profile-spacer {
  height: max(28px, env(safe-area-inset-bottom));
}
.profile-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgb(15 12 40 / 92%);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: fade-in 0.25s ease backwards;
}
.profile-lightbox img {
  max-width: 94%;
  max-height: 80%;
  border-radius: 18px;
  object-fit: contain;
  box-shadow: 0 20px 60px rgb(0 0 0 / 50%);
}
.profile-lightbox-count {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 13px;
}
.profile-lightbox .icon-button {
  position: absolute;
  color: #fff;
  background: rgb(255 255 255 / 16%);
  border-radius: 50%;
}
.lightbox-close {
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
}
.lightbox-prev,
.lightbox-next {
  top: 50%;
  margin-top: -22px;
}
.lightbox-prev {
  left: 10px;
}
.lightbox-next {
  right: 10px;
}

@media (min-width: 651px) {
  /* Desktop: the same page as a centered card; the scrim is its own huge shadow so no extra element is needed. */
  .profile-page {
    inset: 0;
    width: 460px;
    height: min(88vh, 780px);
    height: min(88dvh, 780px);
    margin: auto;
    border-radius: 28px;
    box-shadow: 0 0 0 100vmax rgb(27 23 64 / 42%), 0 24px 70px rgb(50 40 130 / 35%);
    transform: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    animation: none;
  }
  .profile-page.open {
    opacity: 1;
    animation: dialog-in 0.4s var(--spring);
  }
  .profile-page.closing {
    opacity: 0;
    transform: none;
  }
  .profile-cover {
    height: 170px;
    border-radius: 0 0 32px 32px;
  }
  .profile-cover::before {
    display: none;
  }
  .profile-bar {
    padding-top: 12px;
  }
  .profile-lightbox {
    position: fixed;
  }
}
@media (hover: hover) and (pointer: fine) {
  .profile-hit:hover {
    transform: scale(1.06);
  }
  .profile-photo > button:first-child:hover img {
    transform: scale(1.06);
  }
  .profile-photo img {
    transition: transform 0.4s var(--ease);
  }
}
