/* ============================================================================
   Zeli Avatar, live studio UI
   The semantic tokens below mirror docs-site/app/globals.css so the box and the
   product site read as one system, and every colour is a step of the Zeligate
   palette in brand.css (generated from brand/tokens.json by scripts/brand_css.py;
   no hex value is typed here by hand). Dark-committed: this is a video stage,
   and a dark room is the correct ground for it.
   ========================================================================== */

:root {
  /* ---- Zeligate brand palette, legacy names aliased to the palette steps ---- */
  --zg-purple: var(--zg-primary-500);
  --zg-dark-purple: var(--zg-primary-900);
  --zg-pastel: var(--zg-primary-200);
  --zg-peach: var(--zg-secondary-500);
  --zg-blue-clay: var(--zg-info-500);
  --zg-sea-green: var(--zg-success-500);
  --zg-crimson: var(--zg-error-700);

  --brand: var(--zg-brand-primary);
  --brand-hover: var(--zg-primary-400);

  --bg: var(--zg-dark-900);
  --bg2: var(--zg-dark-800);
  --surface: var(--zg-dark-700);
  --panel: rgba(255, 255, 255, 0.045);
  --panel-hover: rgba(255, 255, 255, 0.08);
  --panel-brd: rgba(255, 255, 255, 0.10);
  --panel-brd-strong: rgba(255, 255, 255, 0.18);

  --text: var(--zg-on-dark-text-2);
  --text-strong: var(--zg-on-dark-text);
  --muted: var(--zg-neutral-300);
  --faint: var(--zg-neutral-400);

  --accent: var(--zg-primary-200);
  --accent2: var(--zg-info-500);
  --accent-soft: color-mix(in srgb, var(--zg-primary-300) 18%, transparent);
  --accent-brd: color-mix(in srgb, var(--zg-primary-200) 42%, transparent);

  /* Success and error as text are tinted towards white so they clear 4.5:1 on
     their own tinted chips (the same values the portal's audit settled on). */
  --good: color-mix(in srgb, var(--zg-success-500) 85%, var(--zg-white));
  --warn: var(--zg-warning-500);
  --err: color-mix(in srgb, var(--zg-error-500) 55%, var(--zg-white));
  /* The same three states as an edge and as a chip ground. An edge is its state's text
     colour at 55%, which lands each one at about 3:1 against a panel; a ground is the
     raw palette step, faint enough that whitening it first would only grey it. */
  --good-brd: color-mix(in srgb, var(--good) 55%, transparent);
  --warn-brd: color-mix(in srgb, var(--warn) 55%, transparent);
  --warn-soft: color-mix(in srgb, var(--zg-warning-500) 12%, transparent);
  --err-brd: color-mix(in srgb, var(--err) 55%, transparent);
  --err-soft: color-mix(in srgb, var(--zg-error-500) 14%, transparent);
  --accent2-brd: color-mix(in srgb, var(--accent2) 40%, transparent);
  --accent-soft-hover: color-mix(in srgb, var(--zg-primary-300) 30%, transparent);

  /* Glass over the stage and the page wash: the deepest surface at an opacity, under a
     blur, so the room still shows through the controls that float on it. */
  --glass: color-mix(in srgb, var(--zg-dark-900) 60%, transparent);
  --glass-strong: color-mix(in srgb, var(--zg-dark-900) 72%, transparent);

  --radius-xl: 22px;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.34);

  --font-sans: var(--zg-font-sans);
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Reading text, supporting copy, and compact labels share one scale. */
  --text-body: 16px;
  --text-support: 14px;
  --text-label: 12px;

  --top-h: 60px;
  --chat-w: clamp(360px, 28vw, 480px);
  --gap: 20px;

  /* Motion — one scale, used everywhere (principle 8: consistency). */
  --t-fast: 160ms;
  --t: 220ms;
  --t-slow: 340ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  color-scheme: dark;
}

@media (prefers-reduced-motion: reduce) {
  :root { --t-fast: 1ms; --t: 1ms; --t-slow: 1ms; }
  *, *::before, *::after {
    animation-duration: 1ms !important;
    /* The DELAY too, not just the duration. A staggered entry animation with
       `backwards` fill holds its element at the from-keyframe for the whole
       delay, so collapsing only the duration left rows invisible for up to a
       fifth of a second for somebody who asked for less motion. */
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

* { box-sizing: border-box; }

/* Author `display` rules otherwise beat the UA's [hidden] { display: none },
   which would leave every hidden panel on screen. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 780px at 22% -12%, color-mix(in srgb, var(--zg-primary-500) 34%, transparent), transparent 62%),
    radial-gradient(900px 620px at 104% 0%, color-mix(in srgb, var(--zg-secondary-500) 10%, transparent), transparent 58%),
    linear-gradient(180deg, var(--bg), var(--bg2) 55%, var(--bg));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.015em; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

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

/* ----- app shell ---------------------------------------------------------- */
.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--top-h) minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 var(--gap);
  border-bottom: 1px solid var(--panel-brd);
  background: var(--glass);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 26px; height: 26px; border-radius: 7px; display: block; }
.brand .wordmark {
  font-size: 15.5px; font-weight: 500; letter-spacing: -0.01em; color: var(--muted);
}
.brand .wordmark b { color: var(--text-strong); font-weight: 800; }

.topbar .spacer { flex: 1 1 auto; }

.topbar .env {
  font-size: var(--text-label); letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--faint); border: 1px solid var(--panel-brd);
  padding: 3px 9px; border-radius: var(--radius-pill);
}

/* ----- workspace ---------------------------------------------------------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--chat-w);
  gap: var(--gap);
  padding: var(--gap);
  min-height: 0;
}

.stage-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: 10px; }
.stage-wrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }

/* ----- the stage: the avatar is the hero ---------------------------------- */
.stage {
  position: relative;
  height: 100%;
  width: auto;
  max-width: 100%;
  /* Set from the live track's real dimensions — so the frame hugs the avatar
     and there are never black letterbox bars. */
  aspect-ratio: var(--stage-ar, 1 / 1);
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: linear-gradient(165deg, var(--zg-primary-900), var(--zg-dark-900) 70%);
  border: 1px solid var(--panel-brd);
  box-shadow: var(--shadow);
  isolation: isolate;
}

/* A soft brand halo behind the avatar — the "room" it stands in. */
.stage::before {
  content: "";
  position: absolute; inset: -30%;
  background: radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--zg-primary-500) 55%, transparent), transparent 58%);
  opacity: 0.85;
  z-index: 0;
  transition: opacity var(--t-slow) var(--ease);
}
.stage.is-live::before { opacity: 0.35; }

.stage video {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;    /* AR follows the track (square 512 by default): never cropped or stretched */
  display: block;
  background: transparent;
  opacity: 0;
  transform: scale(1.025);
  transition: opacity var(--t-slow) var(--ease), transform var(--t-slow) var(--ease-out);
}
/* The moment the avatar arrives is the payoff — let it settle in rather than
   snapping on. */
.stage.has-video video { opacity: 1; transform: none; }

/* ----- presence indicator (replaces the old debug badge) ------------------- */
/* Above the veil (z-5): the presence indicator must stay crisp and readable
   even while the veil is blurring the stage behind it. */
.stage-top {
  position: absolute; top: 14px; left: 14px; right: 14px;
  z-index: 7; display: flex; align-items: flex-start; gap: 8px;
}

.presence {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 13px 6px 11px;
  border-radius: var(--radius-pill);
  font-size: var(--text-support); font-weight: 600; letter-spacing: 0.01em;
  color: var(--muted);
  background: var(--glass);
  border: 1px solid var(--panel-brd);
  backdrop-filter: blur(10px);
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease);
}
.presence .pdot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--faint); flex: 0 0 auto;
  transition: background var(--t) var(--ease), box-shadow var(--t) var(--ease);
}

/* Each phase speaks in the 100 step of its state hue, the brand's text tint for a dark
   ground, with the dot and the edge in the state's full colour. */
.presence[data-phase="live"]     { color: var(--zg-success-100); border-color: var(--good-brd); }
.presence[data-phase="live"] .pdot { background: var(--good); box-shadow: 0 0 0 0 color-mix(in srgb, var(--zg-success-500) 55%, transparent); animation: pulse 2.4s var(--ease) infinite; }
.presence[data-phase="connecting"],
.presence[data-phase="reconnecting"] { color: var(--zg-warning-100); border-color: var(--warn-brd); }
.presence[data-phase="connecting"] .pdot,
.presence[data-phase="reconnecting"] .pdot { background: var(--warn); animation: pulse 1.2s var(--ease) infinite; }
.presence[data-phase="thinking"],
.presence[data-phase="speaking"] { color: var(--zg-on-dark-accent); border-color: var(--accent-brd); }
.presence[data-phase="thinking"] .pdot,
.presence[data-phase="speaking"] .pdot { background: var(--accent); animation: pulse 1.5s var(--ease) infinite; }
/* A boot that never landed reads as broken, like a dropped session — the pill
   must not look the same as the perfectly healthy "Offline". */
