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.)65.1 KB · 811 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, viewport-fit=cover">
  <meta name="theme-color" content="#f5f6ef">
  <title>Tiny Worlds — Life, piece by piece</title>
  <style>
    :root{--paper:#f5f6ef;--ink:#243e34;--muted:#7a877a;--line:#dde3d6;--green:#315c46;--accent:#c08057;--part-color:#7aa998}
    *{box-sizing:border-box}
    html{scroll-behavior:smooth}
    body{margin:0;color:var(--ink);background:var(--paper);font-family:Inter,"Segoe UI",Arial,sans-serif;-webkit-font-smoothing:antialiased}
    button,input{-webkit-tap-highlight-color:transparent}
    button{font:inherit;color:inherit;cursor:pointer;touch-action:manipulation}
    button:focus-visible,input:focus-visible{outline:3px solid #739a78;outline-offset:4px}
    button:disabled{cursor:default;opacity:.45}
    button svg{flex:none}
    button{border:0}
    svg{display:block}
    [hidden]{display:none!important}
    .app{height:100svh;min-height:780px;display:flex;flex-direction:column;overflow:hidden}
    .topbar{height:82px;flex:none;margin:0 38px;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line)}
    .brand{display:flex;align-items:center;gap:11px}
    .brand-symbol{width:38px;height:38px}
    .wordmark{font-size:23px;letter-spacing:-1.1px;font-weight:750}
    .brand-divider{height:24px;width:1px;background:var(--line);margin:0 10px}
    .brand-note,.header-index{font-size:9px;letter-spacing:1.6px;font-weight:600;line-height:1.7;color:var(--muted)}
    .header-right{display:flex;align-items:center;gap:24px}
    .edition{display:flex;align-items:center;gap:8px;border:1px solid #d9e1d1;border-radius:30px;padding:9px 14px;font-size:10px;letter-spacing:.9px;font-weight:600;background:#eef1e6}
    .edition-dot{width:6px;height:6px;border-radius:50%;background:#73996d}
    .demo-tag{font-size:9px;font-weight:700;letter-spacing:.7px;color:#8b603d;background:#f0e5d3;border-radius:20px;padding:9px 13px}
    .workspace{width:calc(100% - 76px);max-width:1560px;margin:0 auto;flex:1;min-height:0;display:grid;grid-template-columns:260px minmax(0,1fr) 216px;grid-template-rows:minmax(0,1fr) 108px;gap:22px 24px;padding-top:26px}
    .left-column{display:flex;flex-direction:column;justify-content:space-between;min-height:0;padding:10px 0 0}
    .eyebrow{display:flex;align-items:center;gap:8px;font-size:9px;font-weight:700;letter-spacing:1.7px;color:#7a8b72}
    .eyebrow:before{content:"";width:19px;height:1px;background:#8ba47c}
    h1{font-family:Georgia,"Times New Roman",serif;font-size:61px;line-height:1.025;font-weight:400;letter-spacing:-3.7px;margin:21px 0 18px}
    h1 em{font-weight:400;color:#7a9478}
    .intro{font-size:13px;line-height:1.8;color:#788275;max-width:235px;margin:0}
    .intro-count{display:flex;align-items:center;gap:9px;margin:21px 0 0;font-size:10px;color:#6f8067}
    .tiny-spark{color:#91a078;font-size:17px}
    .detail-card{border:1px solid #e0e5d9;border-radius:19px;background:rgba(255,255,252,.88);padding:20px;box-shadow:0 6px 23px #3d523a04;margin-top:20px;position:relative;transition:border-color .4s}
    .card-heading{display:flex;align-items:center;justify-content:space-between;margin-bottom:18px}
    .micro-label{font-size:8px;font-weight:700;letter-spacing:1.8px;color:#89917e}
    .part-number{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:10px;color:#8e9988}
    .part-art{width:49px;height:49px;border-radius:14px;background:color-mix(in srgb,var(--part-color) 11%,#fffef9);color:var(--part-color);display:flex;align-items:center;justify-content:center;margin-bottom:14px}
    .part-art svg{width:35px;height:35px}
    .part-name{font-family:Georgia,"Times New Roman",serif;font-size:24px;line-height:1.12;font-weight:400;letter-spacing:-.7px;margin:0 0 10px}
    .part-description{font-size:12px;line-height:1.8;color:#74806e;min-height:64px;margin:0}
    .part-category{display:inline-block;font-size:7px;font-weight:700;letter-spacing:1.1px;color:var(--part-color);margin-top:13px}
    .closer-button{background:transparent;border-top:1px solid #e8ebdf;width:100%;min-height:43px;display:flex;align-items:center;justify-content:space-between;font-size:10px;font-weight:600;margin-top:15px;padding:12px 0 0}
    .closer-button svg{color:#89977d}
    .left-note{font-size:9px;line-height:1.7;color:#9aa18e;display:flex;gap:7px;align-items:center;margin:15px 0 0}
    .scene{position:relative;isolation:isolate;min-width:0;min-height:0;border-radius:30px;background:radial-gradient(ellipse at 51% 48%,#e3eddd90 0%,#edf1e555 40%,transparent 71%)}
    .scene:before{position:absolute;inset:24px 0 30px;content:"";background-image:radial-gradient(#8b9b7d36 .7px,transparent .7px);background-size:25px 25px;mask-image:radial-gradient(ellipse at center,#0009,transparent 75%);pointer-events:none;z-index:-1}
    #viewport{position:absolute;inset:0}
    #viewport canvas{display:block;width:100%;height:100%;touch-action:none;outline:none}
    .scene-title{position:absolute;top:13px;left:0;right:0;text-align:center;font-size:8px;font-weight:600;letter-spacing:2px;color:#9aa38c;pointer-events:none}
    .scene-marker{position:absolute;top:50%;font-size:18px;font-weight:200;color:#afbaa1;pointer-events:none;opacity:.6}
    .scene-marker.left{left:10px}.scene-marker.right{right:10px}
    .view-chip{position:absolute;top:43px;left:50%;transform:translateX(-50%);background:#e9efe1e6;border:1px solid #d9e2d1;border-radius:20px;padding:7px 11px;font-size:8px;letter-spacing:1px;font-weight:600;color:#648367;pointer-events:none;white-space:nowrap;transition:opacity .3s;opacity:0}
    .view-chip.visible{opacity:1}
    .hotspot{position:absolute;z-index:3;display:flex;align-items:center;gap:7px;white-space:nowrap;padding:9px 13px;border:1px solid #dce3d4;border-radius:8px;background:#fffff4ef;box-shadow:0 5px 20px #314c3910;font-size:10px;font-weight:600;transform:translate(-50%,-100%);transition:opacity .25s;max-width:95%;pointer-events:auto;backdrop-filter:blur(8px)}
    .hotspot-dot{width:6px;height:6px;background:var(--part-color);border-radius:50%}
    .hotspot:after{content:"";position:absolute;width:1px;height:23px;background:#708b6c80;left:50%;top:100%}
    .hotspot:before{content:"";position:absolute;width:5px;height:5px;border:2px solid #fffff4;border-radius:50%;background:var(--part-color);left:calc(50% - 4px);top:calc(100% + 21px);box-shadow:0 0 0 1px #91a38460}
    .scene-hints{position:absolute;bottom:13px;left:0;right:0;display:flex;justify-content:center;gap:16px;pointer-events:none;color:#8b9681}
    .hint{display:flex;align-items:center;gap:5px;font-size:9px;white-space:nowrap}
    .hint svg{width:13px;height:13px;opacity:.8}
    .hint.mobile-hint{display:none}
    .scene-home,.parts-toggle{position:absolute;bottom:47px;min-height:37px;border:1px solid #dfe5d6;border-radius:9px;background:#f8f9f1df;display:flex;gap:6px;align-items:center;padding:0 10px;font-size:9px;color:#78896e;backdrop-filter:blur(8px);z-index:4}
    .scene-home{right:9px}.parts-toggle{left:9px;display:none}
    .scene-home:hover,.parts-toggle:hover{background:#fffef6}
    .scene-scale{position:absolute;left:11px;bottom:53px;font-family:ui-monospace,Consolas,monospace;font-size:7px;letter-spacing:1.1px;color:#9eaa93;line-height:1.7;pointer-events:none}
    .toast{position:absolute;bottom:94px;left:50%;transform:translate(-50%,8px);padding:11px 16px;background:#315b46;color:#f5f9ed;border-radius:12px;font-size:10px;line-height:1.6;text-align:center;box-shadow:0 8px 28px #294c3820;opacity:0;transition:opacity .3s,transform .3s;pointer-events:none;z-index:8;max-width:90%;width:max-content}
    .toast.show{opacity:1;transform:translate(-50%,0)}
    .loading{position:absolute;inset:25px 0 55px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;font-size:12px;line-height:1.8;color:#819075;text-align:center;z-index:9;background:radial-gradient(ellipse,#f0f3e8e8,transparent 72%);padding:30px}
    .loading-orbit{width:52px;height:52px;border:1px solid #c8d7bc;border-top-color:#5f876b;border-radius:45% 55% 50% 50%;animation:spin 2.5s linear infinite}
    @keyframes spin{to{transform:rotate(360deg)}}
    .parts-panel{align-self:center;background:#edf0e5b3;border:1px solid #e0e5d6;border-radius:18px;padding:20px 14px 16px}
    .panel-top{padding:0 4px;display:flex;align-items:center;justify-content:space-between}
    .panel-title{font-size:15px;font-weight:500;letter-spacing:-.4px;margin:8px 0 15px}
    .counter{font-size:9px;font-family:ui-monospace,Consolas,monospace;color:#849175;border:1px solid #d7dfcc;border-radius:6px;padding:5px 7px}
    .parts-list{list-style:none;padding:0;margin:0}
    .part-row{display:grid;grid-template-columns:12px minmax(0,1fr) 15px;align-items:center;gap:8px;width:100%;min-height:35px;padding:7px 9px;text-align:left;border:1px solid transparent;background:transparent;border-radius:8px;color:#9aa28f;transition:background .25s,color .25s,border-color .25s}
    .part-row:hover{background:#ffffff68}
    .part-row.is-built{color:#64765d}
    .part-row.is-active{background:#fffff8;border-color:#dce3d2;color:#304f3b;box-shadow:0 2px 7px #4a613e04}
    .row-dot{width:7px;height:7px;border-radius:50%;border:1px solid var(--row-color);opacity:.55}
    .is-built .row-dot{background:var(--row-color);opacity:1}
    .row-name{font-size:10.5px;line-height:1.3}
    .row-check{font-size:7px;font-family:ui-monospace,Consolas,monospace;opacity:.6;text-align:right}
    .row-check svg{width:11px;height:11px;color:#7c9b68}
    .panel-footer{display:flex;align-items:center;gap:10px;border-top:1px solid #dfe4d4;padding:15px 5px 0;margin-top:14px;font-size:9px;line-height:1.8;color:#8a987b}
    .panel-footer svg{color:#96a980;flex:none}
    .panel-close{display:none;width:40px;height:40px;align-items:center;justify-content:center;background:transparent;border-radius:50%}
    .panel-backdrop{display:none}
    .transport{grid-column:1/-1;display:grid;grid-template-columns:186px minmax(160px,1fr) 172px;align-items:center;gap:30px;padding:18px 23px;border:1px solid #dfe4d6;border-radius:18px;background:#fcfcf6c9;box-shadow:0 4px 20px #45603c03}
    .transport-actions{display:flex;align-items:center;gap:17px}
    .play-button{width:45px;height:45px;flex:none;background:var(--green);color:#f6f8eb;display:flex;align-items:center;justify-content:center;border-radius:50%;box-shadow:0 3px 8px #2c513319;transition:background .2s,transform .2s}
    .play-button:hover{background:#426e52}.play-button:active{transform:scale(.94)}
    .rebuild-button{display:flex;align-items:center;gap:7px;background:transparent;font-size:11px;font-weight:500;min-height:44px;padding:0}
    .rebuild-button svg{color:#87947a}
    .timeline-head{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:3px}
    .timeline-label{font-size:8px;letter-spacing:1.4px;font-weight:700;color:#758268;white-space:nowrap}
    .build-stage{font-size:9px;color:#8b977f;text-align:right;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
    .track{position:relative;height:30px}
    .build-range{-webkit-appearance:none;appearance:none;width:100%;height:30px;margin:0;background:transparent;cursor:pointer;position:relative;z-index:2;touch-action:pan-y}
    .build-range::-webkit-slider-runnable-track{height:4px;border-radius:9px;background:linear-gradient(to right,#6d8b60 0%,#6d8b60 var(--progress,0%),#e1e6d8 var(--progress,0%),#e1e6d8 100%)}
    .build-range::-moz-range-track{height:4px;border-radius:9px;background:#e1e6d8}
    .build-range::-moz-range-progress{height:4px;border-radius:9px;background:#6d8b60}
    .build-range::-webkit-slider-thumb{-webkit-appearance:none;width:15px;height:15px;border-radius:50%;background:#66845b;border:3px solid #fdfdf5;margin-top:-5.5px;box-shadow:0 0 0 1px #8fa57e;cursor:grab}
    .build-range::-moz-range-thumb{width:10px;height:10px;border-radius:50%;background:#66845b;border:3px solid #fdfdf5;box-shadow:0 0 0 1px #8fa57e}
    .range-ticks{position:absolute;display:flex;justify-content:space-between;left:7px;right:7px;top:14px;pointer-events:none;z-index:3}
    .range-ticks i{width:2px;height:2px;background:#fcfdf3b3;border-radius:50%}
    .timeline-ends{display:flex;justify-content:space-between;font-size:8px;color:#9ba58e}
    .cut-control{border-left:1px solid #e3e8da;padding-left:27px;display:flex;align-items:center;justify-content:flex-end}
    .cut-button{display:flex;align-items:center;gap:11px;min-height:45px;padding:0;background:transparent}
    .cut-copy{text-align:left;font-size:11px;font-weight:500;white-space:nowrap}
    .cut-copy small{display:block;color:#9ba68f;font-size:8px;font-weight:400;margin-top:4px}
    .switch{display:block;flex:none;width:39px;height:23px;border-radius:20px;background:#dce3d2;padding:3px;transition:background .3s}
    .switch:after{display:block;content:"";width:17px;height:17px;background:#fffef7;border-radius:50%;box-shadow:0 1px 3px #38513619;transition:transform .3s}
    .cut-button.on .switch{background:#68865b}.cut-button.on .switch:after{transform:translateX(16px)}
    .page-footer{width:calc(100% - 76px);max-width:1560px;flex:none;margin:0 auto;min-height:39px;display:flex;justify-content:space-between;align-items:center;color:#a2aa98;font-size:8px;letter-spacing:.2px}
    .footer-right{display:flex;align-items:center;gap:6px}
    .footer-right svg{color:#a9b69a}
    .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}
    @media(min-width:1500px){.workspace{grid-template-columns:285px minmax(0,1fr) 230px;gap:26px 34px}h1{font-size:69px}.intro{font-size:14px}.detail-card{padding:23px}.part-description{font-size:13px}.part-row{min-height:38px}.row-name{font-size:11.5px}}
    @media(max-height:820px) and (min-width:1051px){.topbar{height:70px}.workspace{padding-top:16px;gap:17px 24px}.left-column{padding-top:6px}h1{font-size:53px;margin:16px 0 14px}.intro{font-size:12px;line-height:1.7}.intro-count{margin-top:13px}.detail-card{margin-top:16px;padding:17px}.card-heading{margin-bottom:12px}.part-art{width:42px;height:42px;margin-bottom:10px}.part-name{font-size:23px}.part-description{font-size:11px;min-height:56px}.part-category{margin-top:8px}.closer-button{margin-top:10px;min-height:37px}.left-note{margin-top:10px}.parts-panel{padding-top:16px}.part-row{min-height:33px}.panel-footer{margin-top:10px;padding-top:12px}}
    @media(max-width:1200px) and (min-width:1051px){.workspace{width:calc(100% - 52px);grid-template-columns:230px minmax(0,1fr) 194px;gap:20px 17px}.topbar{margin:0 26px}.page-footer{width:calc(100% - 52px)}h1{font-size:54px}.parts-panel{padding-left:9px;padding-right:9px}.row-name{font-size:10px}.scene-hints{gap:10px}.hint{font-size:8px}.scene-scale{display:none}}
    @media(max-width:1050px){.workspace{grid-template-columns:250px minmax(0,1fr);gap:22px}.parts-toggle{display:flex}.scene-scale{display:none}.parts-panel{display:none;position:fixed;z-index:30;right:20px;top:50%;transform:translateY(-50%);width:265px;max-height:calc(100svh - 40px);overflow:auto;background:#f3f5eafb;box-shadow:0 20px 80px #2137282b;padding:18px}.parts-panel.open{display:block}.panel-close{display:flex}.panel-top{align-items:flex-start}.panel-title{font-size:19px}.part-row{min-height:40px}.row-name{font-size:12px}.panel-backdrop.open{display:block;position:fixed;inset:0;z-index:29;background:#233e333f;backdrop-filter:blur(4px)}.transport{grid-template-columns:168px minmax(140px,1fr) 150px;gap:20px;padding:17px 20px}.cut-control{padding-left:20px}.header-index{display:none}.brand-note{font-size:8px}.scene-home,.parts-toggle{font-size:9px}}
    @media(max-width:700px){.app{height:auto;min-height:100svh;overflow:visible}.topbar{height:65px;margin:0 20px}.brand-symbol{width:30px;height:30px}.brand{gap:8px}.wordmark{font-size:21px}.brand-divider,.brand-note{display:none}.header-right{gap:7px}.edition{font-size:8px;padding:8px 10px;letter-spacing:.6px}.demo-tag{font-size:7px;padding:8px}.workspace{width:calc(100% - 32px);padding-top:22px;grid-template-columns:1fr;grid-template-rows:auto 330px auto auto;gap:14px}.left-column{display:contents}.hero{grid-row:1}.eyebrow{font-size:8px;letter-spacing:1.4px}h1{font-size:43px;letter-spacing:-2.5px;margin:13px 0 10px;line-height:1.06}h1 br{display:none}.intro{font-size:12px;line-height:1.7;max-width:340px}.intro-count{display:none}.scene{grid-column:1;grid-row:2;min-height:330px;margin-top:-2px}.scene-title{top:10px;font-size:7px;letter-spacing:1.5px}.view-chip{top:31px;font-size:7px;padding:5px 9px}.scene-marker{font-size:14px}.hotspot{font-size:9px;padding:8px 11px}.scene-hints{bottom:7px;gap:10px}.hint{display:none}.hint.mobile-hint{display:flex;font-size:9px;gap:8px}.scene-home,.parts-toggle{bottom:35px;min-height:34px;font-size:8px;background:#f9faf1e8}.scene-home{right:4px}.parts-toggle{left:4px}.toast{bottom:79px;font-size:9px}.transport{grid-row:3;grid-column:1;grid-template-columns:1fr auto;grid-template-areas:"actions cut" "timeline timeline";gap:7px 16px;padding:12px 16px;border-radius:16px}.transport-actions{grid-area:actions;gap:14px}.play-button{width:40px;height:40px}.rebuild-button{font-size:11px;min-height:40px}.timeline{grid-area:timeline}.timeline-head{margin:2px 0 0}.timeline-label{font-size:7px}.build-stage{font-size:8px}.timeline-ends{display:none}.track,.build-range{height:28px}.range-ticks{top:13px}.cut-control{grid-area:cut;padding-left:15px}.cut-copy{font-size:10px}.cut-copy small{font-size:7px}.cut-button{min-height:40px;gap:9px}.switch{width:35px;height:21px;padding:3px}.switch:after{width:15px;height:15px}.cut-button.on .switch:after{transform:translateX(14px)}.detail-card{grid-row:4;grid-column:1;margin:0;padding:17px 18px;border-radius:16px}.card-heading{margin-bottom:13px}.micro-label{font-size:7px}.detail-body{display:grid;grid-template-columns:43px 1fr;gap:13px;align-items:start}.part-art{width:43px;height:43px;margin:0;border-radius:12px}.part-art svg{width:31px;height:31px}.part-name{font-size:23px;margin:0 0 7px}.part-description{font-size:12px;line-height:1.65;min-height:0}.part-category{margin-top:9px;font-size:6px;letter-spacing:1px}.closer-button{margin-top:12px;padding-top:9px;min-height:35px;font-size:10px}.left-note{display:none}.page-footer{width:calc(100% - 40px);min-height:48px;font-size:7px}.footer-right{font-size:7px}.parts-panel{right:12px;left:12px;top:auto;bottom:12px;transform:none;width:auto;max-height:calc(100svh - 40px);border-radius:22px;padding:19px 22px}.parts-panel .parts-list{display:grid;grid-template-columns:1fr 1fr;gap:5px 9px}.part-row{min-height:44px;padding:8px;gap:6px;grid-template-columns:9px minmax(0,1fr) 11px}.row-name{font-size:11px}.panel-title{margin-bottom:18px}.panel-footer{padding-top:13px}.loading{font-size:11px}}
    @media(max-width:380px){h1{font-size:38px}.workspace{grid-template-rows:auto 300px auto auto}.scene{min-height:300px}.edition{font-size:7px;padding:7px}.demo-tag{display:none!important}.part-name{font-size:21px}.footer-right{display:none}.parts-panel .parts-list{gap:3px}.row-name{font-size:10px}}
    @media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important}html{scroll-behavior:auto}}
  </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>
  <div class="app">
    <header class="topbar">
      <div class="brand">
        <svg class="brand-symbol" viewBox="0 0 40 40" fill="none" aria-hidden="true"><path d="M33.8 15.4c3.6 9.4-2.4 18.4-12.5 19.4C10.1 36 4 30.9 4.8 20.4 5.7 9 13.9 3 23.3 6.1c5.4 1.8 8.7 4.3 10.5 9.3Z" stroke="#698b67" stroke-width="1.4"/><path d="M29 16.5c2.8 7-1.1 14.2-9 14.2-7.9 0-11.9-5.4-9.8-12.3 2.5-8.5 14.7-10.6 18.8-1.9Z" stroke="#a9ba93" stroke-width="1"/><circle cx="20" cy="20" r="5.1" fill="#78956c"/><circle cx="21.5" cy="18.8" r="1.6" fill="#eaf0dc"/><circle cx="28.5" cy="23" r="1.4" fill="#a2b38a"/><circle cx="13" cy="13.5" r="1.1" fill="#a2b38a"/></svg>
        <span class="wordmark">tiny worlds</span><span class="brand-divider"></span><span class="brand-note">A LITTLE SPACE<br>FOR BIG CURIOSITY</span>
      </div>
      <div class="header-right">
        <span id="demoTag" class="demo-tag" hidden>DEMO · TOUCH TO EXPLORE</span>
        <span class="header-index">FIELD TRIP 001<br>THE WORLD WITHIN</span>
        <span class="edition"><span class="edition-dot"></span> THE ANIMAL CELL</span>
      </div>
    </header>

    <main class="workspace">
      <aside class="left-column">
        <div class="hero">
          <div class="eyebrow">SMALL SCALE. ENDLESS WONDER.</div>
          <h1>Life, piece<br> <em>by piece.</em></h1>
          <p class="intro">Meet the tiny team that keeps a cell alive. Watch it grow, then get a little closer.</p>
          <div class="intro-count"><span class="tiny-spark">✳</span> 11 little parts. One extraordinary world.</div>
        </div>
        <section id="detailCard" class="detail-card" aria-label="About the selected cell part" aria-live="polite">
          <div class="card-heading"><span class="micro-label">IN THE SPOTLIGHT</span><span id="partNumber" class="part-number">00 / 11</span></div>
          <div class="detail-body">
            <div id="partArt" class="part-art" aria-hidden="true"></div>
            <div>
              <h2 id="partName" class="part-name">Cell membrane</h2>
              <p id="partDescription" class="part-description">The cell membrane controls what enters and leaves the cell.</p>
              <div id="partCategory" class="part-category">THE FLEXIBLE BOUNDARY</div>
            </div>
          </div>
          <button id="closerButton" class="closer-button" type="button"><span>Take a closer look</span><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><path d="M5 12h14m-6-6 6 6-6 6"/></svg></button>
        </section>
        <p class="left-note"><svg width="12" height="14" viewBox="0 0 20 22" fill="none" stroke="currentColor" stroke-width="1.2" aria-hidden="true"><path d="M7 3h6M8 3v6l-5 9q-1 2 2 2h10q3 0 2-2l-5-9V3M6 14h8"/></svg> A real cell is smaller than a grain of sand.</p>
      </aside>

      <section id="scene" class="scene" aria-label="Interactive three-dimensional animal cell">
        <div class="scene-title">A WHOLE WORLD, RIGHT INSIDE YOU</div>
        <div class="scene-marker left" aria-hidden="true">+</div><div class="scene-marker right" aria-hidden="true">+</div>
        <div id="viewport"></div>
        <div id="cutawayChip" class="view-chip">MEMBRANE CUTAWAY</div>
        <button id="hotspot" class="hotspot" type="button" style="opacity:0"><span class="hotspot-dot"></span><span id="hotspotText">Cell membrane</span></button>
        <div id="loading" class="loading" role="status"><div class="loading-orbit"></div><span id="loadingMessage">A tiny world is waking up…</span></div>
        <div id="toast" class="toast" role="status"></div>
        <div class="scene-scale">ANIMAL CELL<br>NOT TO SCALE</div>
        <button id="partsToggle" class="parts-toggle" type="button" aria-expanded="false" aria-controls="partsPanel"><svg width="13" height="13" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.3" aria-hidden="true"><circle cx="4" cy="5" r="1"/><circle cx="4" cy="10" r="1"/><circle cx="4" cy="15" r="1"/><path d="M8 5h8M8 10h8M8 15h8"/></svg><span id="partsToggleText">Explore 11 parts</span></button>
        <button id="homeButton" class="scene-home" type="button" aria-label="Return to the whole-cell view"><svg width="12" height="12" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.3" aria-hidden="true"><path d="M7 3H3v4m10-4h4v4M3 13v4h4m10-4v4h-4M3 3l5 5m9-5-5 5M3 17l5-5m9 5-5-5"/></svg>Reset view</button>
        <div class="scene-hints" aria-hidden="true">
          <span class="hint"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.2"><path d="M7 11V5a1.2 1.2 0 0 1 2.4 0v5-1a1.2 1.2 0 0 1 2.4 0v1a1.2 1.2 0 0 1 2.4 0v1a1.2 1.2 0 0 1 2.4 0v3c0 3-2 4-5 4-2 0-3-1-4-3l-2-3c-1-2 1-3 2-1Z"/></svg>Drag to orbit</span>
          <span class="hint"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.2"><rect x="5.5" y="2" width="9" height="16" rx="4.5"/><path d="M10 5v4"/></svg>Scroll to zoom</span>
          <span class="hint"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.2"><circle cx="10" cy="10" r="6"/><circle cx="10" cy="10" r="2"/><path d="M10 1v2m0 14v2M1 10h2m14 0h2"/></svg>Tap to discover</span>
          <span class="hint mobile-hint">Drag to orbit <span>·</span> Pinch to zoom <span>·</span> Tap a part</span>
        </div>
      </section>

      <div id="panelBackdrop" class="panel-backdrop"></div>
      <aside id="partsPanel" class="parts-panel" aria-label="Cell parts checklist">
        <div class="panel-top"><div><span class="micro-label">THE CELL CHECKLIST</span><h2 class="panel-title">Meet the team.</h2></div><button id="panelClose" class="panel-close" type="button" aria-label="Close the parts list"><svg width="17" height="17" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><path d="m5 5 10 10M15 5 5 15"/></svg></button><span id="counter" class="counter">0 / 11</span></div>
        <ol id="partsList" class="parts-list"></ol>
        <div class="panel-footer"><svg width="24" height="27" viewBox="0 0 30 32" fill="none" stroke="currentColor" stroke-width="1.1" aria-hidden="true"><path d="M15 29V10m0 11C5 22 3 15 4 10c7-1 12 3 11 11Zm0-6c0-8 4-12 12-12 1 7-3 12-12 12Z"/><path d="m8 14 7 7m6-12-6 6"/></svg><span>Different jobs.<br>One beautiful team.</span></div>
      </aside>

      <section class="transport" aria-label="Build and viewing controls">
        <div class="transport-actions">
          <button id="playButton" class="play-button" type="button" aria-label="Pause the build"><svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><rect x="5" y="4" width="3" height="12" rx="1"/><rect x="12" y="4" width="3" height="12" rx="1"/></svg></button>
          <button id="rebuildButton" class="rebuild-button" type="button"><svg width="15" height="15" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.35" aria-hidden="true"><path d="M4 7a6.5 6.5 0 1 1-.1 5M4 3v4h4"/></svg>Rebuild</button>
        </div>
        <div class="timeline">
          <div class="timeline-head"><label for="buildRange" class="timeline-label">PIECE BY PIECE</label><span id="buildStage" class="build-stage">Just the membrane</span></div>
          <div class="track"><input id="buildRange" class="build-range" type="range" min="0" max="11" step="0.01" value="0" aria-label="Scrub the cell build, from empty to complete"><div class="range-ticks" aria-hidden="true"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></div></div>
          <div class="timeline-ends"><span>A little beginning</span><span>A living little world</span></div>
        </div>
        <div class="cut-control"><button id="cutButton" class="cut-button" role="switch" aria-checked="false" type="button"><span class="cut-copy">Cut open<small>A peek inside</small></span><span class="switch" aria-hidden="true"></span></button></div>
      </section>
    </main>
    <footer class="page-footer"><span>Wonder starts with a closer look.</span><span class="footer-right"><svg width="10" height="10" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1" aria-hidden="true"><path d="M7 1v12M1 7h12M3 3l8 8M3 11l8-8"/></svg> Built for curious minds.</span></footer>
    <div id="buildAnnouncement" class="sr-only" aria-live="polite"></div>
  </div>
  <script>
    window.__cellReady=false;
    window.setTimeout(function(){
      if(!window.__cellReady){
        var message=document.getElementById('loadingMessage');
        if(message)message.textContent='The 3D lab could not load. Please check your internet connection and reload this page.';
      }
    },14000);
  </script>
  <script type="module">
    import * as THREE from 'three';
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

    function startLab(){
      const $=id=>document.getElementById(id);
      const reduced=window.matchMedia('(prefers-reduced-motion: reduce)').matches;
      const N=11;
      const icons={
        membrane:'<path d="M40 18c5 12-2 23-15 24C10 44 4 35 7 22 10 8 21 4 32 10c4 2 6 5 8 8Z"/><path d="M35 20c4 9-1 17-11 17S10 31 12 22c3-9 15-13 23-2Z" opacity=".5"/>',
        nucleus:'<circle cx="24" cy="24" r="17"/><circle cx="24" cy="24" r="12" opacity=".4"/><circle cx="27" cy="23" r="5" fill="currentColor" stroke="none"/><path d="m15 17 3 1m-3 12 3-2m12 4 2-2"/>',
        nucleolus:'<circle cx="24" cy="24" r="17" opacity=".3"/><circle cx="24" cy="24" r="9" fill="currentColor" stroke="none"/><circle cx="21" cy="21" r="2" fill="#fff" stroke="none" opacity=".5"/>',
        rough:'<path d="M8 15c9-9 14 9 31-2M7 23c9-9 15 9 32-2M8 31c9-9 14 9 29-2M11 39c9-8 14 6 24-2"/><g fill="currentColor" stroke="none"><circle cx="12" cy="9" r="1.5"/><circle cx="24" cy="18" r="1.5"/><circle cx="35" cy="25" r="1.5"/><circle cx="16" cy="28" r="1.5"/><circle cx="29" cy="40" r="1.5"/></g>',
        smooth:'<path d="M8 14c13-10 18 12 31-2M7 26c12-11 20 13 33-1M11 38c13-11 18 8 26-3M14 12c-3 12 8 10 5 21M30 16c7 11-4 12 1 20"/>',
        ribosomes:'<g fill="currentColor" stroke="none"><circle cx="13" cy="13" r="4"/><circle cx="32" cy="11" r="3"/><circle cx="23" cy="25" r="4.5"/><circle cx="11" cy="34" r="3"/><circle cx="35" cy="33" r="4"/><circle cx="25" cy="39" r="2"/><circle cx="39" cy="21" r="2"/></g>',
        golgi:'<path d="M10 9c7 8 21 8 28 0M8 17c8 9 24 9 32 0M9 25c7 9 23 9 30 0M12 33c6 7 18 7 24 0"/><circle cx="7" cy="35" r="2"/><circle cx="40" cy="31" r="2"/><circle cx="24" cy="43" r="2"/>',
        mito:'<path d="M9 32C-1 19 23 3 35 9c17 9 0 34-15 31-5-1-8-4-11-8Z"/><path d="M12 28c3-9 5 6 9-4s6 5 8-4 8-1 6-6"/>',
        lyso:'<circle cx="24" cy="24" r="17"/><g fill="currentColor" stroke="none"><circle cx="18" cy="20" r="3"/><circle cx="29" cy="17" r="2"/><circle cx="27" cy="29" r="3"/><circle cx="15" cy="30" r="1.5"/></g>',
        vesicles:'<circle cx="21" cy="25" r="14"/><circle cx="34" cy="12" r="6"/><path d="M12 25a9 9 0 0 1 9-9" opacity=".45"/>',
        centrioles:'<path d="m9 10 12-4 6 18-12 4-6-18Zm2 0 6 17m-1-19 6 17m7 5 4-12 10 4-4 12-10-4Zm2-2 9 3m-7-8 9 3"/><path d="m15 28 11-4M9 10l12-4"/>',
        skeleton:'<path d="m7 12 32 26M9 37 37 9M5 25l38-5M19 5l11 38M9 13l10 24 19-18M8 36l18-26 13 27"/><g fill="currentColor" stroke="none"><circle cx="19" cy="23" r="2"/><circle cx="29" cy="30" r="2"/><circle cx="27" cy="19" r="2"/></g>'
      };
      const parts=[
        {name:'Nucleus',short:'Nucleus',icon:'nucleus',color:'#9a82bd',category:'THE INSTRUCTION LIBRARY',description:'The nucleus stores the DNA instructions that tell the cell what to do.',focus:5.7},
        {name:'Nucleolus',short:'Nucleolus',icon:'nucleolus',color:'#975b9b',category:'THE RIBOSOME WORKSHOP',description:'The nucleolus makes the pieces that join together to form ribosomes.',focus:4.4},
        {name:'Rough endoplasmic reticulum',short:'Rough ER',icon:'rough',color:'#929ccc',category:'THE PROTEIN ASSEMBLY LINE',description:'The rough ER helps fold and move proteins made by the ribosomes on its surface.',focus:6.7},
        {name:'Smooth endoplasmic reticulum',short:'Smooth ER',icon:'smooth',color:'#6fa8a9',category:'THE CHEMISTRY CORNER',description:'The smooth ER makes fats and helps break down harmful chemicals.',focus:5.0},
        {name:'Ribosomes',short:'Ribosomes',icon:'ribosomes',color:'#b77b99',category:'THE TINY BUILDERS',description:'Ribosomes follow DNA messages to build the proteins the cell needs.',focus:4.8},
        {name:'Golgi apparatus',short:'Golgi apparatus',icon:'golgi',color:'#d18b66',category:'THE PACKING & SHIPPING CENTER',description:'The Golgi apparatus sorts and packages proteins and fats for delivery.',focus:4.9},
        {name:'Mitochondria',short:'Mitochondria',icon:'mito',color:'#c99b4e',category:'THE ENERGY CONVERTERS',description:'Mitochondria turn energy from food into a form the cell can use.',focus:4.7},
        {name:'Lysosomes',short:'Lysosomes',icon:'lyso',color:'#98a85d',category:'THE RECYCLING CREW',description:'Lysosomes break down waste and worn-out cell parts so their materials can be reused.',focus:4.4},
        {name:'Vesicles',short:'Vesicles',icon:'vesicles',color:'#76b2b7',category:'THE LITTLE DELIVERY BUBBLES',description:'Vesicles carry materials around the cell in tiny membrane bubbles.',focus:4.4},
        {name:'Centrioles',short:'Centrioles',icon:'centrioles',color:'#c1a254',category:'THE DIVISION ORGANIZERS',description:'Centrioles help organize the fibers that separate chromosomes when the cell divides.',focus:4.5},
        {name:'Cytoskeleton',short:'Cytoskeleton',icon:'skeleton',color:'#78a58b',category:'THE INNER FRAMEWORK',description:'The cytoskeleton supports the cell’s shape and helps move things inside it.',focus:10.8}
      ];
      const membrane={name:'Cell membrane',short:'Cell membrane',icon:'membrane',color:'#7aa998',category:'THE FLEXIBLE BOUNDARY',description:'The cell membrane controls what enters and leaves the cell.',focus:11.3};
      let randomState=20704;
      function random(){randomState=(Math.imul(randomState,1664525)+1013904223)>>>0;return randomState/4294967296}
      const V=(x=0,y=0,z=0)=>new THREE.Vector3(x,y,z);
      const clamp=THREE.MathUtils.clamp;
      const smooth=x=>x*x*(3-2*x);
      const host=$('viewport');
      const scene=new THREE.Scene();
      const renderer=new THREE.WebGLRenderer({antialias:true,alpha:true,powerPreference:'high-performance'});
      renderer.setPixelRatio(Math.min(window.devicePixelRatio||1,2));
      renderer.setClearColor(0x000000,0);
      renderer.outputColorSpace=THREE.SRGBColorSpace;
      renderer.toneMapping=THREE.ACESFilmicToneMapping;
      renderer.toneMappingExposure=1.12;
      renderer.localClippingEnabled=true;
      host.appendChild(renderer.domElement);
      renderer.domElement.setAttribute('aria-label','Animal cell model: drag to rotate, pinch or scroll to zoom, and tap a cell part.');
      renderer.domElement.setAttribute('role','img');
      const camera=new THREE.PerspectiveCamera(39,1,.1,80);
      const homeDirection=V(5.1,2.8,10.3).normalize();
      camera.position.copy(homeDirection).multiplyScalar(11.3);
      const controls=new OrbitControls(camera,renderer.domElement);
      controls.enableDamping=true;controls.dampingFactor=.065;controls.enablePan=false;
      controls.rotateSpeed=.6;controls.zoomSpeed=.75;controls.minDistance=3;controls.maxDistance=20;
      controls.minPolarAngle=.14;controls.maxPolarAngle=Math.PI-.14;controls.autoRotateSpeed=.75;
      scene.add(new THREE.HemisphereLight(0xfffef5,0x8aa58d,2.1));
      const key=new THREE.DirectionalLight(0xfffcf1,3.1);key.position.set(-4,7,8);scene.add(key);
      const fill=new THREE.DirectionalLight(0xffe3ca,1.3);fill.position.set(6,-1,5);scene.add(fill);
      const rim=new THREE.DirectionalLight(0xc4e4cf,2.2);rim.position.set(-5,2,-6);scene.add(rim);
      const root=new THREE.Group();scene.add(root);
      const pickMeshes=[];
      const cutPlane=new THREE.Plane(V(0,0,-1),3.6);
      let cut=false,cutAmount=0,progress=0,stage=-1,playing=true,hold=1.35,selectedId='membrane';
      let flight=null,wholeView=true,toastTimer=0,lastTime=0,completedOnce=false;
      let demo=window.location.hash.toLowerCase()==='#demo',demoStart=performance.now(),demoPhase='',lastDemoT=-1;
      const records=parts.map((part,index)=>{
        const group=new THREE.Group();root.add(group);
        return Object.assign(part,{id:index,group,anchor:V(),base:V(),baseRotation:new THREE.Euler(),materials:new Set(),seed:index*1.71,reveal:0});
      });
      membrane.group=new THREE.Group();root.add(membrane.group);
      membrane.anchor=V(-2.15,1.25,1.05);membrane.materials=new Set();
      const record=id=>id==='membrane'?membrane:records[id];
      function material(color,options={}){return new THREE.MeshStandardMaterial(Object.assign({color,roughness:.43,metalness:.015},options))}
      function mesh(id,geometry,mat,parent){
        const m=new THREE.Mesh(geometry,mat);m.userData.part=id;
        (parent||record(id).group).add(m);record(id).materials.add(mat);pickMeshes.push(m);return m;
      }
      function sphere(id,r,mat,parent,position,scale){
        const m=mesh(id,new THREE.SphereGeometry(r,28,20),mat,parent);
        if(position)m.position.copy(position);if(scale)m.scale.copy(scale);return m;
      }
      function tube(id,points,r,mat,parent,segments=48,closed=false){
        const curve=new THREE.CatmullRomCurve3(points,closed);
        return mesh(id,new THREE.TubeGeometry(curve,segments,r,8,closed),mat,parent);
      }
      function place(id,position,anchor=V()){
        const r=records[id];r.base.copy(position);r.group.position.copy(position);r.anchor.copy(anchor);return r.group;
      }
      function shapePoint(x,y,z){
        const f=1+.036*Math.sin(x*1.3+y*.8)*Math.sin(z*1.2)+.018*Math.cos(y*2.2+z);
        return V(x*1.13*f,y*.96*f,z*.95*f);
      }

      // A softly irregular, translucent membrane, synthesized from a sphere.
      const shellGeometry=new THREE.SphereGeometry(3.05,112,72);
      const positions=shellGeometry.attributes.position;
      for(let i=0;i<positions.count;i++){
        const p=shapePoint(positions.getX(i),positions.getY(i),positions.getZ(i));
        positions.setXYZ(i,p.x,p.y,p.z);
      }
      shellGeometry.computeVertexNormals();
      const shellMaterial=new THREE.ShaderMaterial({
        transparent:true,depthWrite:false,side:THREE.FrontSide,clipping:true,
        clippingPlanes:[cutPlane],uniforms:{uTime:{value:0}},
        vertexShader:[
          '#include <clipping_planes_pars_vertex>',
          'varying vec3 vN; varying vec3 vEye; varying vec3 vLocal;',
          'void main(){',
          'vec4 mvPosition=modelViewMatrix*vec4(position,1.0);',
          'vN=normalize(normalMatrix*normal);vEye=-mvPosition.xyz;vLocal=position;',
          'gl_Position=projectionMatrix*mvPosition;',
          '#include <clipping_planes_vertex>',
          '}'
        ].join('\n'),
        fragmentShader:[
          '#include <clipping_planes_pars_fragment>',
          'varying vec3 vN; varying vec3 vEye; varying vec3 vLocal; uniform float uTime;',
          'void main(){',
          '#include <clipping_planes_fragment>',
          'vec3 n=normalize(vN);float f=pow(1.0-abs(dot(n,normalize(vEye))),2.3);',
          'float glint=pow(max(dot(n,normalize(vec3(-0.6,0.9,1.0))),0.0),28.0);',
          'float cloud=sin(vLocal.x*3.0+uTime*0.15)*sin(vLocal.y*2.5-vLocal.z*2.0)*0.5+0.5;',
          'vec3 col=mix(vec3(0.48,0.70,0.56),vec3(0.88,0.95,0.78),f*0.55+glint*0.4);',
          'gl_FragColor=vec4(col,0.025+f*0.53+glint*0.17+cloud*0.012);',
          '#include <tonemapping_fragment>',
          '#include <colorspace_fragment>',
          '}'
        ].join('\n')
      });
      const shell=mesh('membrane',shellGeometry,shellMaterial);shell.renderOrder=8;
      const gelMaterial=material('#c3ddbb',{transparent:true,opacity:.075,side:THREE.BackSide,depthWrite:false,clippingPlanes:[cutPlane],roughness:.7});
      const gel=mesh('membrane',shellGeometry,gelMaterial);gel.scale.setScalar(.993);gel.renderOrder=0;
      const poreMaterial=material('#9abc9b',{transparent:true,opacity:.44,depthWrite:false,clippingPlanes:[cutPlane]});
      for(let i=0;i<50;i++){
        const z=random()*2-1,a=random()*Math.PI*2,k=Math.sqrt(1-z*z);
        const p=shapePoint(3.05*k*Math.cos(a),3.05*z,3.05*k*Math.sin(a));
        sphere('membrane',.022+random()*.016,poreMaterial,null,p);
      }
      const cutRimPoints=[];
      for(let i=0;i<128;i++){const a=i/128*Math.PI*2;cutRimPoints.push(shapePoint(3.05*Math.cos(a),3.05*Math.sin(a),0))}
      const edgeMaterial=new THREE.MeshBasicMaterial({color:'#9bbb87',transparent:true,opacity:0,depthWrite:false});
      const cutRim=new THREE.Mesh(new THREE.TubeGeometry(new THREE.CatmullRomCurve3(cutRimPoints,true),128,.025,8,true),edgeMaterial);
      root.add(cutRim);cutRim.visible=false;
      const edgeShape=new THREE.Shape(cutRimPoints.map(p=>new THREE.Vector2(p.x,p.y)));
      const cutFace=new THREE.Mesh(new THREE.ShapeGeometry(edgeShape),new THREE.MeshBasicMaterial({color:'#cee2b8',side:THREE.DoubleSide,transparent:true,opacity:0,depthWrite:false}));
      root.add(cutFace);cutFace.visible=false;

      // Nucleus, with a porous envelope and a separately discoverable nucleolus.
      place(0,V(-.62,.35,-.15),V(.05,.2,.8));
      const nucleusMat=new THREE.MeshPhysicalMaterial({color:'#a493cf',roughness:.3,metalness:.02,transparent:true,opacity:.59,depthWrite:false,clearcoat:.8,clearcoatRoughness:.3,side:THREE.DoubleSide});
      const nucleus=sphere(0,1.04,nucleusMat,null,null,V(1.08,1,.97));nucleus.renderOrder=4;
      const innerMat=material('#c1aedc',{transparent:true,opacity:.11,depthWrite:false,side:THREE.BackSide});
      sphere(0,.98,innerMat,null,null,V(1.08,1,.97));
      const nuclearPoreMat=material('#e0d7ec',{roughness:.6});
      for(let i=0;i<33;i++){
        const z=1-2*(i+.5)/33,a=i*2.399963,rr=Math.sqrt(1-z*z);
        const normal=V(rr*Math.cos(a),z,rr*Math.sin(a));
        const pore=mesh(0,new THREE.TorusGeometry(.047,.012,5,12),nuclearPoreMat);
        pore.position.copy(normal).multiplyScalar(1.05);pore.position.x*=1.08;pore.position.z*=.97;
        pore.quaternion.setFromUnitVectors(V(0,0,1),normal);
      }
      place(1,V(-.49,.41,.34));
      const nucleolusMat=material('#8b579e',{roughness:.36,emissive:'#6c397e',emissiveIntensity:.12});
      sphere(1,.36,nucleolusMat,null,null,V(1.05,.97,1));
      const nucleolusSpeck=material('#ad7bb7',{roughness:.6});
      for(let i=0;i<12;i++){const a=random()*Math.PI*2,z=random()*2-1,rr=Math.sqrt(1-z*z);sphere(1,.025+random()*.014,nucleolusSpeck,null,V(rr*Math.cos(a),z,rr*Math.sin(a)).multiplyScalar(.357))}

      // Rough ER: folded ribbons curving around the nuclear envelope.
      place(2,V(-.63,.34,-.36),V(-1.2,.65,.05));
      const roughMat=material('#919dcc',{roughness:.47,side:THREE.DoubleSide});
      const roughEdge=material('#c0c7e3',{roughness:.55});
      const attachedRibosome=material('#76658e',{roughness:.7});
      for(let j=0;j<6;j++){
        const points=[];
        for(let k=0;k<=54;k++){
          const a=.4+k/54*4.5;
          const r=1.21+j*.13+.045*Math.sin(a*5+j);
          points.push(V(Math.cos(a)*r,Math.sin(a)*r*.79,(j-2.5)*.12+.11*Math.sin(a*3)));
        }
        const fold=tube(2,points,.12,roughMat);fold.scale.z=.62;
        const rimPoints=points.map(p=>V(p.x,p.y,p.z*.62+.063));
        tube(2,rimPoints,.017,roughEdge,null,54);
        for(let k=5;k<52;k+=5){
          const p=rimPoints[k].clone();p.z+=.035;
          sphere(2,.036,attachedRibosome,null,p);
        }
      }

      // Smooth ER: a branching tubular network.
      place(3,V(1.25,1.2,-.62),V(.05,.12,.05));
      const smoothMat=material('#7eb6b5',{roughness:.38});
      for(let j=0;j<5;j++){
        const points=[];
        for(let k=0;k<15;k++){const u=k/14;points.push(V((u-.5)*1.55,(j-2)*.22+Math.sin(u*6+j*.45)*.11,Math.sin(u*4+j)*.22))}
        tube(3,points,.065,smoothMat,null,40);
      }
      for(let j=0;j<5;j++){
        const x=(j-2)*.29;const points=[];
        for(let k=0;k<12;k++){const u=k/11;points.push(V(x+Math.sin(u*5+j)*.1,(u-.5)*1.15,Math.sin(u*4+j)*.22))}
        tube(3,points,.06,smoothMat,null,30);
      }
      records[3].baseRotation.z=-.38;records[3].baseRotation.y=-.25;

      // Free ribosomes: many little protein builders, rather than one large object.
      place(4,V(),V(-1.55,-1.2,1.02));
      const riboMat=material('#ad799f',{roughness:.65});
      let accepted=0;
      while(accepted<74){
        const p=V((random()-.5)*5.1,(random()-.5)*4.6,(random()-.5)*4.4);
        if(p.length()>2.75||p.distanceTo(V(-.6,.35,-.15))<1.28)continue;
        const g=new THREE.Group();records[4].group.add(g);g.position.copy(p);
        sphere(4,.037+random()*.018,riboMat,g);
        sphere(4,.027,riboMat,g,V(.025,.028,.01));
        accepted++;
      }
      for(let i=0;i<9;i++)sphere(4,.046,riboMat,null,V(-1.55+(random()-.5)*.55,-1.2+(random()-.5)*.4,1.02+(random()-.5)*.3));

      // Golgi: a gently curved stack of flattened membrane sacs.
      place(5,V(1.32,-.8,.77),V(0,.1,.08));
      const golgiMat=material('#dc9976',{roughness:.39});
      const golgiLip=material('#edbd92',{roughness:.44});
      for(let j=0;j<6;j++){
        const points=[],width=1.35-Math.abs(j-2)*.095;
        for(let k=0;k<=30;k++){
          const t=k/30;
          points.push(V((t-.5)*width,(j-2.5)*.17+.19*Math.sin(t*Math.PI),.11*Math.sin(t*Math.PI*2+j*.4)));
        }
        const sac=tube(5,points,.105,golgiMat,null,40);sac.scale.z=.64;
        tube(5,points.map(p=>V(p.x,p.y+.035,p.z*.64+.067)),.023,golgiLip,null,35);
      }
      for(let j=0;j<8;j++)sphere(5,.055+random()*.025,golgiMat,null,V((j%2?1:-1)*(.72+random()*.15),(random()-.5)*.95,random()*.3));
      records[5].baseRotation.z=-.34;records[5].baseRotation.y=-.2;

      // Mitochondria, with folded inner membranes visible on their faces.
      place(6,V(),V(1.9,.95,.72));
      const mitoOuter=material('#d69a50',{roughness:.37});
      const mitoInner=material('#edbf70',{roughness:.42});
      const mitoFold=material('#ad703e',{roughness:.46});
      const mitoPositions=[[1.9,.95,.72,-.55,.95],[-2.05,-1.05,.42,.75,.88],[.65,-1.99,-.47,-.1,.87],[-1.66,1.69,-.9,-.65,.69],[1.97,-.32,-1.18,.9,.75]];
      mitoPositions.forEach(item=>{
        const g=new THREE.Group();records[6].group.add(g);g.position.set(item[0],item[1],item[2]);g.rotation.set(.12,-.16,item[3]);g.scale.setScalar(item[4]);
        const geo=new THREE.SphereGeometry(.47,36,24),attr=geo.attributes.position;
        for(let i=0;i<attr.count;i++){
          let x=attr.getX(i)*1.55,y=attr.getY(i)*.7,z=attr.getZ(i)*.72;
          y+=.15*(1-x*x/.55);attr.setXYZ(i,x,y,z);
        }
        geo.computeVertexNormals();mesh(6,geo,mitoOuter,g);
        sphere(6,.44,mitoInner,g,V(0,.07,.205),V(1.36,.49,.32));
        const ridge=[];
        for(let i=0;i<=80;i++){
          const u=i/80,x=(u-.5)*1.1;
          ridge.push(V(x,.075+Math.sin(u*Math.PI*10)*.125,Math.sqrt(Math.max(.05,1-x*x/.49))*.14+.24));
        }
        tube(6,ridge,.031,mitoFold,g,90);
      });

      // Lysosomes: enzyme-filled recycling bubbles.
      place(7,V(),V(-1.5,-.38,1.67));
      const lysoMat=material('#a7b565',{roughness:.36,transparent:true,opacity:.88});
      const enzymeMat=material('#7f9349',{roughness:.6});
      const lysosomePositions=[[-1.5,-.38,1.67,.23],[.14,1.91,.83,.19],[2.36,-.92,.23,.18],[-1.15,-1.73,-1.14,.22],[.42,-.22,-2.13,.17],[-2.36,.49,-.32,.17]];
      lysosomePositions.forEach(a=>{
        const g=new THREE.Group();records[7].group.add(g);g.position.set(a[0],a[1],a[2]);
        sphere(7,a[3],lysoMat,g);
        for(let i=0;i<6;i++){const angle=i*2.4;const r=a[3]*.51;sphere(7,.026+random()*.014,enzymeMat,g,V(Math.cos(angle)*r,Math.sin(angle)*r,a[3]*.65))}
      });

      // Vesicles: transparent cargo bubbles.
      place(8,V(),V(1.08,1.82,1.05));
      const vesMat=new THREE.MeshPhysicalMaterial({color:'#90c9cc',roughness:.15,metalness:.02,transparent:true,opacity:.42,depthWrite:false,clearcoat:1,side:THREE.DoubleSide});
      const cargoMat=material('#badbd0',{transparent:true,opacity:.7,roughness:.5});
      const vesPositions=[[1.08,1.82,1.05,.22],[1.69,1.64,.34,.13],[2.29,.12,1.11,.18],[-.45,-1.84,1.52,.18],[-2.01,.84,1.12,.15],[.9,-1.18,1.94,.13],[.45,2.36,-.18,.16]];
      vesPositions.forEach(a=>{
        const bubble=sphere(8,a[3],vesMat,null,V(a[0],a[1],a[2]));bubble.renderOrder=5;
        sphere(8,a[3]*.26,cargoMat,null,V(a[0]-.025,a[1]-.02,a[2]));
      });

      // A perpendicular pair of nine-fold microtubule barrels.
      place(9,V(-.28,-1.55,1.17),V(.14,.04,0));
      const centrioleMat=material('#d6b568',{roughness:.38});
      const centrioleDark=material('#b5974d',{roughness:.5});
      for(let pair=0;pair<2;pair++){
        const g=new THREE.Group();records[9].group.add(g);
        if(pair===0)g.rotation.z=-.4;
        else{g.position.set(.34,.05,-.06);g.rotation.set(Math.PI/2,0,.3)}
        for(let i=0;i<9;i++){
          const a=i/9*Math.PI*2;
          const rod=mesh(9,new THREE.CylinderGeometry(.034,.034,.63,10),centrioleMat,g);
          rod.position.set(Math.cos(a)*.123,0,Math.sin(a)*.123);
        }
        [-.3,.3].forEach(y=>{const ring=mesh(9,new THREE.TorusGeometry(.125,.018,6,25),centrioleDark,g);ring.rotation.x=Math.PI/2;ring.position.y=y});
      }

      // Cytoskeleton filaments arc through and around the cytoplasm.
      place(10,V(),V(-1.84,.58,1.74));
      const fiberMat=material('#8eb39a',{transparent:true,opacity:.55,roughness:.7,depthWrite:false});
      const fiberLight=material('#b2c6a1',{transparent:true,opacity:.48,roughness:.7,depthWrite:false});
      for(let j=0;j<8;j++){
        const points=[],q=new THREE.Quaternion().setFromEuler(new THREE.Euler(j*.43,j*.63,j*.22));
        for(let i=0;i<75;i++){
          const a=i/74*Math.PI*1.72+.16*j;
          const p=V(Math.cos(a)*2.68,Math.sin(a)*2.59,Math.sin(a*2+j)*.13).applyQuaternion(q);
          p.x*=1.11;points.push(p);
        }
        tube(10,points,.012,j%2?fiberMat:fiberLight,null,85);
      }
      for(let j=0;j<7;j++){
        const a=j*2.3999,p=V(Math.cos(a)*2.8,Math.sin(a)*2.48,Math.sin(a*.7)*.9);
        const end=V(-p.x*.9,-p.y*.85,-p.z+.2);
        tube(10,[p,p.clone().multiplyScalar(.5).add(V(0,.28,.55)),end.clone().multiplyScalar(.5).add(V(.1,0,.6)),end],.016,fiberMat,null,45);
      }

      // A quiet field of suspended cytoplasm particles and a soft ground shadow.
      const dustGeometry=new THREE.BufferGeometry(),dustVertices=[];
      for(let i=0;i<150;i++){
        let p;do{p=V((random()-.5)*5.8,(random()-.5)*5.2,(random()-.5)*5.1)}while(p.length()>2.73);
        dustVertices.push(p.x,p.y,p.z);
      }
      dustGeometry.setAttribute('position',new THREE.Float32BufferAttribute(dustVertices,3));
      const dustMaterial=new THREE.PointsMaterial({color:'#9db787',size:.027,transparent:true,opacity:0,depthWrite:false,clippingPlanes:[cutPlane]});
      const dust=new THREE.Points(dustGeometry,dustMaterial);root.add(dust);
      const shadowCanvas=document.createElement('canvas');shadowCanvas.width=128;shadowCanvas.height=128;
      const ctx=shadowCanvas.getContext('2d'),gradient=ctx.createRadialGradient(64,64,4,64,64,64);
      gradient.addColorStop(0,'rgba(90,111,70,0.19)');gradient.addColorStop(.5,'rgba(90,111,70,0.08)');gradient.addColorStop(1,'rgba(90,111,70,0)');
      ctx.fillStyle=gradient;ctx.fillRect(0,0,128,128);
      const shadow=new THREE.Mesh(new THREE.PlaneGeometry(8.6,6.4),new THREE.MeshBasicMaterial({map:new THREE.CanvasTexture(shadowCanvas),transparent:true,depthWrite:false,opacity:.65}));
      shadow.rotation.x=-Math.PI/2;shadow.position.set(0,-3.21,0);scene.add(shadow);

      const tickSVG='<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="m3 8 3 3 7-7"/></svg>';
      const playSVG='<svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path d="M6 3.5c0-.7.7-1 1.3-.6l9 6.3a1 1 0 0 1 0 1.6l-9 6.3c-.6.4-1.3.1-1.3-.6Z"/></svg>';
      const pauseSVG='<svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><rect x="5" y="4" width="3" height="12" rx="1"/><rect x="12" y="4" width="3" height="12" rx="1"/></svg>';
      const replaySVG='<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M5 9a7.5 7.5 0 1 1-.2 5M5 4v5h5"/></svg>';
      const rowButtons=records.map((r,i)=>{
        const li=document.createElement('li'),button=document.createElement('button');
        button.type='button';button.className='part-row';button.style.setProperty('--row-color',r.color);
        button.innerHTML='<span class="row-dot"></span><span class="row-name">'+r.short+'</span><span class="row-check">'+String(i+1).padStart(2,'0')+'</span>';
        button.setAttribute('aria-label','Build and explore '+r.name);
        button.addEventListener('click',()=>{
          endDemo();playing=false;
          if(progress<i+1)setProgress(i+1,false);
          selectPart(i,true);updatePlayback();setPanel(false);
        });
        li.appendChild(button);$('partsList').appendChild(li);return button;
      });
      function updateRows(){
        rowButtons.forEach((button,i)=>{
          button.classList.toggle('is-built',i<stage);button.classList.toggle('is-active',selectedId===i);
          button.setAttribute('aria-pressed',String(selectedId===i));
          button.querySelector('.row-check').innerHTML=i<stage?tickSVG:String(i+1).padStart(2,'0');
        });
        $('counter').textContent=stage+' / '+N;
        $('partsToggleText').textContent='Explore parts · '+stage+'/'+N;
      }
      function updatePlayback(){
        const active=playing||demo;
        $('playButton').innerHTML=active?pauseSVG:progress>=N?replaySVG:playSVG;
        $('playButton').setAttribute('aria-label',active?'Pause the build':progress>=N?'Play the build again':'Continue the build');
        $('demoTag').hidden=!demo;
      }
      function selectPart(id,fly=false){
        selectedId=id;
        const r=record(id);
        $('detailCard').style.setProperty('--part-color',r.color);
        $('hotspot').style.setProperty('--part-color',r.color);
        $('partName').textContent=r.name;$('partDescription').textContent=r.description;
        $('partNumber').textContent=(id==='membrane'?'00':String(id+1).padStart(2,'0'))+' / 11';
        $('partCategory').textContent=r.category;
        $('partArt').innerHTML='<svg viewBox="0 0 48 48" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">'+icons[r.icon]+'</svg>';
        $('hotspotText').textContent=r.short;
        $('closerButton').querySelector('span').textContent=id==='membrane'?'See the whole cell':'Take a closer look';
        updateRows();
        if(fly)focusPart(id);
      }
      function setProgress(value,autoSelect=true){
        progress=clamp(value,0,N);
        const nextStage=clamp(Math.ceil(progress-.0001),0,N);
        if(nextStage!==stage){
          stage=nextStage;
          if(autoSelect)selectPart(stage?stage-1:'membrane',false);
          updateRows();
          $('buildStage').textContent=stage===0?'Just the membrane':progress>=N?'Complete · explore away':String(stage).padStart(2,'0')+' / 11 · '+records[stage-1].short;
          $('buildAnnouncement').textContent=stage===0?'An empty cell membrane.':records[stage-1].name+' added. '+records[stage-1].description;
        }
        if(progress>=N)$('buildStage').textContent='Complete · explore away';
        $('buildRange').value=String(progress);
        $('buildRange').style.setProperty('--progress',(progress/N*100)+'%');
        $('buildRange').setAttribute('aria-valuetext',stage+' of 11 parts built');
      }
      function homePosition(){
        const aspect=host.clientWidth/Math.max(1,host.clientHeight);
        return homeDirection.clone().multiplyScalar(Math.max(10.9,10.3/Math.max(.6,aspect)));
      }
      function moveCamera(position,target,duration=1100){
        flight={from:camera.position.clone(),to:position.clone(),fromTarget:controls.target.clone(),toTarget:target.clone(),start:performance.now(),duration:reduced?150:duration};
      }
      function resetView(instant=false){
        wholeView=true;controls.autoRotate=false;
        if(instant){camera.position.copy(homePosition());controls.target.set(0,0,0);flight=null;controls.update()}
        else moveCamera(homePosition(),V());
      }
      function focusPart(id){
        if(id==='membrane'||id===10){resetView();return}
        const r=record(id);
        r.group.updateWorldMatrix(true,false);
        const target=r.group.localToWorld(r.anchor.clone());
        const direction=camera.position.clone().sub(controls.target).normalize();
        const distance=r.focus;
        moveCamera(target.clone().addScaledVector(direction,distance),target);
        wholeView=false;controls.autoRotate=false;
      }
      function setCut(value){
        cut=value;$('cutButton').classList.toggle('on',cut);$('cutButton').setAttribute('aria-checked',String(cut));
        $('cutawayChip').classList.toggle('visible',cut);
      }
      function notify(text){
        window.clearTimeout(toastTimer);$('toast').textContent=text;$('toast').classList.add('show');
        toastTimer=window.setTimeout(()=>$('toast').classList.remove('show'),3200);
      }
      function setPanel(open){
        $('partsPanel').classList.toggle('open',open);$('panelBackdrop').classList.toggle('open',open);
        $('partsToggle').setAttribute('aria-expanded',String(open));
        if(open)$('panelClose').focus();
      }
      function endDemo(){
        if(!demo)return;
        demo=false;playing=false;controls.autoRotate=false;updatePlayback();
        notify('Your turn. Follow your curiosity.');
      }
      function rebuild(){
        endDemo();setCut(false);playing=true;hold=1.35;completedOnce=false;
        setProgress(0);selectPart('membrane');resetView();updatePlayback();
      }
      $('playButton').addEventListener('click',()=>{
        const wasDemo=demo;endDemo();
        if(wasDemo){playing=false;updatePlayback();return}
        if(progress>=N){rebuild();return}
        playing=!playing;hold=Math.min(hold,.45);updatePlayback();
      });
      $('rebuildButton').addEventListener('click',rebuild);
      $('buildRange').addEventListener('input',event=>{
        endDemo();playing=false;hold=0;completedOnce=false;
        setProgress(Number(event.target.value));updatePlayback();
      });
      $('cutButton').addEventListener('click',()=>{endDemo();setCut(!cut)});
      $('homeButton').addEventListener('click',()=>{endDemo();resetView()});
      $('closerButton').addEventListener('click',()=>{endDemo();playing=false;focusPart(selectedId);updatePlayback()});
      $('hotspot').addEventListener('click',()=>{endDemo();playing=false;focusPart(selectedId);updatePlayback()});
      $('partsToggle').addEventListener('click',()=>setPanel(!$('partsPanel').classList.contains('open')));
      $('panelClose').addEventListener('click',()=>{setPanel(false);$('partsToggle').focus()});
      $('panelBackdrop').addEventListener('click',()=>setPanel(false));
      document.addEventListener('keydown',event=>{if(event.key==='Escape')setPanel(false)});
      window.addEventListener('pointerdown',event=>{if(event.isTrusted)endDemo()},{capture:true,passive:true});
      window.addEventListener('touchstart',event=>{if(event.isTrusted)endDemo()},{capture:true,passive:true});
      window.addEventListener('wheel',event=>{if(event.isTrusted)endDemo()},{passive:true});
      controls.addEventListener('start',()=>{flight=null;controls.autoRotate=false});
      const pointer=new THREE.Vector2(),raycaster=new THREE.Raycaster(),activePointers=new Set();
      let tapStart=null,multiTouch=false;
      renderer.domElement.addEventListener('pointerdown',event=>{
        activePointers.add(event.pointerId);
        if(activePointers.size===1){tapStart={x:event.clientX,y:event.clientY,time:performance.now()};multiTouch=false}
        else multiTouch=true;
      });
      renderer.domElement.addEventListener('pointerup',event=>{
        const canPick=activePointers.size===1&&!multiTouch&&tapStart&&Math.hypot(event.clientX-tapStart.x,event.clientY-tapStart.y)<8&&performance.now()-tapStart.time<650;
        activePointers.delete(event.pointerId);
        if(!canPick)return;
        const rect=renderer.domElement.getBoundingClientRect();
        pointer.set((event.clientX-rect.left)/rect.width*2-1,-(event.clientY-rect.top)/rect.height*2+1);
        raycaster.setFromCamera(pointer,camera);
        const intersections=raycaster.intersectObjects(pickMeshes,false);
        const actual=intersections.find(hit=>hit.object.userData.part!=='membrane'&&record(hit.object.userData.part).reveal>.4);
        let id=actual?actual.object.userData.part:null;
        if(id===null){
          let nearest=27;
          records.forEach(r=>{
            if(r.reveal<.5)return;
            const p=r.group.localToWorld(r.anchor.clone()).project(camera);
            const dx=(p.x*.5+.5)*rect.width-(event.clientX-rect.left),dy=(-p.y*.5+.5)*rect.height-(event.clientY-rect.top);
            const distance=Math.hypot(dx,dy);
            if(distance<nearest){nearest=distance;id=r.id}
          });
        }
        if(id===null&&intersections.some(hit=>hit.object.userData.part==='membrane'))id='membrane';
        if(id!==null){playing=false;selectPart(id,true);updatePlayback()}
      });
      renderer.domElement.addEventListener('pointercancel',event=>{activePointers.delete(event.pointerId);multiTouch=true});
      renderer.domElement.addEventListener('pointerleave',event=>{activePointers.delete(event.pointerId)});

      function resize(){
        const width=Math.max(1,host.clientWidth),height=Math.max(1,host.clientHeight);
        renderer.setSize(width,height,false);camera.aspect=width/height;camera.updateProjectionMatrix();
        if(wholeView&&!flight){
          const direction=camera.position.clone().sub(controls.target).normalize();
          camera.position.copy(controls.target).addScaledVector(direction,homePosition().length());
        }
      }
      new ResizeObserver(resize).observe(host);
      resize();resetView(true);setProgress(0);selectPart('membrane');updatePlayback();
      if(demo){playing=false;updatePlayback()}
      window.__cellReady=true;$('loading').hidden=true;

      function runDemo(now){
        const t=((now-demoStart)/1000)%20.5;
        if(t<lastDemoT)demoPhase='';
        lastDemoT=t;
        const phase=t<1?'empty':t<11.5?'build':t<14?'cut':t<17.4?'focus':'whole';
        if(phase!==demoPhase){
          demoPhase=phase;controls.autoRotate=false;
          if(phase==='empty'){setProgress(0);selectPart('membrane');setCut(false);resetView(true)}
          if(phase==='build'){setCut(false)}
          if(phase==='cut'){setProgress(11);selectPart('membrane');setCut(true);moveCamera(V(3.1,1.65,10.9),V())}
          if(phase==='focus'){selectPart(6,true)}
          if(phase==='whole'){setCut(false);selectPart('membrane');resetView()}
        }
        if(phase==='build')setProgress((t-1)/10.5*N);
        if(phase==='whole'&&!flight)controls.autoRotate=true;
      }
      function animate(now){
        requestAnimationFrame(animate);
        const dt=lastTime?Math.min((now-lastTime)/1000,.05):0;lastTime=now;
        const t=now/1000,motion=reduced?.08:1;
        if(demo)runDemo(now);
        else if(playing){
          if(hold>0)hold-=dt;
          else{
            setProgress(progress+dt/1.65);
            if(progress>=N){
              playing=false;updatePlayback();
              if(!completedOnce){notify('A whole little world! Tap any part to explore.');completedOnce=true}
            }
          }
        }
        records.forEach((r,i)=>{
          const reveal=clamp((progress-i)/.88,0,1);r.reveal=reveal;
          r.group.visible=reveal>.001;
          const pulse=1+Math.sin(t*.9+r.seed)*.009*motion;
          r.group.scale.setScalar(Math.max(.0001,smooth(reveal)*pulse));
          r.group.position.copy(r.base).add(V(Math.sin(t*.39+r.seed)*.025,Math.sin(t*.51+r.seed)*.035,Math.cos(t*.36+r.seed)*.023).multiplyScalar(motion));
          r.group.rotation.set(r.baseRotation.x+Math.sin(t*.24+r.seed)*.018*motion,r.baseRotation.y+Math.sin(t*.21+r.seed)*.028*motion,r.baseRotation.z+Math.sin(t*.28+r.seed)*.018*motion);
          r.materials.forEach(mat=>{
            if(mat.emissive){mat.emissive.set(r.color);mat.emissiveIntensity=selectedId===i?.095+Math.sin(t*1.5)*.025:.016}
          });
        });
        membrane.group.scale.setScalar(1+Math.sin(t*.7)*.006*motion);
        shellMaterial.uniforms.uTime.value=t;
        dustMaterial.opacity=progress/N*.32;dust.rotation.y=t*.012*motion;
        cutAmount+=((cut?1:0)-cutAmount)*Math.min(1,dt*5.5);
        if(Math.abs(cutAmount-(cut?1:0))<.001)cutAmount=cut?1:0;
        cutPlane.constant=3.6*(1-smooth(cutAmount));
        const crossScale=Math.sqrt(Math.max(0,1-Math.pow(cutPlane.constant/2.9,2)));
        cutRim.visible=cutFace.visible=crossScale>.025&&cutAmount>.01;
        cutRim.position.z=cutFace.position.z=cutPlane.constant;
        cutRim.scale.set(crossScale,crossScale,1);cutFace.scale.set(crossScale,crossScale,1);
        edgeMaterial.opacity=cutAmount*.68;cutFace.material.opacity=cutAmount*.035;
        if(flight){
          const a=clamp((now-flight.start)/flight.duration,0,1),e=a<.5?4*a*a*a:1-Math.pow(-2*a+2,3)/2;
          camera.position.lerpVectors(flight.from,flight.to,e);controls.target.lerpVectors(flight.fromTarget,flight.toTarget,e);
          if(a===1)flight=null;
        }
        controls.update();
        root.updateMatrixWorld(true);
        const selected=record(selectedId);
        const point=selected.group.localToWorld(selected.anchor.clone()).project(camera);
        const w=host.clientWidth,h=host.clientHeight;
        const x=clamp((point.x*.5+.5)*w,76,w-76),y=clamp((-point.y*.5+.5)*h-34,69,h-91);
        $('hotspot').style.left=x+'px';$('hotspot').style.top=y+'px';
        $('hotspot').style.opacity=point.z<1&&(selectedId==='membrane'||selected.reveal>.45)?'1':'0';
        $('hotspot').style.pointerEvents=point.z<1&&(selectedId==='membrane'||selected.reveal>.45)?'auto':'none';
        renderer.render(scene,camera);
      }
      requestAnimationFrame(animate);
    }
    try{startLab()}catch(error){
      console.error('The cell explorer could not start:',error);
      document.getElementById('loading').hidden=false;
      document.getElementById('loadingMessage').textContent='This tiny world needs WebGL. Please try a browser with 3D graphics enabled.';
    }
  </script>
</body>
</html>