:root {
  color-scheme: dark;
  --bg: #0b0c10;
  --panel: #15171c;
  --text: #f4f5f7;
  --muted: #9aa0ad;
  --border: #2a2e38;
  --accent: #c9b37e;
  --user-bg: #2a3344;
  --assistant-bg: #1b1d24;
  --mic: #d7263d;
  --mic-soft: #3a1520;
  --focus-ring: #c9b37e;
  --radius: 16px;
  --hud-color: #4fd6ff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* The page itself must never scroll (TM98) — only #messages does. Without
   * this, html/body have no height ceiling and grow with the chat log, so
   * the whole page scrolls and the sticky header/composer scroll away with
   * it. Locking both axes here forces the .app-shell flex column below to
   * absorb overflow internally instead. */
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
}
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #111;
  padding: 0.6rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
a, button, input { font: inherit; }
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
}
button:hover { border-color: var(--accent); }
*:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}
.app-shell {
  /* height, not min-height (TM98): the shell must be CLIPPED to the
   * viewport, not just tall enough to cover it, or a long chat log pushes
   * it taller than the screen and the whole page scrolls instead of just
   * #messages. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  /* TM611: same min-width:auto flex trap as .app-header below — on the
   * /iphone page, .app-shell is itself a flex item of a flex-column
   * container (.phone-screen), so without this it can be forced wider than
   * the viewport by a long unwrapped header-agent-name. */
  min-width: 0;
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  padding-top: calc(0.7rem + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
  /* TM611: without this, a flex item that is ITSELF a flex container (this
   * one) defaults to min-width:auto — its content-based minimum size — which
   * can silently override .header-status/.header-agent-name's own
   * min-width:0 and grow the WHOLE header (and .app-shell above it) past the
   * viewport on a long agent name, on any page where .app-header sits inside
   * another flex container (e.g. the /iphone frame's flex-column
   * .phone-screen > .app-shell). min-width:0 here makes the ellipsis
   * truncation on .header-agent-name actually take effect instead of the
   * header silently overflowing. */
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.brand h1 { font-size: 1.05rem; margin: 0; font-weight: 700; white-space: nowrap; }
.brand-mark { color: var(--accent); font-size: 1.2rem; }
/* TM586/TM611: top-left status area — redesigned (build 36) so the agent
 * name sits on the LEFT and the status word (Ready/Listening/etc.) on the
 * RIGHT of the SAME bar, not stacked underneath, both in noticeably larger
 * type. min-width:0 + flex:1 on the name (only) lets it shrink and truncate
 * with an ellipsis before it ever pushes mute/menu (.header-actions,
 * margin-left:auto) off a phone-width (390px) screen; the status word gets
 * flex-shrink:0 so it is NEVER the one that truncates. The old third
 * build-number line (build 35, .header-version) is gone entirely — the
 * version now lives only in Settings -> About (#versionLine). */
.header-status {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  min-width: 0;
  flex: 1 1 auto;
  line-height: 1.25;
}
.header-agent-name {
  font-size: 1.15rem;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-status-word {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  flex: 0 0 auto;
  white-space: nowrap;
}
/* Gentle opacity pulse — not a hard blink, which reads as an error state.
 * The page's existing @media (prefers-reduced-motion: reduce) rule already
 * forces every animation-duration to ~0 globally, so this needs no separate
 * reduced-motion override. */
.header-status-word.blinking {
  animation: header-status-pulse 1.6s ease-in-out infinite;
}
@keyframes header-status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.header-actions { display: flex; align-items: center; gap: 0.45rem; margin-left: auto; flex: 0 0 auto; }
.agent-select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 1.6rem 0.35rem 0.7rem;
  font-size: 0.78rem;
  max-width: 30vw;
}
.agent-select:disabled { opacity: 0.7; }
/* TM576: the live/fallback badge is removed entirely — no .agent-bridge-hint
 * rules remain (it used to sit next to .agent-select in the header). */
@media (max-width: 480px) {
  .agent-select { max-width: 38vw; font-size: 0.72rem; padding-right: 1.3rem; }
}
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--muted);
}
.mute-button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
}
.mute-button[aria-pressed="true"] { opacity: 0.55; }
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0.75rem 1rem 0.25rem;
  /* Explicit stacking (TM95 regression fix, build 13) — see .hud-canvas
   * below for why. */
  position: relative;
  z-index: 1;
}
.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.4rem 0 0.8rem;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: 86%;
  padding: 0.7rem 0.9rem;
  border-radius: 18px;
  font-size: 0.98rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble-user {
  align-self: flex-end;
  background: var(--user-bg);
  border-bottom-right-radius: 6px;
}
.bubble-assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.bubble-interim { opacity: 0.7; font-style: italic; }
/* TM616: formatted replies — bullets, bold, paragraphs — and a small time
 * under each bubble. Long-press to select/copy is native (text stays
 * selectable). */