.presence[data-phase="error"],
.presence[data-phase="unreachable"] { color: var(--zg-error-100); border-color: var(--err-brd); }
.presence[data-phase="error"] .pdot,
.presence[data-phase="unreachable"] .pdot { background: var(--err); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 currentColor; }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ----- recording indicator ------------------------------------------------ */
/* Deliberately the loudest thing on the stage after the avatar, and deliberately
   NOT styled as one more presence phase. The presence pill answers "is the
   avatar here?", which is about the product working; this answers "is what I am
   saying being kept?", which is about the person. Merging the two would let a
   busy stage hide the second question behind the first.
   Red, filled rather than outlined, with the dot breathing so it reads as live
   rather than as a static badge somebody left on. The animation is dropped for
   anyone who asked for less motion; the indicator itself never is.
   The fill is error.700: the brand's bright red, error.500, is kept for the dot and
   the edge, since white on it would sit under 4.5:1. */
.recording-indicator {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 13px 6px 11px;
  border-radius: var(--radius-pill);
  font-size: var(--text-support); font-weight: 700; letter-spacing: 0.01em;
  color: var(--text-strong);
  background: color-mix(in srgb, var(--zg-error-700) 82%, transparent);
  border: 1px solid color-mix(in srgb, var(--zg-error-500) 55%, transparent);
  backdrop-filter: blur(10px);
}
.recording-indicator .rec-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--zg-error-500); flex: 0 0 auto; color: color-mix(in srgb, var(--zg-error-500) 60%, transparent);
  animation: pulse 1.8s var(--ease) infinite;
}
@media (prefers-reduced-motion: reduce) {
  .recording-indicator .rec-dot { animation: none; }
}

/* Arrives rather than blinks on: a short fade and lift when the box says it is
   recording. Reduced motion keeps the indicator and drops only the movement. */
@keyframes rec-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}
.recording-indicator:not([hidden]),
.record-live:not([hidden]) { animation: rec-in 240ms var(--ease-out) both; }
@media (prefers-reduced-motion: reduce) {
  .recording-indicator:not([hidden]),
  .record-live:not([hidden]) { animation: none; }
}

/* ----- stage veil: idle / connecting / reconnecting / error --------------- */
.veil {
  position: absolute; inset: 0; z-index: 5;
  /* Centred by the card's own auto margins rather than `align-items: center`,
     which would push the top of an over-tall card out of the stage where it
     could not be scrolled back into reach. On a short window the idle card —
     status, portrait, copy, CTA, setup row — can be taller than the stage. */
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto;
  padding: 24px;
  background: var(--glass);
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-slow) var(--ease);
}
.veil.show { opacity: 1; pointer-events: auto; }
/* Idle has no video underneath — no need to dim, let the halo through. */
.veil.solid { background: color-mix(in srgb, var(--zg-dark-900) 20%, transparent); backdrop-filter: none; }

.veil-card {
  width: min(340px, 100%);
  margin: auto 0;                 /* the centring — see .veil above */
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  transform: translateY(10px) scale(0.98);
  opacity: 0;
  transition: transform var(--t-slow) var(--ease-out), opacity var(--t-slow) var(--ease-out);
}
.veil.show .veil-card { transform: none; opacity: 1; }

.veil-card h2 { font-size: 21px; color: var(--text-strong); }
.veil-card p { margin: 0; font-size: var(--text-body); line-height: 1.6; color: var(--muted); }

/* Identity tile, a real visual stand-in for the chosen avatar. app.js hashes the
   avatar id into --id-h (252 to 297, hueFor in web/app.js) so two avatars never share
   a tile. The brand has no hue wheel to spend that on, so the number now places the
   tile along the brand's own range instead: violet at 252, plum in the middle, rose
   at 297. Each stop is a mix of two palette steps that both hold white text above
   6:1, and a mix in sRGB is never lighter than its lighter input, so every tile keeps
   its initials above 4.5:1. */
.identity {
  --id-mix: calc((var(--id-h, 268) - 252) / 45 * 100%);
  width: 92px; height: 92px; border-radius: 26px;
  display: grid; place-items: center;
  font-size: 30px; font-weight: 800; letter-spacing: -0.02em; color: var(--zg-white);
  background: linear-gradient(150deg,
    color-mix(in srgb, var(--zg-secondary-700) var(--id-mix), var(--zg-primary-400)),
    color-mix(in srgb, var(--zg-secondary-900) var(--id-mix), var(--zg-primary-700)));
  box-shadow: 0 14px 40px color-mix(in srgb, var(--zg-primary-500) 50%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  position: relative;
}
.identity.breathe::after {
  content: "";
  position: absolute; inset: -10px; border-radius: 34px;
  border: 1px solid var(--accent-brd);
  animation: breathe 3.4s var(--ease) infinite;
}
@keyframes breathe {
  0%, 100% { transform: scale(1);    opacity: 0.55; }
  50%      { transform: scale(1.07); opacity: 0.15; }
}
.identity.sm { width: 30px; height: 30px; border-radius: 10px; font-size: var(--text-support); box-shadow: none; }
.identity.md { width: 54px; height: 54px; border-radius: 16px; font-size: 18px; box-shadow: none; }

/* The avatar's ACTUAL face, once the box has served its first prepared frame
   (app.js fetches it with the API key and hands over an object URL). It lies on
   top of the initials rather than replacing them, so the tile is never empty
   while the bytes are in flight and stays correct if they never arrive. */
.identity img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; border-radius: inherit; display: block;
  opacity: 0;
  transition: opacity var(--t-slow) var(--ease);
}
.identity.has-photo img { opacity: 1; }
.identity.has-photo { box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.14); }
.identity.sm.has-photo, .identity.md.has-photo { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14); }

/* On the idle card the tile is the ONLY thing on a tall stage, so the avatar
   gets real presence — and once there is a photo, a portrait crop that echoes
   the shape of the stage it is about to fill. */
#veilIdentity { width: 112px; height: 112px; border-radius: 30px; font-size: 34px; }
#veilIdentity.has-photo { width: 148px; height: 188px; border-radius: 24px; }
#veilIdentity.has-photo.breathe::after { border-radius: 32px; }

/* Observed handshake milestones stay readable even with motion reduced. */
.veil-steps {
  width: 100%; display: flex; flex-direction: column; gap: 0;
  padding: 5px 12px; border: 1px solid var(--panel-brd);
  border-radius: var(--radius); background: color-mix(in srgb, var(--zg-dark-900) 32%, transparent);
  text-align: left; animation: rise var(--t) var(--ease-out);
}
.veil-line {
  display: flex; align-items: center; gap: 9px; min-height: 32px;
  padding: 6px 0; font-size: var(--text-support); line-height: 1.5; color: var(--muted);
  transition: color var(--t) var(--ease);
}
.veil-line + .veil-line { border-top: 1px solid var(--panel-brd); }
.veil-line::before {
  content: ""; flex: 0 0 auto; width: 7px; height: 7px;
  border: 1px solid var(--faint); border-radius: 50%;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.veil-line[data-state="complete"] { color: var(--good); }
.veil-line[data-state="complete"]::before { background: var(--good); border-color: var(--good); }
.veil-line[data-state="current"] { color: var(--text); }
.veil-line[data-state="current"]::before {
  background: var(--accent); border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.veil-line.w70, .veil-line.w45 { width: 100%; }
@keyframes shimmer { to { background-position: -220% 0; } }

/* An avatar's name on its way from the portal (web/avatarNames.js). A text
   height bar about as wide as a short name, in the line the name will take,
   so it lands in place with no jump. Reduced motion keeps the bar, still. */
.name-pending {
  display: inline-block; width: 9ch; max-width: 100%; height: 0.9em;
  vertical-align: middle; border-radius: 4px;
  background: linear-gradient(90deg, var(--panel-brd), var(--accent-soft), var(--panel-brd));
  background-size: 220% 100%;
  animation: shimmer 1.6s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .name-pending { animation: none; }
}

.veil-tip {
  min-height: 34px; font-size: var(--text-support); color: var(--faint); line-height: 1.5;
  transition: opacity var(--t) var(--ease);
}
.veil-tip.fade { opacity: 0; }

/* The preparation the box reported while a connect waits on it. The fill
   moves only when the box reports a new step or frame, and eases there, so the
   bar never runs ahead of real work. A soft sheen travels along it so a minute
   of waiting reads as work in progress rather than a frozen card; the global
   reduced motion rule (and the one below) stills both. */
.veil-prep {
  width: 100%; display: flex; flex-direction: column; gap: 8px;
  animation: rise var(--t) var(--ease-out);
}
.veil-prep[hidden] { display: none; }
.veil-prep-track {
  position: relative; width: 100%; height: 6px; overflow: hidden;
  border-radius: 999px; background: var(--panel-brd);
}
.veil-prep-fill {
  position: absolute; inset: 0; transform-origin: left center; transform: scaleX(0);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-soft), var(--accent));
  background-size: 220% 100%;
  transition: transform var(--t-slow) var(--ease-out);
  animation: shimmer 2.4s linear infinite;
}
.veil-prep-line {
  margin: 0; font-size: var(--text-support); line-height: 1.5; color: var(--muted);
  text-align: left; font-variant-numeric: tabular-nums;
}
@media (prefers-reduced-motion: reduce) {
  .veil-prep-fill { animation: none; transition: none; }
}

