html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>NGC 3372 — Carina Nebula Voyage</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,500;1,300;1,500&family=JetBrains+Mono:wght@300;400&family=Space+Grotesk:wght@300;400;500&display=swap" rel="stylesheet">
<style>
:root{
  --ink:#e9e4da; --dim:rgba(233,228,218,.62); --faint:rgba(233,228,218,.28);
  --gold:#f2b866; --teal:#6fd3d0; --rose:#ef7f8e;
  --glass:rgba(8,10,16,.52);
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;background:#020309;overflow:hidden;color:var(--ink);font-family:'Space Grotesk',system-ui,sans-serif;-webkit-font-smoothing:antialiased}
#gl{position:fixed;inset:0;width:100%;height:100%;display:block;cursor:grab;touch-action:none}
#gl.drag{cursor:grabbing}
#shade{position:fixed;inset:0;pointer-events:none;
  background:
   linear-gradient(to top,rgba(2,3,9,.78) 0%,rgba(2,3,9,0) 30%),
   linear-gradient(to bottom,rgba(2,3,9,.55) 0%,rgba(2,3,9,0) 20%)}
.mono{font-family:'JetBrains Mono',monospace;font-weight:300;letter-spacing:.08em;text-transform:uppercase;font-size:10.5px}

/* labels */
#labels{position:fixed;inset:0;pointer-events:none;overflow:hidden}
.lbl{position:absolute;left:0;top:0;white-space:nowrap;opacity:0;will-change:transform,opacity;transition:opacity .25s}
.lbl i{position:absolute;left:-3px;top:-3px;width:7px;height:7px;border-radius:50%;border:1px solid var(--ink);box-shadow:0 0 12px rgba(255,255,255,.5)}
.lbl b{position:absolute;left:3px;top:-1px;width:26px;height:1px;background:linear-gradient(90deg,var(--ink),transparent);transform-origin:left;transform:rotate(-28deg)}
.lbl span{position:absolute;left:30px;top:-27px;font-family:'Cormorant Garamond',serif;font-style:italic;font-size:19px;color:var(--ink);text-shadow:0 0 14px rgba(0,0,0,.9)}
.lbl span small{display:block;font-family:'JetBrains Mono',monospace;font-style:normal;font-size:9px;letter-spacing:.14em;text-transform:uppercase;color:var(--dim);margin-top:-1px}

/* HUD */
.hud{position:fixed;transition:opacity .8s ease}
#brand,#hint,#scale,#year{pointer-events:none}
body.nohud .hud{opacity:0;pointer-events:none}
#brand{left:28px;top:24px}
#brand h1{font-family:'Cormorant Garamond',serif;font-weight:300;font-size:30px;letter-spacing:.02em;line-height:1}
#brand h1 em{font-style:italic;color:var(--gold)}
#brand p{margin-top:8px;color:var(--dim)}
#tools{right:28px;top:22px;display:flex;gap:10px;align-items:center}
.seg{display:flex;background:var(--glass);border:1px solid var(--faint);border-radius:100px;padding:3px;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px)}
.seg button,.pill{font:inherit;cursor:pointer;color:var(--dim);background:none;border:0;padding:7px 14px;border-radius:100px;transition:.25s}
.seg button:hover,.pill:hover{color:var(--ink)}
.seg button.on{background:rgba(233,228,218,.14);color:var(--ink)}
.pill{background:var(--glass);border:1px solid var(--faint);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px)}
.pill.on{color:var(--gold);border-color:rgba(242,184,102,.5)}

#card{left:28px;bottom:84px;width:min(430px,calc(100vw - 56px));padding:20px 22px 18px;background:var(--glass);border:1px solid rgba(233,228,218,.14);border-radius:14px;backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);transition:opacity .9s ease,transform .9s ease}
#card.hide{opacity:0;transform:translateY(10px)}
#card .num{color:var(--gold)}
#card h2{font-family:'Cormorant Garamond',serif;font-weight:500;font-size:34px;line-height:1.05;margin:6px 0 2px}
#card .sub{color:var(--teal);margin-bottom:12px}
#card p{font-size:14px;line-height:1.55;color:rgba(233,228,218,.82);font-weight:300}
#card p+p{margin-top:8px}
#erupt{margin-top:14px;display:none}
#erupt.show{display:inline-block}

#nav{left:50%;bottom:22px;transform:translateX(-50%);display:flex;align-items:center;gap:6px;padding:6px 8px;background:var(--glass);border:1px solid var(--faint);border-radius:100px;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);max-width:calc(100vw - 24px)}
#nav button{font:inherit;cursor:pointer;color:var(--dim);background:none;border:0;padding:7px 11px;border-radius:100px;white-space:nowrap;transition:.25s;position:relative}
#nav button:hover{color:var(--ink)}
#nav button.on{color:var(--ink);background:rgba(233,228,218,.12)}
#nav .play{width:34px;height:34px;padding:0;display:grid;place-items:center;border:1px solid var(--faint);margin-right:4px}
#nav .play svg{width:12px;height:12px;fill:var(--ink)}
#nav .bar{position:absolute;left:11px;bottom:3px;height:1px;background:var(--gold);width:0}

#scale{right:28px;bottom:26px;text-align:right}
#scale .line{height:7px;border:1px solid var(--ink);border-top:0;margin-left:auto;transition:width .1s;opacity:.85}
#scale .val{margin-top:5px;color:var(--ink)}
#scale .z{color:var(--dim);margin-top:2px}
#hint{right:28px;bottom:92px;color:var(--faint);text-align:right;line-height:1.7}

#year{left:50%;top:18%;transform:translateX(-50%);text-align:center;opacity:0;transition:opacity .6s;pointer-events:none}
#year.on{opacity:1}
#year .y{font-family:'Cormorant Garamond',serif;font-size:76px;font-weight:300;letter-spacing:.04em;line-height:1}
#year .t{color:var(--gold);margin-top:6px}

