Skip to content
VibeCodeBench
Back to the app

The code

Build a Cell, Part by Part by GPT-6.2 Sol

Exactly as the AI wrote it. Shown as text, so nothing runs on this page.

index.html

works · auto-checked (Checked by an automated pass. Not hand-played yet.)21.0 KB · 292 lines · loads cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js
Download
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Cell Lab — Animal Cell</title>
<style>
:root{color-scheme:dark;--bg:#080d1b;--panel:#111a2d;--line:#27334a;--soft:#9fadc4;--mint:#72f0d1}*{box-sizing:border-box}body{margin:0;background:var(--bg);color:#f5f7ff;font:15px system-ui,sans-serif}button,input{font:inherit}button{cursor:pointer;color:inherit}button:focus-visible,input:focus-visible{outline:2px solid var(--mint);outline-offset:3px}.shell{max-width:1440px;margin:auto;padding:24px clamp(12px,4vw,60px)}header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:20px}.brand{display:flex;align-items:center;gap:12px;font-size:18px;font-weight:750}.logo{display:grid;place-items:center;width:39px;height:39px;border:1px solid #28635d;border-radius:13px;background:#153735;color:var(--mint);font-size:23px}.tag,.eyebrow{font-size:11px;font-weight:750;letter-spacing:.15em;text-transform:uppercase;color:var(--mint)}.tag{border:1px solid var(--line);border-radius:30px;padding:8px 12px}.layout{display:grid;grid-template-columns:minmax(0,1fr) 300px;gap:16px}.stage,.side,.timeline{border:1px solid var(--line);border-radius:20px;overflow:hidden}.stage{height:clamp(450px,68vh,730px);position:relative;background:radial-gradient(ellipse at 50% 47%,#1b2c45,#0b1426 63%,#0a1120);isolation:isolate}.stage:before{content:'';position:absolute;inset:0;background:radial-gradient(circle,#a4d5f626 1px,transparent 1px) 0 0/26px 26px;mask-image:radial-gradient(ellipse,transparent 27%,black);pointer-events:none}canvas{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none;cursor:grab}canvas:active{cursor:grabbing}.stage-heading{position:absolute;top:22px;left:23px;pointer-events:none}h1{font-size:clamp(23px,4vw,39px);letter-spacing:-.05em;line-height:1;margin:7px 0}.cut{position:absolute;top:19px;right:18px;border:1px solid #33435e;border-radius:12px;background:#111a2ded;display:flex;align-items:center;gap:8px;padding:0 10px;min-height:44px;font-weight:650;font-size:13px}.switch{width:28px;height:16px;border-radius:20px;background:#41506a;padding:3px;display:flex}.switch:after{content:'';width:10px;height:10px;border-radius:50%;background:white;transition:transform .2s}.cut[aria-checked=true] .switch{background:#238573}.cut[aria-checked=true] .switch:after{transform:translateX(12px)}.hint{position:absolute;bottom:14px;left:50%;transform:translateX(-50%);color:#c0cce0;background:#0b1324e6;border:1px solid #27344b;border-radius:25px;white-space:nowrap;padding:7px 12px;font-size:11px;pointer-events:none}.label{position:absolute;transform:translate(-50%,-100%);border:1px solid var(--part);color:white;background:#111a2df5;border-radius:9px;padding:6px 9px;font-size:12px;font-weight:700;white-space:nowrap;pointer-events:none}.label:after{content:'';position:absolute;top:100%;left:50%;height:10px;border-left:1px solid var(--part)}[hidden]{display:none!important}.side{background:var(--panel);display:flex;flex-direction:column;min-width:0}.detail{padding:20px;min-height:152px;border-bottom:1px solid var(--line)}h2{font-size:24px;margin:6px 0;letter-spacing:-.035em}.detail p{color:#c4cee0;margin:0;line-height:1.45}.parts{padding:12px;display:grid;gap:3px;align-content:start}.part{width:100%;text-align:left;min-height:34px;border:1px solid transparent;border-radius:8px;background:transparent;display:flex;align-items:center;gap:9px;padding:4px 8px;font-size:13px}.part:disabled{opacity:.43;cursor:default}.part[aria-current=true]{background:#202d45;border-color:#3b4c69}.dot{width:9px;height:9px;border-radius:50%;background:var(--part);box-shadow:0 0 9px color-mix(in srgb,var(--part),transparent 55%);flex:none}.number{margin-left:auto;color:var(--soft);font-size:11px}.timeline{margin-top:16px;background:var(--panel);padding:14px 16px;display:flex;align-items:center;gap:15px}.rebuild,.play{min-height:44px;border-radius:10px;font-weight:750;padding:0 13px;white-space:nowrap}.rebuild{background:#20304a;border:1px solid #354660}.play{background:var(--mint);color:#082922;border:0;min-width:74px}.scrubber{flex:1;min-width:0}.status{display:flex;justify-content:space-between;color:var(--soft);font-size:12px;gap:8px}.status strong{color:#eff6ff}input[type=range]{width:100%;height:24px;margin:0;accent-color:var(--mint);cursor:pointer}.error{position:absolute;top:50%;width:100%;padding:20px;text-align:center;color:#fbb}.small-rebuild{display:none}@media(max-width:760px){.shell{padding-top:12px}.layout{grid-template-columns:1fr}.stage{height:clamp(320px,54svh,550px)}.side{grid-row:3}.timeline{grid-row:2;margin:0}.detail{min-height:105px;padding:14px}.parts{grid-template-columns:repeat(2,minmax(0,1fr))}.part{min-height:44px}.stage-heading{top:17px;left:14px}.cut{right:10px;top:10px}.timeline{gap:8px;padding:9px}.rebuild,.play{padding:0 9px}.play{min-width:57px}header{margin-bottom:12px}.number{display:none}}@media(max-width:360px){.tag{display:none}}
</style>
</head>
<body><main class="shell">
<header><div class="brand"><span class="logo" aria-hidden="true">◉</span> Cell Lab</div><div class="tag">Interactive biology</div></header>
<div class="layout">
<section class="stage" id="stage" aria-label="Interactive 3D animal cell">
<div class="stage-heading"><div class="eyebrow">3D Explorer</div><h1>Animal cell</h1></div>
<button class="cut" id="cut" role="switch" aria-checked="false"><span class="switch" aria-hidden="true"></span>Cut open</button>
<div class="label" id="label" hidden></div><div class="hint" id="hint">Drag to orbit · Pinch or scroll to zoom · Tap a part</div>
<div class="error" id="error" hidden></div>
</section>
<aside class="side"><div class="detail" aria-live="polite"><div class="eyebrow" id="detailTag">Starting point</div><h2 id="name">Cell membrane</h2><p id="description">The membrane wraps around the cell and controls what goes in and out.</p></div><div class="parts" id="parts" aria-label="Cell parts"></div></aside>
<section class="timeline" aria-label="Cell build controls"><button class="rebuild" id="rebuild">↻ Rebuild</button><button class="play" id="play">Pause</button><div class="scrubber"><div class="status"><strong id="progressText">Building the cell</strong><span id="count">0 / 11</span></div><input id="scrub" aria-label="Build step" type="range" min="0" max="11" value="0" step="1"></div></section>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
<script>
'use strict';
const byId = id => document.getElementById(id);
const stage = byId('stage');
const data = [
 ['Nucleus','#a883ff','The nucleus holds DNA, the instructions that help the cell grow and work.',[-.72,.23,-.25]],
 ['Nucleolus','#ff8ed7','The nucleolus makes the pieces that fit together to form ribosomes.',[-.66,.35,.49]],
 ['Rough ER','#66aaff','The rough endoplasmic reticulum helps make and fold proteins with the ribosomes stuck to it.',[-1.38,.77,-.02]],
 ['Smooth ER','#50e1ff','The smooth endoplasmic reticulum makes fats that the cell uses to build membranes.',[-1.6,-.77,.35]],
 ['Ribosomes','#ffe290','Ribosomes read instructions and use them to build proteins.',[-.25,1.42,.61]],
 ['Golgi apparatus','#ff78ae','The Golgi apparatus sorts and packages proteins so they reach the right place.',[1.03,.35,.12]],
 ['Mitochondria','#ff9b57','Mitochondria turn energy from food into a form the cell can use.',[1.31,-.87,.35]],
 ['Lysosomes','#c6ed72','Lysosomes break down worn-out cell parts so their materials can be reused.',[.38,-1.34,.28]],
 ['Vesicles','#7af6cf','Vesicles are tiny sacs that carry materials around the cell.',[2.05,.33,-.14]],
 ['Centrioles','#ffcd66','Centrioles help organize the fibers that move chromosomes when the cell divides.',[.65,1.26,-.12]],
 ['Cytoskeleton','#55b8bf','The cytoskeleton is a network of fibers that supports the cell and helps move things inside it.',[-.2,-1.16,-.18]]
];
const membraneText = 'The membrane wraps around the cell and controls what goes in and out.';
let renderer;
try { renderer = new THREE.WebGLRenderer({antialias:true,alpha:true}); }
catch(e){ byId('error').textContent='The 3D view needs WebGL. Try opening it in a browser with 3D graphics enabled.'; byId('error').hidden=false; }
if(renderer) run();
function run(){
 const T=THREE, V=(x,y,z)=>new T.Vector3(x,y,z);
 renderer.setPixelRatio(Math.min(devicePixelRatio,2)); renderer.localClippingEnabled=true;
 stage.prepend(renderer.domElement);
 const scene=new T.Scene(), camera=new T.PerspectiveCamera(36,1,.1,80);
 scene.add(new T.HemisphereLight(0xd9f5ff,0x665695,2.0));
 const key=new T.DirectionalLight(0xffe7ed,2.35);key.position.set(-4,5,6);scene.add(key);
 const fill=new T.DirectionalLight(0x68dcff,1.8);fill.position.set(5,0,-5);scene.add(fill);
 const plane=new T.Plane(V(0,0,-1),0), clips=[];
 function mat(color,alpha=1,extra={}){
  const m=new T.MeshStandardMaterial({color,roughness:.4,metalness:.08,transparent:alpha<1,opacity:alpha,depthWrite:alpha===1,...extra});
  clips.push(m);return m;
 }
 const sphere=new T.SphereGeometry(1,32,24), tinySphere=new T.SphereGeometry(1,10,8);
 function ell(g,m,x,y,z,a,b=a,c=a,geo=sphere){
  const mesh=new T.Mesh(geo,m);mesh.position.set(x,y,z);mesh.scale.set(a,b,c);g.add(mesh);return mesh;
 }
 function tube(g,coords,r,m){
  const path=new T.CatmullRomCurve3(coords.map(p=>V(...p)));
  g.add(new T.Mesh(new T.TubeGeometry(path,Math.max(20,coords.length*3),r,7,false),m));
 }
 let seed=781;
 function rand(){seed=(1664525*seed+1013904223)>>>0;return seed/4294967296;}
 const skin=mat('#61e9d8',.15,{side:T.DoubleSide,emissive:0x125448,roughness:.24});
 const shell=ell(scene,skin,0,0,0,2.67,1.9,1.75);shell.renderOrder=3;
 const rimMat=new T.MeshBasicMaterial({color:0x75f9df,transparent:true,opacity:.86});
 const rimPoints=Array.from({length:81},(_,i)=>[2.67*Math.cos(i*Math.PI/40),1.9*Math.sin(i*Math.PI/40),0]);
 const rim=new T.Group();tube(rim,rimPoints,.024,rimMat);rim.visible=false;scene.add(rim);
 const glow=mat('#9cf8ea',.34,{emissive:0x246d67});
 for(let i=0;i<105;i++){
  const y=2*rand()-1, a=rand()*Math.PI*2, r=Math.sqrt(1-y*y);
  const s=.012+rand()*.018;ell(scene,glow,2.67*r*Math.cos(a),1.9*y,1.75*r*Math.sin(a),s,s,s,tinySphere);
 }
 const groups=data.map((d,i)=>{
  const g=new T.Group();g.position.set(...d[3]);g.userData.part=i;scene.add(g);return g;
 });
 const colors=data.map(d=>mat(d[1]));
 ell(groups[0],mat('#9b72fc',.49,{side:T.DoubleSide,emissive:0x241044}),0,0,0,.83,.77,.7).renderOrder=2;
 const pores=mat('#d4b9ff',.78);
 for(let i=0;i<34;i++){
  const y=2*rand()-1,a=rand()*6.283,r=Math.sqrt(1-y*y);
  ell(groups[0],pores,.83*r*Math.cos(a),.77*y,.7*r*Math.sin(a),.032,.032,.032,tinySphere);
 }
 ell(groups[1],colors[1],0,0,0,.29,.25,.23);
 for(let i=0;i<20;i++){
  const a=i*2.4,y=(i/19)*2-1,r=Math.sqrt(1-y*y);
  ell(groups[1],matPink(),.24*r*Math.cos(a),.22*y,.21*r*Math.sin(a),.035,.035,.035,tinySphere);
 }
 function matPink(){return pink||(pink=mat('#ffb4e4'));}
 function ribbon(g,coords,width,m){
  const path=new T.CatmullRomCurve3(coords.map(p=>V(...p))), verts=[], faces=[];
  for(let j=0;j<=28;j++){
   const p=path.getPoint(j/28),t=path.getTangent(j/28),n=V(-t.y,t.x,.25).normalize();
   for(const s of [-1,1]) verts.push(...p.clone().addScaledVector(n,s*width).toArray());
   const a=j*2;if(j<28) faces.push(a,a+1,a+2,a+1,a+3,a+2);
  }
  const geo=new T.BufferGeometry();geo.setAttribute('position',new T.Float32BufferAttribute(verts,3));geo.setIndex(faces);geo.computeVertexNormals();g.add(new T.Mesh(geo,m));
  tube(g,coords,.033,m);
 }
 var pink;
 const rough=mat('#619dff',1,{side:T.DoubleSide}), golgi=mat('#ff74a9',1,{side:T.DoubleSide});
 for(let k=0;k<5;k++){
  const pts=Array.from({length:10},(_,i)=>{const a=.58+i*.19,r=.9+k*.105;return [.65+Math.cos(a)*r,.01+Math.sin(a)*r*.55-k*.13,.42-k*.21+.1*Math.sin(i)];});
  ribbon(groups[2],pts,.09,rough);
  for(let j=1;j<9;j++){
   const [x,y,z]=pts[j];ell(groups[4],colors[4],x-1.13,y-.65,z-.53,.033,.033,.033,tinySphere);
  }
 }
 for(let k=0;k<6;k++){
  const pts=Array.from({length:12},(_,i)=>[-.58+i*.107,.28-k*.10+.09*Math.sin(i*.73+k),.28*Math.sin(i*.44+k*.83)]);
  tube(groups[3],pts,.046,colors[3]);
  if(k<5){const p=pts[3+k];tube(groups[3],[p,[p[0]+.08,p[1]-.07,p[2]+.08],[p[0]+.17,p[1]-.13,p[2]+.1]],.036,colors[3]);}
 }
 for(let i=0;i<30;i++){
  const a=rand()*6.28,r=Math.sqrt(rand()),x=1.92*r*Math.cos(a),y=1.48*r*Math.sin(a),z=(rand()-.36)*1.6;
  ell(groups[4],colors[4],x+.25,y-1.42,z-.61,.038,.038,.038,tinySphere);
 }
 for(let k=0;k<6;k++){
  const pts=Array.from({length:11},(_,i)=>{const x=(i-5)*(.105-k*.006);return [x,k*.12-.31+x*x*.8,.14*Math.cos(i*.38)+k*.035];});
  ribbon(groups[5],pts,.065,golgi);
 }
 const mitoSkin=mat('#ff8350',.42,{side:T.DoubleSide,emissive:0x623014}), fold=mat('#ffbd69');
 [[0,0,0,.27],[-2.88,.37,-.81,-.65],[.2,1.78,-.61,.44],[-.93,.11,-1.23,-.4]].forEach(([x,y,z,a])=>{
  const g=new T.Group();g.position.set(x,y,z);g.rotation.z=a;groups[6].add(g);
  ell(g,mitoSkin,0,0,0,.53,.245,.25).renderOrder=1;
  tube(g,Array.from({length:30},(_,i)=>[-.43+i*.03,.142*Math.sin(i*1.14),.09]),.028,fold);
 });
 const lysSkin=mat('#b9ef71',.65), vesSkin=mat('#65eac1',.48,{side:T.DoubleSide});
 [[0,0,0],[-2.13,1.04,-.55],[.98,.65,.48]].forEach(([x,y,z])=>{
  ell(groups[7],lysSkin,x,y,z,.19);
  for(let j=0;j<7;j++){const a=j*2.4;ell(groups[7],colors[7],x+.11*Math.cos(a),y+.11*Math.sin(a),z+.13,.029,.029,.029,tinySphere);}
 });
 for(let i=0;i<13;i++){
  const a=i*2.4,r=i===0?0:.35+rand()*.75,s=.06+rand()*.07;
  ell(groups[8],vesSkin,Math.min(.25,r*Math.cos(a)),r*Math.sin(a),-.42+rand()*.74,s);
 }
 const rod=new T.CylinderGeometry(.027,.027,.34,9);
 for(let k=0;k<2;k++){
  const pair=new T.Group();pair.position.set(k*.23-.13,k*.12,0);pair.rotation.z=k===0?-.58:1.02;groups[9].add(pair);
  for(let i=0;i<9;i++){
   const a=i*6.283/9, m=new T.Mesh(rod,colors[9]);m.position.set(.105*Math.cos(a),0,.105*Math.sin(a));pair.add(m);
  }
 }
 const fiber=mat('#54b4bd',.58,{emissive:0x123b43});
 for(let i=0;i<15;i++){
  const a=i*6.283/15;
  const p=Array.from({length:10},(_,j)=>{const f=j/9,t=a+.46*Math.sin(f*4+i),r=.89+f*1.55;return [.2+r*Math.cos(t),1.16+r*.66*Math.sin(t),-.25+.91*Math.sin(f*4+i*.85)];});
  tube(groups[10],p,.012+(i%3)*.004,fiber);
 }
 const parts=byId('parts'), label=byId('label'), slider=byId('scrub'), play=byId('play');
 const buttons=data.map(([name,color],i)=>{
  const b=document.createElement('button');b.className='part';b.style.setProperty('--part',color);
  const dot=document.createElement('span');dot.className='dot';dot.setAttribute('aria-hidden','true');
  const number=document.createElement('span');number.className='number';number.textContent=String(i+1).padStart(2,'0');
  b.append(dot,name,number);b.onclick=()=>focus(i);parts.append(b);return b;
 });
 let step=0,selected=-1,playing=true,cut=false,demo=location.hash==='#demo';
 let next=performance.now()+1400, demoStart=performance.now(), phase=-1;
 let yaw=0,pitch=.12,distance=9.2,goalYaw=0,goalPitch=.12,goalDistance=9.2,baseDistance=9.2;
 const target=V(0,0,0), goalTarget=V(0,0,0), projected=V(0,0,0);
 const reduced=matchMedia('(prefers-reduced-motion: reduce)').matches;
 function overview(){goalTarget.set(0,0,0);goalDistance=baseDistance;}
 function info(i){
  selected=i;const item=data[i];
  byId('detailTag').textContent=item?'Part '+(i+1)+' of '+data.length:'Starting point';
  byId('name').textContent=item?item[0]:'Cell membrane';
  byId('description').textContent=item?item[2]:membraneText;
  label.hidden=!item;
  if(item){label.textContent=item[0];label.style.setProperty('--part',item[1]);}
  buttons.forEach((b,j)=>b.setAttribute('aria-current',String(j===i)));
 }
 function sync(){
  slider.value=step;byId('count').textContent=step+' / '+data.length;
  byId('progressText').textContent=step===data.length?'Cell complete':playing?'Building the cell':step===0?'Empty membrane':'Build paused';
  play.textContent=playing?'Pause':step===data.length?'Replay':'Play';
 }
 function build(value,instant=false){
  step=value;const now=performance.now();
  groups.forEach((g,i)=>{
   if(i<step&&!g.visible)g.userData.born=instant?now-800:now;
   g.visible=i<step;
   buttons[i].disabled=i>=step;
  });
  info(step-1);sync();
 }
 function focus(i){
  if(i>=step)return;
  playing=false;sync();info(i);
  goalTarget.copy(groups[i].position).multiplyScalar(.72);
  if(cut)goalTarget.z=Math.min(0,goalTarget.z);
  goalDistance=baseDistance*.62;
 }
 function setCut(value){
  cut=value;byId('cut').setAttribute('aria-checked',String(cut));rim.visible=cut;
  for(const m of clips){m.clippingPlanes=cut?[plane]:[];m.needsUpdate=true;}
  if(cut){goalYaw=0;goalPitch=.08;overview();}
 }
 function rebuild(){playing=true;overview();goalYaw=0;goalPitch=.12;build(0);next=performance.now()+1200;}
 byId('cut').onclick=()=>setCut(!cut);byId('rebuild').onclick=rebuild;
 play.onclick=()=>{
  if(playing){playing=false;sync();}
  else if(step===data.length)rebuild();
  else{playing=true;overview();next=performance.now()+450;sync();}
 };
 slider.oninput=()=>{playing=false;overview();build(Number(slider.value),true);};
 function endDemo(){if(demo){demo=false;next=performance.now()+800;}}
 window.addEventListener('pointerdown',endDemo,{capture:true});window.addEventListener('wheel',endDemo,{capture:true,passive:true});
 const ptrs=new Map(), canvas=renderer.domElement, ray=new T.Raycaster(), ndc=new T.Vector2();
 let drag=false,downX=0,downY=0;
 const spread=()=>{const [a,b]=ptrs.values();return Math.hypot(a.x-b.x,a.y-b.y);};
 const clamp=(v,a,b)=>Math.min(b,Math.max(a,v));
 function zoom(factor){goalDistance=clamp(goalDistance*factor,2.8,baseDistance*1.7);}
 canvas.onpointerdown=e=>{
  if(!ptrs.size){drag=false;downX=e.clientX;downY=e.clientY;}else drag=true;
  ptrs.set(e.pointerId,{x:e.clientX,y:e.clientY});canvas.setPointerCapture(e.pointerId);
 };
 canvas.onpointermove=e=>{
  const p=ptrs.get(e.pointerId);if(!p)return;
  const prior=ptrs.size===2?spread():0;
  const dx=e.clientX-p.x,dy=e.clientY-p.y;p.x=e.clientX;p.y=e.clientY;
  if(ptrs.size===2){zoom(Math.max(1,prior)/Math.max(1,spread()));return;}
  if(ptrs.size!==1)return;
  if(Math.hypot(e.clientX-downX,e.clientY-downY)>5)drag=true;
  if(drag){goalYaw-=dx*.008;goalPitch=clamp(goalPitch+dy*.008,-1.38,1.38);}
 };
 function pick(e){
  const rect=canvas.getBoundingClientRect();ndc.set((e.clientX-rect.left)/rect.width*2-1,1-(e.clientY-rect.top)/rect.height*2);
  ray.setFromCamera(ndc,camera);
  const hits=ray.intersectObjects(groups.filter(g=>g.visible),true);
  for(const h of hits){
   if(cut&&h.point.z>.008)continue;
   let root=h.object;while(root&&root.userData.part===undefined)root=root.parent;
   if(root){focus(root.userData.part);return;}
  }
  if(!playing){overview();info(-1);}
 }
 canvas.onpointerup=e=>{if(ptrs.has(e.pointerId)&&ptrs.size===1&&!drag)pick(e);ptrs.delete(e.pointerId);};
 canvas.onpointercancel=e=>{ptrs.delete(e.pointerId);drag=true;};
 canvas.addEventListener('wheel',e=>{e.preventDefault();zoom(Math.exp(clamp(e.deltaY,-180,180)*.002));},{passive:false});
 function resize(){
  const w=stage.clientWidth,h=stage.clientHeight;
  camera.aspect=w/h;camera.updateProjectionMatrix();renderer.setSize(w,h,false);
  const newDistance=9.1*Math.max(1,.97/camera.aspect);
  goalDistance*=newDistance/baseDistance;baseDistance=newDistance;
 }
 new ResizeObserver(resize).observe(stage);resize();distance=goalDistance;
 build(0);
 function loop(now){
  requestAnimationFrame(loop);
  if(demo){
   const t=((now-demoStart)%20000)/1000;
   const section=t<1?0:t<11?1:t<13.6?2:t<16?3:t<18.4?4:5;
   if(section!==phase){
    phase=section;
    if(section===0){setCut(false);rebuild();}
    if(section===2){playing=false;build(11,true);overview();}
    if(section===3){setCut(true);focus(5);}
    if(section===4){setCut(false);focus(6);goalYaw=-.32;}
    if(section===5){overview();build(5,true);goalYaw=.15;}
   }
   if(section===1){const s=Math.min(11,Math.floor((t-1)/.84)+1);if(s!==step)build(s);}
   if(section===2)goalYaw=(t-11)*.45;
  }else if(playing&&now>=next){
   if(step<data.length){const value=step+1;if(value===data.length)playing=false;build(value);}
   next=now+980;
  }
  const ease=reduced?1:.075;
  yaw+=(goalYaw-yaw)*ease;pitch+=(goalPitch-pitch)*ease;distance+=(goalDistance-distance)*ease;target.lerp(goalTarget,ease);
  camera.position.copy(target).add(V(Math.sin(yaw)*Math.cos(pitch),Math.sin(pitch),Math.cos(yaw)*Math.cos(pitch)).multiplyScalar(distance));camera.lookAt(target);
  groups.forEach((g,i)=>{
   if(!g.visible)return;
   const t=now*.0012+i*1.7,[x,y,z]=data[i][3], drift=reduced?0:.035;
   g.position.set(x+drift*Math.sin(t*.77),y+drift*Math.sin(t),z+drift*Math.cos(t*.8));
   const birth=reduced?1:clamp((now-g.userData.born)/410,0,1);
   g.scale.setScalar((.16+.84*(1-Math.pow(1-birth,3)))*(1+drift*.55*Math.sin(t*1.34)));
  });
  renderer.render(scene,camera);
  if(selected>=0){
   projected.copy(groups[selected].position);if(cut)projected.z=Math.min(projected.z,0);
   projected.y+=.3;projected.project(camera);
   label.hidden=projected.z>1||Math.abs(projected.x)>1.08||Math.abs(projected.y)>1.08;
   if(!label.hidden){label.style.left=clamp((projected.x*.5+.5)*stage.clientWidth,label.offsetWidth/2+6,stage.clientWidth-label.offsetWidth/2-6)+'px';label.style.top=clamp((.5-projected.y*.5)*stage.clientHeight,98,stage.clientHeight-40)+'px';}
  }
 }
 requestAnimationFrame(loop);
}
</script></body></html>