/* The status pill, while app.js has it docked here rather than in the stage's
   corner. It reads as the card's eyebrow: the state, then what to do about it. */
.veil-card .presence { align-self: center; margin-bottom: 2px; }

/* ----- setup row: what you are about to go live AS ------------------------ */
/* Two routes because there are two things — the button this replaced said
   "Choose avatar & voice" and opened only avatars. Quiet by design: these must
   read as the settings above the CTA, never as a second CTA. */
.veil-setup { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 2px; }

.setup-chip {
  font: inherit; color: var(--text); text-align: left;
  display: inline-flex; align-items: center; gap: 9px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--panel-brd);
  background: var(--glass);
  backdrop-filter: blur(10px);
  cursor: pointer;
  /* Shrink before wrapping: an avatar id is usually long and a voice name
     short, so the row stays on one line and only the long half ellipses. */
  flex: 0 1 auto; min-width: 0;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.setup-chip:hover { background: var(--panel-hover); border-color: var(--panel-brd-strong); }
.setup-chip:active { transform: translateY(1px) scale(0.985); }
.setup-chip .ico { font-size: 14px; line-height: 1; }
.setup-chip .chip-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.setup-chip .chip-k {
  font-size: var(--text-label); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint);
}
.setup-chip .chip-v {
  font-size: var(--text-support); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ----- the dock: primary action first, everything else quieter ------------ */
/* The control bar lives BELOW the stage so every control can keep a readable
   label — an unlabelled icon row is the thing this redesign exists to remove.
   Its height is reserved even while empty, so going live never jolts the page. */
.controlbar {
  flex: 0 0 auto;
  min-height: 58px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
}

.dock {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
  padding: 8px;
  /* Rounded rect, not a pill: it stays coherent if it ever wraps to two rows. */
  border-radius: 26px;
  background: var(--glass-strong);
  border: 1px solid var(--panel-brd);
  backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: var(--shadow-sm);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease-out);
}
.dock-sep { width: 1px; align-self: stretch; margin: 2px 3px; background: var(--panel-brd); }

/* Session controls and the recording status share one surface, including
   before Go live, so the "recorded automatically" line is seen before the call. */
.session-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 8px 16px; max-width: min(100%, 1080px); padding: 8px 12px;
  border: 1px solid var(--panel-brd); border-radius: var(--radius-xl);
  background: var(--glass-strong); backdrop-filter: blur(18px);
  box-shadow: var(--shadow-sm);
}
.session-toolbar .dock {
  min-width: 0; padding: 0; border: 0; border-radius: 0;
  background: none; backdrop-filter: none; box-shadow: none;
}
.session-toolbar .dock.is-hidden { display: none; }
.session-toolbar .btn { min-height: 44px; }
.session-toolbar #goLive.danger {
  border-color: var(--panel-brd-strong); color: var(--text);
}
.session-toolbar #micBtn.listening {
  background: var(--accent-soft); border-color: var(--accent-brd);
  color: var(--text-strong); animation: none;
}


/* Before there is a session, the stage's own CTA is the only thing to click. */
.dock.is-hidden { opacity: 0; pointer-events: none; transform: translateY(10px); }

/* ----- buttons ------------------------------------------------------------ */
.btn {
  font: inherit; font-size: var(--text-body); font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 15px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--panel-brd);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--panel-hover); border-color: var(--panel-brd-strong); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.985); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }

/* Brand purple, lit one step lighter at the top. Hover lifts both stops by half a
   step rather than a whole one, so white stays above 5:1 right to the top edge. */
.btn.primary {
  background: linear-gradient(180deg, var(--brand-hover), var(--brand));
  border-color: var(--accent-brd);
  color: var(--zg-white);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--zg-primary-500) 45%, transparent);
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, color-mix(in srgb, var(--zg-primary-300) 50%, var(--brand-hover)), var(--brand-hover)); }

.btn.danger { border-color: var(--err-brd); color: var(--zg-error-100); }
.btn.danger:hover:not(:disabled) { background: var(--err-soft); }

.btn.lg { padding: 12px 24px; font-size: var(--text-body); }
.btn.sm { padding: 6px 11px; font-size: var(--text-support); }
.btn.ghost { background: transparent; }

.btn.icon {
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  font-size: 16px; line-height: 1;
}
.btn.icon.sm { width: 30px; height: 30px; font-size: var(--text-support); }

.btn svg { flex: 0 0 auto; }

/* Selector chips in the dock — visual, labelled, never a raw <select>. */
.btn.chip {
  padding: 6px 12px 6px 6px; gap: 9px; font-weight: 600;
  max-width: 190px;
}
.btn.chip .chip-txt { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; }
.btn.chip .chip-k {
  font-size: var(--text-label); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint);
}
.btn.chip .chip-v {
  font-size: var(--text-support); max-width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn.chip .chev { color: var(--faint); font-size: var(--text-label); }


/* mic */
/* Hot while it listens. The brand's bright red alone leaves white at 3.5:1, so the
   pill is error.700 lifted towards error.500 at the top; white clears 4.9:1 at the
   lightest point. The peach edge and ring are the brand's secondary. */
#micBtn.listening {
  background: linear-gradient(180deg, color-mix(in srgb, var(--zg-error-500) 40%, var(--zg-error-700)), var(--zg-error-700));
  border-color: color-mix(in srgb, var(--zg-secondary-500) 60%, transparent); color: var(--zg-white);
  animation: micpulse 1.6s var(--ease) infinite;
}
@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--zg-secondary-500) 50%, transparent); }
  50%      { box-shadow: 0 0 0 9px transparent; }
}

/* Muted reads as STILL. The pulse above means "you are being heard", so the
   single clearest signal that you are not is that the pulse has stopped —
   #micBtn drops .listening while muted. The amber here says which control did
   it, while End session remains a separate action. */
#micBtn.muted {
  background: var(--warn-soft);
  border-color: var(--warn-brd);
  color: var(--warn);
}
#micBtn { transition: background var(--t) var(--ease), border-color var(--t) var(--ease), color var(--t) var(--ease); }

/* The icon stays a MICROPHONE in both states and gains a slash when muted.
   A crossed-out speaker would read as "you cannot hear the avatar", which is
   the opposite of what this control does. */
.micico { position: relative; display: inline-flex; align-items: center; }
.micico svg { display: block; }
.micico::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 21px; height: 2px; border-radius: 2px;
  background: currentColor;
  transform: translate(-50%, -50%) rotate(-45deg) scaleX(0);
  transform-origin: center;
  transition: transform var(--t) var(--ease-out);
}
#micBtn.muted .micico::after { transform: translate(-50%, -50%) rotate(-45deg) scaleX(1); }

/* ----- mic caption -------------------------------------------------------- */
.miccap {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 30px; padding: 5px 14px;
  font-size: var(--text-support); color: var(--muted);
  border-radius: var(--radius-pill);
  background: var(--panel); border: 1px solid var(--panel-brd);
  align-self: center; max-width: 100%;
  animation: rise var(--t) var(--ease-out);
}
.miccap.live { color: var(--text); }
.miccap.err { color: var(--err); border-color: var(--err-brd); }
/* No .lvl dot is rendered while muted — a pulsing "listening" dot beside the
   word "muted" is the contradiction this state exists to avoid. */
.miccap.muted { color: var(--warn); border-color: var(--warn-brd); }
.miccap .lvl {
  width: 7px; height: 7px; border-radius: 50%; background: var(--zg-peach); flex: 0 0 auto;
  animation: pulse 1.4s var(--ease) infinite;
}
.miccap .partial { font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ----- conversation column ------------------------------------------------ */
.chat-col {
  display: flex; flex-direction: column; min-height: 0;
  background: linear-gradient(155deg, color-mix(in srgb, var(--zg-primary-900) 66%, transparent), color-mix(in srgb, var(--zg-dark-900) 82%, transparent));
  border: 1px solid var(--panel-brd);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.chat-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 15px 16px 13px;
  border-bottom: 1px solid var(--panel-brd);
}
.chat-head { background: rgba(255, 255, 255, 0.018); }
.chat-head h2 { font-size: 14.5px; letter-spacing: -0.01em; }
.chat-head .count { font-size: var(--text-support); color: var(--faint); }
.chat-head .spacer { flex: 1 1 auto; }

.chat-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}
.chat-scroll::-webkit-scrollbar { width: 9px; }
.chat-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 9px; border: 3px solid transparent; background-clip: content-box; }