/* intro */
#intro{position:fixed;inset:0;display:grid;place-items:center;text-align:center;z-index:20;transition:opacity 1.6s ease,visibility 1.6s;background:radial-gradient(ellipse at center,rgba(2,3,9,.15),rgba(2,3,9,.7))}
#intro.gone{opacity:0;visibility:hidden;pointer-events:none}
#intro .cat{color:var(--gold);margin-bottom:16px;opacity:0;animation:rise 2s .4s forwards}
#intro h1{font-family:'Cormorant Garamond',serif;font-weight:300;font-size:clamp(46px,9vw,132px);line-height:.95;letter-spacing:.01em;opacity:0;animation:rise 2.4s .8s forwards}
#intro h1 em{font-style:italic;font-weight:300;background:linear-gradient(100deg,#f7d08f,#f08aa0 45%,#7fd9d4);-webkit-background-clip:text;background-clip:text;color:transparent}
#intro p{max-width:520px;margin:20px auto 30px;color:var(--dim);font-weight:300;line-height:1.6;font-size:15px;opacity:0;animation:rise 2s 1.6s forwards;padding:0 20px}
#intro .btns{display:flex;gap:12px;justify-content:center;flex-wrap:wrap;opacity:0;animation:rise 2s 2.2s forwards}
.cta{font:inherit;cursor:pointer;color:#0a0a10;background:linear-gradient(100deg,#f7d08f,#f0a3a0);border:0;padding:13px 26px;border-radius:100px;font-weight:500;letter-spacing:.1em;text-transform:uppercase;font-size:11px;transition:.3s;box-shadow:0 0 40px rgba(242,184,102,.25)}
.cta:hover{transform:translateY(-2px);box-shadow:0 0 60px rgba(242,184,102,.45)}
.cta.ghost{background:none;color:var(--ink);border:1px solid var(--faint);box-shadow:none}
@keyframes rise{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}
#nogl{position:fixed;inset:0;display:none;place-items:center;text-align:center;padding:30px;z-index:30;background:#020309}

@media (max-width:760px){
  #brand h1{font-size:22px}#tools{top:auto;bottom:140px;right:14px;flex-direction:column;align-items:flex-end}
  #brand{left:16px;top:16px}#card{left:12px;bottom:76px;padding:14px 16px}#card h2{font-size:26px}#card p{font-size:13px}
  #hint,#scale .z{display:none}#scale{right:14px;bottom:88px}
  #nav button:not(.on):not(.play){padding:7px 8px;font-size:9px}
  .seg button{padding:6px 10px}
}
@media (prefers-reduced-motion:reduce){
  #intro .cat,#intro h1,#intro p,#intro .btns{animation-duration:.01s;animation-delay:0s}
}
</style>
</head>
<body>
<canvas id="gl"></canvas>
<div id="shade"></div>
<div id="labels"></div>

<div id="brand" class="hud">
  <h1>NGC&nbsp;3372 · <em>Carina</em></h1>
  <p class="mono">Constellation Carina · ≈ 7,500 light-years</p>
</div>

<div id="tools" class="hud">
  <div class="seg mono" id="pal">
    <button data-m="0" class="on">Hubble</button>
    <button data-m="1">Natural</button>
    <button data-m="2">Infrared</button>
  </div>
  <button class="pill mono" id="snd">Sound off</button>
  <button class="pill mono" id="hide" title="Hide interface (H)">Hide UI</button>
</div>

<div id="card" class="hud hide">
  <div class="num mono" id="cNum"></div>
  <h2 id="cTitle"></h2>
  <div class="sub mono" id="cSub"></div>
  <div id="cText"></div>
  <button class="pill mono" id="erupt">▸ Replay the 1843 Great Eruption</button>
</div>

<div id="year" class="hud"><div class="y" id="yv">1843</div><div class="t mono">The Great Eruption · η Carinae</div></div>

<div id="hint" class="hud mono">Drag · pan<br>Scroll · zoom<br>Cursor · stellar wind<br>Space · pause · H · hide</div>

<div id="nav" class="hud mono"></div>

<div id="scale" class="hud">
  <div class="line" id="sLine" style="width:100px"></div>
  <div class="val mono" id="sVal"></div>
  <div class="z mono" id="sZ"></div>
</div>

<div id="intro">
  <div>
    <div class="cat mono">A procedural voyage · rendered live in your browser</div>
    <h1>The <em>Carina</em><br>Nebula</h1>
    <p>A stellar nursery four times the size of Orion, home to one of the most massive stars known. Fly from 300 light-years down to the scale of a single stellar eruption.</p>
    <div class="btns">
      <button class="cta" id="begin">Begin the voyage</button>
      <button class="cta ghost" id="free">Explore freely</button>
    </div>
  </div>
</div>
<div id="nogl"><div><h2 style="font-family:'Cormorant Garamond',serif;font-weight:300;font-size:34px">WebGL is unavailable</h2><p style="color:var(--dim);margin-top:10px">This animation needs a WebGL-capable browser to render the nebula.</p></div></div>

<script>
/* ============================================================
   NGC 3372 — Carina Nebula voyage
   Everything is generated procedurally on the GPU (no images):
   domain-warped fractal gas, emission-line palettes, dust lanes,
   wind-carved cavities, parallax star fields with diffraction
   spikes, the Keyhole, Mystic Mountains pillars with jets, and
   the Homunculus around Eta Carinae.
   World units: 1 unit ≈ 100 light-years.
   ============================================================ */

const VERT = `attribute vec2 a; void main(){ gl_Position = vec4(a,0.,1.); }`;

const FRAG = `
precision highp float;
uniform vec2  uRes;
uniform float uTime;
uniform vec2  uCam;
uniform float uZoom;
uniform float uMode;      // 0 Hubble SHO, 1 natural, 2 infrared (continuous)
uniform vec3  uPtr;       // pointer world xy, wind strength
uniform float uErupt;     // <0 inactive, 0..1 progress
uniform float uFlash;     // Eta Carinae flare

const vec2 E   = vec2(-0.26, 0.02);   // Eta Carinae
const vec2 K   = vec2(-0.21,-0.01);   // Keyhole
const vec2 T14 = vec2( 0.28, 0.16);   // Trumpler 14
const vec2 MM  = vec2( 0.75,-0.55);   // Mystic Mountains
float W0,W1,W2;

float sq(float x){ return x*x; }
float hash(vec2 p){ vec3 p3 = fract(vec3(p.xyx)*.1031); p3 += dot(p3,p3.yzx+33.33); return fract((p3.x+p3.y)*p3.z); }
float vnoise(vec2 p){
  vec2 i=floor(p), f=fract(p); f=f*f*f*(f*(f*6.-15.)+10.);
  float a=hash(i), b=hash(i+vec2(1.,0.)), c=hash(i+vec2(0.,1.)), d=hash(i+vec2(1.,1.));
  return mix(mix(a,b,f.x),mix(c,d,f.x),f.y);
}
float fbm(vec2 p){
  float s=0., a=.5; mat2 m=mat2(1.6,1.2,-1.2,1.6);
  for(int i=0;i<5;i++){ s+=a*vnoise(p); p=m*p+vec2(1.7,9.2); a*=.5; }
  return s;
}
mat2 rot(float a){ float c=cos(a), s=sin(a); return mat2(c,s,-s,c); }
float sdSeg(vec2 p, vec2 a, vec2 b){ vec2 pa=p-a, ba=b-a; float h=clamp(dot(pa,ba)/dot(ba,ba),0.,1.); return length(pa-ba*h); }
float capR(vec2 p, vec2 a, vec2 b, float ra, float rb){ vec2 pa=p-a, ba=b-a; float h=clamp(dot(pa,ba)/dot(ba,ba),0.,1.); return length(pa-ba*h)-mix(ra,rb,h); }
float smin(float a,float b,float k){ float h=clamp(.5+.5*(b-a)/k,0.,1.); return mix(b,a,h)-k*h*(1.-h); }
vec3 mixM(vec3 a, vec3 b, vec3 c){ return a*W0 + b*W1 + c*W2; }

/* ---------- Mystic Mountains pillar geometry ---------- */
float pd(vec2 u){
  float d1 = capR(u, vec2(0.,-1.5),   vec2(0.12,0.55),  0.55, 0.17);
  float d2 = capR(u, vec2(-0.95,-1.5),vec2(-0.78,-0.3), 0.38, 0.10);
  float d3 = capR(u, vec2(0.9,-1.5),  vec2(1.02,-0.5),  0.34, 0.09);
  float d = smin(d1, smin(d2,d3,0.12), 0.12);
  return d + (fbm(u*2.6+vec2(7.,3.))-.5)*.36;
}

/* ---------- star sprite with Hubble-style cross spikes ---------- */
vec3 sprite(vec2 d, float br, float L, vec3 tint, float u){
  vec2 q = d/u; float r2 = dot(q,q);
  float core = exp(-r2/3.0);
  float halo = 1./(1.+r2*.05);
  float sx = exp(-abs(q.y)*1.5)*exp(-abs(q.x)/L);
  float sy = exp(-abs(q.x)*1.5)*exp(-abs(q.y)/L);
  return tint*br*(core*1.7 + halo*.13 + (sx+sy)*.55);
}

vec3 starField(vec2 cpx, float u){
  vec3 acc = vec3(0.);
  for(int l=0;l<3;l++){
    float fl = float(l);
    float e   = .12 + .28*fl;
    float cell= (34.-8.*fl)*u;
    float par = .25 + .35*fl;
    float tz  = log2(uZoom)*e;
    float k   = floor(tz);
    float f   = tz - k;
    vec2 pan  = uCam*uRes.y*1.2*par;
    for(int b=0;b<2;b++){
      float fb = float(b);
      float sc = exp2(fb - f);
      float wgt = (b==0) ? 1.-f : f;
      vec2 cc = (cpx + pan)*sc/cell;
      vec2 id = floor(cc), fr = fract(cc);
      float seed = k + fb + fl*17.;
      float h1 = hash(id + seed*7.13);
      if(h1 > .875){
        float h2 = hash(id.yx*1.3 + seed*3.7 + 11.);
        float h3 = hash(id*.7 + seed*5.1 + 31.);
        vec2 sp = .22 + .56*vec2(hash(id+seed+50.), hash(id+seed+90.));
        vec2 dpx = (fr - sp)*cell/sc;
        float r = length(dpx)/u;
        float mag = h3*h3*h3;
        float size = .75 + 1.7*mag + .3*fl;
        float core = exp(-r*r/(size*size));
        float halo = mag*.4*exp(-r/(3.+5.*mag));
        float tw = .86 + .14*sin(uTime*(1.+3.*h2)+h2*40.);
        vec3 tint = mix(vec3(1.,.74,.52), vec3(.72,.86,1.2), h2);
        acc += tint*(core*(.3+1.1*mag)+halo)*tw*wgt*(.95-.15*fl);
      }
    }
  }
  return acc;
}

vec3 bigStars(vec2 cpx, float ppu, float u){
  vec3 acc = vec3(0.);
  for(int i=0;i<30;i++){
    float fi = float(i);
    vec2 c; float spread;
    if(fi<12.){ c=E; spread=.17; } else if(fi<22.){ c=T14; spread=.09; } else { c=vec2(.05,.0); spread=1.15; }
    vec2 o = vec2(hash(vec2(fi,1.7)), hash(vec2(fi,9.1)))*2.-1.;
    vec2 sp = c + o*length(o)*spread;
    float m = hash(vec2(fi,4.4));
    float br = .45 + 1.0*m*m;
    vec2 d = (sp-uCam)*ppu - cpx;
    if(abs(d.x)<700.*u && abs(d.y)<700.*u){
      vec3 tint = mix(vec3(.75,.88,1.25), vec3(1.,.82,.62), step(.82, hash(vec2(fi,6.6))));
      acc += sprite(d, br, 26.+60.*m, tint, u);
    }
  }
  // Eta Carinae itself
  vec2 d = (E-uCam)*ppu - cpx;
  if(abs(d.x)<1400.*u && abs(d.y)<1400.*u){
    float br = 2.0 + uFlash*7.;
    acc += sprite(d, br, 110.+uFlash*300., vec3(1.,.9,.74), u);
  }
  return acc;
}

void main(){
  vec2 cpx = gl_FragCoord.xy - .5*uRes;
  float u = uRes.y/900.;
  float ppu = uRes.y/3.2*uZoom;
  vec2 p = uCam + cpx/ppu;
  W0 = max(0.,1.-abs(uMode)); W1 = max(0.,1.-abs(uMode-1.)); W2 = max(0.,1.-abs(uMode-2.));

  // stellar wind from the pointer pushes gas outward
  vec2 wd = p - uPtr.xy;
  float wr = 150.*u/ppu;
  float wf = exp(-dot(wd,wd)/(wr*wr));
  vec2 pw = p - wd*wf*uPtr.z;

  float S  = pow(uZoom,.7);
  vec2 np  = pw*S*1.8;
  float t  = uTime;

  // domain-warped fractal gas
  vec2 q = vec2(fbm(np + vec2(0.,t*.015)), fbm(np + vec2(5.2,1.3) - t*.012));
  vec2 r = vec2(fbm(np + 3.*q + vec2(1.7,9.2) + t*.025), fbm(np + 3.*q + vec2(8.3,2.8) - t*.02));
  float g  = fbm(np + 3.5*r);
  float g2 = smoothstep(.25,.8,g);

  // overall envelope of the nebula
  vec2 ep = rot(-.2)*pw;
  float ed = length(ep/vec2(1.45,.85));
  float env = 1. - smoothstep(.25, 1.05 + .55*(r.x-.5), ed);
  env = pow(max(env,0.),1.15);

  // the great V-shaped dust lane + dust clouds
  vec2 lp = pw + .10*(r-.5);
  float dl = min(sdSeg(lp, vec2(-1.2,.6), vec2(-.05,-.30)), sdSeg(lp, vec2(-.05,-.30), vec2(1.1,.5)));
  float lane = exp(-pow(dl/(.075+.04*g),2.));
  float cloud = smoothstep(.54,.78, r.y*.6+g*.55);
  float dust = clamp(lane*(.6+.9*g) + cloud*.8*env, 0., 1.3);

  // Keyhole globule
  vec2 kp = pw - K;
  float kd = min(length(kp) - .022 - .008*(fbm(kp*140.)-.5)*2., sdSeg(kp, vec2(0.), vec2(.004,-.045)) - .007);
  float kmask = 1. - smoothstep(-.002,.003,kd);
  float krim  = exp(-sq((kd-.003)/.005));
  dust = max(dust, kmask*1.6);

  // ionisation by hot stars, cavities carved by winds
  float dE = length(p-E), dT = length(p-T14), dM = length(p-MM);
  float ion = clamp(exp(-dE*2.2) + .7*exp(-dT*3.) + .5*exp(-dM*5.), 0., 1.5);
  float cav = 1. - .55*exp(-pow(dT/.16,2.)) - .4*exp(-pow(dE/.2,2.));
  float rim = exp(-sq((dT-.2)/.05)) + exp(-sq((dE-.27)/.06));
  float shell = exp(-sq((g-.5)*7.));
  float base = env*cav;

  vec2 mu = (pw-MM)/.017;
  float bgm = exp(-dot(mu,mu)*.08);

  float Ha   = base*(.25 + 1.6*g2*g2 + .6*shell)*(.5+ion) + bgm*.9;
  float OIII = base*(g2*1.4 + .5*shell)*pow(ion,1.6)*1.2 + env*exp(-dE*5.) + bgm*.8;
  float SII  = base*(.15 + 1.2*g2*(1.-min(ion,1.)) + .7*shell*(1.-.5*ion)) + rim*env*.5 + bgm*.3;

  float att = exp(-dust*2.2);
  float edge = clamp(dust*(1.-clamp(dust,0.,1.))*4.,0.,1.)*max(env,bgm);
  Ha*=att; OIII*=att; SII*=att;
  SII += edge*.7*(.4+ion);  Ha += edge*.5*(.4+ion);
  Ha += krim*1.2; OIII += krim*.8; SII += krim*.4;

  // palettes
  vec3 cS = vec3(SII*.95+Ha*.7, Ha*.5+SII*.12+OIII*.45, OIII*.9+Ha*.1)*vec3(1.,.93,.9);
  vec3 cN = Ha*vec3(1.,.16,.3) + OIII*vec3(.05,.65,.8) + SII*vec3(.9,.12,.1) + edge*vec3(.15,.25,.6)*.9*(.3+ion);
  float ir = clamp((dust*.75+.12)*env*(.35+g)*(.5+.8*ion) + (Ha+SII)*.25 + krim*.6, 0., 2.6);
  vec3 cI = vec3(1.3*pow(ir,.8), .75*pow(ir,1.6), .5*pow(ir,3.)) + vec3(.05,0.,.18)*ir + OIII*vec3(.05,.35,.7)*.8;
  vec3 col = (cS*W0 + cN*W1 + cI*W2)*1.1 + vec3(.004,.006,.014);

  // ----- Mystic Mountains pillars & jets -----
  if(abs(mu.x)<2.8 && abs(mu.y)<2.8){
    float d = pd(mu);
    vec2 ee = vec2(.03,0.);
    vec2 n = normalize(vec2(pd(mu+ee.xy)-d, pd(mu+ee.yx)-d) + 1e-5);
    float pa = 1. - smoothstep(-.015,.02,d);
    float lit = smoothstep(-.2,.9, dot(n, normalize(vec2(-1.,.6))));
    float depth = clamp(-d/.35,0.,1.);
    float tex = fbm(mu*6.+vec2(2.,9.));
    vec3 rimc = mixM(vec3(1.,.66,.25), vec3(1.,.42,.38), vec3(1.,.9,.6));
    vec3 body = vec3(.30,.14,.07)*(.25+1.3*tex)*(.35+.65*lit)*mix(1.,.45,depth);
    float tip = exp(-length(mu-vec2(.12,.55))*2.2);
    vec3 pc = body + rimc*exp(-depth*5.)*lit*1.8 + rimc*tip*.5;
    float halo = exp(-max(d,0.)*5.)*(1.-pa)*lit;
    col += rimc*halo*.5;
    // HH 901/902-style jet from the pillar tip
    vec2 ju = rot(-.35)*(mu - vec2(.12,.55));
    float jet = exp(-sq(ju.x/(.018+.012*abs(ju.y))))*smoothstep(0.,.15,ju.y)*exp(-ju.y*.8);
    jet *= .55 + .45*sin(ju.y*13. - uTime*3.);
    col += vec3(1.,.28,.2)*jet*.9*(1.-pa);
    col = mix(col, pc, pa);
  }

  // ----- Homunculus around Eta Carinae -----
  float hz = smoothstep(80.,260.,uZoom);
  if(hz>0.001){
    float grow = 1.;
    if(uErupt>=0.) grow = .03 + .97*smoothstep(0.,1.,uErupt);
    float H = .0027*grow;
    vec2 e = pw - E;
    vec2 hu = rot(.65)*e/H;
    float y = abs(hu.y);
    float lx=.46, ly=.62;
    float ell = (hu.x/lx)*(hu.x/lx) + ((y-.62)/ly)*((y-.62)/ly);
    float n1 = fbm(hu*3.5+4.);
    ell += (n1-.5)*.5;
    float inside = 1. - smoothstep(.8,1.0,ell);
    float limb = smoothstep(.3,1.,ell);
    float tex = fbm(hu*8.+vec2(2.,5.)+t*.02);
    vec3 hc = mix(vec3(.55,.2,.1), vec3(1.,.6,.28), tex)*(.3+.5*tex) + vec3(1.,.55,.3)*pow(limb,2.)*1.1;
    hc += vec3(.35,.45,.8)*pow(limb,5.)*smoothstep(.3,1.1,hu.y*sign(hu.y))*.4;
    float eq = exp(-sq(hu.y/.045))*exp(-sq(hu.x/1.0)*.7);
    float ang = atan(e.y,e.x);
    float rr = length(hu);
    float skirt = smoothstep(.5,.85, fbm(vec2(ang*7., rr*.7 - t*.08)))*exp(-rr*.8)*(1.-inside);
    vec3 add = vec3(1.,.72,.45)*eq*1.3 + vec3(.9,.45,.3)*skirt*.55;
    float core = exp(-dot(hu,hu)*9.);
    add += vec3(1.,.9,.75)*core*(1.5+uFlash*5.);
    if(uErupt>=0.){
      float ringR = uErupt*3.4;
      add += vec3(1.,.85,.65)*exp(-sq((length(hu)-ringR)/.08))*(1.-uErupt)*1.4;
    }
    col = mix(col, hc, inside*hz*.92) + add*hz;
  }

  // ----- stars (attenuated by dust, less so in infrared) -----
  float starAtt = exp(-dust*mix(2.4,.5,W2));
  vec3 st = starField(cpx,u)*starAtt + bigStars(cpx,ppu,u)*mix(1.,starAtt,.5);
  col += st*.9;

  // tone map, vignette, grain
  col = 1. - exp(-col*1.55);
  col = pow(col, vec3(.92));
  col *= 1. - .38*pow(length(cpx/uRes.y)*1.05, 2.2);
  col += (hash(gl_FragCoord.xy + fract(uTime)*91.)-.5)*.014;
  gl_FragColor = vec4(col,1.);
}`;

/* ============================================================ */
const $ = s => document.querySelector(s);
const canvas = $('#gl');
const gl = canvas.getContext('webgl', {antialias:false, alpha:false, powerPreference:'high-performance'});
if(!gl){ $('#nogl').style.display='grid'; }

function sh(type, src){
  const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s);
  if(!gl.getShaderParameter(s, gl.COMPILE_STATUS)){ console.error(gl.getShaderInfoLog(s)); }
  return s;
}
let U = {};
if(gl){
  const prog = gl.createProgram();
  gl.attachShader(prog, sh(gl.VERTEX_SHADER, VERT));
  gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FRAG));
  gl.linkProgram(prog);
  if(!gl.getProgramParameter(prog, gl.LINK_STATUS)){ console.error(gl.getProgramInfoLog(prog)); $('#nogl').style.display='grid'; }
  gl.useProgram(prog);
  const buf = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buf);
  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1,-1, 3,-1, -1,3]), gl.STATIC_DRAW);
  const loc = gl.getAttribLocation(prog,'a'); gl.enableVertexAttribArray(loc); gl.vertexAttribPointer(loc,2,gl.FLOAT,false,0,0);
  ['uRes','uTime','uCam','uZoom','uMode','uPtr','uErupt','uFlash'].forEach(n => U[n] = gl.getUniformLocation(prog, n));
}

