/* Components read tokens from app/ui/tokens.css only. No raw colors below this line. */
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 700;
  font-stretch: 75%;
  font-display: swap;
  src: url("./assets/fonts/roboto-latin-variable.woff2") format("woff2");
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: var(--stage-size);
  height: var(--stage-size);
  overflow: hidden;
  background: var(--color-stage);
  color: var(--color-text);
  font-family: var(--font-family);
  font-weight: 700;
  font-stretch: 75%;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button, input { font: inherit; color: inherit; }

/* ---------- Stage: fixed 600×600, nothing scrolls ---------- */
#stage {
  position: relative;
  isolation: isolate;
  width: var(--stage-size);
  height: var(--stage-size);
  overflow: hidden;
  background: var(--color-stage);
}

/* Ambient background: two soft glows, slow drift. steps() caps the animation at 30 FPS
   (22s × 30 = 660 steps) so the compositor does not repaint at 60/120 Hz for no gain. */
#bg { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
#bg::before, #bg::after {
  content: "";
  position: absolute;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  filter: blur(18px);
}
#bg::before { left: -110px; top: 330px; background: radial-gradient(closest-side, var(--color-glow-a), transparent); animation: bg-drift-a 22s steps(660, end) infinite; }
#bg::after { right: -120px; top: -90px; background: radial-gradient(closest-side, var(--color-glow-b), transparent); animation: bg-drift-b 26s steps(780, end) infinite; }
@keyframes bg-drift-a { 0%, 100% { transform: translate3d(0, 0, 0) scale(1); } 50% { transform: translate3d(14px, -10px, 0) scale(1.05); } }
@keyframes bg-drift-b { 0%, 100% { transform: translate3d(0, 0, 0) scale(1); } 50% { transform: translate3d(-12px, 12px, 0) scale(1.04); } }
body[data-app-visibility="hidden"] #bg::before, body[data-app-visibility="hidden"] #bg::after { animation-play-state: paused; }

/* ---------- App root and screen transitions ---------- */
#app {
  position: absolute;
  inset: 0 0 calc(var(--stage-size) - var(--safe-bottom)) 0; /* ends at y=576 */
  z-index: 1;
  display: flex;
  outline: none;
  transition: opacity var(--motion-fast) ease;
}
#app.is-leaving { opacity: 0; transition: opacity var(--motion-fast) ease, transform var(--motion-fast) ease; }
/* Directional transitions: deeper slides in from the right, back from the left. */
#app.is-leaving[data-direction="forward"] { transform: translateX(-18px); }
#app.is-leaving[data-direction="back"] { transform: translateX(18px); }
#app[data-direction="forward"] > .screen { animation-name: screen-in-forward; }
#app[data-direction="back"] > .screen { animation-name: screen-in-back; }
@keyframes screen-in-forward { from { opacity: 0; transform: translateX(26px); } to { opacity: 1; transform: none; } }
@keyframes screen-in-back { from { opacity: 0; transform: translateX(-26px); } to { opacity: 1; transform: none; } }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--safe-inset);
  text-align: center;
  animation: screen-settle var(--motion-slow) var(--motion-ease-out);
}
@keyframes screen-settle { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }

/* ---------- Type ---------- */
.ui-title { font-size: var(--font-size-display); line-height: var(--line-height-tight); letter-spacing: 0; }
h2.ui-title { font-size: var(--font-size-title); }
.eyebrow { font-size: var(--font-size-body); color: var(--color-text-quiet); text-transform: uppercase; letter-spacing: 0.08em; }
.lede { max-width: 440px; font-size: 20px; line-height: var(--line-height-body); color: var(--color-text-muted); }
.footnote { font-size: var(--font-size-caption); color: var(--color-text-quiet); }
.hint { font-size: var(--font-size-body); color: var(--color-text-quiet); }

