/* === component: auth (lock / first impression) ===
   Centered nickname + Register/Login over the overlay-tint wash (DESIGN §4.5).
   Owned by F0. */

.auth {
  margin: auto;
  width: min(22rem, 100%);
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-4);
}
.auth-tag { text-align: center; color: var(--text-2); font-size: var(--fs-callout); margin-bottom: var(--sp-2); }
.auth-actions { display: flex; gap: var(--sp-3); }
.auth-actions .btn { flex: 1; }

/* === component: base ===
   Reset, 100dvh PWA shell, no-scrollbar momentum scroll, safe-area frame,
   typography defaults, and the shared primitives (.btn, .field, .tag, .msg)
   every page composes. Owned by F0; FROZEN. */

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

/* The shell never scrolls; only inner .scroll regions do (§5.2). */
html, body {
  margin: 0;
  height: 100vh;        /* fallback first */
  height: 100dvh;       /* dynamic viewport: composer clears Safari toolbar */
  overflow: hidden;
}

body {
  font-family: var(--font-sys);
  font-size: var(--fs-body);
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p { margin: 0; }

/* Titles tighten; eyebrows/captions track out + uppercase. */
.t-display { font-size: var(--fs-display); font-weight: 700; line-height: 1.08; letter-spacing: -0.02em; }
.t-title   { font-size: var(--fs-title);   font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; }
.t-eyebrow { font-size: var(--fs-caption); font-weight: 600; line-height: 1.2;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }

/* No-scrollbar + native momentum, contained so the PWA shell never rubber-bands. */
.scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.scroll::-webkit-scrollbar { width: 0; height: 0; display: none; }

/* --- shared primitives --------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 2.75rem; padding: 0 var(--sp-4);
  font: inherit; font-size: var(--fs-callout); font-weight: 600;
  color: var(--text-on-accent); background: var(--accent);
  border: none; border-radius: var(--r-sm); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-std), transform var(--dur-fast) var(--ease-std);
}
.btn:active { background: var(--accent-press); transform: scale(0.98); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn--ghost { color: var(--text); background: transparent; box-shadow: inset 0 0 0 1px var(--border); }
.btn--ghost:active { background: var(--surface-2); }
.btn--sm { min-height: 2rem; padding: 0 var(--sp-3); font-size: var(--fs-footnote); }
.btn--danger { background: var(--danger); }

/* Inputs: never below 16px (no iOS focus zoom), hairline + focus ring. */
.field, input {
  width: 100%; min-height: 2.75rem; padding: 0 var(--sp-3);
  font: inherit; font-size: var(--fs-body);
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-sm);
}
input::placeholder { color: var(--text-3); }
input:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

.tag { font-size: var(--fs-caption); font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--accent); background: var(--accent-soft);
  padding: 0.1rem 0.4rem; border-radius: var(--r-xs); }

.msg { min-height: 1.2rem; text-align: center; font-size: var(--fs-footnote); color: var(--text-2); }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}

/* === component: bubble ===
   Message bubble: gradient sent / hairline received, tail on the trailing bottom
   corner, in-bubble footnote time, run-grouping (collapse spacing, single sender
   label, tail only on the last of a run), hover/long-press branch (DESIGN §4.1). */

.bubble {
  position: relative;
  max-width: min(75%, var(--content-max));
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-bubble);
  font-size: var(--fs-body); line-height: 1.35;
  word-wrap: break-word; overflow-wrap: anywhere;
  animation: bubble-in 60ms var(--ease-out);
}
@keyframes bubble-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }

.bubble--sent {
  align-self: flex-end;
  background: var(--bubble-sent); color: var(--bubble-sent-text);
  border-bottom-right-radius: var(--r-tail);
}
.bubble--received {
  align-self: flex-start;
  background: var(--bubble-recv); color: var(--bubble-recv-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--r-tail);
}

/* Run grouping: continuations sit tight; only the run-leader shows its sender,
   only the run-tail keeps the pointed corner (mid bubbles round it back). */
.bubble--cont { margin-top: calc(-1 * var(--sp-1)); }
.bubble--cont .sender { display: none; }
.bubble--mid.bubble--sent { border-bottom-right-radius: var(--r-bubble); }
.bubble--mid.bubble--received { border-bottom-left-radius: var(--r-bubble); }

.bubble .body { white-space: pre-wrap; }

.sender { display: block; font-size: var(--fs-footnote); font-weight: 600; color: var(--accent-2); }

.bubble time {
  display: block; margin-top: var(--sp-1);
  font-size: var(--fs-footnote); text-align: right; opacity: 0.7;
}

/* Branch affordance: hidden until hover (desktop) / dim-visible on touch. */
.branchbtn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 1.75rem; height: 1.75rem; min-width: 0; border-radius: var(--r-pill);
  color: var(--text-3); opacity: 0; transition: opacity var(--dur-fast) var(--ease-std);
}
.bubble--sent .branchbtn { left: -2rem; }
.bubble--received .branchbtn { right: -2rem; }
.branchbtn svg { width: 1.05rem; height: 1.05rem; fill: none; stroke: currentColor; stroke-width: 1.5; }
.bubble:hover .branchbtn, .branchbtn:focus-visible { opacity: 1; }
@media (hover: none) { .branchbtn { opacity: 0.5; } }

/* === component: chat (chat-detail + thread top-bar + messages + day-divider +
   composer + icon-btn) ===
   The open-conversation pane: sticky thread top-bar, scrollable thread hosting
   the pull-refresh affordance (styled by W3), pill composer. W4 owns. */

#conv-view { display: flex; min-height: 0; }

#conv {
  flex: 1 1 auto; display: flex; flex-direction: column;
  min-height: 0; width: 100%;
  background: var(--bg-elev);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

/* --- shared icon button (thread-bar, branch, back, info) ---------------- */
.icon-btn {
  flex: none; display: inline-grid; place-items: center;
  width: 2.75rem; height: 2.75rem; padding: 0;
  color: var(--text-2); background: transparent; border: none;
  border-radius: var(--r-pill); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-std), color var(--dur-fast) var(--ease-std);
}
.icon-btn:hover { color: var(--text); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.icon-btn svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 1.5; }