/* ---------------- camera / state ---------------- */
const E_ = [-0.26, 0.02], K_ = [-0.21,-0.01], T14_ = [0.28,0.16], MM_ = [0.75,-0.55];
const LZMIN = Math.log(0.6), LZMAX = Math.log(900);
const cam = {x:0.02, y:0.0, lz:Math.log(0.85)};
const tgt = {x:cam.x, y:cam.y, lz:cam.lz};
let mode = 0, modeTarget = 0, userPalette = false;
let W = innerWidth, H = innerHeight;

const stages = [
 { id:'overview', name:'Overview', x:0.0, y:0.0, z:1.2, mode:0, dwell:11,
   title:'The Carina Nebula', sub:'NGC 3372 · Constellation Carina',
   text:['A sprawling stellar nursery roughly 7,500 light-years away, larger and brighter than the Orion Nebula. Nikolas Lacaille catalogued it from the Cape of Good Hope in 1751–52.',
         'Here the gas is painted in the “Hubble palette”: sulfur, hydrogen and oxygen emission mapped to red, green and blue, so that gold and teal reveal how heavily each region is ionised.'] },
 { id:'tr14', name:'Trumpler 14', x:T14_[0], y:T14_[1], z:11, mode:0, dwell:11,
   title:'Trumpler 14', sub:'A cluster carving its own cavity',
   text:['One of the most massive young star clusters in the Milky Way, packed with hot O-type stars only a few million years old at most.',
         'Their ultraviolet light and fierce winds have blown a bubble in the gas — the glowing rim you see is the shock front still pushing outward. Sweep your cursor across the cloud to blow your own stellar wind.'] },
 { id:'keyhole', name:'The Keyhole', x:(E_[0]+K_[0])/2, y:(E_[1]+K_[1])/2, z:38, mode:1, dwell:11,
   title:'The Keyhole', sub:'A dark globule · ≈ 7 ly across',
   text:['A dense knot of cold dust silhouetted against glowing hydrogen, named for its shape by John Herschel. Its edge is being slowly eroded by radiation from the stars around it.',
         'The brilliant point to the left is Eta Carinae.'] },
 { id:'eta', name:'Eta Carinae', x:E_[0], y:E_[1], z:520, mode:1, dwell:20, eruption:true,
   title:'Eta Carinae', sub:'Homunculus Nebula · ≈ 0.6 ly',
   text:['A massive binary — the primary is around 100 solar masses — orbiting every 5.54 years. In the 1840s it erupted, briefly reaching magnitude −1 to become the second-brightest star in the night sky.',
         'The two-lobed Homunculus is the debris of that outburst: at least ten solar masses of gas, flung outward at hundreds of kilometres per second.'] },
 { id:'mystic', name:'Mystic Mountains', x:MM_[0], y:MM_[1]+0.002, z:78, mode:0, dwell:12,
   title:'Mystic Mountains', sub:'HH 901 & HH 902 · ≈ 3 ly tall',
   text:['A pillar of cool gas and dust sculpted by radiation from nearby stars, imaged by Hubble for its 20th anniversary in 2010.',
         'Buried inside, newborn stars fire twin jets out of the pillar’s tip — the thin red streamers here. The pillar is, quite literally, being eaten away as stars are born inside it.'] },
 { id:'ir', name:'Infrared', x:0.0, y:0.0, z:1.3, mode:2, dwell:12,
   title:'Through the dust', sub:'The nebula in infrared',
   text:['Infrared light slips through the dust that blocks visible light. The dark lanes now glow, and thousands of stars hidden within them appear.',
         'Observatories like Spitzer and JWST use this to catch stars still forming — including in NGC 3324, the neighbouring “Cosmic Cliffs” region of the greater Carina complex.'] },
];

