/** Copy-to-clipboard with a legacy fallback for non-secure contexts. */ export async function copyText(text: string): Promise { try { if (navigator.clipboard && window.isSecureContext !== false) { await navigator.clipboard.writeText(text) return true } } catch { /* fall through to legacy path */ } try { const ta = document.createElement('textarea') ta.value = text ta.style.position = 'fixed' ta.style.opacity = '0' document.body.appendChild(ta) ta.focus() ta.select() const ok = document.execCommand('copy') ta.remove() return ok } catch { return false } }