/* --- thread top-bar (frosted, hairline bottom) -------------------------- */
.thread-top {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  padding-top: calc(var(--sp-1) + var(--safe-top));
  background: var(--chrome);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.thread-peer {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2); text-align: left;
  background: transparent; border: none; border-radius: var(--r-sm); cursor: pointer; color: inherit;
}
.thread-peer:active { background: var(--surface-2); }
.thread-peer:focus-visible { outline: none; box-shadow: var(--ring); }
.thread-name {
  font-size: var(--fs-headline); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Back is compact-only; the expanded master-detail layout keeps the list visible. */
@media (min-width: 1024px) { .thread-back { display: none; } }

.backlink {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  align-self: flex-start; font-size: var(--fs-footnote); color: var(--accent);
  background: none; border: none; cursor: pointer; padding: var(--sp-2) var(--sp-4) 0;
}
.backlink svg { fill: none; stroke: currentColor; stroke-width: 1.5; }

.thread-add { padding: var(--sp-2) var(--sp-3) 0; }

/* --- thread scroll region ---------------------------------------------- */
.messages {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-4);
}

/* --- day divider (centered date chip) ---------------------------------- */
.day-divider {
  display: flex; align-items: center; justify-content: center;
  margin: var(--sp-3) 0 var(--sp-2);
}
.day-divider span {
  font-size: var(--fs-footnote); font-weight: 600; color: var(--text-3);
  background: var(--surface-2); padding: 0.15rem var(--sp-3); border-radius: var(--r-pill);
}

/* --- pill composer (pinned above keyboard/safe area) ------------------- */
.composer {
  display: flex; align-items: flex-end; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  padding-bottom: calc(var(--sp-2) + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--chrome);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.composer input {
  flex: 1; min-height: 2.75rem; border-radius: var(--r-pill);
  background: var(--surface-2); padding: 0 var(--sp-4);
}
.composer-send {
  flex: none; display: inline-grid; place-items: center;
  width: 2.75rem; height: 2.75rem; padding: 0;
  color: var(--text-on-accent); background: var(--accent);
  border: none; border-radius: var(--r-pill); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-std), transform var(--dur-fast) var(--ease-std);
}
.composer-send:active { background: var(--accent-press); transform: scale(0.94); }
.composer-send:focus-visible { outline: none; box-shadow: var(--ring); }
.composer-send svg { width: 1.375rem; height: 1.375rem; fill: none; stroke: currentColor; stroke-width: 1.8; }

/* === component: conversations (conv-list + conv-row + request-row + avatar +
   empty-state + skeleton) ===
   Inset list rows with hairline separators, identicon avatars, decrypted-snippet
   placeholder, last-activity stamp, group tag (DESIGN §4.1, §5.4, §6). W4 owns. */

.start {
  display: flex; gap: var(--sp-2); flex-wrap: wrap;
}
.start input { flex: 1; min-width: 8rem; }
.start .btn { flex: none; }

#conversations {
  display: flex; flex-direction: column;
  overflow-y: auto;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.conv-h {
  padding: var(--sp-3) var(--sp-4) var(--sp-1);
}

/* --- avatar (frames the identicon SVG; size variants) -------------------- */
.avatar {
  flex: none; display: inline-grid; place-items: center;
  width: 2.5rem; height: 2.5rem; border-radius: var(--r-pill);
  overflow: hidden; background: var(--surface-2);
}
.avatar--sm { width: 2rem; height: 2rem; }
.avatar .identicon { width: 100%; height: 100%; display: block; border-radius: inherit; }

/* --- request row -------------------------------------------------------- */
.conv-req {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--separator);
}
.conv-req .conv-name { flex: 1; font-size: var(--fs-callout); color: var(--text-2); }
.conv-req__act { display: flex; gap: var(--sp-2); flex: none; }

/* --- conversation row --------------------------------------------------- */
.conv-row {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%;
  text-align: left; padding: var(--sp-3) var(--sp-4); min-height: 3.75rem;
  color: var(--text); background: transparent; border: none;
  border-bottom: 1px solid var(--separator); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-std);
}
.conv-req:last-child, .conv-row:last-child { border-bottom: none; }
.conv-row:active { background: var(--surface-2); }
.conv-row:focus-visible { outline: none; box-shadow: var(--ring); }

.conv-row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.1rem; }
.conv-row__head { display: flex; align-items: baseline; gap: var(--sp-2); }
.conv-name {
  flex: 1; min-width: 0; font-size: var(--fs-headline); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-time { flex: none; font-size: var(--fs-footnote); color: var(--text-3); }
.conv-snippet {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-callout); color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-lock { font-style: italic; color: var(--text-3); }

/* --- empty state (seal glyph + headline + copy) ------------------------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-2); text-align: center; padding: var(--sp-10) var(--sp-6);
  margin: auto; color: var(--text-2);
}
.empty-seal { color: var(--accent); opacity: 0.85; }
.empty-title { font-size: var(--fs-headline); font-weight: 600; color: var(--text); }
.empty-sub { font-size: var(--fs-callout); color: var(--text-3); max-width: 22rem; }

/* --- skeleton (token-driven shimmer; reduced-motion safe) --------------- */
.skeleton {
  background: var(--surface-2);
  background-image: linear-gradient(90deg,
    transparent 0%, color-mix(in srgb, var(--text-3) 14%, transparent) 50%, transparent 100%);
  background-size: 200% 100%; background-repeat: no-repeat;
  border-radius: var(--r-sm); animation: shimmer 1.3s var(--ease-std) infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background-image: none; }
}

/* === component: detail-panel (chat-details + participant-row + avatar) ===
   The conversation inspector (DESIGN §4.2): big avatar, E2E seal line, Participants
   inset group, branch lineage, danger Leave. Inset groups + hairlines, not boxes.
   Owned by W1. Tokens only. */

.detail { display: flex; flex-direction: column; height: 100%; overflow: hidden; padding: var(--sp-4) var(--sp-4) 0; }
.detail-scroll {
  flex: 1; min-height: 0; width: 100%;
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding-bottom: var(--sp-8);
}