/* empty state — an invitation, not a void */
.empty {
  margin: auto 0; display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 12px; padding: 8px 4px 18px;
  animation: rise var(--t-slow) var(--ease-out);
}
.empty h3 { font-size: 17px; color: var(--text-strong); }
.empty p { margin: 0; font-size: var(--text-body); line-height: 1.6; color: var(--muted); max-width: 30ch; }
.empty .suggestions { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 4px; }
.suggestion {
  font: inherit; font-size: var(--text-body); color: var(--text);
  padding: 7px 13px; border-radius: var(--radius-pill);
  border: 1px solid var(--accent-brd); background: var(--accent-soft);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.suggestion:hover { background: var(--accent-soft-hover); }
.suggestion:active { transform: scale(0.97); }
.suggestion:disabled { opacity: 0.4; cursor: not-allowed; }

/* turns */
.turn { display: flex; gap: 9px; align-items: flex-end; animation: rise var(--t) var(--ease-out); }
.turn.me { flex-direction: row-reverse; }
.turn .body { max-width: 84%; min-width: 0; }

.bubble {
  padding: 11px 14px; border-radius: 15px; font-size: var(--text-body); line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word;
}
.turn.me .bubble {
  background: linear-gradient(180deg, var(--brand-hover), var(--brand));
  color: var(--zg-white); border-bottom-right-radius: 5px;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--zg-primary-500) 35%, transparent);
}
.turn.bot .bubble {
  background: var(--panel); border: 1px solid var(--panel-brd);
  color: var(--text); border-bottom-left-radius: 5px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.025);
}
.turn.err .bubble {
  background: var(--err-soft); border: 1px solid var(--err-brd);
  color: var(--zg-error-100);
}
.turn .tone {
  display: flex; align-items: center; gap: 5px; width: fit-content; max-width: 100%;
  margin-top: 9px; padding: 3px 8px; border-radius: var(--radius-pill);
  border: 1px solid var(--accent-brd); background: var(--accent-soft);
  font-size: var(--text-label); line-height: 1.4; font-weight: 500;
  letter-spacing: 0.02em; color: var(--muted); white-space: normal;
  animation: doing-in var(--t) var(--ease-out) both;
}
.turn .tone::before {
  content: ""; width: 5px; height: 5px; flex: 0 0 auto;
  border-radius: 50%; background: var(--accent);
}
.turn.me .tone {
  color: rgba(255, 255, 255, 0.85); border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
}

/* THE REPLY WHILE IT IS STILL BEING SAID.
   Both doors now write a clause at a time into this bubble as the avatar speaks
   it, so the bubble has to say "there is more coming" without becoming a
   progress bar. A bar would claim to know how long the answer is, and nothing
   here does. A soft caret breathing after the last word is the smallest honest
   cue and the one a reader already knows as thinking aloud. It is cleared the
   instant the finished reply lands, so a still bubble always means a turn that
   is over. */
.bubble[data-live="1"] .said::after {
  content: ""; display: inline-block;
  width: 2px; height: 0.95em; margin-left: 3px;
  vertical-align: -0.12em; border-radius: 1px;
  background: var(--accent);
  animation: caret 1.5s var(--ease) infinite;
}
@keyframes caret {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  /* Steady rather than blinking. Somebody who asked for less motion still needs
     to know the reply has not finished, so the cue stays and the movement goes. */
  .bubble[data-live="1"] .said::after { animation: none; opacity: 0.85; }
}

/* WHY the avatar paused.
   A tool call is the longest silence in a turn, and an unexplained pause reads as
   a broken page. These two states say what is happening instead: the first WHILE
   it happens, the second as a quiet record afterwards.
   Motion is deliberately small -- this appears mid-conversation and must inform
   without pulling the eye off the reply. The global prefers-reduced-motion rule
   near the top of this file already flattens both. */
.typing .doing {
  font-size: var(--text-support); color: var(--muted); white-space: normal; overflow-wrap: anywhere;
  animation: doing-in var(--t) var(--ease) both;
}
@keyframes doing-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: none; }
}

/* On a finished turn: what the avatar consulted to answer. Past tense, quiet --
   the answer is the point, this is the receipt. */
.turn .tools { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.turn .tool-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--panel-brd); background: rgba(255, 255, 255, 0.03);
  font-size: var(--text-label); letter-spacing: 0.03em; color: var(--muted);
  animation: doing-in var(--t) var(--ease) both;
}
.turn .tool-chip .dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); opacity: 0.75; flex: none;
}
/* A custom tool call carries its outcome. The words say it; the dot only
   agrees, so nothing here depends on telling two colours apart. */
.turn .tool-chip.is-running .dot { animation: tool-chip-pulse 1.2s ease-in-out infinite; }
.turn .tool-chip.is-done .dot { background: var(--good); opacity: 1; }
.turn .tool-chip.is-failed { border-color: color-mix(in srgb, var(--err) 45%, transparent); }
.turn .tool-chip.is-failed .dot { background: var(--err); opacity: 1; }
@keyframes tool-chip-pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) {
  .turn .tool-chip.is-running .dot { animation: none; }
}

/* WHAT THE PERSONA DID rather than said.
   A skipped turn gets one quiet line in the mic caption, where the person's next
   words replace it by themselves. It eases in the way the tool caption does, and
   the global prefers-reduced-motion rule near the top of this file flattens it. */
.miccap .take-time {
  color: var(--muted);
  animation: doing-in var(--t) var(--ease) both;
}
/* The line that closes a call the avatar ended. Centred and quiet: it is a fact
   about the conversation, not a turn in it. */
.turn.note { justify-content: center; }
.turn.note .identity { display: none; }
.turn.note .bubble {
  background: transparent; border: 1px solid var(--panel-brd); border-radius: 999px;
  padding: 4px 12px; font-size: var(--text-support); color: var(--muted);
  animation: doing-in var(--t) var(--ease) both;
}
/* THE CONVERSATION IS ON HOLD. The same pill as the mic caption so it reads as
   part of the dock, a touch warmer so it reads as a state and not a caption. It
   rises in, and LEAVES (is-leaving) rather than vanishing: a bar that blinks out
   the moment somebody speaks looks like a fault. The meter is the ninety seconds
   running down, decorative, and it stands still for reduced motion: the words
   and the button carry everything it says. */
.pausebar {
  flex: 0 0 auto; align-self: center; max-width: 100%;
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 10px;
  min-height: 34px; padding: 5px 8px 5px 14px;
  font-size: var(--text-support); color: var(--text);
  border-radius: var(--radius-pill);
  background: var(--panel); border: 1px solid var(--warn-brd);
  animation: rise var(--t) var(--ease-out);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.pausebar[hidden] { display: none; }
.pausebar.is-leaving { opacity: 0; transform: translateY(4px); }
.pausebar .pause-ico {
  flex: 0 0 auto; width: 8px; height: 10px;
  border-left: 3px solid var(--warn); border-right: 3px solid var(--warn);
}
.pausebar .pause-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pausebar .pause-meter {
  position: absolute; left: 0; right: 0; bottom: 0; height: 2px; pointer-events: none;
}
.pausebar .pause-meter i {
  display: block; height: 100%; background: var(--warn); opacity: 0.55;
  transform-origin: left center;
  animation: pause-run-down var(--pause-seconds, 90s) linear both;
}
@keyframes pause-run-down { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) {
  .pausebar .pause-meter i { animation: none; transform: none; opacity: 0.3; }
}

/* typing / generating indicator */
.typing { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 12px 14px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: typing 1.25s var(--ease) infinite;
}
.typing i:nth-child(2) { animation-delay: 0.16s; }
.typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* honest unavailability notice — replaces the raw log line */
.notice {
  flex: 0 0 auto; margin: 0 16px 12px;
  display: grid; grid-template-columns:auto minmax(0,1fr); gap:8px 10px; align-items:start;
  padding: 11px 13px; border-radius: var(--radius);
  font-size: var(--text-support); line-height: 1.55; color: var(--muted);
  background: var(--warn-soft); border: 1px solid var(--warn-brd);
  animation: rise var(--t) var(--ease-out);
}
.notice .ico { flex: 0 0 auto; font-size: 14px; line-height: 1.3; }
.notice strong { color: var(--text); font-weight: 700; }
.notice code {
  font-family: var(--font-mono); font-size: var(--text-support);
  background: rgba(0, 0, 0, 0.35); padding: 1px 5px; border-radius: 5px;
}
.notice.info { background: var(--accent-soft); border-color: var(--accent-brd); }
.notice .body { min-width:0; overflow-wrap:anywhere; }
.notice > .btn { grid-column:2; justify-self:start; margin-left:0; white-space:nowrap; min-height:36px; }
/* Technical cause is available, but never the first thing a person reads. */
.notice details { margin-top: 7px; }
.notice summary {
  cursor: pointer; font-size: var(--text-support); color: var(--faint);
  list-style: none; display: inline-flex; align-items: center; gap: 5px;
}
.notice summary::-webkit-details-marker { display: none; }
/* Drawn with borders rather than a ▸ code point, which is missing from some
   system font stacks and renders as nothing (or a stray dot). */
.notice summary::before {
  content: ""; width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 3.5px solid transparent; border-bottom: 3.5px solid transparent;
  transition: transform var(--t-fast) var(--ease);
}
.notice details[open] summary::before { transform: rotate(90deg); }
.notice details p { margin: 6px 0 0; font-size: var(--text-support); line-height: 1.55; color: var(--faint); }

/* composer */
.composer {
  flex: 0 0 auto; display: flex; gap: 8px; align-items: center;
  padding: 12px 14px 14px; border-top: 1px solid var(--panel-brd);
  background: color-mix(in srgb, var(--zg-dark-900) 40%, transparent);
}
.composer .field {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px;
  padding: 4px 4px 4px 14px;
  border-radius: var(--radius-pill);
  background: var(--panel); border: 1px solid var(--panel-brd);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.composer .field:focus-within { border-color: var(--accent-brd); background: var(--panel-hover); }
.composer input[type="text"] {
  flex: 1 1 auto; min-width: 0;
  font: inherit; font-size: var(--text-body); color: var(--text);
  background: transparent; border: 0; outline: none; padding: 8px 0;
}
.composer input::placeholder { color: var(--faint); }
.composer input:disabled { cursor: not-allowed; }

.composer-hint {
  flex: 0 0 auto; margin: 0; padding: 0 16px 12px;
  font-size: var(--text-support); line-height: 1.5; color: var(--faint);
}
.composer-hint b { color: var(--muted); font-weight: 600; }

/* ----- drawers ------------------------------------------------------------ */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: color-mix(in srgb, var(--zg-dark-900) 62%, transparent);
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t) var(--ease);
}
.overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; z-index: 41;
  height: 100dvh; width: 400px; min-width: 300px; max-width: 94vw;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--zg-primary-900), var(--bg));
  border-left: 1px solid var(--panel-brd);
  box-shadow: -18px 0 60px rgba(0, 0, 0, 0.55);
  transform: translateX(100%);
  pointer-events: none;
  /* NB: `visibility` is deliberately absent. Animating it makes the computed
     value — which every child inherits — depend on transition timing, and the
     panel can paint completely empty. Keyboard/AT reachability is handled by
     the `inert` attribute in app.js instead, which is exact and untimed. */
  transition: transform var(--t-slow) var(--ease);
}
.drawer.open { transform: none; pointer-events: auto; }

