@spectosh/browser 0.2.5 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,859 @@
1
+ // Point — the cursor mode (VISION.md §4). Instead of a corner bubble and a
2
+ // form, the person points at what is wrong in the running app: the cursor
3
+ // turns into a ring, whatever is under it is outlined with its name, a click
4
+ // pins a numbered marker, a drag frames a region, and — when the project
5
+ // allows it — they talk while they do it. Send, and Specto files a bug with
6
+ // everything an engineer or a coding agent needs (describe.js, context.js).
7
+ //
8
+ // States (the ring shows which): armed (grey ring: elements outline as you
9
+ // move) → marking (coloured ring, the next marker's number) — listening (the
10
+ // ring pulses with your voice) — flow (red dot: the page works normally while
11
+ // a stretch of the recording is bracketed; F again ends it).
12
+ //
13
+ // Keys while open: click to mark · drag to frame · click a marker's number to
14
+ // change its flag · F flow · M microphone · Backspace removes the last marker
15
+ // · Enter sends · ? how it works · Esc leaves (twice when markers exist).
16
+ //
17
+ // Voice (§4.6), when the project has it: the first time, the rail explains
18
+ // it and *Start talking* asks for the microphone; after a yes it starts by
19
+ // itself whenever Point opens. Words come back phrase by phrase (voice.js)
20
+ // and land on the marker that was current, in its note, editable until
21
+ // Send. Typing — or a no to the microphone — switches to the note field.
22
+ //
23
+ // Everything Point draws lives in one shadow root inside a zero-size host
24
+ // with `specto-block`, so the recording never shows it and the page's CSS
25
+ // never reaches it. The page gets none of the clicks Point takes.
26
+ import { describe, chipOf, componentOf, accessibleName, isMasked } from './describe.js'
27
+ import { contextFor, environment } from './context.js'
28
+ import { startVoice, voiceSupported, base64Of } from './voice.js'
29
+ import { keyCaps, capsHtml, keepReceipt, dropReceipt } from './entry.js'
30
+
31
+ export { mountEntry, showFixed } from './entry.js'
32
+ export const FLAGS = ['broken', 'wrong', 'slow', 'confusing', 'idea']
33
+ const VOICE_KEY = 'specto-point-voice' // 'yes' | 'no': the answer to the first-time card
34
+ const SENT_KEY = 'specto-point-sent' // reports sent on this device (teach the shortcut twice)
35
+ const USED_KEY = 'specto-point-used' // ever opened (the reminder stops)
36
+ const TEACH_TIMES = 2
37
+ const PENDING_WAIT_MS = 6000
38
+ const CIRCLED = ['', '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩']
39
+ const MIC_SVG = '<svg viewBox="0 0 18 18" aria-hidden="true"><rect x="6.5" y="2" width="5" height="9" rx="2.5"/><path d="M3.5 8.5a5.5 5.5 0 0 0 11 0M9 14v2.5"/></svg>'
40
+ const CHECK_SVG = '<svg viewBox="0 0 12 12" aria-hidden="true"><path d="M2.5 6.2 5 8.5 9.5 3.5"/></svg>'
41
+ const local = {
42
+ get: (k) => { try { return localStorage.getItem(k) } catch { return null } },
43
+ set: (k, v) => { try { localStorage.setItem(k, v) } catch { /* private mode */ } },
44
+ }
45
+ const FLAG_COLOR = { broken: '#F43F5E', wrong: '#F59E0B', slow: '#8B5CF6', confusing: '#0EA5E9', idea: '#10B981' }
46
+ const FLAG_LABEL = { broken: 'Broken', wrong: 'Wrong', slow: 'Slow', confusing: 'Confusing', idea: 'Idea' }
47
+ const HOWTO_KEY = 'specto-point-howto'
48
+ const MAX_MARKERS = 20
49
+ const DRAG_PX = 8
50
+ const TRIGGER_WORDS = {
51
+ 'double-ctrl': 'Double-tap Ctrl',
52
+ 'hold-alt': 'Hold Alt',
53
+ 'hold-ctrl': 'Hold Ctrl',
54
+ chord: 'Alt + Shift + P',
55
+ }
56
+
57
+ const BLOCKED = ['pointerdown', 'pointerup', 'mousedown', 'mouseup', 'click', 'dblclick', 'auxclick', 'contextmenu', 'touchstart', 'touchend']
58
+
59
+ export function openPoint(rec, cfg = {}) {
60
+ if (document.getElementById('specto-point')) return null
61
+ const p = rec._point
62
+ const strict = () => p.strict()
63
+ const unmask = () => p.unmask?.() || ''
64
+ const markers = [] // { n, el, kind, flag, note, at, desc, ctx, region }
65
+ let state = 'armed' // armed | marking | flow | sent
66
+ let hover = null
67
+ let down = null // { x, y, el, region }
68
+ let flow = null // { start, end }
69
+ let voice = null // the running recording
70
+ let audio = null // { blob, mime, startedAt } once stopped — only when it may be kept
71
+ let live = null // { startedAt } once the person talked
72
+ let pending = 0 // phrases still being turned into words
73
+ const timeline = [] // [{ at, marker }] — which marker was current from when
74
+ let currentMarker = 0
75
+ let escArmed = false
76
+ let sending = false
77
+ let raf = 0
78
+ let closed = false
79
+ let howtoShown = false
80
+
81
+ // ---- the host + shadow root -------------------------------------------
82
+ const host = document.createElement('div')
83
+ host.id = 'specto-point'
84
+ host.className = 'specto-block'
85
+ host.setAttribute('style', 'all:initial;position:fixed;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483646')
86
+ const root = host.attachShadow({ mode: 'open' })
87
+ root.innerHTML = `<style>${CSS}</style>
88
+ <div class="ring" data-state="armed" aria-hidden="true"><span class="badge"></span><span class="dot"></span></div>
89
+ <div class="outline" aria-hidden="true"><span class="chip"></span></div>
90
+ <div class="frame" aria-hidden="true"></div>
91
+ <div class="marks"></div>
92
+ <section class="rail" role="region" aria-label="Specto Point — report what is wrong">
93
+ <header><b>Point</b><span class="hint"></span><button class="x" aria-label="Leave Point" title="Leave (Esc)">×</button></header>
94
+ <ol class="list"></ol>
95
+ <p class="empty">Click what is wrong. Drag to frame an area.</p>
96
+ <div class="vcard" hidden>
97
+ <b>Tell us like you’d tell a friend</b>
98
+ <p>Point at things and just talk: “this button does nothing”. Your words show up here as you go.</p>
99
+ <p class="fine">Your browser will ask to use the microphone. We only turn your voice into text; the recording is deleted.</p>
100
+ <button class="vstart" type="button">${MIC_SVG}Start talking</button>
101
+ <p class="fine c">Rather type? Just start typing.</p>
102
+ </div>
103
+ <div class="listening" hidden>
104
+ <div class="lh"><span class="rd" aria-hidden="true"></span>Listening<span class="bars" aria-hidden="true"><i></i><i></i><i></i><i></i><i></i></span></div>
105
+ <p class="cap" aria-live="polite"></p>
106
+ <p class="fine">Each phrase shows up a moment after you pause, on the marker you were pointing at.</p>
107
+ </div>
108
+ <details class="exp"><summary>Expected / what happened</summary>
109
+ <input class="expected" maxlength="500" placeholder="What did you expect?" aria-label="What did you expect?">
110
+ <input class="actual" maxlength="500" placeholder="What happened instead?" aria-label="What happened instead?">
111
+ </details>
112
+ <label class="keep" hidden><input type="checkbox"> Also send my voice recording (kept 30 days)</label>
113
+ <button class="flowbtn" type="button" title="F — use the page normally while Specto brackets this stretch of the recording">Record a flow</button>
114
+ <div class="row bottom">
115
+ <button class="mic" type="button" hidden aria-label="Talk" title="M — talk instead of typing; your words appear as you go">${MIC_SVG}</button>
116
+ <button class="typei" type="button" hidden>Type instead</button>
117
+ <button class="send" type="button" disabled>Send</button>
118
+ </div>
119
+ <p class="status" role="status" aria-live="polite"></p>
120
+ </section>
121
+ <div class="howto" hidden role="dialog" aria-label="How Point works"></div>`
122
+ const $ = (s) => root.querySelector(s)
123
+ const ring = $('.ring')
124
+ const outline = $('.outline')
125
+ const frame = $('.frame')
126
+ const marks = $('.marks')
127
+ const rail = $('.rail')
128
+ const list = $('.list')
129
+ const statusEl = $('.status')
130
+ const hint = $('.hint')
131
+ document.documentElement.appendChild(host)
132
+ const style = document.createElement('style')
133
+ style.id = 'specto-point-cursor'
134
+ style.textContent = 'html.specto-point-on,html.specto-point-on *{cursor:none!important}'
135
+ document.head?.appendChild(style)
136
+ const setCursorHidden = (on) => document.documentElement.classList.toggle('specto-point-on', on)
137
+ setCursorHidden(true)
138
+ p.active(true)
139
+
140
+ const inOurs = (e) => e.composedPath?.().includes(host)
141
+ const say = (msg, bad) => { statusEl.textContent = msg || ''; statusEl.classList.toggle('bad', Boolean(bad)) }
142
+
143
+ // ---- state ---------------------------------------------------------------
144
+ function setState(s) {
145
+ state = s
146
+ ring.dataset.state = voice ? `${s} listening` : s
147
+ const pass = s === 'flow'
148
+ setCursorHidden(!pass && s !== 'sent')
149
+ p.active(!pass && s !== 'sent')
150
+ outline.style.display = pass ? 'none' : ''
151
+ hint.textContent = s === 'flow' ? 'Use the page — F ends the flow' : 'Esc to cancel'
152
+ $('.flowbtn').textContent = flow && !flow.end ? 'End the flow' : flow?.end ? 'Flow recorded ✓' : 'Record a flow'
153
+ $('.flowbtn').classList.toggle('on', s === 'flow')
154
+ $('.send').disabled = sending || !(markers.length || flow?.end || $('.expected').value.trim() || $('.actual').value.trim())
155
+ $('.empty').hidden = markers.length > 0
156
+ ring.querySelector('.badge').textContent = s === 'marking' || s === 'armed' ? String(markers.length + 1) : ''
157
+ }
158
+
159
+ function setCurrent(n) {
160
+ if (n === currentMarker) return
161
+ // the phrase being said belongs to the marker it started on: end it here
162
+ if (voice) { voice.cut(); timeline.push({ at: Date.now(), marker: n }) }
163
+ currentMarker = n
164
+ }
165
+
166
+ // ---- markers --------------------------------------------------------------
167
+ function addMarker(el, region) {
168
+ if (markers.length >= MAX_MARKERS) { say(`At most ${MAX_MARKERS} markers in one report`, true); return }
169
+ offerVoice()
170
+ const at = Date.now()
171
+ const desc = describe(el, { strict: strict(), unmask: unmask() })
172
+ const ctx = contextFor({ recent: p.recent(), contains: (c) => el === c || el.contains(c) || c.contains?.(el), now: at })
173
+ const m = {
174
+ n: markers.length + 1, el, kind: region ? 'region' : 'element', flag: 'broken', note: '', at, desc, ctx,
175
+ region: region ? { x: region.x + scrollX, y: region.y + scrollY, w: region.w, h: region.h } : null,
176
+ }
177
+ if (region) m.desc.rect = { x: Math.round(region.x), y: Math.round(region.y), w: Math.round(region.w), h: Math.round(region.h) }
178
+ markers.push(m)
179
+ setCurrent(m.n)
180
+ renderList()
181
+ setState('marking')
182
+ if (!railPlaced) dodge(el, region)
183
+ }
184
+ // the panel covers what was marked → it goes to the other side
185
+ function dodge(el, region) {
186
+ if (innerWidth <= 560) return // a bottom sheet there: nothing to dodge sideways
187
+ let r
188
+ try { r = region || el.getBoundingClientRect() } catch { return }
189
+ const p = rail.getBoundingClientRect()
190
+ const over = r.x < p.right && r.x + (r.w ?? r.width) > p.left && r.y < p.bottom && r.y + (r.h ?? r.height) > p.top
191
+ if (over) rail.classList.toggle('left')
192
+ }
193
+ function removeMarker(i) {
194
+ markers.splice(i, 1)
195
+ markers.forEach((m, j) => { m.n = j + 1 })
196
+ setCurrent(markers.length ? markers[markers.length - 1].n : 0)
197
+ renderList()
198
+ setState(markers.length ? 'marking' : 'armed')
199
+ }
200
+ const cycleFlag = (m) => { m.flag = FLAGS[(FLAGS.indexOf(m.flag) + 1) % FLAGS.length]; renderList() }
201
+
202
+ function renderList() {
203
+ list.replaceChildren(...markers.map((m, i) => {
204
+ const li = document.createElement('li')
205
+ li.innerHTML = `<button class="num" type="button" title="Change the flag" style="--c:${FLAG_COLOR[m.flag]}">${m.n}</button>
206
+ <span class="what"><span class="name"></span><button class="flag" type="button" style="--c:${FLAG_COLOR[m.flag]}">${FLAG_LABEL[m.flag]}</button></span>
207
+ <textarea class="note" rows="1" maxlength="1000" placeholder="${voice ? 'Talk, or type here' : 'Note (optional)'}" aria-label="Note for marker ${m.n}"></textarea>
208
+ <button class="rm" type="button" aria-label="Remove marker ${m.n}">×</button>`
209
+ li.dataset.n = String(m.n)
210
+ li.querySelector('.name').textContent = m.desc.component ? `${m.desc.component} · ${m.desc.name}` : m.desc.name
211
+ li.querySelector('.note').value = m.note
212
+ li.querySelector('.note').addEventListener('input', (e) => { m.note = e.target.value })
213
+ li.querySelector('.note').addEventListener('focus', () => setCurrent(m.n))
214
+ li.querySelector('.num').addEventListener('click', () => cycleFlag(m))
215
+ li.querySelector('.flag').addEventListener('click', () => cycleFlag(m))
216
+ li.querySelector('.rm').addEventListener('click', () => removeMarker(i))
217
+ li.addEventListener('pointerenter', () => setCurrent(m.n))
218
+ return li
219
+ }))
220
+ marks.replaceChildren(...markers.map((m) => {
221
+ const d = document.createElement('div')
222
+ d.className = `mk ${m.kind}`
223
+ d.style.setProperty('--c', FLAG_COLOR[m.flag])
224
+ d.innerHTML = `<button class="pin" type="button" aria-label="Marker ${m.n}: ${FLAG_LABEL[m.flag]} — click to change">${m.n}</button>`
225
+ d.querySelector('.pin').addEventListener('click', (e) => { e.stopPropagation(); cycleFlag(m) })
226
+ m.node = d
227
+ return d
228
+ }))
229
+ place()
230
+ }
231
+
232
+ // keep markers on their elements while the page scrolls or moves
233
+ function place() {
234
+ for (const m of markers) {
235
+ if (!m.node) continue
236
+ let r
237
+ if (m.region) r = { left: m.region.x - scrollX, top: m.region.y - scrollY, width: m.region.w, height: m.region.h }
238
+ else { try { r = m.el.getBoundingClientRect() } catch { r = null } }
239
+ if (!r || (!m.region && !m.el.isConnected)) { m.node.style.display = 'none'; continue }
240
+ m.node.style.display = ''
241
+ m.node.style.transform = `translate(${r.left}px, ${r.top}px)`
242
+ m.node.style.width = `${Math.max(4, r.width)}px`
243
+ m.node.style.height = `${Math.max(4, r.height)}px`
244
+ }
245
+ }
246
+ const loop = () => {
247
+ if (closed) return
248
+ place()
249
+ if (voice) { const lv = voice.level(); ring.style.setProperty('--lv', lv.toFixed(2)); $('.bars').style.setProperty('--lv', Math.min(1, lv * 2.5).toFixed(2)) }
250
+ raf = requestAnimationFrame(loop)
251
+ }
252
+ raf = requestAnimationFrame(loop)
253
+
254
+ // ---- pointer ---------------------------------------------------------------
255
+ const under = (x, y) => {
256
+ const el = document.elementFromPoint(x, y)
257
+ return el && el !== host && el !== document.documentElement ? el : null
258
+ }
259
+ function showOutline(el) {
260
+ if (!el) { outline.style.opacity = '0'; return }
261
+ let r
262
+ try { r = el.getBoundingClientRect() } catch { return }
263
+ outline.style.opacity = '1'
264
+ outline.style.transform = `translate(${r.left}px, ${r.top}px)`
265
+ outline.style.width = `${r.width}px`
266
+ outline.style.height = `${r.height}px`
267
+ if (hover !== el) {
268
+ const masked = isMasked(el, strict(), unmask())
269
+ const { component } = componentOf(el)
270
+ const label = chipOf(el, { component, name: accessibleName(el, masked).slice(0, 30) })
271
+ outline.querySelector('.chip').textContent = label
272
+ outline.classList.toggle('below', r.top < 24)
273
+ }
274
+ }
275
+ const onMove = (e) => {
276
+ ring.style.transform = `translate(${e.clientX}px, ${e.clientY}px)`
277
+ ring.classList.add('seen')
278
+ if (state === 'flow' || state === 'sent') return
279
+ if (inOurs(e)) { showOutline(null); hover = null; return }
280
+ if (down && (Math.abs(e.clientX - down.x) > DRAG_PX || Math.abs(e.clientY - down.y) > DRAG_PX)) {
281
+ down.region = { x: Math.min(down.x, e.clientX), y: Math.min(down.y, e.clientY), w: Math.abs(e.clientX - down.x), h: Math.abs(e.clientY - down.y) }
282
+ Object.assign(frame.style, { display: 'block', transform: `translate(${down.region.x}px, ${down.region.y}px)`, width: `${down.region.w}px`, height: `${down.region.h}px` })
283
+ showOutline(null)
284
+ return
285
+ }
286
+ const el = under(e.clientX, e.clientY)
287
+ showOutline(el)
288
+ hover = el
289
+ const onMarker = el && markers.find((m) => m.el === el || m.el.contains?.(el))
290
+ if (onMarker) setCurrent(onMarker.n)
291
+ }
292
+ const block = (e) => {
293
+ if (closed || state === 'flow' || state === 'sent' || inOurs(e)) return
294
+ e.preventDefault()
295
+ e.stopImmediatePropagation()
296
+ if (e.type === 'pointerdown' && e.button === 0) down = { x: e.clientX, y: e.clientY, el: under(e.clientX, e.clientY), region: null }
297
+ if (e.type === 'pointerup' && down) {
298
+ const d = down
299
+ down = null
300
+ frame.style.display = 'none'
301
+ if (d.region && d.region.w > DRAG_PX && d.region.h > DRAG_PX) {
302
+ const cx = d.region.x + d.region.w / 2
303
+ const cy = d.region.y + d.region.h / 2
304
+ addMarker(under(cx, cy) || document.body, d.region)
305
+ } else if (d.el) addMarker(d.el, null)
306
+ }
307
+ }
308
+
309
+ // ---- keys -------------------------------------------------------------------
310
+ const typing = (e) => {
311
+ const t = e.composedPath?.()[0]
312
+ return t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA') && inOurs(e)
313
+ }
314
+ const onKey = (e) => {
315
+ if (closed || state === 'sent') return
316
+ if (typing(e)) { if (e.key === 'Escape') { e.target.blur?.(); rail.focus?.() } else if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send() } return }
317
+ const k = e.key
318
+ // while the voice card shows or the microphone listens, any letter means
319
+ // "I'd rather type" (so F and M type too)
320
+ if ((!vcard.hidden || voice) && k.length === 1 && k !== '?' && !e.ctrlKey && !e.metaKey && !e.altKey && state !== 'flow') { typeInstead(e); return }
321
+ // Ctrl/⌘+A would select the whole page and Point's own text, and a click
322
+ // can't clear it while Point holds the clicks: not while Point is open
323
+ if ((e.ctrlKey || e.metaKey) && (k === 'a' || k === 'A')) { e.preventDefault(); return }
324
+ const mine = ['Escape', 'Enter', 'Backspace', 'f', 'F', 'm', 'M', '?', 'Tab']
325
+ if (!mine.includes(k)) return
326
+ if (state === 'flow' && !['f', 'F', 'Escape'].includes(k)) return
327
+ e.preventDefault()
328
+ e.stopImmediatePropagation()
329
+ if (k === 'Escape') {
330
+ if (state === 'flow') { endFlow(); return }
331
+ if (markers.length && !escArmed) { escArmed = true; say('Press Esc again to discard this report'); setTimeout(() => { escArmed = false }, 3000); return }
332
+ close()
333
+ } else if (k === 'Enter') {
334
+ if (hover && !markers.some((m) => m.el === hover) && focusWalk.active) addMarker(hover, null)
335
+ else send()
336
+ } else if (k === 'Backspace') { if (markers.length) removeMarker(markers.length - 1) }
337
+ else if (k === 'f' || k === 'F') { state === 'flow' ? endFlow() : startFlow() }
338
+ else if (k === 'm' || k === 'M') toggleMic()
339
+ else if (k === '?') showHowto(true)
340
+ else if (k === 'Tab') focusWalk.next(e.shiftKey)
341
+ }
342
+ // keyboard-only marking: Tab walks the page's focusable elements, Enter pins
343
+ const focusWalk = {
344
+ active: false, i: -1,
345
+ next(back) {
346
+ const els = Array.from(document.querySelectorAll('a[href],button,input,select,textarea,summary,[tabindex]:not([tabindex="-1"]),[role=button],[role=link]'))
347
+ .filter((el) => { const r = el.getBoundingClientRect(); return r.width > 0 && r.height > 0 && !host.contains(el) })
348
+ if (!els.length) return
349
+ this.active = true
350
+ this.i = (this.i + (back ? -1 : 1) + els.length) % els.length
351
+ hover = els[this.i]
352
+ try { hover.scrollIntoView({ block: 'nearest' }) } catch { /* old engines */ }
353
+ showOutline(hover)
354
+ },
355
+ }
356
+
357
+ // ---- flow ----------------------------------------------------------------------
358
+ function startFlow() {
359
+ if (flow?.end) flow = null
360
+ flow = { start: Date.now(), end: null }
361
+ showOutline(null)
362
+ setState('flow')
363
+ tickFlow()
364
+ }
365
+ function endFlow() {
366
+ if (!flow || flow.end) return
367
+ flow.end = Date.now()
368
+ setState(markers.length ? 'marking' : 'armed')
369
+ say(`Flow recorded (${Math.round((flow.end - flow.start) / 1000)} s)`)
370
+ }
371
+ function tickFlow() {
372
+ if (closed || !flow || flow.end) return
373
+ const s = Math.round((Date.now() - flow.start) / 1000)
374
+ hint.textContent = `Recording the flow ${String(Math.floor(s / 60)).padStart(2, '0')}:${String(s % 60).padStart(2, '0')} — F ends it`
375
+ setTimeout(tickFlow, 500)
376
+ }
377
+
378
+ // ---- voice -----------------------------------------------------------------------
379
+ const mic = $('.mic')
380
+ const vcard = $('.vcard')
381
+ const canTalk = Boolean(cfg.voice) && voiceSupported()
382
+ const lang = cfg.voiceLang && cfg.voiceLang !== 'auto' ? cfg.voiceLang : String(navigator.language || '').slice(0, 2).toLowerCase()
383
+ const txEndpoint = String(p.endpoint).replace(/\/api\/point$/, '/api/point-transcribe')
384
+ if (canTalk) mic.hidden = false
385
+ if (canTalk && cfg.keepAudio) $('.keep').hidden = false
386
+ // which marker a phrase was said about: the one current when it began
387
+ const markerAt = (t) => {
388
+ let current = 0
389
+ for (const s of timeline) { if (s.at <= t) current = s.marker; else break }
390
+ return current
391
+ }
392
+ // the field a phrase (or a first typed key) goes to: the current marker's
393
+ // note, else the report's "what happened"
394
+ function fieldFor(n) {
395
+ const li = n && list.querySelector(`li[data-n="${n}"]`)
396
+ if (li) return li.querySelector('.note')
397
+ $('.exp').open = true
398
+ return $('.actual')
399
+ }
400
+ async function onPhrase(ph) {
401
+ const n = markerAt(ph.startedAt)
402
+ const endedAt = Date.now() // the phrase was cut just now
403
+ pending++
404
+ setState(state)
405
+ try {
406
+ const res = await fetch(txEndpoint, {
407
+ method: 'POST', headers: { 'Content-Type': 'text/plain;charset=UTF-8' }, credentials: 'omit',
408
+ body: JSON.stringify({ key: p.key, mime: ph.mime, data: await base64Of(ph.blob), lang }),
409
+ })
410
+ const j = await res.json().catch(() => ({}))
411
+ const words = res.ok ? String(j.text || '').trim() : ''
412
+ if (words) {
413
+ caption(n, words, ph.startedAt, endedAt)
414
+ const m = markers.find((x) => x.n === n)
415
+ const el = fieldFor(m ? n : 0)
416
+ if (m) m.note = `${m.note ? `${m.note} ` : ''}${words}`.slice(0, 1000)
417
+ if (el) { el.value = m ? m.note : `${el.value ? `${el.value} ` : ''}${words}`.slice(0, 500); el.dispatchEvent(new Event('input')) }
418
+ } else if (!res.ok) say('Some of what you said couldn’t be written down — type it if it’s missing', true)
419
+ } catch { say('Some of what you said couldn’t be written down — type it if it’s missing', true) }
420
+ pending--
421
+ setState(state)
422
+ }
423
+ // the listening panel's running caption: the last few phrases, each in its
424
+ // marker's colour with the marker's number (V1 on the design board)
425
+ const cap = $('.cap')
426
+ const phrases = []
427
+ function caption(n, words, at, end) {
428
+ phrases.push({ n, words, at, end })
429
+ cap.replaceChildren(...phrases.slice(-4).map((ph) => {
430
+ const span = document.createElement('span')
431
+ const m = markers.find((x) => x.n === ph.n)
432
+ if (m) { span.className = 'said'; span.style.setProperty('--c', FLAG_COLOR[m.flag]) }
433
+ span.textContent = `${ph.words}${m ? ` ${CIRCLED[m.n] || `(${m.n})`}` : ''} `
434
+ return span
435
+ }))
436
+ }
437
+ function showMic(on) {
438
+ mic.classList.toggle('on', on)
439
+ mic.setAttribute('aria-label', on ? 'Stop talking' : 'Talk')
440
+ $('.typei').hidden = !on
441
+ $('.listening').hidden = !on
442
+ }
443
+ async function stopMic() {
444
+ if (!voice) return
445
+ const v = voice
446
+ voice = null
447
+ // the page says so at once; the last phrase is still handed over
448
+ showMic(false)
449
+ setState(state)
450
+ audio = await v.stop()
451
+ }
452
+ async function startMic() {
453
+ if (!canTalk || voice) return
454
+ vcard.hidden = true
455
+ mic.hidden = false
456
+ try {
457
+ voice = await startVoice({ onPhrase, keep: Boolean(cfg.keepAudio) })
458
+ live = live || { startedAt: voice.startedAt }
459
+ local.set(VOICE_KEY, 'yes')
460
+ timeline.push({ at: voice.startedAt, marker: currentMarker })
461
+ if (!phrases.length) cap.textContent = 'Say what you see…'
462
+ showMic(true)
463
+ setState(state)
464
+ } catch (e) {
465
+ voice = null
466
+ if (e?.name === 'NotAllowedError') local.set(VOICE_KEY, 'no')
467
+ say(e?.name === 'NotAllowedError' ? 'The microphone is blocked for this site — type instead' : 'The microphone could not start — type instead', true)
468
+ }
469
+ }
470
+ const toggleMic = () => (voice ? stopMic() : startMic())
471
+ // the voice card, once: the first time on this device, after the how-to
472
+ let offered = false
473
+ function offerVoice() {
474
+ if (offered || !canTalk || voice || local.get(VOICE_KEY)) return
475
+ offered = true
476
+ vcard.hidden = false
477
+ mic.hidden = true
478
+ }
479
+ // the button for it: the microphone stops, the note it would have gone to opens
480
+ $('.typei').addEventListener('click', () => { stopMic(); fieldFor(currentMarker)?.focus() })
481
+ // typing instead: the voice card goes, the microphone stops, and the key
482
+ // lands in the note it was meant for
483
+ function typeInstead(e) {
484
+ vcard.hidden = true
485
+ mic.hidden = !canTalk
486
+ if (voice) stopMic()
487
+ const el = fieldFor(currentMarker)
488
+ if (!el) return
489
+ e.preventDefault()
490
+ e.stopImmediatePropagation()
491
+ el.focus()
492
+ el.value += e.key
493
+ el.dispatchEvent(new Event('input'))
494
+ }
495
+
496
+ // ---- how it works (first time on this device, or ?) ----------------------------------
497
+ function showHowto(force) {
498
+ let seen = false
499
+ try { seen = localStorage.getItem(HOWTO_KEY) === '1' } catch { /* private mode */ }
500
+ if (seen && !force) return
501
+ try { localStorage.setItem(HOWTO_KEY, '1') } catch { /* private mode */ }
502
+ howtoShown = true
503
+ const card = $('.howto')
504
+ const how = TRIGGER_WORDS[cfg.trigger] || 'Use the shortcut'
505
+ card.innerHTML = `<div class="scene" aria-hidden="true"><div class="page"><i></i><i></i><b class="btn">Pay</b></div><span class="cur"></span><span class="pinh">1</span><span class="wave"></span></div>
506
+ <ol><li><b>${how}</b> to point</li><li><b>Click</b> what is wrong</li>${cfg.voice ? '<li><b>Say</b> what you see</li>' : '<li><b>Add a note</b> if you like</li>'}<li><b>Enter</b> sends it</li></ol>
507
+ <button class="ok" type="button">Got it</button>`
508
+ card.hidden = false
509
+ const hide = () => { if (card.hidden) return; card.hidden = true; offerVoice() }
510
+ card.querySelector('.ok').addEventListener('click', hide)
511
+ setTimeout(hide, 9000)
512
+ }
513
+
514
+ // ---- send ---------------------------------------------------------------------------
515
+ async function send() {
516
+ if (sending) return
517
+ if (flow && !flow.end) endFlow()
518
+ const expected = $('.expected').value.trim()
519
+ const actual = $('.actual').value.trim()
520
+ if (!markers.length && !flow?.end && !expected && !actual) { say('Mark something first — click what is wrong', true); return }
521
+ sending = true
522
+ setState(state)
523
+ // the panel holds still while it goes: one spinner, one line of what's happening
524
+ const sendBtn = $('.send')
525
+ sendBtn.innerHTML = '<span class="spin" aria-hidden="true"></span>Sending…'
526
+ rail.classList.add('busy')
527
+ say('')
528
+ try {
529
+ if (voice) await stopMic()
530
+ // the last words are still on their way: wait for them, a little
531
+ if (pending > 0) say('Writing down the last of what you said…')
532
+ for (const until = Date.now() + PENDING_WAIT_MS; pending > 0 && Date.now() < until;) await new Promise((r) => setTimeout(r, 100))
533
+ say('')
534
+ const keep = Boolean(cfg.keepAudio && $('.keep input').checked && audio?.blob?.size)
535
+ const report = {
536
+ page: location.pathname,
537
+ release: p.release || undefined,
538
+ expected: expected || undefined,
539
+ actual: actual || undefined,
540
+ markers: markers.map((m) => ({
541
+ n: m.n, kind: m.kind, flag: m.flag, note: m.note.trim() || undefined, at: m.at,
542
+ ...m.desc,
543
+ viewport: { w: innerWidth, h: innerHeight }, scroll: { x: Math.round(scrollX), y: Math.round(scrollY) }, dpr: devicePixelRatio || 1,
544
+ events: m.ctx.events, network: m.ctx.network, console: m.ctx.console,
545
+ })),
546
+ flow: flow?.end ? flow : undefined,
547
+ env: environment(),
548
+ // the words are already in the notes; the recording only if kept
549
+ // the phrases with when they were said: the replay captions them there
550
+ voice: live ? { live: true, startedAt: live.startedAt, timeline, lang: lang || undefined, keep, phrases: phrases.map((x) => ({ at: x.at, end: x.end, marker: markers.some((m) => m.n === x.n) ? x.n : 0, text: x.words })) } : undefined,
551
+ via: cfg.via || undefined,
552
+ }
553
+ // "Tell me when it's fixed" starts as the project says; the box under
554
+ // the confirmation changes it. about: "Still happening?" on that bug
555
+ const body = { key: p.key, sessionId: rec.sessionId || null, report, notify: { on: Boolean(cfg.notify?.tick) }, ...(cfg.about ? { about: cfg.about } : {}) }
556
+ if (keep) body.audio = { mime: audio.mime, data: await base64Of(audio.blob) }
557
+ const res = await fetch(p.endpoint, { method: 'POST', headers: { 'Content-Type': 'text/plain;charset=UTF-8' }, credentials: 'omit', body: JSON.stringify(body) })
558
+ const j = await res.json().catch(() => ({}))
559
+ if (!res.ok) throw new Error(j.error || `HTTP ${res.status}`)
560
+ done(j.bug, j.receipt, j.reopened)
561
+ } catch (e) {
562
+ sending = false
563
+ sendBtn.textContent = 'Send'
564
+ rail.classList.remove('busy')
565
+ setState(state)
566
+ say(`Couldn't send: ${String(e?.message || e).slice(0, 80)} — try again`, true)
567
+ }
568
+ }
569
+ function done(number, receipt = null, reopened = false) {
570
+ setState('sent')
571
+ p.active(false)
572
+ setCursorHidden(false)
573
+ showOutline(null)
574
+ rail.classList.add('done')
575
+ const n = Math.floor(Number(number)) || 0
576
+ // the project's own words ({number} → the bug), else ours
577
+ const msg = cfg.thanks?.message
578
+ ? cfg.thanks.message.replace(/\{number\}/g, n ? String(n) : '')
579
+ : reopened ? `Thanks — bug #${n} is open again, and the team can see what you saw.` : n ? `Sent as bug #${n} — thank you.` : 'Sent — thank you.'
580
+ const thanks = document.createElement('div')
581
+ thanks.className = 'thanks'
582
+ thanks.innerHTML = `<div class="th"><span class="okc" aria-hidden="true">${CHECK_SVG}</span><b></b></div>`
583
+ thanks.querySelector('b').textContent = msg
584
+ // whoever came through a button, a nudge or a link learns the shortcut
585
+ // at the moment it paid off — on their first two reports
586
+ const sent = (Number(local.get(SENT_KEY)) || 0) + 1
587
+ local.set(SENT_KEY, String(sent))
588
+ const caps = keyCaps(cfg)
589
+ const touch = typeof matchMedia === 'function' && matchMedia('(pointer: coarse)').matches
590
+ const teach = cfg.thanks?.teach !== false && caps.length > 0 && !touch && cfg.via !== 'shortcut' && sent <= TEACH_TIMES
591
+ if (teach) {
592
+ const t = document.createElement('p')
593
+ t.className = 'teach'
594
+ t.innerHTML = `Next time, from any page: ${cfg.trigger === 'double-ctrl' ? 'tap ' : ''}<span class="caps">${capsHtml(caps)}</span> and click what’s wrong.`
595
+ thanks.append(t)
596
+ }
597
+ // N1 on the design board: one more line — the box, and for someone the
598
+ // app doesn't know, an optional address
599
+ const tell = cfg.notify && receipt ? notifyBox(receipt) : null
600
+ if (tell) thanks.append(tell)
601
+ rail.replaceChildren(thanks)
602
+ cfg.onSent?.(number)
603
+ // it stays up while the person is in it
604
+ let timer = null
605
+ const later = (ms) => { clearTimeout(timer); timer = setTimeout(close, ms) }
606
+ thanks.addEventListener('pointerenter', () => clearTimeout(timer))
607
+ thanks.addEventListener('focusin', () => clearTimeout(timer))
608
+ thanks.addEventListener('pointerleave', () => { if (!thanks.contains(thanks.getRootNode().activeElement)) later(2500) })
609
+ thanks.addEventListener('focusout', () => later(2500))
610
+ later(tell ? 6500 : teach ? 5200 : 2600)
611
+ }
612
+ // "Tell me when it's fixed" → /api/point-notify; the receipt stays in this
613
+ // browser either way only while it is ticked
614
+ function notifyBox(receipt) {
615
+ const notifyEndpoint = p.endpoint.replace(/\/api\/point$/, '/api/point-notify')
616
+ const post = (o) => fetch(notifyEndpoint, { method: 'POST', headers: { 'Content-Type': 'text/plain;charset=UTF-8' }, credentials: 'omit', body: JSON.stringify({ key: p.key, receipt, ...o }) })
617
+ const known = Boolean(p.identified?.())
618
+ const box = document.createElement('div')
619
+ box.className = 'tell'
620
+ box.innerHTML = `<label class="tick"><input type="checkbox"><span><b>Tell me when it’s fixed</b><small></small></span></label>`
621
+ const input = box.querySelector('input')
622
+ const small = box.querySelector('small')
623
+ input.checked = Boolean(cfg.notify.tick)
624
+ small.textContent = known && cfg.notify.email ? 'Here, and by email' : 'We’ll show it here next time you visit'
625
+ if (input.checked) keepReceipt(receipt)
626
+ let form = null
627
+ if (cfg.notify.email && !known) {
628
+ form = document.createElement('form')
629
+ form.className = 'mail'
630
+ form.innerHTML = '<label for="sp-mail">Email me too (optional)</label><div><input id="sp-mail" type="email" autocomplete="email" placeholder="you@example.com" maxlength="254"><button type="submit">Save</button></div><p class="mailmsg" role="status"></p>'
631
+ form.hidden = !input.checked
632
+ form.addEventListener('submit', async (e) => {
633
+ e.preventDefault()
634
+ const field = form.querySelector('input')
635
+ const msg = form.querySelector('.mailmsg')
636
+ const email = field.value.trim()
637
+ if (!email) return
638
+ msg.textContent = 'Saving…'
639
+ try {
640
+ const r = await post({ on: true, email })
641
+ const j = await r.json().catch(() => ({}))
642
+ msg.textContent = r.ok ? 'Saved — one email when it’s fixed, then we delete it' : j.error || 'Couldn’t save it'
643
+ if (r.ok) field.disabled = true
644
+ } catch { msg.textContent = 'Couldn’t save it' }
645
+ })
646
+ box.append(form)
647
+ }
648
+ input.addEventListener('change', () => {
649
+ const on = input.checked
650
+ if (on) keepReceipt(receipt)
651
+ else dropReceipt(receipt)
652
+ if (form) form.hidden = !on
653
+ post({ on }).catch(() => {})
654
+ })
655
+ return box
656
+ }
657
+
658
+ // ---- open/close -------------------------------------------------------------------
659
+ function close() {
660
+ if (closed) return
661
+ closed = true
662
+ cancelAnimationFrame(raf)
663
+ if (voice) voice.stop()
664
+ p.active(false)
665
+ setCursorHidden(false)
666
+ for (const t of BLOCKED) window.removeEventListener(t, block, true)
667
+ window.removeEventListener('pointermove', onMove, true)
668
+ window.removeEventListener('keydown', onKey, true)
669
+ host.remove()
670
+ style.remove()
671
+ cfg.onClose?.()
672
+ }
673
+ for (const t of BLOCKED) window.addEventListener(t, block, { capture: true, passive: false })
674
+ // a selection made before Point opened couldn't be cleared while it's open
675
+ try { getSelection()?.removeAllRanges() } catch { /* nothing selected */ }
676
+ window.addEventListener('pointermove', onMove, true)
677
+ window.addEventListener('keydown', onKey, true)
678
+ $('.x').addEventListener('click', close)
679
+ // the panel can be dragged out of the way for this report only: it is not
680
+ // remembered — each time Point opens, it starts in its usual place (the
681
+ // launcher is what visitors set up once)
682
+ let railPlaced = false
683
+ const placeRail = (x, y) => {
684
+ const w = rail.offsetWidth
685
+ const h = rail.offsetHeight
686
+ rail.style.left = `${Math.min(innerWidth - w - 8, Math.max(8, x))}px`
687
+ rail.style.top = `${Math.min(innerHeight - Math.min(h, 120), Math.max(8, y))}px`
688
+ rail.style.right = 'auto'
689
+ rail.style.bottom = 'auto'
690
+ railPlaced = true
691
+ }
692
+ const head = rail.querySelector('header')
693
+ head.title = 'Drag to move'
694
+ head.addEventListener('pointerdown', (e) => {
695
+ if (e.button !== 0 || e.target.closest('button') || innerWidth <= 560) return
696
+ const r = rail.getBoundingClientRect()
697
+ const dx = e.clientX - r.left
698
+ const dy = e.clientY - r.top
699
+ rail.classList.add('moving')
700
+ const move = (ev) => placeRail(ev.clientX - dx, ev.clientY - dy)
701
+ const up = () => {
702
+ rail.classList.remove('moving')
703
+ window.removeEventListener('pointermove', move, true)
704
+ window.removeEventListener('pointerup', up, true)
705
+ }
706
+ window.addEventListener('pointermove', move, true)
707
+ window.addEventListener('pointerup', up, true)
708
+ e.preventDefault()
709
+ })
710
+ $('.send').addEventListener('click', send)
711
+ $('.flowbtn').addEventListener('click', () => (flow && !flow.end ? endFlow() : startFlow()))
712
+ mic.addEventListener('click', toggleMic)
713
+ $('.vstart').addEventListener('click', startMic)
714
+ for (const sel of ['.expected', '.actual']) $(sel).addEventListener('input', () => setState(state))
715
+ setState('armed')
716
+ local.set(USED_KEY, '1')
717
+ // voice: the first time, the card explains it; after a yes, it just listens
718
+ const voicePref = local.get(VOICE_KEY)
719
+ if (canTalk && voicePref === 'yes') startMic()
720
+ showHowto(false)
721
+ if (!howtoShown) offerVoice()
722
+ if (cfg.target?.isConnected && !host.contains(cfg.target)) addMarker(cfg.target, null)
723
+
724
+ return {
725
+ // the trigger again: nothing marked → leave; something marked → send
726
+ toggle: () => (markers.length || flow?.end ? send() : close()),
727
+ // a held trigger let go with nothing marked → leave (VISION.md §4.3)
728
+ released: () => { if (!markers.length && !flow && !howtoShown && state === 'armed') close() },
729
+ close,
730
+ send,
731
+ get markers() { return markers.length },
732
+ get state() { return state },
733
+ }
734
+ }
735
+
736
+ // dark chips on any page: they pass contrast on light and dark sites alike
737
+ const CSS = `
738
+ :host{all:initial}
739
+ *{-webkit-user-select:none;user-select:none}
740
+ input,textarea{-webkit-user-select:text;user-select:text}
741
+ *{box-sizing:border-box;font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif}
742
+ [hidden]{display:none!important}
743
+ .ring{position:fixed;left:0;top:0;width:24px;height:24px;margin:-12px 0 0 -12px;border-radius:50%;border:2px solid #94A3B8;background:rgba(148,163,184,.12);pointer-events:none;z-index:4;transition:border-color .15s,background .15s;will-change:transform}
744
+ .ring .dot{position:absolute;left:50%;top:50%;width:4px;height:4px;margin:-2px;border-radius:50%;background:#94A3B8}
745
+ .ring .badge{position:absolute;left:16px;top:-12px;min-width:16px;height:16px;padding:0 4px;border-radius:8px;background:#0E1320;color:#fff;font-size:10px;font-weight:700;line-height:16px;text-align:center;display:none}
746
+ .ring[data-state~="marking"]{border-color:#5B4BF0;background:rgba(91,75,240,.16)}
747
+ .ring[data-state~="marking"] .dot{background:#5B4BF0}
748
+ .ring[data-state~="armed"] .badge,.ring[data-state~="marking"] .badge{display:block}
749
+ .ring[data-state~="listening"]{box-shadow:0 0 0 calc(2px + var(--lv,0) * 10px) rgba(91,75,240,.35)}
750
+ .ring[data-state~="flow"]{width:14px;height:14px;margin:-7px 0 0 -7px;border-color:#F43F5E;background:#F43F5E;opacity:.9}
751
+ .ring[data-state~="flow"] .dot{display:none}
752
+ .ring[data-state~="sent"]{display:none}
753
+ .ring:not(.seen){opacity:0}
754
+ @media (prefers-reduced-motion:reduce){.ring{transition:none}}
755
+ .outline{position:fixed;left:0;top:0;border:1.5px solid #5B4BF0;border-radius:3px;background:rgba(91,75,240,.06);pointer-events:none;opacity:0;z-index:2}
756
+ .outline .chip{position:absolute;left:-1px;bottom:100%;margin-bottom:4px;max-width:320px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;background:#0E1320;color:#fff;font-size:11px;font-weight:600;padding:3px 7px;border-radius:5px}
757
+ .outline.below .chip{bottom:auto;top:100%;margin:4px 0 0}
758
+ .frame{position:fixed;left:0;top:0;display:none;border:1.5px dashed #5B4BF0;background:rgba(91,75,240,.08);pointer-events:none;z-index:2}
759
+ .marks{position:fixed;left:0;top:0;width:0;height:0;z-index:3}
760
+ .mk{position:fixed;left:0;top:0;border:2px solid var(--c);border-radius:4px;pointer-events:none}
761
+ .mk.region{border-style:dashed}
762
+ .mk .pin{position:absolute;left:-11px;top:-11px;width:22px;height:22px;border-radius:50%;border:2px solid #fff;background:var(--c);color:#fff;font:700 11px/18px ui-sans-serif,system-ui;text-align:center;pointer-events:auto;cursor:pointer;padding:0;box-shadow:0 2px 8px rgba(0,0,0,.35)}
763
+ .rail{position:fixed;top:16px;right:16px;width:320px;max-height:calc(100vh - 32px);overflow:auto;background:#0E1320;color:#E6E8EE;border:1px solid #2a3346;border-radius:12px;padding:12px;box-shadow:0 12px 40px rgba(0,0,0,.45);font-size:13px;z-index:5;cursor:default}
764
+ .rail *{cursor:auto}
765
+ .rail header,.rail header *:not(button){cursor:grab}
766
+ .rail.moving,.rail.moving *{cursor:grabbing!important;user-select:none}
767
+ .rail.left{right:auto;left:16px}
768
+ .rail button{cursor:pointer}
769
+ .rail header{display:flex;align-items:center;gap:8px;margin-bottom:8px}
770
+ .rail header b{font-size:14px}
771
+ .hint{flex:1;color:#94A3B8;font-size:11.5px}
772
+ .x{background:none;border:0;color:#94A3B8;font-size:18px;line-height:1;padding:2px 6px}
773
+ .list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}
774
+ .list li{display:grid;grid-template-columns:22px 1fr 18px;gap:4px 8px;align-items:center;background:#151B2B;border:1px solid #232c40;border-radius:8px;padding:6px 8px}
775
+ .num{width:22px;height:22px;border-radius:50%;border:0;background:var(--c);color:#fff;font-weight:700;font-size:11px;padding:0}
776
+ .what{display:flex;align-items:center;gap:6px;min-width:0}
777
+ .name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600}
778
+ .flag{border:1px solid var(--c);color:var(--c);background:transparent;border-radius:999px;font-size:10.5px;font-weight:700;padding:1px 7px}
779
+ .note{grid-column:2/4;grid-row:2;width:100%;background:#0B0F19;border:1px solid #2a3346;border-radius:6px;color:#E6E8EE;padding:5px 8px;font-size:12.5px;outline:none;resize:none;min-height:28px;field-sizing:content;max-height:120px;line-height:1.45}
780
+ .vcard{margin-top:10px;background:#151B2B;border:1px solid #3b3a7a;border-radius:10px;padding:12px}
781
+ .vcard b{font-size:13.5px}
782
+ .vcard p{margin:6px 0;color:#C3C8D4;font-size:12.5px;line-height:1.5}
783
+ .vcard .fine{color:#94A3B8;font-size:11.5px}
784
+ .vcard .c{text-align:center;margin-bottom:0}
785
+ .kc{display:inline-flex;align-items:center;justify-content:center;min-width:20px;height:20px;padding:0 5px;border:1px solid rgba(255,255,255,.22);border-bottom-width:2px;border-radius:5px;background:rgba(255,255,255,.06);color:inherit;font:600 10.5px/1 ui-monospace,SFMono-Regular,Menlo,monospace}
786
+ .caps{display:inline-flex;gap:3px;vertical-align:middle;margin:0 2px}
787
+ .vstart{width:100%;height:44px;margin-top:6px;display:flex;align-items:center;justify-content:center;gap:8px;background:#5B4BF0;border:0;color:#fff;font-weight:700;border-radius:10px;font-size:13.5px}
788
+ .vstart svg,.mic svg{width:17px;height:17px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round}
789
+ .listening{margin-top:10px;background:rgba(255,255,255,.04);border-radius:10px;padding:12px;display:flex;flex-direction:column;gap:8px}
790
+ .lh{display:flex;align-items:center;gap:8px;font-size:12px;color:#C3C8D4}
791
+ .rd{width:8px;height:8px;border-radius:50%;background:#F87171;box-shadow:0 0 0 4px rgba(248,113,113,.2)}
792
+ .bars{margin-left:auto;display:flex;align-items:flex-end;gap:2px;height:14px}
793
+ .bars i{display:block;width:3px;border-radius:2px;background:#14C8A6;height:calc(3px + var(--lv,0) * 11px)}
794
+ .bars i:nth-child(2){height:calc(5px + var(--lv,0) * 9px)}.bars i:nth-child(3){height:calc(3px + var(--lv,0) * 8px)}.bars i:nth-child(4){height:calc(6px + var(--lv,0) * 8px)}.bars i:nth-child(5){height:calc(2px + var(--lv,0) * 6px)}
795
+ .cap{margin:0;font-size:14px;line-height:1.6;color:#F4F5F8;min-height:1.6em}
796
+ .cap .said{color:var(--c);font-weight:600}
797
+ .listening .fine{margin:0;font-size:11px;color:#8A93A6;line-height:1.5}
798
+ .flowbtn{margin-top:10px;width:100%;background:#151B2B;border:1px solid #2a3346;color:#E6E8EE;border-radius:8px;padding:7px 8px;font-size:12px;font-weight:600}
799
+ .flowbtn.on{border-color:#F43F5E;color:#FDA4AF}
800
+ .bottom{gap:8px}
801
+ .mic{flex:none;width:44px;height:44px;border-radius:50%;display:flex;align-items:center;justify-content:center;background:transparent;border:1px solid rgba(169,160,255,.5);color:#A9A0FF;padding:0}
802
+ .mic.on{background:#F87171;border-color:#F87171;color:#0E1320}
803
+ .typei{height:44px;padding:0 12px;border:1px solid rgba(255,255,255,.12);border-radius:10px;background:transparent;color:#C3C8D4;font-size:13px}
804
+ .send{flex:1;height:44px;background:#5B4BF0;border:0;color:#fff;font-weight:700;border-radius:10px;padding:0 16px;font-size:14px}
805
+ .send:disabled{opacity:.45;cursor:default}
806
+ .rail.busy .send:disabled{opacity:1}
807
+ .rail.busy .list,.rail.busy .exp,.rail.busy .flowbtn,.rail.busy .mic,.rail.busy .typei,.rail.busy .listening{opacity:.5;pointer-events:none}
808
+ .send{display:flex;align-items:center;justify-content:center;gap:8px}
809
+ .spin{width:15px;height:15px;border-radius:50%;border:2px solid rgba(255,255,255,.35);border-top-color:#fff;animation:sp-spin .7s linear infinite}
810
+ @keyframes sp-spin{to{transform:rotate(360deg)}}
811
+ @media (prefers-reduced-motion:reduce){.spin{animation-duration:2s}}
812
+ @media (max-width:560px){.rail{top:auto;left:8px;right:8px;bottom:8px;width:auto;max-height:55vh;border-radius:14px}.howto{width:calc(100vw - 24px);bottom:auto;top:12px}}
813
+ .rail.done{width:auto;max-width:360px;padding:14px 16px}
814
+ .thanks{margin:0;color:#F4F5F8;display:flex;flex-direction:column;gap:8px}
815
+ .th{display:flex;align-items:center;gap:10px}
816
+ .th b{font-size:14px;font-weight:600}
817
+ .okc{width:22px;height:22px;flex:none;border-radius:50%;background:#14C8A6;display:flex;align-items:center;justify-content:center}
818
+ .okc svg{width:12px;height:12px;fill:none;stroke:#0E1320;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
819
+ .teach{margin:0;font-size:13px;line-height:1.7;color:#C3C8D4}
820
+ .tell{border-top:1px solid rgba(255,255,255,.1);padding-top:12px;display:flex;flex-direction:column;gap:10px}
821
+ .tick{display:flex;gap:10px;align-items:flex-start;font-size:13px;line-height:1.5;color:#C3C8D4;cursor:pointer}
822
+ .tick input{width:16px;height:16px;margin:2px 0 0;flex:none;accent-color:#14C8A6;cursor:pointer}
823
+ .tick b{display:block;color:#F4F5F8;font-weight:600}
824
+ .tick small{font-size:13px}
825
+ .mail{display:flex;flex-direction:column;gap:6px;padding-left:26px;margin:0}
826
+ .mail label{font-size:12px;color:#C3C8D4}
827
+ .mail div{display:flex;gap:8px}
828
+ .mail input{flex:1;min-width:0;height:34px;border-radius:8px;border:1px solid rgba(255,255,255,.22);background:rgba(255,255,255,.06);color:#F4F5F8;padding:0 10px;font:inherit;font-size:13px}
829
+ .mail input:disabled{opacity:.6}
830
+ .mail button{height:34px;padding:0 14px;border:0;border-radius:8px;background:#F4F5F8;color:#0E1320;font:inherit;font-size:13px;font-weight:600;cursor:pointer}
831
+ .mailmsg{margin:0;font-size:12px;color:#8A93A6}
832
+ .mailmsg:empty{display:none}
833
+ .keep{display:flex;gap:6px;align-items:center;margin-top:10px;font-size:12px;color:#C3C8D4}
834
+ .note:focus,.exp input:focus{border-color:#5B4BF0}
835
+ .rm{grid-column:3;grid-row:1;background:none;border:0;color:#64748B;font-size:15px;padding:0}
836
+ .empty{color:#94A3B8;margin:6px 0 8px;font-size:12.5px}
837
+ .row{display:flex;align-items:center;gap:8px;margin-top:10px}
838
+ .exp{margin-top:10px;color:#94A3B8;font-size:12px}
839
+ .exp summary{cursor:pointer}
840
+ .exp input{display:block;width:100%;margin-top:6px;background:#0B0F19;border:1px solid #2a3346;border-radius:6px;color:#E6E8EE;padding:6px 8px;font-size:12.5px;outline:none}
841
+ .status{margin:8px 0 0;font-size:12px;color:#94A3B8;min-height:1em}
842
+ .status:empty{display:none}
843
+ .status.bad{color:#FCA5A5}
844
+ .howto{position:fixed;left:50%;bottom:24px;transform:translateX(-50%);width:360px;background:#0E1320;color:#E6E8EE;border:1px solid #2a3346;border-radius:14px;padding:14px;box-shadow:0 16px 50px rgba(0,0,0,.5);z-index:6;font-size:13px}
845
+ .howto ol{margin:10px 0 8px;padding-left:20px;line-height:1.7}
846
+ .howto .ok{background:#5B4BF0;border:0;color:#fff;border-radius:8px;padding:6px 12px;font-weight:700;cursor:pointer}
847
+ .scene{position:relative;height:96px;border-radius:9px;background:#151B2B;overflow:hidden}
848
+ .scene .page{position:absolute;inset:12px 14px}
849
+ .scene .page i{display:block;height:8px;border-radius:4px;background:#232c40;margin-bottom:8px;width:70%}
850
+ .scene .page i+i{width:45%}
851
+ .scene .btn{position:absolute;right:10px;bottom:6px;background:#2E86F0;color:#fff;font-size:11px;padding:5px 14px;border-radius:6px}
852
+ .scene .cur{position:absolute;left:30px;top:20px;width:18px;height:18px;margin:-9px;border-radius:50%;border:2px solid #94A3B8;animation:sp-move 8s infinite}
853
+ .scene .pinh{position:absolute;right:62px;bottom:20px;width:18px;height:18px;border-radius:50%;background:#F43F5E;color:#fff;font:700 10px/18px ui-sans-serif,system-ui;text-align:center;opacity:0;animation:sp-pin 8s infinite}
854
+ .scene .wave{position:absolute;left:20px;bottom:16px;width:40px;height:10px;border-radius:5px;background:linear-gradient(90deg,#5B4BF0,#2E86F0);opacity:0;animation:sp-wave 8s infinite}
855
+ @keyframes sp-move{0%,8%{transform:translate(0,0);border-color:#94A3B8}30%,100%{transform:translate(250px,52px);border-color:#5B4BF0}}
856
+ @keyframes sp-pin{0%,34%{opacity:0;transform:scale(.4)}40%,100%{opacity:1;transform:scale(1)}}
857
+ @keyframes sp-wave{0%,48%{opacity:0;transform:scaleX(.3)}55%,60%{opacity:1;transform:scaleX(1)}65%,70%{opacity:1;transform:scaleX(.5)}75%,85%{opacity:1;transform:scaleX(1)}92%,100%{opacity:0}}
858
+ @media (prefers-reduced-motion:reduce){.scene .cur,.scene .pinh,.scene .wave{animation:none}.scene .pinh,.scene .wave{opacity:1}.scene .cur{transform:translate(250px,52px)}}
859
+ `