/* nav chips */
const nav = $('#nav');
nav.innerHTML = '<button class="play" id="playBtn" aria-label="Play / pause"></button>';
stages.forEach((s,i)=>{ const b=document.createElement('button'); b.textContent=s.name; b.dataset.i=i; nav.appendChild(b); });
const bar = document.createElement('div'); bar.className='bar'; nav.appendChild(bar);
const ICON_PLAY = '<svg viewBox="0 0 12 12"><path d="M2 1l9 5-9 5z"/></svg>', ICON_PAUSE='<svg viewBox="0 0 12 12"><path d="M2 1h3v10H2zM7 1h3v10H7z"/></svg>';
function setPlayIcon(){ $('#playBtn').innerHTML = tour.playing ? ICON_PAUSE : ICON_PLAY; }

/* labels */
const labelDefs = [
  {n:'Trumpler 14',  s:'Star cluster',          p:[T14_[0],T14_[1]],        z0:.5, z1:30},
  {n:'Trumpler 16',  s:'Star cluster',          p:[E_[0]+.03,E_[1]+.11],    z0:.5, z1:7},
  {n:'Great dust lane', s:'Cold, dark dust',    p:[-.62,.07],               z0:.5, z1:2.6},
  {n:'η Carinae',    s:'≈ 100 solar masses',    p:[E_[0],E_[1]],            z0:2.5, z1:130},
  {n:'Keyhole Nebula', s:'Dark globule',        p:[K_[0],K_[1]-.018],       z0:9,  z1:300},
  {n:'Homunculus Nebula', s:'Ejected 1840s',    p:[E_[0],E_[1]],            z0:160, z1:2000, dy:60},
  {n:'Mystic Mountains', s:'HH 901 · HH 902',   p:[MM_[0],MM_[1]],          z0:2.5, z1:420},
];
const labBox = $('#labels');
labelDefs.forEach(l=>{ const d=document.createElement('div'); d.className='lbl'; d.innerHTML='<i></i><b></b><span>'+l.n+'<small>'+l.s+'</small></span>'; labBox.appendChild(d); l.el=d; });