.drawer-resize { position: absolute; top: 0; left: 0; width: 8px; height: 100%; cursor: col-resize; z-index: 2; }
.drawer-resize:hover, .drawer-resize.active { background: linear-gradient(90deg, var(--accent-brd), transparent); }

.drawer-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px; border-bottom: 1px solid var(--panel-brd);
}
.drawer-head h2 { font-size: 16px; }
.drawer-head .count { font-size: var(--text-support); color: var(--faint); }
.drawer-head .spacer { flex: 1 1 auto; }

.drawer-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 16px 20px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}
.drawer-body::-webkit-scrollbar { width: 9px; }
.drawer-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 9px; border: 3px solid transparent; background-clip: content-box; }

.drawer-foot {
  flex: 0 0 auto; padding: 12px 16px 16px;
  border-top: 1px solid var(--panel-brd); background: color-mix(in srgb, var(--zg-dark-900) 50%, transparent);
}

.drawer-search { flex: 0 0 auto; padding: 12px 16px 4px; }

/* ----- form controls ------------------------------------------------------ */
.input, select.input, textarea.input {
  width: 100%; font: inherit; font-size: var(--text-body); color: var(--text);
  background: rgba(0, 0, 0, 0.28); border: 1px solid var(--panel-brd);
  border-radius: var(--radius-sm); padding: 9px 11px; outline: none;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.input:focus, select.input:focus, textarea.input:focus { border-color: var(--accent-brd); background: rgba(0, 0, 0, 0.4); }
.input::placeholder { color: var(--faint); }
textarea.input { min-height: 132px; resize: vertical; line-height: 1.55; }
select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23a89fc4' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px;
}

.field-group { margin: 0 0 15px; }
.field-group > label {
  display: block; font-size: var(--text-support); font-weight: 600; color: var(--muted);
  margin-bottom: 6px; letter-spacing: 0.01em;
}
.field-group.disabled { opacity: 0.42; }
.field-row { display: flex; gap: 11px; }
.field-row > .field-group { flex: 1; }

.note { margin: 6px 0 0; font-size: var(--text-support); line-height: 1.5; color: var(--faint); }
.note code { font-family: var(--font-mono); font-size: var(--text-label); }
/* A note that explains the section heading it sits under, rather than the field
   above it — so it hugs the heading instead of floating between the two. */
.note-lead { margin: -4px 0 10px; }

.section-title {
  display: flex; align-items: center; gap: 9px;
  font-size: var(--text-label); font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--faint); margin: 22px 0 11px;
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--panel-brd); }
.section-title:first-child { margin-top: 4px; }

/* The persona is what people open Settings for, so it gets the room the three
   deleted paragraphs used to occupy. */
textarea.input.tall { min-height: 208px; }

/* Settings needs a writing surface; avatar and voice drawers stay compact. */
#settingsDrawer { width: min(720px, 94vw); min-width: 0; }
#settingsDrawer .drawer-head { padding-inline: 24px; }
#settingsDrawer .drawer-body { padding: 20px 24px 28px; }
#settingsDrawer .drawer-foot { padding-inline: 24px; }
#settingsDrawer #setSystem {
  height: clamp(320px, 50dvh, 560px);
  min-height: 280px;
  padding: 16px;
  font-size: var(--text-body);
  line-height: 1.65;
}
@media (max-width: 900px) {
  #settingsDrawer { width: 100vw; max-width: 100vw; }
  #settingsDrawer .drawer-head,
  #settingsDrawer .drawer-body,
  #settingsDrawer .drawer-foot { padding-inline: 16px; }
  #settingsDrawer #setSystem { height: clamp(240px, 45dvh, 420px); min-height: 200px; }
}


/* ----- label + ⓘ hint ------------------------------------------------------
   Every explanatory paragraph that survived the purge became one of these. The
   button is REAL — focusable, Enter-able, and carrying the same words in
   `aria-label` that the tooltip paints from `data-tip` — because a hint that
   only exists on hover is a hint that half the users never get.

   The tooltip is drawn from `.lbl-row` rather than from the button so it can
   span the field's width instead of trailing off into `.drawer-body`, whose
   `overflow-y: auto` would otherwise clip or scroll it. */
.lbl-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; position: relative; }
.lbl-row > label { margin-bottom: 0; }

/* The ring is a border and the "i" is ASCII — `ⓘ` is missing from some system
   font stacks and would silently render as an empty button. */
.hint {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; padding: 0; margin: 0;
  font: inherit; font-size: var(--text-label); font-weight: 700; font-style: italic; line-height: 1;
  color: var(--faint); background: none;
  border: 1px solid currentColor; border-radius: 50%;
  cursor: help;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.hint:hover { color: var(--muted); background: rgba(255, 255, 255, 0.05); }
.hint::after {
  content: attr(data-tip);
  position: absolute; left: 0; right: 0; top: calc(100% + 5px); z-index: 6;
  padding: 7px 9px; border-radius: var(--radius-sm);
  background: var(--zg-dark-100); border: 1px solid var(--panel-brd-strong);
  box-shadow: var(--shadow-sm);
  font-size: var(--text-support); line-height: 1.45; font-weight: 400;
  color: var(--muted); text-transform: none; letter-spacing: 0;
  opacity: 0; visibility: hidden; transform: translateY(-3px);
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease-out),
              visibility var(--t-fast) var(--ease);
}
/* `:focus`, not `:focus-visible` — keyboard parity is the point, and a plain
   `:focus` also covers touch, where there is no hover and no focus-visible. It
   pins the tip open until you look away, which is what you wanted when you
   pressed a ⓘ in the first place. */
.hint:hover::after, .hint:focus::after {
  opacity: 1; visibility: visible; transform: none;
}

/* ----- Advanced disclosure -------------------------------------------------
   One control, one region, everything rare inside it. Collapsed it is `hidden`,
   so the contents leave the tab order entirely rather than lurking in it. */
.disclosure {
  display: flex; align-items: center; gap: 9px; width: 100%;
  margin: 22px 0 0; padding: 11px 13px;
  font: inherit; font-size: var(--text-body); font-weight: 600; color: var(--text);
  text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--panel-brd); border-radius: var(--radius);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.disclosure:hover { background: var(--panel-hover); border-color: var(--panel-brd-strong); }
/* Same press feedback as .btn, so it reads as part of one system. */
.disclosure:active { transform: translateY(1px) scale(0.995); }
/* A CSS triangle, not `▸` — see the "decorative code points" note in README. */
.disclosure .disc-chev {
  flex: 0 0 auto; width: 0; height: 0; margin-left: 2px;
  border-top: 4.5px solid transparent;
  border-bottom: 4.5px solid transparent;
  border-left: 6px solid var(--faint);
  transition: transform var(--t) var(--ease-out), border-left-color var(--t) var(--ease);
  transform-origin: 2px 50%;
}
.disclosure.open .disc-chev { transform: rotate(90deg); border-left-color: var(--muted); }
.disclosure .disclosure-lbl { flex: 0 0 auto; }
.disclosure .disclosure-sub {
  flex: 1 1 auto; min-width: 0;
  font-size: var(--text-support); font-weight: 400; color: var(--faint);
  text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.disclosure-panel {
  margin-top: 13px; padding: 14px 13px 1px;
  border: 1px solid var(--panel-brd); border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.16);
  animation: rise var(--t) var(--ease-out);
}

/* ----- save state ----------------------------------------------------------
   "Saved on the box" as a standing phrase said nothing about whether the form
   in front of you still matched the box. One word, and a colour when it does
   not, replaces both that phrase and the paragraph under it. */
.pill-state {
  font-size: var(--text-label); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--faint);
  padding: 3px 8px; border-radius: var(--radius-pill);
  border: 1px solid var(--panel-brd); background: rgba(255, 255, 255, 0.03);
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease),
              background var(--t) var(--ease);
}
/* Before the first load there is no state to report; an empty bordered pill
   would read as a control that failed to render. */
