import { jsx as n, jsxs as i, Fragment as Fe } from "react/jsx-runtime";
import { useMemo as he, useState as $, useRef as Z, useEffect as de } from "react";
import { useFrame as Qe } from "@react-three/fiber";
import { Html as De, Grid as At } from "@react-three/drei";
import * as Ye from "three";
import { Color as Dt } from "three";
function Nt({ vector: e, origin: t = [0, 0, 0], color: o = "#facc15" }) {
  const { dir: r, len: l, position: a } = he(() => {
    const c = new Ye.Vector3(...t), s = new Ye.Vector3(...e), d = c.distanceTo(s);
    return { dir: s.clone().sub(c).normalize(), len: d, position: c };
  }, [e, t]), h = he(() => new Ye.ArrowHelper(r, a, l, o, 0.2 * Math.min(l, 1) + 0.1, 0.1 * Math.min(l, 1) + 0.05), [r, l, a, o]);
  return /* @__PURE__ */ n("primitive", { object: h });
}
function _t(e, t = !1) {
  const o = [];
  for (let r = 0; r <= e; r++)
    for (let l = 0; l <= e - r; l++) {
      const a = e - r - l;
      if (a >= 0)
        if (!t)
          o.push([r, l, a]);
        else {
          const h = r === 0 ? [1] : [1, -1], c = l === 0 ? [1] : [1, -1], s = a === 0 ? [1] : [1, -1];
          for (const d of h)
            for (const m of c)
              for (const u of s)
                o.push([r * d, l * m, a * u]);
        }
    }
  return o;
}
function Ht({ vector: e, radius: t, distance: o, color: r }) {
  const { position: l, quaternion: a } = he(() => {
    const h = new Ye.Vector3(...e).normalize(), c = new Ye.Vector3(0, 1, 0), s = new Ye.Quaternion().setFromUnitVectors(c, h);
    return { position: h.clone().multiplyScalar(o / 2), quaternion: s };
  }, [e, o]);
  return /* @__PURE__ */ i("mesh", { position: l, quaternion: a, children: [
    /* @__PURE__ */ n("cylinderGeometry", { args: [t, t, o, 32] }),
    /* @__PURE__ */ n("meshStandardMaterial", { color: r, opacity: 0.5, transparent: !0 })
  ] });
}
function Wt({ complexity: e, lightlanes: t = !1, radius: o = 0.5, distance: r = 5, allSectors: l = !1, cumulative: a = !1 }) {
  const h = he(() => {
    const s = [], d = a ? 1 : e, m = e;
    for (let u = d; u <= m; u++) {
      const x = _t(u, l);
      for (const y of x)
        s.push({ vec: y, c: u });
    }
    return s;
  }, [e, l, a]), c = (s) => {
    const d = a ? Math.max(e, 1) : e;
    return `hsl(${270 * (1 - (d > 1 ? (s - 1) / (d - 1) : 1))}, 100%, 50%)`;
  };
  return /* @__PURE__ */ n("group", { children: h.map((s, d) => {
    const m = a ? c(s.c) : t ? "#ff33c5" : "#4ade80";
    return t ? /* @__PURE__ */ n(
      Ht,
      {
        vector: s.vec,
        radius: o,
        distance: r,
        color: m
      },
      `cyl-${d}-${s.vec.join(",")}-${s.c}`
    ) : /* @__PURE__ */ n(
      Nt,
      {
        vector: s.vec,
        color: m
      },
      `vec-${d}-${s.vec.join(",")}-${s.c}`
    );
  }) });
}
const Vt = "glitch:play-sound", jt = "glitch:stop-sound", we = {
  click: "ui.button_click",
  hover: "ui.button_hover",
  computeStart: "machine.compute_start",
  computeStep: "machine.compute_step",
  computeDone: "machine.compute_done"
};
function Ct(e, t) {
  typeof window > "u" || window.dispatchEvent(new CustomEvent(e, { detail: t }));
}
function Ce(e, t, o) {
  try {
    if (e?.playSound) {
      e.playSound(t, o);
      return;
    }
  } catch {
  }
  Ct(Vt, { id: t, payload: o });
}
function Yt(e, t, o) {
  try {
    if (e?.stopSound) {
      e.stopSound(t, o);
      return;
    }
  } catch {
  }
  Ct(jt, { id: t, payload: o });
}
const Ue = 1e-12;
function ut(e = 123456789) {
  let t = e >>> 0;
  return function() {
    t |= 0, t = t + 1831565813 | 0;
    let r = Math.imul(t ^ t >>> 15, 1 | t);
    return r = r + Math.imul(r ^ r >>> 7, 61 | r) ^ r, ((r ^ r >>> 14) >>> 0) / 4294967296;
  };
}
function Ut(e, t = Math.random) {
  if (!Number.isFinite(e) || e <= 0) return 0;
  if (e < 30) {
    const h = Math.exp(-e);
    let c = 0, s = 1;
    do
      c++, s *= t();
    while (s > h);
    return c - 1;
  }
  const o = Math.max(1e-12, t()), r = t(), l = Math.sqrt(-2 * Math.log(o)) * Math.cos(2 * Math.PI * r), a = e + Math.sqrt(e) * l;
  return Math.max(0, Math.round(a));
}
function st(e) {
  return [e[0] ?? e.x, e[1] ?? e.y, e[2] ?? e.z];
}
function Gt(e, t, o) {
  return Math.sqrt(e * e + t * t + o * o);
}
function kt(e) {
  const t = 2 * Math.PI;
  let o = e % t;
  return o < 0 && (o += t), o;
}
function Jt(e) {
  const t = 2 * e() - 1, o = 2 * Math.PI * e();
  return {
    theta: Math.acos(Math.max(-1, Math.min(1, t))),
    phi: o
  };
}
function mt(e) {
  const t = 2 * Math.PI;
  let o = e % t;
  return o < 0 && (o += t), o > Math.PI && (o = t - o), o;
}
function Mt(e = Math.random) {
  const t = Math.max(1e-12, e()), o = e();
  return Math.sqrt(-2 * Math.log(t)) * Math.cos(2 * Math.PI * o);
}
function qt(e, t, o) {
  const r = Math.sin(t);
  return [
    e * r * Math.cos(o),
    e * Math.cos(t),
    e * r * Math.sin(o)
  ];
}
function Xt(e, t = !1, o = !1) {
  const r = [], l = o ? 1 : e, a = e;
  for (let h = l; h <= a; h++)
    for (let c = 0; c <= h; c++)
      for (let s = 0; s <= h - c; s++) {
        const d = h - c - s;
        if (!t) {
          r.push([c, s, d]);
          continue;
        }
        const m = c === 0 ? [1] : [1, -1], u = s === 0 ? [1] : [1, -1], x = d === 0 ? [1] : [1, -1];
        for (const y of m)
          for (const B of u)
            for (const F of x)
              r.push([c * y, s * B, d * F]);
      }
  return r;
}
function wt({
  D: e,
  complexity: t,
  allSectors: o = !1,
  cumulative: r = !1
}) {
  if (!Number.isFinite(e) || e <= 0) return [];
  if (!Number.isInteger(t) || t < 1) return [];
  const l = Xt(t, o, r), a = [];
  for (let h = 0; h < l.length; h++) {
    const [c, s, d] = l[h], m = Gt(c, s, d);
    m <= Ue || a.push([e * c / m, e * s / m, e * d / m]);
  }
  return a;
}
function Kt(e, t, o) {
  if (!e || e.length === 0 || !Number.isFinite(o) || o <= 0) return 0;
  const [r, l, a] = st(t), h = o * o;
  let c = 0;
  for (let s = 0; s < e.length; s++) {
    const [d, m, u] = st(e[s]), x = d * d + m * m + u * u;
    if (x <= Ue) continue;
    let y = (r * d + l * m + a * u) / x;
    y < 0 && (y = 0), y > 1 && (y = 1);
    const B = y * d, F = y * m, R = y * u, C = r - B, j = l - F, v = a - R;
    C * C + j * j + v * v < h && c++;
  }
  return c;
}
function Qt(e, t, o, r) {
  if (!e || e.length === 0 || !Number.isFinite(t) || t <= 0 || !Number.isFinite(r) || r <= 0) return 0;
  const [l, a, h] = st(o), s = t * t - 0.5 * r * r;
  let d = 0;
  for (let m = 0; m < e.length; m++) {
    const [u, x, y] = st(e[m]);
    l * u + a * x + h * y > s && d++;
  }
  return d;
}
function Bt({ D: e, lane_radius: t }) {
  if (!Number.isFinite(e) || e <= 0 || !Number.isFinite(t) || t <= 0) return 0;
  const o = t * t / (4 * e * e);
  return o <= 0 ? 0 : o > 1 ? 1 : o;
}
function Zt({ D: e, lane_radius: t, lane_length: o }) {
  if (!Number.isFinite(e) || e <= 0 || !Number.isFinite(t) || t <= 0 || !Number.isFinite(o) || o <= 0) return 0;
  if (o >= e - Ue)
    return Bt({ D: e, lane_radius: t });
  const r = t, l = o, a = e - l;
  if (r <= a) return 0;
  if (r >= e + l) return 1;
  const h = Math.sqrt(Math.max(0, e * e - l * l));
  let c;
  return r < h ? c = (e * e + l * l - r * r) / (2 * e * l) : r < e ? c = Math.sqrt(Math.max(0, 1 - r * r / (e * e))) : c = -1, Number.isFinite(c) ? (c < -1 && (c = -1), c > 1 && (c = 1), (1 - c) / 2) : 0;
}
function en({ flux: e, D: t, lane_radius: o, dt: r }) {
  if (!Number.isFinite(e) || e <= 0 || !Number.isFinite(r) || r <= 0) return 0;
  const l = Bt({ D: t, lane_radius: o });
  return e * l * r;
}
function tn({ flux: e, D: t, lane_radius: o, lane_length: r, dt: l }) {
  if (!Number.isFinite(e) || e <= 0 || !Number.isFinite(l) || l <= 0) return 0;
  const a = Zt({ D: t, lane_radius: o, lane_length: r });
  return e * a * l;
}
function Et({
  flux: e,
  D: t,
  lane_radius: o,
  dt: r,
  hitTestModel: l = "shell",
  lane_length: a
}) {
  return l === "segment" ? tn({ flux: e, D: t, lane_radius: o, lane_length: a, dt: r }) : en({ flux: e, D: t, lane_radius: o, dt: r });
}
function nn(e) {
  if (!e || typeof e != "object")
    throw new Error("createSamplingSimulation: config object is required.");
  const t = e.lane_radius ?? e.radius, o = e.D, r = e.complexity, l = e.flux, a = e.bin_size ?? 1, h = e.sub_bin_sampling ?? 4, c = e.thetaDrift ?? e.theta_drift ?? 0, s = e.thetaJitter ?? e.theta_jitter ?? 0, d = e.phiJitter ?? e.phi_jitter ?? 0, m = e.laneLength ?? e.lane_length ?? e.distance ?? o, u = e.hitTestModel ?? e.hit_test_model ?? "shell", x = e.observationMode ?? e.observation_mode ?? "orbit";
  if (!Number.isFinite(o) || o <= 0)
    throw new Error("createSamplingSimulation: D must be a positive number.");
  if (!Number.isFinite(t) || t <= 0)
    throw new Error("createSamplingSimulation: lane_radius (or radius) must be a positive number.");
  if (!Number.isInteger(r) || r < 1)
    throw new Error("createSamplingSimulation: complexity must be an integer >= 1.");
  if (!Number.isFinite(l) || l < 0)
    throw new Error("createSamplingSimulation: flux must be a finite number >= 0.");
  if (!Number.isFinite(a) || a <= 0)
    throw new Error("createSamplingSimulation: bin_size must be a positive number.");
  if (!Number.isInteger(h) || h < 1)
    throw new Error("createSamplingSimulation: sub_bin_sampling must be an integer >= 1.");
  if (!Number.isFinite(c))
    throw new Error("createSamplingSimulation: thetaDrift must be finite.");
  if (!Number.isFinite(s) || s < 0)
    throw new Error("createSamplingSimulation: thetaJitter must be a finite number >= 0.");
  if (!Number.isFinite(d) || d < 0)
    throw new Error("createSamplingSimulation: phiJitter must be a finite number >= 0.");
  if (!Number.isFinite(m) || m <= 0)
    throw new Error("createSamplingSimulation: laneLength/lane_length/distance must be a positive number.");
  if (u !== "shell" && u !== "segment")
    throw new Error('createSamplingSimulation: hitTestModel must be "shell" or "segment".');
  if (x !== "orbit" && x !== "randomSphere")
    throw new Error('createSamplingSimulation: observationMode must be "orbit" or "randomSphere".');
  return {
    D: o,
    lane_radius: t,
    complexity: r,
    flux: l,
    bin_size: a,
    sub_bin_sampling: h,
    theta: mt(e.theta ?? Math.PI / 2),
    phi: kt(e.phi ?? 0),
    velocity: e.velocity ?? 0,
    thetaDrift: c,
    thetaJitter: s,
    phiJitter: d,
    lane_length: m,
    hitTestModel: u,
    observationMode: x,
    allSectors: !!e.allSectors,
    cumulative: !!e.cumulative,
    usePoisson: e.usePoisson !== !1,
    seed: Number.isFinite(e.seed) ? e.seed : 1
  };
}
function It(e) {
  const t = nn(e), o = wt(t), r = t.hitTestModel === "segment" ? wt({ ...t, D: t.lane_length }) : o, l = ut(t.seed), a = ut(t.seed + 1), h = ut(t.seed + 2), c = t.bin_size / t.sub_bin_sampling, s = Et({
    flux: t.flux,
    D: t.D,
    lane_radius: t.lane_radius,
    dt: c,
    hitTestModel: t.hitTestModel,
    lane_length: t.lane_length
  });
  let d = 0, m = 0, u = t.phi, x = t.theta, y = 0, B = 0, F = 0, R = 0, C = 0, j = 0, v = 0;
  function L(k, A) {
    return t.usePoisson ? Ut(k, A) : k;
  }
  function O(k = x, A = u) {
    return qt(t.D, k, A);
  }
  function J() {
    let k, A;
    if (t.observationMode === "randomSphere") {
      const P = Jt(h);
      k = P.theta, A = P.phi;
    } else
      k = mt(
        x + (t.thetaJitter > 0 ? t.thetaJitter * Mt(h) : 0)
      ), A = kt(
        u + (t.phiJitter > 0 ? t.phiJitter * Mt(h) : 0)
      );
    const ee = O(k, A), z = t.hitTestModel === "segment" ? Kt(r, ee, t.lane_radius) : Qt(o, t.D, ee, t.lane_radius);
    j = z;
    const D = o.length, N = D > 0 ? z * t.flux * c / D : 0;
    return B += L(N, l), F += L(s, a), R += N, v += z, C++, {
      laneCount: z,
      satPos: ee,
      lambdaLightlaneSubBin: N,
      phase: A,
      theta: k
    };
  }
  function _() {
    const k = C > 0 ? C * c : t.bin_size, A = s * t.sub_bin_sampling, D = {
      time: y,
      bin_size: k,
      lightlane: B,
      isotropic: F,
      lambdaIsotropic: C > 0 ? s * C : A,
      overlaps: j,
      overlapsMean: C > 0 ? v / C : 0,
      subBins: C,
      phase: u,
      theta: x,
      lambdaLightlaneExpected: R
    };
    return B = 0, F = 0, R = 0, v = 0, C = 0, D;
  }
  return {
    config: { ...t },
    getLaneCount() {
      return o.length;
    },
    getState() {
      return {
        elapsed: y,
        phase: u,
        theta: x,
        timeInBin: d,
        timeInSubBin: m,
        accumulatedLightlane: B,
        accumulatedIsotropic: F,
        expectedLightlaneThisBin: R,
        processedSubBinsInCurrentBin: C,
        lastLaneCount: j,
        laneCount: o.length
      };
    },
    reset() {
      d = 0, m = 0, u = t.phi, x = t.theta, y = 0, B = 0, F = 0, R = 0, C = 0, j = 0, v = 0;
    },
    flushPartialBin() {
      if (C <= 0) return null;
      const k = _();
      return d = 0, m = 0, k;
    },
    simulate(k) {
      if (!Number.isFinite(k) || k <= 0)
        return {
          bins: [],
          lastLaneCount: j,
          subBinEvents: 0,
          elapsed: y
        };
      let A = k, ee = 0;
      const z = [];
      for (; A > Ue; ) {
        const D = c - m, N = t.bin_size - d, P = Math.min(A, D, N);
        u += t.velocity * P, x = mt(x + t.thetaDrift * P), y += P, m += P, d += P, A -= P, m >= c - Ue && (m = 0, J(), ee++), d >= t.bin_size - Ue && (d = 0, z.push(_()));
      }
      return {
        bins: z,
        lastLaneCount: j,
        subBinEvents: ee,
        elapsed: y
      };
    }
  };
}
function Ft(e, t) {
  const o = e.n + 1, r = t - e.mean, l = e.mean + r / o, a = e.m2 + r * (t - l);
  return { n: o, mean: l, m2: a };
}
function Pt() {
  return { n: 0, mean: 0, m2: 0 };
}
function on({
  complexity: e,
  samplesPerPoint: t,
  runsPerPoint: o,
  binSize: r,
  subBinSampling: l,
  props: a,
  observationMode: h,
  seed: c
}) {
  let s = Pt(), d = Pt(), m = 0;
  for (let F = 0; F < o; F++) {
    const R = It({
      D: a.chandraDistance,
      theta: a.theta,
      phi: a.phi,
      observationMode: h,
      velocity: a.orbitSpeed,
      thetaDrift: a.thetaDrift,
      thetaJitter: a.thetaJitter,
      phiJitter: a.phiJitter,
      bin_size: r,
      complexity: e,
      sub_bin_sampling: l,
      flux: a.K,
      lane_radius: a.radius,
      distance: a.distance,
      hitTestModel: "segment",
      allSectors: a.allSectors,
      cumulative: a.cumulative,
      usePoisson: a.usePoisson,
      seed: c + F * 7919
    });
    F === 0 && (m = R.getLaneCount());
    for (let C = 0; C < t; C++) {
      const { bins: j } = R.simulate(r), v = j[0];
      v && (s = Ft(s, v.lightlane), d = Ft(d, v.isotropic));
    }
  }
  const u = s.n > 1 ? s.m2 / (s.n - 1) : 0, x = d.n > 1 ? d.m2 / (d.n - 1) : 0, y = s.mean > 0 ? u / s.mean : 0, B = d.mean > 0 ? x / d.mean : 0;
  return {
    complexity: e,
    laneCount: m,
    meanBlue: s.mean,
    meanYellow: d.mean,
    fanoBlue: y,
    fanoYellow: B,
    fanoExcess: Math.max(0, y - B)
  };
}
function rn(e, t = 1) {
  const o = e.filter((u) => u.complexity >= t && u.complexity > 1 && u.fanoExcess > 1e-6);
  if (o.length < 3) return null;
  let r = 0, l = 0, a = 0, h = 0;
  const c = o.length;
  for (const u of o) {
    const x = Math.log(u.laneCount), y = Math.log(u.fanoExcess);
    r += x, l += y, a += x * x, h += x * y;
  }
  const s = c * a - r * r;
  if (Math.abs(s) < 1e-12) return null;
  const d = (c * h - r * l) / s, m = (l - d * r) / c;
  return {
    A: Math.exp(m),
    alpha: -d,
    predictFanoExcessFromLaneCount(u) {
      return Math.exp(m + d * Math.log(Math.max(1, u)));
    }
  };
}
function an(e, t = 1) {
  const o = e.filter((c) => c.complexity >= t && c.complexity > 1 && c.fanoExcess > 1e-6);
  if (o.length < 4) return null;
  const r = Math.min(...o.map((c) => c.fanoExcess)), l = Math.max(0, r * 0.98);
  let a = null;
  const h = 80;
  for (let c = 0; c <= h; c++) {
    const s = c / h * l, d = o.map((O) => ({ x: O.laneCount, y: O.fanoExcess - s })).filter((O) => O.y > 1e-9);
    if (d.length < 3) continue;
    let m = 0, u = 0, x = 0, y = 0;
    const B = d.length;
    for (const O of d) {
      const J = Math.log(O.x), _ = Math.log(O.y);
      m += J, u += _, x += J * J, y += J * _;
    }
    const F = B * x - m * m;
    if (Math.abs(F) < 1e-12) continue;
    const R = (B * y - m * u) / F, C = (u - R * m) / B, j = Math.exp(C), v = -R;
    if (!(j > 0) || !(v > 0)) continue;
    let L = 0;
    for (const O of o) {
      const J = s + j * Math.pow(Math.max(1, O.laneCount), -v), _ = Math.log(Math.max(1e-9, O.fanoExcess)) - Math.log(Math.max(1e-9, J));
      L += _ * _;
    }
    (!a || L < a.score) && (a = { A: j, alpha: v, B: s, score: L });
  }
  return a ? {
    A: a.A,
    alpha: a.alpha,
    B: a.B,
    score: a.score,
    predictFanoExcessFromLaneCount(c) {
      return a.B + a.A * Math.pow(Math.max(1, c), -a.alpha);
    }
  } : null;
}
function sn(e) {
  const t = e.filter((u) => u.x > 0 && u.y > 0);
  if (t.length < 3) return null;
  let o = 0, r = 0, l = 0, a = 0;
  const h = t.length;
  for (const u of t) {
    const x = Math.log(u.x), y = Math.log(u.y);
    o += x, r += y, l += x * x, a += x * y;
  }
  const c = h * l - o * o;
  if (Math.abs(c) < 1e-12) return null;
  const s = (h * a - o * r) / c, d = (r - s * o) / h, m = Math.exp(d);
  return {
    A: m,
    beta: s,
    predict(u) {
      return m * Math.pow(Math.max(1e-9, u), s);
    },
    invert(u) {
      return m <= 0 || Math.abs(s) < 1e-12 || u <= 0 ? null : Math.pow(u / m, 1 / s);
    }
  };
}
function ln(e, t) {
  if (!Number.isFinite(t) || t <= 0 || e.length === 0) return null;
  const o = [...e].sort((s, d) => s.complexity - d.complexity), r = [...o].sort((s, d) => s.laneCount - d.laneCount), l = r[0], a = r[r.length - 1];
  if (t <= l.laneCount)
    return { complexity: l.complexity, mode: "observed-range" };
  for (let s = 1; s < r.length; s++) {
    const d = r[s - 1], m = r[s];
    if (t <= m.laneCount) {
      const u = Math.max(1e-9, m.laneCount - d.laneCount), x = (t - d.laneCount) / u;
      return {
        complexity: d.complexity + x * (m.complexity - d.complexity),
        mode: "observed-range"
      };
    }
  }
  const c = sn(o.map((s) => ({ x: s.complexity, y: s.laneCount })))?.invert(t) ?? null;
  return c && Number.isFinite(c) ? { complexity: c, mode: "extrapolated" } : { complexity: a.complexity, mode: "observed-max" };
}
function Tt(e, t, o, r) {
  return e.map((l, a) => `${a === 0 ? "M" : "L"} ${o(l.complexity)} ${r(t(l))}`).join(" ");
}
function cn(e) {
  return e >= 10 ? e.toFixed(0) : e >= 2 ? e.toFixed(1) : e.toFixed(2);
}
function dn(e, t) {
  const r = [
    0.5,
    0.6,
    0.7,
    0.8,
    0.9,
    1,
    1.1,
    1.2,
    1.4,
    1.6,
    1.8,
    2,
    2.5,
    3,
    4,
    5,
    7.5,
    10
  ].filter((c) => c >= e && c <= t);
  if (r.length >= 3) return r;
  const l = 5, a = Math.log(e), h = Math.log(t);
  return Array.from({ length: l }, (c, s) => {
    const d = s / (l - 1);
    return Math.exp(a + (h - a) * d);
  });
}
function pn(e) {
  const [t, o] = $(40), [r, l] = $(1e3), [a, h] = $(3), [c, s] = $(1), [d, m] = $(4), [u, x] = $("randomSphere"), [y, B] = $(0.05), [F, R] = $(10), [C, j] = $(0), [v, L] = $([]), [O, J] = $(0), [_, k] = $(!1), A = Z(!1), ee = Z(-1), z = () => {
    Ce(e.host, we.hover, { page: "fano" });
  }, D = (b, T) => {
    Ce(e.host, we.click, { page: "fano", target: b, ...T });
  };
  de(() => {
    let b = !1;
    return L([]), J(0), k(!0), (async () => {
      const T = [];
      for (let E = 1; E <= t; E++) {
        if (b) return;
        const I = on({
          complexity: E,
          samplesPerPoint: r,
          runsPerPoint: a,
          binSize: c,
          subBinSampling: d,
          props: e,
          observationMode: u,
          seed: 1e4 + E * 97 + C * 100003
        });
        T.push(I), L([...T]), J(E / t), await new Promise((ne) => setTimeout(ne, 0));
      }
      b || k(!1);
    })(), () => {
      b = !0;
    };
  }, [
    t,
    r,
    a,
    c,
    d,
    u,
    C,
    e.radius,
    e.distance,
    e.chandraDistance,
    e.allSectors,
    e.cumulative,
    e.theta,
    e.phi,
    e.orbitSpeed,
    e.thetaDrift,
    e.thetaJitter,
    e.phiJitter,
    e.K,
    e.speedup,
    e.usePoisson
  ]), de(() => {
    const b = A.current;
    if (A.current = _, _ && !b) {
      ee.current = -1, Ce(e.host, we.computeStart, { page: "fano" });
      return;
    }
    !_ && b && (Yt(e.host, we.computeStep, { page: "fano" }), Ce(e.host, we.computeDone, { page: "fano", points: v.length }));
  }, [_, e.host, v.length]), de(() => {
    if (!_) return;
    const b = Math.floor(O * 10);
    b <= ee.current || (ee.current = b, Ce(e.host, we.computeStep, { page: "fano", progress: O }));
  }, [O, _, e.host]);
  const N = he(() => rn(v, F), [v, F]), P = he(() => an(v, F), [v, F]), H = he(() => {
    if (!N || N.alpha <= 0 || y <= 0) return null;
    if (P && P.B >= y)
      return {
        targetExcess: y,
        requiredLaneCount: Number.POSITIVE_INFINITY,
        measuredCrossing: v.find((se) => se.fanoExcess <= y) ?? null,
        complexityEstimate: null,
        blockedByFloor: !0,
        floorExcess: P.B
      };
    const b = P ? Math.max(1e-9, y - P.B) : y, T = P ? P.A : N.A, E = P ? P.alpha : N.alpha, I = Math.pow(T / b, 1 / E);
    if (!Number.isFinite(I) || I <= 0) return null;
    const ne = v.find((se) => se.fanoExcess <= y) ?? null, G = ln(v, I);
    return {
      targetExcess: y,
      requiredLaneCount: I,
      measuredCrossing: ne,
      complexityEstimate: G,
      blockedByFloor: !1,
      floorExcess: P?.B ?? 0
    };
  }, [N, P, v, y]), g = he(() => {
    const E = { top: 20, right: 20, bottom: 42, left: 48 }, I = 860 - E.left - E.right, ne = 360 - E.top - E.bottom, G = Math.max(2, t), se = [
      1,
      ...v.map((Y) => Y.fanoBlue),
      ...v.map((Y) => Y.fanoYellow),
      ...v.map((Y) => 1 + Y.fanoExcess)
    ].filter((Y) => Number.isFinite(Y) && Y > 0), ve = Math.min(...se), Re = Math.max(...se), X = Math.max(1e-3, Math.min(0.95, ve * 0.95)), Pe = Math.max(1.05, Re * 1.05), Be = Math.log(X), Je = Math.log(Pe), me = (Y) => E.left + (Y - 1) / (G - 1) * I, Ee = (Y) => {
      const Ie = Math.min(Pe, Math.max(X, Y)), le = Math.log(Ie);
      return E.top + ne - (le - Be) / Math.max(1e-9, Je - Be) * ne;
    }, Se = dn(X, Pe);
    return { width: 860, height: 360, margin: E, innerW: I, innerH: ne, xToPx: me, yToPx: Ee, yMax: Pe, yMin: X, yTicks: Se };
  }, [v, t]), ue = he(
    () => v.length > 1 ? Tt(v, (b) => b.fanoBlue, g.xToPx, g.yToPx) : "",
    [v, g]
  ), ke = he(
    () => v.length > 1 ? Tt(v, (b) => b.fanoYellow, g.xToPx, g.yToPx) : "",
    [v, g]
  ), q = v.at(-1) ?? null;
  return /* @__PURE__ */ n(De, { fullscreen: !0, style: { pointerEvents: "auto" }, children: /* @__PURE__ */ i(
    "div",
    {
      style: {
        width: "100%",
        height: "100%",
        display: "flex",
        flexDirection: "column",
        background: "radial-gradient(circle at 20% 10%, rgba(30,41,59,0.9), rgba(2,6,23,0.96))",
        color: "var(--terminal-green-soft)",
        padding: "16px",
        paddingBottom: `${16 + (e.bottomInset ?? 0)}px`,
        boxSizing: "border-box",
        gap: "12px",
        fontFamily: "var(--font-ui)"
      },
      children: [
        /* @__PURE__ */ i("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: "12px", flexWrap: "wrap" }, children: [
          /* @__PURE__ */ i("div", { children: [
            /* @__PURE__ */ n("div", { style: { fontSize: "14px", fontWeight: 400, letterSpacing: "0.12em", textTransform: "uppercase", fontFamily: "var(--font-headline)", color: "var(--terminal-green-soft)" }, children: "Fano Sweep" }),
            /* @__PURE__ */ i("div", { style: { fontSize: "11px", color: "var(--terminal-green)", marginTop: "4px" }, children: [
              "Goal: show ",
              "Fano(Blue)",
              " trending toward 1.0 (or toward Yellow) as complexity increases."
            ] })
          ] }),
          /* @__PURE__ */ i("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
            e.onBack && /* @__PURE__ */ n(
              "button",
              {
                type: "button",
                onClick: () => {
                  D("back-to-simulator"), e.onBack?.();
                },
                onPointerEnter: z,
                style: {
                  border: "1px solid var(--terminal-panel-border)",
                  background: "rgba(7,19,11,0.8)",
                  color: "var(--terminal-green-soft)",
                  padding: "8px 12px",
                  borderRadius: "8px",
                  cursor: "pointer",
                  fontSize: "12px",
                  fontWeight: 400,
                  fontFamily: "var(--font-headline)",
                  letterSpacing: "0.08em",
                  textTransform: "uppercase"
                },
                children: "Back To Simulator"
              }
            ),
            /* @__PURE__ */ n(
              "button",
              {
                type: "button",
                onClick: () => {
                  D("rerun-sweep"), j((b) => b + 1);
                },
                onPointerEnter: z,
                style: {
                  border: "1px solid var(--terminal-panel-border)",
                  background: _ ? "rgba(125, 255, 155, 0.14)" : "rgba(7,19,11,0.8)",
                  color: "var(--terminal-green-soft)",
                  padding: "8px 12px",
                  borderRadius: "8px",
                  cursor: "pointer",
                  fontSize: "12px",
                  fontWeight: 400,
                  fontFamily: "var(--font-headline)",
                  letterSpacing: "0.08em",
                  textTransform: "uppercase"
                },
                children: _ ? "Rerun (queued)" : "Rerun Sweep"
              }
            )
          ] })
        ] }),
        /* @__PURE__ */ i("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
          /* @__PURE__ */ n(
            "button",
            {
              type: "button",
              onClick: () => {
                D("preset-video-demo"), x("randomSphere"), o(60), l(1200), h(2), s(1), m(4), R(12);
              },
              onPointerEnter: z,
              style: {
                border: "1px solid var(--terminal-panel-border)",
                background: "rgba(7,19,11,0.8)",
                color: "var(--terminal-green-soft)",
                padding: "6px 10px",
                borderRadius: 8,
                cursor: "pointer",
                fontSize: 11,
                fontWeight: 400,
                fontFamily: "var(--font-headline)",
                letterSpacing: "0.06em"
              },
              children: "Preset: Video Demo"
            }
          ),
          /* @__PURE__ */ n(
            "button",
            {
              type: "button",
              onClick: () => {
                D("preset-robust-sweep"), x("randomSphere"), o(200), l(3e3), h(5), s(1), m(16), R(40);
              },
              onPointerEnter: z,
              style: {
                border: "1px solid rgba(125, 255, 155, 0.32)",
                background: "rgba(2,6,23,0.8)",
                color: "var(--terminal-green-soft)",
                padding: "6px 10px",
                borderRadius: 8,
                cursor: "pointer",
                fontSize: 11,
                fontWeight: 400,
                fontFamily: "var(--font-headline)",
                letterSpacing: "0.06em"
              },
              children: "Preset: Robust Sweep"
            }
          )
        ] }),
        /* @__PURE__ */ i("div", { style: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(140px, 1fr))", gap: "8px" }, children: [
          /* @__PURE__ */ i("label", { style: { fontSize: "11px", color: "var(--terminal-green-soft)", display: "flex", flexDirection: "column", gap: "4px" }, children: [
            "Max Complexity",
            /* @__PURE__ */ n(
              "input",
              {
                type: "number",
                min: 2,
                max: 200,
                value: t,
                onChange: (b) => o(Math.max(2, Math.min(200, Number(b.target.value) || 2))),
                onFocus: () => z(),
                style: { background: "#07130b", color: "var(--terminal-green-soft)", border: "1px solid var(--terminal-panel-border)", borderRadius: "6px", padding: "6px 8px" }
              }
            )
          ] }),
          /* @__PURE__ */ i("label", { style: { fontSize: "11px", color: "var(--terminal-green-soft)", display: "flex", flexDirection: "column", gap: "4px" }, children: [
            "Samples / Point",
            /* @__PURE__ */ n(
              "input",
              {
                type: "number",
                min: 100,
                max: 2e4,
                step: 100,
                value: r,
                onChange: (b) => l(Math.max(100, Math.min(2e4, Number(b.target.value) || 100))),
                onFocus: () => z(),
                style: { background: "#07130b", color: "var(--terminal-green-soft)", border: "1px solid var(--terminal-panel-border)", borderRadius: "6px", padding: "6px 8px" }
              }
            )
          ] }),
          /* @__PURE__ */ i("label", { style: { fontSize: "11px", color: "var(--terminal-green-soft)", display: "flex", flexDirection: "column", gap: "4px" }, children: [
            "Runs / Point (Seeds)",
            /* @__PURE__ */ n(
              "input",
              {
                type: "number",
                min: 1,
                max: 20,
                step: 1,
                value: a,
                onChange: (b) => h(Math.max(1, Math.min(20, Number(b.target.value) || 1))),
                onFocus: () => z(),
                style: { background: "#07130b", color: "var(--terminal-green-soft)", border: "1px solid var(--terminal-panel-border)", borderRadius: "6px", padding: "6px 8px" }
              }
            )
          ] }),
          /* @__PURE__ */ i("label", { style: { fontSize: "11px", color: "var(--terminal-green-soft)", display: "flex", flexDirection: "column", gap: "4px" }, children: [
            "Bin Size (s)",
            /* @__PURE__ */ n(
              "input",
              {
                type: "number",
                min: 0.1,
                max: 20,
                step: 0.1,
                value: c,
                onChange: (b) => s(Math.max(0.1, Math.min(20, Number(b.target.value) || 0.1))),
                onFocus: () => z(),
                style: { background: "#07130b", color: "var(--terminal-green-soft)", border: "1px solid var(--terminal-panel-border)", borderRadius: "6px", padding: "6px 8px" }
              }
            )
          ] }),
          /* @__PURE__ */ i("label", { style: { fontSize: "11px", color: "var(--terminal-green-soft)", display: "flex", flexDirection: "column", gap: "4px" }, children: [
            "Sub-Bin Sampling",
            /* @__PURE__ */ n(
              "input",
              {
                type: "number",
                min: 1,
                max: 256,
                step: 1,
                value: d,
                onChange: (b) => m(Math.max(1, Math.min(256, Math.round(Number(b.target.value) || 1)))),
                onFocus: () => z(),
                style: { background: "#07130b", color: "var(--terminal-green-soft)", border: "1px solid var(--terminal-panel-border)", borderRadius: "6px", padding: "6px 8px" }
              }
            )
          ] }),
          /* @__PURE__ */ i("label", { style: { fontSize: "11px", color: "var(--terminal-green-soft)", display: "flex", flexDirection: "column", gap: "4px" }, children: [
            "Observation Mode",
            /* @__PURE__ */ i(
              "select",
              {
                value: u,
                onChange: (b) => x(b.target.value),
                onFocus: () => z(),
                style: { background: "#07130b", color: "var(--terminal-green-soft)", border: "1px solid var(--terminal-panel-border)", borderRadius: "6px", padding: "6px 8px" },
                children: [
                  /* @__PURE__ */ n("option", { value: "randomSphere", children: "Random Sphere (recommended)" }),
                  /* @__PURE__ */ n("option", { value: "orbit", children: "Orbit (path-biased)" })
                ]
              }
            )
          ] }),
          /* @__PURE__ */ i("label", { style: { fontSize: "11px", color: "var(--terminal-green-soft)", display: "flex", flexDirection: "column", gap: "4px" }, children: [
            "Target Excess (B-Y)",
            /* @__PURE__ */ n(
              "input",
              {
                type: "number",
                min: 1e-3,
                max: 1,
                step: 5e-3,
                value: y,
                onChange: (b) => B(Math.max(1e-3, Math.min(1, Number(b.target.value) || 0.05))),
                onFocus: () => z(),
                style: { background: "#07130b", color: "var(--terminal-green-soft)", border: "1px solid var(--terminal-panel-border)", borderRadius: "6px", padding: "6px 8px" }
              }
            )
          ] }),
          /* @__PURE__ */ i("label", { style: { fontSize: "11px", color: "var(--terminal-green-soft)", display: "flex", flexDirection: "column", gap: "4px" }, children: [
            "Fit Start Complexity",
            /* @__PURE__ */ n(
              "input",
              {
                type: "number",
                min: 1,
                max: t,
                step: 1,
                value: F,
                onChange: (b) => R(Math.max(1, Math.min(t, Number(b.target.value) || 1))),
                onFocus: () => z(),
                style: { background: "#07130b", color: "var(--terminal-green-soft)", border: "1px solid var(--terminal-panel-border)", borderRadius: "6px", padding: "6px 8px" }
              }
            )
          ] }),
          /* @__PURE__ */ i("div", { style: { fontSize: "11px", color: "var(--terminal-green-soft)", display: "flex", flexDirection: "column", gap: "6px" }, children: [
            "Progress",
            /* @__PURE__ */ n("div", { style: { background: "rgba(7,19,11,0.9)", border: "1px solid var(--terminal-panel-border)", borderRadius: "999px", padding: "3px" }, children: /* @__PURE__ */ n(
              "div",
              {
                style: {
                  height: "8px",
                  width: `${Math.round(O * 100)}%`,
                  background: "linear-gradient(90deg, var(--terminal-green-dim), var(--terminal-green-soft))",
                  borderRadius: "999px",
                  transition: "width 0.15s ease"
                }
              }
            ) }),
            /* @__PURE__ */ n("div", { style: { color: "var(--terminal-green)" }, children: _ ? `Running ${Math.round(O * 100)}%` : "Complete" })
          ] })
        ] }),
        /* @__PURE__ */ i("div", { style: { display: "flex", flexDirection: "column", gap: "12px", minHeight: 0, flex: 1 }, children: [
          /* @__PURE__ */ n(
            "div",
            {
              style: {
                background: "rgba(7,19,11,0.72)",
                border: "1px solid var(--terminal-panel-border)",
                borderRadius: "10px",
                padding: "10px",
                width: "100%",
                minWidth: 0,
                minHeight: "min(58vh, 520px)"
              },
              children: /* @__PURE__ */ i("svg", { viewBox: `0 0 ${g.width} ${g.height}`, style: { width: "100%", height: "100%" }, children: [
                /* @__PURE__ */ n("rect", { x: 0, y: 0, width: g.width, height: g.height, fill: "transparent" }),
                g.yTicks.map((b, T) => {
                  const E = g.yToPx(b);
                  return /* @__PURE__ */ i("g", { children: [
                    /* @__PURE__ */ n("line", { x1: g.margin.left, y1: E, x2: g.margin.left + g.innerW, y2: E, stroke: "rgba(125, 255, 155, 0.12)" }),
                    /* @__PURE__ */ n("text", { x: 8, y: E + 4, fill: "var(--terminal-green)", fontSize: "10", fontFamily: "var(--font-ui)", children: cn(b) })
                  ] }, `ygrid-${T}`);
                }),
                /* @__PURE__ */ n(
                  "line",
                  {
                    x1: g.margin.left,
                    y1: g.yToPx(1),
                    x2: g.margin.left + g.innerW,
                    y2: g.yToPx(1),
                    stroke: "#f97316",
                    strokeDasharray: "4 4",
                    opacity: 0.8
                  }
                ),
                /* @__PURE__ */ n("text", { x: g.margin.left + 6, y: g.yToPx(1) - 6, fill: "#fdba74", fontSize: "10", children: "Fano = 1" }),
                /* @__PURE__ */ n("line", { x1: g.margin.left, y1: g.margin.top + g.innerH, x2: g.margin.left + g.innerW, y2: g.margin.top + g.innerH, stroke: "rgba(125, 255, 155, 0.3)" }),
                /* @__PURE__ */ n("line", { x1: g.margin.left, y1: g.margin.top, x2: g.margin.left, y2: g.margin.top + g.innerH, stroke: "rgba(125, 255, 155, 0.3)" }),
                Array.from({ length: Math.min(t, 10) }, (b, T) => {
                  const E = 1 + (t - 1) * T / Math.max(1, Math.min(t - 1, 9)), I = g.xToPx(E);
                  return /* @__PURE__ */ i("g", { children: [
                    /* @__PURE__ */ n("line", { x1: I, y1: g.margin.top + g.innerH, x2: I, y2: g.margin.top + g.innerH + 4, stroke: "rgba(125, 255, 155, 0.3)" }),
                    /* @__PURE__ */ n("text", { x: I, y: g.margin.top + g.innerH + 18, fill: "var(--terminal-green)", fontSize: "10", fontFamily: "var(--font-ui)", textAnchor: "middle", children: Math.round(E) })
                  ] }, `xtick-${T}`);
                }),
                ke && /* @__PURE__ */ n("path", { d: ke, fill: "none", stroke: "#fbbf24", strokeWidth: "2", opacity: 0.95 }),
                ue && /* @__PURE__ */ n("path", { d: ue, fill: "none", stroke: "#60a5fa", strokeWidth: "2.25", opacity: 0.95 }),
                N && v.length > 2 && (() => {
                  const b = v.filter((T) => T.complexity >= F).map((T, E) => {
                    const I = 1 + N.predictFanoExcessFromLaneCount(T.laneCount);
                    return `${E === 0 ? "M" : "L"} ${g.xToPx(T.complexity)} ${g.yToPx(I)}`;
                  }).join(" ");
                  return /* @__PURE__ */ n("path", { d: b, fill: "none", stroke: "#93c5fd", strokeDasharray: "5 4", strokeWidth: "1.5", opacity: 0.8 });
                })(),
                P && v.length > 2 && (() => {
                  const b = v.filter((T) => T.complexity >= F).map((T, E) => {
                    const I = 1 + P.predictFanoExcessFromLaneCount(T.laneCount);
                    return `${E === 0 ? "M" : "L"} ${g.xToPx(T.complexity)} ${g.yToPx(I)}`;
                  }).join(" ");
                  return /* @__PURE__ */ n("path", { d: b, fill: "none", stroke: "#22d3ee", strokeDasharray: "2 4", strokeWidth: "1.5", opacity: 0.7 });
                })(),
                v.map((b) => /* @__PURE__ */ i("g", { children: [
                  /* @__PURE__ */ n("circle", { cx: g.xToPx(b.complexity), cy: g.yToPx(b.fanoYellow), r: "2.2", fill: "#fbbf24" }),
                  /* @__PURE__ */ n("circle", { cx: g.xToPx(b.complexity), cy: g.yToPx(b.fanoBlue), r: "2.5", fill: "#60a5fa" })
                ] }, `dot-${b.complexity}`)),
                /* @__PURE__ */ n("text", { x: g.margin.left + g.innerW / 2, y: g.height - 8, fill: "var(--terminal-green)", fontSize: "11", fontFamily: "var(--font-ui)", textAnchor: "middle", children: "Complexity" }),
                /* @__PURE__ */ n(
                  "text",
                  {
                    x: 14,
                    y: g.margin.top + g.innerH / 2,
                    fill: "var(--terminal-green)",
                    fontSize: "11",
                    fontFamily: "var(--font-ui)",
                    textAnchor: "middle",
                    transform: `rotate(-90 14 ${g.margin.top + g.innerH / 2})`,
                    children: "Fano Factor (Var / Mean, log scale)"
                  }
                )
              ] })
            }
          ),
          /* @__PURE__ */ i(
            "div",
            {
              style: {
                display: "grid",
                gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))",
                gap: "8px",
                alignItems: "start"
              },
              children: [
                /* @__PURE__ */ i("div", { style: { background: "rgba(7,19,11,0.72)", border: "1px solid var(--terminal-panel-border)", borderRadius: "10px", padding: "10px", fontSize: "11px" }, children: [
                  /* @__PURE__ */ n("div", { style: { fontWeight: 400, marginBottom: "6px", color: "var(--terminal-green-soft)", fontFamily: "var(--font-headline)", letterSpacing: "0.06em", textTransform: "uppercase" }, children: "Legend" }),
                  /* @__PURE__ */ n("div", { style: { color: "#60a5fa" }, children: "Blue: Lightlane Fano" }),
                  /* @__PURE__ */ n("div", { style: { color: "#fbbf24" }, children: "Yellow: Isotropic Fano" }),
                  /* @__PURE__ */ n("div", { style: { color: "#fdba74", marginTop: "4px" }, children: "Dashed orange: Fano = 1" }),
                  /* @__PURE__ */ n("div", { style: { color: "#93c5fd", marginTop: "4px" }, children: "Dashed blue: power-fit extrapolation (blue excess over yellow)" }),
                  /* @__PURE__ */ n("div", { style: { color: "#22d3ee", marginTop: "4px" }, children: "Dashed cyan: floor-aware fit (B + A×N^-α)" })
                ] }),
                /* @__PURE__ */ i("div", { style: { background: "rgba(7,19,11,0.72)", border: "1px solid var(--terminal-panel-border)", borderRadius: "10px", padding: "10px", fontSize: "11px" }, children: [
                  /* @__PURE__ */ n("div", { style: { fontWeight: 400, marginBottom: "6px", color: "var(--terminal-green-soft)", fontFamily: "var(--font-headline)", letterSpacing: "0.06em", textTransform: "uppercase" }, children: "Latest Point" }),
                  q ? /* @__PURE__ */ i(Fe, { children: [
                    /* @__PURE__ */ i("div", { children: [
                      "Complexity: ",
                      /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: q.complexity })
                    ] }),
                    /* @__PURE__ */ i("div", { children: [
                      "Lanes: ",
                      /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: q.laneCount })
                    ] }),
                    /* @__PURE__ */ i("div", { children: [
                      "Mean Ratio (B/Y): ",
                      /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: (q.meanBlue / Math.max(1e-9, q.meanYellow)).toFixed(3) })
                    ] }),
                    /* @__PURE__ */ i("div", { children: [
                      "Fano Blue: ",
                      /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "#93c5fd" }, children: q.fanoBlue.toFixed(3) })
                    ] }),
                    /* @__PURE__ */ i("div", { children: [
                      "Fano Yellow: ",
                      /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "#fef3c7" }, children: q.fanoYellow.toFixed(3) })
                    ] }),
                    /* @__PURE__ */ i("div", { children: [
                      "Excess (B-Y): ",
                      /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: q.fanoExcess.toFixed(3) })
                    ] }),
                    /* @__PURE__ */ i("div", { style: { color: "var(--terminal-green)", marginTop: "6px" }, children: [
                      "Aggregated over ",
                      r.toLocaleString(),
                      " bins × ",
                      a,
                      " seeds"
                    ] })
                  ] }) : /* @__PURE__ */ n("div", { style: { color: "var(--terminal-green)" }, children: "No points yet." })
                ] }),
                /* @__PURE__ */ i("div", { style: { background: "rgba(7,19,11,0.72)", border: "1px solid var(--terminal-panel-border)", borderRadius: "10px", padding: "10px", fontSize: "11px" }, children: [
                  /* @__PURE__ */ n("div", { style: { fontWeight: 400, marginBottom: "6px", color: "var(--terminal-green-soft)", fontFamily: "var(--font-headline)", letterSpacing: "0.06em", textTransform: "uppercase" }, children: "Power Fit" }),
                  N ? /* @__PURE__ */ i(Fe, { children: [
                    /* @__PURE__ */ i("div", { style: { color: "var(--terminal-green-soft)" }, children: [
                      "Excess ≈ ",
                      /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: N.A.toExponential(2) }),
                      " × N",
                      /* @__PURE__ */ i("sup", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: [
                        "-",
                        N.alpha.toFixed(2)
                      ] })
                    ] }),
                    /* @__PURE__ */ i("div", { style: { color: "var(--terminal-green)", marginTop: "6px" }, children: [
                      "Fit is on blue excess over yellow using lane count N, starting at complexity ",
                      F,
                      "."
                    ] })
                  ] }) : /* @__PURE__ */ n("div", { style: { color: "var(--terminal-green)" }, children: "Need more points with nonzero excess." }),
                  P && /* @__PURE__ */ i("div", { style: { color: "var(--terminal-green)", marginTop: "6px" }, children: [
                    "Floor fit: excess ≈ ",
                    /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: P.B.toFixed(3) }),
                    " + ",
                    /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: P.A.toExponential(2) }),
                    " × N",
                    /* @__PURE__ */ i("sup", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: [
                      "-",
                      P.alpha.toFixed(2)
                    ] })
                  ] })
                ] }),
                /* @__PURE__ */ i("div", { style: { background: "rgba(7,19,11,0.72)", border: "1px solid var(--terminal-panel-border)", borderRadius: "10px", padding: "10px", fontSize: "11px" }, children: [
                  /* @__PURE__ */ n("div", { style: { fontWeight: 400, marginBottom: "6px", color: "var(--terminal-green-soft)", fontFamily: "var(--font-headline)", letterSpacing: "0.06em", textTransform: "uppercase" }, children: "Indistinguishable Target" }),
                  /* @__PURE__ */ i("div", { style: { color: "var(--terminal-green)", marginBottom: "6px" }, children: [
                    "Criterion: ",
                    /* @__PURE__ */ i("span", { style: { color: "var(--terminal-green-soft)" }, children: [
                      "Fano Blue - Fano Yellow ≤ ",
                      y.toFixed(3)
                    ] })
                  ] }),
                  H ? /* @__PURE__ */ i(Fe, { children: [
                    H.blockedByFloor ? /* @__PURE__ */ i(Fe, { children: [
                      /* @__PURE__ */ n("div", { style: { color: "#ff8f8f" }, children: "Floor-aware fit predicts no finite crossing for this threshold." }),
                      /* @__PURE__ */ i("div", { children: [
                        "Fitted excess floor:",
                        " ",
                        /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: H.floorExcess.toFixed(3) })
                      ] }),
                      /* @__PURE__ */ n("div", { style: { color: "var(--terminal-green)", marginTop: "6px" }, children: "Increase `Max Complexity` / `Samples`, or raise fit start to test whether the floor is a transient or a genuine plateau." })
                    ] }) : /* @__PURE__ */ i(Fe, { children: [
                      /* @__PURE__ */ i("div", { children: [
                        "Required lane count N (fit):",
                        " ",
                        /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "var(--terminal-green-soft)" }, children: Math.round(H.requiredLaneCount).toLocaleString() })
                      ] }),
                      /* @__PURE__ */ i("div", { children: [
                        "Estimated complexity:",
                        " ",
                        /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", color: "#93c5fd" }, children: H.complexityEstimate ? Math.ceil(H.complexityEstimate.complexity).toLocaleString() : "n/a" }),
                        H.complexityEstimate && /* @__PURE__ */ i("span", { style: { color: "var(--terminal-green)" }, children: [
                          " ",
                          "(",
                          H.complexityEstimate.mode === "observed-range" ? "interpolated from current sweep" : H.complexityEstimate.mode === "extrapolated" ? "extrapolated" : "bounded by current sweep",
                          ")"
                        ] })
                      ] })
                    ] }),
                    /* @__PURE__ */ n("div", { style: { marginTop: "6px", color: "var(--terminal-green)" }, children: H.measuredCrossing ? `Observed crossing already reached at complexity ${H.measuredCrossing.complexity}.` : "No observed crossing yet in current sweep; estimate uses fit." })
                  ] }) : /* @__PURE__ */ n("div", { style: { color: "var(--terminal-green)" }, children: "Need a stable excess fit (nonzero blue excess across multiple points)." })
                ] }),
                /* @__PURE__ */ i("div", { style: { background: "rgba(7,19,11,0.72)", border: "1px solid var(--terminal-panel-border)", borderRadius: "10px", padding: "10px", fontSize: "11px", color: "var(--terminal-green)" }, children: [
                  "Use ",
                  /* @__PURE__ */ n("span", { style: { color: "var(--terminal-green-soft)" }, children: "Random Sphere" }),
                  " to isolate discretization convergence from path bias. Orbit mode is still useful to show persistent anisotropy on specific trajectories.",
                  /* @__PURE__ */ i("div", { style: { marginTop: "6px" }, children: [
                    "For a stronger/cleaner claim in the video: report the threshold estimate together with ",
                    /* @__PURE__ */ n("span", { style: { color: "var(--terminal-green-soft)" }, children: "bin size" }),
                    ", ",
                    /* @__PURE__ */ n("span", { style: { color: "var(--terminal-green-soft)" }, children: "sub-bin sampling" }),
                    ", and ",
                    /* @__PURE__ */ n("span", { style: { color: "var(--terminal-green-soft)" }, children: "runs/point" }),
                    "."
                  ] }),
                  /* @__PURE__ */ n("div", { style: { marginTop: "6px" }, children: "If the floor-aware fit stays above zero as you increase complexity and samples, frame it as an open question for viewers." })
                ] })
              ]
            }
          )
        ] })
      ]
    }
  ) });
}
const Ge = new Dt("#dbeafe");
function hn(e, t) {
  const o = new Float32Array(t * 3), r = new Float32Array(t * 3), l = [], a = e + 0.01;
  for (let h = 0; h < t; h += 1) {
    const c = Math.random(), s = Math.random(), d = 2 * Math.PI * c, m = 1 - 2 * s, u = Math.sqrt(Math.max(0, 1 - m * m)), x = h * 3;
    o[x] = a * u * Math.cos(d), o[x + 1] = a * u * Math.sin(d), o[x + 2] = a * m, r[x] = Ge.r * 0.15, r[x + 1] = Ge.g * 0.15, r[x + 2] = Ge.b * 0.15, l.push({
      speed: 0.8 + Math.random() * 2.6,
      phase: Math.random() * Math.PI * 2,
      minBrightness: 0.03 + Math.random() * 0.06,
      maxBoost: 0.35 + Math.random() * 0.85
    });
  }
  return { positions: o, colors: r, sparklePoints: l };
}
function un({ radius: e }) {
  const t = Z(null), o = 16e3, { positions: r, colors: l, sparklePoints: a } = he(
    () => hn(e, o),
    [e]
  );
  return Qe(({ clock: h }) => {
    const c = t.current;
    if (!c) return;
    const s = c.geometry.getAttribute("color");
    if (!s) return;
    const d = h.getElapsedTime(), m = s.array;
    for (let u = 0; u < a.length; u += 1) {
      const x = a[u], y = Math.pow(Math.max(0, Math.sin(d * x.speed + x.phase)), 24), B = x.minBrightness + y * x.maxBoost, F = u * 3;
      m[F] = Ge.r * B, m[F + 1] = Ge.g * B, m[F + 2] = Ge.b * B;
    }
    s.needsUpdate = !0;
  }), /* @__PURE__ */ i("group", { children: [
    /* @__PURE__ */ i("mesh", { children: [
      /* @__PURE__ */ n("sphereGeometry", { args: [e, 64, 64] }),
      /* @__PURE__ */ n(
        "meshStandardMaterial",
        {
          color: "#60a5fa",
          emissive: "#1d4ed8",
          emissiveIntensity: 0.18,
          transparent: !0,
          opacity: 0.08,
          roughness: 0.15,
          metalness: 0.05
        }
      )
    ] }),
    /* @__PURE__ */ i("mesh", { renderOrder: 2, children: [
      /* @__PURE__ */ n("sphereGeometry", { args: [e, 48, 48] }),
      /* @__PURE__ */ n(
        "meshBasicMaterial",
        {
          color: "#93c5fd",
          wireframe: !0,
          transparent: !0,
          opacity: 0.14,
          toneMapped: !1
        }
      )
    ] }),
    /* @__PURE__ */ i("points", { ref: t, renderOrder: 3, children: [
      /* @__PURE__ */ i("bufferGeometry", { children: [
        /* @__PURE__ */ n("bufferAttribute", { attach: "attributes-position", args: [r, 3] }),
        /* @__PURE__ */ n("bufferAttribute", { attach: "attributes-color", args: [l, 3] })
      ] }),
      /* @__PURE__ */ n(
        "pointsMaterial",
        {
          size: Math.max(0.06, e * 0.018),
          sizeAttenuation: !0,
          transparent: !0,
          opacity: 0.95,
          vertexColors: !0,
          depthWrite: !1,
          toneMapped: !1
        }
      )
    ] })
  ] });
}
function mn({ radius: e, paused: t = !1 }) {
  const o = Z(null);
  return Qe((r) => {
    if (!t && o.current) {
      const l = r.clock.elapsedTime * 3, a = 0.5 + (Math.sin(l) + 1) / 2 * 1.5;
      o.current.emissiveIntensity = a;
    }
  }), /* @__PURE__ */ i("mesh", { position: [0, 0, 0], children: [
    /* @__PURE__ */ n("sphereGeometry", { args: [e, 64, 64] }),
    /* @__PURE__ */ n(
      "meshStandardMaterial",
      {
        ref: o,
        color: "#ec4899",
        emissive: "#db2777",
        emissiveIntensity: 1,
        toneMapped: !1
      }
    )
  ] });
}
function fn(e) {
  const t = 2 * Math.PI;
  let o = e % t;
  return o < 0 && (o += t), o > Math.PI && (o = t - o), o;
}
function gn({ radius: e, theta: t, phi: o, orbitTime: r, simTime: l, thetaDrift: a = 0, paused: h = !1 }) {
  const c = Z(null);
  return Qe(() => {
    if (!h && c.current) {
      const s = o + r.current, d = fn(t + (l?.current ?? 0) * a), m = e * Math.sin(d) * Math.cos(s), u = e * Math.cos(d), x = e * Math.sin(d) * Math.sin(s);
      c.current.position.set(m, u, x), c.current.lookAt(0, 0, 0);
    }
  }), /* @__PURE__ */ i("group", { ref: c, children: [
    /* @__PURE__ */ i("mesh", { renderOrder: 10, children: [
      /* @__PURE__ */ n("sphereGeometry", { args: [0.09, 16, 16] }),
      /* @__PURE__ */ n("meshBasicMaterial", { color: "#22d3ee", toneMapped: !1 })
    ] }),
    /* @__PURE__ */ i("mesh", { renderOrder: 9, children: [
      /* @__PURE__ */ n("sphereGeometry", { args: [0.16, 16, 16] }),
      /* @__PURE__ */ n("meshBasicMaterial", { color: "#22d3ee", transparent: !0, opacity: 0.18, toneMapped: !1 })
    ] }),
    /* @__PURE__ */ i("mesh", { rotation: [Math.PI / 2, 0, 0], children: [
      /* @__PURE__ */ n("cylinderGeometry", { args: [0.14, 0.18, 1, 16] }),
      /* @__PURE__ */ n("meshStandardMaterial", { color: "#c0c0c0", metalness: 0.8, roughness: 0.2 })
    ] }),
    /* @__PURE__ */ i("mesh", { position: [0, 0, 0.3], rotation: [Math.PI / 2, 0, 0], children: [
      /* @__PURE__ */ n("cylinderGeometry", { args: [0.18, 0.18, 0.16, 8] }),
      /* @__PURE__ */ n("meshStandardMaterial", { color: "#d4af37", metalness: 0.95, roughness: 0.18 })
    ] }),
    /* @__PURE__ */ i("mesh", { position: [0, 0, 0.6], rotation: [Math.PI / 2, 0, 0], children: [
      /* @__PURE__ */ n("cylinderGeometry", { args: [0.22, 0.22, 0.2, 16] }),
      /* @__PURE__ */ n("meshStandardMaterial", { color: "#ffd700", metalness: 1, roughness: 0.1 })
    ] }),
    /* @__PURE__ */ i("mesh", { position: [0, 0, 0.7], renderOrder: 11, children: [
      /* @__PURE__ */ n("sphereGeometry", { args: [0.05, 12, 12] }),
      /* @__PURE__ */ n("meshBasicMaterial", { color: "#f97316", toneMapped: !1 })
    ] }),
    /* @__PURE__ */ i("mesh", { position: [0, 0, 0.35], rotation: [Math.PI / 2, 0, 0], renderOrder: 8, children: [
      /* @__PURE__ */ n("cylinderGeometry", { args: [0.015, 0.015, 0.7, 8] }),
      /* @__PURE__ */ n("meshBasicMaterial", { color: "#f97316", transparent: !0, opacity: 0.7, toneMapped: !1 })
    ] }),
    /* @__PURE__ */ i("group", { position: [0, 0, 0.22], children: [
      /* @__PURE__ */ i("mesh", { position: [0.6, 0, 0], children: [
        /* @__PURE__ */ n("boxGeometry", { args: [0.8, 0.4, 0.05] }),
        /* @__PURE__ */ n("meshStandardMaterial", { color: "#1e3a8a", metalness: 0.5, roughness: 0.1 })
      ] }),
      /* @__PURE__ */ i("mesh", { position: [-0.6, 0, 0], children: [
        /* @__PURE__ */ n("boxGeometry", { args: [0.8, 0.4, 0.05] }),
        /* @__PURE__ */ n("meshStandardMaterial", { color: "#1e3a8a", metalness: 0.5, roughness: 0.1 })
      ] }),
      /* @__PURE__ */ i("mesh", { position: [0.28, 0, -0.01], children: [
        /* @__PURE__ */ n("boxGeometry", { args: [0.18, 0.05, 0.04] }),
        /* @__PURE__ */ n("meshStandardMaterial", { color: "#94a3b8", metalness: 0.7, roughness: 0.22 })
      ] }),
      /* @__PURE__ */ i("mesh", { position: [-0.28, 0, -0.01], children: [
        /* @__PURE__ */ n("boxGeometry", { args: [0.18, 0.05, 0.04] }),
        /* @__PURE__ */ n("meshStandardMaterial", { color: "#94a3b8", metalness: 0.7, roughness: 0.22 })
      ] })
    ] })
  ] });
}
const ce = {
  solid: "#60a5fa",
  dark: "#3b82f6",
  light: "#93c5fd",
  glow: "rgba(96,165,250,0.5)",
  panel: "rgba(0,20,40,0.8)"
}, ae = {
  solid: "#fbbf24",
  dark: "#f59e0b",
  light: "#fef3c7",
  glow: "rgba(251,191,36,0.5)"
}, it = "var(--font-headline)", pe = "var(--font-ui)", xn = "var(--terminal-green)", Ae = "var(--terminal-green-soft)", ye = "var(--terminal-green-muted)";
function bn({ bars: e }) {
  const t = window.innerHeight;
  return /* @__PURE__ */ i(Fe, { children: [
    e.map((o) => {
      const r = t - o.startBottom - o.barHeight, l = o.targetLeft - o.startLeft, a = o.targetTop - r;
      return /* @__PURE__ */ n(
        "div",
        {
          style: {
            position: "absolute",
            left: `${o.startLeft}px`,
            top: `${r}px`,
            width: `${o.barWidth}px`,
            height: `${o.barHeight}px`,
            background: o.color,
            borderRadius: "2px 2px 0 0",
            opacity: 0.95,
            animation: "flyToDistribution 1.2s ease-in-out forwards",
            "--delta-x": `${l}px`,
            "--delta-y": `${a}px`,
            zIndex: 1e3,
            boxShadow: `0 0 15px ${o.color}`
          }
        },
        o.id
      );
    }),
    /* @__PURE__ */ n("style", { children: `
                @keyframes flyToDistribution {
                    0% {
                        transform: translate(0, 0) scale(1);
                        opacity: 0.95;
                    }
                    40% {
                        transform: translate(calc(var(--delta-x) * 0.3), calc(var(--delta-y) * 0.5)) scale(0.9);
                        opacity: 0.9;
                    }
                    85% {
                        transform: translate(calc(var(--delta-x) * 0.95), calc(var(--delta-y) * 0.95)) scale(0.7);
                        opacity: 0.85;
                    }
                    100% {
                        transform: translate(var(--delta-x), var(--delta-y)) scale(0.6);
                        opacity: 0;
                    }
                }
                .clickable-bar {
                    transition: all 0.2s ease;
                }
                .clickable-bar:hover {
                    transform: scaleY(1.1) scaleX(1.2);
                    filter: brightness(1.3);
                    box-shadow: 0 0 10px currentColor;
                }
            ` })
  ] });
}
function at() {
  return { n: 0, meanObs: 0, m2Obs: 0, meanIso: 0, m2Iso: 0 };
}
function yn(e, t, o) {
  const r = e.n + 1, l = t - e.meanObs, a = e.meanObs + l / r, h = e.m2Obs + l * (t - a), c = o - e.meanIso, s = e.meanIso + c / r, d = e.m2Iso + c * (o - s);
  return { n: r, meanObs: a, m2Obs: h, meanIso: s, m2Iso: d };
}
function vn({
  complexity: e,
  radius: t,
  distance: o,
  theta: r,
  phi: l,
  observationMode: a,
  allSectors: h,
  cumulative: c,
  K: s,
  orbitRadius: d,
  orbitVelocity: m,
  thetaDrift: u,
  thetaJitter: x,
  phiJitter: y,
  usePoisson: B,
  speedup: F,
  paused: R,
  sceneView: C,
  bottomInset: j = 0,
  showNumericDiagnostics: v = !0,
  compactNumericDiagnostics: L = !1,
  host: O,
  centerDistribution: J = !1,
  hideFlyingBars: _ = !1
}) {
  const [k, A] = $({
    current: 0,
    total: 0,
    lastCheck: 0,
    overlaps: 0,
    currentTheory: 0,
    binOverlapsMean: 0,
    currentExpectedLightlane: 0
  }), ee = 4, z = he(() => It({
    D: d,
    theta: r,
    phi: l,
    observationMode: a,
    velocity: m,
    thetaDrift: u,
    thetaJitter: x,
    phiJitter: y,
    distance: o,
    hitTestModel: "segment",
    bin_size: 1,
    complexity: e,
    sub_bin_sampling: ee,
    flux: s,
    lane_radius: t,
    allSectors: h,
    cumulative: c,
    usePoisson: B
  }), [d, r, l, a, m, u, x, y, e, s, t, o, h, c, B]), D = 60, N = Z(new Array(D).fill(-1)), P = Z(new Array(D).fill(-1)), H = Z(0), [g, ue] = $(new Array(D).fill(-1)), [ke, q] = $(new Array(D).fill(-1)), b = Et({
    flux: s,
    D: d,
    lane_radius: t,
    dt: 1,
    hitTestModel: "segment",
    lane_length: o
  }), T = Math.sqrt(b), E = 15, I = 4 * T, ne = Math.max(0, b - I), G = b + I, se = B, ve = Math.max(0, Math.floor(ne)), Re = Math.max(ve, Math.ceil(G)), X = se ? Re - ve + 1 : E, Pe = se ? 1 : Math.max(1e-9, (G - ne) / E), Be = (f) => {
    if (se) {
      const S = Math.round(f);
      return S <= ve ? 0 : S >= Re ? X - 1 : S - ve;
    }
    return f < ne ? 0 : f >= G ? X - 1 : Math.floor((f - ne) / Pe);
  }, Je = (f) => se ? ve + f : ne + (f + 0.5) * Pe, [me, Ee] = $(new Array(X).fill(0)), [Se, Y] = $(new Array(X).fill(0)), [Ie, le] = $(/* @__PURE__ */ new Set()), [qe, Le] = $(/* @__PURE__ */ new Set()), [Ne, ze] = $([]), $e = Z(0), _e = Z(at()), [U, Ze] = $(at()), et = Z(R), tt = Z(0);
  de(() => {
    Ee(new Array(X).fill(0)), Y(new Array(X).fill(0)), N.current.fill(-1), P.current.fill(-1), H.current = 0, ue(new Array(D).fill(-1)), q(new Array(D).fill(-1)), le(/* @__PURE__ */ new Set()), Le(/* @__PURE__ */ new Set()), ze([]), _e.current = at(), Ze(at()), A({
      current: 0,
      total: 0,
      lastCheck: 0,
      overlaps: 0,
      currentTheory: 0,
      binOverlapsMean: 0,
      currentExpectedLightlane: 0
    });
  }, [e, s, t, o, d, r, l, a, m, u, x, y, h, c, B, X]);
  const nt = (f, S) => {
    if (f.length === 0) return;
    let w = 0, oe = 0, te = 0, fe = k.binOverlapsMean, V = k.currentExpectedLightlane, re = _e.current;
    for (const ie of f) {
      const ge = ie.lightlane, xe = ie.isotropic;
      if (w += ge, oe = ge, te = xe, fe = ie.overlapsMean, V = ie.lambdaLightlaneExpected, re = yn(re, ge, xe), N.current[H.current] = ge, P.current[H.current] = xe, H.current++, H.current >= D) {
        const Me = Math.max(10, ...N.current.filter((Q) => Q >= 0), ...P.current.filter((Q) => Q >= 0));
        K([...N.current], [...P.current], Me), N.current.fill(-1), P.current.fill(-1), H.current = 0, le(/* @__PURE__ */ new Set()), Le(/* @__PURE__ */ new Set());
      }
    }
    _e.current = re, A((ie) => ({
      current: oe,
      total: ie.total + w,
      lastCheck: Date.now(),
      overlaps: S,
      currentTheory: te,
      binOverlapsMean: fe,
      currentExpectedLightlane: V
    })), Ze(re), ue([...N.current]), q([...P.current]);
  }, He = Z(!1), We = Z(null), ot = (f, S) => {
    f.stopPropagation(), He.current = !0, We.current = S, f.target.setPointerCapture(f.pointerId), Ce(O, we.click, { target: `${S}-periodogram`, action: "pointer-down" });
  }, rt = (f, S, w, oe) => {
    if (!He.current || We.current !== S) return;
    f.stopPropagation();
    const te = f.currentTarget.getBoundingClientRect(), fe = f.clientX - te.left, V = Math.floor(fe / te.width * D);
    if (V >= 0 && V < D) {
      const re = w[V], ie = S === "observed" ? Ie.has(V) : qe.has(V);
      re >= 0 && !ie && W(V, re, S, oe);
    }
  }, p = (f) => {
    f.stopPropagation(), He.current = !1, We.current = null;
  }, M = (f, S, w, oe) => {
    const te = window.innerWidth, fe = f / D * te, V = te / D, re = Math.max(2, S / oe * 80), xe = w === "observed" ? 25 : 110, Me = Be(S), Q = 20, be = te - 2 * Q, Te = Q + (Me + 0.5) / X * be;
    return { startLeft: fe, startBottom: xe, barHeight: re, barWidth: V, targetLeft: Te, targetTop: 150, binIndex: Me };
  }, W = (f, S, w, oe) => {
    if (S < 0) return;
    const te = Date.now();
    te - tt.current >= 45 && (tt.current = te, Ce(O, we.computeStep, { target: `${w}-periodogram`, value: S }));
    const { startLeft: fe, startBottom: V, barHeight: re, barWidth: ie, targetLeft: ge, targetTop: xe } = M(f, S, w, oe), Me = {
      id: $e.current++,
      value: S,
      startLeft: fe,
      startBottom: V,
      barHeight: re,
      barWidth: ie,
      targetLeft: ge,
      targetTop: xe,
      color: w === "observed" ? ae.solid : ce.solid,
      type: w
    };
    ze((Q) => [...Q, Me]), w === "observed" ? (le((Q) => new Set(Q).add(f)), Ee((Q) => {
      const be = [...Q], Te = Be(S);
      return be[Te]++, be;
    })) : (Le((Q) => new Set(Q).add(f)), Y((Q) => {
      const be = [...Q], Te = Be(S);
      return be[Te]++, be;
    }));
  }, K = (f, S, w) => {
    const oe = [], te = [...me], fe = [...Se];
    f.forEach((V, re) => {
      if (V >= 0) {
        const { startLeft: ie, startBottom: ge, barHeight: xe, barWidth: Me, targetLeft: Q, targetTop: be, binIndex: Te } = M(re, V, "observed", w);
        oe.push({
          id: $e.current++,
          value: V,
          startLeft: ie,
          startBottom: ge,
          barHeight: xe,
          barWidth: Me,
          targetLeft: Q,
          targetTop: be,
          color: ae.solid,
          type: "observed"
        }), te[Te]++;
      }
    }), S.forEach((V, re) => {
      if (V >= 0) {
        const { startLeft: ie, startBottom: ge, barHeight: xe, barWidth: Me, targetLeft: Q, targetTop: be, binIndex: Te } = M(re, V, "theory", w);
        oe.push({
          id: $e.current++,
          value: V,
          startLeft: ie,
          startBottom: ge,
          barHeight: xe,
          barWidth: Me,
          targetLeft: Q,
          targetTop: be,
          color: ce.solid,
          type: "theory"
        }), fe[Te]++;
      }
    }), ze((V) => [...V, ...oe]), Ee(te), Y(fe);
  };
  de(() => {
    if (Ne.length > 0) {
      const f = setTimeout(() => {
        ze([]);
      }, 1300);
      return () => clearTimeout(f);
    }
  }, [Ne.length]);
  const Ve = Z(0);
  de(() => {
    H.current < Ve.current && (le(/* @__PURE__ */ new Set()), Le(/* @__PURE__ */ new Set())), Ve.current = H.current;
  }), de(() => {
    const f = et.current;
    if (et.current = R, !R || f) return;
    const S = z.flushPartialBin();
    S && nt([S], S.overlaps);
  }, [R, z]), Qe((f, S) => {
    if (R) return;
    const w = z.simulate(S * F);
    w.subBinEvents > 0 && A((oe) => ({ ...oe, overlaps: w.lastLaneCount })), nt(w.bins, w.lastLaneCount);
  });
  const zt = g.filter((f) => f >= 0), Rt = ke.filter((f) => f >= 0), lt = Math.max(10, Math.max(0, ...zt)), ct = Math.max(10, Math.max(0, ...Rt)), ft = Math.max(1, ...me, ...Se), gt = U.n > 1 ? U.m2Obs / (U.n - 1) : 0, dt = U.n > 1 ? U.m2Iso / (U.n - 1) : 0, Lt = U.meanIso > 0 ? U.meanObs / U.meanIso : 0, xt = dt > 0 ? gt / dt : 0, pt = U.meanObs > 0 ? gt / U.meanObs : 0, Xe = U.meanIso > 0 ? dt / U.meanIso : 0, ht = z.getLaneCount(), bt = ht > 0 && s > 0 ? ht * b / s : 0, yt = v && !L, Ke = C !== "lightlane", Oe = C !== "poisson", $t = Ne.filter((f) => f.type === "theory" && Ke || f.type === "observed" && Oe), Ot = C === "poisson" ? "Shot Noise Distribution" : C === "lightlane" ? "Shot Noise + Lightlane" : "Head to Head", je = {
    background: "rgba(255,255,255,0.04)",
    border: "1px solid var(--terminal-panel-border)",
    borderRadius: "6px",
    padding: "6px 8px",
    fontFamily: pe
  }, vt = /* @__PURE__ */ i("div", { style: {
    marginTop: L ? "0" : "12px",
    display: "grid",
    gridTemplateColumns: L ? "1fr" : "repeat(3, minmax(0, 1fr))",
    gap: L ? "6px" : "8px",
    fontSize: "10px",
    color: Ae,
    fontFamily: pe
  }, children: [
    /* @__PURE__ */ i("div", { style: je, children: [
      /* @__PURE__ */ n("div", { style: { color: ye }, children: "Samples" }),
      /* @__PURE__ */ n("div", { style: { fontFamily: "monospace" }, children: U.n })
    ] }),
    /* @__PURE__ */ i("div", { style: je, children: [
      /* @__PURE__ */ n("div", { style: { color: ye }, children: "Mean Ratio (Lightlane/Poisson)" }),
      /* @__PURE__ */ n("div", { style: { fontFamily: "monospace", color: Ae }, children: U.n > 0 ? Lt.toFixed(3) : "n/a" })
    ] }),
    /* @__PURE__ */ i("div", { style: je, children: [
      /* @__PURE__ */ n("div", { style: { color: ye }, children: "Var Ratio (Lightlane/Poisson)" }),
      /* @__PURE__ */ n("div", { style: { fontFamily: "monospace", color: xt > 1.1 ? ae.light : ce.light }, children: U.n > 1 ? xt.toFixed(3) : "n/a" })
    ] }),
    /* @__PURE__ */ i("div", { style: je, children: [
      /* @__PURE__ */ n("div", { style: { color: ye }, children: "Fano Lightlane" }),
      /* @__PURE__ */ n("div", { style: { fontFamily: "monospace", color: ae.light }, children: U.n > 1 ? pt.toFixed(3) : "n/a" })
    ] }),
    /* @__PURE__ */ i("div", { style: je, children: [
      /* @__PURE__ */ n("div", { style: { color: ye }, children: "Fano Poisson" }),
      /* @__PURE__ */ n("div", { style: { fontFamily: "monospace", color: ce.light }, children: U.n > 1 ? Xe.toFixed(3) : "n/a" })
    ] }),
    /* @__PURE__ */ i("div", { style: je, children: [
      /* @__PURE__ */ n("div", { style: { color: ye }, children: "Fano Ratio (Lightlane/Poisson)" }),
      /* @__PURE__ */ n("div", { style: { fontFamily: "monospace", color: Xe > 0 && pt / Xe > 1.05 ? ae.light : Ae }, children: U.n > 1 && Xe > 0 ? (pt / Xe).toFixed(3) : "n/a" })
    ] })
  ] }), St = /* @__PURE__ */ i("div", { style: {
    marginTop: L ? "6px" : "8px",
    display: L ? "grid" : "flex",
    gridTemplateColumns: L ? "1fr" : void 0,
    justifyContent: L ? void 0 : "center",
    gap: L ? "4px" : "12px",
    flexWrap: L ? void 0 : "wrap",
    fontSize: "10px",
    color: ye,
    fontFamily: pe
  }, children: [
    /* @__PURE__ */ i("span", { children: [
      "LC(now): ",
      k.overlaps
    ] }),
    /* @__PURE__ */ i("span", { children: [
      "LC(bin avg): ",
      k.binOverlapsMean.toFixed(2)
    ] }),
    /* @__PURE__ */ i("span", { children: [
      "LC iso target: ",
      Number.isFinite(bt) ? bt.toFixed(2) : "n/a"
    ] }),
    /* @__PURE__ */ i("span", { children: [
      "E[Lightlane|bin]: ",
      k.currentExpectedLightlane.toFixed(2)
    ] }),
    /* @__PURE__ */ i("span", { children: [
      "Lightlane(last): ",
      typeof k.current == "number" ? Number(k.current).toFixed(2) : k.current
    ] }),
    /* @__PURE__ */ i("span", { children: [
      "Lanes: ",
      ht
    ] }),
    /* @__PURE__ */ i("span", { children: [
      "Mode: ",
      a === "randomSphere" ? "Random Sphere" : "Orbit"
    ] }),
    /* @__PURE__ */ i("span", { children: [
      "theta drift: ",
      u.toFixed(3)
    ] }),
    /* @__PURE__ */ i("span", { children: [
      "theta jitter: ",
      x.toFixed(3)
    ] }),
    /* @__PURE__ */ i("span", { children: [
      "phi jitter: ",
      y.toFixed(3)
    ] })
  ] });
  return /* @__PURE__ */ i(Fe, { children: [
    !_ && /* @__PURE__ */ n(De, { fullscreen: !0, style: { pointerEvents: "none" }, children: /* @__PURE__ */ n(bn, { bars: $t }) }),
    /* @__PURE__ */ i(De, { fullscreen: !0, style: { pointerEvents: "none", display: "flex", flexDirection: "column", justifyContent: J ? "center" : "flex-start" }, children: [
      /* @__PURE__ */ i("div", { style: {
        position: "absolute",
        top: "18px",
        left: "20px",
        right: "20px",
        color: Ae,
        fontSize: "12px",
        fontWeight: 400,
        textAlign: "center",
        textTransform: "uppercase",
        letterSpacing: "0.16em",
        fontFamily: it
      }, children: [
        Ot,
        /* @__PURE__ */ i("span", { style: { fontSize: "10px", fontWeight: "normal", marginLeft: "10px", opacity: 0.8, fontFamily: pe, color: xn }, children: [
          "(λ = ",
          b.toFixed(1),
          ", σ = ",
          T.toFixed(1),
          ")"
        ] })
      ] }),
      /* @__PURE__ */ i("div", { style: {
        width: "100%",
        padding: J ? "20px" : "60px 20px 20px 20px",
        background: J ? "transparent" : "linear-gradient(to bottom, rgba(0,0,0,0.9), transparent)",
        fontFamily: pe,
        alignSelf: "center"
      }, children: [
        /* @__PURE__ */ n("div", { style: {
          position: "absolute",
          left: "5px",
          top: J ? "130px" : "170px",
          transform: "rotate(-90deg)",
          transformOrigin: "left top",
          fontSize: "10px",
          color: ye,
          fontStyle: "italic",
          whiteSpace: "nowrap",
          fontFamily: pe
        }, children: "← Frequency (how many)" }),
        /* @__PURE__ */ n("div", { style: {
          display: "flex",
          height: "100px",
          gap: "2px",
          alignItems: "flex-end",
          padding: "0 20px"
        }, children: me.map((f, S) => {
          const w = Se[S], oe = f / ft * 100, te = w / ft * 100;
          return /* @__PURE__ */ i("div", { style: {
            flex: 1,
            display: "flex",
            flexDirection: "column",
            alignItems: "center",
            position: "relative",
            height: "100%",
            justifyContent: "flex-end"
          }, children: [
            /* @__PURE__ */ i("div", { style: {
              width: "100%",
              display: "flex",
              justifyContent: "center",
              gap: "1px",
              alignItems: "flex-end",
              height: "100%",
              position: "relative"
            }, children: [
              Ke && /* @__PURE__ */ n("div", { style: {
                width: Oe ? "45%" : "92%",
                height: `${te}%`,
                background: `linear-gradient(to top, ${ce.solid}, ${ce.dark})`,
                borderRadius: "2px 2px 0 0",
                minHeight: w > 0 ? "2px" : "0",
                transition: "height 0.3s ease",
                boxShadow: w > 0 ? `0 0 5px ${ce.glow}` : "none",
                position: "relative"
              }, children: w > 0 && /* @__PURE__ */ n("div", { style: {
                position: "absolute",
                top: "-16px",
                left: "50%",
                transform: "translateX(-50%)",
                fontSize: "9px",
                fontWeight: "bold",
                color: ce.solid,
                textShadow: "0 0 3px rgba(0,0,0,0.8)"
              }, children: w }) }),
              Oe && /* @__PURE__ */ n("div", { style: {
                width: Ke ? "45%" : "92%",
                height: `${oe}%`,
                background: `linear-gradient(to top, ${ae.solid}, ${ae.dark})`,
                borderRadius: "2px 2px 0 0",
                minHeight: f > 0 ? "2px" : "0",
                transition: "height 0.3s ease",
                boxShadow: f > 0 ? `0 0 5px ${ae.glow}` : "none",
                position: "relative"
              }, children: f > 0 && /* @__PURE__ */ n("div", { style: {
                position: "absolute",
                top: "-16px",
                left: "50%",
                transform: "translateX(-50%)",
                fontSize: "9px",
                fontWeight: "bold",
                color: ae.solid,
                textShadow: "0 0 3px rgba(0,0,0,0.8)"
              }, children: f }) })
            ] }),
            /* @__PURE__ */ n("div", { style: {
              position: "absolute",
              bottom: "-18px",
              fontSize: "9px",
              color: ye,
              fontWeight: "bold",
              fontFamily: pe
            }, children: Je(S).toFixed(0) })
          ] }, S);
        }) }),
        /* @__PURE__ */ n("div", { style: {
          textAlign: "center",
          marginTop: "25px",
          fontSize: "10px",
          color: ye,
          fontStyle: "italic",
          fontFamily: pe
        }, children: "Photon Count Value →" }),
        /* @__PURE__ */ i("div", { style: {
          display: "flex",
          justifyContent: "center",
          gap: "20px",
          marginTop: "25px",
          fontSize: "10px"
        }, children: [
          Ke && /* @__PURE__ */ i("div", { style: { display: "flex", alignItems: "center", gap: "5px" }, children: [
            /* @__PURE__ */ n("div", { style: { width: "12px", height: "12px", background: ce.solid, borderRadius: "2px" } }),
            /* @__PURE__ */ n("span", { style: { color: ce.solid }, children: "Theory (Poisson)" })
          ] }),
          Oe && /* @__PURE__ */ i("div", { style: { display: "flex", alignItems: "center", gap: "5px" }, children: [
            /* @__PURE__ */ n("div", { style: { width: "12px", height: "12px", background: ae.solid, borderRadius: "2px" } }),
            /* @__PURE__ */ n("span", { style: { color: ae.solid }, children: "Observed (Lightlanes)" })
          ] })
        ] }),
        yt && vt,
        yt && St
      ] })
    ] }),
    v && L && /* @__PURE__ */ n(De, { fullscreen: !0, style: { pointerEvents: "none" }, children: /* @__PURE__ */ i("div", { style: {
      position: "absolute",
      top: "88px",
      left: "12px",
      width: "min(300px, calc(100vw - 24px))",
      background: "linear-gradient(to bottom, rgba(0,0,0,0.88), rgba(0,0,0,0.55))",
      border: "1px solid var(--terminal-panel-border)",
      borderRadius: "10px",
      padding: "10px",
      boxShadow: "0 8px 24px rgba(0,0,0,0.35)",
      fontFamily: pe
    }, children: [
      /* @__PURE__ */ n("div", { style: {
        color: Ae,
        fontSize: "10px",
        textTransform: "uppercase",
        letterSpacing: "0.08em",
        marginBottom: "8px",
        fontWeight: 400,
        fontFamily: it
      }, children: "Diagnostics" }),
      vt,
      St
    ] }) }),
    /* @__PURE__ */ i(De, { fullscreen: !0, style: { pointerEvents: "none", display: "flex", flexDirection: "column", justifyContent: "flex-end", paddingBottom: `${j}px`, boxSizing: "border-box" }, children: [
      Ke && /* @__PURE__ */ i(
        "div",
        {
          onPointerDown: (f) => ot(f, "theory"),
          onPointerMove: (f) => rt(f, "theory", ke, ct),
          onPointerUp: p,
          onPointerLeave: p,
          style: {
            width: "100%",
            height: "100px",
            background: `linear-gradient(to top, ${ce.panel}, transparent)`,
            display: "flex",
            alignItems: "flex-end",
            padding: Oe ? "0 20px 5px 20px" : "0 20px 20px 20px",
            gap: "2px",
            position: "relative",
            borderBottom: Oe ? "1px solid #555" : "none",
            pointerEvents: "auto",
            touchAction: "none",
            cursor: "crosshair"
          },
          children: [
            /* @__PURE__ */ n("div", { style: { position: "absolute", top: "10px", left: "20px", color: ce.solid, fontSize: "10px", fontWeight: 400, pointerEvents: "none", fontFamily: it, letterSpacing: "0.08em" }, children: "THEORY (Poisson) - Swipe or click to count" }),
            ke.map((f, S) => {
              const w = qe.has(S);
              return /* @__PURE__ */ n(
                "div",
                {
                  className: f >= 0 && !w ? "clickable-bar" : "",
                  style: {
                    flex: 1,
                    height: f >= 0 && !w ? `${f / ct * 100}%` : "0",
                    background: f === 0 ? "rgba(255,255,255,0.1)" : ce.solid,
                    color: ce.solid,
                    minHeight: f >= 0 && !w ? "1px" : "0",
                    transition: "all 0.3s ease",
                    opacity: w ? 0 : 0.8,
                    borderRadius: "2px 2px 0 0",
                    transform: w ? "scale(0)" : "scale(1)",
                    pointerEvents: "none"
                  }
                },
                S
              );
            }),
            /* @__PURE__ */ i("div", { style: { position: "absolute", bottom: "10px", right: "80px", color: Ae, fontFamily: pe, fontSize: "10px", pointerEvents: "none" }, children: [
              "Max: ",
              ct
            ] })
          ]
        }
      ),
      Oe && /* @__PURE__ */ i(
        "div",
        {
          onPointerDown: (f) => ot(f, "observed"),
          onPointerMove: (f) => rt(f, "observed", g, lt),
          onPointerUp: p,
          onPointerLeave: p,
          style: {
            width: "100%",
            height: "100px",
            background: "linear-gradient(to top, rgba(0,0,0,0.8), transparent)",
            display: "flex",
            alignItems: "flex-end",
            padding: "0 20px 20px 20px",
            gap: "2px",
            position: "relative",
            pointerEvents: "auto",
            touchAction: "none",
            cursor: "crosshair"
          },
          children: [
            /* @__PURE__ */ n("div", { style: { position: "absolute", top: "10px", left: "20px", color: ae.solid, fontSize: "10px", fontWeight: 400, pointerEvents: "none", fontFamily: it, letterSpacing: "0.08em" }, children: "OBSERVED (Lightlanes) - Swipe or click to count" }),
            g.map((f, S) => {
              const w = Ie.has(S);
              return /* @__PURE__ */ n(
                "div",
                {
                  className: f >= 0 && !w ? "clickable-bar" : "",
                  style: {
                    flex: 1,
                    height: f >= 0 && !w ? `${f / lt * 100}%` : "0",
                    background: f === 0 ? "rgba(255,255,255,0.1)" : f > 0 ? ae.solid : "transparent",
                    color: ae.solid,
                    minHeight: f >= 0 && !w ? "2px" : "0",
                    transition: "all 0.3s ease",
                    borderTop: f >= 0 && !w ? `2px solid ${ae.light}` : "none",
                    opacity: w ? 0 : 0.8,
                    position: "relative",
                    borderRadius: "2px 2px 0 0",
                    transform: w ? "scale(0)" : "scale(1)",
                    pointerEvents: "none"
                  },
                  children: (S + 1) % 5 === 0 && !w && /* @__PURE__ */ n("div", { style: {
                    position: "absolute",
                    bottom: "-20px",
                    left: "50%",
                    transform: "translateX(-50%)",
                    width: "1px",
                    height: "5px",
                    background: "#fff",
                    opacity: 0.5,
                    pointerEvents: "none"
                  }, children: /* @__PURE__ */ n("span", { style: { position: "absolute", top: "5px", left: "-50%", fontSize: "10px", color: ye, fontFamily: pe }, children: S + 1 }) })
                },
                S
              );
            }),
            /* @__PURE__ */ i("div", { style: { position: "absolute", bottom: "10px", right: "80px", color: Ae, fontFamily: pe, fontSize: "10px" }, children: [
              "Max: ",
              lt
            ] })
          ]
        }
      )
    ] })
  ] });
}
const Sn = {
  complexity: 1,
  radius: 2,
  distance: 5,
  chandraDistance: 6,
  showAxes: !1,
  // Cleaner look for challenge
  lightlanes: !0,
  // Always show lightlanes
  allSectors: !0,
  cumulative: !1,
  phi: 0,
  theta: Math.PI / 2,
  observationMode: "orbit",
  orbitSpeed: 0.2,
  thetaDrift: 0,
  thetaJitter: 0,
  phiJitter: 0,
  speedup: 1,
  K: 1e3,
  usePoisson: !0,
  sceneView: "both",
  hideScenePresentation: !1,
  hideFlyingBars: !1,
  hideDataBoxes: !1
};
function kn(e) {
  const t = e.host, o = e.devUi?.compactNumericDiagnostics ?? !1, r = e.devUi?.maxComplexity ?? 20, l = e.devUi?.maxSpeedup ?? 240, a = 74, h = 20, c = e.config?.params || {}, {
    complexity: s,
    radius: d,
    distance: m,
    chandraDistance: u,
    showAxes: x,
    lightlanes: y,
    allSectors: B,
    cumulative: F,
    phi: R,
    theta: C,
    observationMode: j,
    orbitSpeed: v,
    thetaDrift: L,
    thetaJitter: O,
    phiJitter: J,
    speedup: _,
    K: k,
    usePoisson: A,
    sceneView: ee,
    hideScenePresentation: z,
    hideFlyingBars: D,
    hideDataBoxes: N
  } = { ...Sn, ...c }, P = !N, H = Z(0), g = Z(0), [ue, ke] = $(!1), [q, b] = $("scene"), [T, E] = $(ee), [I, ne] = $(s), [G, se] = $(_), [ve, Re] = $(null), X = Z(null);
  de(() => {
    E(ee);
  }, [ee]), de(() => {
    ne(s);
  }, [s]), de(() => {
    se(_);
  }, [_]);
  const Pe = G > 20, Be = T !== "lightlane", Je = T !== "poisson", me = q === "scene" && T !== "poisson", Ee = (p) => p === "poisson" ? "Poisson" : p === "lightlane" ? "Lightlane" : "Both", Se = () => {
    Ce(t, we.hover, { page: q, sceneView: T });
  }, Y = (p, M) => {
    Ce(t, we.click, { page: q, sceneView: T, target: p, ...M });
  }, Ie = (p) => {
    Re(p), X.current && clearTimeout(X.current), X.current = setTimeout(() => {
      Re(null), X.current = null;
    }, 1500);
  }, le = (p) => {
    const M = Array.from({ length: h }, (W, K) => K === 0 ? 1 : K === h - 1 ? p : Math.round(1 + (p - 1) * K / (h - 1)));
    return Array.from(new Set(M)).sort((W, K) => W - K);
  }, qe = (p, M) => {
    const W = le(M);
    return W.find((K) => p < K) ?? W[W.length - 1];
  }, Le = (p, M) => {
    const W = le(M);
    for (let K = W.length - 1; K >= 0; K -= 1)
      if (p > W[K]) return W[K];
    return W[0];
  }, Ne = (p, M) => {
    const W = le(M), K = W.findIndex((Ve) => p <= Ve);
    return K >= 0 ? K : W.length - 1;
  }, ze = Ne(I, r), $e = Ne(G, l), _e = `${(ze + 1) / h * 100}%`, U = `${($e + 1) / h * 100}%`, Ze = me && I > le(r)[0], et = me && I < le(r).at(-1), tt = G > le(l)[0], nt = G < le(l).at(-1), He = (p) => {
    if (!me) return;
    const M = p === "up" ? qe(I, r) : Le(I, r);
    M !== I && (Y("complexity", { direction: p, value: M }), ne(M), e.devUi?.onSetParam?.("complexity", M), Ie(`Complexity ${M}`));
  }, We = (p) => {
    const M = p === "up" ? qe(G, l) : Le(G, l);
    M !== G && (Y("turbo", { direction: p, value: M }), se(M), e.devUi?.onSetParam?.("speedup", M), Ie(`Turbo ${M}x`));
  }, ot = () => {
    const p = ["poisson", "lightlane", "both"], M = p.indexOf(T), W = p[(M + 1) % p.length];
    Y("mode", { value: W }), E(W), Ie(`Mode ${Ee(W)}`);
  }, rt = () => {
    Y("fano-page", { value: q === "scene" ? "fano" : "scene" }), b((p) => p === "scene" ? "fano" : "scene");
  };
  return de(() => {
    const p = (M) => {
      if (M.code !== "Space" || M.repeat) return;
      const W = M.target, K = W?.tagName;
      K === "INPUT" || K === "TEXTAREA" || W?.isContentEditable || (M.preventDefault(), ke((Ve) => !Ve));
    };
    return window.addEventListener("keydown", p), () => window.removeEventListener("keydown", p);
  }, []), de(() => () => {
    X.current && clearTimeout(X.current);
  }, []), Qe((p, M) => {
    ue || q === "fano" || (H.current += M * v * G, g.current += M * G);
  }), de(() => {
    H.current = 0, g.current = 0;
  }, [
    I,
    d,
    m,
    u,
    R,
    C,
    j,
    v,
    L,
    O,
    J,
    G,
    k,
    B,
    F,
    A
  ]), /* @__PURE__ */ i(Fe, { children: [
    /* @__PURE__ */ n(De, { fullscreen: !0, style: { pointerEvents: "none", zIndex: 3e3 }, children: /* @__PURE__ */ n("div", { style: { position: "absolute", top: 12, right: 12, display: "flex", gap: 8, pointerEvents: "auto" }, children: /* @__PURE__ */ n(
      "button",
      {
        type: "button",
        onClick: () => {
          Y("advanced"), e.devUi?.onOpenHarness?.();
        },
        onPointerEnter: Se,
        style: {
          border: "1px solid var(--terminal-panel-border)",
          background: "rgba(7,19,11,0.86)",
          color: "var(--terminal-green-soft)",
          borderRadius: 10,
          padding: "10px 12px",
          fontSize: 12,
          fontWeight: 400,
          letterSpacing: "0.08em",
          fontFamily: "var(--font-headline)",
          textTransform: "uppercase",
          cursor: "pointer",
          boxShadow: "0 8px 24px rgba(0,0,0,0.25)"
        },
        children: "Advanced"
      }
    ) }) }),
    /* @__PURE__ */ n("ambientLight", { intensity: 0.4 }),
    /* @__PURE__ */ n("directionalLight", { position: [10, 10, 5], intensity: 1, castShadow: !0 }),
    /* @__PURE__ */ n("pointLight", { position: [-10, -10, -10], intensity: 0.5, color: "blue" }),
    q === "scene" ? /* @__PURE__ */ i(Fe, { children: [
      !z && Be && /* @__PURE__ */ n(un, { radius: u }),
      !z && Je && /* @__PURE__ */ n(
        Wt,
        {
          complexity: I,
          lightlanes: y,
          radius: d,
          distance: m,
          allSectors: B,
          cumulative: F
        }
      ),
      !z && /* @__PURE__ */ n(mn, { radius: d, paused: ue }),
      /* @__PURE__ */ n(
        gn,
        {
          radius: u,
          theta: C,
          phi: R,
          orbitTime: H,
          simTime: g,
          thetaDrift: L,
          paused: ue
        }
      ),
      /* @__PURE__ */ n(
        vn,
        {
          complexity: I,
          radius: d,
          distance: m,
          theta: C,
          phi: R,
          observationMode: j,
          allSectors: B,
          cumulative: F,
          K: k,
          orbitRadius: u,
          orbitVelocity: v,
          thetaDrift: L,
          thetaJitter: O,
          phiJitter: J,
          usePoisson: A,
          speedup: G,
          paused: ue,
          sceneView: T,
          bottomInset: a,
          showNumericDiagnostics: P,
          compactNumericDiagnostics: o,
          host: t,
          centerDistribution: z,
          hideFlyingBars: D || Pe
        }
      ),
      ue && /* @__PURE__ */ n("group", { position: [0, u + 1.5, 0], children: /* @__PURE__ */ i("mesh", { children: [
        /* @__PURE__ */ n("sphereGeometry", { args: [0.12, 16, 16] }),
        /* @__PURE__ */ n("meshBasicMaterial", { color: "#ef4444", toneMapped: !1 })
      ] }) }),
      x && /* @__PURE__ */ n("axesHelper", { args: [Math.max(5, I)] }),
      /* @__PURE__ */ n(
        At,
        {
          infiniteGrid: !0,
          fadeDistance: 50,
          sectionColor: "#333",
          cellColor: "#111",
          position: [0, -0.01, 0]
        }
      )
    ] }) : /* @__PURE__ */ n(
      pn,
      {
        radius: d,
        distance: m,
        chandraDistance: u,
        allSectors: B,
        cumulative: F,
        theta: C,
        phi: R,
        orbitSpeed: v,
        thetaDrift: L,
        thetaJitter: O,
        phiJitter: J,
        K: k,
        speedup: G,
        usePoisson: A,
        bottomInset: a,
        onBack: () => b("scene"),
        host: t
      }
    ),
    /* @__PURE__ */ i(De, { fullscreen: !0, style: { pointerEvents: "none", zIndex: 3200 }, children: [
      ve && /* @__PURE__ */ n(
        "div",
        {
          style: {
            position: "absolute",
            top: "50%",
            left: "50%",
            transform: "translate(-50%, -50%) skewX(-12deg)",
            padding: "16px 28px",
            color: "var(--terminal-green-soft)",
            fontFamily: "var(--font-headline)",
            fontStyle: "italic",
            fontSize: 42,
            letterSpacing: "0.16em",
            textTransform: "uppercase",
            textShadow: "0 0 20px rgba(125,255,155,0.38), 0 0 42px rgba(125,255,155,0.18)"
          },
          children: /* @__PURE__ */ n("span", { style: { display: "inline-block", transform: "skewX(12deg)" }, children: ve })
        }
      ),
      /* @__PURE__ */ n(
        "div",
        {
          style: {
            position: "absolute",
            left: 10,
            bottom: a + 16,
            width: 26,
            height: "min(44vh, 320px)",
            display: "flex",
            alignItems: "flex-end"
          },
          children: /* @__PURE__ */ i(
            "div",
            {
              style: {
                position: "relative",
                width: "100%",
                height: "100%",
                borderRadius: 14,
                border: "1px solid rgba(251,191,36,0.35)",
                background: "linear-gradient(to top, rgba(30,18,0,0.92), rgba(7,19,11,0.15))",
                boxShadow: "0 0 22px rgba(251,191,36,0.12)",
                overflow: "hidden",
                opacity: me ? 1 : 0.35,
                transition: "opacity 0.2s ease"
              },
              children: [
                /* @__PURE__ */ n(
                  "div",
                  {
                    style: {
                      position: "absolute",
                      inset: "6px",
                      borderRadius: 10,
                      border: "1px solid rgba(251,191,36,0.14)"
                    }
                  }
                ),
                /* @__PURE__ */ n(
                  "div",
                  {
                    style: {
                      position: "absolute",
                      left: 5,
                      right: 5,
                      bottom: 5,
                      height: _e,
                      borderRadius: 9,
                      background: "linear-gradient(to top, rgba(245,158,11,0.96), rgba(253,224,71,0.96))",
                      boxShadow: "0 0 18px rgba(251,191,36,0.5)",
                      transition: "height 0.25s ease"
                    }
                  }
                ),
                /* @__PURE__ */ n(
                  "div",
                  {
                    style: {
                      position: "absolute",
                      inset: "8px 7px",
                      display: "grid",
                      gridTemplateRows: `repeat(${h}, 1fr)`,
                      pointerEvents: "none"
                    },
                    children: Array.from({ length: h }).map((p, M) => /* @__PURE__ */ n(
                      "div",
                      {
                        style: {
                          borderTop: M === 0 ? "none" : "1px solid rgba(251,191,36,0.15)"
                        }
                      },
                      `complexity-tick-${M}`
                    ))
                  }
                ),
                /* @__PURE__ */ i(
                  "div",
                  {
                    style: {
                      position: "absolute",
                      left: 34,
                      bottom: 0,
                      color: "#fcd34d",
                      fontFamily: "var(--font-headline)",
                      fontSize: 10,
                      letterSpacing: "0.08em",
                      textTransform: "uppercase",
                      writingMode: "vertical-rl",
                      transform: "rotate(180deg)",
                      textShadow: "0 0 12px rgba(251,191,36,0.25)"
                    },
                    children: [
                      "Complexity ",
                      ze + 1,
                      "/",
                      h
                    ]
                  }
                )
              ]
            }
          )
        }
      ),
      /* @__PURE__ */ n(
        "div",
        {
          style: {
            position: "absolute",
            right: 10,
            bottom: a + 16,
            width: 26,
            height: "min(44vh, 320px)",
            display: "flex",
            alignItems: "flex-end"
          },
          children: /* @__PURE__ */ i(
            "div",
            {
              style: {
                position: "relative",
                width: "100%",
                height: "100%",
                borderRadius: 14,
                border: "1px solid rgba(244,114,182,0.35)",
                background: "linear-gradient(to top, rgba(42,7,23,0.94), rgba(7,19,11,0.15))",
                boxShadow: "0 0 22px rgba(244,114,182,0.14)",
                overflow: "hidden"
              },
              children: [
                /* @__PURE__ */ n(
                  "div",
                  {
                    style: {
                      position: "absolute",
                      inset: "6px",
                      borderRadius: 10,
                      border: "1px solid rgba(244,114,182,0.14)"
                    }
                  }
                ),
                /* @__PURE__ */ n(
                  "div",
                  {
                    style: {
                      position: "absolute",
                      left: 5,
                      right: 5,
                      bottom: 5,
                      height: U,
                      borderRadius: 9,
                      background: "linear-gradient(to top, rgba(236,72,153,0.96), rgba(244,114,182,0.98))",
                      boxShadow: "0 0 18px rgba(244,114,182,0.5)",
                      transition: "height 0.25s ease"
                    }
                  }
                ),
                /* @__PURE__ */ n(
                  "div",
                  {
                    style: {
                      position: "absolute",
                      inset: "8px 7px",
                      display: "grid",
                      gridTemplateRows: `repeat(${h}, 1fr)`,
                      pointerEvents: "none"
                    },
                    children: Array.from({ length: h }).map((p, M) => /* @__PURE__ */ n(
                      "div",
                      {
                        style: {
                          borderTop: M === 0 ? "none" : "1px solid rgba(244,114,182,0.15)"
                        }
                      },
                      `turbo-tick-${M}`
                    ))
                  }
                ),
                /* @__PURE__ */ i(
                  "div",
                  {
                    style: {
                      position: "absolute",
                      right: 34,
                      bottom: 0,
                      color: "#f9a8d4",
                      fontFamily: "var(--font-headline)",
                      fontSize: 10,
                      letterSpacing: "0.08em",
                      textTransform: "uppercase",
                      writingMode: "vertical-rl",
                      textShadow: "0 0 12px rgba(244,114,182,0.25)"
                    },
                    children: [
                      "Turbo ",
                      $e + 1,
                      "/",
                      h
                    ]
                  }
                )
              ]
            }
          )
        }
      ),
      /* @__PURE__ */ n(
        "div",
        {
          style: {
            position: "absolute",
            left: 12,
            right: 12,
            bottom: 10,
            display: "grid",
            gridTemplateColumns: "repeat(4, minmax(0, 1fr))",
            gap: 8,
            pointerEvents: "auto"
          },
          children: [
            {
              label: "Complexity",
              kind: "adjust",
              active: !1,
              disabled: !me,
              accent: "rgba(245,158,11,0.2)",
              sublabel: `${I} • ${ze + 1}/${h}`,
              meterColor: "linear-gradient(to top, rgba(245,158,11,0.95), rgba(253,224,71,0.95))",
              meterSide: "left",
              meterFill: _e,
              onDecrease: () => He("down"),
              onIncrease: () => He("up"),
              canDecrease: Ze,
              canIncrease: et
            },
            {
              label: "Mode",
              kind: "action",
              onClick: ot,
              active: !1,
              accent: "rgba(59,130,246,0.18)",
              sublabel: Ee(T)
            },
            {
              label: "Fano Sweep",
              kind: "action",
              onClick: rt,
              active: q === "fano",
              accent: "rgba(59,130,246,0.22)",
              sublabel: q === "fano" ? "Open" : "Scene"
            },
            {
              label: "Turbo",
              kind: "adjust",
              active: !1,
              accent: "rgba(34,197,94,0.2)",
              sublabel: `${G}x • ${$e + 1}/${h}`,
              meterColor: "linear-gradient(to top, rgba(236,72,153,0.95), rgba(244,114,182,0.95))",
              meterSide: "right",
              meterFill: U,
              onDecrease: () => We("down"),
              onIncrease: () => We("up"),
              canDecrease: tt,
              canIncrease: nt
            }
          ].map((p) => p.kind === "adjust" ? /* @__PURE__ */ i(
            "div",
            {
              style: {
                minHeight: 54,
                border: "1px solid var(--terminal-panel-border)",
                background: p.active ? p.accent : "rgba(7,19,11,0.86)",
                color: "var(--terminal-green-soft)",
                borderRadius: 10,
                padding: "8px 10px",
                display: "flex",
                flexDirection: "column",
                alignItems: "center",
                justifyContent: "center",
                gap: 6,
                boxShadow: p.active ? "0 0 18px rgba(125,255,155,0.12)" : "0 8px 24px rgba(0,0,0,0.25)",
                position: "relative",
                overflow: "hidden",
                opacity: p.disabled ? 0.38 : 1
              },
              children: [
                "meterColor" in p && /* @__PURE__ */ i(Fe, { children: [
                  /* @__PURE__ */ n(
                    "div",
                    {
                      style: {
                        position: "absolute",
                        top: 6,
                        bottom: 6,
                        left: p.meterSide === "left" ? 6 : void 0,
                        right: p.meterSide === "right" ? 6 : void 0,
                        width: 6,
                        borderRadius: 999,
                        background: "rgba(255,255,255,0.07)",
                        border: "1px solid rgba(255,255,255,0.08)"
                      }
                    }
                  ),
                  /* @__PURE__ */ n(
                    "div",
                    {
                      style: {
                        position: "absolute",
                        bottom: 7,
                        left: p.meterSide === "left" ? 7 : void 0,
                        right: p.meterSide === "right" ? 7 : void 0,
                        width: 4,
                        height: p.meterFill,
                        borderRadius: 999,
                        background: p.meterColor,
                        boxShadow: p.meterSide === "left" ? "0 0 10px rgba(251,191,36,0.45)" : "0 0 10px rgba(244,114,182,0.45)",
                        transition: "height 0.25s ease"
                      }
                    }
                  )
                ] }),
                /* @__PURE__ */ n(
                  "span",
                  {
                    style: {
                      fontFamily: "var(--font-headline)",
                      fontSize: 11,
                      fontWeight: 400,
                      letterSpacing: "0.08em",
                      textTransform: "uppercase",
                      lineHeight: 1.1
                    },
                    children: p.label
                  }
                ),
                /* @__PURE__ */ n(
                  "span",
                  {
                    style: {
                      fontFamily: "var(--font-ui)",
                      fontSize: 10,
                      color: "var(--terminal-green)",
                      letterSpacing: "0.08em",
                      lineHeight: 1
                    },
                    children: p.sublabel
                  }
                ),
                /* @__PURE__ */ i("div", { style: { display: "grid", gridTemplateColumns: "repeat(2, minmax(0, 1fr))", gap: 6, width: "100%", marginTop: "auto" }, children: [
                  /* @__PURE__ */ n(
                    "button",
                    {
                      type: "button",
                      onClick: p.onDecrease,
                      onPointerEnter: Se,
                      disabled: p.disabled || !p.canDecrease,
                      style: {
                        border: "1px solid rgba(255,255,255,0.12)",
                        background: "rgba(255,255,255,0.04)",
                        color: "var(--terminal-green-soft)",
                        borderRadius: 8,
                        minHeight: 24,
                        cursor: p.disabled || !p.canDecrease ? "not-allowed" : "pointer",
                        fontFamily: "var(--font-headline)",
                        fontSize: 12,
                        letterSpacing: "0.08em",
                        opacity: p.disabled || !p.canDecrease ? 0.35 : 1,
                        position: "relative",
                        zIndex: 1
                      },
                      children: "-"
                    }
                  ),
                  /* @__PURE__ */ n(
                    "button",
                    {
                      type: "button",
                      onClick: p.onIncrease,
                      onPointerEnter: Se,
                      disabled: p.disabled || !p.canIncrease,
                      style: {
                        border: "1px solid rgba(255,255,255,0.12)",
                        background: "rgba(255,255,255,0.04)",
                        color: "var(--terminal-green-soft)",
                        borderRadius: 8,
                        minHeight: 24,
                        cursor: p.disabled || !p.canIncrease ? "not-allowed" : "pointer",
                        fontFamily: "var(--font-headline)",
                        fontSize: 12,
                        letterSpacing: "0.08em",
                        opacity: p.disabled || !p.canIncrease ? 0.35 : 1,
                        position: "relative",
                        zIndex: 1
                      },
                      children: "+"
                    }
                  )
                ] })
              ]
            },
            p.label
          ) : /* @__PURE__ */ i(
            "button",
            {
              type: "button",
              onClick: p.onClick,
              onPointerEnter: Se,
              disabled: "disabled" in p ? p.disabled : !1,
              style: {
                minHeight: 54,
                border: "1px solid var(--terminal-panel-border)",
                background: p.active ? p.accent : "rgba(7,19,11,0.86)",
                color: "var(--terminal-green-soft)",
                borderRadius: 10,
                padding: "8px 10px",
                cursor: "disabled" in p && p.disabled ? "not-allowed" : "pointer",
                display: "flex",
                flexDirection: "column",
                alignItems: "center",
                justifyContent: "center",
                gap: 2,
                boxShadow: p.active ? "0 0 18px rgba(125,255,155,0.12)" : "0 8px 24px rgba(0,0,0,0.25)",
                position: "relative",
                overflow: "hidden",
                opacity: "disabled" in p && p.disabled ? 0.38 : 1
              },
              children: [
                /* @__PURE__ */ n(
                  "span",
                  {
                    style: {
                      fontFamily: "var(--font-headline)",
                      fontSize: 11,
                      fontWeight: 400,
                      letterSpacing: "0.08em",
                      textTransform: "uppercase",
                      lineHeight: 1.1
                    },
                    children: p.label
                  }
                ),
                /* @__PURE__ */ n(
                  "span",
                  {
                    style: {
                      fontFamily: "var(--font-ui)",
                      fontSize: 10,
                      color: "var(--terminal-green)",
                      letterSpacing: "0.08em",
                      lineHeight: 1
                    },
                    children: p.sublabel
                  }
                )
              ]
            },
            p.label
          ))
        }
      )
    ] }),
    /* @__PURE__ */ n("color", { attach: "background", args: ["#050505"] })
  ] });
}
const Bn = {
  name: "lightlane",
  displayName: "Lightlane Challenge",
  version: "1.1.0",
  paramSchema: {
    hideScenePresentation: { type: "boolean", label: "Hide Sphere + Lightlanes", default: !1 },
    hideFlyingBars: { type: "boolean", label: "Hide Flying Bars", default: !1 },
    hideDataBoxes: { type: "boolean", label: "Hide Data Boxes", default: !1 },
    complexity: { type: "range", label: "Complexity", default: 5, min: 1, max: 20, step: 1 },
    radius: { type: "range", label: "Distance to star", default: 2, min: 0.1, max: 5, step: 0.1 },
    chandraDistance: { type: "range", label: "Chandra Camera Distance", default: 6, min: 5, max: 30, step: 0.5 },
    observationMode: {
      type: "select",
      label: "Observation Mode",
      default: "randomSphere",
      options: [
        { value: "orbit", label: "Orbit" },
        { value: "randomSphere", label: "Random Sphere" }
      ]
    },
    sceneView: {
      type: "select",
      label: "Scene View",
      default: "both",
      options: [
        { value: "both", label: "Both" },
        { value: "poisson", label: "Poisson" },
        { value: "lightlane", label: "Lightlane" }
      ]
    },
    orbitSpeed: { type: "range", label: "Orbit Speed", default: 0.2, min: 0, max: 2, step: 0.01 },
    thetaDrift: { type: "range", label: "Theta Drift", default: 0, min: -1, max: 1, step: 0.01 },
    thetaJitter: { type: "range", label: "Theta Jitter", default: 0, min: 0, max: 0.25, step: 5e-3 },
    phiJitter: { type: "range", label: "Phi Jitter", default: 0, min: 0, max: 0.5, step: 0.01 },
    speedup: { type: "range", label: "Speedup", default: 1, min: 1, max: 240, step: 1 }
  },
  defaultParams: {
    complexity: 5,
    radius: 2,
    orbitSpeed: 0.2,
    thetaDrift: 0,
    thetaJitter: 0,
    phiJitter: 0,
    chandraDistance: 6,
    observationMode: "randomSphere",
    sceneView: "both",
    speedup: 1,
    // Internal defaults will handle the rest
    distance: 5,
    showAxes: !1,
    lightlanes: !0,
    allSectors: !0,
    cumulative: !1,
    phi: 0,
    theta: Math.PI / 2,
    K: 1e3,
    usePoisson: !0,
    hideScenePresentation: !1,
    hideFlyingBars: !1,
    hideDataBoxes: !1
  }
};
export {
  kn as default,
  Bn as metadata
};
//# sourceMappingURL=lightlane.js.map