.detail-hero { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: var(--sp-4) 0 var(--sp-2); text-align: center; }
.detail-title { font-size: var(--fs-title); font-weight: 700; letter-spacing: -0.02em; }
.detail-seal { display: inline-flex; align-items: center; gap: 6px; color: var(--accent-2); font-size: var(--fs-footnote); }
.detail-seal .icon { width: 18px; height: 18px; }

.detail-eyebrow { margin-top: var(--sp-2); }

.detail-link {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font: inherit; font-size: var(--fs-callout); color: var(--text-2);
  background: var(--surface); border: 0; border-radius: var(--r-md); cursor: pointer;
  box-shadow: var(--shadow-1);
}
.detail-link .icon { width: 18px; height: 18px; flex: 0 0 auto; }
.detail-link:active { background: var(--surface-2); }

/* inset grouped list (iOS Settings style) */
.list-group {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-1);
}

.participant-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--separator); }
.participant-row:last-child { border-bottom: 0; }
.participant-name { flex: 1; font-size: var(--fs-headline); }
.participant-badge {
  font-size: var(--fs-caption); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--accent); background: var(--accent-soft); padding: 0.12rem 0.45rem; border-radius: var(--r-xs);
}
.participant-badge.is-pending { color: var(--text-3); background: var(--surface-2); text-transform: none; letter-spacing: 0; font-weight: 500; }

.detail-add { margin-top: var(--sp-2); }
.detail-leave { width: 100%; margin-top: var(--sp-4); }

/* avatar frame holds the inline identicon (size variants via the markup) */
.avatar {
  display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center;
  width: 40px; height: 40px; overflow: hidden;
  background: var(--surface-2); border-radius: var(--r-pill);
}
.avatar .identicon { width: 100%; height: 100%; border-radius: inherit; }
.avatar--lg { width: 88px; height: 88px; box-shadow: var(--shadow-1); }

@media (min-width: 1024px) {
  .detail-scroll { max-width: var(--content-max); margin: 0 auto; }
}

/* === component: profile-card === */
/* Me-page identity surface (DESIGN §4.3). Read-only; tokens only, no uploads. */
.page-me {
  height: 100%;
  padding: var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-5);
}
.page-title {
  margin: 0;
  font-size: var(--fs-title); font-weight: 700; letter-spacing: -0.02em;
}
.profile-card {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--sp-1); padding: var(--sp-4) 0 var(--sp-2);
}
.profile-name {
  margin: var(--sp-2) 0 0;
  font-size: var(--fs-display); font-weight: 700; letter-spacing: -0.02em;
}
.profile-handle { margin: 0; font-size: var(--fs-callout); color: var(--text-2); }
.seal-line {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  margin: var(--sp-3) 0 0; padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-pill); background: var(--accent-soft);
  color: var(--text-2); font-size: var(--fs-footnote);
}
.seal-line .seal-glyph { width: 1rem; height: 1rem; color: var(--accent-2); }

/* === component: avatar === */
.avatar { display: block; line-height: 0; }
.avatar svg { display: block; width: 100%; height: 100%; }
.avatar--profile {
  width: 6rem; height: 6rem; overflow: hidden;
  border-radius: var(--r-lg); box-shadow: var(--shadow-1);
}

/* === component: keyfield === */
.me-section { display: flex; flex-direction: column; gap: var(--sp-2); }
.group-eyebrow {
  margin: 0 0 0 var(--sp-2);
  font-size: var(--fs-caption); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3);
}
.keyfield {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface); border: none; border-radius: var(--r-md);
  color: var(--text); text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.keyfield:active { background: var(--surface-2); }
.keyfield:focus-visible { outline: none; box-shadow: var(--ring); }
.keyfield.is-copied { background: var(--accent-soft); }
.keyfield-grid {
  flex: none; width: 2.25rem; height: 2.25rem; line-height: 0;
  overflow: hidden; border-radius: var(--r-xs);
}
.keyfield-grid svg { display: block; width: 100%; height: 100%; }
.keyfield-key {
  flex: 1; min-width: 0;
  font-family: var(--font-mono); font-size: var(--fs-callout); letter-spacing: 0.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.keyfield-copy { flex: none; width: 1.25rem; height: 1.25rem; color: var(--text-3); }
.keyfield-hint { margin: 0 var(--sp-2); font-size: var(--fs-footnote); color: var(--text-3); }

/* === component: list-group === */
.list-group {
  margin: 0; padding: 0; list-style: none; overflow: hidden;
  background: var(--surface); border-radius: var(--r-md);
}

/* === component: list-item === */
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  min-height: 2.75rem; padding: var(--sp-3) var(--sp-4);
}
.list-item + .list-item { border-top: 1px solid var(--separator); }
.list-label { font-size: var(--fs-body); color: var(--text); }
.list-value { font-size: var(--fs-callout); color: var(--text-2); }
.list-value--ok { display: inline-flex; align-items: center; gap: var(--sp-1); color: var(--success); }
.list-value--ok svg { width: 1rem; height: 1rem; }

/* Expanded: center within the readable column (DESIGN §4.3 expanded). */
@media (min-width: 600px) {
  .page-me { max-width: var(--content-max); margin-inline: auto; padding: var(--sp-6); }
}

/* === component: nav (tab-bar + nav-rail + page-top + chat-page shell) ===
   Frosted primary nav: compact bottom tab bar with a raised Compose, reflowing to
   a vertical icon rail at >=600px (DESIGN §3.2/§3.3, §6). One markup, CSS-driven.
   Also the per-page top-bar chrome and the Chats page two-pane layout. Owned by
   W1. Uses tokens only. */

/* Inline-SVG icon helper, retained for any vendored <svg class="icon"> still in
   FEATURE templates; primary chrome now uses Font Awesome <i class="fa fa-…">. */
