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.)48.2 KB · 287 lines · loads cdn.jsdelivr.net/npm/three@0.160.1/build/three.module.js, cdn.jsdelivr.net/npm/three@0.160.1/examples/jsm/
Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#f5f6ef">
<title>Cellular — Life, piece by piece</title>
<script type="importmap">{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.1/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.160.1/examples/jsm/"}}</script>
<style>
:root{--paper:#f5f6ef;--ink:#243e32;--muted:#748176;--green:#315c45;--line:#dfe5d9;--white:#fffffb}
*{box-sizing:border-box}body{margin:0;background:var(--paper);color:var(--ink);font-family:Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;-webkit-font-smoothing:antialiased}button,input{font:inherit}button{cursor:pointer;-webkit-tap-highlight-color:transparent;color:inherit}button:focus-visible,input:focus-visible{outline:3px solid #9db89a;outline-offset:5px}svg{display:block;flex-shrink:0}button svg{pointer-events:none}.page{max-width:1512px;margin:auto;padding:0 48px}.masthead{height:91px;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line);gap:16px}.brand{display:flex;align-items:center;gap:10px;font-size:25px;font-weight:700;letter-spacing:-1px}.brand-icon{width:35px;height:35px}.brand sup{font-size:10px;align-self:flex-start;margin:8px 0 0 -5px;letter-spacing:0}.masthead-right{display:flex;align-items:center;gap:25px}.edition{font-size:10px;letter-spacing:2px;font-weight:650;color:var(--muted)}.help-btn{border:1px solid #d4ded0;border-radius:50%;width:44px;height:44px;background:transparent;font-size:17px;font-family:Georgia,serif}.workspace{display:grid;grid-template-columns:340px minmax(0,1fr);gap:37px;padding:31px 0 25px;align-items:center;min-height:610px}.intro{padding:7px 0}.eyebrow{display:flex;align-items:center;gap:9px;font-size:10px;font-weight:650;letter-spacing:2px;text-transform:uppercase;color:#71816e}.eyebrow .dash{width:22px;height:1px;background:#849a7e}.hero-title{font-family:Georgia,"Times New Roman",serif;font-weight:400;font-size:65px;line-height:1.02;letter-spacing:-3.8px;margin:22px 0 18px}.hero-title em{color:#6b8963;font-weight:400}.intro-description{font-size:14px;line-height:1.75;color:#7a8375;margin:0 0 26px;max-width:315px}.part-card{background:var(--white);border:1px solid var(--line);border-radius:17px;padding:21px 22px 20px;min-height:193px;position:relative;box-shadow:0 5px 15px #243e3203}.card-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px;gap:10px}.card-role{font-size:9px;letter-spacing:1.3px;text-transform:uppercase;font-weight:700;color:#81917a}.part-number{font-size:10px;color:#92a08a;font-variant-numeric:tabular-nums;white-space:nowrap}.part-title{display:flex;align-items:center;gap:9px;font-size:22px;font-weight:550;letter-spacing:-.6px;line-height:1.2;margin:0 0 10px}.part-dot{width:10px;height:10px;border-radius:50%;background:#91b69c;flex-shrink:0;box-shadow:0 0 0 4px #91b69c18}.part-description{margin:0;font-size:13px;line-height:1.75;color:#788271;min-height:65px}.parts-library{margin-top:23px}.library-heading{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:11px}.library-heading span:first-child{font-size:9px;letter-spacing:1.5px;font-weight:650;color:#7a8774}.library-heading span:last-child{font-size:10px;color:#85917d}.part-buttons{display:flex;gap:5px;flex-wrap:wrap}.part-btn{border:1px solid #dce3d5;background:transparent;width:26px;min-height:37px;padding:0;border-radius:7px;display:grid;place-items:center;font-size:10px;font-weight:600;color:#9ca794;transition:background .2s,color .2s,transform .2s}.part-btn.built{background:#e7edde;color:#607959;border-color:#d4dfca}.part-btn.selected{background:var(--green);border-color:var(--green);color:#fff;transform:translateY(-2px)}.library-hint{font-size:10px;line-height:1.5;margin:11px 0 0;color:#8d9786;display:flex;align-items:center;gap:6px}
.stage{height:590px;min-width:0;position:relative;overflow:hidden;border:1px solid #dce5d6;border-radius:24px;background:radial-gradient(ellipse at 50% 42%,#f9fbf3 0%,#edf3e5 54%,#e6eedf 100%);isolation:isolate}.stage:after{content:"";position:absolute;inset:0;pointer-events:none;border-radius:inherit;box-shadow:inset 0 0 80px #dbe7d24a}.stage-top{position:absolute;top:25px;left:25px;right:23px;z-index:4;display:flex;align-items:flex-start;justify-content:space-between;gap:10px;pointer-events:none}.stage-heading{font-size:10px;font-weight:700;letter-spacing:1.6px}.stage-subtitle{font-size:11px;color:#899780;margin-top:7px;letter-spacing:.1px}.cut-toggle{pointer-events:auto;display:flex;align-items:center;gap:9px;border:1px solid #d5dfcd;background:#f8fbf2d9;backdrop-filter:blur(8px);border-radius:25px;min-height:44px;padding:6px 11px 6px 12px;font-size:11px;font-weight:550;box-shadow:0 2px 4px #315c4503}.switch{width:29px;height:17px;background:#c8d1c0;border-radius:20px;position:relative;transition:background .25s}.switch:before{content:"";position:absolute;left:3px;top:3px;width:11px;height:11px;border-radius:50%;background:#fff;transition:transform .25s}.cut-toggle[aria-checked=true] .switch{background:#477252}.cut-toggle[aria-checked=true] .switch:before{transform:translateX(12px)}#viewport{position:absolute;inset:0;touch-action:none;z-index:2}#viewport canvas{display:block;width:100%;height:100%;touch-action:none;cursor:grab}#viewport canvas:active{cursor:grabbing}.specimen-shadow{position:absolute;bottom:69px;left:27%;width:48%;height:28px;filter:blur(14px);border-radius:50%;background:#547e4d19;z-index:0}.orbit-track{position:absolute;width:73%;height:69%;left:13.5%;top:15%;border:1px dashed #9caf901f;border-radius:50%;transform:rotate(-21deg);pointer-events:none}.stage-status{position:absolute;bottom:24px;left:25px;z-index:4;font-size:9px;letter-spacing:1.1px;text-transform:uppercase;color:#7c8e73;display:flex;align-items:center;gap:7px;pointer-events:none}.status-dot{height:5px;width:5px;border-radius:50%;background:#6e9763;box-shadow:0 0 0 3px #6e976315;animation:breathe 2.8s ease-in-out infinite}.scale{position:absolute;right:25px;bottom:24px;z-index:4;font-size:9px;color:#829477;display:flex;align-items:center;gap:9px}.scale-line{display:block;width:37px;height:6px;border:1px solid #91a585;border-top:0}.stage-hint{position:absolute;z-index:4;left:50%;bottom:49px;transform:translateX(-50%);display:flex;align-items:center;justify-content:center;gap:14px;color:#819174;white-space:nowrap;font-size:10px;pointer-events:none}.stage-hint span{display:flex;align-items:center;gap:5px}.hint-divider{width:1px;height:10px;background:#ccd8c2}.selection-label{position:absolute;z-index:5;pointer-events:none;transform:translate(22px,-50%);opacity:0;transition:opacity .3s;white-space:nowrap;filter:drop-shadow(0 3px 5px #45603a0c)}.selection-label.visible{opacity:1}.selection-label:before{content:"";position:absolute;height:1px;width:23px;left:-23px;top:50%;background:#809774a0}.selection-label:after{content:"";position:absolute;width:5px;height:5px;border:2px solid #f7faf1;background:#54764b;border-radius:50%;left:-28px;top:calc(50% - 4px)}.selection-label div{background:#fcfff7ec;border:1px solid #d7e3cc;border-radius:8px;padding:9px 12px;font-size:11px;font-weight:550;backdrop-filter:blur(6px)}.selection-label small{font-size:8px;color:#8e9f83;letter-spacing:1px;margin-right:6px}.start-note{position:absolute;left:50%;top:51%;transform:translate(-50%,-50%);z-index:4;text-align:center;pointer-events:none;color:#6f8967;transition:opacity .7s;width:80%;font-family:Georgia,serif;font-style:italic;font-size:20px;text-shadow:0 2px 12px #f4f9eb}.start-note small{display:block;margin-top:10px;font-family:inherit;font-size:12px;opacity:.65}.demo-pill{display:none;position:absolute;z-index:7;left:50%;top:24px;transform:translateX(-50%);border:1px solid #d9e4cf;background:#f9fcf2e8;padding:9px 12px;border-radius:20px;font-size:9px;font-weight:600;letter-spacing:1px;pointer-events:none}.demo-pill.show{display:block}.loading{position:absolute;z-index:10;left:50%;top:50%;transform:translate(-50%,-50%);text-align:center;font-size:13px;color:#687e5e;line-height:1.8;width:80%}.loading.hidden{display:none}.loading-spinner{width:25px;height:25px;border:2px solid #d0dcc6;border-top-color:#587a4b;border-radius:50%;margin:0 auto 15px;animation:spin 1.1s linear infinite}.error-message{font-size:12px;line-height:1.8}
.transport{background:var(--white);border:1px solid var(--line);border-radius:18px;display:flex;align-items:center;gap:25px;padding:22px 26px;position:relative;z-index:8}.transport-actions{display:flex;gap:12px;align-items:center}.play-button{width:44px;height:44px;border-radius:50%;border:0;background:#345b41;color:#f6f8ef;display:grid;place-items:center;flex-shrink:0;transition:background .2s}.play-button:hover{background:#244a30}.rebuild-button{border:1px solid #dde4d6;border-radius:9px;display:flex;align-items:center;justify-content:center;gap:8px;background:transparent;padding:11px 14px;min-height:44px;font-size:11px;font-weight:550}.transport-separator{height:39px;width:1px;background:#e5e9df}.timeline{flex:1;min-width:0}.timeline-top{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:5px}.timeline-title{font-size:9px;font-weight:650;letter-spacing:1.6px;color:#79886f}.timeline-count{font-size:10px;color:#84917a;font-variant-numeric:tabular-nums}.timeline-track{position:relative;height:24px;display:flex;align-items:center}input[type=range]{appearance:none;-webkit-appearance:none;width:100%;height:24px;background:transparent;margin:0;position:relative;z-index:2;cursor:pointer;touch-action:pan-y}input[type=range]::-webkit-slider-runnable-track{height:5px;border-radius:5px;background:linear-gradient(to right,#7d9f69 0%,#7d9f69 var(--progress,0%),#e5ebdf var(--progress,0%),#e5ebdf 100%)}input[type=range]::-webkit-slider-thumb{appearance:none;-webkit-appearance:none;width:15px;height:15px;margin-top:-5px;border:3px solid #fff;background:#567d46;border-radius:50%;box-shadow:0 0 0 1px #7e9e6b}input[type=range]::-moz-range-track{height:5px;background:#e5ebdf;border-radius:5px}input[type=range]::-moz-range-progress{height:5px;background:#7d9f69;border-radius:5px}input[type=range]::-moz-range-thumb{width:9px;height:9px;border:3px solid #fff;background:#567d46;border-radius:50%;box-shadow:0 0 0 1px #7e9e6b}.timeline-labels{display:flex;justify-content:space-between;font-size:9px;color:#a0aa95;margin-top:1px}.transport-end{display:flex;align-items:center;gap:9px;font-size:10px;line-height:1.6;color:#8a9780;max-width:134px}.footer{display:flex;justify-content:space-between;gap:20px;padding:19px 1px 23px;color:#9aa490;font-size:9px;letter-spacing:.2px}.footer-name{display:flex;align-items:center;gap:6px}.footer .small-dot{height:3px;width:3px;border-radius:50%;background:#a8b29c}.help-panel{position:fixed;inset:0;z-index:40;background:#243e3245;backdrop-filter:blur(7px);display:grid;place-items:center;padding:24px}.help-panel[hidden]{display:none}.help-card{background:#fafbf4;max-width:420px;padding:30px;border-radius:23px;box-shadow:0 20px 80px #19352220;position:relative}.help-card h2{font-family:Georgia,serif;font-weight:400;font-size:32px;margin:9px 0 13px;letter-spacing:-1px}.help-card p{font-size:13px;color:#79856e;line-height:1.8}.help-list{display:grid;gap:13px;margin:24px 0;font-size:13px}.help-list>div{display:flex;gap:11px;align-items:center}.help-list svg{color:#6c8e5b}.close-help{width:44px;height:44px;border:1px solid #dce4d3;background:transparent;border-radius:50%;position:absolute;right:14px;top:14px;font-size:20px}.tour-button{width:100%;min-height:45px;border:0;background:#345b41;color:#f5f8ef;border-radius:9px;font-size:12px;font-weight:550}.help-fine{font-size:10px!important;color:#99a28f!important;margin-bottom:0}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}@keyframes breathe{50%{opacity:.45}}@keyframes spin{to{transform:rotate(360deg)}}@media(min-width:1500px){.workspace{grid-template-columns:350px minmax(0,1fr);gap:55px;padding:35px 0}.stage{height:620px}.hero-title{font-size:73px}.intro-description{font-size:15px;max-width:325px}.part-description{font-size:14px}.part-card{min-height:203px}.part-btn{width:27px}.page{padding:0 54px}}@media(max-width:1100px){.page{padding:0 28px}.workspace{grid-template-columns:285px minmax(0,1fr);gap:23px}.hero-title{font-size:58px}.stage{height:550px}.stage-top{left:19px;right:17px}.stage-subtitle{max-width:120px;line-height:1.5}.cut-toggle{gap:7px;padding-left:10px;font-size:10px}.cut-toggle>svg{display:none}.part-card{padding:19px}.part-btn{width:23px}.part-buttons{gap:3px}.transport{gap:18px}.transport-end{display:none}.demo-pill{top:80px}.selection-label div{font-size:10px;padding:8px 9px}.selection-label small{display:none}}@media(max-width:760px){.page{padding:0 20px}.masthead{height:71px}.brand{font-size:23px}.brand-icon{width:31px;height:31px}.edition{font-size:8px;letter-spacing:1.2px}.masthead-right{gap:13px}.workspace{display:flex;flex-direction:column;align-items:stretch;gap:20px;padding:25px 0 20px;min-height:0}.intro{display:contents}.intro-copy{order:0;position:relative}.eyebrow{font-size:9px;letter-spacing:1.6px}.hero-title{font-size:46px;letter-spacing:-2px;margin:14px 0 11px;line-height:1.04}.hero-title br{display:none}.hero-title em{white-space:nowrap}.intro-description{font-size:12px;line-height:1.7;max-width:460px;margin:0}.stage{order:1;height:440px;border-radius:20px;margin:0 -5px}.stage-top{top:20px;left:19px;right:16px}.stage-status{left:18px;bottom:20px;font-size:8px;letter-spacing:.7px}.scale{right:18px;bottom:20px;font-size:8px}.stage-hint{bottom:45px;font-size:9px;gap:10px}.part-card{order:2;min-height:0;padding:18px 20px}.card-top{margin-bottom:11px}.part-title{font-size:21px;margin-bottom:7px}.part-description{min-height:0;font-size:13px}.parts-library{order:3;margin-top:0}.part-buttons{justify-content:space-between;gap:5px}.part-btn{height:44px;width:calc((100% - 25px)/6);max-width:none}.library-hint{margin-top:8px}.transport{position:sticky;bottom:0;margin:0 -20px;border-radius:15px 15px 0 0;padding:17px 20px 18px;gap:15px;border-bottom:0;box-shadow:0 -8px 20px #28432206}.transport-actions{gap:8px}.rebuild-button{width:44px;min-height:44px;padding:0;border-radius:50%}.rebuild-button span{display:none}.play-button{width:44px;height:44px}.transport-separator{display:none}.timeline-top{margin-bottom:3px}.timeline-title{font-size:8px;letter-spacing:1px}.timeline-count{font-size:9px}.timeline-labels{font-size:8px}.footer{font-size:8px;line-height:1.6;gap:10px;padding:17px 0}.footer>span:last-child{text-align:right}.selection-label div{padding:8px 10px}.start-note{font-size:18px}.demo-pill{font-size:8px;top:76px}}@media(max-width:390px){.page{padding:0 16px}.hero-title{font-size:41px}.edition{display:none}.stage{height:397px}.transport{margin:0 -16px;padding-left:16px;padding-right:16px;gap:10px}.timeline-title{font-size:7px}.part-buttons{gap:4px}.part-btn{width:calc((100% - 20px)/6)}}@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;scroll-behavior:auto!important}.part-btn{transition:none}}
</style>
</head>
<body>
<div class="page">
<header class="masthead">
<div class="brand"><svg class="brand-icon" viewBox="0 0 40 40" fill="none" aria-hidden="true"><path d="M33.2 10.5c5.2 7.2 1.8 19.3-5.8 23.3-7.2 3.8-17.1.7-21.1-5.8C1.8 20.7 6.6 8.9 14.9 5.5c6.2-2.5 14.2-.7 18.3 5Z" stroke="#54734b" stroke-width="1.5"/><path d="M30.4 12.4c4.2 5.9 1.4 15.7-4.7 19-5.9 3.1-14 .6-17.2-4.7C4.9 20.7 8.7 11.1 15.5 8.3c5-2 11.6-.5 14.9 4.1Z" stroke="#9ab18b" stroke-width=".8"/><circle cx="21" cy="19" r="6" fill="#739267"/><circle cx="23" cy="17.5" r="2" fill="#f5f6ef"/><circle cx="11" cy="20" r="1.2" fill="#9ab18b"/><circle cx="26" cy="28" r="1.3" fill="#9ab18b"/></svg>cellular<sup>®</sup></div>
<div class="masthead-right"><span class="edition">SMALL WORLDS. BIG DISCOVERIES.</span><button class="help-btn" id="helpOpen" aria-label="How to explore">?</button></div>
</header>
<main>
<section class="workspace">
<div class="intro">
<div class="intro-copy"><div class="eyebrow"><span class="dash"></span> THE LIVING LAB <span style="color:#afb7a5">/ 001</span></div><h1 class="hero-title">Life, <em>piece<br>by piece.</em></h1><p class="intro-description">Meet the tiny world that makes you, you.<br>Watch an animal cell come to life, one part at a time.</p></div>
<article class="part-card" aria-label="About the selected cell part">
<div class="card-top"><span class="card-role" id="partRole">EVERY WORLD NEEDS A BOUNDARY</span><span class="part-number" id="partNumber">THE BEGINNING</span></div>
<h2 class="part-title"><span class="part-dot" id="partDot"></span><span id="partTitle">Cell membrane</span></h2>
<p class="part-description" id="partDescription">This flexible boundary controls what enters and leaves the cell.</p>
</article>
<div class="parts-library"><div class="library-heading"><span>THE PARTS THAT MAKE IT WORK</span><span id="libraryCount">0 / 11</span></div><div class="part-buttons" id="partButtons" role="group" aria-label="Explore the 11 cell parts"></div><p class="library-hint"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 11v6m0-10v1"/></svg>Pick a number to meet a part.</p></div>
</div>
<div class="stage" id="stage">
<div class="orbit-track"></div><div class="specimen-shadow"></div>
<div class="stage-top"><div><div class="stage-heading">THE ANIMAL CELL</div><div class="stage-subtitle">A whole little universe inside.</div></div><button id="cutToggle" class="cut-toggle" role="switch" aria-checked="false" aria-label="Cut open the cell"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="m4 20 16-16M7 6a8 8 0 0 1 11 11M6 10a8 8 0 0 0 8 8"/></svg>Cut open<span class="switch" aria-hidden="true"></span></button></div>
<div id="viewport" role="img" aria-label="Interactive 3D animal cell. Drag to orbit, pinch or scroll to zoom, and tap a part to learn about it. Use the numbered buttons as an alternative to tapping the model."></div>
<div class="selection-label" id="selectionLabel"><div><small id="labelNumber">01</small><span id="labelName">Nucleus</span></div></div>
<div class="start-note" id="startNote">It begins with a boundary.<small>Now, let's build a little life.</small></div>
<div class="demo-pill" id="demoPill">GUIDED TOUR · TOUCH TO EXPLORE</div>
<div class="stage-hint"><span><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><path d="M8 11V6a2 2 0 0 1 4 0v5m0-2a2 2 0 0 1 4 0v3m0-1a2 2 0 0 1 4 0v5c0 4-3 6-6 6-3 0-4-2-6-4l-4-4a2 2 0 0 1 3-3l1 1"/></svg>Drag to orbit</span><i class="hint-divider"></i><span><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><circle cx="10" cy="10" r="6"/><path d="m15 15 6 6M7 10h6m-3-3v6"/></svg>Pinch or scroll to zoom</span></div>
<div class="stage-status"><span class="status-dot"></span><span id="statusText">BUILDING YOUR CELL</span></div><div class="scale"><span class="scale-line"></span>≈ 30 μm</div>
<div class="loading" id="loading"><div class="loading-spinner"></div>Preparing your little world…</div>
</div>
</section>
<section class="transport" aria-label="Cell assembly controls">
<div class="transport-actions"><button id="playButton" class="play-button" aria-label="Pause assembly"><svg width="15" height="16" viewBox="0 0 18 20" fill="currentColor" aria-hidden="true"><rect x="3" y="3" width="4" height="14" rx="1"/><rect x="11" y="3" width="4" height="14" rx="1"/></svg></button><button id="rebuildButton" class="rebuild-button" aria-label="Rebuild the cell"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M4 10a8 8 0 1 1 1 7M4 4v6h6"/></svg><span>Rebuild</span></button></div>
<div class="transport-separator"></div><div class="timeline"><div class="timeline-top"><label class="timeline-title" for="buildSlider">BUILD YOUR CELL</label><span class="timeline-count" id="timelineCount">0 of 11 parts</span></div><div class="timeline-track"><input type="range" min="0" max="11" step="0.01" value="0" id="buildSlider" aria-label="Scrub through cell assembly" aria-valuetext="Empty cell membrane"></div><div class="timeline-labels"><span>A simple beginning</span><span>A world of possibility</span></div></div>
<div class="transport-end"><svg width="23" height="23" viewBox="0 0 24 24" fill="none" stroke="#91a47f" stroke-width="1.2" aria-hidden="true"><path d="m12 3 1.8 6.2L20 11l-6.2 1.8L12 19l-1.8-6.2L4 11l6.2-1.8L12 3Z"/><path d="m20 17 .6 2.4L23 20l-2.4.6L20 23l-.6-2.4L17 20l2.4-.6Z"/></svg><span>Big things start<br>in tiny places.</span></div>
</section>
</main>
<footer class="footer"><span class="footer-name">MADE FOR CURIOUS MINDS <span class="small-dot"></span> AGES 12 & UP</span><span>A learning model. Sizes and numbers simplified.</span></footer>
</div>
<div class="help-panel" id="helpPanel" hidden><div class="help-card" role="dialog" aria-modal="true" aria-labelledby="helpTitle"><button class="close-help" id="helpClose" aria-label="Close help">×</button><div class="eyebrow">A LITTLE FIELD GUIDE</div><h2 id="helpTitle">Follow your curiosity.</h2><p>Watch the cell build itself, or take the lead. Every tiny part has a big job to do.</p><div class="help-list"><div><svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="m4 12 4-4m-4 4 4 4m-4-4h16m0 0-4-4m4 4-4 4"/></svg>Drag the cell to see every side.</div><div><svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="10" cy="10" r="6"/><path d="m15 15 6 6m-14-11h6m-3-3v6"/></svg>Pinch or scroll to get closer.</div><div><svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="12" cy="12" r="8"/><circle cx="12" cy="12" r="2"/></svg>Tap a part, or choose its number.</div><div><svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="m4 20 16-16M6 9a8 8 0 0 0 9 9M9 6a8 8 0 0 1 9 9"/></svg>Cut it open. Scrub back. Build it again.</div></div><button class="tour-button" id="tourButton">Take a 20-second tour <span aria-hidden="true">↗</span></button><p class="help-fine">This is an animal cell. Plant cells have some different parts, including a cell wall and chloroplasts.</p></div></div>
<div id="announcer" class="sr-only" role="status" aria-live="polite"></div>
<script type="module">
const $=id=>document.getElementById(id);
const parts=[
{name:"Nucleus",role:"THE INSTRUCTION KEEPER",color:"#d790a0",text:"The nucleus holds DNA, the instructions that tell the cell how to grow and work.",anchor:[-.45,.4,.25]},
{name:"Nucleolus",role:"THE RIBOSOME WORKSHOP",color:"#b86683",text:"The nucleolus makes the pieces that become ribosomes.",anchor:[-.57,.48,.12]},
{name:"Rough endoplasmic reticulum",short:"Rough ER",role:"THE PROTEIN WORKSHOP",color:"#829eaf",text:"The rough ER folds and moves new proteins, with ribosomes dotted along its surface.",anchor:[-1.45,.03,.2]},
{name:"Smooth endoplasmic reticulum",short:"Smooth ER",role:"THE CHEMISTRY LAB",color:"#b4bd86",text:"The smooth ER makes fats and helps clear away harmful chemicals.",anchor:[1.15,.7,-.35]},
{name:"Ribosomes",role:"THE TINY BUILDERS",color:"#976b7c",text:"Ribosomes build proteins, the tiny tools and building blocks a cell needs.",anchor:[.4,-.25,.83]},
{name:"Golgi apparatus",role:"THE PACKING & SHIPPING CENTER",color:"#aa8eb3",text:"The Golgi apparatus sorts, packages and sends proteins where they need to go.",anchor:[1,-.84,.2]},
{name:"Mitochondria",role:"THE ENERGY MAKERS",color:"#dca05e",text:"Mitochondria turn energy from food into a form the cell can use.",anchor:[1.55,1.12,.5]},
{name:"Lysosomes",role:"THE RECYCLING TEAM",color:"#c7af59",text:"Lysosomes break down waste and worn-out cell parts so their materials can be reused.",anchor:[1.6,-.15,.83]},
{name:"Vesicles",role:"THE LITTLE DELIVERY BUBBLES",color:"#79afaa",text:"Vesicles are little bubbles that carry materials around the cell.",anchor:[1.67,-1,.25]},
{name:"Centrioles",role:"THE DIVISION HELPERS",color:"#c78f72",text:"Centrioles help organize the fibers that pull chromosomes apart when a cell divides.",anchor:[.65,.05,.92]},
{name:"Cytoskeleton",role:"THE INNER FRAMEWORK",color:"#70a18b",text:"The cytoskeleton is a network of fibers that gives the cell shape and helps things move.",anchor:[-1.6,-.95,-.25]}
];
let progress=0,selected=-1,playing=true,cut=false,ready=false,waitTime=1.8;
let demo=location.hash==="#demo",demoStart=0,lastDemoStep=-1;
let THREE,renderer,scene,camera,controls,cell,groups=[],pickables=[],cutRim,cutPlane;
let fly=null,clockTime=0,down=null,gestureMoved=false,pointerCount=0;
const reduced=matchMedia("(prefers-reduced-motion: reduce)").matches;
const viewport=$("viewport"),slider=$("buildSlider"),buttons=[];
parts.forEach((p,i)=>{
 const b=document.createElement("button");b.className="part-btn";b.textContent=String(i+1).padStart(2,"0");
 b.title=p.name;b.setAttribute("aria-label",(i+1)+". "+p.name);b.setAttribute("aria-pressed","false");
 b.addEventListener("click",()=>{stopDemo();setPlaying(false);setProgress(Math.max(progress,i+1));activate(i,true)});
 $("partButtons").appendChild(b);buttons.push(b);
});
const pauseSVG='<svg width="15" height="16" viewBox="0 0 18 20" fill="currentColor" aria-hidden="true"><rect x="3" y="3" width="4" height="14" rx="1"/><rect x="11" y="3" width="4" height="14" rx="1"/></svg>';
const playSVG='<svg width="15" height="16" viewBox="0 0 18 20" fill="currentColor" aria-hidden="true"><path d="M4 2.8c0-.8.9-1.3 1.6-.8l11 7.2a1 1 0 0 1 0 1.6L5.6 18c-.7.5-1.6 0-1.6-.8V2.8Z"/></svg>';
function setPlaying(v){playing=v;$("playButton").innerHTML=v?pauseSVG:playSVG;$("playButton").setAttribute("aria-label",v?"Pause assembly":progress>=11?"Replay assembly":"Play assembly");updateStatus()}
function updateStatus(){$("statusText").textContent=demo?"A LITTLE GUIDED DISCOVERY":progress>=11?"YOUR CELL IS ALIVE":playing?"BUILDING YOUR CELL":"PAUSED · FOLLOW YOUR CURIOSITY"}
function activate(i,zoom=false){
 if(i===selected&&!zoom)return;selected=i;
 buttons.forEach((b,j)=>{b.classList.toggle("selected",j===i);b.setAttribute("aria-pressed",String(j===i))});
 const p=parts[i];
 $("partRole").textContent=p?p.role:"EVERY WORLD NEEDS A BOUNDARY";$("partNumber").textContent=p?String(i+1).padStart(2,"0")+" / 11":"THE BEGINNING";
 $("partTitle").textContent=p?p.name:"Cell membrane";$("partDescription").textContent=p?p.text:"This flexible boundary controls what enters and leaves the cell.";
 $("partDot").style.background=p?p.color:"#91b69c";$("partDot").style.boxShadow="0 0 0 4px "+(p?p.color:"#91b69c")+"18";
 $("labelName").textContent=p?(p.short||p.name):"";$("labelNumber").textContent=String(i+1).padStart(2,"0");
 if(p)$("announcer").textContent=p.name+". "+p.text;
 if(zoom&&ready&&p)focusPart(i);
}
function setProgress(v,autoSelect=true){
 progress=Math.min(11,Math.max(0,v));slider.value=progress;slider.style.setProperty("--progress",(progress/11*100)+"%");
 const count=Math.min(11,Math.floor(progress+.001));$("timelineCount").textContent=count+" of 11 parts";$("libraryCount").textContent=count+" / 11";slider.setAttribute("aria-valuetext",count+" of 11 parts built");
 buttons.forEach((b,i)=>b.classList.toggle("built",progress>=i+.03));
 if(autoSelect)activate(progress<.015?-1:Math.min(10,Math.ceil(progress)-1));
 $("startNote").style.opacity=progress>.03?"0":"1";updateStatus();
}
function setCut(v){cut=v;$("cutToggle").setAttribute("aria-checked",String(v));if(ready){renderer.clippingPlanes=v?[cutPlane]:[];cutRim.visible=v}}
function stopDemo(){if(!demo)return;demo=false;$("demoPill").classList.remove("show");setPlaying(false);if(ready)controls.autoRotate=false;lastDemoStep=-1}
function resetView(){if(!ready)return;fly={from:camera.position.clone(),to:new THREE.Vector3(0,.55,9.1),startTarget:controls.target.clone(),endTarget:new THREE.Vector3(0,0,0),elapsed:0,duration:reduced?.01:1.2}}
function rebuild(){stopDemo();setCut(false);setProgress(0);waitTime=1.3;setPlaying(true);resetView()}
function focusPart(i){
 if(!ready)return;const target=new THREE.Vector3(...parts[i].anchor);if(cut)target.z=Math.min(target.z,.03);
 const direction=camera.position.clone().sub(controls.target).normalize();if(cut&&direction.z<.35)direction.set(.16,.25,1).normalize();
 const distance=i===0||i===2||i===3?5.5:i===10?7.5:4.4;
 fly={from:camera.position.clone(),to:target.clone().addScaledVector(direction,distance),startTarget:controls.target.clone(),endTarget:target,elapsed:0,duration:reduced?.01:1.1};
}
$("rebuildButton").addEventListener("click",rebuild);
$("playButton").addEventListener("click",()=>{stopDemo();if(progress>=11){rebuild();return}setPlaying(!playing)});
slider.addEventListener("input",()=>{stopDemo();setPlaying(false);setProgress(Number(slider.value));if(ready&&controls.target.length()>.25)resetView()});
$("cutToggle").addEventListener("click",()=>{stopDemo();setCut(!cut)});
const help=$("helpPanel");
function showHelp(){stopDemo();help.hidden=false;$("helpClose").focus()}
function hideHelp(){help.hidden=true;$("helpOpen").focus()}
$("helpOpen").addEventListener("click",showHelp);$("helpClose").addEventListener("click",hideHelp);
help.addEventListener("click",e=>{if(e.target===help)hideHelp()});
document.addEventListener("keydown",e=>{if(e.key==="Escape"&&!help.hidden)hideHelp();if(!help.hidden&&e.key==="Tab"){const f=[$("helpClose"),$("tourButton")];if(e.shiftKey&&document.activeElement===f[0]){e.preventDefault();f[1].focus()}else if(!e.shiftKey&&document.activeElement===f[1]){e.preventDefault();f[0].focus()}}});
$("tourButton").addEventListener("click",()=>{help.hidden=true;startDemo()});
document.addEventListener("pointerdown",e=>{if(e.isTrusted)stopDemo()},{capture:true,passive:true});
document.addEventListener("wheel",()=>stopDemo(),{capture:true,passive:true});
function startDemo(){demo=true;demoStart=clockTime;lastDemoStep=-1;setPlaying(false);setCut(false);setProgress(0);$("demoPill").classList.add("show");resetView()}
function runDemo(elapsed){
 const t=elapsed%20;
 if(t<.15&&lastDemoStep!==0){lastDemoStep=0;setCut(false);setProgress(0);resetView();controls.autoRotate=false}
 if(t<1.5){setProgress(0)}
 else if(t<9.3){setProgress((t-1.5)/7.8*11);lastDemoStep=1}
 else if(t<11.5){if(lastDemoStep!==2){lastDemoStep=2;setProgress(11);activate(0,false);resetView()}controls.autoRotate=true;controls.autoRotateSpeed=2.8}
 else if(t<13.5){if(lastDemoStep!==3){lastDemoStep=3;controls.autoRotate=false;activate(6,true)}}
 else if(t<16.5){if(lastDemoStep!==4){lastDemoStep=4;setCut(true);activate(0,false);fly={from:camera.position.clone(),to:new THREE.Vector3(.2,.65,8.6),startTarget:controls.target.clone(),endTarget:new THREE.Vector3(0,0,0),elapsed:0,duration:1.1}}}
 else if(t<18.2){if(lastDemoStep!==5){lastDemoStep=5;setCut(false)}setProgress(11-(t-16.5)/1.7*6)}
 else if(t<19.4){setProgress(5+(t-18.2)/1.2*6);lastDemoStep=6}
 else{if(lastDemoStep!==7){lastDemoStep=7;setProgress(11);activate(10,false);resetView()}}
}
function fail(message){$("loading").classList.remove("hidden");$("loading").innerHTML='<div class="error-message"><strong>Your 3D world couldn’t load.</strong><br>'+message+'<br>You can still pick the numbered parts to learn what they do.</div>';$("startNote").style.display="none";$("playButton").disabled=true;$("rebuildButton").disabled=true;$("cutToggle").disabled=true;setPlaying(false)}
try{
 THREE=await import("three");
 const {OrbitControls}=await import("three/addons/controls/OrbitControls.js");
 scene=new THREE.Scene();
 renderer=new THREE.WebGLRenderer({antialias:true,alpha:true,powerPreference:"high-performance"});
 renderer.setPixelRatio(Math.min(devicePixelRatio||1,2));renderer.setClearColor(0x000000,0);renderer.outputColorSpace=THREE.SRGBColorSpace;renderer.toneMapping=THREE.ACESFilmicToneMapping;renderer.toneMappingExposure=1.12;renderer.localClippingEnabled=true;viewport.appendChild(renderer.domElement);
 camera=new THREE.PerspectiveCamera(39,1,.1,80);camera.position.set(0,.55,9.1);
 controls=new OrbitControls(camera,renderer.domElement);controls.enableDamping=true;controls.dampingFactor=.06;controls.enablePan=false;controls.minDistance=3.8;controls.maxDistance=15;controls.rotateSpeed=.6;controls.zoomSpeed=.75;controls.autoRotateSpeed=.5;controls.target.set(0,0,0);
 controls.addEventListener("start",()=>{fly=null});
 scene.add(new THREE.HemisphereLight(0xfffff5,0x8d9d7f,2.1));
 const key=new THREE.DirectionalLight(0xfffaf1,3);key.position.set(-4,5,6);scene.add(key);
 const fill=new THREE.DirectionalLight(0xd9f5e2,1.65);fill.position.set(5,1,3);scene.add(fill);
 const back=new THREE.DirectionalLight(0xffe6d0,1.3);back.position.set(1,2,-4);scene.add(back);
 cell=new THREE.Group();scene.add(cell);
 cutPlane=new THREE.Plane(new THREE.Vector3(0,0,-1),.12);
 let seed=7306;function rand(){seed=(seed*1664525+1013904223)>>>0;return seed/4294967296}
 function material(color,extra={}){return new THREE.MeshStandardMaterial({color,roughness:.49,metalness:.015,...extra})}
 function mesh(geometry,mat,parent){const o=new THREE.Mesh(geometry,mat);parent.add(o);return o}
 function sphere(r,mat,parent,pos,detail=24){const o=mesh(new THREE.SphereGeometry(r,detail,Math.max(12,Math.floor(detail*.7))),mat,parent);if(pos)o.position.set(...pos);return o}
 function tube(points,r,mat,parent,segments=48){return mesh(new THREE.TubeGeometry(new THREE.CatmullRomCurve3(points.map(p=>Array.isArray(p)?new THREE.Vector3(...p):p)),segments,r,7,false),mat,parent)}
 function ribbon(fn,nu,nv,mat,parent){const verts=[],uvs=[],idx=[];for(let j=0;j<=nv;j++)for(let i=0;i<=nu;i++){const p=fn(i/nu,j/nv);verts.push(...p);uvs.push(i/nu,j/nv)}for(let j=0;j<nv;j++)for(let i=0;i<nu;i++){const a=j*(nu+1)+i,b=a+nu+1;idx.push(a,b,a+1,b,b+1,a+1)}const g=new THREE.BufferGeometry();g.setAttribute("position",new THREE.Float32BufferAttribute(verts,3));g.setAttribute("uv",new THREE.Float32BufferAttribute(uvs,2));g.setIndex(idx);g.computeVertexNormals();return mesh(g,mat,parent)}
 function makePart(i,pos=[0,0,0]){const g=new THREE.Group();g.position.set(...pos);g.userData.base=g.position.clone();cell.add(g);groups[i]=g;return g}
 function registerParts(){groups.forEach((g,i)=>g.traverse(o=>{if(o.isMesh){o.userData.part=i;pickables.push(o)}}))}
 const membraneGeometry=new THREE.SphereGeometry(2.65,80,56);
 const mp=membraneGeometry.attributes.position;
 for(let i=0;i<mp.count;i++){const x=mp.getX(i),y=mp.getY(i),z=mp.getZ(i);const n=1+.018*Math.sin(x*1.8+y*.8)*Math.cos(z*1.7)+.009*Math.sin(y*3+z);mp.setXYZ(i,x*n*1.065,y*n*.93,z*n)}
 membraneGeometry.computeVertexNormals();
 mesh(membraneGeometry,material("#a0c6a1",{transparent:true,opacity:.105,side:THREE.BackSide,roughness:.27,depthWrite:false}),cell).renderOrder=1;
 const frontShell=mesh(membraneGeometry,new THREE.MeshPhysicalMaterial({color:"#9dc6a2",transparent:true,opacity:.135,roughness:.23,metalness:.02,clearcoat:.9,clearcoatRoughness:.25,side:THREE.FrontSide,depthWrite:false}),cell);frontShell.renderOrder=7;
 const innerShell=mesh(membraneGeometry,material("#bbd8b6",{transparent:true,opacity:.035,side:THREE.DoubleSide,depthWrite:false}),cell);innerShell.scale.setScalar(.975);
 const dotCanvas=document.createElement("canvas");dotCanvas.width=32;dotCanvas.height=32;const ctx=dotCanvas.getContext("2d");const grd=ctx.createRadialGradient(16,16,0,16,16,16);grd.addColorStop(0,"rgba(255,255,255,1)");grd.addColorStop(.5,"rgba(255,255,255,.8)");grd.addColorStop(1,"rgba(255,255,255,0)");ctx.fillStyle=grd;ctx.fillRect(0,0,32,32);const dotTexture=new THREE.CanvasTexture(dotCanvas);
 const motes=[];for(let i=0;i<650;i++){const a=rand()*Math.PI*2,z=rand()*2-1,r=Math.sqrt(1-z*z);const shell=i<420?1:Math.cbrt(rand())*.92;motes.push(Math.cos(a)*r*2.65*1.065*shell,z*2.65*.93*shell,Math.sin(a)*r*2.65*shell)}
 const dustGeo=new THREE.BufferGeometry();dustGeo.setAttribute("position",new THREE.Float32BufferAttribute(motes,3));const dust=new THREE.Points(dustGeo,new THREE.PointsMaterial({color:"#699973",size:.032,map:dotTexture,transparent:true,opacity:.45,depthWrite:false}));cell.add(dust);
 cutRim=new THREE.Group();scene.add(cutRim);
 const rimPoints=[];for(let i=0;i<=160;i++){const a=i/160*Math.PI*2;rimPoints.push([Math.cos(a)*2.65*1.065,Math.sin(a)*2.65*.93,.10])}tube(rimPoints,.018,material("#88ac86",{transparent:true,opacity:.72}),cutRim,160);
 const innerRim=[];for(let i=0;i<=160;i++){const a=i/160*Math.PI*2;innerRim.push([Math.cos(a)*2.65*1.04,Math.sin(a)*2.65*.905,.10])}tube(innerRim,.009,material("#bed0a9",{transparent:true,opacity:.6}),cutRim,160);cutRim.visible=false;
 // 01. A translucent nuclear envelope, with tiny pores.
 const nucleus=makePart(0,[-.45,.38,-.28]);
 const nucMat=material("#df96a3",{transparent:true,opacity:.64,roughness:.48,side:THREE.DoubleSide,depthWrite:false});
 const nucShell=sphere(.83,nucMat,nucleus,null,48);nucShell.scale.set(1.02,1,.92);nucShell.renderOrder=3;
 sphere(.765,material("#e8afba",{transparent:true,opacity:.14,depthWrite:false}),nucleus);
 const poreMat=material("#c8798b",{roughness:.7});
 for(let i=0;i<36;i++){const phi=Math.acos(1-2*(i+.5)/36),theta=i*2.39996;const n=new THREE.Vector3(Math.sin(phi)*Math.cos(theta),Math.cos(phi),Math.sin(phi)*Math.sin(theta));const pore=mesh(new THREE.TorusGeometry(.035,.012,6,12),poreMat,nucleus);pore.position.copy(n.clone().multiplyScalar(.836));pore.scale.z=.92;pore.quaternion.setFromUnitVectors(new THREE.Vector3(0,0,1),n)}
 const dnaMat=material("#c57f9d",{transparent:true,opacity:.5});
 for(let i=0;i<7;i++){const pts=[];for(let j=0;j<20;j++){const t=j/19*5;pts.push([Math.sin(t*2+i)*.38,Math.cos(t*1.5+i)*.4,Math.sin(t+i*2)*.4])}tube(pts,.014,dnaMat,nucleus,45)}
 // 02. The small workshop inside the nucleus.
 const nucleolus=makePart(1,[-.57,.47,.1]);const no=sphere(.255,material("#ac5c7b",{roughness:.75}),nucleolus,null,32);no.scale.set(1,.96,.9);
 const noDetail=material("#d38aa3");
 for(let i=0;i<17;i++){const a=rand()*6.283,b=Math.acos(rand()*2-1);sphere(.025,noDetail,nucleolus,[Math.sin(b)*Math.cos(a)*.246,Math.cos(b)*.246,Math.sin(b)*Math.sin(a)*.225],8)}
 // 03. Folded rough ER sheets wrap around the nucleus.
 const rough=makePart(2,[-.45,.32,-.32]),roughSamples=[];
 const roughColors=["#8cabb7","#94b0be","#a4bdc7","#91aab8","#adc4cd"],roughEdge=material("#7397a8");
 for(let l=0;l<5;l++){
  const fn=(u,v)=>{const a=1.65+u*3.65,r=1.03+l*.13+v*.115;return [Math.cos(a)*r,Math.sin(a)*r*.74,-.06+l*.075+Math.sin(a*3.2)*.065+Math.sin(v*Math.PI)*.05]};
  ribbon(fn,66,7,material(roughColors[l],{side:THREE.DoubleSide,roughness:.62}),rough);
  for(const edge of [0,1]){const pts=[];for(let j=0;j<=55;j++)pts.push(fn(j/55,edge));tube(pts,.022,roughEdge,rough,55)}
  for(let k=0;k<18;k++){const p=fn(.04+rand()*.92,rand());roughSamples.push([p[0]-.45,p[1]+.32,p[2]-.275])}
 }
 // 04. Smooth ER is an interconnected, ribosome-free tube network.
 const smooth=makePart(3,[1.05,.55,-.65]);const smat=material("#b0bf87",{roughness:.62});
 for(let k=0;k<10;k++){const x=(k%4)*.16-.25,y=Math.floor(k/4)*.16;const pts=[];for(let j=0;j<13;j++){const t=j/12;pts.push([x+Math.sin(t*7+k*.5)*.22,y+(t-.5)*.92,Math.cos(t*6+k)*.19])}tube(pts,.049,smat,smooth,45)}
 for(let k=0;k<4;k++)tube([[-.25,k*.14-.25,.1],[0,k*.14-.21,-.05],[.25,k*.14-.25,.05],[.43,k*.14-.18,-.02]],.046,smat,smooth,24);
 // 05. Both free ribosomes and ribosomes attached to rough ER.
 const ribs=makePart(4);const ribMat=material("#8d697e",{roughness:.8}),ribPositions=roughSamples.slice();
 for(let i=0;i<85;i++){let p;do{p=[(rand()-.5)*4.2,(rand()-.5)*3.7,(rand()-.5)*3.6]}while((p[0]*p[0]/5.1+p[1]*p[1]/3.9+p[2]*p[2]/4)>1||new THREE.Vector3(...p).distanceTo(new THREE.Vector3(-.45,.38,-.28))<1);ribPositions.push(p)}
 ribPositions.push([.4,-.25,.83]);
 const ribInst=new THREE.InstancedMesh(new THREE.SphereGeometry(.031,9,7),ribMat,ribPositions.length),dummy=new THREE.Object3D();
 ribPositions.forEach((p,i)=>{dummy.position.set(...p);dummy.scale.setScalar(.8+rand()*.45);dummy.updateMatrix();ribInst.setMatrixAt(i,dummy.matrix)});ribs.add(ribInst);
 // 06. Stacks of curved Golgi sacs with small budding packages.
 const golgi=makePart(5,[.95,-.95,-.2]);golgi.rotation.z=-.23;
 const gcolors=["#a98bb4","#b394bf","#be9fc6","#c7aad0","#cdb3d4","#d7c1de"],golgiEdge=material("#ad8bb9");
 for(let k=0;k<6;k++){const width=1.1-k*.065;
  const fn=(u,v)=>{const x=(u-.5)*width;return [x,k*.105+.19*Math.pow((u-.5)*2,2),Math.sin(u*Math.PI)*.06+(v-.5)*(.27+k*.015)]};
  ribbon(fn,45,8,material(gcolors[k],{side:THREE.DoubleSide,roughness:.6}),golgi);
  for(const v of [0,1]){const pts=[];for(let j=0;j<=35;j++)pts.push(fn(j/35,v));tube(pts,.025,golgiEdge,golgi,35)}
 }
 const budMat=material("#b69bc2");
 for(let k=0;k<7;k++)sphere(.05+rand()*.025,budMat,golgi,[(k%2===0?-1:1)*(.58+rand()*.18),rand()*.65,.03+rand()*.25],16);
 // 07. Mitochondria, each with a folded inner membrane.
 const mitos=makePart(6),mitoShell=material("#e5a262",{transparent:true,opacity:.83,roughness:.42,depthWrite:false}),cristaMat=material("#b9763e",{roughness:.65}),mitoEdge=material("#d08a49");
 const mitoSpots=[[1.52,1.12,.48,-.63],[-1.52,-.94,.48,.65],[.06,-1.7,-.55,-.18],[-.66,1.65,-.75,.28]];
 mitoSpots.forEach((a,k)=>{const g=new THREE.Group();g.position.set(a[0],a[1],a[2]);g.rotation.set(k*.2,.15*(k-1),a[3]);mitos.add(g);
  const geo=new THREE.SphereGeometry(.52,32,22),pa=geo.attributes.position;
  for(let i=0;i<pa.count;i++){const x=pa.getX(i),y=pa.getY(i),z=pa.getZ(i);pa.setXYZ(i,x,y*.48+.06*Math.cos(x*5),z*.44)}geo.computeVertexNormals();const shell=mesh(geo,mitoShell,g);shell.renderOrder=2;
  for(let j=0;j<7;j++){const x=-.35+j*.113,pts=[];for(let q=0;q<10;q++){const t=q/9,lim=.165*Math.sqrt(Math.max(.1,1-(x/.5)*(x/.5)));pts.push([x+Math.sin(t*6.283)*.033,(t-.5)*2*lim+.035,Math.sin(t*Math.PI)*.052+.123])}tube(pts,.022,cristaMat,g,22)}
  const edge=[];for(let j=0;j<=64;j++){const t=j/64*Math.PI*2;edge.push([Math.cos(t)*.49,Math.sin(t)*.21+.02,.035])}tube(edge,.019,mitoEdge,g,64);
 });
 // 08. Enzyme-filled recycling sacs.
 const lysos=makePart(7),lysoMat=material("#c8b45e",{transparent:true,opacity:.83,roughness:.55}),enzymeMat=material("#a49246");
 [[1.6,-.15,.83],[-1.66,.74,-.7],[.65,1.69,-.16],[.67,-1.5,.69]].forEach((p,k)=>{const g=new THREE.Group();g.position.set(...p);lysos.add(g);sphere(.15+(k%2)*.025,lysoMat,g);for(let j=0;j<9;j++){const a=rand()*6.283,r=rand()*.09;sphere(.022,enzymeMat,g,[Math.cos(a)*r,Math.sin(a)*r,(rand()-.5)*.15],8)}});
 // 09. Vesicles are membrane bubbles.
 const vesicles=makePart(8),vesMat=material("#83b6ad",{transparent:true,opacity:.55,roughness:.18,metalness:.02,side:THREE.DoubleSide,depthWrite:false}),vesInner=material("#c0dfcc",{transparent:true,opacity:.25,depthWrite:false}),vesSpot=material("#e4f3df",{transparent:true,opacity:.85});
 [[1.7,-1.05,.22],[1.7,-.65,.1],[-1.5,1.1,.72],[-1.98,-.2,.52],[.85,1.65,.7],[1.97,.35,-.45],[-.72,-1.66,.72]].forEach((p,k)=>{const r=.095+(k%3)*.035,v=sphere(r,vesMat,vesicles,p,24);sphere(r*.67,vesInner,v);sphere(r*.2,vesSpot,v,[-r*.3,r*.4,r*.7],10)});
 // 10. A pair of perpendicular, ninefold centrioles.
 const centrioles=makePart(9,[.6,.03,.92]),rodmat=material("#bf8b64",{roughness:.56}),rodlight=material("#dfb088",{roughness:.6});
 function centriole(pos,direction){const g=new THREE.Group();g.position.set(...pos);g.quaternion.setFromUnitVectors(new THREE.Vector3(0,1,0),new THREE.Vector3(...direction).normalize());centrioles.add(g);
  for(let k=0;k<9;k++){const a=k/9*Math.PI*2;for(let j=0;j<3;j++){const rod=mesh(new THREE.CylinderGeometry(.021,.021,.52,8),j===1?rodlight:rodmat,g);rod.position.set(Math.cos(a)*(.11+j*.021),0,Math.sin(a)*(.11+j*.021))}}
  for(const y of [-.24,.24]){const ring=mesh(new THREE.TorusGeometry(.13,.017,6,24),rodmat,g);ring.rotation.x=Math.PI/2;ring.position.y=y}
 }
 centriole([-.12,.04,0],[.95,.25,.05]);centriole([.15,-.06,.04],[.12,.96,.3]);
 // 11. Cytoskeletal fibers connect the cell's interior.
 const skeleton=makePart(10),fiberMat=material("#7ca58c",{transparent:true,opacity:.43,roughness:.8,depthWrite:false}),crossMat=material("#a8b590",{transparent:true,opacity:.4,depthWrite:false});
 for(let k=0;k<23;k++){const a=k/23*Math.PI*2,z=-.65+(k%5)*.3,p0=[Math.cos(a)*2.35,Math.sin(a)*2.1,z],p1=[Math.cos(a+.16)*1.7,Math.sin(a+.16)*1.55,z-.18],p2=[Math.cos(a-.1)*1.24,Math.sin(a-.1)*1.05,z+.12],p3=[.3+Math.cos(a)*.37,-.03+Math.sin(a)*.36,z];tube([p0,p1,p2,p3],k%3===0?.015:.009,fiberMat,skeleton,35)}
 for(let k=0;k<7;k++){const a=k/7*Math.PI*2,pts=[];for(let j=0;j<20;j++){const t=j/19;pts.push([Math.cos(a+t*1.3)*2.1,Math.sin(a+t*1.3)*1.85,-1.1+t*2.1])}tube(pts,.011,crossMat,skeleton,35)}
 registerParts();groups.forEach(g=>{g.visible=false;g.scale.setScalar(.001)});
 ready=true;$("loading").classList.add("hidden");
 function resize(){const w=viewport.clientWidth,h=viewport.clientHeight;renderer.setSize(w,h);camera.aspect=w/h;camera.updateProjectionMatrix()}
 new ResizeObserver(resize).observe(viewport);resize();
 const raycaster=new THREE.Raycaster(),pointer=new THREE.Vector2(),activePointers=new Set();
 viewport.addEventListener("pointerdown",e=>{activePointers.add(e.pointerId);pointerCount=activePointers.size;gestureMoved=pointerCount>1;down={x:e.clientX,y:e.clientY,time:performance.now()};fly=null},{passive:true});
 viewport.addEventListener("pointermove",e=>{if(down&&Math.hypot(e.clientX-down.x,e.clientY-down.y)>7)gestureMoved=true},{passive:true});
 function endPointer(e){
  const wasMulti=pointerCount>1;activePointers.delete(e.pointerId);pointerCount=activePointers.size;
  if(!down||gestureMoved||wasMulti||e.type==="pointercancel"){if(pointerCount===0)down=null;return}
  if(performance.now()-down.time>700){down=null;return}
  const rect=viewport.getBoundingClientRect();pointer.set((e.clientX-rect.left)/rect.width*2-1,-(e.clientY-rect.top)/rect.height*2+1);raycaster.setFromCamera(pointer,camera);
  const hits=raycaster.intersectObjects(pickables,false);let found=null;
  for(const hit of hits){const i=hit.object.userData.part;if(!groups[i].visible||progress<i+.15)continue;if(cut&&cutPlane.distanceToPoint(hit.point)<0)continue;found=i;break}
  if(found!==null){setPlaying(false);activate(found,true)}else if(progress>=11){activate(-1);resetView()}down=null;
 }
 viewport.addEventListener("pointerup",endPointer,{passive:true});viewport.addEventListener("pointercancel",endPointer,{passive:true});
 viewport.addEventListener("pointerleave",()=>{if(activePointers.size===0)down=null},{passive:true});
 renderer.domElement.addEventListener("webglcontextlost",e=>{e.preventDefault();fail("The graphics connection was interrupted. Reload this page to rebuild the cell.")});
 if(demo)startDemo();
 let previous=performance.now();const projected=new THREE.Vector3(),worldAnchor=new THREE.Vector3();
 function animate(now){
  requestAnimationFrame(animate);const dt=Math.min((now-previous)/1000,.05);previous=now;clockTime+=dt;
  if(!help.hidden){renderer.render(scene,camera);return}
  if(demo)runDemo(clockTime-demoStart);
  else if(playing){if(waitTime>0)waitTime-=dt;else if(progress<11){setProgress(progress+dt/1.7);if(progress>=11)setPlaying(false)}}
  groups.forEach((g,i)=>{const growth=Math.max(0,Math.min(1,(progress-i)/.72));g.visible=growth>.001;const eased=growth*growth*(3-2*growth),pulse=reduced?0:Math.sin(clockTime*.9+i*.8)*.009;g.scale.setScalar(Math.max(.001,eased*(1+pulse)));g.position.copy(g.userData.base);if(!reduced){g.position.y+=Math.sin(clockTime*.65+i*.7)*.025;g.position.x+=Math.sin(clockTime*.45+i)*.012}});
  if(!reduced){dust.rotation.y=Math.sin(clockTime*.055)*.025;frontShell.scale.setScalar(1+Math.sin(clockTime*.7)*.003)}
  if(fly){fly.elapsed+=dt;const q=Math.min(1,fly.elapsed/fly.duration),e=q*q*(3-2*q);camera.position.lerpVectors(fly.from,fly.to,e);controls.target.lerpVectors(fly.startTarget,fly.endTarget,e);if(q>=1)fly=null}
  controls.update();
  if(selected>=0&&groups[selected].visible&&progress>selected+.23){
   worldAnchor.set(...parts[selected].anchor);if(!reduced)worldAnchor.y+=Math.sin(clockTime*.65+selected*.7)*.025;if(cut&&worldAnchor.z>.1)worldAnchor.z=.08;
   projected.copy(worldAnchor).project(camera);const w=viewport.clientWidth,h=viewport.clientHeight;let x=(projected.x*.5+.5)*w,y=(-projected.y*.5+.5)*h;
   const show=projected.z<1&&projected.z>-1&&x>12&&x<w-15&&y>80&&y<h-75,label=$("selectionLabel");label.classList.toggle("visible",show);
   x=Math.min(w-(w<500?137:171),Math.max(30,x));y=Math.max(100,Math.min(h-92,y));label.style.left=x+"px";label.style.top=y+"px";
  }else $("selectionLabel").classList.remove("visible");
  renderer.render(scene,camera);
 }
 requestAnimationFrame(animate);
}catch(err){console.error("Cell model could not initialize:",err);fail("Check your internet connection and make sure WebGL is available in your browser.")}
</script>
</body>
</html>