@spectosh/browser 0.2.5 → 0.3.0

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