.bubble-rich { white-space: normal; }
.bubble-rich p { margin: 0 0 0.45rem; }
.bubble-rich p:last-child { margin-bottom: 0; }
.bubble-rich ul, .bubble-rich ol { margin: 0.2rem 0 0.45rem; padding-left: 1.25rem; }
.bubble-rich li { margin: 0.18rem 0; }
.bubble-rich li::marker { color: var(--muted); }
.bubble-rich strong { font-weight: 650; }
.bubble-rich code { font-family: ui-monospace, Menlo, monospace; font-size: 0.9em; padding: 0 0.25em; border-radius: 4px; background: rgba(255, 255, 255, 0.08); }
.bubble-time {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: right;
  user-select: none;
  -webkit-user-select: none;
}
.bubble { -webkit-user-select: text; user-select: text; }
/* TM617: attachments */
.attach-button {
  flex: 0 0 auto;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.attach-button:active { color: var(--text); }
.attach-button[disabled] { opacity: 0.45; }
.bubble-attachments { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.15rem 0 0.4rem; }
.bubble-attachments:last-child { margin-bottom: 0; }
.attachment-thumb {
  display: block;
  min-width: 64px;
  min-height: 64px;
  max-width: 220px;
  max-height: 220px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.85rem;
  color: inherit;
  text-decoration: none;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pending-attachments {
  display: flex;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem 0;
  overflow-x: auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.pending-attachments[hidden] { display: none; }
.pending-chip {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.55rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 200px;
}
.pending-chip img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.pending-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-chip button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0 0 0 0.2rem;
}
.pending-chip.uploading { opacity: 0.6; }
.fallback-note { font-size: 0.8rem; color: var(--muted); margin: 0 0 0.4rem; }
.composer {
  display: flex;
  flex-wrap: wrap; /* TM696: the message box takes a full row of its own; buttons sit beneath it */
  align-items: flex-end; /* TM689: buttons stay at the bottom as the box grows */
  gap: 0.45rem;
  padding: 0.65rem 0.85rem;
  padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg);
  /* Explicit stacking (TM95 regression fix, build 13) — see .hud-canvas
   * below for why. */
  position: relative;
  z-index: 1;
}
#textInput {
  flex: 1 1 100%; /* TM696 (Barry: "way too narrow — full width and 1/4 in height") */
  order: -1;
  min-width: 0;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 1.2rem; /* TM689: a growing box — pill corners only fit one line */
  resize: none;
  line-height: 1.35;
  font: inherit;
  max-height: 45vh; /* TM696/TM698: one line until used; a quarter of the screen while typing; grows to under half */
  overflow-y: hidden;
  background: var(--panel);
  color: var(--text);
  /* TM652: iPhone painted this box white (its own form-control look and the
   * autofill highlight). Take the native look off and pin the dark colours. */
  -webkit-appearance: none;
  appearance: none;
  color-scheme: dark;
  caret-color: var(--accent);
}
#textInput:focus { background: var(--panel); color: var(--text); outline: 2px solid var(--accent); outline-offset: 1px; }
#textInput:-webkit-autofill,
#textInput:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--panel) inset;
  box-shadow: 0 0 0 1000px var(--panel) inset;
}
.custom-agent-form input, .custom-agent-form textarea, .custom-agent-form select, .login-form input {
  -webkit-appearance: none; appearance: none; color-scheme: dark;
}
.send-button {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
  font-weight: 700;
}
/* Mic button colors (TM100, build 16) — SWAPPED from the original design.
 * Was: red/highlighted by default, dimming when a session is active. Barry
 * wants the opposite — dark/neutral at rest, bright red only while actually
 * listening — so idle no longer reads as "something needs attention" and
 * red now means what it should: recording is live. */
