// ===== SHARED JS - AI Chapter Forge ===== // Initialize Lucide icons function initIcons() { if (typeof lucide !== 'undefined') { lucide.createIcons(); } } // ===== CURSOR GLOW ===== function initCursorGlow() { const cursorGlow = document.getElementById('cursorGlow'); if (!cursorGlow) return; document.addEventListener('mousemove', (e) => { cursorGlow.style.left = e.clientX + 'px'; cursorGlow.style.top = e.clientY + 'px'; cursorGlow.style.opacity = '1'; }); } // ===== SCROLL REVEAL ===== function initScrollReveal() { const revealObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('active'); } }); }, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }); document.querySelectorAll('.reveal, .reveal-left, .reveal-scale').forEach(el => { revealObserver.observe(el); }); } // ===== ANIMATED COUNTERS ===== function initCounters() { const counterObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting && !entry.target.classList.contains('counted')) { entry.target.classList.add('counted'); const target = parseInt(entry.target.getAttribute('data-target')); const suffix = entry.target.getAttribute('data-suffix') || ''; if (target) { animateCounter(entry.target, target, suffix); } } }); }, { threshold: 0.5 }); document.querySelectorAll('.counter').forEach(el => counterObserver.observe(el)); } function animateCounter(el, target, suffix) { const duration = 2000; const start = performance.now(); const step = (now) => { const elapsed = now - start; const progress = Math.min(elapsed / duration, 1); const eased = 1 - Math.pow(1 - progress, 4); const current = Math.floor(eased * target); el.textContent = current.toLocaleString() + suffix; if (progress < 1) { requestAnimationFrame(step); } else { el.textContent = target.toLocaleString() + suffix; } }; requestAnimationFrame(step); } // ===== NAV SCROLL EFFECT ===== function initNavScroll() { const mainNav = document.getElementById('mainNav'); if (!mainNav) return; window.addEventListener('scroll', () => { if (window.scrollY > 50) { mainNav.classList.add('glass', 'nav-scrolled'); } else { mainNav.classList.remove('glass', 'nav-scrolled'); } }); } // ===== MOBILE MENU ===== function initMobileMenu() { const toggle = document.getElementById('mobileMenuToggle'); const menu = document.getElementById('mobileMenu'); const close = document.getElementById('mobileMenuClose'); const overlay = document.getElementById('mobileMenuOverlay'); if (!toggle || !menu) return; function openMenu() { menu.classList.add('open'); if (overlay) overlay.classList.remove('hidden'); document.body.style.overflow = 'hidden'; } function closeMenu() { menu.classList.remove('open'); if (overlay) overlay.classList.add('hidden'); document.body.style.overflow = ''; } toggle.addEventListener('click', openMenu); if (close) close.addEventListener('click', closeMenu); if (overlay) overlay.addEventListener('click', closeMenu); // Close on link click menu.querySelectorAll('a').forEach(link => { link.addEventListener('click', closeMenu); }); } // ===== SMOOTH SCROLL OFFSET ===== function initSmoothScroll() { document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function(e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { const offset = 80; const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - offset; window.scrollTo({ top: targetPosition, behavior: 'smooth' }); } }); }); } // ===== TOAST SYSTEM ===== function showToast(message, type = 'success') { // Remove existing toast const existingToast = document.getElementById('toast'); if (existingToast) existingToast.remove(); const iconMap = { success: 'check-circle', error: 'alert-circle', info: 'info' }; const colorMap = { success: 'text-green-400', error: 'text-red-400', info: 'text-blue-400' }; const toast = document.createElement('div'); toast.id = 'toast'; toast.className = 'fixed bottom-6 right-6 z-[60] flex'; toast.innerHTML = `