/* ===================================================================== Academy for Learning AI — shared front-end behavior Vanilla JS, no dependencies. Respects prefers-reduced-motion. ===================================================================== */ (function () { "use strict"; var reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; /* ---- Sticky header shadow on scroll ---- */ var header = document.querySelector(".site-header"); function onScrollHeader() { if (!header) return; header.classList.toggle("is-scrolled", window.scrollY > 12); } /* ---- Mobile nav toggle ---- */ var toggle = document.querySelector(".nav__toggle"); var links = document.querySelector(".nav__links"); if (toggle && links) { toggle.addEventListener("click", function () { var open = links.classList.toggle("is-open"); toggle.setAttribute("aria-expanded", open ? "true" : "false"); }); links.addEventListener("click", function (e) { if (e.target.tagName === "A") { links.classList.remove("is-open"); toggle.setAttribute("aria-expanded","false"); } }); } /* ---- Smooth scroll for in-page anchors (with sticky-header offset) ---- */ document.querySelectorAll('a[href^="#"]').forEach(function (a) { a.addEventListener("click", function (e) { var id = a.getAttribute("href"); if (id === "#" || id.length < 2) return; var el = document.querySelector(id); if (!el) return; e.preventDefault(); var top = el.getBoundingClientRect().top + window.scrollY - 80; window.scrollTo({ top: top, behavior: reduceMotion ? "auto" : "smooth" }); }); }); /* ---- Scroll reveal via IntersectionObserver ---- */ var revealEls = document.querySelectorAll(".reveal"); if ("IntersectionObserver" in window && !reduceMotion) { var io = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting) { entry.target.classList.add("is-visible"); io.unobserve(entry.target); } }); }, { threshold: 0.12, rootMargin: "0px 0px -8% 0px" }); revealEls.forEach(function (el) { io.observe(el); }); } else { revealEls.forEach(function (el) { el.classList.add("is-visible"); }); } /* ---- Lightweight parallax (hero bg + band glow) ---- */ var heroBg = document.querySelector(".hero__bg"); var bandGlow = document.querySelector(".parallax-band__glow"); var ticking = false; function applyParallax() { var y = window.scrollY; if (heroBg) heroBg.style.transform = "translate3d(0," + (y * 0.18).toFixed(1) + "px,0)"; if (bandGlow) { var rect = bandGlow.parentElement.getBoundingClientRect(); bandGlow.style.transform = "translate3d(0," + (rect.top * -0.08).toFixed(1) + "px,0)"; } ticking = false; } function onScroll() { onScrollHeader(); if (!reduceMotion && !ticking) { window.requestAnimationFrame(applyParallax); ticking = true; } } window.addEventListener("scroll", onScroll, { passive: true }); onScrollHeader(); if (!reduceMotion) applyParallax(); /* ---- Footer year ---- */ var yr = document.getElementById("year"); if (yr) yr.textContent = new Date().getFullYear(); })();