(function () { var root = document.documentElement; var themeToggle = document.getElementById('theme-toggle'); var navToggle = document.getElementById('nav-toggle'); var navList = document.getElementById('nav-list'); var year = document.getElementById('year'); try { var saved = localStorage.getItem('theme'); if (saved) { root.setAttribute('data-theme', saved); if (saved === 'dark') themeToggle.textContent = '☀️'; } else { var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; root.setAttribute('data-theme', prefersDark ? 'dark' : 'light'); themeToggle.textContent = prefersDark ? '☀️' : '🌙'; } } catch (e) {} if (themeToggle) { themeToggle.addEventListener('click', function () { var current = root.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'; var next = current === 'dark' ? 'light' : 'dark'; root.setAttribute('data-theme', next); themeToggle.textContent = next === 'dark' ? '☀️' : '🌙'; try { localStorage.setItem('theme', next); } catch (e) {} }); } if (navToggle && navList) { navToggle.addEventListener('click', function () { var isOpen = navList.classList.contains('open'); navList.classList.toggle('open'); navToggle.setAttribute('aria-expanded', String(!isOpen)); }); navList.querySelectorAll('a').forEach(function (a) { a.addEventListener('click', function () { navList.classList.remove('open'); navToggle.setAttribute('aria-expanded', 'false'); }); }); } if (year) { year.textContent = String(new Date().getFullYear()); } // Smooth scroll for in-page anchors document.querySelectorAll('a[href^="#"]').forEach(function (a) { a.addEventListener('click', function (e) { var id = a.getAttribute('href'); if (id.length > 1) { var el = document.querySelector(id); if (el) { e.preventDefault(); el.scrollIntoView({ behavior: 'smooth' }); } } }); }); // Reveal-on-scroll var observer = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting) { entry.target.classList.add('visible'); observer.unobserve(entry.target); } }); }, { threshold: 0.1 }); document.querySelectorAll('[data-reveal]').forEach(function (el) { observer.observe(el); }); // Skills horizontal scroll with arrows var skillsContainer = document.getElementById('skills-container'); var left = document.getElementById('skills-left'); var right = document.getElementById('skills-right'); function scrollByAmount(amount) { if (!skillsContainer) return; skillsContainer.scrollBy({ left: amount, behavior: 'smooth' }); } if (left) left.addEventListener('click', function () { scrollByAmount(-300); }); if (right) right.addEventListener('click', function () { scrollByAmount(300); }); // Back to top button var backToTop = document.getElementById('back-to-top'); if (backToTop) { window.addEventListener('scroll', function () { if (window.scrollY > 600) backToTop.classList.add('show'); else backToTop.classList.remove('show'); }); backToTop.addEventListener('click', function () { window.scrollTo({ top: 0, behavior: 'smooth' }); }); } })();