/* ---------- Buttons ---------- */
.ui-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  min-width: 160px;
  padding: var(--space-3) var(--space-5);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface-control-top), var(--surface-control-bottom));
  box-shadow: var(--shadow-raised);
  font-size: var(--font-size-control);
  line-height: var(--line-height-tight);
  cursor: pointer;
  outline: none;
  transition: transform var(--motion-fast) var(--motion-ease-spring), background var(--motion-fast) ease, border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease;
}
.ui-button-detail { font-size: var(--font-size-body); color: var(--color-text-quiet); }
.ui-button--primary { background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom)); }
.ui-button--danger { background: linear-gradient(180deg, var(--surface-danger-top), var(--surface-danger-bottom)); }
.ui-button[aria-disabled="true"] { opacity: 0.55; }

/* Focus: border + ring + scale, so selection never depends on color alone. */
.focusable.nav-on {
  border-color: var(--focus-border);
  background: linear-gradient(180deg, var(--focus-top), var(--focus-bottom));
  box-shadow: 0 0 0 4px var(--focus-ring), var(--shadow-raised);
  transform: scale(var(--focus-scale));
}
.ui-button--primary.nav-on { background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom)); }
.ui-button--danger.nav-on { background: linear-gradient(180deg, var(--surface-danger-top), var(--surface-danger-bottom)); }
.ui-button .ui-button-detail { pointer-events: none; }

/* ---------- Menus ---------- */
.ui-menu { display: flex; flex-direction: column; gap: var(--space-3); width: 400px; }
.ui-menu .ui-button { width: 100%; min-height: 72px; }
.ui-menu--settings .ui-button { flex-direction: row; justify-content: space-between; min-height: 64px; }
.ui-button--setting .ui-button-detail { font-size: 20px; color: var(--color-text-muted); }
.ui-button--setting.nav-on .ui-button-detail::before { content: "‹  "; }
.ui-button--setting.nav-on .ui-button-detail::after { content: "  ›"; }

.screen-actions { display: flex; flex-direction: column; gap: var(--space-3); }
.screen-actions--row { flex-direction: row; }