.icon {
  width: 24px; height: 24px; display: block;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
/* Font Awesome glyphs render at 1em; size the chrome glyphs explicitly. */
.icon-btn .fa { font-size: 1.5rem; line-height: 1; }

/* --- tab bar (compact) ---------------------------------------------------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-chrome);
  display: flex; align-items: flex-end; justify-content: space-around;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 var(--sp-2) var(--safe-bottom);
  background: var(--chrome);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
}
.nav-item {
  position: relative; flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--tabbar-h);
  font: inherit; color: var(--text-3);
  background: none; border: 0; cursor: pointer;
  transition: color var(--dur-fast) var(--ease-std);
}
.nav-item .fa { font-size: 1.625rem; line-height: 1; }
.nav-label { font-size: var(--fs-caption); font-weight: 600; letter-spacing: 0.02em; }
/* Active = the CURRENT page tab (issue #5): accent glyph + label. Compose is an
   action (.nav-action), never a tab, so it never receives this state. */
.nav-item.is-active { color: var(--accent); }
.nav-item:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }

/* raised center Compose ACTION (soft FAB embedded in the bar) — not a tab. */
.nav-action {
  flex: 0 0 auto; align-self: center;
  display: flex; align-items: center; justify-content: center;
  width: 3.25rem; height: 3.25rem; margin-bottom: var(--sp-2);
  font: inherit; color: var(--text-on-accent); background: var(--accent);
  border: 0; border-radius: var(--r-pill); box-shadow: var(--shadow-2); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-std), transform var(--dur-fast) var(--ease-std);
}
.nav-action .fa { font-size: 1.625rem; line-height: 1; }
.nav-action:active { background: var(--accent-press); transform: scale(0.96); }
.nav-action:focus-visible { outline: none; box-shadow: var(--ring); }

/* unread / requests badge on Chats */
.nav-badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 1.05rem; height: 1.05rem; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-caption); font-weight: 700; line-height: 1;
  color: var(--text-on-accent); background: var(--danger);
  border-radius: var(--r-pill);
}

/* reserve room so content clears the fixed tab bar */
.app-main { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom)); }

/* --- per-page top-bar ----------------------------------------------------- */
.page-top { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) 0 var(--sp-1); }
.page-top .t-title { flex: 1; font-size: var(--fs-title); font-weight: 700; letter-spacing: -0.02em; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.75rem; height: 2.75rem; flex: 0 0 auto;
  color: var(--text); background: none; border: 0; border-radius: var(--r-pill); cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }

/* --- Chats page: list -> thread stacked routes (compact) ------------------ */
.page-chat {
  display: flex; flex-direction: column; gap: var(--sp-3);
  height: 100%; padding: var(--sp-4); overflow: hidden; position: relative;
}
.page-chat #conversations { flex: 1 1 auto; min-height: 0; }
#conv-view:empty { display: none; }
@media (max-width: 599px) {
  #conv-view:not(:empty) { position: absolute; inset: 0; z-index: var(--z-sticky); background: var(--bg); }
}

/* --- page transitions on the swap target (§5.3) --------------------------- */
.nav-fade > * { animation: navFade var(--dur-fast) var(--ease-std); }
.nav-push > * { animation: navPush var(--dur-base) var(--ease-out); }
.nav-pop  > * { animation: navPop  var(--dur-base) var(--ease-out); }
@keyframes navFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes navPush { from { opacity: 0.4; transform: translateX(14%); } to { opacity: 1; transform: none; } }
@keyframes navPop  { from { opacity: 0.4; transform: translateX(-14%); } to { opacity: 1; transform: none; } }

/* --- medium / expanded: tab bar becomes a vertical icon rail (§3.2) ------- */
@media (min-width: 600px) {
  .nav {
    top: calc(var(--header-h) + var(--safe-top)); bottom: 0; right: auto;
    flex-direction: column; justify-content: flex-start; align-items: center;
    width: var(--rail-w); height: auto;
    padding: var(--sp-3) 0 calc(var(--safe-bottom) + var(--sp-3));
    border-top: 0; border-right: 1px solid var(--border);
  }
  .nav-item { flex: 0 0 auto; min-height: var(--rail-w); }
  .nav-label { display: none; }
  .nav-action { margin: var(--sp-2) 0; }
  .nav-badge { left: auto; right: 12px; top: 10px; }
  .app-main { padding-bottom: 0; padding-left: var(--rail-w); }

  /* Chats page as master-detail: list column + flexible thread (§4.1) */
  .page-chat {
    display: grid; padding: var(--sp-6); column-gap: var(--sp-6);
    grid-template-columns: var(--list-w) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
  }
  .page-chat .page-top,
  .page-chat #conversations { grid-column: 1; }
  .page-chat #conv-view { grid-column: 2; grid-row: 1 / -1; min-height: 0; }
  #conv-view:empty { display: block; }
}
@media (min-width: 1024px) {
  .page-chat #conv-view { max-width: var(--content-max); }
}
@media (prefers-reduced-motion: reduce) {
  .nav-fade > *, .nav-push > *, .nav-pop > * { animation: navFade 1ms linear; }
}

/* === component: pull-refresh ===
   Pull-past-bottom sync affordance under the thread (DESIGN §5.1): a centered
   seal/arrow glyph over a hairline track whose fill follows --pull (0..1, set on
   #conv by sync.js and inherited here). transform/opacity only — no width/height
   animation. States toggled by sync.js: idle → is-pulling → is-ready →
   is-syncing → is-done / is-error. The spinner is self-contained (no spinner.css
   exists yet). Reduced-motion safe (the global reduce block neutralises spin).
   Owned by W3. Lives in W4's thread markup immediately after #messages. */

.pull-refresh {
  --p: clamp(0, var(--pull, 0), 1);
  position: relative;
  z-index: var(--z-pull);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  min-height: 3rem;
  padding: var(--sp-5) var(--sp-4) var(--sp-3);
  color: var(--text-3);
  user-select: none;
  -webkit-user-select: none;
  opacity: calc(0.5 + 0.5 * var(--p));
  transition: color var(--dur-fast) var(--ease-std), opacity var(--dur-fast) var(--ease-std);
}

/* Hairline track (::before) + accent fill (::after) drawn above the glyph; the
   fill is a scaleX transform (never width). Pseudo-elements keep the DOM to the
   two mandated spans (.pull-glyph / .pull-label). */