.pill-state:empty { display: none; }
.pill-state.dirty {
  color: var(--warn); border-color: var(--warn-brd);
  background: var(--warn-soft);
}

/* switch */
.switch {
  display: flex; align-items: center; gap: 11px; cursor: pointer;
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--panel-brd); background: var(--panel);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.switch:hover { background: var(--panel-hover); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  flex: 0 0 auto; width: 36px; height: 21px; border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.12); border: 1px solid var(--panel-brd);
  position: relative; transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: 50%; background: var(--muted);
  transition: transform var(--t) var(--ease-out), background var(--t) var(--ease);
}
.switch input:checked + .track { background: var(--brand); border-color: var(--accent-brd); }
.switch input:checked + .track::after { transform: translateX(15px); background: var(--zg-white); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .lbl { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch .lbl b { font-size: var(--text-body); font-weight: 600; color: var(--text); }
.switch .lbl span { font-size: var(--text-support); line-height: 1.45; color: var(--faint); }

/* ----- pickable cards (avatars & voices) ---------------------------------- */
.card-list { display: flex; flex-direction: column; gap: 9px; }

.pick {
  display: flex; align-items: center; gap: 11px; text-align: left; width: 100%;
  font: inherit; color: var(--text);
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--panel-brd); background: var(--panel);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.pick:hover { background: var(--panel-hover); border-color: var(--panel-brd-strong); }
.pick:active { transform: scale(0.99); }
/* Selection used to be a lone ✓ at the far right of the row, which you had to
   go looking for. Now the row itself is marked: an accent spine down its edge,
   the tinted ground it already had, and a filled badge instead of a bare tick. */
.pick.sel {
  border-color: var(--accent-brd); background: var(--accent-soft);
  box-shadow: inset 3px 0 0 0 var(--accent);
}

.pick .meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pick .nm { font-size: var(--text-body); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .desc {
  font-size: var(--text-support); line-height: 1.45; color: var(--faint);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
/* Empty circle when unchosen, filled when chosen — the one-of-many shape people
   already read as "pick one", where a tick that is simply absent reads as
   nothing at all. */
.pick .check {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: var(--text-support); line-height: 1; color: transparent;
  border: 1px solid var(--panel-brd-strong); background: rgba(0, 0, 0, 0.22);
  opacity: 0.5;
  transition: opacity var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
.pick:hover .check { opacity: 0.85; }
.pick.sel .check {
  opacity: 1; color: var(--zg-white);
  background: linear-gradient(180deg, var(--brand-hover), var(--brand));
  border-color: var(--accent-brd);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: var(--text-label); font-weight: 600; letter-spacing: 0.03em;
  padding: 2px 8px; border-radius: var(--radius-pill);
  border: 1px solid var(--panel-brd); color: var(--muted); text-transform: capitalize;
}
.tag.plain { text-transform: none; }
.tag.on { color: var(--accent); border-color: var(--accent-brd); background: var(--accent-soft); text-transform: none; }
.tag.lang { color: var(--accent2); border-color: var(--accent2-brd); text-transform: uppercase; }
.tag.rec { color: var(--good); border-color: var(--good-brd); text-transform: none; }
.tag.ready { color: var(--good); border-color: var(--good-brd); }
.tag.preparing { color: var(--warn); border-color: var(--warn-brd); }
.tag.failed { color: var(--err); border-color: var(--err-brd); }

.play {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; padding: 0;
  display: grid; place-items: center; font: inherit; font-size: var(--text-support);
  border: 1px solid var(--panel-brd-strong); background: rgba(0, 0, 0, 0.3); color: var(--text);
  cursor: pointer; transition: all var(--t-fast) var(--ease);
}
.play:hover { border-color: var(--accent-brd); color: var(--accent); }
.play.loading { opacity: 0.6; cursor: progress; }
.play.playing { background: var(--brand); border-color: var(--accent-brd); color: var(--zg-white); }

.list-empty {
  text-align: center; padding: 30px 14px; font-size: var(--text-support); line-height: 1.6; color: var(--faint);
}

.group-label {
  font-size: var(--text-label); font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--faint); padding: 12px 2px 3px;
}
.group-label:first-child { padding-top: 2px; }

/* ----- voice picker: one list, grouped by provider ------------------------ */
/* Each provider is a group with a heading that STICKS while its rows scroll
   past, so "which provider am I looking at" is always on screen. The heading
   sits on the drawer's own surface so rows slide under it cleanly. */
.voice-list { gap: 0; }
.voice-group { display: flex; flex-direction: column; gap: 9px; padding-bottom: 10px; }
.voice-group > .group-label {
  position: sticky; top: -1px; z-index: 1;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 0 -2px; padding: 10px 2px 6px;
  background: var(--surface);
  box-shadow: 0 8px 10px -10px rgba(0, 0, 0, 0.6);
}
.voice-group.current > .group-label { color: var(--accent); }
.voice-group > .group-label .group-n {
  font-weight: 600; letter-spacing: 0.02em; text-transform: none; color: var(--faint);
}
.group-reason {
  margin: 0; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px dashed var(--panel-brd); color: var(--muted);
  font-size: var(--text-support); line-height: 1.45;
}
.group-reason.refused, .group-reason.key_problem { border-color: var(--warn-brd); color: var(--warn); }
.group-reason.starting::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px;
  border-radius: 50%; border: 2px solid var(--panel-brd-strong); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite; vertical-align: -1px;
}
.tag.prov { color: var(--accent2); border-color: var(--accent2-brd); text-transform: none; }
.voice-group.current .tag.prov { color: var(--accent); border-color: var(--accent-brd); }
/* Rows arrive, they do not pop: a short rise on the shared motion token,
   staggered by index (capped, so a long list does not queue up half a second
   of delay). The global prefers-reduced-motion rule collapses the duration to
   1 ms AND zeroes the delay, so no row is held invisible waiting its turn. */
.pick.enter {
  animation: pick-enter var(--t) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 18ms);
}
@keyframes pick-enter {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ----- dropzone + uploads ------------------------------------------------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 20px 14px; border-radius: var(--radius);
  border: 1.5px dashed var(--panel-brd-strong); background: rgba(0, 0, 0, 0.18);
  cursor: pointer; text-align: center;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.dropzone:hover, .dropzone.over { border-color: var(--accent-brd); background: var(--accent-soft); }
.dropzone b { font-size: var(--text-body); color: var(--text); }
.dropzone span { font-size: var(--text-support); color: var(--faint); line-height: 1.5; }
.dropzone input { display: none; }

.uploads { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.uprow {
  display: flex; align-items: center; gap: 9px; font-size: var(--text-support);
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--panel); border: 1px solid var(--panel-brd);
  animation: rise var(--t) var(--ease-out);
}
.uprow .nm {
  flex: 0 0 34%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-mono); font-size: var(--text-label); color: var(--text);
}
.uprow .bar { flex: 1 1 auto; height: 5px; border-radius: 4px; background: rgba(0, 0, 0, 0.4); overflow: hidden; }
.uprow .bar > i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--accent); transition: width var(--t) var(--ease); }
.uprow .st { flex: 0 0 auto; min-width: 74px; text-align: right; color: var(--faint); }
.uprow.ready .st { color: var(--good); }
.uprow.ready .bar > i { background: var(--good); }
.uprow.failed .st { color: var(--err); }
.uprow.failed .bar > i { background: var(--err); }

/* ----- inline status line (voice engine / cloning) ------------------------ */
.status-line {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius);
  font-size: var(--text-support); line-height: 1.5; color: var(--muted);
  background: var(--accent-soft); border: 1px solid var(--accent-brd);
  animation: rise var(--t) var(--ease-out);
}
.spin {
  flex: 0 0 auto; display: inline-block; width: 13px; height: 13px;
  border: 2px solid var(--accent-brd); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- developer: in-flow diagnostics + activity log ---------------------- */
.debug-panel {
  width: min(100%, 800px); align-self: center;
  flex: none; min-width: 0; border: 1px solid var(--panel-brd);
  border-radius: var(--radius); background: var(--surface);
}
.debug-panel > summary {
  display: flex; align-items: center; gap: 12px; min-height: 44px;
  padding: 8px 12px; cursor: pointer; list-style: none;
  font-size: var(--text-support); font-weight: 600; color: var(--text);
}
.debug-panel > summary::-webkit-details-marker { display: none; }
.debug-panel > summary::after { content: "+"; font-size: 18px; margin-left: auto; }
.debug-panel[open] > summary::after { content: "−"; }
.debug-panel > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.debug-hint { font-size: var(--text-label); font-weight: 400; color: var(--muted); }
.debug-hud {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 16px; width: 100%; max-height: min(24dvh, 200px);
  overflow: auto; overscroll-behavior: contain; scrollbar-width: thin;
  margin: 0; padding: 10px 12px; border-top: 1px solid var(--panel-brd);
  font-family: var(--font-sans); font-size: var(--text-label); line-height: 1.5;
  color: var(--muted);
}
.debug-group { min-width: 0; }
@media (max-width: 480px) {
  .debug-hud { grid-template-columns: minmax(0, 1fr); max-height: 30dvh; }
  .debug-hint { font-size: var(--text-label); }
}
.debug-group h3 { font-size: var(--text-label); letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent2); }
.debug-group dl { margin: 5px 0 0; }
.debug-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: 8px; padding: 3px 0; }
.debug-row dt { color: var(--muted); }
.debug-row dd { margin: 0; min-width: 0; text-align: right; }
.debug-value {
  font-family: var(--font-mono); font-size: var(--text-label); font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere; color: var(--text);
  transition: color var(--t) var(--ease);
}
.debug-health { display: block; font-size: var(--text-label); color: var(--muted); }
.debug-health:empty { display: none; }
.debug-row[data-health="good"] .debug-value { color: var(--good); }
.debug-row[data-health="warn"] .debug-value { color: var(--warn); }
.debug-row[data-health="err"] .debug-value { color: var(--err); }