/* ---------- Avatars: drawn portraits in a circle (app/ui/chat-art.js) ---------- */
.avatar {
  --avatar-size: 44px;
  --pt-bg: var(--cast-unknown);
  --pt-skin: var(--skin-2);
  --pt-hair: var(--hair-jace);
  --pt-shirt: var(--shirt-mika);
  --pt-shirt-2: var(--shirt-mika);
  flex: 0 0 var(--avatar-size);
  display: grid;
  place-items: center;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%;
  overflow: hidden;
  background: var(--pt-bg);
  color: var(--cast-ink);
  font-size: calc(var(--avatar-size) * 0.5);
  line-height: 1;
}
.avatar--xs { --avatar-size: 26px; }
.avatar--sm { --avatar-size: 34px; }
.avatar--lg { --avatar-size: 58px; }
.avatar--xl { --avatar-size: 132px; }
.avatar-spacer { flex: 0 0 44px; }
.portrait { width: 100%; height: 100%; display: block; }
.avatar[data-cast="jace"] { --pt-bg: var(--cast-jace); --pt-skin: var(--skin-1); --pt-hair: var(--hair-jace); --pt-shirt: var(--shirt-jace); --pt-shirt-2: var(--shirt-jace-2); }
.avatar[data-cast="rafe"] { --pt-bg: var(--cast-rafe); --pt-skin: var(--skin-3); --pt-hair: var(--hair-rafe); --pt-shirt: var(--shirt-rafe); --pt-shirt-2: var(--shirt-rafe-2); }
.avatar[data-cast="eli"] { --pt-bg: var(--cast-eli); --pt-skin: var(--skin-1); --pt-hair: var(--hair-eli); --pt-shirt: var(--shirt-eli); }
.avatar[data-cast="dom"] { --pt-bg: var(--cast-dom); --pt-skin: var(--skin-4); --pt-hair: var(--hair-dom); --pt-shirt: var(--shirt-dom); }
.avatar[data-cast="cole"] { --pt-bg: var(--cast-cole); --pt-skin: var(--skin-2); --pt-hair: var(--hair-cole); --pt-shirt: var(--shirt-cole); --pt-shirt-2: var(--shirt-cole-2); }
.avatar[data-cast="mika"] { --pt-bg: var(--cast-mika); --pt-skin: var(--skin-2); --pt-hair: var(--hair-mika); --pt-shirt: var(--shirt-mika); }
.avatar[data-cast="you"] { --pt-bg: var(--cast-you); }
.pt-bg { fill: var(--pt-bg); }
.pt-skin { fill: var(--pt-skin); }
.pt-shade { fill: var(--pt-skin); }
.pt-hair { fill: var(--pt-hair); }
.pt-hair-hi { fill: var(--hair-jace-hi); }
.pt-shirt { fill: var(--pt-shirt); }
.pt-shirt-2 { fill: var(--pt-shirt-2); }
.pt-tee { fill: var(--tee-jace); }
.pt-ink { fill: var(--portrait-ink); }
.pt-line, .pt-line-soft, .pt-frame { fill: none; stroke: var(--portrait-ink); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.pt-line-soft { stroke: var(--pt-shirt-2); stroke-width: 1.4; }
.pt-frame { stroke: var(--portrait-frame); stroke-width: 1.6; }
.pt-mouth { fill: var(--portrait-mouth); }
.pt-teeth { fill: var(--portrait-teeth); }
.pt-blush { fill: var(--portrait-blush); }
.pt-stubble { fill: var(--portrait-stubble); }
.pt-metal { fill: var(--portrait-metal); }
.pt-hat { fill: var(--hat-eli); }
.pt-hat-band { fill: var(--hat-eli-band); }
.pt-band { fill: var(--band-dom); }
.pt-camera { fill: var(--camera-mika); }
.pt-lens { fill: var(--lens-mika); }
.pt-shadow { fill: var(--shadow-unknown); }
.pt-mark { fill: var(--cast-unknown-soft); font-size: 22px; font-weight: 700; text-anchor: middle; }

/* A few portraits overlapped (group chats). Each keeps a ring of the panel color. */
.avatar-stack { display: inline-flex; flex: none; }
.avatar-stack .avatar { box-shadow: 0 0 0 3px var(--surface-system); }
.avatar-stack .avatar + .avatar { margin-left: calc(var(--avatar-size) * -0.42); }

/* Each speaker's light tint: names, bubble edge, reaction glyphs. */
[data-cast="jace"] { --speaker: var(--cast-jace-soft); }
[data-cast="rafe"] { --speaker: var(--cast-rafe-soft); }
[data-cast="eli"] { --speaker: var(--cast-eli-soft); }
[data-cast="dom"] { --speaker: var(--cast-dom-soft); }
[data-cast="cole"] { --speaker: var(--cast-cole-soft); }
[data-cast="mika"] { --speaker: var(--cast-mika-soft); }
[data-cast="unknown"] { --speaker: var(--cast-unknown-soft); }

.glyph { width: 18px; height: 18px; fill: currentColor; flex: none; }

/* ---------- Chat: header, bottom-aligned log, reply tray ----------
   Nothing scrolls. Live: the newest entry is the one primary reading; older ones are
   dimmer context. History (after a swipe up): one page of earlier entries at reading
   size. Whatever does not fit fades out at the top. */
.screen--chat {
  align-items: stretch;
  justify-content: flex-start;
  gap: 0;
  padding: 0;
  text-align: left;
}
.chat-header {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 68px;
  padding: var(--space-2) var(--space-5);
  background: linear-gradient(180deg, var(--surface-panel-top), var(--surface-panel-bottom));
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.chat-badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom));
}
.chat-badge-glyph { width: 26px; height: 26px; color: var(--color-text); }
.chat-badge .avatar { --avatar-size: 46px; }
.chat-heading { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chat-title { font-size: 24px; line-height: var(--line-height-tight); letter-spacing: 0.02em; }
.chat-status { display: flex; align-items: center; gap: 6px; min-height: 26px; font-size: var(--font-size-body); color: var(--color-text-quiet); }
.chat-status.is-typing { color: var(--color-accent-soft); }
.chat-status .avatar { animation: typing-pulse 1.2s steps(36, end) infinite; }
@keyframes typing-pulse { 0%, 100% { scale: 1; } 50% { scale: 1.14; } }
body[data-app-visibility="hidden"] .chat-status .avatar { animation-play-state: paused; }

/* History (swiped up): the log sits on its own panel so it never reads as "now". */
.screen--chat[data-mode="history"] .chat-log { margin: var(--space-2) var(--space-3) 0; border-radius: var(--radius-lg); background: var(--surface-system); }
.screen--chat[data-mode="history"] .chat-status { color: var(--color-warn); }
.chat-row--start, .chat-row--resume { justify-content: center; }
.chat-row--start { align-self: center; padding: 3px var(--space-4); border-radius: var(--radius-pill); background: var(--surface-bubble-bottom); font-size: var(--font-size-caption); color: var(--color-text-quiet); }
.chat-resume {
  padding: 3px var(--space-4);
  border-radius: var(--radius-pill);
  background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom));
  font-size: var(--font-size-caption);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-log {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  padding: var(--space-3) var(--space-5) var(--space-2);
  overflow: hidden;
  mask-image: linear-gradient(180deg, transparent 6px, var(--color-stage) 56px);
}
.chat-row {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  font-size: var(--font-size-body);
  line-height: var(--line-height-body);
}
.chat-row.is-grouped { margin-top: -5px; }
.chat-log[data-mode="live"] .chat-row { opacity: 0.66; }
.chat-log[data-mode="live"] .chat-row.is-current { font-size: 21px; opacity: 1; }
.chat-log[data-mode="history"] .chat-row { font-size: 18px; }
.chat-row.is-new { animation: chat-arrive var(--motion-base) var(--motion-ease-spring); transform-origin: 0 100%; }
.chat-row--you.is-new { transform-origin: 100% 100%; animation: chat-send var(--motion-base) var(--motion-ease-out); }
@keyframes chat-send { from { opacity: 0.3; transform: translateY(54px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes chat-arrive { from { opacity: 0; transform: translateY(10px) scale(0.94); } to { opacity: 1; transform: none; } }
.chat-row--you { justify-content: flex-end; }
.chat-row--system { justify-content: center; }
.chat-system {
  padding: 3px var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--surface-system);
  color: var(--color-text-muted);
  font-size: var(--font-size-body);
  text-align: center;
}
.chat-column { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.chat-row--you .chat-column { align-items: flex-end; }
.chat-name { padding-left: var(--space-2); font-size: var(--font-size-caption); letter-spacing: 0.03em; color: var(--speaker, var(--color-text-quiet)); }
.chat-bubble {
  max-width: 416px;
  padding: 9px var(--space-4) 10px;
  border-radius: 20px;
  border-bottom-left-radius: 6px;
  border-left: 5px solid var(--speaker, transparent);
  background: linear-gradient(180deg, var(--surface-bubble-top), var(--surface-bubble-bottom));
  overflow-wrap: anywhere;
}
.chat-row.is-grouped .chat-bubble { border-top-left-radius: 6px; }
.chat-row--you .chat-bubble {
  border-left: none;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 6px;
  background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom));
}
.chat-bubble--deleted {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  border-left-color: transparent;
  background: var(--surface-system);
  color: var(--color-text-quiet);
  font-style: italic;
}
.chat-deleted-glyph { width: 16px; height: 16px; }
.chat-receipt { padding-right: var(--space-1); font-size: var(--font-size-caption); color: var(--color-text-quiet); }
.chat-receipt[data-receipt="read"] { color: var(--color-accent-soft); }
/* "Eli liked that": who warmed to the reply, under it. */
.chat-noticed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px var(--space-3) 3px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--surface-system);
  font-size: var(--font-size-caption);
  color: var(--color-text-muted);
  animation: noticed-in var(--motion-slow) var(--motion-ease-spring);
}
.chat-noticed-glyph { width: 14px; height: 14px; color: var(--color-accent); }
.chat-noticed-faces { display: inline-flex; }
.chat-noticed-faces .avatar { --avatar-size: 22px; box-shadow: 0 0 0 2px var(--surface-system); }
.chat-noticed-faces .avatar + .avatar { margin-left: -7px; }
@keyframes noticed-in { from { opacity: 0; transform: translateY(6px) scale(0.9); } to { opacity: 1; transform: none; } }
.chat-log[data-mode="live"] .chat-row:not(.is-current) .chat-noticed { animation: none; }

