/* =====================================================================
   House Hunt · Apple · voice input (deck fixes 2, 10 Oct 2026)
   ONE component for talking or typing to House Hunt: the mic, its
   recording state (pulsing red dot + timer, a halo that follows the
   voice), the level meter, the keyboard toggle, the text field and the
   buttons. Used by the brief screen (onboarding.js) and by the card's
   "Why this score?" comment (#csVoice). Markup + state: voice-input.js.

   It carries the onboarding "private office" palette under the token
   names onboarding.css gives its layers, so it looks the same on the deck
   (which keeps its own Apple tokens round it). Keep these values in step
   with the palette at the top of onboarding.css. States come from
   [data-vi] on the component root (voice-input.js ui.state()).
   ===================================================================== */

/* ---------------------------------------------------------------- palette (.vi-palette: a wrapper that wants it too,
   e.g. the deck's whole comment step, so its phrases and score pill sit in the same colours) */
.vi, .vi-palette {
  --bg: #f6f3ee;
  --bg-elev: #fffdf9;
  --label: #1c1a17;
  --label-2: #4d4740;
  --label-3: #6e675d;
  --sep: rgba(40, 33, 24, .13);
  --sep-2: rgba(40, 33, 24, .26);
  --fill: rgba(60, 48, 32, .065);
  --fill-2: rgba(60, 48, 32, .11);
  --tint: #8a6a3d;
  --tint-text: #7a5b33;
  --tint-soft: rgba(138, 106, 61, .12);
  --on-tint: #ffffff;
  --btn: #1c1a17;
  --on-btn: #f8f5ef;
  --focus: rgba(138, 106, 61, .62);
  --warn: #8f4a1f;
  --rec: #b8372d;
}
.vi {
  --lvl: 0;
  --vi-mic: 76px;        /* the mic's size; the icon and the rings scale with it */
  --vi-mic-i: 34px;
}
html[data-theme="dark"] :is(.vi, .vi-palette) {
  --bg: #12110f;
  --bg-elev: #1c1a17;
  --label: #f1ece4;
  --label-2: #c8c0b3;
  --label-3: #9c9488;
  --sep: rgba(241, 236, 228, .12);
  --sep-2: rgba(241, 236, 228, .24);
  --fill: rgba(241, 236, 228, .07);
  --fill-2: rgba(241, 236, 228, .12);
  --tint: #c8a46a;
  --tint-text: #d4b47e;
  --tint-soft: rgba(200, 164, 106, .16);
  --on-tint: #16140f;
  --btn: #efe8dc;
  --on-btn: #16140f;
  --focus: rgba(212, 180, 126, .72);
  --warn: #e0a070;
  --rec: #d9493d;
}
:is(.vi, .vi-palette) :focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* ---------------------------------------------------------------- the mic */
.vi-mic {
  position: relative; flex: none; width: var(--vi-mic); height: var(--vi-mic); padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; color: var(--on-btn); background: var(--btn);
  box-shadow: 0 calc(var(--vi-mic) * .24) calc(var(--vi-mic) * .45) calc(var(--vi-mic) * -.21) rgba(28, 20, 10, .75);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: transform .35s var(--spring), background-color .35s, box-shadow .3s, opacity .2s;
}
@media (hover: hover) { .vi-mic:hover:not(:disabled) { transform: scale(1.04); } }
.vi-mic:active:not(:disabled) { transform: scale(.95); }
.vi-mic:disabled { opacity: .8; }
.vi-mic > .i { grid-area: 1 / 1; position: relative; z-index: 1; transition: opacity .2s, transform .35s var(--spring); }
.vi-mic .vi-i-mic { width: var(--vi-mic-i); height: var(--vi-mic-i); stroke-width: 1.5; }
.vi-mic .vi-i-stop { width: calc(var(--vi-mic-i) * .88); height: calc(var(--vi-mic-i) * .88); opacity: 0; transform: scale(.5); }
/* idle: a fine bronze ring breathes round it */
.vi-breath { position: absolute; inset: calc(var(--vi-mic) * -.12); border-radius: 50%; box-shadow: inset 0 0 0 1px var(--tint); opacity: 0; pointer-events: none; }
.vi[data-vi="idle"] .vi-breath { animation: viBreathe 3.8s ease-in-out infinite; }
@keyframes viBreathe { 0%, 100% { transform: scale(.94); opacity: .2; } 50% { transform: scale(1.1); opacity: .85; } }
/* recording: a soft red halo that follows the voice */
.vi-halo {
  position: absolute; inset: calc(var(--vi-mic) * -.24); border-radius: 50%; pointer-events: none; opacity: 0;
  background: radial-gradient(circle, color-mix(in srgb, var(--rec) 34%, transparent), transparent 68%);
  transform: scale(calc(1 + var(--lvl) * .7)); transition: transform .09s linear, opacity .3s;
}
/* starting / finishing: a bronze arc runs round it */
.vi-ring { position: absolute; inset: calc(var(--vi-mic) * -.092); width: calc(100% + var(--vi-mic) * .184); height: calc(100% + var(--vi-mic) * .184); transform: rotate(-90deg); opacity: 0; pointer-events: none; }
.vi-ring circle { fill: none; stroke: var(--tint); stroke-width: 2.2; stroke-linecap: round; stroke-dasharray: 296; stroke-dashoffset: 220; }
.vi:is([data-vi="starting"], [data-vi="stopping"], [data-vi="sending"]) .vi-ring { opacity: 1; animation: viSpin 1.1s linear infinite; }
@keyframes viSpin { to { transform: rotate(360deg); } }
.vi:is([data-vi="rec"], [data-vi="paused"], [data-vi="stopping"], [data-vi="sending"]) .vi-mic {
  color: #fff; background: var(--rec); box-shadow: 0 calc(var(--vi-mic) * .24) calc(var(--vi-mic) * .45) calc(var(--vi-mic) * -.18) color-mix(in srgb, var(--rec) 80%, transparent);
}
.vi[data-vi="rec"] .vi-halo { opacity: 1; }
.vi:is([data-vi="rec"], [data-vi="paused"], [data-vi="stopping"], [data-vi="sending"]) .vi-mic .vi-i-mic { opacity: 0; transform: scale(.5); }
.vi:is([data-vi="rec"], [data-vi="paused"], [data-vi="stopping"], [data-vi="sending"]) .vi-mic .vi-i-stop { opacity: 1; transform: none; }