.activity {
  margin: 0; padding: 10px 12px; border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.35); border: 1px solid var(--panel-brd);
  font-family: var(--font-mono); font-size: var(--text-label); line-height: 1.6;
  color: var(--muted); white-space: pre-wrap; word-break: break-word;
  max-height: 220px; overflow-y: auto;
}

/* ----- unlock panel ------------------------------------------------------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 20px;
  background: color-mix(in srgb, var(--zg-dark-900) 86%, transparent);
  backdrop-filter: blur(8px);
}
.gate.show { display: flex; animation: gatefade var(--t) var(--ease); }
@keyframes gatefade { from { opacity: 0; } to { opacity: 1; } }

.gate-card {
  width: min(430px, 100%);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px;
  padding: 26px 24px 22px;
  background: linear-gradient(180deg, var(--zg-primary-900), var(--surface));
  border: 1px solid var(--panel-brd);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  animation: gaterise var(--t-slow) var(--ease-out);
}
@keyframes gaterise {
  from { transform: translateY(12px) scale(0.985); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.gate-card h2 { font-size: 19px; color: var(--text-strong); }
.gate-card p { margin: 0; font-size: var(--text-body); line-height: 1.6; color: var(--muted); }
.gate-card .input { font-family: var(--font-mono); text-align: center; }
.gate-card .gate-err { min-height: 17px; margin: 0; font-size: var(--text-support); color: var(--err); }
.gate-card .btn { width: 100%; }
/* The way OUT of this panel for someone who never needed a key — quiet enough
   not to compete with Unlock, present enough to be the obvious escape. */
.gate-card .gate-portal { margin: 0; font-size: var(--text-body); }
.gate-card .gate-portal a {
  color: var(--text-strong);
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.28);
  padding-bottom: 1px;
  transition: border-color var(--t) var(--ease), color var(--t) var(--ease);
}
.gate-card .gate-portal a:hover { border-bottom-color: currentColor; }
.gate-card .gate-portal a:focus-visible { outline: 2px solid var(--text-strong); outline-offset: 3px; border-radius: 2px; }

/* Small depth cues keep interaction feedback consistent across the studio. */
.btn.primary { box-shadow: 0 8px 24px color-mix(in srgb, var(--zg-primary-500) 45%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.14); }
.btn.primary:hover:not(:disabled) { box-shadow: 0 10px 28px color-mix(in srgb, var(--zg-primary-500) 55%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.2); }
.composer .field { transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
.composer .field:focus-within { box-shadow: 0 0 0 3px var(--accent-soft); }
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pick:focus-visible, .setup-chip:focus-visible, .suggestion:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.drawer-head, .drawer-foot { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.025); }
.notice { box-shadow: inset 3px 0 0 var(--warn), 0 4px 16px rgba(0, 0, 0, 0.12); }
.notice.info { box-shadow: inset 3px 0 0 var(--accent), 0 4px 16px rgba(0, 0, 0, 0.12); }
.uprow .bar { height: 7px; }
.uprow .st { font-variant-numeric: tabular-nums; color: var(--muted); }

/* Preserve immediate hidden semantics for keyboard and assistive technology.
   Supporting browsers can still paint the outgoing surface during its fade. */
@supports (transition-behavior: allow-discrete) {
  .debug-hud, .notice, .miccap, .disclosure-panel, .veil-setup, .veil-steps, #chatReset {
    transition: opacity var(--t) var(--ease), display var(--t) allow-discrete;
  }
  :is(.debug-hud, .notice, .miccap, .disclosure-panel, .veil-setup, .veil-steps, #chatReset)[hidden] { opacity: 0; }
  @starting-style {
    .debug-hud, .notice, .miccap, .disclosure-panel, .veil-setup, .veil-steps, #chatReset { opacity: 0; }
  }
}

/* ----- responsive --------------------------------------------------------- */
@media (max-width: 1120px) { :root { --chat-w: 340px; } }

/* The idle card grew a status pill, a portrait tile and a setup row. On a short
   window that is more than the stage has room for, and the stage clips — so give
   the tile back its smaller square and tighten the rhythm rather than lose the
   bottom of the card. */
@media (max-height: 780px) {
  .veil-card { gap: 11px; }
  #veilIdentity { width: 88px; height: 88px; border-radius: 24px; font-size: 28px; }
  #veilIdentity.has-photo { width: 104px; height: 132px; border-radius: 20px; }
  #veilIdentity.has-photo.breathe::after { border-radius: 28px; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; grid-template-rows: var(--top-h) auto; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 14px; }
  .stage-wrap { height: 52dvh; }
  .stage { height: 100%; }
  .chat-col { min-height: 62dvh; }
  .dock { gap: 6px; padding: 6px; }
  .btn.chip { max-width: 140px; padding: 5px 10px 5px 5px; }
  .btn.chip .chip-v { max-width: 82px; }
  /* The stage is 52dvh here, so the card has to fit in half a phone screen. */
  .veil-card { gap: 10px; }
  #veilIdentity { width: 76px; height: 76px; border-radius: 22px; font-size: 25px; }
  #veilIdentity.has-photo { width: 88px; height: 112px; border-radius: 18px; }
  #veilIdentity.has-photo.breathe::after { border-radius: 26px; }
  .setup-chip { padding: 6px 12px; }
  .drawer { width: 100vw; max-width: 100vw; }
  .drawer-resize { display: none; }
}

@media (max-width: 520px) {
  :root { --gap: 12px; }
  .brand .wordmark { font-size: var(--text-support); }
  .topbar { gap: 8px; flex-wrap: wrap; padding-block: 8px; }
  .app { grid-template-rows: minmax(var(--top-h), auto) auto; }
  .topbar .btn { padding-inline: 10px; }
  .disclosure { flex-wrap: wrap; }
  .disclosure .disclosure-sub { flex-basis: 100%; text-align: left; white-space: normal; }
  .debug-panel > summary { flex-wrap: wrap; gap: 6px 12px; }
  .topbar .env { display: none; }
}

/* Recording is on for every conversation, so the bar is a STATUS with one
   action in it (Stop), never a toggle. Before the call it is a quiet line;
   during it, a red live dot, "Recording", the timer and Stop. */
.recordbar {
  width: fit-content; max-width: min(100%, 800px); align-self: center;
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px;
  padding: 8px 12px; margin-top: 0; border: 1px solid var(--panel-brd);
  border-radius: var(--radius); background: var(--panel);
}
.recordbar .btn { min-height: 44px; }
.record-note {
  display: inline-flex; align-items: center; gap: 8px; margin: 0;
  color: var(--muted); font-size: var(--text-support); line-height: 1.6;
  cursor: default;
}
.rec-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--zg-error-500); flex: 0 0 auto; color: color-mix(in srgb, var(--zg-error-500) 60%, transparent);
}
/* At rest, before anything is kept, the dot is the brand's peach: a red dot asleep. */
.rec-dot.rec-dot-quiet { background: var(--zg-secondary-500); }
.record-live {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--zg-error-100); font-size: var(--text-support); font-weight: 700;
}
.record-live .rec-dot { animation: pulse 1.8s var(--ease) infinite; }
@media (prefers-reduced-motion: reduce) {
  .record-live .rec-dot { animation: none; }
}
.record-status { flex: 1 1 180px; min-width: 0; overflow-wrap: anywhere; color: var(--muted); font-size: var(--text-support); line-height: 1.6; }
/* Empty, the live region stays in the page (so its next words are announced)
   but takes no room. */
.record-status:empty {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; flex: 0 0 0;
}
.recordbar[data-state="recording"] { border-color: var(--zg-error-500); background: var(--err-soft); }
.recordbar[data-state="recording"] .record-status { color: var(--text-strong); font-weight: 600; }
.recordbar[data-state="starting"],
.recordbar[data-state="saving"] { border-color: var(--accent-brd); }
.recordbar[data-state="saved"] .record-status { color: var(--good); }
.recordbar[data-state="error"] .record-status { color: var(--err); }
/* The one solid destructive fill on the page: error.700, white above 6:1, and a step
   towards error.500 on hover where white still clears 5:1. */