/* The unknown number: a colder, flatter thread. One speaker, so no names. */
.screen--chat[data-kind="direct"] .chat-name { display: none; }
.screen--chat[data-kind="direct"] .chat-header,
.screen--chat[data-kind="direct"] .chat-row--them .chat-bubble { background: linear-gradient(180deg, var(--surface-future-top), var(--surface-future-bottom)); }
.screen--chat[data-kind="direct"] .chat-row--them .chat-bubble { border-left: none; }
.screen--chat[data-kind="direct"] .chat-status { color: var(--cast-unknown-soft); }

/* Typing: three dots, quantized to the 30 FPS budget. */
.chat-typing { display: flex; align-items: center; gap: 6px; min-height: 42px; }
.chat-typing-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--speaker, var(--color-text-muted));
  animation: chat-typing 1.2s steps(36, end) infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-typing { 0%, 60%, 100% { opacity: 0.35; transform: none; } 30% { opacity: 1; transform: translateY(-4px); } }
body[data-app-visibility="hidden"] .chat-typing-dot { animation-play-state: paused; }

/* Reactions hang off the bottom edge of the bubble they answer. */
.chat-reactions { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: -9px 0 0 var(--space-3); }
.chat-row--you .chat-reactions { margin: -9px var(--space-3) 0 0; }
.chat-reaction {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2) 2px 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-system);
  color: var(--speaker, var(--color-accent-soft));
  font-size: var(--font-size-caption);
  line-height: 1.3;
}
.chat-reaction-name { color: var(--color-text-muted); }

