(() => {
  "use strict";
  const palettes = {
    universe:["#616161","#dadada","#111315","rgba(97, 97, 97,.38)"],
    "computer-vision":["#555555","#afafaf","#0d0d0d","rgba(85, 85, 85,.38)"],
    "incident-monitoring":["#898989","#c9c9c9","#111111","rgba(137, 137, 137,.38)"],
    "it-helpdesk":["#919191","#cecece","#131313","rgba(145, 145, 145,.36)"],
    "kotlin-policy":["#717171","#717171","#0f0f0f","rgba(113, 113, 113,.38)"],
    "malaysia-cost":["#606060","#afafaf","#151515","rgba(96, 96, 96,.38)"],
    "network-subnet":["#606060","#a5a5a5","#101010","rgba(96, 96, 96,.38)"],
    "sentiment-analysis":["#535353","#909090","#0f0f0f","rgba(83, 83, 83,.38)"],
    "url-shortener":["#848484","#c9c9c9","#131313","rgba(132, 132, 132,.38)"],
    "academic-evidence":["#4d4d4d","#a2a2a2","#0e0e0e","rgba(77, 77, 77,.36)"],
    "ai-architect":["#535353","#999999","#0d0d0d","rgba(83, 83, 83,.38)"],
    "student-performance":["#8b8b8b","#dddddd","#141414","rgba(139, 139, 139,.36)"],
    legal:["#3f3f3f","#a1a1a1","#171717","rgba(63, 63, 63,.34)"]
  };
  const root = document.documentElement;
  let theme = root.dataset.scrollTheme || "";
  if (!theme) {
    const match = location.pathname.match(/\/projects\/([^/]+)/);
    theme = match ? match[1] : (location.pathname.includes("privacy") || location.pathname.includes("terms") ? "legal" : "universe");
  }
  const p = palettes[theme] || palettes.universe;
  root.style.setProperty("--apu-scroll-thumb",p[0]);
  root.style.setProperty("--apu-scroll-thumb-2",p[1]);
  root.style.setProperty("--apu-scroll-track",p[2]);
  root.style.setProperty("--apu-scroll-glow",p[3]);
  root.dataset.scrollTheme = theme;
  let bar = document.getElementById("scrollProgress") || document.querySelector(".apu-scroll-progress");
  if (!bar) {
    bar = document.createElement("div");
    bar.className = "apu-scroll-progress";
    bar.setAttribute("aria-hidden","true");
    document.body.prepend(bar);
  }
  let ticking = false;
  const update = () => {
    const doc = document.documentElement;
    const max = Math.max(0, doc.scrollHeight - doc.clientHeight);
    const value = max ? Math.min(1, Math.max(0, doc.scrollTop / max)) : 0;
    bar.style.transform = `scaleX(${value})`;
    ticking = false;
  };
  const schedule = () => {
    if (!ticking) { ticking = true; requestAnimationFrame(update); }
  };
  addEventListener("scroll",schedule,{passive:true});
  addEventListener("resize",schedule,{passive:true});
  update();
})();
