Skip to content
VibeCodeBench
Back to the app

The code

Build a Cell, Part by Part by GPT-6.1 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.)23.4 KB · 82 lines · loads cdn.jsdelivr.net/npm/[email protected]/build/three.module.js, cdn.jsdelivr.net/npm/[email protected]/examples/jsm/
Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Cell by Cell — A tiny world, brought to life</title>
<style>
:root{--ink:#173c3c;--muted:#6d8380;--paper:#f7f9f2;--green:#245c48;--line:#dce4d9}*{box-sizing:border-box}body{margin:0;background:var(--paper);color:var(--ink);font-family:Arial,Helvetica,sans-serif}button,input{font:inherit}button{cursor:pointer}button:focus-visible,input:focus-visible{outline:3px solid #deaa46;outline-offset:4px}header{height:80px;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;padding:0 36px;background:#fbfcf7}.brand{display:flex;align-items:center;gap:12px;font-size:21px;font-weight:750;letter-spacing:-.8px}.brandmark{width:35px;height:35px;border:2px solid var(--green);border-radius:45% 55% 60% 40%;position:relative;transform:rotate(-16deg)}.brandmark:after{content:'';position:absolute;width:11px;height:11px;border:2px solid var(--green);border-radius:50%;left:9px;top:9px}.brand small{font-size:11px;font-weight:500;color:var(--muted);letter-spacing:1.8px;margin-left:19px;border-left:1px solid var(--line);padding-left:20px}.header-note{font-size:12px;display:flex;gap:9px;align-items:center}.dot{width:7px;height:7px;border-radius:50%;background:#69a58b;box-shadow:0 0 0 4px #e9efe4}.layout{height:calc(100dvh - 80px);min-height:650px;display:grid;grid-template-columns:340px 1fr}aside{padding:33px 28px 23px 34px;border-right:1px solid var(--line);overflow-y:auto;z-index:2}.eyebrow{font-size:10px;letter-spacing:2px;font-weight:700;color:#74897c}.intro h1{font-family:Georgia,serif;font-size:37px;line-height:1.12;font-weight:400;letter-spacing:-1.4px;margin:13px 0}.intro p{font-size:13px;color:var(--muted);line-height:1.65;margin-bottom:25px}.detail{background:#fff;border:1px solid var(--line);border-radius:17px;padding:19px;min-height:169px;box-shadow:0 5px 16px #173c3c04}.detail-top{display:flex;justify-content:space-between;align-items:center;font-size:9px;letter-spacing:1.4px;color:var(--muted)}#partDot{width:9px;height:9px;border-radius:50%;background:#7abeb2}.detail h2{font-family:Georgia,serif;font-size:26px;font-weight:400;margin:16px 0 9px;line-height:1.12}.detail p{font-size:12px;line-height:1.65;color:#647974;margin:0}.explore-heading{display:flex;justify-content:space-between;margin:25px 0 11px;font-size:10px;letter-spacing:1.3px}.explore-heading span:last-child{letter-spacing:0;color:var(--muted)}.parts{display:grid;grid-template-columns:1fr 1fr;gap:6px}.part{min-height:39px;text-align:left;background:transparent;border:1px solid var(--line);border-radius:8px;font-size:10px;display:flex;align-items:center;gap:7px;padding:7px 9px;color:#4b6660;transition:.2s}.part .swatch{width:7px;height:7px;border-radius:50%;flex-shrink:0}.part.locked{opacity:.42}.part.active{border-color:#739c81;background:#e9f0e4;color:#214b38}.part:hover{background:#eaf0e5}.sidebar-foot{color:#809087;font-size:10px;margin-top:20px;display:flex;gap:8px;align-items:center}.stage{position:relative;min-width:0;overflow:hidden;background:radial-gradient(ellipse at 50% 44%,#eff6ea 0%,#eaf1e6 47%,#e3ebdf 100%)}.stage:before{content:'';position:absolute;inset:0;background-image:radial-gradient(#74927a30 .7px,transparent .7px);background-size:24px 24px;pointer-events:none}#canvas{width:100%;height:100%;position:absolute;inset:0;touch-action:none}.stage-top{position:absolute;top:26px;left:29px;right:29px;display:flex;align-items:center;justify-content:space-between;pointer-events:none}.specimen{font-size:10px;letter-spacing:1.4px;color:#6b8270}.specimen strong{display:block;font-weight:500;color:#304e3e;margin-top:7px;letter-spacing:0;font-size:13px}.tools{display:flex;gap:8px;pointer-events:auto}.tool{height:43px;border:1px solid #d0dccb;background:#f9fcf3d9;border-radius:24px;padding:0 15px;color:#3e5e4c;font-size:11px;display:flex;gap:9px;align-items:center}.switch{width:27px;height:16px;background:#c5d3c0;border-radius:20px;padding:3px;transition:.2s}.switch:after{content:'';display:block;width:10px;height:10px;background:#fff;border-radius:50%;transition:.2s}.tool[aria-pressed=true] .switch{background:#32674e}.tool[aria-pressed=true] .switch:after{transform:translateX(11px)}.float-label{position:absolute;pointer-events:none;display:none;color:#395f50;font-size:12px;white-space:nowrap;background:#fbfdf5e8;border:1px solid #cbd9c4;padding:11px 15px;border-radius:10px;box-shadow:0 7px 24px #3b63350c;transform:translate(20px,-50%)}.float-label:before{content:'';position:absolute;left:-25px;top:50%;width:25px;height:1px;background:#799e7d}.float-label small{font-size:8px;text-transform:uppercase;letter-spacing:1.4px;display:block;margin-bottom:4px;color:#8a9d89}.orientation{position:absolute;right:30px;bottom:167px;width:42px;height:42px;border:1px solid #bacdb5;border-radius:50%;color:#63815d;display:grid;place-items:center;font-family:Georgia,serif;font-style:italic;font-size:17px}.hint{position:absolute;bottom:155px;left:50%;transform:translateX(-50%);display:flex;gap:19px;font-size:10px;color:#6e856e;white-space:nowrap}.hint span{display:flex;gap:6px;align-items:center}.timeline{position:absolute;bottom:24px;left:29px;right:29px;padding:18px 21px;background:#fbfdf6ed;border:1px solid #d5dfce;border-radius:16px;box-shadow:0 12px 30px #304c3010;backdrop-filter:blur(14px)}.timeline-head{display:flex;justify-content:space-between;align-items:center;font-size:11px}.timeline-head strong{font-weight:500}.timeline-head .status{font-size:10px;color:var(--muted)}.timeline-row{display:flex;align-items:center;gap:16px;margin-top:12px}.play{border:0;background:var(--green);color:white;border-radius:50%;height:36px;width:36px;flex-shrink:0;font-size:12px}.range-wrap{flex:1;position:relative}input[type=range]{width:100%;height:24px;accent-color:#3e7151;cursor:pointer;margin:0}.range-labels{display:flex;justify-content:space-between;color:#8a9b85;font-size:9px;margin-top:2px}.step-value{font-size:11px;color:#5d795e;width:34px;text-align:right}.demo-tag{position:absolute;left:29px;top:89px;background:#e1ebd8;padding:8px 10px;border-radius:6px;font-size:10px;color:#41633e;display:none}#error{display:none;position:absolute;inset:30%;text-align:center;line-height:1.8;font-size:15px}.scale{position:absolute;left:30px;bottom:174px;font-size:9px;letter-spacing:1px;color:#82977b}.scale:before{content:'';display:block;width:48px;height:5px;border:1px solid #8ca382;border-top:0;margin-bottom:5px}@media(min-width:1450px){aside{padding:42px}.layout{grid-template-columns:380px 1fr}.intro h1{font-size:44px}.detail{margin-top:30px}.part{min-height:43px}}@media(max-width:850px){header{height:64px;padding:0 20px}.brand small{display:none}.layout{height:calc(100dvh - 64px);min-height:690px;grid-template-columns:270px 1fr}aside{padding:26px 18px}.intro h1{font-size:32px}.stage-top{left:18px;right:18px;top:20px}.tools{gap:5px}.tool{padding:0 11px}.specimen{display:none}.stage-top{justify-content:flex-end}.timeline{left:15px;right:15px}.hint{gap:10px;font-size:9px}.scale,.orientation{display:none}}@media(max-width:600px){header{height:58px}.brand{font-size:19px}.header-note{font-size:10px}.layout{display:block;height:calc(100dvh - 58px);min-height:660px;position:relative}.stage{position:absolute;inset:0}.intro,.explore-heading,.parts,.sidebar-foot{display:none}aside{position:absolute;top:67px;left:16px;right:16px;padding:0;border:0;overflow:visible;pointer-events:none}.detail{background:#fbfdf3dd;min-height:0;max-width:100%;padding:13px 16px;border-radius:12px;backdrop-filter:blur(12px)}.detail-top{font-size:8px}.detail h2{font-size:23px;margin:9px 0 5px}.detail p{font-size:11px;line-height:1.45}.stage-top{top:13px;left:17px;right:17px;justify-content:space-between}.specimen{display:block;font-size:8px}.specimen strong{font-size:10px;margin-top:4px}.tool{height:38px;font-size:10px;padding:0 12px}.hint{bottom:145px}.timeline{bottom:17px;padding:16px}.float-label{font-size:10px;padding:8px 10px}.demo-tag{top:auto;bottom:181px;left:17px}.float-label small{font-size:7px}}
</style>
<script type="importmap">{"imports":{"three":"https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/"}}</script>
</head>
<body>
<header><div class="brand"><div class="brandmark"></div>cell by cell <small>A LITTLE SCIENCE. A LOT OF WONDER.</small></div><div class="header-note"><span class="dot"></span> The living collection</div></header>
<main class="layout"><aside><div class="intro"><div class="eyebrow">01 / THE ANIMAL CELL</div><h1>Small world.<br>Big discoveries.</h1><p>Meet the tiny team that keeps you alive.<br>Watch a cell come together, part by part.</p></div><section class="detail" aria-live="polite"><div class="detail-top"><span id="stepLabel">THE OUTER BOUNDARY</span><span id="partDot"></span></div><h2 id="partTitle">Cell membrane</h2><p id="partDescription">A thin, flexible skin controls what enters and leaves the cell.</p></section><div class="explore-heading"><span>MEET THE PARTS</span><span id="count">0 of 11</span></div><div id="parts" class="parts"></div><div class="sidebar-foot"><span>↗</span> Tap a part to get a closer look.</div></aside>
<section class="stage" aria-label="Interactive three-dimensional animal cell"><div id="canvas"></div><div class="stage-top"><div class="specimen">SPECIMEN 001<strong>Animal cell · 3D explorer</strong></div><div class="tools"><button class="tool" id="cut" aria-pressed="false"><span class="switch"></span>Cut open</button><button class="tool" id="rebuild"><span style="font-size:17px">↻</span>Rebuild</button></div></div><div class="demo-tag" id="demoTag">GUIDED TOUR · touch to explore</div><div id="label" class="float-label"><small>LOOK CLOSER</small><span></span></div><div class="scale">A WORLD INSIDE YOU</div><div class="orientation">3D</div><div class="hint"><span>↔ Drag to orbit</span><span>⊕ Pinch to zoom</span><span>◎ Tap to discover</span></div><div class="timeline"><div class="timeline-head"><strong id="buildTitle">A cell, coming to life</strong><span class="status" id="status">Building your cell…</span></div><div class="timeline-row"><button id="play" class="play" aria-label="Pause building">Ⅱ</button><div class="range-wrap"><input id="scrub" type="range" min="0" max="11" step="0.01" value="0" aria-label="Cell build progress"><div class="range-labels"><span>EMPTY MEMBRANE</span><span>COMPLETE CELL</span></div></div><span id="stepValue" class="step-value">0 / 11</span></div></div><div id="error">The 3D explorer couldn’t start. Please check that WebGL and the versioned Three.js library are available, then reload.</div></section></main>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
const data=[
['Nucleus','The nucleus stores DNA, the instructions that tell the cell what to do.','#9580bf'],
['Nucleolus','The nucleolus makes the tiny pieces that become ribosomes.','#67427f'],
['Rough ER','The rough endoplasmic reticulum uses attached ribosomes to make and move proteins.','#638eac'],
['Smooth ER','The smooth endoplasmic reticulum makes fats and helps remove harmful chemicals.','#79b6ac'],
['Ribosomes','Ribosomes build proteins, the useful molecules that do many jobs in a cell.','#d3a568'],
['Golgi apparatus','The Golgi apparatus sorts, packages and sends proteins where they need to go.','#df9c85'],
['Mitochondria','Mitochondria turn energy from food into a form the cell can use.','#d6a251'],
['Lysosomes','Lysosomes break down waste and worn-out cell parts for recycling.','#c88b9a'],
['Vesicles','Vesicles are little bubbles that carry materials around or out of the cell.','#91b88c'],
['Centrioles','Centrioles help organize the tiny fibers that separate chromosomes when a cell divides.','#bba269'],
['Cytoskeleton','The cytoskeleton is a network of fibers that supports the cell and helps things move inside it.','#6caa9b']];
const $=id=>document.getElementById(id);let progress=0,playing=true,selected=-1,cut=false,demo=location.hash==='#demo',demoStart=performance.now(),last=performance.now(),buildWait=.7,fly=null;
let scene,camera,renderer,controls,cell,membrane,rim;const groups=[],pickables=[],v=new THREE.Vector3(),ray=new THREE.Raycaster(),pointer=new THREE.Vector2();
let seed=31;function rnd(){seed=(seed*16807)%2147483647;return(seed-1)/2147483646}function mat(color,extra={}){return new THREE.MeshStandardMaterial({color,roughness:.43,metalness:.03,...extra})}
function mesh(geo,material,parent,pos=[0,0,0],scale=[1,1,1]){const o=new THREE.Mesh(geo,material);o.position.set(...pos);o.scale.set(...scale);parent.add(o);return o}
function sphere(parent,pos,scale,color){return mesh(new THREE.SphereGeometry(1,32,24),mat(color),parent,pos,scale)}
function tube(parent,points,r,color){return mesh(new THREE.TubeGeometry(new THREE.CatmullRomCurve3(points.map(p=>new THREE.Vector3(...p))),52,r,8,false),mat(color),parent)}
function randomPos(radius=3.8){let p;do{p=[(rnd()-.5)*radius*2,(rnd()-.5)*radius*2,(rnd()-.5)*radius*1.7]}while(Math.hypot(...p)>radius||Math.hypot(p[0]+.7,p[1]-.4,p[2])<1.65);return p}
data.forEach((d,i)=>{const b=document.createElement('button');b.className='part locked';b.innerHTML='<span class="swatch" style="background:'+d[2]+'"></span>'+d[0];b.addEventListener('click',()=>{stopDemo();playing=false;progress=Math.max(progress,i+1);select(i,true);refresh()});$('parts').append(b)});
function info(i){selected=i;const d=i<0?['Cell membrane','A thin, flexible skin controls what enters and leaves the cell.','#7abeb2']:data[i];$('partTitle').textContent=d[0];$('partDescription').textContent=d[1];$('partDot').style.background=d[2];$('stepLabel').textContent=i<0?'THE OUTER BOUNDARY':'PART '+String(i+1).padStart(2,'0')+' / 11';Array.from($('parts').children).forEach((b,k)=>b.classList.toggle('active',k===i));$('label').querySelector('span').textContent=d[0]}
function refresh(){const n=Math.min(11,Math.floor(progress+.001));$('scrub').value=progress;$('count').textContent=n+' of 11';$('stepValue').textContent=n+' / 11';$('status').textContent=progress>=11?'Ready to explore':playing?'Building your cell…':'Explore at your own pace';$('buildTitle').textContent=progress>=11?'One tiny cell. An incredible team.':'A cell, coming to life';$('play').textContent=playing&&progress<11?'Ⅱ':'▶';$('play').setAttribute('aria-label',playing&&progress<11?'Pause building':'Play building');Array.from($('parts').children).forEach((b,k)=>b.classList.toggle('locked',k>=n))}
function select(i,focus=false){info(i);if(focus&&groups[i]){const center=groups[i].position.clone();const dir=camera.position.clone().sub(controls.target).normalize();fly={start:performance.now(),from:camera.position.clone(),targetFrom:controls.target.clone(),to:center.clone().addScaledVector(dir,i===10?10:5.7),target:center};}}
function toggleCut(value){cut=value;renderer.clippingPlanes=cut?[new THREE.Plane(new THREE.Vector3(0,0,-1),0)]:[];rim.visible=cut;$('cut').setAttribute('aria-pressed',String(cut))}
function reset(){progress=0;playing=true;buildWait=.7;info(-1);fly={start:performance.now(),from:camera.position.clone(),targetFrom:controls.target.clone(),to:new THREE.Vector3(8,5,13.5),target:new THREE.Vector3()};toggleCut(false);refresh()}
function stopDemo(){if(demo){demo=false;$('demoTag').style.display='none'}}
try{
scene=new THREE.Scene();camera=new THREE.PerspectiveCamera(38,1,.1,100);camera.position.set(8,5,13.5);renderer=new THREE.WebGLRenderer({antialias:true,alpha:true});renderer.setPixelRatio(Math.min(devicePixelRatio,2));renderer.setClearColor(0,0);renderer.localClippingEnabled=true;renderer.outputColorSpace=THREE.SRGBColorSpace;renderer.toneMapping=THREE.ACESFilmicToneMapping;renderer.toneMappingExposure=1.35;$('canvas').appendChild(renderer.domElement);controls=new OrbitControls(camera,renderer.domElement);controls.enableDamping=true;controls.dampingFactor=.06;controls.minDistance=5;controls.maxDistance=24;controls.enablePan=false;controls.autoRotate=true;controls.autoRotateSpeed=.25;controls.addEventListener('start',()=>{fly=null;controls.autoRotate=false});
scene.add(new THREE.HemisphereLight(0xffffff,0x70947e,2.5));let key=new THREE.DirectionalLight(0xfffaf0,3);key.position.set(-5,9,8);scene.add(key);let fill=new THREE.DirectionalLight(0xbce7e7,2);fill.position.set(5,0,-5);scene.add(fill);
cell=new THREE.Group();scene.add(cell);
membrane=mesh(new THREE.SphereGeometry(4.65,80,60),mat('#81bdb0',{transparent:true,opacity:.13,side:THREE.DoubleSide,depthWrite:false,roughness:.16}),cell,[0,0,0],[1.07,.91,1]);membrane.renderOrder=5;
const outline=mesh(new THREE.SphereGeometry(4.67,64,48),new THREE.MeshPhysicalMaterial({color:'#8ebca1',transparent:true,opacity:.11,side:THREE.BackSide,depthWrite:false,roughness:.3}),cell,[0,0,0],[1.07,.91,1]);outline.renderOrder=4;
rim=mesh(new THREE.TorusGeometry(4.65,.023,8,140),mat('#83b6a1',{transparent:true,opacity:.65}),scene);rim.scale.set(1.07,.91,1);rim.visible=false;
for(let i=0;i<11;i++){let g=new THREE.Group();g.userData.index=i;cell.add(g);groups.push(g)}
let g=groups[0];g.position.set(-.75,.5,-.15);sphere(g,[0,0,0],[1.39,1.32,1.29],'#ad9acb');for(let j=0;j<20;j++){const a=rnd()*6.28,b=Math.acos(2*rnd()-1);const p=[1.405*Math.sin(b)*Math.cos(a),1.335*Math.cos(b),1.305*Math.sin(b)*Math.sin(a)];const pore=mesh(new THREE.TorusGeometry(.065,.019,6,12),mat('#81659e'),g,p);pore.quaternion.setFromUnitVectors(new THREE.Vector3(0,0,1),new THREE.Vector3(...p).normalize())}
g=groups[1];g.position.set(-.45,.56,1.02);sphere(g,[0,0,0],[.43,.42,.38],'#705087');
g=groups[2];g.position.set(-1.35,.28,-.58);for(let j=0;j<6;j++){const points=[];for(let k=0;k<36;k++){let a=-1.1+k/35*3.6;let r=1.5+j*.16;points.push([Math.cos(a)*r,Math.sin(a)*r*.8,(j-2.5)*.18+Math.sin(a*3)*.12])}tube(g,points,.095,'#7c9fb1');for(let k=2;k<34;k+=4){let p=points[k];sphere(g,[p[0],p[1],p[2]+.1],[.055,.055,.055],'#d7ba90')}}
g=groups[3];g.position.set(1.25,1.45,-.4);for(let j=0;j<5;j++){const pts=[];for(let k=0;k<18;k++)pts.push([(k/17-.5)*2.1,Math.sin(k*.47+j)*.28+(j-2)*.27,Math.cos(k*.32+j)*.26]);tube(g,pts,.09,'#79b5a8')}
g=groups[4];for(let j=0;j<65;j++){let p=randomPos(3.7);sphere(g,p,[.052,.052,.052],'#c69d66')}
g=groups[5];g.position.set(1.7,-.7,.6);g.rotation.z=-.35;for(let j=0;j<6;j++){let pts=[];for(let k=0;k<25;k++){let t=k/24;pts.push([(t-.5)*(1.95-j*.12),Math.sin(t*Math.PI)*.31+j*.18,Math.cos(t*6.28)*.13])}tube(g,pts,.1,'#d6947c')}for(let j=0;j<5;j++)sphere(g,[1.1+rnd()*.35,j*.23-.1,rnd()*.5],[.12,.12,.12],'#e2b39a');
g=groups[6];g.position.set(.1,-.4,0);const mitoPos=[[-2.65,-1.25,.8],[2.5,1.2,1.2],[.2,-2.45,-.6],[-.8,2.7,-.5]];mitoPos.forEach((p,j)=>{const m=new THREE.Group();m.position.set(...p);m.rotation.set(.4,j*.7,j*.9);g.add(m);sphere(m,[0,0,0],[.68,.32,.32],'#d7a45c');const pts=[];for(let k=0;k<28;k++){let t=k/27;pts.push([-.5+t,Math.sin(t*6*Math.PI)*.17,.28])}tube(m,pts,.034,'#93692f')});
g=groups[7];g.position.set(-1.5,-2,1);for(let j=0;j<4;j++){let p=j===0?[0,0,0]:[rnd()*2.8-.5,rnd()*2-1,rnd()*1.5-1];sphere(g,p,[.24,.24,.24],'#c78b9e');for(let k=0;k<5;k++)sphere(g,[p[0]+(rnd()-.5)*.24,p[1]+(rnd()-.5)*.24,p[2]+.21],[.025,.025,.025],'#a86a82')}
g=groups[8];g.position.set(2.55,-1.9,-.35);for(let j=0;j<7;j++){let p=j===0?[0,0,0]:[(rnd()-.5)*1.7,(rnd()-.5)*2.2,(rnd()-.5)*2];mesh(new THREE.SphereGeometry(.15+rnd()*.12,24,16),mat('#95bd8c',{transparent:true,opacity:.65,roughness:.15}),g,p)}
g=groups[9];g.position.set(.5,1.05,1.8);for(let c=0;c<2;c++){let bundle=new THREE.Group();bundle.rotation.z=c===0?.45:2;bundle.position.x=c*.5;g.add(bundle);for(let j=0;j<9;j++){let a=j/9*6.28;mesh(new THREE.CylinderGeometry(.045,.045,.62,8),mat('#b99d5b'),bundle,[Math.cos(a)*.14,0,Math.sin(a)*.14])}}
g=groups[10];for(let j=0;j<24;j++){let a=j/24*6.28;let pts=[];for(let k=0;k<12;k++){let t=k/11;let r=1.8+t*2.4;pts.push([Math.cos(a+t*.23)*r,Math.sin(a+t*.23)*r*.85,-1.2+Math.sin(a*3+t*2)*.8])}tube(g,pts,.016,'#80b3a4')}
// All visible organelle surfaces remain individually discoverable.
groups.forEach((g,i)=>{g.userData.base=g.position.clone();g.traverse(o=>{if(o.isMesh){o.userData.part=i;pickables.push(o)}})});
const resize=()=>{const b=$('canvas').getBoundingClientRect();renderer.setSize(b.width,b.height);camera.aspect=b.width/b.height;camera.updateProjectionMatrix()};new ResizeObserver(resize).observe($('canvas'));resize();
let down=null;renderer.domElement.addEventListener('pointerdown',e=>{stopDemo();down={x:e.clientX,y:e.clientY,time:performance.now()}});renderer.domElement.addEventListener('pointerup',e=>{if(!down||Math.hypot(e.clientX-down.x,e.clientY-down.y)>7||performance.now()-down.time>700)return;const b=renderer.domElement.getBoundingClientRect();pointer.set((e.clientX-b.left)/b.width*2-1,-(e.clientY-b.top)/b.height*2+1);ray.setFromCamera(pointer,camera);const hits=ray.intersectObjects(pickables,false).filter(h=>{const i=h.object.userData.part;return groups[i].visible&&(!cut||h.point.z<=0)});if(hits.length){playing=false;select(hits[0].object.userData.part,true);refresh()}});
$('cut').onclick=()=>{stopDemo();toggleCut(!cut)};$('rebuild').onclick=()=>{stopDemo();reset()};$('play').onclick=()=>{stopDemo();if(progress>=11){reset()}else{playing=!playing;refresh()}};$('scrub').addEventListener('input',()=>{stopDemo();playing=false;progress=Number($('scrub').value);let n=Math.ceil(progress)-1;info(n);refresh()});document.addEventListener('pointerdown',stopDemo,{passive:true});document.addEventListener('wheel',stopDemo,{passive:true});
if(demo)$('demoTag').style.display='block';
let previousCount=0,demoPhase=-1;
function frame(now){requestAnimationFrame(frame);const dt=Math.min((now-last)/1000,.06);last=now;const t=now/1000;
if(demo){let phase=((now-demoStart)/1000)%20;progress=Math.min(11,phase*1.15);let p=phase<10?0:phase<13?1:phase<16?2:3;if(p!==demoPhase){demoPhase=p;if(p===0){info(-1);toggleCut(false);fly=null;camera.position.set(8,5,13.5);controls.target.set(0,0,0)}if(p===1){toggleCut(true);select(0,true)}if(p===2)select(6,true);if(p===3){toggleCut(false);fly={start:now,from:camera.position.clone(),targetFrom:controls.target.clone(),to:new THREE.Vector3(8,5,13.5),target:new THREE.Vector3()}}}controls.autoRotate=true;controls.autoRotateSpeed=1.1;refresh()}
else if(playing&&progress<11){if(buildWait>0)buildWait-=dt;else progress=Math.min(11,progress+dt*.64);refresh()}
const n=Math.ceil(progress);if(n!==previousCount){previousCount=n;if(n>0&&!demo)info(n-1);else if(n===0)info(-1)}
groups.forEach((g,i)=>{const f=THREE.MathUtils.clamp(progress-i,0,1);g.visible=f>0;let s=THREE.MathUtils.smoothstep(f,0,1);g.scale.setScalar(Math.max(.001,s)*(1+Math.sin(t*.8+i)*.012));g.position.copy(g.userData.base);if(i!==1){g.position.x+=Math.sin(t*.32+i)*.028;g.position.y+=Math.sin(t*.4+i)*.035}g.rotation.y=Math.sin(t*.28+i)*.018});
membrane.scale.set(1.07*(1+Math.sin(t*.65)*.005),.91*(1+Math.sin(t*.65)*.005),1+Math.sin(t*.65)*.005);
if(fly){let f=Math.min(1,(now-fly.start)/1250);let ease=f*f*(3-2*f);camera.position.lerpVectors(fly.from,fly.to,ease);controls.target.lerpVectors(fly.targetFrom,fly.target,ease);if(f===1)fly=null}controls.update();
const label=$('label');if(selected>=0&&groups[selected].visible){groups[selected].getWorldPosition(v);v.project(camera);const b=$('canvas').getBoundingClientRect();let x=(v.x*.5+.5)*b.width,y=(-v.y*.5+.5)*b.height;label.style.display=v.z<1&&x>0&&x<b.width&&y>0&&y<b.height?'block':'none';label.style.left=Math.min(b.width-145,Math.max(12,x+32))+'px';label.style.top=Math.max(innerWidth<=600?235:120,Math.min(b.height-210,y-35))+'px'}else label.style.display='none';renderer.render(scene,camera)}
info(-1);refresh();requestAnimationFrame(frame);
}catch(err){$('error').style.display='block';$('status').textContent='3D is unavailable';console.error(err)}
</script>
</body>
</html>