/* global Cesium */
// Deterministic frame renderer for the Cosmos 2612 / ICEYE-X36 replay.
// window.rpo.frame(seconds) sets every piece of state for one video instant,
// renders, and resolves once imagery and models have settled.
const params = new URLSearchParams(location.search);
const W = Number(params.get('w') || 1920);
const H = Number(params.get('h') || 1080);
const PORTRAIT = H > W;
const U = PORTRAIT ? W / 1080 : W / 1920;
document.documentElement.style.setProperty('--u', `${U}px`);
if (PORTRAIT) document.body.classList.add('portrait');
const D = await (await fetch('data.json')).json();
const T0 = Date.parse(D.t0);
const DT = D.dt;
const NS = D.sep_km.length;
const sec = (iso) => (Date.parse(iso) - T0) / 1000;
const DUR = 45;
// ---------------------------------------------------------------------------
// Interpolation
// ---------------------------------------------------------------------------
function cr(arr, t, out, scale = 1) {
const x = Math.min(Math.max(t / DT, 1), NS - 3);
const i = Math.floor(x);
const u = x - i;
const u2 = u * u;
const u3 = u2 * u;
for (let k = 0; k < 3; k++) {
const p0 = arr[(i - 1) * 3 + k];
const p1 = arr[i * 3 + k];
const p2 = arr[(i + 1) * 3 + k];
const p3 = arr[(i + 2) * 3 + k];
out[k] =
0.5 * scale *
(2 * p1 + (-p0 + p2) * u + (2 * p0 - 5 * p1 + 4 * p2 - p3) * u2 + (-p0 + 3 * p1 - 3 * p2 + p3) * u3);
if (out.length > 3) {
out[3 + k] = (0.5 * scale * ((-p0 + p2) + 2 * (2 * p0 - 5 * p1 + 4 * p2 - p3) * u + 3 * (-p0 + 3 * p1 - 3 * p2 + p3) * u2)) / DT;
}
}
return out;
}
const v3 = Cesium.Cartesian3;
const tmp6 = new Float64Array(6);
function x36Teme(t) {
cr(D.x36, t, tmp6, 1000);
return { r: new v3(tmp6[0], tmp6[1], tmp6[2]), v: new v3(tmp6[3], tmp6[4], tmp6[5]) };
}
const tmp3 = new Float64Array(3);
function relAt(t) {
cr(D.rel, t, tmp3, 1);
return [tmp3[0], tmp3[1], tmp3[2]];
}
function sepAt(t) {
const x = Math.min(Math.max(t / DT, 0), NS - 2);
const i = Math.floor(x);
return D.sep_km[i] + (D.sep_km[i + 1] - D.sep_km[i]) * (x - i);
}
function litAt(t) {
return D.lit[Math.round(Math.min(Math.max(t / DT, 0), NS - 1))] === '1';
}
function basis(r, v) {
const R = v3.normalize(r, new v3());
const N = v3.normalize(v3.cross(r, v, new v3()), new v3());
const T = v3.cross(N, R, new v3());
return { R, T, N };
}
// Curvilinear placement: along-track offset is an arc on the anchor orbit.
function place(anchor, B, rel) {
const rm = v3.magnitude(anchor);
const th = rel[1] / rm;
const c = Math.cos(th);
const s = Math.sin(th);
const Rp = new v3(B.R.x * c + B.T.x * s, B.R.y * c + B.T.y * s, B.R.z * c + B.T.z * s);
const out = v3.multiplyByScalar(Rp, rm + rel[0], new v3());
return v3.add(out, v3.multiplyByScalar(B.N, rel[2], new v3()), out);
}
// ---------------------------------------------------------------------------
// Time maps. tau(s): simulation clock. b(s): backdrop/anchor clock (Earth and
// lighting), equal to tau around closest approach.
// ---------------------------------------------------------------------------
const CA_T = sec(D.ca.t);
const VANTOR_T = sec(D.vantor.t);
const TAU_KEYS = [
[0.0, '2026-09-30T07:30:00Z'],
[4.0, '2026-09-30T10:20:00Z'],
[7.0, '2026-09-30T13:00:00Z'],
[12.5, '2026-10-11T23:20:00Z'],
[15.0, '2026-10-12T03:20:00Z'],
[17.0, '2026-10-15T01:30:00Z'],
[18.6, '2026-10-15T04:40:00Z'],
[20.6, '2026-10-16T04:40:00Z'],
[22.2, '2026-10-16T07:40:00Z'],
[25.8, '2026-10-17T15:40:00Z'],
[27.6, '2026-10-17T18:10:00Z'],
[29.8, D.ca.t, -14 * 60],
[35.0, D.ca.t, 11 * 60],
[36.4, '2026-10-18T07:00:00Z'],
[40.6, '2026-10-21T10:00:00Z'],
[45.0, '2026-10-21T13:00:00Z'],
].map(([s, iso, off = 0]) => [s, sec(iso) + off]);
function monotone(keys) {
const n = keys.length;
const xs = keys.map((k) => k[0]);
const ys = keys.map((k) => k[1]);
const d = [];
for (let i = 0; i < n - 1; i++) d.push((ys[i + 1] - ys[i]) / (xs[i + 1] - xs[i]));
// Geometric-mean slopes keep huge rate swings smooth in log-space.
const m = [d[0]];
for (let i = 1; i < n - 1; i++) m.push(Math.sqrt(d[i - 1] * d[i]));
m.push(d[n - 2]);
for (let i = 0; i < n - 1; i++) {
const a = m[i] / d[i];
const b = m[i + 1] / d[i];
const h = a * a + b * b;
if (h > 9) {
const t = 3 / Math.sqrt(h);
m[i] = t * a * d[i];
m[i + 1] = t * b * d[i];
}
}
const f = (s) => {
let i = 0;
while (i < n - 2 && s > xs[i + 1]) i++;
const hh = xs[i + 1] - xs[i];
const t = Math.min(Math.max((s - xs[i]) / hh, 0), 1);
const t2 = t * t;
const t3 = t2 * t;
return (
(2 * t3 - 3 * t2 + 1) * ys[i] + (t3 - 2 * t2 + t) * hh * m[i] + (-2 * t3 + 3 * t2) * ys[i + 1] + (t3 - t2) * hh * m[i + 1]
);
};
return f;
}
const tau = monotone(TAU_KEYS);
const rate = (s) => (tau(s + 0.01) - tau(s - 0.01)) / 0.02;
const S_SYNC0 = 29.8;
const S_SYNC1 = 35.0;
function hermite(s, s0, y0, m0, s1, y1, m1) {
const h = s1 - s0;
const t = (s - s0) / h;
const t2 = t * t;
const t3 = t2 * t;
return (2 * t3 - 3 * t2 + 1) * y0 + (t3 - 2 * t2 + t) * h * m0 + (-2 * t3 + 3 * t2) * y1 + (t3 - t2) * h * m1;
}
const BG_RATE = 110;
function bclock(s) {
if (s >= S_SYNC0 && s <= S_SYNC1) return tau(s);
if (s < S_SYNC0) {
const y1 = tau(S_SYNC0);
return hermite(s, 0, y1 - S_SYNC0 * BG_RATE * 1.15, BG_RATE, S_SYNC0, y1, rate(S_SYNC0));
}
const y0 = tau(S_SYNC1);
return hermite(s, S_SYNC1, y0, rate(S_SYNC1), DUR, y0 + (DUR - S_SYNC1) * BG_RATE * 1.2, BG_RATE);
}
function sOfTau(t) {
let lo = 0;
let hi = DUR;
for (let k = 0; k < 50; k++) {
const mid = (lo + hi) / 2;
if (tau(mid) < t) lo = mid;
else hi = mid;
}
return lo;
}
// ---------------------------------------------------------------------------
// Story: captions, events, camera
// ---------------------------------------------------------------------------
const fmtKm = (km) => (km >= 100 ? `${Math.round(km).toLocaleString('en-US')}` : km >= 10 ? km.toFixed(0) : km.toFixed(1));
const CAPTIONS = [
{
s0: 0.2, s1: 4.3,
kicker: 'Low Earth orbit · 540 km · Sep 30 – Oct 21, 2026',
title: 'Hunting a radar satellite',
body: 'Over three weeks, Russia\'s military satellite Cosmos 2612 stalked ICEYE-X36, a U.S.-registered radar imager whose pictures help Ukraine — and closed to a few hundred meters.',
},
{
s0: 4.5, s1: 12.3,
kicker: '1 · Phasing',
title: 'Climb high, fall behind',
body: 'Two burns lift Cosmos 2612 47 km above its target. A higher orbit is slower, so it drifts back ~6,500 km a day and laps X36 — while Earth\'s equatorial bulge slowly swings its orbit plane into line.',
},
{
s0: 12.6, s1: 21.9,
kicker: '2 · Descent',
title: 'Drop into the same orbit',
body: 'Directly overhead on Oct 12, it drops 47 km into X36\'s orbit, 480 km behind. On Oct 15 a 2 km dip makes it slightly faster: it closes ~350 km a day — then brakes 3 km behind.',
},
{
s0: 22.1, s1: 29.6,
kicker: '3 · Proximity',
title: 'Close enough to inspect',
body: 'For two days it holds station behind X36, its path looping 1.6 km each orbit as it creeps forward. These are the maneuvers of an inspector: they need fuel, planning, and sensors that can find the target.',
},
{
s0: 29.8, s1: 35.6,
kicker: '3 · Closest approach',
title: 'In Earth\'s shadow',
body: 'Early on Oct 18, during orbital night, it passes about %CA% m behind X36 at under 1 m/s. Published estimates range from 150 to 650 m. Nine minutes later, the sun comes up.',
},
{
s0: 35.8, s1: 41.0,
kicker: '4 · Departure',
title: 'Back off, and wait',
body: 'A 1.3 m/s burn lifts it 2.4 km and it falls away at ~350 km a day. On Oct 19 it matches orbits again — and today it is still parked 480 km behind.',
},
];
const BURNS = D.burns.map((b) => ({ ...b, t: sec(b.t) }));
const BURN_NOTES = {
'Phasing raise': '+46 km',
'Plane trim': 'out-of-plane',
'Descent to X36 orbit': '−47 km',
'Closing burn': '−2.3 km',
'Braking burn': '+2.5 km',
'Back-off': '+0.13 km',
'Departure burn': '+2.4 km',
'Re-match orbit': '−2.6 km',
};
const EVENTS = [
...BURNS.map((b) => ({ t: b.t, kind: 'burn', title: `BURN · Δv ${b.dv < 1 ? b.dv.toFixed(2) : b.dv.toFixed(1)} m/s`, sub: `${b.label} · ${BURN_NOTES[b.label] || ''}`, at: 'cosmos' })),
{ t: sec('2026-10-05T11:55:00Z'), kind: 'note', title: 'OVERHEAD PASS', sub: '~50 km above X36', at: 'cosmos' },
{ t: sec('2026-10-12T00:10:00Z'), kind: 'note', title: 'OVERHEAD PASS', sub: '47 km directly above', at: 'cosmos' },
{ t: VANTOR_T, kind: 'vantor', title: 'VANTOR IMAGES THE PAIR', sub: `from orbit · ~${D.vantor.km.toFixed(1)} km apart · Oct 17`, at: 'mid' },
{ t: CA_T, kind: 'ca', title: `CLOSEST APPROACH · ~${Math.round(D.ca.m / 5) * 5} m`, sub: `${D.ca.t.slice(11, 16)} UTC Oct 18 · est. range 150–650 m`, at: 'mid' },
].map((e) => ({ ...e, s: sOfTau(e.t) }));
// Two burns that land in the same instant only show once.
EVENTS.sort((a, b) => a.s - b.s);
// Camera keys, in X36's local frame (R up, T velocity, N orbit normal).
// dist: metres (or auto = f * separation, floored at min). az: 0 = behind X36
// looking forward. look: 0 = X36, 1 = Cosmos. earth: pull aim to Earth centre.
const WIDE = { f: 0, look: 0, earth: 0.86, fov: 40, mag: 0, sun: 0.55 };
const CAM = [
{ s: 0.0, ...WIDE, dist: 5.4e7, az: 82, el: 36, trail: 2 },
{ s: 6.0, ...WIDE, dist: 4.6e7, az: 96, el: 34, trail: 20 },
{ s: 12.5, ...WIDE, dist: 4.4e7, az: 118, el: 30, trail: 30 },
{ s: 12.5, cut: true, dist: 6.0e5, f: 2.8, az: 50, el: 38, look: 0.5, earth: 0, fov: 34, mag: 0, trail: 3 },
{ s: 15.4, dist: 1.6e6, f: 2.8, az: 32, el: 36, look: 0.5, earth: 0, fov: 34, mag: 0, trail: 8 },
{ s: 18.0, dist: 1.4e6, f: 2.8, az: 26, el: 34, look: 0.5, earth: 0, fov: 34, mag: 0, trail: 12 },
{ s: 20.4, dist: 4.0e4, f: 2.8, az: 40, el: 32, look: 0.5, earth: 0, fov: 34, mag: 0, trail: 10 },
{ s: 22.4, dist: 6.5e3, f: 0, az: 58, el: 34, look: 0.45, earth: 0, fov: 36, mag: 1, trail: 9 },
{ s: 26.0, dist: 4.6e3, f: 0, az: 76, el: 30, look: 0.5, earth: 0, fov: 36, mag: 1, trail: 9 },
{ s: 28.8, dist: 2.2e3, f: 0, az: 100, el: 22, look: 0.4, earth: 0, fov: 36, mag: 1, trail: 4 },
{ s: 29.9, dist: 12, f: 0, az: 96, el: 16, look: 0.0, earth: 0, fov: 40, mag: 0, trail: 0.3 },
{ s: 30.8, dist: 13, f: 0, az: 122, el: 14, look: 0.0, earth: 0, fov: 40, mag: 0, trail: 0.3 },
{ s: 31.6, dist: 18, f: 0, az: 168, el: 9, look: 0.0, earth: 0, fov: 40, mag: 0, trail: 0.3, aimRel: [0, -60, 0] },
{ s: 32.6, dist: 1.0e3, f: 0, az: 112, el: 26, look: 0.5, earth: 0, fov: 36, mag: 1, trail: 1.2 },
{ s: 35.0, dist: 1.3e3, f: 0, az: 96, el: 18, look: 0.5, earth: 0, fov: 36, mag: 1, trail: 1.6 },
{ s: 36.6, dist: 1.2e4, f: 2.8, az: 110, el: 30, look: 0.4, earth: 0, fov: 36, mag: 1, trail: 4 },
{ s: 39.0, dist: 9.0e5, f: 2.8, az: 60, el: 30, look: 0.5, earth: 0, fov: 34, mag: 0, trail: 30 },
{ s: 41.2, dist: 2.0e6, f: 2.8, az: 44, el: 30, look: 0.5, earth: 0, fov: 34, mag: 0, trail: 60 },
{ s: 41.2, cut: true, ...WIDE, dist: 4.8e7, az: 80, el: 34, trail: 60 },
{ s: 45.0, ...WIDE, dist: 4.2e7, az: 96, el: 32, trail: 60 },
];
const CUTS = CAM.filter((k) => k.cut).map((k) => k.s);
const smooth = (x) => x * x * x * (x * (x * 6 - 15) + 10);
function camAt(s) {
// Keys are grouped into shots at cut keys; interpolation never crosses a cut.
let start = 0;
for (let k = 1; k < CAM.length; k++) if (CAM[k].cut && s >= CAM[k].s) start = k;
let end = CAM.length - 1;
for (let k = start + 1; k < CAM.length; k++) if (CAM[k].cut) { end = k - 1; break; }
let i = start;
while (i < end - 1 && s > CAM[i + 1].s) i++;
const a = CAM[i];
const b = CAM[Math.min(i + 1, end)];
const u = b === a ? 0 : smooth(Math.min(Math.max((s - a.s) / (b.s - a.s), 0), 1));
const lerp = (x, y) => x + (y - x) * u;
const ar = a.aimRel || [0, 0, 0];
const br = b.aimRel || [0, 0, 0];
return {
dist: Math.exp(lerp(Math.log(a.dist), Math.log(b.dist))),
f: lerp(a.f, b.f),
az: lerp(a.az, b.az),
el: lerp(a.el, b.el),
look: lerp(a.look, b.look),
earth: lerp(a.earth, b.earth),
fov: lerp(a.fov, b.fov),
mag: lerp(a.mag, b.mag),
trail: Math.exp(lerp(Math.log(a.trail), Math.log(b.trail))),
aimRel: [0, 1, 2].map((k) => lerp(ar[k], br[k])),
sun: lerp(a.sun || 0, b.sun || 0),
};
}
// ---------------------------------------------------------------------------
// Cesium scene
// ---------------------------------------------------------------------------
const esri = await Cesium.ArcGisMapServerImageryProvider.fromUrl(
'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
{ enablePickFeatures: false, maximumLevel: 11 },
);
const viewer = new Cesium.Viewer('globe', {
baseLayer: new Cesium.ImageryLayer(esri, { brightness: 0.92, contrast: 1.08, gamma: 1.05 }),
animation: false, timeline: false, baseLayerPicker: false, geocoder: false, homeButton: false,
sceneModePicker: false, navigationHelpButton: false, fullscreenButton: false, infoBox: false,
selectionIndicator: false, useDefaultRenderLoop: false, shouldAnimate: false,
contextOptions: { webgl: { preserveDrawingBuffer: true, alpha: false } },
msaaSamples: 1,
});
const scene = viewer.scene;
// Night side: NASA Black Marble city lights (keyless GIBS tiles).
const nightLayer = viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
url: 'https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/VIIRS_Black_Marble/default/2016-01-01/GoogleMapsCompatible_Level8/{z}/{y}/{x}.png',
maximumLevel: 8, credit: 'NASA Black Marble',
}));
nightLayer.dayAlpha = 0.0;
nightLayer.nightAlpha = 1.0;
nightLayer.brightness = 1.6;
viewer.imageryLayers.get(0).nightAlpha = 0.0;
// Sky: ESO Milky Way cube (stars removed) + Yale Bright Star Catalogue points.
scene.skyBox = new Cesium.SkyBox({ sources: Object.fromEntries(
[['positiveX', 'px'], ['negativeX', 'nx'], ['positiveY', 'py'], ['negativeY', 'ny'], ['positiveZ', 'pz'], ['negativeZ', 'nz']]
.map(([k, f]) => [k, `/sky/milkyway_${f}.webp`])) });
const starData = await (await fetch('/sky/bright_stars.json')).json();
const starArr = Array.isArray(starData) ? starData : starData.stars || starData.data;
const stars = scene.primitives.add(new Cesium.PointPrimitiveCollection({ blendOption: Cesium.BlendOption.TRANSLUCENT }));
const starDirs = [];
for (let i = 0; i + 3 < starArr.length; i += 4) {
const [ra, dec, vm, bv] = [starArr[i], starArr[i + 1], starArr[i + 2], starArr[i + 3]];
const r = Cesium.Math.toRadians(ra);
const d = Cesium.Math.toRadians(dec);
const dir = new Cesium.Cartesian3(Math.cos(d) * Math.cos(r), Math.cos(d) * Math.sin(r), Math.sin(d));
const b = Math.min(1, Math.sqrt(10 ** (-0.4 * ((Number.isFinite(vm) ? vm : 6.5) - 6.5))) / 9);
const t = Math.min(Math.max(((Number.isFinite(bv) ? bv : 0.6) + 0.3) / 2.0, 0), 1);
const col = new Cesium.Color(0.78 + 0.22 * t, 0.84 + 0.06 * (1 - Math.abs(t - 0.4)), 1.0 - 0.3 * t, 0.25 + 0.75 * b);
starDirs.push(dir);
stars.add({ position: dir, color: col, pixelSize: 0.9 + 2.6 * b });
}
const globe = scene.globe;
globe.enableLighting = true;
globe.dynamicAtmosphereLighting = true;
globe.dynamicAtmosphereLightingFromSun = true;
globe.showGroundAtmosphere = true;
globe.atmosphereLightIntensity = 9;
globe.lightingFadeOutDistance = 1;
globe.lightingFadeInDistance = 2;
globe.nightFadeOutDistance = 1e10;
globe.nightFadeInDistance = 1e10;
globe.maximumScreenSpaceError = 1.6;
globe.tileCacheSize = 1500;
globe.preloadSiblings = false;
globe.baseColor = Cesium.Color.fromCssColorString('#04070d');
scene.fog.enabled = false;
scene.skyAtmosphere.show = true;
scene.skyAtmosphere.atmosphereLightIntensity = 10;
scene.highDynamicRange = false;
scene.sun.glowFactor = 1.6;
scene.moon.show = true;
scene.postProcessStages.fxaa.enabled = true;
scene.backgroundColor = Cesium.Color.BLACK;
scene.screenSpaceCameraController.enableInputs = false;
scene.camera.frustum.near = 0.5;
scene.camera.frustum.far = 1e9;
viewer.resolutionScale = 1;
const bloom = scene.postProcessStages.bloom;
bloom.enabled = false;
bloom.uniforms.contrast = 119;
bloom.uniforms.brightness = -0.42;
bloom.uniforms.glowOnly = false;
bloom.uniforms.delta = 1.0;
bloom.uniforms.sigma = 3.2;
bloom.uniforms.stepSize = 1.0;
const COL_X36 = Cesium.Color.fromCssColorString('#5ce1e6');
const COL_COS = Cesium.Color.fromCssColorString('#ff5a3c');
const COL_BURN = Cesium.Color.fromCssColorString('#ffb547');
const modelOpts = { upAxis: Cesium.Axis.Z, forwardAxis: Cesium.Axis.X, shadows: Cesium.ShadowMode.DISABLED };
const mX36 = await Cesium.Model.fromGltfAsync({ url: 'iceye-x36.glb', ...modelOpts });
const mCos = await Cesium.Model.fromGltfAsync({ url: 'cosmos-2612.glb', ...modelOpts });
scene.primitives.add(mX36);
scene.primitives.add(mCos);
for (const m of [mX36, mCos]) {
m.environmentMapOptions = { enabled: false };
m.imageBasedLighting.sphericalHarmonicCoefficients = undefined;
}
function glowCanvas(color, core = 0.18) {
const c = document.createElement('canvas');
c.width = c.height = 128;
const g = c.getContext('2d');
const grd = g.createRadialGradient(64, 64, 0, 64, 64, 64);
grd.addColorStop(0, 'rgba(255,255,255,1)');
grd.addColorStop(core, color.withAlpha(1).toCssColorString());
grd.addColorStop(0.45, color.withAlpha(0.28).toCssColorString());
grd.addColorStop(1, color.withAlpha(0).toCssColorString());
g.fillStyle = grd;
g.fillRect(0, 0, 128, 128);
return c;
}
const billboards = scene.primitives.add(new Cesium.BillboardCollection({ scene }));
const bX36 = billboards.add({ image: glowCanvas(COL_X36), scale: 0.3 * U, disableDepthTestDistance: 0 });
const bCos = billboards.add({ image: glowCanvas(COL_COS), scale: 0.3 * U, disableDepthTestDistance: 0 });
const bBurn = billboards.add({ image: glowCanvas(COL_BURN, 0.08), scale: 0, disableDepthTestDistance: 0 });
let dynamic = [];
function clearDynamic() {
for (const p of dynamic) scene.primitives.remove(p);
dynamic = [];
}
function polyline(positions, colors, width) {
if (positions.length < 2) return;
const p = new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.PolylineGeometry({
positions, colors, colorsPerVertex: true, width: width * U, arcType: Cesium.ArcType.NONE,
}),
}),
appearance: new Cesium.PolylineColorAppearance({ translucent: true }),
asynchronous: false,
});
scene.primitives.add(p);
dynamic.push(p);
}
// ---------------------------------------------------------------------------
// HUD
// ---------------------------------------------------------------------------
const $ = (q) => document.querySelector(q);
const capEl = $('#caption');
const tagsEl = $('#tags');
const leaders = $('#leaders');
const callEl = $('#callouts');
leaders.setAttribute('viewBox', `0 0 ${W} ${H}`);
function fade(s, s0, s1, ramp = 0.45) {
return Math.min(1, Math.max(0, (s - s0) / ramp), Math.max(0, (s1 - s) / ramp));
}
function fmtRate(r) {
const p = 10 ** Math.floor(Math.log10(r) - 1);
const rr = Math.round(r / p) * p;
const real = rr;
let per;
if (real < 60) per = `${real.toFixed(0)} s`;
else if (real < 3600) per = `${(real / 60).toFixed(real < 600 ? 1 : 0)} min`;
else if (real < 86400) per = `${(real / 3600).toFixed(real < 36000 ? 1 : 0)} h`;
else per = `${(real / 86400).toFixed(1)} days`;
return `×${rr.toLocaleString('en-US')} · 1 s = ${per}`;
}
// Separation chart (log scale), drawn once and revealed by a clip.
const CH = { t0: sec('2026-09-30T00:00:00Z'), t1: sec('2026-10-21T18:00:00Z'), lo: 0.1, hi: 20000 };
const chartBox = $('#chart');
function buildChart() {
const cw = chartBox.clientWidth;
const ch = chartBox.clientHeight;
const padL = 70 * U;
const padT = 34 * U;
const padB = 26 * U;
const x = (t) => padL + ((t - CH.t0) / (CH.t1 - CH.t0)) * (cw - padL);
const y = (km) => padT + (1 - (Math.log10(km) - Math.log10(CH.lo)) / (Math.log10(CH.hi) - Math.log10(CH.lo))) * (ch - padT - padB);
const cols = Math.round(cw - padL);
let lo = '';
let hi = '';
const ptsHi = [];
for (let c = 0; c <= cols; c++) {
const ta = CH.t0 + (c / cols) * (CH.t1 - CH.t0);
const tb = CH.t0 + ((c + 1) / cols) * (CH.t1 - CH.t0);
let mn = Infinity;
let mx = 0;
for (let i = Math.floor(ta / DT); i <= Math.ceil(tb / DT); i++) {
const v = D.sep_km[Math.min(Math.max(i, 0), NS - 1)];
mn = Math.min(mn, v);
mx = Math.max(mx, v);
}
mn = Math.max(mn, CH.lo);
lo += `${c ? 'L' : 'M'}${(padL + c).toFixed(1)},${y(mn).toFixed(1)}`;
ptsHi.push(`${(padL + c).toFixed(1)},${y(mx).toFixed(1)}`);
}
hi = 'L' + ptsHi.reverse().join('L');
const grid = [0.1, 1, 10, 100, 1000, 10000]
.map((v) => {
const lab = v < 1 ? '100 m' : v < 1000 ? `${v} km` : `${(v).toLocaleString('en-US')} km`;
return `