.mic-button {
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.7rem 0.95rem;
}
.mic-button[aria-pressed="true"] {
  background: var(--mic);
  color: #fff;
  border-color: var(--mic);
  box-shadow: 0 0 0 3px rgba(215, 38, 61, 0.35);
}
.mic-copy { font-size: 0.85rem; max-width: 4.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* TM689: never squeeze the message box */
#sendButton { margin-left: auto; } /* TM696: Send sits at the right of the button row, next to the mic */
.app-footer { display: none; }
@media (min-width: 720px) {
  .app-footer {
    display: block;
    text-align: center;
    color: var(--muted);
    font-size: 0.75rem;
    padding: 0.4rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
@media (max-width: 480px) {
  html, body { overflow-x: hidden; }
  main { grid-template-columns: 1fr; }
  .app-shell { max-width: 100%; }
  .mic-copy { display: none; }
  .badge { display: none; }
  .bubble { max-width: 92%; }
}
/* TM593 (build 30): Barry, 2026-09-24 — no more "Thinking…"/"Speaking…" text
 * inside the chat area; the header status word (updateHeaderStatus() in
 * app.js) already says the same thing at the top of the screen. The element
 * stays in the DOM (goTo() in app.js still sets its data-state/text — read
 * by hudDraw() via the separate hudCurrentState variable, not by this
 * element's text), just never shown. */
.state-indicator {
  display: none;
}

.bubble-error {
  align-self: flex-start;
  background: #3a1520;
  border: 1px solid var(--mic);
  color: #ffd2d8;
}

.bubble-fallback {
  opacity: 0.95;
  border-style: dashed;
}

/* Settings panel (TM-VOICE, 2026-09-20) — holds the voice-engine switch. */
.app-menu {
  position: absolute;
  right: 1rem;
  top: 100%;
  z-index: 20;
  min-width: min(22rem, calc(100vw - 2rem));
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 0.75rem;
  background: #121722;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.settings-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}
.settings-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  cursor: pointer;
}
.settings-row input[type='checkbox'] { margin-top: 0.2rem; }
.settings-row input[type='checkbox']:disabled { cursor: not-allowed; }
.settings-label { display: flex; flex-direction: column; gap: 0.2rem; }
.settings-hint { font-size: 0.8rem; opacity: 0.75; line-height: 1.35; }
.app-header { position: relative; }

/* Hamburger menu groups (TM548). */
.app-menu { max-height: min(70vh, 34rem); overflow-y: auto; }
.menu-group + .menu-group { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,0.1); }
.menu-heading { margin: 0 0 0.5rem; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.65; }
/* TM607: sub-heading inside a menu-group — "Create your own agents" under
 * "Agent Configuration" — smaller/quieter than menu-heading so it reads as
 * a subsection, not a new top-level group. */
.menu-subheading { margin: 1rem 0 0.35rem; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.55; }

/* Diagnostics panel (TM107) — hidden unless unlocked; a plain scrollable log box. */
.diagnostics-log {
  margin: 0.5rem 0 0;
  max-height: 12rem;
  overflow-y: auto;
  padding: 0.6rem;
  font-size: 0.72rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 0.4rem;
}
.menu-text { margin: 0; font-size: 0.85rem; line-height: 1.45; opacity: 0.9; }
.menu-text a { color: inherit; }
.settings-row-stack { flex-direction: column; align-items: stretch; gap: 0.35rem; }
.settings-label-strong { font-size: 0.9rem; }
.settings-row + .settings-row { margin-top: 0.75rem; }
/* TM592 (build 29): the same gap used between two rows, applied when a
 * section's explanation paragraph (.menu-text) is immediately followed by
 * a field — currently just Agent Configuration's intro text above "Default".
 * Without this the paragraph sat flush against the next label. */
.menu-text + .settings-row { margin-top: 0.75rem; }

/* Custom agent settings (TM557). */
.custom-agent-list { list-style: none; margin: 0 0 0.75rem; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.custom-agent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.85rem;
}
.custom-agent-delete {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.72rem;
  cursor: pointer;
}
.custom-agent-delete:hover { color: var(--text); }
.custom-agent-form { display: flex; flex-direction: column; gap: 0.6rem; }
.custom-agent-form input {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
}
.custom-agent-form .send-button { align-self: flex-start; }
#customAgentHint[data-error='1'] { color: #ff8a8a; }
/* TM642: type choice, personality box, edit/remove, form title */
.custom-agent-form select,
.custom-agent-form textarea {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}
.custom-agent-form textarea { min-height: 7rem; resize: vertical; line-height: 1.4; }
.custom-agent-kind { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.custom-agent-kind legend { margin-bottom: 0.25rem; }
.radio-row { display: flex; align-items: flex-start; gap: 0.45rem; font-size: 0.85rem; line-height: 1.35; }
.radio-row input { margin-top: 0.15rem; flex: 0 0 auto; }
.custom-agent-form-title { margin: 0.25rem 0 0; font-weight: 600; font-size: 0.9rem; }
.custom-agent-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.custom-agent-label { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; flex: 1 1 auto; }
.custom-agent-label strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-agent-label small { color: var(--muted); font-size: 0.72rem; }
.custom-agent-edit {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.72rem;
  cursor: pointer;
}
#customAgentCancel {
  background: transparent;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
}

/* Field help "?" buttons (TM94). Click/tap-only, no hover dependency —
 * mobile has no hover. Reuses .settings-hint for the revealed text. */
.field-label-row { display: flex; align-items: center; gap: 0.4rem; }
.field-help {
  width: 1.3rem;
  height: 1.3rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
}
.field-help:hover { color: var(--text); border-color: var(--accent); }
.field-help-text { margin-top: -0.1rem; }

/* Jarvis HUD (TM558, full-screen redesign TM95) — opt-in, off by default.
 *
 * TM95 first pass drew a small 84px-tall ring strip above the chat log plus
 * a separate, much fainter full-screen CSS glow div behind everything.
 * Barry tested it live and said that read as "a little Jarvis icon," not a
 * whole-screen effect — the glow div was too subtle to register at all.
 * Redesigned: #hudCanvas itself now goes position:fixed/full-viewport when
 * .hud-active is set (app.js draws the ambient wash + ring + particles at
 * viewport scale — see hudDraw() in app.js), so there is exactly ONE
 * animated layer and it visibly fills the screen. The separate .hud-glow
 * div/keyframes from the first pass are gone.
 *
 * Stacking (fixed in build 13 — read this before changing it again): the
 * FIRST full-screen version used `z-index: -1` on the canvas, relying on it
 * landing behind the app shell's own (non-positioned, un-z-indexed) content
 * automatically. That shipped as a complete regression on Barry's actual
 * phone — the canvas painted NOTHING, not even the old small ring. A
 * from-scratch JS/CSS trace (headless-browser test driving the real toggle
 * handler, not just reading the diff) found zero script errors and correct
 * resize/redraw — canvas.width/height and the drawn pixels were all exactly
 * right once the draw loop actually ran. That points at a stacking/
 * compositing issue specific to `position: fixed` + negative `z-index`
 * combined with the `overflow: hidden` this same build added to html/body/
 * .app-shell for TM98 — a known problem class in WebKit/WKWebView (the
 * runtime an iPhone actually uses; the Chrome-based trace above could not
 * reproduce it because Chrome doesn't share that bug).
 *
 * Build 13 fix: stopped relying on negative z-index. Canvas was `z-index: 0`
 * (still `position: fixed`, behind everything by default), `main`/
 * `.composer` explicitly `position: relative; z-index: 1` so they painted
 * above it. Bubbles/header/composer were made semi-transparent so that
 * background-layer HUD would show through them.
 *
 * Build 14 — Barry asked for the layering reversed: "the HUD/canvas should
 * be the TOP layer... rendered transparently... like a heads-up-display
 * overlay effect rather than a background wallpaper." Canvas went to
 * `z-index: 6` (above `.app-header`'s 5, above `main`/`.composer`'s 1,
 * still below the `.app-menu` settings dropdown's 20) with
 * `mix-blend-mode: screen`. Bubbles/header/composer went back to fully
 * opaque, since the see-through effect was meant to come from the blend
 * mode, not from punching holes in the content.
 *
 * Build 15 (this version) — build 14 shipped BROKEN on Barry's actual
 * iPhone: "text is still visually ON TOP, not showing the graphics-over-
 * text blend effect." Researched rather than re-guessed (a headless-Chrome
 * trace already proved unreliable for this exact class of bug once, in
 * build 13 — Chrome doesn't share WebKit's stacking/compositing quirks, so
 * a Chrome trace cannot vouch for blend-mode fidelity on an iPhone).
 * Confirmed with real, citable sources this is a KNOWN WebKit-specific
 * problem, not something to keep tuning CSS around:
 *   - piperhaywood.com/css-blend-modes-beware-the-stacking-context/ —
 *     `position: fixed` creates its own stacking context, and a blended
 *     element only blends with content inside ITS OWN stacking context;
 *     the author's own repro showed `mix-blend-mode` + `position: fixed`
 *     failing to blend specifically in Safari while Chrome/Firefox at
 *     least attempted something. Their fix: stop combining the two.
 *   - github.com/home-assistant/frontend/issues/29866 — a currently open,
 *     reproducible report of `mix-blend-mode` breaking specifically in
 *     WKWebView/iOS Safari (renders as flat opaque color, ignores
 *     blending) while the same markup works on Chrome/Firefox desktop.
 * Conclusion: `mix-blend-mode` on a `position: fixed` element is an
 * unreliable combination specifically in WebKit/WKWebView — exactly the
 * runtime an iPhone uses — so it is dropped entirely rather than patched
 * further. `position: fixed` + positive `z-index` WITHOUT a blend mode is
 * NOT part of that bug class and was already proven live on Barry's phone
 * (build 13's fix). The "top layer, text shows through" effect now comes
 * from plain top-layer alpha compositing instead: the canvas keeps its
 * `z-index: 6` (still above the content, still below Settings) and stays
 * `position: fixed`, but with NO blend mode — ordinary partial-alpha
 * canvas draws over opaque content, which is one of the most basic,
 * universally-identical primitives in every rendering engine, with no
 * known cross-engine quirks to research around.
 *
 * Legibility re-verified for THIS compositing model (plain alpha is
 * different math from screen-blend, so build 14's numbers had to be
 * re-checked, not assumed to still hold): same WCAG contrast measurement
 * as build 14 — TEXT (#f4f5f7) against every bubble/header background, at
 * each voice-state's alpha, including a bright/near-white custom color —
 * but composited with plain source-over alpha instead of the screen
 * formula. The existing HUD_OVERLAY_ALPHA_SCALE (0.35) and ambient ratio
 * (0.25) from build 14 already clear the WCAG AA 4.5:1 floor under this
 * model too (worst case ~4.66:1) — no JS alpha values needed to change.
 *
 * Build 16 — four more asks in one round:
 *  (a) Barry: dim the chat text further, so it reads as "dimmed text
 *      behind bright graphics," not two equally-weighted layers. Handled
 *      entirely here with a plain `opacity` on `#messages` — no new
 *      compositing technique, nothing WebKit-specific to research; this
 *      is the same primitive already confirmed safe for build 15.
 *      Scrolling is untouched by `opacity` (still `overflow-y: auto` on
 *      `.messages`), so the log still scrolls normally underneath, per
 *      Barry's own phrasing.
 *  (b) a "Jarvis HUD (no text)" mode — same full-screen canvas, but
 *      `#messages` is hidden outright (not just dimmed). The composer/mic
 *      stay visible and usable; hiding the header too would trap the user
 *      with no way back into Settings to turn the mode back off, so the
 *      header is left alone deliberately.
 *  (c) `.mic-button` colors swapped — see that rule below.
 *  (d) an "Iron Man" visual mode — same canvas, same state machine, a
 *      different color/shape drawn by hudDraw() in app.js (see the
 *      isIronman branch there). No CSS changes needed for this one; the
 *      canvas is still just `.hud-active .hud-canvas` regardless of which
 *      JS-drawn theme is active inside it.
 * (b) and (d) both add a distinct mode, so the old single on/off checkbox
 * became a `<select id="hudMode">` in ui-template.js — see HUD_MODES in
 * app.js. `.hud-active` now means "mode !== off" (any of the three visual
 * modes); a second class, `.hud-no-text`, means specifically the "no text"
 * mode.
 */
.hud-canvas {
  display: none;
}
.hud-active .hud-canvas {
  display: block;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 6;
  pointer-events: none;
}
.hud-active .state-indicator { display: none !important; }
.hud-active .messages { opacity: 0.35; }
.hud-no-text .messages { display: none; }

.hud-color-input {
  width: 100%;
  height: 2.3rem;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--panel);
  cursor: pointer;
}

/* "Find a voice" (TM583) — a small search form + results list, only shown
 * with the caller's own Fish key (see #voiceSearchRow[hidden] in app.js). */
.voice-search-form { display: flex; gap: 0.4rem; }
.voice-search-form input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--text);
  font-size: 0.85rem;
}
.voice-search-results { list-style: none; margin: 0.4rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.voice-search-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.82rem;
}
.voice-search-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-search-play,
.voice-search-use {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.72rem;
  color: var(--text);
  cursor: pointer;
}
.voice-search-use { border-color: var(--accent); color: var(--accent); }

