/* Sundae voice client — matched EXACTLY to the Sundae Fleet dashboard
 * (webapp/fleet-dashboard.html): same tokens, same fonts, same shadows,
 * LIGHT ONLY (the dashboard has no dark mode). No external assets — the
 * Sora/Manrope stacks fall back to SF Pro on iPhone/Mac, exactly as the
 * dashboard does. */

:root {
  --brand: #0e8ab1;
  --brand-dark: #0a6f90;
  --brand-light: #e8f5fa;
  --brand-muted: #7bbdd4;
  --grad-start: #0d6f8d;
  --grad-end: #119bc6;
  --grad: linear-gradient(135deg, #0d6f8d, #119bc6);

  --bg: #eef4f8;
  --card: #ffffff;
  --card-alt: #f4fbff;
  --ink: #112536;
  --muted: #4d6575;
  --faint: #8ca3b2;
  --line: #c7d3dc;
  --line-light: #dde7ed;

  --ok: #1f8a4d;   --ok-light: #e8f7ee;
  --warn: #a16908; --warn-light: #fff4e7;
  --err: #b62f2f;  --err-light: #fdecec;
  --gold: #f4b15e; --gold-light: #fff7eb;

  --shadow-sm: 0 1px 3px rgba(13,59,82,.06);
  --shadow-md: 0 4px 12px rgba(13,59,82,.10);
  --shadow-lg: 0 8px 24px rgba(13,59,82,.14);
  --shadow-xl: 0 18px 48px rgba(13,59,82,.20);

  --font-display: 'Sora', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  --font-ui: 'Manrope', 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Space Mono', Menlo, monospace;

  --mic: 0;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(1000px 560px at 84% -8%, rgba(17,155,198,.10), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.01em; }

/* ============================ shell ============================ */
.app {
  min-height: 100%; max-width: 1120px; margin: 0 auto;
  padding: 20px clamp(16px,4vw,32px) 32px;
  display: flex; flex-direction: column; gap: 20px;
}
header.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
  width: 42px; height: 42px; border-radius: 12px; background: var(--grad);
  box-shadow: var(--shadow-md), inset 0 0 0 1px rgba(255,255,255,.28);
  display: grid; place-items: center; flex: none;
}
.brand .mark::after {
  content: ""; width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, var(--gold) 78%);
  box-shadow: 0 0 12px rgba(244,177,94,.75);
}
.brand h1 { font-size: 1.18rem; margin: 0; font-weight: 700; }
.brand .tag { display: block; font-size: .72rem; color: var(--faint); font-weight: 600; letter-spacing: .3px; margin-top: 1px; }
.top-right { display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: .74rem; font-weight: 700; letter-spacing: .2px; padding: 7px 13px;
  border-radius: 999px; white-space: nowrap; border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: 7px;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-off  { color: var(--faint); background: #eaf1f5; border-color: var(--line-light); }
.pill-wait { color: var(--warn); background: var(--warn-light); border-color: #f0dcb8; }
.pill-ok   { color: var(--ok); background: var(--ok-light); border-color: #c6e9d4; }
.pill-err  { color: var(--err); background: var(--err-light); border-color: #f2cfcf; }
.pill-state{ color: var(--brand); background: var(--brand-light); border-color: #cbe6f0; text-transform: capitalize; }

/* ============================ stage ============================ */
.stage { display: grid; grid-template-columns: 1.02fr .98fr; gap: 20px; align-items: stretch; }
@media (max-width: 860px) { .stage { grid-template-columns: 1fr; } }

.card, .presence, .convo {
  background: var(--card); border: 1px solid var(--line-light);
  border-radius: 20px; box-shadow: var(--shadow-sm);
}
.presence {
  position: relative; padding: 30px 24px 26px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.presence::before {
  content: ""; position: absolute; inset: -45% 0 auto 0; height: 72%;
  background: radial-gradient(58% 100% at 50% 0%, rgba(17,155,198,.12), transparent 72%); pointer-events: none;
  transition: opacity .8s ease;
}
/* Keeps every child above .presence::after (the wake sunrise, z-index 0), so
   the flourish lights the card from behind instead of washing over the text. */
.presence > * { position: relative; z-index: 1; }

.orb-wrap { position: relative; width: 220px; height: 220px; display: grid; place-items: center; }
.orb-ring {
  position: absolute; width: 202px; height: 202px; border-radius: 50%;
  border: 2px solid rgba(14,138,177,.32); opacity: 0; transform: scale(.9); transition: opacity .3s;
}
.orb {
  position: relative; width: 172px; height: 172px; border-radius: 50%;
  background: radial-gradient(60% 55% at 34% 30%, #dff4fb 0%, rgba(255,255,255,0) 55%), var(--grad);
  box-shadow: var(--shadow-lg), inset 0 -14px 30px rgba(10,70,95,.30), inset 0 10px 22px rgba(255,255,255,.34);
  display: grid; place-items: center;
  transform: scale(calc(1 + var(--mic) * .06)); transition: transform .09s ease-out;
  animation: breathe 5.5s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.028); } }
.face { width: 120px; height: 96px; overflow: visible; }
.eye { fill: #0e2a38; }
.blush { fill: var(--gold); opacity: .5; }
.mouth { fill: none; stroke: #0e2a38; stroke-width: 6; stroke-linecap: round; }
.eyes { transform-origin: center; transform-box: fill-box; animation: blink 5.2s infinite; }
@keyframes blink { 0%,96%,100% { transform: scaleY(1); } 98% { transform: scaleY(.1); } }

.orb-status { font-family: var(--font-display); font-weight: 700; font-size: 1.02rem; color: var(--ink); min-height: 1.4em; text-align: center; }
.orb-sub { font-size: .8rem; color: var(--faint); margin-top: -8px; text-align: center; }

body[data-sstate="listening"] .orb-ring { opacity: 1; animation: halo 1.6s ease-out infinite; }
@keyframes halo { 0% { transform: scale(.92); opacity: .8; } 100% { transform: scale(1.16); opacity: 0; } }
body[data-sstate="listening"] .orb { animation: breathe 3s ease-in-out infinite; }
body[data-sstate="thinking"] .orb { animation: think 1.5s ease-in-out infinite; }
@keyframes think { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.08); } }
body[data-sstate="speaking"] .orb { animation: breathe 2.4s ease-in-out infinite; }
body[data-sstate="speaking"] .mouth { animation: talk .34s ease-in-out infinite; }
@keyframes talk { 0%,100% { d: path("M42 64 Q60 74 78 64"); } 50% { d: path("M44 62 Q60 88 76 62"); } }
body[data-sstate="speaking"] .blush { opacity: .85; }

/* ======================================================================
 * SLEEPING  (B3 — the lifecycle port's most visible surface)
 * ======================================================================
 * When Sundae goes quiet the page must say so unmistakably and WARMLY.
 * "Unmistakably" rules out a subtle tint: the difference between asleep
 * and simply-not-talking has to be readable across a room, because that
 * is the distance a resident is usually at. "Warmly" rules out the
 * obvious engineering answer (grey everything out, "SESSION IDLE"),
 * which reads as broken. A sleeping companion is not a disabled control.
 *
 * Four signals, all describing the same thing so none of them has to
 * carry it alone:
 *   1. the face closes its eyes            (the thing you look at)
 *   2. the orb dims and breathes at ~7/min (the thing you feel)
 *   3. three z's drift off it              (the thing you name)
 *   4. a card says it in words + how to wake her (the thing you act on)
 *
 * Everything here is a cross-fade or a slow keyframe. Nothing appears by
 * display-swap on the face itself, so waking can be animated in reverse.
 * ---------------------------------------------------------------------- */

/* -- the face -------------------------------------------------------- */
/* Both eye drawings live in the DOM at all times; sleep is a cross-fade
   between them, which is what lets the WAKE animation run backwards. */
.eyes { transition: opacity .45s ease; }
.lids { opacity: 0; transition: opacity .45s ease; pointer-events: none; }
.lid {
  fill: none; stroke: #0e2a38; stroke-width: 5.5;
  stroke-linecap: round; stroke-linejoin: round;
}
body[data-sstate="sleeping"] .eyes { opacity: 0; animation: none; }
body[data-sstate="sleeping"] .lids { opacity: .88; }
/* A resting mouth: the smile relaxes almost flat, but never turns down.
   Sundae asleep is content, not sad. */
body[data-sstate="sleeping"] .mouth {
  d: path("M48 66 Q60 70.5 72 66");
  animation: none;
  opacity: .72;
}
body[data-sstate="sleeping"] .blush { opacity: .3; }

/* -- the orb --------------------------------------------------------- */
/* transform is claimed by the animation, which is deliberate: it is what
   overrides the --mic scale binding, so a noisy room can no longer make a
   sleeping doll twitch. She is asleep; she does not react. */
body[data-sstate="sleeping"] .orb {
  animation: sleepBreathe 8.5s ease-in-out infinite;
  filter: saturate(.34) brightness(.84);
  box-shadow:
    var(--shadow-md),
    inset 0 -14px 30px rgba(10,70,95,.34),
    inset 0 10px 22px rgba(255,255,255,.18);
  transition: filter .8s ease, box-shadow .8s ease;
}
/* ~7 breaths a minute, and the exhale is longer than the inhale (the peak
   sits at 38 %, not 50 %) — that asymmetry is the difference between
   "breathing" and "pulsing like a status LED". */
@keyframes sleepBreathe {
  0%, 100% { transform: scale(.972); }
  38%      { transform: scale(1.012); }
}
body[data-sstate="sleeping"] .orb-ring { opacity: 0; animation: none; }
/* The presence card itself dims one small step — enough to feel like the
   lights went down, not enough to look disabled. */
body[data-sstate="sleeping"] .presence::before { opacity: .35; }
body[data-sstate="sleeping"] .orb-status { color: var(--muted); }

/* -- the z's --------------------------------------------------------- */
.zzz {
  position: absolute; top: 4%; right: 2%;
  display: none; align-items: flex-end; gap: 2px;
  font-family: var(--font-display); font-weight: 700;
  color: var(--brand); pointer-events: none;
}
body[data-sstate="sleeping"] .zzz { display: flex; }
.zzz span {
  display: block; opacity: 0;
  animation: zzzDrift 4.2s ease-in-out infinite;
}
.zzz span:nth-child(1) { font-size: .78rem; animation-delay: 0s; }
.zzz span:nth-child(2) { font-size: 1.02rem; animation-delay: .55s; }
.zzz span:nth-child(3) { font-size: 1.34rem; animation-delay: 1.1s; }
@keyframes zzzDrift {
  0%   { opacity: 0; transform: translate(0, 8px) rotate(-8deg) scale(.8); }
  22%  { opacity: .85; }
  70%  { opacity: .5; }
  100% { opacity: 0; transform: translate(16px, -26px) rotate(12deg) scale(1.1); }
}

/* -- the sleeping card ----------------------------------------------- */
.sleep-note {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  padding: 15px 16px 16px;
  border-radius: 18px;
  border: 1px solid #d6e2ec;
  background: linear-gradient(180deg, #f6fafd 0%, #eef4f9 100%);
  box-shadow: var(--shadow-sm);
  text-align: center;
  animation: pop .32s ease-out;
}
.sleep-note[hidden] { display: none; }
.sn-title {
  font-family: var(--font-display); font-weight: 700; font-size: .98rem;
  color: var(--ink); display: inline-flex; align-items: center; gap: 8px;
}
.sn-moon {
  font-size: 1.1rem; color: var(--brand); line-height: 1;
  animation: moonGlow 4.6s ease-in-out infinite;
}
@keyframes moonGlow { 0%,100% { opacity: .55; } 50% { opacity: 1; } }
.sn-body { font-size: .82rem; line-height: 1.55; color: var(--muted); max-width: 34ch; }
.sn-body b { color: var(--brand-dark); font-weight: 800; white-space: nowrap; }
/* Sleep silences CHAT, never SAFETY — and the person in the room is told
   so, in one plain sentence, without being made to think about protocols. */
.sn-safety {
  font-size: .74rem; line-height: 1.5; font-weight: 700; color: var(--ok);
  background: var(--ok-light); border: 1px solid #c6e9d4;
  border-radius: 999px; padding: 5px 13px; max-width: 36ch;
}
.btn-wake {
  margin-top: 2px; padding: 11px 20px; font-size: .9rem;
  border-color: var(--brand); color: var(--brand); background: var(--card);
}
.btn-wake:hover:not(:disabled) { background: var(--brand); color: #fff; border-color: var(--brand); }

/* -- drowsy: the idle ladder, before she is actually asleep ----------- */
/* Stages 2 and 3 of the doll's ladder ANNOUNCE a nap without taking one.
   The face should agree with what she just said, so the eyes get heavy a
   step at a time — and this is the one cue that makes the eventual sleep
   feel like a consequence rather than a dropout. */
body[data-drowsy="2"] .orb { animation: breathe 7s ease-in-out infinite; filter: saturate(.8) brightness(.95); }
body[data-drowsy="3"] .orb { animation: breathe 8s ease-in-out infinite; filter: saturate(.6) brightness(.9); }
body[data-drowsy="2"] .eyes { transform: scaleY(.72); }
body[data-drowsy="3"] .eyes { transform: scaleY(.5); }
body[data-drowsy="2"] .eyes, body[data-drowsy="3"] .eyes {
  animation: none; transform-origin: center; transform-box: fill-box;
  transition: transform .7s ease;
}

/* -- WAKING ----------------------------------------------------------
 * Waking has to FEEL like waking, which means it is the one moment on
 * this page that is allowed to be theatrical. body.waking is set by
 * app.js for ~1.5 s on every sleeping -> awake transition (spoken wake
 * phrase, console toggle, or a clinical override). Three things happen
 * together: the lids sweep up, the orb stretches and colour floods back,
 * and a sunrise wash rises through the card from below.
 * ------------------------------------------------------------------ */
body.waking .orb {
  animation: wakeStretch 1.15s cubic-bezier(.22,.61,.36,1);
  filter: none;
}
@keyframes wakeStretch {
  0%   { transform: scale(.968); filter: saturate(.34) brightness(.84); }
  38%  { transform: scale(1.062); filter: saturate(1.16) brightness(1.1); }
  70%  { transform: scale(.992); filter: saturate(1.02) brightness(1.02); }
  100% { transform: scale(1); filter: none; }
}
/* The lids retract upward and fade; the eyes come back a beat later with
   one deliberate blink, the way a person actually surfaces. */
body.waking .lids { animation: lidLift .5s ease-out forwards; transform-origin: center; transform-box: fill-box; }
@keyframes lidLift {
  0%   { opacity: .88; transform: translateY(0) scaleY(1); }
  100% { opacity: 0;   transform: translateY(-5px) scaleY(.25); }
}
body.waking .eyes { animation: eyeOpen .62s ease-out; transform-origin: center; transform-box: fill-box; }
@keyframes eyeOpen {
  0%   { opacity: 0; transform: scaleY(.08); }
  45%  { opacity: 1; transform: scaleY(1.14); }
  62%  { transform: scaleY(.86); }
  100% { opacity: 1; transform: scaleY(1); }
}
body.waking .blush { animation: blushWarm 1.4s ease-out; }
@keyframes blushWarm { 0% { opacity: .3; } 30% { opacity: .95; } 100% { opacity: .5; } }
/* Sunrise: gold rising through the presence card from the bottom edge.
   ::after is unused on .presence (::before is the existing blue wash), so
   this costs no new element. */
.presence::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  opacity: 0; z-index: 0;
  background: radial-gradient(78% 68% at 50% 110%, rgba(244,177,94,.42), transparent 68%);
}
body.waking .presence::after { animation: sunrise 1.5s ease-out; }
@keyframes sunrise {
  0%   { opacity: 0; transform: translateY(14px); }
  30%  { opacity: 1; transform: none; }
  100% { opacity: 0; transform: none; }
}

.presence-controls { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.btn {
  font: inherit; font-family: var(--font-ui); font-weight: 700; cursor: pointer; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 12px 20px; transition: .15s;
}
.btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid rgba(14,138,177,.4); outline-offset: 2px; }
.btn-primary { background: var(--grad); color: #fff; border: none; font-size: 1.04rem; padding: 15px 42px; box-shadow: var(--shadow-md); }
.btn-primary:hover:not(:disabled) { color: #fff; transform: translateY(-2px); filter: brightness(1.05); box-shadow: var(--shadow-lg); }
.btn-warn { color: var(--warn); }
.btn-warn:hover:not(:disabled) { border-color: var(--gold); color: var(--warn); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* STT engine segmented control ("Speech: Auto / Sundae GPU / Google") */
.stt-select { display: flex; align-items: center; gap: 9px; }
.stt-select .stt-lab { font-size: .68rem; color: var(--faint); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.seg-group { display: inline-flex; background: #eaf1f5; border: 1px solid var(--line-light); border-radius: 999px; padding: 3px; gap: 2px; }
.seg {
  font: inherit; font-family: var(--font-ui); font-size: .74rem; font-weight: 700; color: var(--muted);
  background: transparent; border: 1px solid transparent; border-radius: 999px; padding: 6px 12px;
  cursor: pointer; transition: .15s; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.seg:hover { color: var(--brand); }
.seg.active { background: var(--card); color: var(--brand); border-color: #cbe6f0; box-shadow: var(--shadow-sm); }
.stat-eng { font-weight: 700; color: var(--brand); text-transform: none; letter-spacing: 0; margin-left: 5px; }

.mode-chip { display: none; align-items: center; gap: 8px; padding: 7px 15px; border-radius: 999px;
  font-weight: 700; font-size: .82rem; background: var(--gold-light); color: #9a6a17; border: 1px solid #f2ddb6; }
.mode-chip.show { display: inline-flex; }
.mode-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }

/* ============================ conversation ============================ */
.convo { display: flex; flex-direction: column; overflow: hidden; position: relative; }
.convo-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--line-light); }
.convo-head h2 { margin: 0; font-size: .98rem; }
.session-label { font-size: .72rem; color: var(--faint); font-family: var(--font-mono); }
.transcript { flex: 1; min-height: 300px; max-height: 52vh; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }

/* Shown when the reader has scrolled up and new messages arrive below. */
.jump-latest {
  position: absolute; left: 50%; bottom: 78px; transform: translateX(-50%);
  z-index: 2; border: none; cursor: pointer;
  font-family: var(--font-ui); font-weight: 700; font-size: .78rem;
  padding: 8px 16px; border-radius: 999px;
  background: var(--brand); color: #fff; box-shadow: var(--shadow-md);
  animation: pop .22s ease-out;
}
.jump-latest:hover { background: var(--brand-dark); }
.jump-latest:focus-visible { outline: 3px solid rgba(14,138,177,.4); outline-offset: 2px; }
.bubble { max-width: 84%; padding: 11px 15px; border-radius: 16px; line-height: 1.5; font-size: .95rem; position: relative; animation: pop .22s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.bubble .who { display: block; font-size: .64rem; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; opacity: .62; margin-bottom: 3px; }
.bubble .body { display: block; }
.bubble.user { align-self: flex-end; background: var(--grad); color: #fff; border-bottom-right-radius: 5px; }
.bubble.user .who { color: #e6f6fc; }
.bubble.assistant { align-self: flex-start; background: var(--card-alt); color: var(--ink); border: 1px solid var(--line-light); border-bottom-left-radius: 5px; }
.bubble.partial { opacity: .6; font-style: italic; }
.bubble.interrupted { opacity: .55; }
.bubble.interrupted::after { content: " ⏹ stopped"; font-size: .7rem; color: var(--faint); }
.sys { align-self: center; font-size: .74rem; color: var(--faint); font-family: var(--font-mono); background: #eaf1f5; padding: 4px 11px; border-radius: 999px; text-align: center; }
.sys.warn { color: var(--warn); background: var(--warn-light); }
.sys.err  { color: var(--err); background: var(--err-light); }
.sys.barge{ color: var(--brand); background: var(--brand-light); }
.sys.hint { color: var(--faint); }
.sys.alert{ color: #fff; background: var(--err); font-weight: 700; padding: 7px 15px; box-shadow: var(--shadow-md); }
/* Lifecycle notes (idle check-in, asleep, awake) read as their own quiet
   voice in the transcript — not a warning, not an error, not chat. */
.sys.sleep{ color: var(--brand-dark); background: var(--brand-light); font-weight: 700; }
.sys.wake { color: #8a5c14; background: var(--gold-light); font-weight: 700; }

.say-form { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line-light); }
.say-form input { flex: 1; font: inherit; font-family: var(--font-ui); padding: 12px 15px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--ink); transition: .15s; }
.say-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,138,177,.15); }
.say-form input:disabled { opacity: .5; }

/* ============================ dev panel ============================ */
.dev { border: 1px solid var(--line-light); border-radius: 16px; background: var(--card); box-shadow: var(--shadow-sm); overflow: hidden; }
.dev > summary { cursor: pointer; list-style: none; padding: 13px 18px; font-weight: 700; font-size: .86rem; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.dev > summary::-webkit-details-marker { display: none; }
.dev > summary::before { content: "▸"; color: var(--faint); transition: .2s; }
.dev[open] > summary::before { transform: rotate(90deg); }
.dev .dev-body { padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 16px; }
.metrics-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.mic-meter { display: flex; align-items: center; gap: 9px; }
.mic-meter .lab { font-size: .72rem; color: var(--faint); font-weight: 700; }
.meter-track { width: 130px; height: 8px; border-radius: 999px; background: #e3edf2; overflow: hidden; }
.meter-fill { height: 100%; width: 0%; background: var(--grad); border-radius: 999px; transition: width .08s; }
.rtt { font-size: .78rem; color: var(--muted); font-family: var(--font-mono); }
.rtt b { color: var(--brand); }
.hud-head { display: flex; align-items: baseline; justify-content: space-between; }
.hud-head h3 { margin: 0; font-size: .8rem; color: var(--muted); }
.hud-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; }
.stat { background: var(--card-alt); border: 1px solid var(--line-light); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
.stat-total { border-color: #cbe6f0; }
.stat-label { font-size: .62rem; text-transform: uppercase; letter-spacing: .4px; color: var(--faint); font-weight: 700; }
.stat-val { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }
.stat-val.flash { animation: flash .5s ease-out; }
@keyframes flash { from { color: var(--brand); } to { color: var(--ink); } }
.stat-prev { font-size: .68rem; font-variant-numeric: tabular-nums; min-height: 1em; }
.stat-prev.better { color: var(--ok); } .stat-prev.worse { color: var(--err); }
.hud-turn { font-size: .74rem; color: var(--faint); font-family: var(--font-mono); }

.hidden { display: none !important; }
footer { text-align: center; color: var(--faint); font-size: .76rem; padding-top: 4px; line-height: 1.6; }
footer .by { color: var(--muted); font-weight: 700; }

/* ============================ iPhone / touch ============================ */
.app {
  padding-left: max(clamp(16px,4vw,32px), env(safe-area-inset-left));
  padding-right: max(clamp(16px,4vw,32px), env(safe-area-inset-right));
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  padding-top: max(20px, env(safe-area-inset-top));
}
.btn, .dev > summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
.transcript { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
@media (max-width: 560px) {
  .app { gap: 16px; }
  /* B5: the waveform hero costs ~110 px of the first screen on a 390x844
     iPhone. The orb gives it back (188->160) so "Connect & talk" stays above
     the fold; Sundae's face is still the second-largest thing on the page. */
  .orb-wrap { width: 160px; height: 160px; }
  .orb { width: 130px; height: 130px; }
  .face { width: 104px; height: 84px; }
  .presence { padding: 20px 18px 20px; gap: 13px; }
  .orb-sub { margin-top: -6px; }
  .transcript { max-height: 44vh; }
  .say-form input { font-size: 16px; }   /* stops iOS zoom-on-focus */
  .btn-primary { width: 100%; }
  /* The sleeping card replaces the sub-line's job on a phone, so it may be
     full width; the wake button follows the primary CTA's full-width rule
     because it IS the primary action while she is asleep. */
  .sleep-note { padding: 13px 13px 14px; gap: 8px; }
  .sn-body { font-size: .8rem; max-width: none; }
  .sn-safety { max-width: none; border-radius: 12px; }
  .btn-wake { width: 100%; }
  .zzz { top: 2%; right: 0; }
  .zzz span:nth-child(1) { font-size: .7rem; }
  .zzz span:nth-child(2) { font-size: .9rem; }
  .zzz span:nth-child(3) { font-size: 1.14rem; }
}
@media (pointer: coarse) {
  .btn { min-height: 46px; }
  .say-form input { min-height: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  .orb, .orb-ring, .eyes, .mouth, .bubble, .jump-latest { animation: none !important; transition: none !important; }
  /* Sleeping must still be UNMISTAKABLE without motion, so the state cues
     stay and only the motion is removed: closed eyes, the dim, the card and
     the z's all remain — the z's simply sit there instead of drifting, and
     the wake flourish becomes an instant, honest state change. */
  .zzz span, .sn-moon, .lids, .sleep-note, .presence::after, .presence::before {
    animation: none !important; transition: none !important;
  }
  .zzz span { opacity: .7; transform: none; }
}

/* ================== waveform hero integration (B5) ==================
 * The hero (waveform.css) is inserted between header.top and .stage. Three
 * things have to give way for it; nothing else in this file changes.
 *
 * 1. The page-level radial wash used to be the only thing at the top of the
 *    viewport. With a live ribbon there it competes, so pull it up and out of
 *    the hero's band — the ribbon supplies the colour now.
 * 2. On a 390x844 iPhone the hero costs ~120 px of the first screen (104 px
 *    of strip + a 16 px gap). The presence card gives that back by tightening
 *    its padding and shrinking the orb one step (188 -> 160).
 *    Layout sum at 390 px wide, from the top of the page to the bottom of
 *    "Connect & talk":
 *      20 app pad + 42 header + 16 gap + 104 hero + 16 gap
 *      + [20 pad + 160 orb + 13 + 22 status + 13 + 10 sub + 13] + 46 button
 *      = 495 px, against ~700 px of visible Safari viewport at 390x844.
 *    The CTA clears the fold with room to spare, and the hero is width:100%
 *    inside .app so nothing can introduce horizontal page scroll.
 *    (Arithmetic, not a browser measurement — confirm in device mode.)
 * 3. The hero must never be what a keyboard user tabs into — it is
 *    decoration with an aria-live label, no controls.
 */
body {
  background:
    radial-gradient(1000px 520px at 84% -22%, rgba(17,155,198,.09), transparent 62%),
    var(--bg);
}

.wf-hero { flex: none; }          /* .app is a flex column: never let it squash */

/* (2) is applied in the max-width:560px block above, next to the sizes it
 * overrides, rather than duplicated down here. */

/* ==================================================================
 * B3 — PROVENANCE STRIP, THE COMPUTED AWS BADGE, AND THE CONTROL PANEL
 * ==================================================================
 * Same tokens as everything above (--brand / --ink / --muted / --err …),
 * light only, iPhone-first. Nothing here is a custom widget: every control
 * the panel builds is a native <select>/<input>/<button> inside a real
 * <label>, so VoiceOver, keyboard focus and form semantics come for free and
 * cannot be broken by a future restyle.
 */

/* ---------------------------------------------------------- provenance */
.prov {
  background: var(--card); border: 1px solid var(--line-light);
  border-radius: 20px; box-shadow: var(--shadow-sm);
  padding: 16px 18px 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.prov-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.prov-head h2 { margin: 0; font-size: .95rem; }

/* The badge has exactly three looks and they must be unmistakable at a
   glance AND without colour: each carries its own leading glyph. */
.aws-badge {
  font-size: .74rem; font-weight: 800; letter-spacing: .01em;
  padding: 7px 13px; border-radius: 999px; border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: 7px; text-align: left;
}
.aws-badge::before { font-weight: 900; }
.aws-badge.badge-idle { color: var(--muted); background: #eaf1f5; border-color: var(--line-light); }
.aws-badge.badge-idle::before { content: "○"; }
.aws-badge.badge-ok  { color: var(--ok); background: var(--ok-light); border-color: #c6e9d4; }
.aws-badge.badge-ok::before { content: "✓"; }
.aws-badge.badge-bad { color: #fff; background: var(--err); border-color: var(--err); box-shadow: var(--shadow-md); }
.aws-badge.badge-bad::before { content: "!"; }

.prov-lanes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.prov-lane {
  display: grid; grid-template-columns: 42px auto 1fr; align-items: baseline; gap: 10px;
  padding: 8px 11px; border-radius: 12px;
  background: var(--card-alt); border: 1px solid var(--line-light);
}
.pl-stage {
  font-family: var(--font-mono); font-size: .64rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--faint);
}
.pl-win { font-weight: 800; font-size: .88rem; color: var(--ink); overflow-wrap: anywhere; }
.pl-where {
  font-size: .74rem; color: var(--muted); overflow-wrap: anywhere;
  display: inline-flex; align-items: baseline; gap: 6px;
}
/* The per-lane dot is the honest bit: it is drawn from where the winning rung
   actually ran, never from configuration. Shape backs up colour. */
.pl-where::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--faint); transform: translateY(-1px);
}
.prov-lane[data-where="aws-gpu"] { border-color: #cbe6f0; }
.prov-lane[data-where="aws-gpu"] .pl-where::before,
.prov-lane[data-where="aws-cpu"] .pl-where::before { background: var(--brand); }
.prov-lane[data-where="third-party"] { border-color: #f2cfcf; background: var(--err-light); }
.prov-lane[data-where="third-party"] .pl-where::before { background: var(--err); border-radius: 2px; }
.prov-lane[data-where="third-party"] .pl-where { color: var(--err); font-weight: 700; }
.prov-foot { margin: 0; font-size: .72rem; color: var(--faint); line-height: 1.5; }

/* ---------------------------------------------------------- the panel */
.panel {
  border: 1px solid var(--line-light); border-radius: 20px;
  background: var(--card); box-shadow: var(--shadow-sm); overflow: hidden;
}
.panel > summary {
  cursor: pointer; list-style: none; padding: 15px 18px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  min-height: 46px;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before { content: "▸"; color: var(--faint); transition: .2s; }
.panel[open] > summary::before { transform: rotate(90deg); }
.panel > summary:focus-visible { outline: 3px solid rgba(14,138,177,.4); outline-offset: -3px; }
.panel-title { font-family: var(--font-display); font-weight: 700; font-size: .95rem; color: var(--ink); }
.panel-sum-note { font-size: .72rem; color: var(--faint); font-weight: 700; margin-left: auto; }
.panel-sum-note.staged { color: var(--warn); }

.panel-body { padding: 0 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.panel-tabs { align-self: flex-start; max-width: 100%; overflow-x: auto; }
.panel-tabs .seg { min-height: 38px; }

/* One column on a phone, two once there is room. The rows are independent, so
   a plain grid is right — no row here needs to line up with its neighbour. */
.panel-rows { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .panel-rows { grid-template-columns: 1fr 1fr; } }
.panel-rows[hidden] { display: none; }

.prow {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px 13px; border-radius: 14px;
  background: var(--card-alt); border: 1px solid var(--line-light);
  position: relative;
}
.prow.wide { grid-column: 1 / -1; }
.prow-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.prow-label { font-weight: 700; font-size: .86rem; color: var(--ink); }
.prow-out {
  font-family: var(--font-mono); font-size: .76rem; font-weight: 700;
  color: var(--brand); font-variant-numeric: tabular-nums; margin-left: auto;
}
.prow-hint { font-size: .72rem; color: var(--muted); line-height: 1.45; }
.prow-hint.warn { color: var(--warn); font-weight: 700; }

/* Every row says where its value came from, so "why is it like that?" is
   always answerable without opening a console. */
.prow-src {
  font-size: .62rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--faint);
}
.prow-src[data-src="url"]   { color: var(--brand); }
.prow-src[data-src="saved"] { color: var(--muted); }
.prow-src[data-src="doll"]  { color: var(--ok); }

/* Apply feedback. LIVE rows tick; NEXT-CONNECT rows go amber and stay amber
   until the reconnect happens. A row the server refused says so in red. */
.prow[data-apply="applied"] { border-color: #c6e9d4; }
.prow[data-apply="applied"]::after {
  content: "✓ applied"; position: absolute; top: 9px; right: 11px;
  font-size: .64rem; font-weight: 800; color: var(--ok);
  animation: prowTick .6s ease-out;
}
@keyframes prowTick { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.prow[data-apply="staged"] { border-color: #f0dcb8; background: var(--warn-light); }
.prow[data-apply="staged"]::after {
  content: "reconnect to apply"; position: absolute; top: 9px; right: 11px;
  font-size: .64rem; font-weight: 800; color: var(--warn);
}
.prow[data-apply="local"]::after {
  content: "not confirmed"; position: absolute; top: 9px; right: 11px;
  font-size: .64rem; font-weight: 800; color: var(--faint);
}
.prow[data-apply="rejected"] { border-color: #f2cfcf; background: var(--err-light); }
.prow[data-apply="rejected"]::after {
  content: "refused"; position: absolute; top: 9px; right: 11px;
  font-size: .64rem; font-weight: 800; color: var(--err);
}
.prow[data-apply] .prow-head { padding-right: 96px; }

/* Native controls, sized for a thumb. */
.prow select, .prow input[type="text"] {
  font: inherit; font-family: var(--font-ui); font-size: 16px; /* no iOS zoom */
  min-height: 44px; width: 100%;
  padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.prow select:focus, .prow input[type="text"]:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,138,177,.15);
}
.prow input[type="range"] {
  width: 100%; min-height: 44px; accent-color: var(--brand);
  background: transparent; touch-action: manipulation;
}
.prow input[type="range"]:focus-visible { outline: 3px solid rgba(14,138,177,.4); outline-offset: 4px; }

/* A checkbox row is a 44px tappable label, not a 13px box with words next to it. */
.prow-check { display: flex; align-items: center; gap: 11px; min-height: 44px; cursor: pointer; }
.prow-check input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.prow-check span { font-weight: 700; font-size: .86rem; color: var(--ink); }

/* Segmented rows reuse the header's .seg-group so the panel and the STT
   selector are visibly the same control, not two dialects of one. */
.prow .seg-group { flex-wrap: wrap; }
.prow .seg { min-height: 38px; }

/* An engine row carries its own provenance dot: choosing Google or Edge is
   the one action on this page that can turn the badge red, and the row has to
   say so before the tap, not after. */
.prow-eng-note {
  font-size: .72rem; font-weight: 700; color: var(--err);
  background: var(--err-light); border: 1px solid #f2cfcf;
  border-radius: 10px; padding: 7px 10px; line-height: 1.45;
}
.prow-eng-note.ok { color: var(--ok); background: var(--ok-light); border-color: #c6e9d4; }

.panel-foot { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }
.panel-foot-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-sm { padding: 10px 16px; font-size: .82rem; min-height: 44px; }
.btn-reconnect {
  background: var(--warn); color: #fff; border-color: var(--warn); font-weight: 800;
  min-height: 46px;
}
.btn-reconnect:hover:not(:disabled) { color: #fff; border-color: var(--warn); filter: brightness(1.06); }
.panel-foot-note { margin: 0; font-size: .72rem; color: var(--faint); line-height: 1.5; }
.panel-foot-note em { color: var(--muted); font-style: normal; font-weight: 700; }

/* ---------------------------------------------------------- analytics shell
 * Mount points only — every chart inside is B4's (charts.js/charts.css). The
 * shell owns the card, the range filter and the overflow rule that keeps a
 * wide chart from making the whole PAGE scroll sideways on a phone. */
.analytics {
  background: var(--card); border: 1px solid var(--line-light);
  border-radius: 20px; box-shadow: var(--shadow-sm);
  padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 14px;
}
.an-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.an-head h2 { margin: 0; font-size: .95rem; }
.an-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 860px) { .an-grid { grid-template-columns: 1fr 1fr; } }
.an-mount:empty { display: none; }
.an-mount { overflow-x: auto; -webkit-overflow-scrolling: touch; }
#chart-kpi, #chart-provenance { grid-column: 1 / -1; }

@media (prefers-reduced-motion: reduce) {
  .prow[data-apply="applied"]::after { animation: none !important; }
}
@media (max-width: 560px) {
  .prov { padding: 14px 14px 12px; }
  .prov-lane { grid-template-columns: 38px 1fr; row-gap: 2px; }
  .prov-lane .pl-where { grid-column: 2; }
  .panel-body { padding: 0 13px 16px; }
  .analytics { padding: 14px 14px 16px; }
  .panel-foot-row .btn { flex: 1 1 auto; }
}