/* ---------------- tour ---------------- */
const tour = {playing:false, idx:0, phase:'intro', t:0, dur:6, from:null, arc:0, useArc:false};
const ease = x => x<.5 ? 4*x*x*x : 1-Math.pow(-2*x+2,3)/2;
const smoother = x => x*x*x*(x*(x*6-15)+10);
let started = false;

function goTo(i, dur){
  const s = stages[i]; tour.idx = i; tour.phase='travel'; tour.t=0; tour.dur = dur || 8;
  tour.from = {x:cam.x, y:cam.y, lz:cam.lz, mode:mode};
  const lzB = Math.log(s.z), zA = Math.exp(tour.from.lz), zB = s.z;
  const dist = Math.hypot(s.x-cam.x, s.y-cam.y);
  tour.useArc = dist*Math.min(zA,zB) > 1.2;
  if(tour.useArc){
    const zm = 3.2/(2.5*dist+.05);
    tour.arc = Math.max(0, (tour.from.lz+lzB)/2 - Math.log(Math.max(zm,.8)));
  }
  hideCard();
  document.querySelectorAll('#nav button[data-i]').forEach(b=>b.classList.toggle('on', +b.dataset.i===i));
  $('#erupt').classList.remove('show');
  if(!userPalette) modeTarget = s.mode;
}
function showCard(i){
  const s = stages[i];
  $('#cNum').textContent = String(i+1).padStart(2,'0')+' / '+String(stages.length).padStart(2,'0');
  $('#cTitle').textContent = s.title; $('#cSub').textContent = s.sub;
  $('#cText').innerHTML = s.text.map(t=>'<p>'+t+'</p>').join('');
  $('#erupt').classList.toggle('show', !!s.eruption);
  $('#card').classList.remove('hide');
}
function hideCard(){ $('#card').classList.add('hide'); }

