document.addEventListener('fortis:backup-complete', () => {
  const overlay = document.createElement('div');
  overlay.className = 'fortis-complete';
  overlay.innerHTML = '<div class="fortis-complete-shield"><img src="'+FortisRestoreData.icon+'" alt=""><b>BACKUP COMPLETE</b></div>';
  document.body.appendChild(overlay);
  window.setTimeout(() => overlay.classList.add('visible'), 30);
  window.setTimeout(() => overlay.classList.remove('visible'), 5030);
  window.setTimeout(() => overlay.remove(), 5800);
});

document.addEventListener('DOMContentLoaded', () => {
  const label = document.querySelector('#fortis-progress p');
  if (!label) return;
  let shown = false;
  new MutationObserver(() => {
    if (!shown && /encrypted backup verified/i.test(label.textContent || '')) {
      shown = true;
      document.dispatchEvent(new CustomEvent('fortis:backup-complete'));
    }
  }).observe(label, {childList: true, characterData: true, subtree: true});
});
