Prompt specification
Build or customize the Three.js 3D scene "Genotype and phenotype specimen rack" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Genotype and phenotype specimen rack
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/genotype-and-phenotype-specimen-rack-x0881
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: genotype and phenotype specimen rack. Place three token-pair genotypes beneath fictional flowers with a stated dominance rule; show that different token pairs can share one visible phenotype.
Working Three.js Starter (genotype-and-phenotype-specimen-rack-x0881):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Token Trait Specimen Rack — dominance demo</title>
<style>
:root{
--cr:#d94452; /* crimson phenotype */
--vi:#8b5cf6; /* violet phenotype */
--dom:#f2b134; /* token T */
--rec:#58c7c0; /* token t */
--ink:#e8eefc;
--dim:#93a3c0;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:#0b111c;overflow:hidden;
font-family:ui-sans-serif,system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;color:var(--ink)}
#app{position:fixed;inset:0}
canvas{display:block}
.ui{position:fixed;inset:0;pointer-events:none;z-index:5}
.card{
position:absolute;pointer-events:auto;
background:linear-gradient(180deg,rgba(19,26,41,.92),rgba(12,17,28,.92));
border:1px solid rgba(120,145,190,.28);border-radius:14px;
box-shadow:0 18px 44px rgba(0,0,0,.45);
padding:14px 16px;backdrop-filter:blur(7px);
}
.kicker{font:600 10.5px/1 ui-monospace,monospace;letter-spacing:.18em;color:var(--dim);text-transform:uppercase}
h1{margin:6px 0 2px;font-size:19px;letter-spacing:.02em}
.sub{color:var(--dim);font-size:12px;line-height:1.45}
.title-card{top:18px;left:18px;max-width:330px}
.legend-card{bottom:18px;left:18px;max-width:330px}
.ctrl-card{bottom:18px;right:18px;max-width:250px}
.info-card{top:18px;right:18px;width:262px}
.row{display:flex;align-items:center;gap:9px;margin:8px 0}
.chip{width:22px;height:22px;border-radius:50%;display:grid;place-items:center;
font:800 12px/1 ui-monospace,monospace;color:#131a28;box-shadow:0 2px 6px rgba(0,0,0,.45)}
.sw{width:16px;height:16px;border-radius:4px;box-shadow:0 0 0 1px rgba(255,255,255,.18)}
.mono{font-family:ui-monospace,monospace}
.rule{margin:9px 0 2px;padding:9px 11px;border-left:3px solid var(--dom);
background:rgba(242,177,52,.08);border-radius:0 8px 8px 0;font-size:12.5px;line-height:1.5}
.note{font-size:12px;color:#b9c6e0;line-height:1.5}
.eq{color:#6ee7ff;font-weight:700}
.btnrow{display:flex;gap:6px;margin-top:10px}
button{flex:1;pointer-events:auto;background:rgba(110,231,255,.08);color:var(--ink);
border:1px solid rgba(110,231,255,.35);border-radius:9px;padding:7px 8px;cursor:pointer;
font:600 11.5px/1 ui-sans-serif,system-ui;letter-spacing:.06em;text-transform:uppercase}
button:hover{background:rgba(110,231,255,.18)}
.hint{margin-top:9px;font-size:11px;color:var(--dim);line-height:1.5}
.big{font:700 15px/1.35 ui-monospace,monospace;letter-spacing:.06em}
@media(max-width:820px){
.title-card,.legend-card{max-width:250px;padding:11px 12px}
.info-card{width:210px}.ctrl-card{max-width:180px}
h1{font-size:15px}.sub,.note{font-size:11px}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="ui">
<div class="card title-card">
<div class="kicker">Fictional species · Florina tokenis</div>
<h1>Token Trait Specimen Rack</h1>
<div class="sub">Each pedestal holds one flower. Beneath every flower is its
<b>token-pair genotype</b>; the petals show the <b>visible phenotype</b>.</div>
</div>
<div class="card info-card" id="info"></div>
<div class="card legend-card">
<div class="kicker">Stated dominance rule</div>
<div class="rule"><b>Token T</b> <span class="eq">DOMINATES</span> token <b>t</b>.<br>
Any specimen carrying at least one <b>T</b> shows <b style="color:var(--cr)">crimson petals</b>;
only <span class="mono">t t</span> shows <b style="color:var(--vi)">violet petals</b>.</div>
<div class="row"><span class="chip" style="background:var(--dom)">T</span>
<span class="chip" style="background:var(--rec)">t</span>
<span class="sub">dominant / recessive token</span></div>
<div class="row"><span class="sw" style="background:var(--cr)"></span>
<span class="sub">crimson petals ← <span class="mono">T T</span> or <span class="mono">T t</span></span></div>
<div class="row"><span class="sw" style="background:var(--vi)"></span>
<span class="sub">violet petals ← <span class="mono">t t</span></span></div>
<div class="note" style="margin-top:8px;border-top:1px solid rgba(120,145,190,.2);padding-top:8px">
Specimens <b>A</b> and <b>B</b> carry <i>different token pairs</i> yet produce
<b>one visible phenotype</b> — dominance hides the recessive token in B.
</div>
</div>
<div class="card ctrl-card">
<div class="kicker">Controls</div>
<div class="btnrow">
<button id="prev">‹</button><button id="ov">Overview</button><button id="next">›</button>
</div>
<div class="hint">Drag to orbit · scroll to zoom · click a specimen to select
(keys: 1 2 3, ← →).</div>
</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ============================================================
0. SPECIMEN TABLE
Phenotype depends ONLY on the token pair -> TT and Tt are
built from identical geometry + identical colour, so they
genuinely share one visible phenotype.
============================================================ */
const DOM = '#f2b134', REC = '#58c7c0';
const SPECS = [
{ id:'A', a:['T','T'], pheno:'CRIMSON PETALS', css:'#d94452', hex:0xd94452,
note:'Homozygous dominant — phenotype matches specimen B.' },
{ id:'B', a:['T','t'], pheno:'CRIMSON PETALS', css:'#d94452', hex:0xd94452,
note:'Heterozygous — same visible phenotype as specimen A.' },
{ id:'C', a:['t','t'], pheno:'VIOLET PETALS', css:'#8b5cf6', hex:0x8b5cf6,
note:'Homozygous recessive — the only violet form.' },
];
const XS = [-1.25, 0, 1.25];
/* ============================================================
1. RENDERER / SCENE
============================================================ */
const app = document.getElementById('app');
const renderer = new THREE.WebGLRenderer({ antialias:true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
app.appendChild(renderer.domElement);
const MAXANISO = renderer.capabilities.getMaxAnisotropy();
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b111c);
scene.fog = new THREE.Fog(0x0b111c, 9, 26);
const camera = new THREE.PerspectiveCamera(40, innerWidth/innerHeight, .1, 120);
/* lights */
scene.add(new THREE.HemisphereLight(0x9fb6e0, 0x141a26, .55));
const key = new THREE.DirectionalLight(0xfff1dc, 1.75);
key.position.set(3.4, 6.2, 4.2);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6; key.shadow.camera.right = 6;
key.shadow.camera.top = 6; key.shadow.camera.bottom = -4;
key.shadow.camera.near = 1; key.shadow.camera.far = 20;
key.shadow.bias = -0.0006; key.shadow.normalBias = 0.02;
scene.add(key);
const fill = new THREE.DirectionalLight(0x86a9ff, .38); fill.position.set(-5, 3.4, -2); scene.add(fill);
const rim = new THREE.DirectionalLight(0xffb27a, .45); rim.position.set(0, 2.4, -5); scene.add(rim);
/* ground */
const ground = new THREE.Mesh(new THREE.CircleGeometry(16, 40),
new THREE.MeshStandardMaterial({ color:0x141b28, roughness:1 }));
ground.rotation.x = -Math.PI/2; ground.receiveShadow = true; scene.add(ground);
const grid = new THREE.GridHelper(26, 26, 0x27334c, 0x1a2334);
grid.position.y = .004;
grid.material.transparent = true; grid.material.opacity = .30; scene.add(grid);
/* ============================================================
2. LOW-POLY HELPERS
============================================================ */
function rr(c,x,y,w,h,r){c.beginPath();c.moveTo(x+r,y);c.arcTo(x+w,y,x+w,y+h,r);
c.arcTo(x+w,y+h,x,y+h,r);c.arcTo(x,y+h,x,y,r);c.arcTo(x,y,x+w,y,r);c.closePath();}
function tex(canvas){const t=new THREE.CanvasTexture(canvas);t.colorSpace=THREE.SRGBColorSpace;
t.anisotropy=MAXANISO;return t;}
function chip(c,x,y,r,letter,col){c.beginPath();c.arc(x,y,r,0,Math.PI*2);
c.fillStyle=col;c.fill();c.lineWidth=3;c.strokeStyle='rgba(255,255,255,.25)';c.stroke();
c.fillStyle='#131a28';c.font='800 '+(r*1.05)+'px ui-monospace,monospace';
c.textAlign='center';c.textBaseline='middle';c.fillText(letter,x,y+1);}
function swatch(c,x,y,r,col){c.beginPath();c.arc(x,y,r,0,Math.PI*2);c.fillStyle=col;c.fill();
c.lineWidth=3;c.strokeStyle='rgba(255,255,255,.22)';c.stroke();}
/* petal / leaf geometry: lies in XZ plane, extends +X, ridge raised +Y */
function bladeGeom(L,W,ridge=.055){
const A=[0,0,0], T=[L,0,0], Ls=[L*.5,0,-W/2], Rs=[L*.5,0,W/2], C=[L*.5,ridge,0];
const p=[...A,...C,...Ls, ...Ls,...C,...T, ...T,...C,...Rs, ...Rs,...C,...A];
const g=new THREE.BufferGeometry();
g.setAttribute('position',new THREE.Float32BufferAttribute(p,3));
g.computeVertexNormals(); return g;
}
const PETAL_G = bladeGeom(.34,.26,.05);
const LEAF_G = bladeGeom(.30,.17,.03);
/* ============================================================
3. RACK, BENCH, HEADER BOARD (the stated dominance rule)
============================================================ */
const M = {
slab : new THREE.MeshStandardMaterial({color:0x2a3347, roughness:.95, flatShading:true}),
ped : new THREE.MeshStandardMaterial({color:0x3d4862, roughness:.9, flatShading:true}),
cap : new THREE.MeshStandardMaterial({color:0x4c5878, roughness:.85, flatShading:true}),
wood : new THREE.MeshStandardMaterial({color:0x6b4a33, roughness:.9, flatShading:true}),
pot : new THREE.MeshStandardMaterial({color:0xc0663f, roughness:.95, flatShading:true}),
rim : new THREE.MeshStandardMaterial({color:0xd47b52, roughness:.9, flatShading:true}),
soil : new THREE.MeshStandardMaterial({color:0x2a1d14, roughness:1, flatShading:true}),
stem : new THREE.MeshStandardMaterial({color:0x3f7d3a, roughness:.9, flatShading:true}),
leaf : new THREE.MeshStandardMaterial({color:0x4e9a44, roughness:.85, flatShading:true,
side:THREE.DoubleSide}),
petalA: new THREE.MeshStandardMaterial({color:0xd94452, roughness:.78, flatShading:true,
side:THREE.DoubleSide}),
petalB: new THREE.MeshStandardMaterial({color:0xd94452, roughness:.78, flatShading:true,
side:THREE.DoubleSide}),
petalC: new THREE.MeshStandardMaterial({color:0x8b5cf6, roughness:.78, flatShading:true,
side:THREE.DoubleSide}),
heart: new THREE.MeshStandardMaterial({color:0xffd166, roughness:.7, flatShading:true}),
accent: new THREE.MeshStandardMaterial({color:0x6ee7ff, emissive:0x1c5f73, emissiveIntensity:1.4,
roughness:.4})
};
function box(w,h,d,mat,x,y,z,parent=scene){const m=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),mat);
m.position.set(x,y,z);m.castShadow=true;m.receiveShadow=true;parent.add(m);return m;}
/* bench slab */
box(4.7,.14,1.75,M.slab,0,.07,0);
/* frame posts + top beam (holds the rule board) */
box(.13,2.72,.13,M.wood,-1.92,1.50,-.58);
box(.13,2.72,.13,M.wood, 1.92,1.50,-.58);
box(4.05,.13,.13,M.wood, 0,2.82,-.58);
box(4.05,.11,.11,M.wood, 0,.42,-.58);
/* header board texture ------------------------------------------------ */
function drawBoard(){
const c=document.createElement('canvas'); c.width=1120; c.height=304;
const x=c.getContext('2d');
const g=x.createLinearGradient(0,0,0,304); g.addColorStop(0,'#182338'); g.addColorStop(1,'#101827');
x.fillStyle=g; rr(x,4,4,1112,296,16); x.fill();
x.strokeStyle='rgba(120,145,190,.35)'; x.lineWidth=2; x.stroke();
x.textBaseline='middle';
x.fillStyle='#93a3c0'; x.font='700 20px ui-monospace,monospace';
x.fillText('DOMINANCE RULE',34,44);
x.fillStyle='#e8eefc'; x.font='700 34px ui-sans-serif,system-ui';
x.fillText('Token T DOMINATES token t',34,88);
const rows=[['T','T','#d94452','CRIMSON PETALS'],['T','t','#d94452','CRIMSON PETALS'],
['t','t','#8b5cf6','VIOLET PETALS']];
rows.forEach((r,i)=>{
const y=150+i*52;
chip(x,60,y,21,r[0], r[0]==='T'?DOM:REC); chip(x,110,y,21,r[1], r[1]==='T'?DOM:REC);
x.fillStyle='#93a3c0'; x.font='700 26px ui-sans-serif,system-ui';
x.fillText('→',156,y+2);
swatch(x,210,y,18,r[2]);
x.fillStyle=r[2]; x.font='800 28px ui-sans-serif,system-ui';
x.fillText(r[3],244,y+2);
});
x.fillStyle='#9fb0cf'; x.font='500 21px ui-sans-serif,system-ui';
x.fillText('Different token pairs (T T and T t) can share ONE visible phenotype.',560,150);
x.fillStyle='#6ee7ff'; x.font='700 21px ui-monospace,monospace';
x.fillText('T T = T t',560,192);
x.fillStyle='#9fb0cf'; x.font='500 19px ui-sans-serif,system-ui';
x.fillText('(crimson, crimson)',560,228);
return c;
}
const board = new THREE.Mesh(new THREE.PlaneGeometry(3.5,.95),
new THREE.MeshBasicMaterial({map:tex(drawBoard())}));
board.position.set(0,2.30,-.565); scene.add(board);
/* ============================================================
4. SPECIMENS
============================================================ */
const plants=[], hits=[], rings=[], pedMats=[];
function makePlaque(spec){
const c=document.createElement('canvas'); c.width=640; c.height=288;
const x=c.getContext('2d');
const g=x.createLinearGradient(0,0,0,288); g.addColorStop(0,'#161e2f'); g.addColorStop(1,'#0e1523');
x.fillStyle=g; rr(x,4,4,632,280,14); x.fill();
x.strokeStyle='rgba(120,145,190,.35)'; x.lineWidth=2; x.stroke();
x.textBaseline='middle';
x.fillStyle='#93a3c0'; x.font='700 21px ui-monospace,monospace';
x.fillText('SPECIMEN '+spec.id,26,42);
x.strokeStyle='rgba(120,145,190,.25)'; x.lineWidth=1;
x.beginPath(); x.moveTo(26,62); x.lineTo(614,62); x.stroke();
x.fillStyle='#93a3c0'; x.font='700 18px ui-monospace,monospace';
x.fillText('GENOTYPE',26,104);
chip(x,132,100,25,spec.a[0], spec.a[0]==='T'?DOM:REC);
chip(x,192,100,25,spec.a[1], spec.a[1]==='T'?DOM:REC);
x.fillStyle='#93a3c0'; x.font='700 18px ui-monospace,monospace';
x.fillText('PHENOTYPE',26,180);
swatch(x,132,176,25,spec.css);
x.fillStyle=spec.css; x.font='800 27px ui-sans-serif,system-ui';
x.fillText(spec.pheno,170,177);
x.fillStyle='#9fb0cf'; x.font='500 19px ui-sans-serif,system-ui';
x.fillText(spec.note,26,238);
return tex(c);
}
function makeLabel(text,css){
const c=document.createElement('canvas'); c.width=512; c.height=150;
const x=c.getContext('2d');
x.fillStyle=css; rr(x,6,6,500,138,22); x.fill();
x.strokeStyle='rgba(255,255,255,.45)'; x.lineWidth=4; x.stroke();
x.fillStyle='#ffffff'; x.font='800 46px ui-sans-serif,system-ui';
x.textAlign='center'; x.textBaseline='middle';
x.fillText(text,256,72);
const s=new THREE.Sprite(new THREE.SpriteMaterial({map:tex(c),transparent:true,depthWrite:false}));
s.scale.set(.94,.275,1); return s;
}
function buildSpecimen(i, spec, xpos){
/* pedestal */
const pedMat = M.ped.clone(); pedMats.push(pedMat);
const ped = new THREE.Mesh(new THREE.BoxGeometry(.84,.62,.84), pedMat);
ped.position.set(xpos,.45,0); ped.castShadow=ped.receiveShadow=true; scene.add(ped);
box(.90,.05,.90,M.cap,xpos,.785,0);
/* selection ring on the bench */
const ring = new THREE.Mesh(new THREE.TorusGeometry(.56,.016,4,24),M.accent);
ring.rotation.x=-Math.PI/2; ring.position.set(xpos,.155,0); ring.visible=false; scene.add(ring);
rings.push(ring);
/* plant group (base at pedestal top) */
const plant = new THREE.Group(); plant.position.set(xpos,.81,-.12); scene.add(plant);
const pot = new THREE.Mesh(new THREE.CylinderGeometry(.25,.18,.26,6),M.pot);
pot.position.y=.13; pot.castShadow=true; plant.add(pot);
const rim = new THREE.Mesh(new THREE.CylinderGeometry(.275,.275,.05,6),M.rim);
rim.position.y=.255; rim.castShadow=true; plant.add(rim);
const soil = new THREE.Mesh(new THREE.CylinderGeometry(.225,.225,.05,6),M.soil);
soil.position.y=.235; plant.add(soil);
const stem = new THREE.Mesh(new THREE.CylinderGeometry(.028,.038,.34,5),M.stem);
stem.position.y=.43; stem.castShadow=true; plant.add(stem);
/* leaves */
[[.38,.6,.9],[.5,-2.4,1.15]].forEach(([y,az,tilt])=>{
const piv=new THREE.Group(); piv.position.y=y; piv.rotation.y=az; plant.add(piv);
const lf=new THREE.Mesh(LEAF_G,M.leaf); lf.rotation.x=-tilt; lf.castShadow=true; piv.add(lf);
});
/* flower head — identical construction for A and B */
const head=new THREE.Group(); head.position.y=.60; head.rotation.x=.92; plant.add(head);
const petalMat = i===0?M.petalA:(i===1?M.petalB:M.petalC);
for(let k=0;k<6;k++){
const piv=new THREE.Group(); piv.rotation.y=k*Math.PI/3+(i*0.12); head.add(piv);
const p=new THREE.Mesh(PETAL_G,petalMat);
p.rotation.x=-0.26; p.castShadow=true; piv.add(p);
}
const heart=new THREE.Mesh(new THREE.IcosahedronGeometry(.075,0),M.heart);
heart.scale.y=.72; heart.position.y=.02; head.add(heart);
plants.push({plant,head,phase:i*1.7});
/* genotype plaque directly BENEATH the flower */
const plaque=new THREE.Mesh(new THREE.PlaneGeometry(.80,.36),
new THREE.MeshBasicMaterial({map:makePlaque(spec)}));
plaque.position.set(xpos,.45,.50); plaque.rotation.x=-.55; scene.add(plaque);
box(.84,.03,.06,M.slab,xpos,.315,.52); // little shelf under the plaque
/* literal token pucks (the token pair) */
const off=[-.135,.135];
spec.a.forEach((letter,k)=>{
const col = letter==='T'?DOM:REC;
const puck=new THREE.Mesh(new THREE.CylinderGeometry(.085,.085,.035,12),
new THREE.MeshStandardMaterial({color:new THREE.Color(col),roughness:.6,flatShading:true}));
puck.position.set(xpos+off[k],.8275,.30); puck.castShadow=true; scene.add(puck);
const lc=document.createElement('canvas'); lc.width=lc.height=128;
const lx=lc.getContext('2d');
lx.fillStyle='#131a28'; lx.font='800 78px ui-monospace,monospace';
lx.textAlign='center'; lx.textBaseline='middle'; lx.fillText(letter,64,68);
const letterMesh=new THREE.Mesh(new THREE.PlaneGeometry(.115,.115),
new THREE.MeshBasicMaterial({map:tex(lc),transparent:true,depthWrite:false}));
letterMesh.rotation.x=-Math.PI/2; letterMesh.position.set(xpos+off[k],.848,.30);
scene.add(letterMesh);
});
/* phenotype tag above the flower */
const lab=makeLabel(spec.pheno,spec.css); lab.position.set(xpos,1.80,0); scene.add(lab);
/* invisible hit volume for picking */
const hit=new THREE.Mesh(new THREE.BoxGeometry(1.05,1.7,1.05),
new THREE.MeshBasicMaterial({visible:false}));
hit.position.set(xpos,1.15,0); hit.userData.idx=i; scene.add(hit); hits.push(hit);
}
SPECS.forEach((s,i)=>buildSpecimen(i,s,XS[i]));
/* "=" tag linking the two crimson specimens */
{
const c=document.createElement('canvas'); c.width=160; c.height=160;
const x=c.getContext('2d');
x.fillStyle='rgba(12,18,30,.85)'; rr(x,10,10,140,140,24); x.fill();
x.strokeStyle='rgba(110,231,255,.8)'; x.lineWidth=5; x.stroke();
x.fillStyle='#6ee7ff'; x.font='800 92px ui-monospace,monospace';
x.textAlign='center'; x.textBaseline='middle'; x.fillText('=',80,84);
const s=new THREE.Sprite(new THREE.SpriteMaterial({map:tex(c),transparent:true,depthWrite:false}));
s.scale.set(.30,.30,1); s.position.set(-.625,1.80,.02); scene.add(s);
}
/* pollen motes */
const pn=140, pp=new Float32Array(pn*3), pv=[];
for(let i=0;i<pn;i++){pp[i*3]=(Math.random()-.5)*4.6;pp[i*3+1]=Math.random()*1.9+.7;pp[i*3+2]=(Math.random()-.5)*1.6;}
const pg=new THREE.BufferGeometry(); pg.setAttribute('position',new THREE.BufferAttribute(pp,3));
const motes=new THREE.Points(pg,new THREE.PointsMaterial({color:0xffe6b0,size:.028,transparent:true,
opacity:.55,depthWrite:false,sizeAttenuation:true}));
scene.add(motes);
/* ============================================================
5. CUSTOM CAMERA CONTROLS (no addons)
============================================================ */
let az=-0.10, pol=Math.PI/2-0.20, rad=5.4;
let azT=az, polT=pol, radT=rad, tgt=new THREE.Vector3(0,1.25,0), tgtT=tgt.clone();
let dragging=false, lastX=0, lastY=0, moved=0, idle=0;
const dom=renderer.domElement;
dom.style.touchAction='none';
dom.addEventListener('pointerdown',e=>{dragging=true;moved=0;lastX=e.clientX;lastY=e.clientY;
dom.setPointerCapture(e.pointerId);idle=0;});
dom.addEventListener('pointermove',e=>{
if(dragging){const dx=e.clientX-lastX, dy=e.clientY-lastY; moved+=Math.abs(dx)+Math.abs(dy);
azT-=dx*.006; polT=THREE.MathUtils.clamp(polT-dy*.005,.35,1.48);
lastX=e.clientX;lastY=e.clientY;idle=0;}
});
dom.addEventListener('pointerup',e=>{dragging=false;if(moved<6) pick(e);});
dom.addEventListener('pointercancel',()=>{dragging=false;});
dom.addEventListener('wheel',e=>{e.preventDefault();
radT=THREE.MathUtils.clamp(radT+e.deltaY*.0028,2.6,9);idle=0;},{passive:false});
/* picking */
const ray=new THREE.Raycaster(), ndc=new THREE.Vector2();
function pick(e){
ndc.x=(e.clientX/innerWidth)*2-1; ndc.y=-(e.clientY/innerHeight)*2+1;
ray.setFromCamera(ndc,camera);
const it=ray.intersectObjects(hits,false);
if(it.length) select(it[0].object.userData.idx);
}
/* ============================================================
6. SELECTION + UI
============================================================ */
let sel=0;
const info=document.getElementById('info');
function select(i){
sel=((i%3)+3)%3;
rings.forEach((r,k)=>r.visible=(k===sel));
pedMats.forEach((m,k)=>{m.emissive.setHex(k===sel?0x16323f:0x000000);
m.emissiveIntensity=k===sel?.55:0;});
const s=SPECS[sel];
info.innerHTML=`
<div class="kicker">Selected specimen</div>
<div class="big" style="margin:6px 0 2px">${s.id} · ${s.a[0]} ${s.a[1]}</div>
<div class="row"><span class="chip" style="background:${s.a[0]==='T'?DOM:REC}">${s.a[0]}</span>
<span class="chip" style="background:${s.a[1]==='T'?DOM:REC}">${s.a[1]}</span>
<span class="sub">token pair</span></div>
<div class="row"><span class="sw" style="background:${s.css}"></span>
<span class="sub" style="color:${s.css};font-weight:700">${s.pheno}</span></div>
<div class="note" style="margin-top:8px">${s.note}</div>
${sel<2?'<div class="note" style="margin-top:8px;color:#6ee7ff">Genotype differs, phenotype identical → dominance.</div>':''}`;
tgtT.set(XS[sel]*.45,1.20,0); radT=4.7; idle=0;
}
function overview(){ tgtT.set(0,1.25,0); radT=5.4; azT=-.10; polT=Math.PI/2-.20; }
document.getElementById('ov').onclick=overview;
document.getElementById('prev').onclick=()=>select(sel-1);
document.getElementById('next').onclick=()=>select(sel+1);
addEventListener('keydown',e=>{
if(e.key==='1')select(0); if(e.key==='2')select(1); if(e.key==='3')select(2);
if(e.key==='ArrowLeft')select(sel-1); if(e.key==='ArrowRight')select(sel+1);
});
select(0);
/* ============================================================
7. LOOP
============================================================ */
const clock=new THREE.Clock();
function animate(){
requestAnimationFrame(animate);
const dt=Math.min(clock.getDelta(),.05), t=clock.elapsedTime;
idle+=dt;
if(idle>4 && !dragging) azT+=dt*.045; // gentle idle orbit
az += (azT-az)*Math.min(1,dt*6);
pol+= (polT-pol)*Math.min(1,dt*6);
rad+= (radT-rad)*Math.min(1,dt*5);
tgt.lerp(tgtT,Math.min(1,dt*3.5));
const sp=Math.sin(pol);
camera.position.set(tgt.x+rad*sp*Math.sin(az), tgt.y+rad*Math.cos(pol), tgt.z+rad*sp*Math.cos(az));
camera.lookAt(tgt);
plants.forEach((p,i)=>{
p.plant.rotation.z=Math.sin(t*.72+p.phase)*.045;
p.plant.rotation.x=Math.cos(t*.55+p.phase)*.028;
p.head.rotation.z=Math.sin(t*.9+p.phase)*.05;
});
const pos=pg.attributes.position;
for(let i=0;i<pn;i++){
let y=pos.getY(i)+dt*.055; if(y>2.7)y=.7;
pos.setY(i,y);
pos.setX(i,pos.getX(i)+Math.sin(t*.6+i)*dt*.012);
}
pos.needsUpdate=true;
renderer.render(scene,camera);
}
animate();
addEventListener('resize',()=>{
camera.aspect=innerWidth/innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
</script>
</body>
</html>
```