.pull-refresh::before,
.pull-refresh::after {
  content: "";
  position: absolute;
  top: var(--sp-2);
  left: 50%;
  width: 2.75rem;
  height: 2px;
  margin-left: -1.375rem;
  border-radius: var(--r-pill);
}
.pull-refresh::before { background: var(--separator); }
.pull-refresh::after {
  background: var(--accent);
  transform: scaleX(var(--p));
  transform-origin: left center;
  transition: transform var(--dur-fast) var(--ease-std);
}

/* Glyph: an up-chevron that rotates toward 180° as the pull crosses threshold,
   morphs into a spinner while syncing, then a seal-check on success. */
.pull-glyph {
  position: relative;
  width: 1.25rem;
  height: 1.25rem;
  transform: rotate(calc(var(--p) * 180deg));
  transition: transform var(--dur-base) var(--ease-spring);
}
.pull-glyph::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 0.6rem;
  height: 0.6rem;
  border-left: 2px solid currentColor;
  border-top: 2px solid currentColor;
  transform: rotate(45deg) translate(15%, 15%);
}

.pull-label {
  font-size: var(--fs-footnote);
  letter-spacing: 0.01em;
}

/* --- states --------------------------------------------------------------- */
.pull-refresh.is-ready { color: var(--accent); }

.pull-refresh.is-syncing { color: var(--accent); }
.pull-refresh.is-syncing .pull-glyph { transform: none; }
.pull-refresh.is-syncing .pull-glyph::before {
  width: 1.05rem;
  height: 1.05rem;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  transform: none;
  animation: pr-spin 0.7s linear infinite;
}

.pull-refresh.is-done { color: var(--success); }
.pull-refresh.is-done .pull-glyph { transform: none; }
.pull-refresh.is-done .pull-glyph::before {
  width: 0.5rem;
  height: 0.85rem;
  border: 0 solid var(--success);
  border-right-width: 2.5px;
  border-bottom-width: 2.5px;
  border-radius: 1px;
  transform: rotate(45deg) translate(-10%, -10%);
}

.pull-refresh.is-error { color: var(--warn); }
.pull-refresh.is-error .pull-glyph { transform: none; }
.pull-refresh.is-error .pull-glyph::before { border-color: var(--warn); }

@keyframes pr-spin { to { transform: rotate(360deg); } }

/* Reduced motion: no rubber-band rotation/fill transitions; the spinner spin and
   spring are neutralised by the global reduce block in base.css. State + label
   still communicate progress. */
@media (prefers-reduced-motion: reduce) {
  .pull-glyph { transform: none; }
}

/* === component: requests ===
   Chat-request history page: inset request rows, colour-coded handshake status
   badges (one colour per status from --success/--warn/--text-2/--danger), and a
   vertical event timeline. Tokens only; matches "Obsidian Glass" (hairline inset
   groups, frosted-calm surfaces). The .req-badge classes are shared with the
   pinned Requests section in conversations.html. */

.page-requests {
  display: flex; flex-direction: column; gap: var(--sp-5);
  padding: var(--sp-4); overflow-y: auto;
}
.page-requests__title { margin-bottom: var(--sp-1); }

.req-section { display: flex; flex-direction: column; gap: var(--sp-2); }
.req-section__title { color: var(--text-3); padding-inline: var(--sp-1); }

/* --- inset request-row group ------------------------------------------- */
.req-group {
  display: flex; flex-direction: column;
  border-radius: var(--r-md); background: var(--surface);
  box-shadow: var(--shadow-1); list-style: none;
}
.req-row {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--separator);
}
.req-row:last-child { border-bottom: none; }
.req-row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.req-row__head { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.req-row__head .conv-name { flex: 1; min-width: 0; }
.req-row__act { display: flex; gap: var(--sp-2); margin-top: var(--sp-1); }

/* --- status badge (shared with conversations.html requests) ------------- */
.req-badge {
  display: inline-flex; align-items: center; gap: var(--sp-1); flex: none;
  padding: 0.1rem var(--sp-2); border-radius: var(--r-pill);
  font-size: var(--fs-caption); font-weight: 600; text-transform: capitalize;
  letter-spacing: 0.02em;
  color: var(--rq-c, var(--text-2));
  background: color-mix(in srgb, var(--rq-c, var(--text-2)) 14%, transparent);
}
.req-badge .fa { font-size: 0.85em; }
.req-badge--created   { --rq-c: var(--text-2); }
.req-badge--delivered { --rq-c: var(--text-2); }
.req-badge--pending   { --rq-c: var(--warn); }
.req-badge--accepted  { --rq-c: var(--success); }
.req-badge--rejected  { --rq-c: var(--danger); }
@supports not (color: color-mix(in srgb, red, blue)) {
  .req-badge { background: var(--surface-2); }
}

/* --- handshake timeline ------------------------------------------------- */
.req-timeline {
  display: flex; flex-direction: column; gap: var(--sp-1);
  list-style: none; margin: 0; padding-left: var(--sp-1);
}
.req-step {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-footnote); color: var(--text-2);
}
.req-step__dot {
  flex: none; width: 0.5rem; height: 0.5rem; border-radius: var(--r-pill);
  background: var(--rq-c, var(--text-3));
}
.req-step__dot--pending   { --rq-c: var(--warn); }
.req-step__dot--accepted  { --rq-c: var(--success); }
.req-step__dot--rejected  { --rq-c: var(--danger); }
.req-step__label { text-transform: capitalize; color: var(--text); }
.req-step__at { margin-left: auto; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* --- empty state glyph -------------------------------------------------- */
.req-empty-glyph { font-size: 2.5rem; color: var(--accent); opacity: 0.85; }

@media (min-width: 600px) {
  .page-requests { max-width: var(--content-max); margin-inline: auto; padding: var(--sp-6); }
}

/* === component: settings ===
   Settings page: inset list-groups, the live theme-card picker, the iOS-style
   notifications toggle, and the zero-knowledge explainer card. Uses only tokens
   from tokens.css (theme blocks live there; never redefined here). Owned by W2. */

.settings {
  height: 100%;
  padding: var(--sp-4) var(--sp-4) var(--sp-10);
  display: flex; flex-direction: column; gap: var(--sp-6);
  max-width: var(--content-max); margin: 0 auto; width: 100%;
}
.settings-head { padding: var(--sp-2) var(--sp-1) 0; }

.settings-section { display: flex; flex-direction: column; gap: var(--sp-3); }
.settings-section__title { padding: 0 var(--sp-1); }
.settings-note { padding: 0 var(--sp-1); font-size: var(--fs-footnote); color: var(--text-3); }

/* --- list-group / list-item (iOS inset grouped rows) --------------------- */
.list-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.list-group > * + * { border-top: 1px solid var(--separator); }
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); min-height: 2.75rem;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-body);
}
.list-item__label { color: var(--text); }
.list-item__value { color: var(--text-2); font-size: var(--fs-callout); }
.list-item__value--muted { color: var(--text-3); }