/* Login screen (TM584) — full-screen, shown before the welcome sequence.
 * No real auth exists yet; Apple/Google/email all just explain that and
 * point at Skip. Sits above everything else in the app (z-index higher
 * than the Settings menu's 20 and the HUD canvas's 6). */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 24rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.login-app-name {
  margin: 0 0 0.4rem;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
}
.login-oauth-button {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 600;
  padding: 0.7rem 0.9rem;
}
.login-divider {
  margin: 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
}
.login-form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-form input {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--text);
}
.login-signin { width: 100%; }
.login-skip {
  width: 100%;
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
  font-weight: 700;
  padding: 0.75rem 0.9rem;
}
.login-version {
  margin: 0.6rem 0 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}
.login-oauth-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.login-links {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  margin: 0;
}
.login-link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 0.8rem;
  text-decoration: underline;
  cursor: pointer;
}
.danger-button {
  background: #7a1f1f;
  color: #fff;
  border-color: #7a1f1f;
}

/* TM652: "Welcome back" screen for a remembered sign-in (no flash). */
.login-welcome-back { display: flex; flex-direction: column; gap: 0.7rem; }
.login-welcome-text { margin: 0; font-size: 1.05rem; color: var(--text); }
.custom-agent-try {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-weight: 700;
}
.custom-agent-next { color: var(--accent); }

