(function () { 'use strict'; var root = document.documentElement; var themeToggle = document.getElementById('themeToggle'); if (themeToggle) { themeToggle.addEventListener('click', function () { var next = root.dataset.theme === 'dark' ? 'light' : 'dark'; root.dataset.theme = next; try { localStorage.setItem('stg-site-theme', next); } catch (error) {} }); } var revealEls = Array.prototype.slice.call(document.querySelectorAll('.reveal')); var revealTick = 0; function revealInViewport() { var viewportHeight = window.innerHeight || document.documentElement.clientHeight; revealEls.forEach(function (el) { if (el.classList.contains('visible')) return; var rect = el.getBoundingClientRect(); if (rect.top < viewportHeight * 0.94 && rect.bottom > 0) el.classList.add('visible'); }); } function scheduleReveal() { if (revealTick) return; revealTick = window.requestAnimationFrame(function () { revealTick = 0; revealInViewport(); }); } revealInViewport(); window.addEventListener('scroll', scheduleReveal, { passive: true }); window.addEventListener('resize', scheduleReveal); setTimeout(function () { revealEls.forEach(function (el) { el.classList.add('visible'); }); }, 2000); var lightbox = document.getElementById('lightbox'); var lightboxImg = lightbox ? lightbox.querySelector('img') : null; function closeLightbox() { if (!lightbox || lightbox.hidden) return; lightbox.hidden = true; lightboxImg.removeAttribute('src'); document.body.style.overflow = ''; } if (lightbox) { document.querySelectorAll('img.zoomable').forEach(function (img) { img.addEventListener('click', function () { lightboxImg.src = img.currentSrc || img.src; lightboxImg.alt = img.alt || ''; lightbox.hidden = false; document.body.style.overflow = 'hidden'; }); }); lightbox.addEventListener('click', closeLightbox); window.addEventListener('keydown', function (event) { if (event.key === 'Escape') closeLightbox(); }); } })();