export async function copyTextToClipboard(text: string): Promise { try { if (navigator.clipboard?.writeText) { await navigator.clipboard.writeText(text) return true } } catch { // Fall through to legacy copy path. } try { const textarea = document.createElement('textarea') textarea.value = text textarea.setAttribute('readonly', 'true') textarea.style.position = 'fixed' textarea.style.opacity = '0' document.body.appendChild(textarea) textarea.select() const copied = document.execCommand('copy') document.body.removeChild(textarea) return copied } catch { return false } }