/* TM623 slice 2: an answer still being written. */
.bubble-streaming::after { content: '\2026'; opacity: 0.6; margin-left: 0.15em; }

/* TM655: a spoken command (stop / wait) — shown, never sent. */
.bubble-command { opacity: 0.75; font-style: italic; }

/* TM678: which model answered. */
.model-tag { display: block; margin-top: 0.35rem; font-size: 0.72rem; opacity: 0.6; letter-spacing: 0.02em; }

/* TM681: what the agent is doing right now. */
.bubble-activity { opacity: 0.6; font-style: italic; font-size: 0.85rem; }

/* TM692: console button + panel */
.console-icon { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; font-weight: 700; }
.console-button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.console-panel {
  position: fixed; left: 0; right: 0;
  top: calc(3.9rem + env(safe-area-inset-top, 0px)); /* drops down under the header; never covers the typing box */
  max-height: 42vh; margin: 0 0.6rem;
  background: rgba(8, 9, 12, 0.96); border: 1px solid var(--border); border-radius: 0.8rem;
  display: flex; flex-direction: column; z-index: 20; box-shadow: 0 -6px 24px rgba(0,0,0,0.45);
}
.console-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--border); }
.console-sub { color: var(--muted); font-size: 0.75rem; flex: 1; }
.console-close { background: transparent; border: none; color: var(--text); font-size: 1.3rem; line-height: 1; padding: 0 0.3rem; }
.console-log { margin: 0; padding: 0.5rem 0.7rem; overflow-y: auto; font: 0.72rem/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; color: #b8f5c8; white-space: pre-wrap; word-break: break-word; }
.header-agent-name { min-width: 4.5rem; } /* the agent name always stays readable next to the short status word */
