
      if (loadingScreen) {
        setTimeout(() => {
          loadingScreen.style.display = 'none';
        }, 600);
      }
    });

    // Unified Back-to-top logic (single implementation)
    (function () {
      const backBtn = document.getElementById('backToTopBtn');
      if (!backBtn) return;
      const updateThreshold = () => Math.max(300, (document.body.scrollHeight || 800) / 3);
      const check = () => {
        const threshold = updateThreshold();
        if (window.scrollY > 