/* ==========================================================================
   ds/voice.css — «ds-voice», the voice field of the app and the site. Needs ds/tokens-core.css; driven by ds/voice.js.
   The design and motion of Comma's own composer dictation (iOS DictationGlassControl.swift, Android
   DictationCapsule.kt), measured from their source and re-drawn here in our own code (their code is AGPL-3.0; none
   of it is copied): ~/cnte/research/comma/ALGORITHM.md §3d.

   The field is the composer's one-row capsule: 44 pt high, fully round, white, a soft shadow (black 6 %, blur 10 pt,
   3 pt down). At its end: the mic (a 20-pt glyph in a 44-pt slot) and the send button (an 18-pt arrow on a 32-pt
   disc, grey until there is text, then THE red action).
     idle          the text (or the placeholder), the mic, the send
     listening     the waveform fills the capsule end to end (fades in 0.2 s); the mic fades out; a tap anywhere on
                   the capsule ends it (a press held ≥ 0.35 s on the mic ends it when it lifts)
     transcribing  «أكتب ما قلتِ…» in the tertiary grey + a spinner in the send corner (send hidden)
     result        the words appear grapheme by grapheme (150 ms each, 10 ms apart, ≤ 90 ms of stagger), send turns red
     error         one plain line in the field (no red flash)
   data-mode="loop": the 6-second picture loop of comma.surf's «Say it» tile (marketing), §3.
   Light only. RTL: built left-to-right and mirrored, so the mic and send sit at the line's end (the left), and the
   bars enter at that end and travel toward the words, as the original does in a left-to-right language.
   ========================================================================== */
.ds-voice{
  --pt:1px; --ds-voice-fade:.2s cubic-bezier(.4, 0, .2, 1);
  position:relative; direction:ltr; height:calc(44 * var(--pt)); border-radius:calc(22 * var(--pt));
  background:#FFFFFF; color:var(--fg-1); font-family:var(--font);
  box-shadow:0 calc(3 * var(--pt)) calc(10 * var(--pt)) #0000000F, inset 0 0 0 .5px #0000000F;
}
[dir="rtl"] .ds-voice{ scale:-1 1; }
[dir="rtl"] .ds-voice :is(.ds-voice-text, .ds-voice-note, .ds-voice-mic svg, .ds-voice-send svg){ scale:-1 1; }

/* the waveform (a canvas drawn by voice.js only while listening) */
.ds-voice-canvas{ position:absolute; inset:0; width:100%; height:100%; border-radius:inherit; opacity:0; pointer-events:none; transition:opacity var(--ds-voice-fade); }
.ds-voice[data-state="listening"] .ds-voice-canvas{ opacity:1; }
.ds-voice[data-state="listening"]{ cursor:pointer; }

/* the words, the transcribing note */
.ds-voice-text, .ds-voice-note{ position:absolute; top:0; bottom:0; left:calc(16 * var(--pt)); right:calc(88 * var(--pt)); display:flex; align-items:center; direction:rtl; overflow:hidden;
  font-size:calc(16 * var(--pt)); line-height:1.3; white-space:nowrap; }