/* eruption */
let erupt = -1, flash = 0, eruptDur = 11;
function startEruption(){ erupt = 0; $('#yv').textContent='1838'; $('#year').classList.add('on'); sndSwell(); }

/* ---------------- audio ---------------- */
let ac=null, master=null, filt=null, swellG=null, sndOn=false;
function startAudio(){
  if(ac){ ac.resume(); return; }
  try{
    ac = new (window.AudioContext||window.webkitAudioContext)();
    master = ac.createGain(); master.gain.value = 0; master.connect(ac.destination);
    filt = ac.createBiquadFilter(); filt.type='lowpass'; filt.frequency.value=500; filt.Q.value=.7; filt.connect(master);
    [[55,.55],[82.4,.35],[110.3,.3],[164.9,.16],[220.6,.1],[329.7,.05]].forEach(([f,a],i)=>{
      const o = ac.createOscillator(); o.type = i%2? 'sine':'triangle'; o.frequency.value=f*(1+(i-2)*.0017);
      const g = ac.createGain(); g.gain.value=a*.5;
      const lfo = ac.createOscillator(); lfo.frequency.value = .03+.017*i; const lg = ac.createGain(); lg.gain.value=a*.3;
      lfo.connect(lg); lg.connect(g.gain); lfo.start();
      o.connect(g); g.connect(filt); o.start();
    });
    const lf = ac.createOscillator(); lf.frequency.value=.045; const lfg = ac.createGain(); lfg.gain.value=180; lf.connect(lfg); lfg.connect(filt.frequency); lf.start();
    const nb = ac.createBuffer(1, ac.sampleRate*3, ac.sampleRate); const d = nb.getChannelData(0);
    let last=0; for(let i=0;i<d.length;i++){ last = (last + .02*(Math.random()*2-1))/1.02; d[i]=last*3.5; }
    const ns = ac.createBufferSource(); ns.buffer=nb; ns.loop=true;
    swellG = ac.createGain(); swellG.gain.value = .25;
    ns.connect(swellG); swellG.connect(filt); ns.start();
  }catch(e){ ac=null; }
}
function setSound(on){
  sndOn = on; $('#snd').classList.toggle('on', on); $('#snd').textContent = on ? 'Sound on' : 'Sound off';
  if(on){ startAudio(); if(master) master.gain.setTargetAtTime(.2, ac.currentTime, 1.5); }
  else if(master){ master.gain.setTargetAtTime(0, ac.currentTime, .4); }
}
function sndSwell(){ if(!sndOn||!swellG) return; const t=ac.currentTime; swellG.gain.cancelScheduledValues(t); swellG.gain.setTargetAtTime(2.2,t,.6); swellG.gain.setTargetAtTime(.25,t+3,2.5); }