/* "How encryption works" as a self-contained native disclosure row. */
.list-item--details { display: block; padding: 0; }
.list-item__summary {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); min-height: 2.75rem;
  padding: var(--sp-3) var(--sp-4);
  list-style: none; cursor: pointer;
}
.list-item__summary::-webkit-details-marker { display: none; }
.list-item--details:focus-within .list-item__summary { box-shadow: var(--ring); }
.list-item__expand {
  padding: 0 var(--sp-4) var(--sp-3);
  font-size: var(--fs-callout); color: var(--text-2);
}
.chevron {
  width: 1rem; height: 1rem; flex: none;
  fill: none; stroke: var(--text-3); stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
  transition: transform var(--dur-fast) var(--ease-std);
}
.list-item--details[open] .chevron { transform: rotate(90deg); }

/* Hide the Add-to-Home-Screen hint once the app runs as an installed PWA. */
@media (display-mode: standalone) { .a2hs-hint { display: none; } }

.settings-logout { width: 100%; }

/* --- toggle (iOS switch) ------------------------------------------------- */
.toggle { position: relative; display: inline-flex; flex: none; }
.toggle input {
  position: absolute; inset: 0; margin: 0;
  width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
.toggle__track {
  display: flex; align-items: center;
  width: 3.25rem; height: 1.9rem; padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-pill);
  transition: background var(--dur-fast) var(--ease-std);
}
.toggle__thumb {
  width: 1.55rem; height: 1.55rem;
  background: var(--bg-elev); border-radius: var(--r-pill);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-fast) var(--ease-std);
}
.toggle input:checked + .toggle__track { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle__track .toggle__thumb { transform: translateX(1.35rem); }
.toggle input:focus-visible + .toggle__track { box-shadow: var(--ring); }
.toggle input:disabled + .toggle__track { opacity: 0.5; }
.toggle input:disabled { cursor: not-allowed; }

/* --- zero-knowledge explainer card -------------------------------------- */
.zk-card {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-md);
}
.zk-card .seal { width: 2rem; height: 2rem; flex: none; }
.zk-card__title { font-size: var(--fs-headline); font-weight: 600; margin-bottom: var(--sp-1); }
.zk-card__body { font-size: var(--fs-callout); color: var(--text-2); }

/* --- theme-picker + theme-card (live token previews) -------------------- */
.theme-picker {
  display: flex; gap: var(--sp-3);
  overflow-x: auto; padding: var(--sp-1) var(--sp-1) var(--sp-2);
}
.theme-card {
  flex: 0 0 4.75rem;
  display: flex; flex-direction: column; gap: var(--sp-2);
  padding: 0; background: none; border: none; cursor: pointer;
}
.theme-card__preview {
  position: relative; display: block; width: 100%; aspect-ratio: 3 / 4;
  padding: var(--sp-2);
  background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  overflow: hidden;
  transition: box-shadow var(--dur-fast) var(--ease-std), border-color var(--dur-fast) var(--ease-std);
}
.theme-card__chrome {
  position: absolute; top: 0; left: 0; right: 0; height: 26%;
  background: var(--chrome);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.theme-card__bubbles {
  position: absolute; left: var(--sp-2); right: var(--sp-2); bottom: var(--sp-2);
  display: flex; flex-direction: column; gap: var(--sp-1);
}
.theme-card__bubble { height: 0.55rem; border-radius: var(--r-tail); }
.theme-card__bubble--recv {
  width: 68%; align-self: flex-start;
  background: var(--bubble-recv); border: 1px solid var(--border);
}
.theme-card__bubble--sent { width: 74%; align-self: flex-end; background: var(--bubble-sent); }
.theme-card__check { display: none; position: absolute; top: var(--sp-1); right: var(--sp-1); width: 1.1rem; height: 1.1rem; }
.theme-card.is-selected .theme-card__preview { border-color: var(--accent); box-shadow: var(--ring); }
.theme-card.is-selected .theme-card__check { display: block; }
.theme-card:focus-visible { outline: none; }
.theme-card:focus-visible .theme-card__preview { box-shadow: var(--ring); }
.theme-card__label {
  text-align: center; font-size: var(--fs-footnote); color: var(--text-2);
}
.theme-card.is-selected .theme-card__label { color: var(--text); font-weight: 600; }

/* === component: sheet ===
   Bottom-sheet / modal shell for the compose forms (DESIGN §5.3, §6 #28). Scrim +
   grab handle + rounded top; rises on compact, centers as a card on >=600px.
   Animates transform/opacity only (no layout thrash). [hidden] gates display;
   nav.js toggles .is-open to drive the transition. Owned by W1. Tokens only. */

.sheet { position: fixed; inset: 0; z-index: var(--z-sheet); }
.sheet[hidden] { display: none; }

.sheet__scrim {
  position: absolute; inset: 0; z-index: var(--z-scrim);
  background: var(--scrim); opacity: 0;
  transition: opacity var(--dur-base) var(--ease-std);
}
.sheet.is-open .sheet__scrim { opacity: 1; }

.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: var(--z-sheet);
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4) calc(var(--safe-bottom) + var(--sp-5));
  background: var(--bg-elev); color: var(--text);
  border-top-left-radius: var(--r-xl); border-top-right-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  transform: translateY(100%);
  transition: transform var(--dur-slow) var(--ease-in);
  will-change: transform;
}
.sheet.is-open .sheet__panel {
  transform: none;
  transition: transform var(--dur-base) var(--ease-out);
}

