/* FinCosmos leaderboard. All numbers come from data.js (window.FC), generated by leaderboard/space_build.py from the E1 records. No numbers are typed here. */ (function () { "use strict"; const D = window.FC; const $ = (s, r = document) => r.querySelector(s); const $$ = (s, r = document) => Array.from(r.querySelectorAll(s)); const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c])); const pct = (x) => Math.round(100 * x) + "%"; const f1 = (x) => Number(x).toFixed(1); const minus = (s) => String(s).replace(/^-/, "−"); const median = (xs) => { const s = [...xs].sort((a, b) => a - b), m = s.length >> 1; return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2; }; const NS = "http://www.w3.org/2000/svg"; document.documentElement.classList.add("js"); /* ---------- order, lookups ---------- */ const isAgent = (a) => a.kind === "agent"; const ranked = D.agents.filter(isAgent).sort((a, b) => b.accepted / b.n - a.accepted / a.n || b.quality - a.quality); const baselines = D.agents.filter((a) => !isAgent(a)); const ORDER = ranked.concat(baselines); const byKey = Object.fromEntries(D.agents.map((a) => [a.key, a])); const vetoName = Object.fromEntries(D.vetoes.map((v) => [v.id, v.name])); const N = D.sessions_total; const signedTotal = D.sessions.filter((s) => s.s).length; const acceptedTotal = D.agents.reduce((t, a) => t + a.accepted, 0); const arxiv = D.paper.arxiv; const paperUrl = arxiv ? `https://arxiv.org/abs/${arxiv}` : "#"; const hfUrl = arxiv ? `https://huggingface.co/papers/${arxiv}` : "#"; const dataUrl = "https://huggingface.co/datasets/TheFinAI/FinCosmos"; /* ---------- tooltip ---------- */ const tip = $("#tip"); function showTip(e, html) { tip.innerHTML = html; tip.classList.add("on"); const r = tip.getBoundingClientRect(); let x = e.clientX + 14, y = e.clientY + 14; if (x + r.width > innerWidth - 8) x = e.clientX - r.width - 14; if (y + r.height > innerHeight - 8) y = e.clientY - r.height - 14; tip.style.left = x + "px"; tip.style.top = y + "px"; } const hideTip = () => tip.classList.remove("on"); function bindTip(node, html) { node.addEventListener("mousemove", (e) => showTip(e, typeof html === "function" ? html() : html)); node.addEventListener("mouseleave", hideTip); } /* ---------- shared numbers, links ---------- */ const NUM = { sessions: N, accepted: acceptedTotal, signed: signedTotal }; $$("[data-n]").forEach((n) => (n.textContent = NUM[n.dataset.n])); $$("[data-paper]").forEach((a) => (a.href = paperUrl)); $("#paperLinks").innerHTML = arxiv ? `arXiv ${arxiv} ↗Hugging Face Papers ↗Scores and tasks ↗` : ""; $("#footLinks").innerHTML = (arxiv ? `Paper · arXiv ${arxiv} ↗Hugging Face Papers ↗` : "") + `Scores and tasks ↗Evaluator ${esc(D.evaluator)} · updated ${esc(D.updated)}`; $("#stats").innerHTML = [ [N, "sessions on " + D.tasks_n + " tasks"], [acceptedTotal, "accepted"], [signedTotal, "signed off, all vetoed"], [D.paper.vetoes, "vetoes in " + D.paper.dimensions + " dimensions"], ].map(([b, s]) => `
${b}${s}
`).join(""); /* ---------- rotator ---------- */ (function () { const r = $("#rotator"), names = ranked.map((a) => a.name); let i = 0; r.textContent = names[0]; if (matchMedia("(prefers-reduced-motion: reduce)").matches) return; setInterval(() => { r.classList.add("off"); setTimeout(() => { i = (i + 1) % names.length; r.textContent = names[i]; r.classList.remove("off"); }, 260); }, 2400); })(); /* ---------- orbit map ---------- */ (function () { const host = $("#orbit"), C = 170, rOf = (q) => 14 + q * 1.06, ACC = 140; const svg = document.createElementNS(NS, "svg"); svg.setAttribute("viewBox", "-14 -14 368 368"); svg.setAttribute("role", "img"); svg.setAttribute("aria-label", `${N} sessions as stars; distance from the center is quality before vetoes; none reaches the accepted orbit.`); let g = ``; g += ``; for (let t = 0; t < D.tasks_n; t++) { const a = ((t * 36 - 90) * Math.PI) / 180; g += ``; const m = (((t + 0.5) * 36 - 90) * Math.PI) / 180; g += `T${t}`; } [25, 50, 75, 100].forEach((q) => { g += ``; g += `${q}`; }); g += ``; g += `accepted orbit · ${acceptedTotal} sessions`; svg.innerHTML = g; const agentIdx = Object.fromEntries(D.agents.map((a, i) => [a.key, i])); const stars = D.sessions.map((s) => { const slot = agentIdx[s.a] * 3 + (s.r - 1); const deg = s.t * 36 + 1.4 + slot * (33.2 / 14) - 90, a = (deg * Math.PI) / 180, r = rOf(s.q); const x = C + r * Math.cos(a), y = C + r * Math.sin(a); const grp = document.createElementNS(NS, "g"); grp.setAttribute("class", "star"); const base = byKey[s.a].kind === "agent" ? "#2b6cb0" : "#9aa6b6"; grp.innerHTML = (s.s ? `` : "") + `` + ``; bindTip(grp, () => `${esc(byKey[s.a].name)} · Task ${s.t}, session ${s.r}
Quality before vetoes ${f1(s.q)}
` + (s.s ? `Signed off by the investor
` : `Ended: ${s.e === "max_turns" ? "turn limit" : "investor walked away"}
`) + `${s.v.length} of 15 vetoes fail: ${s.v.join(", ")}`); svg.appendChild(grp); return { s, grp }; }); host.appendChild(svg); const chips = $("#orbitChips"), opts = [{ key: "all", name: "All" }].concat(ORDER); chips.innerHTML = opts.map((o, i) => ``).join(""); function pick(k) { $$(".chip", chips).forEach((c) => c.setAttribute("aria-selected", c.dataset.k === k)); stars.forEach(({ s, grp }) => grp.classList.toggle("dim", k !== "all" && s.a !== k)); const ss = D.sessions.filter((s) => k === "all" || s.a === k); const acc = k === "all" ? acceptedTotal : byKey[k].accepted; $("#orbitSigned").textContent = ss.filter((s) => s.s).length; $("#orbitAccepted").textContent = acc; const q = k === "all" ? ss.reduce((t, s) => t + s.q, 0) / ss.length : byKey[k].quality; $("#orbitEnds").innerHTML = [ [f1(q), "mean quality before vetoes"], [f1(ss.reduce((t, s) => t + s.v.length, 0) / ss.length), "vetoes failed per session"], [ss.length, "sessions"], [ss.filter((s) => s.e === "blocked").length, "investor walked away"], ].map(([b, s]) => `
${b}${s}
`).join(""); } chips.addEventListener("click", (e) => { const b = e.target.closest(".chip"); if (b) pick(b.dataset.k); }); pick("all"); })(); /* ---------- ticker ---------- */ (function () { const items = ORDER.map((a, i) => `${isAgent(a) ? "#" + (i + 1) : "base"}${esc(a.name)}quality ${f1(a.quality)} · signed off ${a.signed} · accepted ${a.accepted}`).join(""); $("#tickerTrack").innerHTML = items + items + items + items; })(); /* ---------- replay ---------- */ (function () { const cases = D.replay || []; if (!cases.length) { $("#replay").hidden = true; $$('[data-sec="replay"], a[href="#replay"]').forEach((a) => (a.hidden = true)); return; } const KIND = { intent: ["Intent", "The strategy is not the one the investor holds."], data: ["Data", "The reported numbers cannot be rebuilt, or contradict the delivered files."], time: ["Time", "The backtest uses data after the cutoff, or trades before its signal."], }; let i = 0, marks = new Set(), done = false, score = [0, 0]; const chk = $("#rChecks"); function render() { const c = cases[i]; marks = new Set(); done = false; $("#rKick").textContent = `Task ${c.task} · ${c.persona} · ${c.agent}`; $("#rN").textContent = `Session ${i + 1} of ${cases.length}`; $("#rAsk").innerHTML = `What the investor holds (hidden from the agent)${esc(c.ask)}`; const last = c.chat.length - 1; $("#rChat").innerHTML = c.chat.map((m, j) => { const so = j === last && m.who === "investor"; return `
${m.who === "investor" ? "Investor" : esc(c.agent)} · turn ${m.turn}${so ? ' ✓ signed off' : ""}${esc(m.text)}
`; }).join(""); const rep = Object.entries(c.reported || {}); $("#rReported").innerHTML = rep.length ? `As reported by the agent` + rep.map(([k, v]) => `
${esc(minus(v))}${esc(k)}
`).join("") : ""; chk.innerHTML = c.checks.map((k) => ``).join(""); $("#rPrompt").hidden = false; $("#rVerdict").hidden = true; $("#rCheck").hidden = false; $("#rReveal").hidden = false; $("#rNext").hidden = true; $("#rScore").textContent = score[1] ? `You: ${score[0]} of ${score[1]} right` : ""; } chk.addEventListener("click", (e) => { const b = e.target.closest("button.ck"); if (!b || done) return; const k = b.dataset.kind, on = !marks.has(k); on ? marks.add(k) : marks.delete(k); b.setAttribute("aria-pressed", on); $(".ck-ic", b).textContent = on ? "✗" : "?"; }); function open(guessed) { const c = cases[i]; done = true; let right = 0; chk.innerHTML = c.checks.map((k) => { const marked = marks.has(k.kind), ok = marked === !k.ok; if (ok) right++; const you = guessed ? `${ok ? "you got this" : marked ? "you marked it wrong" : "you missed it"}` : ""; return `
${k.ok ? "✓" : "✗"}${KIND[k.kind][0]} · ${esc(k.title)}${you}

${esc(k.detail)}

${k.vetoes && k.vetoes.length ? `${k.vetoes.map((v) => esc(v + " " + (vetoName[v] || ""))).join(" · ")}` : ""}
`; }).join(""); if (guessed) { score[0] += right; score[1] += c.checks.length; } $("#rScore").textContent = score[1] ? `You: ${score[0]} of ${score[1]} right` : ""; $("#rVerdict").innerHTML = `Investor: ✓ signed off   FinCosmos: ✗ rejected
${c.vetoes_failed.length} of 15 vetoes fail (${c.vetoes_failed.map(esc).join(", ")}). Quality before vetoes: ${f1(c.quality)}.`; $("#rVerdict").hidden = false; $("#rPrompt").hidden = true; $("#rCheck").hidden = true; $("#rReveal").hidden = true; $("#rNext").hidden = false; $("#rNext").textContent = i === cases.length - 1 ? "Start over →" : "Next session →"; } $("#rCheck").addEventListener("click", () => open(true)); $("#rReveal").addEventListener("click", () => open(false)); $("#rNext").addEventListener("click", () => { i = (i + 1) % cases.length; if (i === 0) score = [0, 0]; render(); }); render(); })(); /* ---------- leaderboard ---------- */ (function () { const lerp = (a, b, t) => Math.round(a + (b - a) * t); const heat = (v, max) => { const t = Math.max(0, Math.min(1, v / max)), c = [lerp(238, 43, t), lerp(243, 108, t), lerp(249, 176, t)]; return `background:rgb(${c});color:${t > 0.55 ? "#fff" : "#0f1a2a"}`; }; const CATN = ["Data", "Strategy", "Backtest", "Assess.", "UX"]; const COLS = [ { k: "rank", h: "#", v: (a) => ORDER.indexOf(a), asc: true }, { k: "agent", h: "Agent", v: (a) => a.name, asc: true }, { k: "accepted", h: "Accepted", v: (a) => a.accepted / a.n }, { k: "signed", h: "Signed off", v: (a) => a.signed / a.n }, { k: "quality", h: "Quality", v: (a) => a.quality }, ...CATN.map((h, j) => ({ k: "c" + j, h, v: (a) => a.cats[j] })), { k: "vetoes", h: "Vetoes", v: (a) => a.vetoes_mean, asc: true }, { k: "asked", h: "Asked", v: (a) => a.coverage }, { k: "usd", h: "Cost", v: (a) => a.usd, asc: true }, ]; let sortK = "rank", asc = true, openKey = null; const lb = $("#lb"); function cells(a) { const rk = isAgent(a) ? ranked.indexOf(a) + 1 : "—"; return `${rk}` + `${esc(a.name)}${esc(a.model)}` + `${pct(a.accepted / a.n)}` + `${pct(a.signed / a.n)}` + `${f1(a.quality)}[${a.ci.map(f1).join(", ")}]` + a.cats.map((c) => `${f1(c)}`).join("") + `${f1(a.vetoes_mean)}${pct(a.coverage)}$${a.usd.toFixed(2)}`; } function detail(a) { const ss = D.sessions.filter((s) => s.a === a.key); const grid = D.tasks.map((t) => { const ts = ss.filter((s) => s.t === t.seed).sort((x, y) => x.r - y.r); return `
T${t.seed}${ts.map((s) => `
Signed off' : ""}`)}">
`).join("")}
`; }).join(""); const vb = D.vetoes.map((v) => `${v.id} ${esc(v.name)}
${pct(a.veto[v.id])}`).join(""); const pl = [["Turns per session", f1(a.turns)], ["Turns cut at 300 s", pct(a.cut)], ["Minutes per session", f1(a.minutes)], ["Input tokens (M)", a.tokens_m.toFixed(2)], ["Investor's details stated by the end", `${f1(a.stated)} of ${f1(a.hidden)}`], ["Cost per session", "$" + a.usd.toFixed(2)]] .map(([k, v]) => `${k}${v}`).join(""); return `

Every session, by task

${grid}
quality before vetoes, darker is highersigned off by the investor
` + `

Share of sessions failing each veto

${vb}
` + `

Process

${pl}
`; } function render() { const col = COLS.find((c) => c.k === sortK); const rows = [...ORDER].sort((x, y) => { const a = col.v(x), b = col.v(y); const d = typeof a === "string" ? a.localeCompare(b) : a - b; return asc ? d : -d; }); lb.innerHTML = `${COLS.map((c) => `${c.h}`).join("")}` + rows.map((a) => `${cells(a)}` + (openKey === a.key ? `${detail(a)}` : "")).join("") + ""; $$(".tcell", lb).forEach((n) => bindTip(n, n.dataset.tip)); fit(); } // The table scrolls sideways on narrow screens; keep the open row's breakdown in view. function fit() { const d = $(".det", lb); if (d) d.style.width = lb.parentElement.clientWidth + "px"; } addEventListener("resize", fit); lb.addEventListener("click", (e) => { const th = e.target.closest("th"); if (th) { const c = COLS.find((x) => x.k === th.dataset.k); if (sortK === c.k) asc = !asc; else { sortK = c.k; asc = !!c.asc; } render(); return; } const tr = e.target.closest("tr.row"); if (tr) { openKey = openKey === tr.dataset.k ? null : tr.dataset.k; render(); } }); render(); })(); /* ---------- graders ---------- */ (function () { const G = [ ["The investor signs off", "signed", "count as a success when the investor's sign-off is the grade"], ["+ LLM-judged vetoes", "data", "still pass when an LLM judge also checks its four vetoes (2.7, 4.1, 5.1, 5.6)"], ["All 15 vetoes · FinCosmos", "pass", "pass once programs also check the delivery itself"], ]; const COLOR = { signed: "#c9a24a", data: "#2b6cb0", pass: "#2f855a" }; const seg = $("#graderSeg"); seg.innerHTML = G.map((g, i) => ``).join(""); const bars = $("#grBars"); bars.innerHTML = ORDER.map((a) => `
${esc(a.name)}
`).join(""); function pick(i) { $$("button", seg).forEach((b) => b.setAttribute("aria-selected", +b.dataset.i === i)); const total = D.agents.reduce((t, a) => t + a.graders[i], 0); $("#grTotal").textContent = total; $("#grTotal").style.color = i === 2 ? "#c05621" : "#0f1a2a"; $("#grTotalNote").textContent = `of ${N} sessions ${G[i][2]}.`; $$(".hrow", bars).forEach((r) => { const a = byKey[r.dataset.k], v = a.graders[i]; $("i", r).style.width = (100 * v) / a.n + "%"; $("i", r).style.background = isAgent(a) ? COLOR[G[i][1]] : ""; $("em", r).textContent = `${v} / ${a.n}`; }); } seg.addEventListener("click", (e) => { const b = e.target.closest("button"); if (b) pick(+b.dataset.i); }); pick(0); const sat = D.sessions.filter((s) => s.s); const groups = [ ["Audit and process", ["3.7", "3.8"]], ["Recomputation", ["3.2"]], ["LLM-judged", ["4.1", "5.1", "5.6"]], ["Point-in-time", ["1.1", "3.1"]], ["Strategy fidelity", ["2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7"]], ].map(([n, ids]) => [n, ids, sat.filter((s) => s.v.some((v) => ids.includes(v))).length]).sort((a, b) => b[2] - a[2]); $("#grWhy").innerHTML = groups.map(([n, ids, c]) => `
${n}
${pct(c / sat.length)}
`).join(""); $$("#grWhy .hrow").forEach((r, j) => bindTip(r, `${groups[j][0]} (${groups[j][1].join(", ")})
${groups[j][2]} of ${sat.length} signed-off sessions fail at least one`)); })(); /* ---------- workflow funnel ---------- */ (function () { const STEPS = [ ["The investor's strategy", "The delivered strategy is the one the investor holds", "2.1–2.7"], ["Data within the cutoff", "No delivered row is dated after the cutoff", "1.1"], ["No look-ahead", "Every fill comes after its signal", "3.1"], ["Reproducible", "Delivered trades reproduce the reported returns", "3.2 ≥ 2"], ]; const agentsN = ranked.reduce((t, a) => t + a.n, 0); const cell = (v, n, base) => `
${v}
`; $("#funnel").innerHTML = `Step${ORDER.map((a) => `${esc(a.name)}`).join("")}In sequence · ${agentsN} agent sessions` + STEPS.map((s, k) => `(${k + 1})${s[0]}${s[1]} · ${s[2]}${ORDER.map((a) => `${cell(a.funnel[k], a.n, !isAgent(a))}`).join("")}${cell(D.seq[k], agentsN)}`).join("") + ""; })(); /* ---------- elicitation ---------- */ (function () { const row = (a, v, sub) => `
${esc(a.name)}
${pct(v)}
`; $("#elCov").innerHTML = ORDER.map((a) => row(a, a.coverage)).join(""); $("#elAssume").innerHTML = ORDER.filter((a) => a.assume != null).map((a) => row(a, a.assume)).join(""); })(); /* ---------- learning ---------- */ (function () { const L = D.learning, n = L.map((t) => t.sessions); const lastCount = {}; L.forEach((t) => (lastCount[t.last_veto] = (lastCount[t.last_veto] || 0) + 1)); const [topV, topN] = Object.entries(lastCount).sort((a, b) => b[1] - a[1])[0]; const mFirst = median(L.map((t) => t.first)), mF5 = median(L.map((t) => t.first5)), mL5 = median(L.map((t) => t.last5)); $("#learnStats").innerHTML = [ [`${L.length} / ${L.length}`, "tasks learned, none passed at the first attempt"], [median(n), "median sessions to the first acceptance"], [n.reduce((a, b) => a + b, 0), `sessions in all, ${Math.min(...n)} to ${Math.max(...n)} per task`], [`${f1(mFirst)} → ${f1(mL5)}`, "median failed vetoes, first session → last five"], ].map(([b, s]) => `
${b}${s}
`).join("") + `

The last veto to clear is most often ${topV} ${esc(vetoName[topV])}, in ${topN} of ${L.length} tasks. The leak-free rule withholds its reasons, so the agent has to infer them from the investor's words.

`; const W = 640, H = 300, P = { l: 40, r: 70, t: 14, b: 34 }, X = ["1st session", "First 5", "Last 5", "Accepted"]; const ymax = Math.max(15, ...L.map((t) => t.first)); const x = (i) => P.l + (i * (W - P.l - P.r)) / 3, y = (v) => P.t + (1 - v / ymax) * (H - P.t - P.b); const pts = (vals) => vals.map((v, i) => `${x(i)},${y(v)}`).join(" "); let s = `${[0, 3, 6, 9, 12, 15].map((v) => ``).join("")}`; s += `${[0, 3, 6, 9, 12, 15].map((v) => `${v}`).join("")}${X.map((t, i) => `${t}`).join("")}`; s += `Failed vetoes per session`; L.forEach((t, j) => { const v = [t.first, t.first5, t.last5, 0]; s += `${v.map((u, i) => ``).join("")}`; }); const mv = [mFirst, mF5, mL5, 0]; s += ``; s += mv.map((u, i) => ``).join(""); s += mv.slice(0, 3).map((u, i) => `${f1(u)}`).join(""); s += `0 · accepted`; const host = $("#learnChart"); host.innerHTML = `${s}`; $$(".tl", host).forEach((g) => { const t = L[+g.dataset.j]; g.addEventListener("mouseenter", () => $$("polyline,circle", g).forEach((p) => { if (p.getAttribute("stroke") !== "transparent") { p.setAttribute(p.tagName === "circle" ? "fill" : "stroke", "#4a576a"); } })); g.addEventListener("mouseleave", () => $$("polyline,circle", g).forEach((p) => { if (p.getAttribute("stroke") !== "transparent") { p.setAttribute(p.tagName === "circle" ? "fill" : "stroke", "#b8c2cf"); } })); bindTip(g, `Difficulty ${t.difficulty} · ${t.sessions} sessions to acceptance
Failed vetoes ${t.first} first → ${f1(t.first5)} first five → ${f1(t.last5)} last five
Investor signed off in ${pct(t.satisfied)} of practice sessions
Last to clear ${t.last_veto} ${esc(vetoName[t.last_veto] || "")}`); }); })(); /* ---------- benchmark ---------- */ (function () { const P = D.paper; $("#parts").innerHTML = [ ["Strategy Generator", "A hidden strategy per task", `A strategy fixes one option for each of six components: stock selection, market timing, portfolio construction, risk control, execution, and transaction cost. New tasks can be drawn whenever a released set saturates.`, [`~${P.strategies} strategies before parameters`, "6 components", "Seeded and reproducible"]], ["User Simulator", "An investor who answers, never volunteers", `A language model plays the investor. It opens with a vague request, states a detail only when the agent asks about it or proposes it, and objects when a proposal conflicts with what it wants.`, [`${P.personas} personas`, "Never says “point-in-time” or “cutoff”", "Signs off only with cited evidence"]], ["Evaluator", "The delivery, not the conversation", `Programs recompute numbers and check dates, an LLM judge grades only semantics, and every score carries its evidence. Feedback is leak-free: it never reveals the hidden strategy.`, [`${P.dimensions} dimensions, ${P.vetoes} vetoes`, "No reference answer needed", "Every score tied to an evaluator version"]], ["Setup", "Frozen, so scores compare", `The released benchmark freezes the first ten sampled tasks (seeds 0 to 9) on U.S. equities. The agent receives no data: it searches the Web and calls ${P.fmp_apis} financial APIs, then must stay before each task's cutoff.`, [`${D.tasks_n} tasks × ${D.sessions_per_task} sessions`, `${P.turns} turns of ${P.seconds_per_turn} s`, "One data cutoff per task"]], ].map(([h, k, p, li]) => `
${k}

${h}

${p}

    ${li.map((x) => `
  • ${x}
  • `).join("")}
`).join(""); const J = { program: "program", LLM: "LLM judge", "program + LLM": "program + LLM" }; $("#vgrid").innerHTML = D.vetoes.map((v) => `
${v.id} · ${esc(v.cat)}${J[v.judge] || esc(v.judge)}

${esc(v.name)}

${v.sat_fail}of ${signedTotal}

${esc(v.text)}

`).join(""); const H = D.human; $("#trust").innerHTML = [ [pct(H.agent / H.sessions), `of failed sessions are the agent's fault, according to two financial experts (${H.agent} of ${H.sessions} sampled; ${H.simulator} the simulator, ${H.evaluator} the evaluator).`], [`κ = ${H.kappa_judge}`, `agreement between the LLM judge and the experts on the judge-graded vetoes; the experts agree with each other at ${H.kappa_experts}.`], [`${acceptedTotal} of ${N}`, `sessions accepted. Every session the investor signed off fails at least one program check.`], ].map(([b, p]) => `
${b}

${p}

`).join(""); })(); /* ---------- chrome: reveal, header, progress, nav ---------- */ const io = new IntersectionObserver((es) => es.forEach((e) => { if (e.isIntersecting) { e.target.classList.add("in"); io.unobserve(e.target); } }), { threshold: 0.08 }); $$(".reveal").forEach((n) => io.observe(n)); const header = $("#header"), prog = $("#progress"); const onScroll = () => { header.classList.toggle("scrolled", scrollY > 10); const h = document.documentElement.scrollHeight - innerHeight; prog.style.transform = `scaleX(${h > 0 ? scrollY / h : 0})`; }; addEventListener("scroll", onScroll, { passive: true }); onScroll(); const links = $$("#navLinks a"); const so = new IntersectionObserver((es) => es.forEach((e) => { if (e.isIntersecting) links.forEach((a) => a.classList.toggle("active", a.dataset.sec === e.target.id)); }), { rootMargin: "-45% 0px -50% 0px" }); links.forEach((a) => { const s = document.getElementById(a.dataset.sec); if (s) so.observe(s); }); })();