.ds-voice-text{ color:var(--fg-1); }
.ds-voice-text:empty::before{ content:attr(data-placeholder); color:#8E8D88; }
.ds-voice-note{ color:var(--fg-3); font-size:calc(15 * var(--pt)); opacity:0; transition:opacity var(--ds-voice-fade); }
.ds-voice[data-state="transcribing"] .ds-voice-note{ opacity:1; }
.ds-voice:is([data-state="listening"], [data-state="transcribing"]) .ds-voice-text{ visibility:hidden; }
.ds-voice[data-state="error"] .ds-voice-text{ color:var(--fg-2); white-space:normal; font-size:calc(14 * var(--pt)); }
/* grapheme reveal: 16 solid steps from the field's white to the ink (no alpha on Arabic text) */
.ds-voice-text::highlight(dsv-0){ color:#F0F0F0; } .ds-voice-text::highlight(dsv-1){ color:#E1E1E1; } .ds-voice-text::highlight(dsv-2){ color:#D2D2D2; } .ds-voice-text::highlight(dsv-3){ color:#C3C3C3; }
.ds-voice-text::highlight(dsv-4){ color:#B4B4B4; } .ds-voice-text::highlight(dsv-5){ color:#A5A5A5; } .ds-voice-text::highlight(dsv-6){ color:#969696; } .ds-voice-text::highlight(dsv-7){ color:#878787; }
.ds-voice-text::highlight(dsv-8){ color:#787878; } .ds-voice-text::highlight(dsv-9){ color:#696969; } .ds-voice-text::highlight(dsv-10){ color:#5A5A5A; } .ds-voice-text::highlight(dsv-11){ color:#4B4B4B; }
.ds-voice-text::highlight(dsv-12){ color:#3C3C3C; } .ds-voice-text::highlight(dsv-13){ color:#2D2D2D; } .ds-voice-text::highlight(dsv-14){ color:#1E1E1E; } .ds-voice-text::highlight(dsv-15){ color:#161616; }

/* the mic: a 20-pt glyph centred in the 44-pt slot just before send */
.ds-voice-mic, .ds-voice-send{ position:absolute; top:0; display:grid; place-items:center; width:calc(44 * var(--pt)); height:calc(44 * var(--pt)); padding:0; border:0; background:none; color:var(--fg-1); cursor:pointer;
  transition:opacity var(--ds-voice-fade), scale .18s cubic-bezier(.22, 1, .36, 1); -webkit-tap-highlight-color:transparent; }
.ds-voice-mic{ right:calc(44 * var(--pt)); }
.ds-voice-mic svg{ width:calc(20 * var(--pt)); height:calc(20 * var(--pt)); }
.ds-voice-send{ right:0; }
.ds-voice-send > span{ display:grid; place-items:center; width:calc(32 * var(--pt)); height:calc(32 * var(--pt)); border-radius:50%; background:#B6B8BB; color:#FFFFFF; transition:background-color var(--ds-voice-fade); }
.ds-voice-send svg{ width:calc(18 * var(--pt)); height:calc(18 * var(--pt)); }
.ds-voice[data-state="result"] .ds-voice-send > span{ background:var(--accent); }
.ds-voice-mic:active, .ds-voice-send:active{ scale:.92; transition-duration:.12s; }
.ds-voice:is([data-state="listening"], [data-state="transcribing"]) .ds-voice-mic{ opacity:0; pointer-events:none; }
.ds-voice:is([data-state="listening"], [data-state="transcribing"]) .ds-voice-send{ opacity:0; pointer-events:none; }
/* the spinner of «transcribing»: an 18-pt ring in the send corner */
.ds-voice-spin{ position:absolute; top:calc(13 * var(--pt)); right:calc(13 * var(--pt)); width:calc(18 * var(--pt)); height:calc(18 * var(--pt)); border-radius:50%; box-sizing:border-box;
  border:calc(2 * var(--pt)) solid #E4E3DE; border-top-color:var(--fg-3); opacity:0; transition:opacity var(--ds-voice-fade); }
.ds-voice[data-state="transcribing"] .ds-voice-spin{ opacity:1; animation:ds-voice-spin .8s linear infinite; }
@keyframes ds-voice-spin{ to{ rotate:360deg; } }

/* inside a drawn phone the field follows the screen's unit */
.ui-phone-screen .ds-voice{ --pt:calc(100cqw / 390); }

/* ---- the 6-second picture loop of comma.surf's «Say it» tile (ALGORITHM.md §3) ---- */
.ds-voice[data-mode="loop"]{ --rest:2.31; --mic-size:calc(36 * var(--pt)) calc(36 * var(--pt)); --mic-at:calc(216 * var(--pt)) calc(4 * var(--pt)); --whole-size:calc(1200 * var(--pt)) calc(240 * var(--pt)); --whole-at:calc(-366 * var(--pt)) calc(-98 * var(--pt)); }
.ds-voice[data-mode="loop"] :is(.ds-voice-text, .ds-voice-note, .ds-voice-spin, .ds-voice-canvas){ display:none; }
.dsv-wave{ position:absolute; top:0; right:0; width:calc(300 * var(--pt)); height:100%; overflow:hidden; color:var(--fg-1); border-radius:0 calc(22 * var(--pt)) calc(22 * var(--pt)) 0;
  -webkit-mask-image:linear-gradient(to left, transparent calc(6 * var(--pt)), #000 calc(8 * var(--pt))); mask-image:linear-gradient(to left, transparent calc(6 * var(--pt)), #000 calc(8 * var(--pt))); }
.dsv-lens{ position:absolute; inset:0; -webkit-mask-image:radial-gradient(closest-side, #000 60%, #0000); mask-image:radial-gradient(closest-side, #000 60%, #0000); -webkit-mask-repeat:no-repeat; mask-repeat:no-repeat;
  -webkit-mask-size:var(--whole-size); mask-size:var(--whole-size); -webkit-mask-position:var(--whole-at); mask-position:var(--whole-at); }
.dsv-strip{ position:absolute; top:0; bottom:0; left:100%; translate:calc(var(--rest) * -50 * var(--pt)) 0; }
.dsv-strip::before{ content:""; position:absolute; top:50%; right:0; width:calc(120 * 5.5 * var(--pt)); height:calc(2.5 * var(--pt)); margin-top:calc(-1.25 * var(--pt));
  background:radial-gradient(circle at calc(1.25 * var(--pt)) 50%, #B9B9B9 calc(1.25 * var(--pt) - .5px), transparent calc(1.25 * var(--pt))) 0 0 / calc(5.5 * var(--pt)) 100%; }
.dsv-strip > i{ position:absolute; top:50%; left:calc(var(--c) * 5.5 * var(--pt)); width:calc(2.5 * var(--pt)); height:calc(var(--h) * var(--pt)); border-radius:calc(1.25 * var(--pt)); background:currentColor; translate:0 -50%; }
.ds-voice[data-mode="loop"] :is(.ds-voice-mic, .ds-voice-send){ opacity:0; transition:none; pointer-events:none; width:auto; height:auto; }
.ds-voice[data-mode="loop"] .ds-voice-mic{ top:calc(12 * var(--pt)); right:calc(56 * var(--pt)); }
.ds-voice[data-mode="loop"] .ds-voice-send{ top:calc(6 * var(--pt)); right:calc(6 * var(--pt)); scale:.92; }
[data-scene-playing] .ds-voice[data-mode="loop"] .dsv-strip{ animation:dsv-strip 6s linear calc(var(--rest) * -1s) infinite; }
[data-scene-playing] .ds-voice[data-mode="loop"] .dsv-strip > i{ animation:dsv-grow 6s linear calc(((var(--c) + 1) * .11 - var(--rest)) * 1s) infinite; }
[data-scene-playing] .ds-voice[data-mode="loop"] .dsv-wave{ animation:dsv-wave 6s linear calc(var(--rest) * -1s) infinite; }
[data-scene-playing] .ds-voice[data-mode="loop"] .dsv-lens{ animation:dsv-open 6s linear calc(var(--rest) * -1s) infinite; }
[data-scene-playing] .ds-voice[data-mode="loop"] .ds-voice-mic{ animation:dsv-mic 6s linear calc(var(--rest) * -1s) infinite; }
[data-scene-playing] .ds-voice[data-mode="loop"] .ds-voice-send{ animation:dsv-send 6s linear calc((.06 - var(--rest)) * 1s) infinite; }
@keyframes dsv-strip{ from{ translate:0 0; } to{ translate:calc(-300 * var(--pt)) 0; } }
@keyframes dsv-grow{ 0%{ height:calc(2.5 * var(--pt)); animation-timing-function:cubic-bezier(.3333, 0, .6667, 1); } 11.67%, 100%{ height:calc(var(--h) * var(--pt)); } }
@keyframes dsv-open{
  0%, 1%{ -webkit-mask-position:var(--mic-at); mask-position:var(--mic-at); -webkit-mask-size:var(--mic-size); mask-size:var(--mic-size); animation-timing-function:cubic-bezier(.32, .72, 0, 1); }
  7.67%, 73.33%{ -webkit-mask-position:var(--whole-at); mask-position:var(--whole-at); -webkit-mask-size:var(--whole-size); mask-size:var(--whole-size); animation-timing-function:cubic-bezier(.32, .72, 0, 1); }
  78.33%, 100%{ -webkit-mask-position:var(--mic-at); mask-position:var(--mic-at); -webkit-mask-size:var(--mic-size); mask-size:var(--mic-size); } }
@keyframes dsv-wave{ 0%, 1%{ opacity:0; animation-timing-function:cubic-bezier(.22, 1, .36, 1); } 4.33%, 73.33%{ opacity:1; animation-timing-function:ease; } 78%, 100%{ opacity:0; } }
@keyframes dsv-mic{ 0%{ opacity:1; filter:blur(0); scale:.9; animation-timing-function:cubic-bezier(.22, 1, .36, 1); } 2.5%, 75%{ opacity:0; filter:blur(calc(2 * var(--pt))); scale:.85; animation-timing-function:cubic-bezier(.22, 1, .36, 1); } 80%{ opacity:1; filter:blur(0); scale:1; } 97.5%{ scale:1; animation-timing-function:cubic-bezier(.22, 1, .36, 1); } 100%{ opacity:1; filter:blur(0); scale:.9; } }
@keyframes dsv-send{ 0%{ opacity:1; filter:blur(0); scale:.92; animation-timing-function:cubic-bezier(.22, 1, .36, 1); } 2.5%, 75%{ opacity:0; filter:blur(calc(2 * var(--pt))); scale:.8; animation-timing-function:cubic-bezier(.22, 1, .36, 1); } 80%, 100%{ opacity:1; filter:blur(0); scale:.92; } }

@media (prefers-reduced-motion:reduce){
  .ds-voice, .ds-voice *{ transition:none !important; }
  .ds-voice[data-mode="loop"] *{ animation:none !important; }
  .ds-voice[data-state="transcribing"] .ds-voice-spin{ animation:none; }
}

.app-actions .ds-voice[data-state="result"] .ds-voice-send > span{ background:var(--action); color:#fff; }
.app-actions .ds-voice[data-state="result"] .ds-voice-send:is(:hover, :active) > span{ background:var(--action-press); }