/* Sticker: an illustrated die-cut character, no bubble (app/ui/chat-art.js). */
.sticker { display: inline-block; width: 118px; height: 118px; margin: var(--space-1) var(--space-1) 0; rotate: -4deg; }
.chat-row--you .sticker { rotate: 4deg; }
.chat-log[data-mode="live"] .chat-row.is-current .sticker { width: 132px; height: 132px; }
.sticker-art { width: 100%; height: 100%; display: block; overflow: visible; }
.sticker-art .st-face, .sticker-art .st-hand, .sticker-art .st-mug, .sticker-art .st-cap, .sticker-art .st-fire,
.sticker-art .st-heart, .sticker-art .st-star { stroke: var(--sticker-cut); stroke-width: 4; stroke-linejoin: round; paint-order: stroke; }
.st-face { fill: var(--sticker-face); }
.st-hand { fill: var(--sticker-hand); }
.st-ink { fill: var(--sticker-ink); }
.st-shine { fill: var(--sticker-cut); }
.st-line { fill: none; stroke: var(--sticker-ink); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.st-line--thin { stroke-width: 2.5; stroke: var(--sticker-face); }
.st-mouth { fill: var(--sticker-mouth); }
.st-tongue { fill: var(--sticker-tongue); }
.st-blush { fill: var(--sticker-blush); }
.st-heart { fill: var(--sticker-heart); }
.st-star { fill: var(--sticker-star); }
.st-fire { fill: var(--sticker-fire); }
.st-halo { fill: none; stroke: var(--sticker-halo); stroke-width: 5; }
.st-cap { fill: var(--sticker-cap); }
.st-pom { fill: var(--sticker-cut); }
.st-z { fill: var(--sticker-z); font-size: 18px; font-weight: 700; stroke: var(--sticker-cut); stroke-width: 3; paint-order: stroke; }
.st-z--big { font-size: 26px; }
.st-mug { fill: var(--sticker-mug); }
.st-mug-handle { fill: none; stroke: var(--sticker-mug); stroke-width: 6; }
.st-steam, .st-zip { fill: none; stroke: var(--sticker-steam); stroke-width: 3.5; stroke-linecap: round; }
.st-tear { fill: var(--sticker-tear); }
.st-stick { fill: none; stroke: var(--sticker-stick); stroke-width: 6; stroke-linecap: round; }
.st-stick-tip { fill: var(--sticker-stick); }
.st-arm { fill: none; stroke: var(--sticker-face); stroke-width: 9; stroke-linecap: round; }
.st-caption {
  fill: var(--sticker-caption);
  stroke: var(--sticker-caption-edge);
  stroke-width: 6;
  stroke-linejoin: round;
  paint-order: stroke;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-anchor: middle;
}
.chat-row.is-new .sticker { animation: sticker-pop var(--motion-slow) var(--motion-ease-spring); }
@keyframes sticker-pop { 0% { scale: 0.5; } 60% { scale: 1.1; } 100% { scale: 1; } }

/* Photo: a print pinned to the chat. Who is in the frame, where, and a caption. */
.photo {
  display: flex;
  flex-direction: column;
  width: 340px;
  padding: var(--space-2) var(--space-2) 0;
  border-radius: var(--radius-sm);
  background: var(--surface-print);
  rotate: -2deg;
  margin: var(--space-1) 0 var(--space-1) var(--space-1);
}
.photo-frame {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 150px;
  padding: var(--space-3);
  border-radius: var(--space-2);
  background: var(--surface-photo);
  background-image: radial-gradient(ellipse at 50% 0%, var(--color-glow-a), transparent 70%);
}
.photo-scene {
  position: absolute;
  top: var(--space-2);
  left: var(--space-3);
  font-size: var(--font-size-caption);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-quiet);
}
.photo-people { display: flex; gap: var(--space-2); }
.photo-caption { padding: 6px var(--space-2) var(--space-2); font-size: var(--font-size-body); color: var(--color-text-muted); }