.sheet__handle {
  align-self: center; width: 2.25rem; height: var(--r-tail);
  margin: var(--sp-1) 0; opacity: 0.45;
  background: var(--text-3); border-radius: var(--r-pill);
}
.sheet__head { display: flex; align-items: center; gap: var(--sp-2); }
.sheet__title { flex: 1; font-size: var(--fs-title-2); font-weight: 600; letter-spacing: -0.02em; }

/* >=600px: present as a centered modal card rather than an edge-anchored sheet. */
@media (min-width: 600px) {
  .sheet__panel {
    left: 50%; right: auto; bottom: auto; top: 50%;
    width: min(28rem, calc(100vw - var(--sp-8)));
    padding-bottom: var(--sp-5);
    border-radius: var(--r-lg);
    transform: translate(-50%, calc(-50% + 16px));
  }
  .sheet.is-open .sheet__panel { transform: translate(-50%, -50%); }
  .sheet__handle { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet__scrim, .sheet__panel { transition-duration: 1ms; }
}

/* === component: shell (app-shell) ===
   The responsive app-shell grid + frosted chrome + the 600/1024 breakpoints
   from DESIGN.md §3. One DOM, CSS-driven reflow — no JS layout branching.
   Owned by F0; FROZEN. Downstream nav/pages slot their panes into this grid. */

body {
  display: grid;
  grid-template-rows: auto 1fr;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* Frosted, translucent header that floats over content (§0, §1.4). */
.app-header {
  position: sticky; top: 0; z-index: var(--z-chrome);
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--header-h);
  padding: var(--safe-top) var(--sp-4) 0;
  background: var(--chrome);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.app-header h1 { flex: 1; font-size: var(--fs-title-2); font-weight: 700; letter-spacing: -0.02em; }

.who { display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-callout); color: var(--text-2); }
.who #me { font-weight: 600; color: var(--text); }

/* Content region: scrolls internally, tinted lock/empty wash behind it. */
.app-main {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: var(--overlay-tint), var(--bg);
}

/* Chat workspace: stacked on compact, master-detail from medium up. */
.chat {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: var(--sp-3);
  height: 100%;
  padding: var(--sp-4);
  overflow: hidden;
}

@media (min-width: 600px) {
  .chat {
    grid-template-columns: var(--list-w) 1fr;
    grid-template-rows: auto 1fr;
    column-gap: var(--sp-6);
    padding: var(--sp-6);
  }
  /* compose forms span the list column; conv-view fills the detail side. */
  .chat .start { grid-column: 1; }
  #conversations { grid-column: 1; }
  #conv-view { grid-column: 2; grid-row: 1 / span 2; }
}

@media (min-width: 1024px) {
  .chat { grid-template-columns: var(--list-w) minmax(0, 1fr); }
  #conv-view { max-width: var(--content-max); }
}

/* === component: tokens ===
   Complete custom-property system + the four theme blocks + the auto
   prefers-color-scheme query. Verbatim values from DESIGN.md §1–2.
   Owned by F0; FROZEN — theme blocks live here, not in a separate themes.css. */

/* --- theme-independent foundations (§1) ---------------------------------- */
:root {
  /* Type */
  --font-sys: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Mono",
    "Roboto Mono", monospace;
  --fs-display: 2.125rem; --fs-title: 1.5rem; --fs-title-2: 1.25rem;
  --fs-headline: 1.0625rem; --fs-body: 1rem; --fs-callout: 0.9375rem;
  --fs-footnote: 0.8125rem; --fs-caption: 0.6875rem;

  /* Spacing (4px base) */
  --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem;
  --sp-5: 1.25rem; --sp-6: 1.5rem; --sp-8: 2rem; --sp-10: 2.5rem; --sp-12: 3rem;

  /* Radii */
  --r-xs: 0.375rem; --r-sm: 0.625rem; --r-md: 0.875rem; --r-lg: 1.25rem;
  --r-xl: 1.75rem; --r-bubble: 1.125rem; --r-tail: 0.3125rem; --r-pill: 999px;

  /* Elevation */
  --shadow-1: 0 1px 2px var(--shadow-color),
    0 4px 12px color-mix(in srgb, var(--shadow-color) 60%, transparent);
  --shadow-2: 0 8px 28px color-mix(in srgb, var(--shadow-color) 80%, transparent);
  --shadow-3: 0 20px 60px var(--shadow-color);
  --ring: 0 0 0 3px var(--accent-ring);

  /* Motion */
  --dur-fast: 120ms; --dur-base: 240ms; --dur-slow: 360ms;
  --ease-std: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.5, 0, 0.84, 0);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Layout metrics */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);
  --header-h: 3rem; --tabbar-h: 3.25rem; --composer-h: 3rem;
  --rail-w: 4.5rem; --list-w: 21rem; --detail-w: 20rem;
  --content-max: 48rem; --pull-trigger: 64px;

  /* Z-index */
  --z-base: 0; --z-sticky: 10; --z-pull: 40; --z-chrome: 100;
  --z-scrim: 190; --z-sheet: 200; --z-toast: 300;
}

/* color-mix fallback for the elevation tokens (older WebKit safety net). */
@supports not (color: color-mix(in srgb, red, blue)) {
  :root { --shadow-1: 0 1px 2px var(--shadow-color), 0 4px 12px var(--shadow-color);
    --shadow-2: 0 8px 28px var(--shadow-color); }
}