/* ---------------- input ---------------- */
let ptr = {x:W/2, y:H/2, inside:false, last:0}, windS = 0;
let dragging=false, dragLast=null, touches = new Map(), pinchD=0;
const ppuCss = () => H/3.2*Math.exp(tgt.lz);
function toManual(){
  if(tour.phase!=='manual'){ tour.phase='manual'; tour.playing=false; setPlayIcon(); tgt.x=cam.x; tgt.y=cam.y; tgt.lz=cam.lz; if(!tour.arrived) {} }
}
canvas.addEventListener('pointerdown', e=>{
  canvas.setPointerCapture(e.pointerId); touches.set(e.pointerId,{x:e.clientX,y:e.clientY});
  if(touches.size===1){ dragging=true; dragLast={x:e.clientX,y:e.clientY}; canvas.classList.add('drag'); }
  if(touches.size===2){ const [a,b]=[...touches.values()]; pinchD=Math.hypot(a.x-b.x,a.y-b.y); }
});
canvas.addEventListener('pointermove', e=>{
  ptr.x=e.clientX; ptr.y=e.clientY; ptr.inside=true; ptr.last=performance.now();
  if(touches.has(e.pointerId)) touches.set(e.pointerId,{x:e.clientX,y:e.clientY});
  if(touches.size===2){
    const [a,b]=[...touches.values()]; const d=Math.hypot(a.x-b.x,a.y-b.y);
    if(pinchD>0){ toManual(); zoomAt((a.x+b.x)/2,(a.y+b.y)/2, Math.log(d/pinchD)); } pinchD=d; return;
  }
  if(dragging && dragLast && (e.pointerType!=='mouse' || e.buttons)){
    const dx=e.clientX-dragLast.x, dy=e.clientY-dragLast.y;
    if(Math.abs(dx)+Math.abs(dy)>0){ toManual(); const p=ppuCss(); tgt.x-=dx/p; tgt.y+=dy/p; }
    dragLast={x:e.clientX,y:e.clientY};
  }
});
const endP = e=>{ touches.delete(e.pointerId); if(touches.size===0){ dragging=false; canvas.classList.remove('drag'); } pinchD=0; if(e.pointerType==='touch'){ ptr.inside=false; } };
canvas.addEventListener('pointerup', endP); canvas.addEventListener('pointercancel', endP);
canvas.addEventListener('pointerleave', ()=>{ ptr.inside=false; });
function zoomAt(sx,sy,dlz){
  const before = ppuCss();
  const wx = tgt.x + (sx-W/2)/before, wy = tgt.y - (sy-H/2)/before;
  tgt.lz = Math.min(LZMAX, Math.max(LZMIN, tgt.lz + dlz));
  const after = ppuCss();
  tgt.x = wx - (sx-W/2)/after; tgt.y = wy + (sy-H/2)/after;
}
canvas.addEventListener('wheel', e=>{ e.preventDefault(); if(!started) return; toManual(); zoomAt(e.clientX,e.clientY, -e.deltaY*(e.deltaMode?0.05:0.0016)); }, {passive:false});

/* UI wiring */
$('#pal').addEventListener('click', e=>{ const b=e.target.closest('button'); if(!b) return; userPalette=true; modeTarget=+b.dataset.m; });
function syncPal(){ document.querySelectorAll('#pal button').forEach(b=>b.classList.toggle('on', Math.abs(+b.dataset.m - modeTarget)<.5)); }
nav.addEventListener('click', e=>{
  const b = e.target.closest('button'); if(!b) return;
  if(b.id==='playBtn'){
    if(!started) return;
    tour.playing = !tour.playing; setPlayIcon();
    if(tour.playing && tour.phase==='manual') goTo((tour.idx+1)%stages.length, 8);
    return;
  }
  started = true; goTo(+b.dataset.i, 8);
});
$('#snd').onclick = ()=> setSound(!sndOn);
$('#hide').onclick = ()=> document.body.classList.toggle('nohud');
$('#erupt').onclick = startEruption;
function begin(withTour){
  started = true; $('#intro').classList.add('gone');
  if(withTour){ tour.playing = true; setPlayIcon(); goTo(0, 6); setSound(true); }
  else { tour.phase='manual'; tour.playing=false; setPlayIcon(); tgt.x=cam.x; tgt.y=cam.y; tgt.lz=Math.log(1.2); }
}
$('#begin').onclick = ()=>begin(true);
$('#free').onclick = ()=>begin(false);
addEventListener('keydown', e=>{
  if(e.key==='h'||e.key==='H') document.body.classList.toggle('nohud');
  if(!started) return;
  if(e.key===' '){ e.preventDefault(); $('#playBtn').click(); }
  if(e.key==='ArrowRight') goTo((tour.idx+1)%stages.length, 8);
  if(e.key==='ArrowLeft')  goTo((tour.idx+stages.length-1)%stages.length, 8);
  if(e.key>='1'&&e.key<='3'){ userPalette=true; modeTarget=+e.key-1; }
  if(e.key==='f'||e.key==='F'){ document.fullscreenElement ? document.exitFullscreen() : document.documentElement.requestFullscreen?.(); }
});

/* ---------------- sizing + adaptive quality ---------------- */
let maxScale = Math.min(devicePixelRatio||1, 1.5), scale = maxScale * .6, scaleCap = maxScale;
function resize(){
  W=innerWidth; H=innerHeight;
  canvas.width = Math.max(2,Math.floor(W*scale)); canvas.height = Math.max(2,Math.floor(H*scale));
  if(gl) gl.viewport(0,0,canvas.width,canvas.height);
}
addEventListener('resize', resize); resize();