/* Tray: a quiet hint, or the replies on their own panel. */
.chat-tray {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5) var(--space-3);
}
.chat-tray[data-mode="empty"] { padding: 0 0 var(--space-3); }
.ui-menu--settings .ui-button--primary { justify-content: center; }
.chat-tray[data-mode="options"] {
  padding: 10px var(--space-4) var(--space-3);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface-system);
}
.chat-hint { min-height: 22px; font-size: var(--font-size-body); color: var(--color-text-quiet); text-align: center; }
.chat-hint--reply { min-height: 0; padding-left: var(--space-2); font-size: var(--font-size-caption); text-align: left; }
.ui-button--reply {
  flex-direction: row;
  justify-content: flex-start;
  gap: var(--space-3);
  width: 100%;
  min-height: 48px;
  padding: 6px var(--space-4) 6px var(--space-2);
  border-radius: var(--radius-md);
  font-size: 20px;
  text-align: left;
  box-shadow: none;
}
.reply-tone {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-system);
  color: var(--color-accent-soft);
}
.ui-button--silent .ui-button-label { color: var(--color-text-muted); font-style: italic; }
/* The focused reply leads: the others step back, and its tone is named. */
.chat-tray[data-mode="options"] .ui-button--reply:not(.nav-on) { opacity: 0.72; }
.reply-tone-name { display: none; margin-left: auto; font-size: var(--font-size-caption); letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-accent-soft); }
.ui-button--reply.nav-on .reply-tone-name { display: block; }
.ui-button--reply.nav-on .reply-tone { background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom)); color: var(--color-text); }
/* Sending: the chosen reply lifts toward the chat, the rest fade. */
.chat-tray[data-mode="sending"] { padding: 10px var(--space-4) var(--space-3); border-radius: var(--radius-lg) var(--radius-lg) 0 0; background: var(--surface-system); }
.chat-tray[data-mode="sending"] .ui-button--reply:not(.is-chosen) { opacity: 0.25; transition: opacity var(--motion-fast) ease; }
.ui-button--reply.is-chosen { animation: reply-lift 220ms var(--motion-ease-out) forwards; }
@keyframes reply-lift { to { opacity: 0.2; transform: translateY(-34px) scale(1.03); } }