/* ---------------------------------------------------------------- the level meter: wave · ● REC · 0:00 */
.vi-meter { display: none; align-items: center; gap: 12px; width: 100%; height: 40px; min-width: 0; }
.vi:is([data-vi="rec"], [data-vi="paused"], [data-vi="stopping"], [data-vi="sending"]) .vi-meter { display: flex; animation: viIn .35s var(--spring); }
@keyframes viIn { from { opacity: 0; transform: scale(.94) translateY(-4px); } }
.vi-wave { display: block; flex: 1; min-width: 0; height: 100%; color: var(--tint); }
.vi-live { display: inline-flex; align-items: center; gap: 6px; flex: none; font: 700 11px/1 var(--font); letter-spacing: .12em; text-transform: uppercase; color: var(--rec); }
.vi-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 0 0 color-mix(in srgb, var(--rec) 55%, transparent); animation: viDot 1.4s ease-in-out infinite; }
@keyframes viDot { 0%, 100% { opacity: 1; box-shadow: 0 0 0 0 color-mix(in srgb, var(--rec) 50%, transparent); } 50% { opacity: .55; box-shadow: 0 0 0 6px color-mix(in srgb, var(--rec) 0%, transparent); } }
.vi[data-vi="paused"] .vi-live { color: var(--label-3); }
.vi:is([data-vi="paused"], [data-vi="stopping"], [data-vi="sending"]) .vi-dot { animation: none; background: var(--label-3); box-shadow: none; }
.vi[data-vi="paused"] .vi-word::after { content: " · paused"; letter-spacing: .06em; }
.vi-clock { min-width: 3.4em; font: 500 22px/1 var(--font); font-variant-numeric: tabular-nums; letter-spacing: -.01em; text-align: right; color: var(--label); }
.vi[data-vi="paused"] .vi-clock { color: var(--label-3); }