/* ---------------- scale bar ---------------- */
function niceNum(v){ const e=Math.pow(10,Math.floor(Math.log10(v))); const f=v/e; return (f<1.5?1:f<3.5?2:f<7.5?5:10)*e; }
function fmt(n){ return n>=1000 ? n.toLocaleString('en-US',{maximumFractionDigits:0}) : (n>=10? String(Math.round(n)) : String(+n.toPrecision(2))); }
function updateScale(){
  const lyPerPx = 100/ppuCssFrom(cam.lz);
  const target = 110*lyPerPx;
  let label, px;
  if(target >= 1){ const n = niceNum(target); px = n/lyPerPx; label = fmt(n)+' light-year'+(n>1?'s':''); }
  else { const au = target*63241; const n = niceNum(au); px = n/63241/lyPerPx; label = fmt(n)+' AU'; }
  $('#sLine').style.width = px+'px'; $('#sVal').textContent = label;
  const z = Math.exp(cam.lz); $('#sZ').textContent = '×'+(z>=10? Math.round(z) : z.toFixed(1))+' magnification';
}
function ppuCssFrom(lz){ return H/3.2*Math.exp(lz); }

/* ---------------- main loop ---------------- */
let last = performance.now(), simT = 0, ftAvg = 16, ftN = 0;
function frame(now){
  requestAnimationFrame(frame);
  let dt = Math.min(.05, (now-last)/1000); last = now; simT += dt;

  // adaptive resolution
  ftAvg += (dt*1000 - ftAvg)*.05; ftN++;
  if(ftN>60 && ftN%45===0){
    if(ftAvg>24 && scale>.38){ scale*=.88; scaleCap = scale*1.04; resize(); }
    else if(ftAvg<17.6 && scale<scaleCap){ scale=Math.min(scaleCap,scale*1.08); resize(); }
  }

  // camera
  if(tour.phase==='intro'){
    cam.x = .02 + Math.sin(simT*.05)*.05; cam.y = Math.cos(simT*.04)*.03; cam.lz = Math.log(.85) + Math.sin(simT*.03)*.04;
  } else if(tour.phase==='travel'){
    tour.t += dt; const s = Math.min(1, tour.t/tour.dur), e = ease(s), st = stages[tour.idx], f = tour.from;
    const lzB = Math.log(st.z);
    let lz = f.lz + (lzB-f.lz)*e, u;
    if(tour.useArc){ lz -= tour.arc*Math.sin(Math.PI*e); u = smoother(e); }
    else {
      const zA=Math.exp(f.lz), zB=st.z, z=Math.exp(lz);
      u = Math.abs(1/zA-1/zB)<1e-9 ? e : (1/zA-1/z)/(1/zA-1/zB);
    }
    cam.lz = lz; cam.x = f.x + (st.x-f.x)*u; cam.y = f.y + (st.y-f.y)*u;
    if(s>=1){ tour.phase='dwell'; tour.t=0; showCard(tour.idx); if(st.eruption && tour.playing) setTimeout(()=>{ if(tour.idx===3 && erupt<0) startEruption(); }, 5500); }
  } else if(tour.phase==='dwell'){
    tour.t += dt;
    const st = stages[tour.idx], z = st.z;
    cam.x = st.x + Math.sin(simT*.21)*.012/z; cam.y = st.y + Math.cos(simT*.17)*.009/z; cam.lz = Math.log(z) + Math.sin(simT*.13)*.012;
    if(tour.playing && tour.t > st.dwell && erupt<0) goTo((tour.idx+1)%stages.length, 8.5);
  } else { // manual
    const k = 1-Math.exp(-dt*7);
    cam.x += (tgt.x-cam.x)*k; cam.y += (tgt.y-cam.y)*k; cam.lz += (tgt.lz-cam.lz)*k;
  }

  // palette
  const mk = 1-Math.exp(-dt*(tour.phase==='travel'?1.4:3));
  mode += (modeTarget-mode)*mk; syncPal();

  // eruption
  if(erupt>=0){
    erupt += dt/eruptDur;
    flash = Math.min(1, erupt/.07) * Math.exp(-Math.max(0,erupt-.07)*3.2);
    $('#yv').textContent = Math.min(1858, Math.round(1838 + erupt*20));
    if(erupt>=1){ erupt=-1; flash=0; $('#year').classList.remove('on'); }
  }

  // wind
  const active = ptr.inside && !dragging && started && (performance.now()-ptr.last<2200);
  windS += ((active? .8:0) - windS)*(1-Math.exp(-dt*3));
  const pp = ppuCssFrom(cam.lz);
  const px = cam.x + (ptr.x-W/2)/pp, py = cam.y - (ptr.y-H/2)/pp;

  if(gl){
    gl.uniform2f(U.uRes, canvas.width, canvas.height);
    gl.uniform1f(U.uTime, simT);
    gl.uniform2f(U.uCam, cam.x, cam.y);
    gl.uniform1f(U.uZoom, Math.exp(cam.lz));
    gl.uniform1f(U.uMode, mode);
    gl.uniform3f(U.uPtr, px, py, windS);
    gl.uniform1f(U.uErupt, erupt);
    gl.uniform1f(U.uFlash, flash);
    gl.drawArrays(gl.TRIANGLES, 0, 3);
  }

  // labels
  const z = Math.exp(cam.lz);
  labelDefs.forEach(l=>{
    let o = 0;
    if(started && tour.phase!=='intro'){
      const fin = Math.min(1, Math.log(z/l.z0)/.5 + .0), fout = Math.min(1, Math.log(l.z1/z)/.5);
      o = Math.max(0, Math.min(1, Math.min(fin, fout)));
      if(tour.phase==='travel') o *= .6;
    }
    const sx = (l.p[0]-cam.x)*pp + W/2, sy = H/2 - (l.p[1]-cam.y)*pp + (l.dy||0);
    if(sx<-60||sx>W+60||sy<-40||sy>H+40) o = 0;
    l.el.style.opacity = o.toFixed(3);
    l.el.style.transform = 'translate('+sx.toFixed(1)+'px,'+sy.toFixed(1)+'px)';
  });

  // stage progress bar
  const active_b = document.querySelector('#nav button.on[data-i]');
  if(active_b && tour.phase==='dwell' && tour.playing){
    bar.style.left = active_b.offsetLeft+10+'px'; bar.style.width = Math.min(1,tour.t/stages[tour.idx].dwell)*(active_b.offsetWidth-20)+'px';
  } else bar.style.width='0';

  if(sndOn && filt){ filt.frequency.setTargetAtTime(380 + Math.log(z)*55 + flash*1200, ac.currentTime, .3); }
  updateScale();
}
setPlayIcon();
requestAnimationFrame(frame);

/* auto-fall back to window.__capture for static screenshots */
if(new URLSearchParams(location.search).has('auto')) setTimeout(()=>begin(true), 300);
</script>
</body>
</html>