/* --- Light (default) & Dark (§2.2) -------------------------------------- */
:root,
[data-theme="light"] {
  --bg: #F2F3F7; --bg-elev: #FFFFFF; --surface: #FFFFFF; --surface-2: #ECEEF4;
  --chrome: rgba(248, 249, 252, 0.72); --scrim: rgba(16, 19, 27, 0.32);
  --text: #0E1116; --text-2: #5B6573; --text-3: #9AA3B2; --text-on-accent: #FFFFFF;
  --accent: #3B49DF; --accent-press: #2E3BC4; --accent-soft: #E6E8FF;
  --accent-2: #00B3A4; --accent-ring: rgba(59, 73, 223, 0.40);
  --bubble-sent: linear-gradient(180deg, #4A58F2 0%, #3B49DF 100%);
  --bubble-sent-text: #FFFFFF; --bubble-recv: #FFFFFF; --bubble-recv-text: #0E1116;
  --success: #1FBF75; --warn: #F5A524; --danger: #E5402B; --danger-soft: #FCE5E1;
  --border: rgba(16, 19, 27, 0.10); --separator: rgba(16, 19, 27, 0.07);
  --shadow-color: rgba(20, 26, 50, 0.10);
  --overlay-tint: radial-gradient(120% 80% at 50% 0%,
    rgba(59, 73, 223, 0.06) 0%, transparent 60%);
}

[data-theme="dark"] {
  --bg: #0B0E14; --bg-elev: #11151D; --surface: #161B25; --surface-2: #1E2430;
  --chrome: rgba(12, 15, 21, 0.66); --scrim: rgba(0, 0, 0, 0.55);
  --text: #EAEDF3; --text-2: #99A2B2; --text-3: #5E6675; --text-on-accent: #FFFFFF;
  --accent: #5B6CFF; --accent-press: #4655E0; --accent-soft: rgba(91, 108, 255, 0.16);
  --accent-2: #2BD4C4; --accent-ring: rgba(91, 108, 255, 0.45);
  --bubble-sent: linear-gradient(180deg, #5E6DFF 0%, #4A58F0 100%);
  --bubble-sent-text: #FFFFFF; --bubble-recv: #1E2430; --bubble-recv-text: #EAEDF3;
  --success: #34D08A; --warn: #F7B84B; --danger: #FF6A56; --danger-soft: rgba(255, 106, 86, 0.16);
  --border: rgba(255, 255, 255, 0.08); --separator: rgba(255, 255, 255, 0.06);
  --shadow-color: rgba(0, 0, 0, 0.50);
  --overlay-tint: radial-gradient(120% 80% at 50% 0%,
    rgba(91, 108, 255, 0.10) 0%, transparent 60%);
}

/* --- aurora (§2.3) ------------------------------------------------------- */
[data-theme="aurora"] {
  --bg: #070B16; --bg-elev: #0D1426; --surface: #111A30; --surface-2: #16213C;
  --chrome: rgba(8, 12, 24, 0.62); --scrim: rgba(2, 4, 10, 0.58);
  --text: #ECF1FF; --text-2: #93A1C4; --text-3: #5A678A; --text-on-accent: #04201A;
  --accent: #3DE0C0; --accent-press: #2BC4A6; --accent-soft: rgba(61, 224, 192, 0.14);
  --accent-2: #8B7BFF; --accent-ring: rgba(61, 224, 192, 0.45);
  --bubble-sent: linear-gradient(135deg, #3DE0C0 0%, #36B8E0 100%);
  --bubble-sent-text: #04201A; --bubble-recv: #16213C; --bubble-recv-text: #ECF1FF;
  --success: #3DE0C0; --warn: #F2C14E; --danger: #FF6A7A; --danger-soft: rgba(255, 106, 122, 0.16);
  --border: rgba(140, 170, 255, 0.12); --separator: rgba(140, 170, 255, 0.08);
  --shadow-color: rgba(0, 0, 0, 0.55);
  --overlay-tint: radial-gradient(120% 80% at 50% 0%,
    rgba(61, 224, 192, 0.10) 0%, transparent 55%);
}

/* --- ember (§2.3) -------------------------------------------------------- */
[data-theme="ember"] {
  --bg: #14100E; --bg-elev: #1C1714; --surface: #221B17; --surface-2: #2B231D;
  --chrome: rgba(20, 16, 14, 0.64); --scrim: rgba(8, 5, 3, 0.58);
  --text: #F7EEE6; --text-2: #BBA595; --text-3: #7A685B; --text-on-accent: #2A0F06;
  --accent: #FF7A4D; --accent-press: #E8623A; --accent-soft: rgba(255, 122, 77, 0.16);
  --accent-2: #FFC24B; --accent-ring: rgba(255, 122, 77, 0.45);
  --bubble-sent: linear-gradient(135deg, #FF8A52 0%, #F2643C 100%);
  --bubble-sent-text: #2A0F06; --bubble-recv: #2B231D; --bubble-recv-text: #F7EEE6;
  --success: #62C98B; --warn: #FFC24B; --danger: #FF5C57; --danger-soft: rgba(255, 92, 87, 0.16);
  --border: rgba(255, 200, 160, 0.10); --separator: rgba(255, 200, 160, 0.07);
  --shadow-color: rgba(0, 0, 0, 0.55);
  --overlay-tint: radial-gradient(120% 80% at 50% 0%,
    rgba(255, 122, 77, 0.10) 0%, transparent 55%);
}

/* --- auto: follow the OS (§2.4). 'light' is the default above; this maps the
   dark overrides onto the OS dark preference for the auto/unset state. ------ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]),
  [data-theme="auto"] {
    --bg: #0B0E14; --bg-elev: #11151D; --surface: #161B25; --surface-2: #1E2430;
    --chrome: rgba(12, 15, 21, 0.66); --scrim: rgba(0, 0, 0, 0.55);
    --text: #EAEDF3; --text-2: #99A2B2; --text-3: #5E6675; --text-on-accent: #FFFFFF;
    --accent: #5B6CFF; --accent-press: #4655E0; --accent-soft: rgba(91, 108, 255, 0.16);
    --accent-2: #2BD4C4; --accent-ring: rgba(91, 108, 255, 0.45);
    --bubble-sent: linear-gradient(180deg, #5E6DFF 0%, #4A58F0 100%);
    --bubble-sent-text: #FFFFFF; --bubble-recv: #1E2430; --bubble-recv-text: #EAEDF3;
    --success: #34D08A; --warn: #F7B84B; --danger: #FF6A56; --danger-soft: rgba(255, 106, 86, 0.16);
    --border: rgba(255, 255, 255, 0.08); --separator: rgba(255, 255, 255, 0.06);
    --shadow-color: rgba(0, 0, 0, 0.50);
    --overlay-tint: radial-gradient(120% 80% at 50% 0%,
      rgba(91, 108, 255, 0.10) 0%, transparent 60%);
  }
}