/* ---------------------------------------------------------------- round secondary buttons (Start again, Pause, keyboard) */
.vi-side {
  display: inline-flex; flex-direction: column; align-items: center; gap: 6px; padding: 0; border: 0; background: none;
  font: 500 12px/1.2 var(--font); color: var(--label-2); touch-action: manipulation; -webkit-tap-highlight-color: transparent; animation: viIn .35s var(--spring);
}
.vi-side[hidden] { display: none; }
.vi-side .i {
  width: 48px; height: 48px; padding: 14px; border-radius: 50%; color: var(--label); stroke-width: 1.8;
  box-shadow: inset 0 0 0 1px var(--sep-2); transition: transform .2s var(--spring), background-color .2s, color .2s, box-shadow .2s;
}
@media (hover: hover) { .vi-side:hover:not(:disabled) .i { background: var(--fill); } }
.vi-side:active:not(:disabled) .i { transform: scale(.92); }
.vi-side:disabled { opacity: .45; }
.vi-kb[aria-expanded="true"] .i { color: var(--tint-text); background: var(--tint-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tint) 50%, transparent); }

/* ---------------------------------------------------------------- the text field */
.vi-text {
  display: block; width: 100%; margin: 0; padding: 16px 18px; border: 0; border-radius: 18px; -webkit-appearance: none; appearance: none;
  font: inherit; font-size: 16px; line-height: 1.55; color: var(--label); background: var(--bg-elev);
  box-shadow: inset 0 0 0 1px var(--sep-2); transition: box-shadow .2s;
}
.vi-text::placeholder { color: var(--label-3); opacity: .85; }
.vi-text:focus { outline: none; box-shadow: inset 0 0 0 1.5px var(--tint), 0 0 0 4px var(--tint-soft); }

/* ---------------------------------------------------------------- words round it */
.vi-cap { min-height: 1.45em; font-size: 14px; line-height: 1.45; color: var(--label-2); }
.vi-status { margin: 0; font-size: 14px; line-height: 1.4; color: var(--label-2); }
.vi-status[hidden] { display: none; }
.vi-status.err { color: var(--warn); }
.vi .vox-retry { padding: 0 2px; color: var(--tint-text); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
/* "Type instead": an underlined quiet link with the keyboard */
.vi-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 14px; border-radius: 999px;
  font: 500 15px/1 var(--font); color: var(--label); text-decoration: underline; text-decoration-color: var(--sep-2); text-underline-offset: 5px;
  transition: background-color .2s;
}
.vi-link .i { width: 18px; height: 18px; color: var(--label-2); }
@media (hover: hover) { .vi-link:hover { background: var(--fill); } }

/* buttons: the deck's .btn / .btn-primary / .btn-plain take the brief screen's shape inside the component
   (onboarding.css: ".ob .btn, .vi .btn …"), coloured by the palette above. No hover look on touch screens: Android keeps
   :hover on whatever was last tapped, and Skip sits where Next was. */
@media (hover: none) { .vi .btn-plain:hover { background: transparent; } .vi .btn-primary:hover { background: var(--btn); } }

/* ---------------------------------------------------------------- compact: one row under a card (the comment) */
.vi-inline { --vi-mic: 56px; --vi-mic-i: 25px; display: flex; flex-direction: column; gap: 10px; }
.vi-inline .vi-field[hidden] { display: none; }
.vi-inline .vi-text { padding: 12px 16px; border-radius: 16px; line-height: 1.45; resize: none; }
.vi-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.vi-inline .vi-mic { margin: 7px 2px 7px 7px; }   /* room for the breathing ring */
.vi-inline > .vi-meter { height: 36px; }   /* while it listens: a full-width line over the mic, as on the brief screen */
.vi-inline .vi-clock { min-width: 2.6em; font-size: 20px; }
.vi-inline .vi-side .i { width: 46px; height: 46px; padding: 13px; }
.vi-gap { flex: 1 1 0; min-width: 0; }
/* while it listens the meter takes the room; only the mic and the save button stay beside it */
.vi-inline:is([data-vi="rec"], [data-vi="paused"], [data-vi="stopping"], [data-vi="sending"]) .vi-idle-only { display: none; }
.vi-inline:is([data-vi="rec"], [data-vi="paused"], [data-vi="stopping"], [data-vi="sending"]) .vi-row > .btn { flex: none; }

@media (prefers-reduced-motion: reduce) {
  .vi-breath { animation: none !important; opacity: .5 !important; transform: none !important; }
  .vi-dot { animation: none !important; }
  .vi-halo { transition: none !important; }
  .vi-meter, .vi-side { animation: none !important; }
}