/* ---------- Name ---------- */
.screen--name { gap: var(--space-3); }
.name-display { min-height: 50px; font-size: var(--font-size-display); line-height: var(--line-height-tight); color: var(--color-accent-soft); }
.name-display.is-empty { color: var(--color-text-quiet); }
.name-field {
  width: 400px;
  min-height: 58px;
  padding: 0 var(--space-5);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface-field-top), var(--surface-field-bottom));
  font-size: 20px;
  text-align: center;
  outline: none;
}
.name-field::placeholder { color: var(--color-text-quiet); }
.screen--name .ui-button { width: 400px; min-height: 60px; }
.ui-button--wheel .ui-button-label { font-size: 26px; font-variant-numeric: tabular-nums; }

/* ---------- Inbox, settings and recap ---------- */
/* Inbox: chats as rows (portrait, name, last line, state), settings apart below. */
.screen--home { gap: var(--space-3); }
.ui-menu--threads { width: 500px; gap: var(--space-3); }
.ui-button--thread {
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: var(--space-4);
  min-height: 96px;
  padding: var(--space-3) var(--space-5) var(--space-3) var(--space-4);
  text-align: left;
}
.ui-button--thread .avatar-stack, .ui-button--thread > .avatar { width: 72px; justify-content: center; }
.thread-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.thread-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.thread-title { font-size: var(--font-size-control); letter-spacing: 0.02em; }
.thread-preview {
  font-size: var(--font-size-body);
  line-height: var(--line-height-body);
  color: var(--color-text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ui-button--thread[data-state="failed"] .thread-preview { color: var(--color-bad); }
.thread-badge {
  flex: none;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--surface-system);
  font-size: var(--font-size-caption);
  letter-spacing: 0.06em;
  color: var(--color-text-quiet);
  text-transform: uppercase;
}
.thread-badge[data-kind="new"] { background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom)); color: var(--color-text); }
.thread-badge[data-kind="dot"] { width: 14px; height: 14px; padding: 0; background: var(--color-accent); box-shadow: 0 0 0 3px var(--color-accent-soft); }
.thread-badge[data-kind="failed"] { background: var(--surface-danger-bottom); color: var(--color-bad); }
.thread-meter { display: flex; align-items: center; gap: var(--space-2); }
.thread-meter[hidden], .thread-badge[hidden] { display: none; }
.thread-meter-track { flex: 1; height: 6px; border-radius: var(--radius-pill); background: var(--surface-system); overflow: hidden; }
.thread-meter-fill { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--surface-action-top), var(--color-accent-soft)); }
.thread-meter-label { font-size: var(--font-size-caption); color: var(--color-text-quiet); }
.ui-button--quiet {
  flex-direction: row;
  gap: var(--space-2);
  min-width: 0;
  min-height: 48px;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-pill);
  background: var(--surface-system);
  box-shadow: none;
  font-size: 18px;
  color: var(--color-text-muted);
}
.ui-button--quiet .glyph { width: 20px; height: 20px; }
.ui-button[aria-disabled="true"] .ui-button-label { color: var(--color-text-muted); }
.screen--settings { gap: var(--space-2); padding-top: var(--space-5); padding-bottom: var(--space-3); }
.ui-menu--settings { gap: 5px; }
.ui-menu--settings .ui-button { min-height: 46px; padding-top: var(--space-1); padding-bottom: var(--space-1); }
.settings-preview { display: flex; align-items: flex-end; gap: var(--space-2); width: 440px; min-height: 52px; text-align: left; }
.settings-preview .chat-bubble { font-size: var(--font-size-body); }
.settings-preview-them { flex: 1; border-left-color: var(--cast-mika-soft); }
.settings-preview-you {
  flex: none;
  border-left: none;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 6px;
  background: linear-gradient(180deg, var(--surface-action-top), var(--surface-action-bottom));
}
.recap-portrait { display: grid; place-items: center; min-height: 112px; }
.recap-portrait .avatar { --avatar-size: 112px; }
.screen--chat-end[data-revealed="true"] .recap-portrait .avatar { animation: recap-pop var(--motion-slow) var(--motion-ease-spring); box-shadow: 0 0 0 5px var(--color-accent-soft), 0 0 36px var(--color-glow-a); }
@keyframes recap-pop { 0% { scale: 0.6; opacity: 0; } 70% { scale: 1.08; opacity: 1; } 100% { scale: 1; } }
.recap-name { font-size: var(--font-size-display); line-height: var(--line-height-tight); }
.screen--chat-end[data-revealed="true"] .recap-name { animation: recap-pop var(--motion-slow) var(--motion-ease-spring); }
.recap-line { min-height: 27px; font-size: 18px; }
.screen--chat-end { gap: var(--space-2); }
.recap-ranking { display: flex; align-items: flex-end; gap: var(--space-4); list-style: none; }
.recap-rank { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.recap-rank-name { font-size: var(--font-size-caption); color: var(--color-text-quiet); }
.recap-rank[data-place="1"] .recap-rank-name { color: var(--color-text); }
.recap-hook { display: flex; align-items: center; gap: var(--space-2); text-align: left; }
.recap-hook-text { font-size: var(--font-size-body); background: linear-gradient(180deg, var(--surface-future-top), var(--surface-future-bottom)); border-left: none; }
.screen--chat-end .screen-actions { margin-top: var(--space-1); }
.screen--chat-end .ui-button { min-width: 190px; min-height: 56px; }

/* ---------- Feedback: nudge + toast ---------- */
[data-nudge="left"] { animation: nudge-left 320ms ease-out; }
[data-nudge="right"] { animation: nudge-right 320ms ease-out; }
[data-nudge="up"] { animation: nudge-up 320ms ease-out; }
[data-nudge="down"] { animation: nudge-down 320ms ease-out; }
@keyframes nudge-left { 0%, 100% { translate: 0 0; } 24% { translate: calc(var(--motion-nudge-distance) * -1) 0; } 43% { translate: 4px 0; } 62% { translate: -3px 0; } 80% { translate: 1px 0; } }
@keyframes nudge-right { 0%, 100% { translate: 0 0; } 24% { translate: var(--motion-nudge-distance) 0; } 43% { translate: -4px 0; } 62% { translate: 3px 0; } 80% { translate: -1px 0; } }
@keyframes nudge-up { 0%, 100% { translate: 0 0; } 24% { translate: 0 calc(var(--motion-nudge-distance) * -1); } 43% { translate: 0 4px; } 62% { translate: 0 -3px; } 80% { translate: 0 1px; } }
@keyframes nudge-down { 0%, 100% { translate: 0 0; } 24% { translate: 0 var(--motion-nudge-distance); } 43% { translate: 0 -4px; } 62% { translate: 0 3px; } 80% { translate: 0 -1px; } }

.toast {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(var(--stage-size) - var(--safe-bottom) + var(--space-4)); /* stays above y=576 */
  max-width: 480px;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-pill);
  background: linear-gradient(180deg, var(--surface-panel-top), var(--surface-panel-bottom));
  font-size: 18px;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity var(--motion-base) ease, transform var(--motion-base) var(--motion-ease-out);
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast[data-tone="good"] { color: var(--color-good); }
.toast[data-tone="warn"] { color: var(--color-warn); }

/* ---------- Production FPS meter (passive) ---------- */
.performance-overlay {
  position: absolute; z-index: 9; top: var(--space-3); left: 50%; transform: translateX(-50%);
  display: flex; gap: var(--space-2); padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill); background: var(--surface-panel-bottom);
  font-size: var(--font-size-caption); pointer-events: none;
}

/* ---------- Reduced motion ---------- */
:root[data-motion="reduced"] *, :root[data-motion="reduced"] *::before, :root[data-motion="reduced"] *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 1ms !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