.record-stop { border-color: var(--zg-error-500); background: var(--zg-error-700); color: var(--zg-white); }
.record-stop:hover { background: color-mix(in srgb, var(--zg-error-500) 25%, var(--zg-error-700)); }
.record-view {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px;
  color: var(--accent); font-size: var(--text-support); font-weight: 600;
  text-decoration: underline; text-underline-offset: 3px;
}
.record-view:focus-visible,
.record-terms-note > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.recording-clock { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.record-terms-note { font-size: var(--text-support); color: var(--muted); }
.record-terms-note > summary {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px;
  cursor: pointer; text-decoration: underline; text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.record-terms-note[open] { flex-basis: 100%; }
.record-terms-text {
  margin: 4px 0 0; padding: 12px 14px; max-width: 64ch;
  border: 1px solid var(--panel-brd); border-radius: var(--radius);
  background: var(--panel); color: var(--text); line-height: 1.65;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
@media (max-width: 600px) {
  .recordbar { width: 100%; padding: 8px 10px; gap: 8px; }
  .record-status { flex-basis: 100%; }
  .recording-indicator { font-size: var(--text-label); padding: 6px 9px; }
}

/* Desktop browser windows can be short: scroll rather than hide Go live. */
@media (min-width: 901px) and (max-height: 760px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .stage-wrap { flex: 0 0 auto; height: max(440px, 60dvh); }
}


/* Recording state remains visible inside the toolbar without a second panel.
   Only Stop recording uses a solid destructive color; stopping the microphone
   and ending the session keep their own explicit text labels. */
.session-toolbar .recordbar {
  width: auto; max-width: 100%; min-width: 0; flex: 0 1 auto;
  gap: 8px; padding: 0; border: 0; border-radius: 0; background: none;
}
.session-toolbar .record-status { flex: 0 1 auto; max-width: 300px; }
.session-toolbar .recordbar[data-state="recording"] .record-status { color: var(--zg-error-100); }
.debug-panel:not([open]) {
  width: fit-content; background: none; border-color: transparent;
}
.debug-panel:not([open]) .debug-hint { display: none; }
@media (max-width: 600px) {
  .session-toolbar { width: 100%; padding: 8px; gap: 10px; }
  .session-toolbar .dock { width: 100%; gap: 6px; }
  .session-toolbar .recordbar { justify-content: center; width: 100%; }
  .session-toolbar .record-status { flex: 1 1 100%; max-width: none; text-align: center; }
  .session-toolbar .recordbar:not([data-state="off"]) { padding-top: 8px; border-top: 1px solid var(--panel-brd); }
}

.voice-group > button.group-label { width:100%; border:0; text-align:left; font:inherit; font-size:12px; font-weight:600; color:var(--muted); cursor:pointer; min-height:44px; }
.voice-group > button.group-label::after { content:'⌃'; font-size:16px; }
.voice-group.collapsed > button.group-label::after { content:'⌄'; }
.voice-group.collapsed > :not(.group-label) { display:none; }
.voice-group > button.group-label .group-n { margin-left:auto; }
.voice-group > button.group-label:focus-visible { outline:2px solid var(--accent); outline-offset:-2px; }

/* A refused New chat, said beside the button. Empty, it keeps its place in
   the accessibility tree (so its next words are announced) but takes no room. */
.reset-hint { color: var(--muted); font-size: var(--text-support); line-height: 1.4; }
.reset-hint:empty {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ------------------------------------------------ model readiness --------
   The line under the model picker: Ready, Enabling (a breathing dot while AWS
   switches the model on), or Not available. Colours are the existing state
   tokens, all above 4.5:1 on the drawer surface. The global
   prefers-reduced-motion rule near the top of this file stills the dot. */
.model-readiness {
  display: flex; gap: 8px; align-items: flex-start;
  margin: 8px 0 0; font-size: var(--text-support); line-height: 1.5; color: var(--muted);
  animation: readiness-in var(--t) var(--ease-out);
}
/* Kept in the page when empty (a live region must exist before it speaks),
   so it takes no room until there is something to say. */
.model-readiness:empty { margin: 0; }
.model-readiness strong { color: var(--text); font-weight: 600; }
.model-readiness .rdot {
  flex: 0 0 auto; width: 8px; height: 8px; margin-top: 7px; border-radius: 50%;
  background: var(--muted);
}
.model-readiness[data-state="ready"] .rdot { background: var(--good); }
.model-readiness[data-state="ready"] strong { color: var(--good); }
.model-readiness[data-state="enabling"] .rdot,
.model-readiness[data-state="checking"] .rdot {
  background: var(--warn); color: color-mix(in srgb, var(--warn) 55%, transparent);
  animation: pulse 1.6s var(--ease) infinite;
}
.model-readiness[data-state="checking"] .rdot { background: var(--muted); color: color-mix(in srgb, var(--muted) 50%, transparent); }
.model-readiness[data-state="unavailable"] .rdot { background: transparent; border: 1.5px solid var(--muted); }
/* The wait is over: one small pop of the dot, once. */
.model-readiness.just-ready .rdot { animation: readiness-pop var(--t-slow) var(--ease-out); }
@keyframes readiness-in { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: none; } }
@keyframes readiness-pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  /* Higher specificity: the rules themselves come later in the file. */
  html .conv-mode-option, html .conv-mode-fields { transition: none; }
  html .conv-mode-voice:not([hidden]) { animation: none; }
  .model-readiness, .model-readiness .rdot { animation: none !important; }
}

/* ------------------------------------------------ conversation mode --------
   Standard, Realtime (OpenAI) or Live (OpenAI GPT-Live), web/conversationMode.js.
   Three cards on the Voice tab, chosen first; the mode's voice list fades in
   under them. The mode's OpenAI model expands in place on the Model tab (grid
   rows 0fr to 1fr), so nothing below it jumps. */
.conv-mode-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-bottom: 10px; }
.conv-mode-option { display: flex; gap: 10px; align-items: flex-start; padding: 12px; min-height: 44px; border: 1px solid var(--panel-brd-strong); border-radius: var(--radius-sm); background: var(--panel); color: var(--text); cursor: pointer; transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
.conv-mode-option:hover { background: var(--panel-hover); }
.conv-mode-option:has(input:checked) { border-color: var(--accent-brd); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-brd); }
/* Disabled reads as disabled by its dashed edge and the reason in words, not by
   fading the whole card: the reason has to stay as legible as everything else. */
.conv-mode-option:has(input:disabled) { cursor: not-allowed; border-style: dashed; background: transparent; }
.conv-mode-option:has(input:disabled) b, .conv-mode-option:has(input:disabled) .conv-mode-facts { color: var(--muted); }
.conv-mode-option:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.conv-mode-option input { width: 18px; height: 18px; margin-top: 2px; flex: none; accent-color: var(--accent); }
.conv-mode-option > span { display: grid; gap: 4px; min-width: 0; }
.conv-mode-option > span > span { display: grid; gap: 4px; }
.conv-mode-option b { color: var(--text-strong); font-size: 13px; }
.conv-mode-line { color: var(--text); font-size: 12px; line-height: 1.45; }
.conv-mode-facts { display: grid; gap: 1px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.conv-mode-option .conv-mode-residency { justify-self: start; margin-top: 2px; padding: 2px 8px; border: 1px solid var(--panel-brd-strong); border-radius: var(--radius-pill); color: var(--text); font-size: 11px; }
.conv-mode-residency[data-where="onshore"] { border-color: var(--good-brd); }
.conv-mode-residency[data-where="offshore"] { border-color: var(--warn-brd); }
.conv-mode-reason { color: var(--text-strong); font-size: 12px; font-weight: 600; }
.conv-mode-chip { padding: 1px 8px; border: 1px solid var(--accent-brd); border-radius: var(--radius-pill); color: var(--text); }
#convModeNote:empty, #realtimeVoiceNote:empty, #liveVoiceNote:empty { display: none; }
/* Samples never change the selected voice. */
#rtVoicePreview, #lvVoicePreview { margin-top: 8px; min-height: 44px; }
/* Switching mode swaps the voice list: the new one arrives, it does not blink. */
.conv-mode-voice:not([hidden]) { animation: conv-mode-in var(--t-fast) var(--ease-out); }
@keyframes conv-mode-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.conv-mode-fields { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .24s ease; }
.conv-mode-fields[data-open="true"] { grid-template-rows: 1fr; }
.conv-mode-fields-inner { overflow: hidden; min-height: 0; }

/* Region detail is an independent action, never part of the radio label. */
.conv-mode-option { display: grid; grid-template-columns: 20px minmax(0, 1fr); }
.conv-mode-choice { display: contents; }
.conv-mode-choice > span { min-width: 0; }
.region-info { grid-column: 2; justify-self: start; }
.conv-mode-residency { min-height: 44px; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; margin: 0; background: var(--surface); font: inherit; font-size: 12px; cursor: pointer; }
.region-detail { max-height: 160px; overflow: auto; position: fixed; z-index: 1000; width: 280px; max-width: calc(100vw - 16px); box-sizing: border-box; padding: 12px; border: 1px solid var(--panel-brd-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text-strong); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); font-size: 12px; line-height: 1.5; }

.region-detail[hidden] { display: none !important; }
.model-fallback { min-width: 0; border-top: 1px solid var(--panel-brd-strong); padding-top: 8px; }
.model-fallback summary { min-height: 44px; padding: 12px 0; cursor: pointer; overflow-wrap: anywhere; }
.model-fallback summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.model-context { margin: 0; line-height: 1.6; }

.model-mode-link { min-height: 44px; align-self: flex-start; }
