Prompt specification
Build or customize the Three.js 3D scene "Modular housing assembly puzzle" 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: Modular housing assembly puzzle
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/modular-housing-assembly-puzzle-x0308
Scene Description Prompt:
A low-poly enclosure puzzle: snap panels into a closed box, then release accessible tabs in valid reverse order. Three.js from cdnjs, one HTML file.
Working Three.js Starter (modular-housing-assembly-puzzle-x0308):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LOCKS / SIX — Enclosure Puzzle</title>
<style>
:root {
--bg: #071116;
--panel: rgba(13, 25, 31, 0.82);
--panel-strong: rgba(17, 31, 37, 0.94);
--line: rgba(213, 239, 232, 0.14);
--text: #e7f0eb;
--muted: #8ca39f;
--accent: #d9f66f;
--accent-dark: #182117;
--orange: #ffb45c;
--danger: #ff746c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 53% 42%, rgba(45, 86, 83, 0.18), transparent 34%),
radial-gradient(circle at 18% 15%, rgba(80, 58, 105, 0.14), transparent 28%),
linear-gradient(145deg, #091419, #050b0f 70%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.topbar {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 210px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 1px solid rgba(217, 246, 111, 0.5);
background: rgba(217, 246, 111, 0.06);
clip-path: polygon(25% 6%, 75% 6%, 100% 50%, 75% 94%, 25% 94%, 0 50%);
display: grid;
place-items: center;
}
.brand-mark::after {
content: "";
width: 11px;
height: 11px;
background: var(--accent);
clip-path: polygon(25% 6%, 75% 6%, 100% 50%, 75% 94%, 25% 94%, 0 50%);
box-shadow: 0 0 18px rgba(217, 246, 111, 0.45);
}
.brand-name {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 14px;
font-weight: 800;
letter-spacing: 0.18em;
}
.brand-sub {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.phase-pill {
display: flex;
align-items: center;
gap: 9px;
min-height: 39px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--panel);
backdrop-filter: blur(14px);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.phase-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 13px rgba(217, 246, 111, 0.7);
}
.icon-button,
.primary-button,
.secondary-button {
border: 1px solid var(--line);
color: var(--text);
background: var(--panel);
backdrop-filter: blur(14px);
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.icon-button:hover,
.secondary-button:hover {
border-color: rgba(217, 246, 111, 0.45);
background: rgba(27, 46, 48, 0.92);
}
.icon-button:active,
.primary-button:active,
.secondary-button:active {
transform: translateY(1px);
}
.icon-button {
height: 39px;
padding: 0 13px;
border-radius: 11px;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.brief {
position: absolute;
top: 104px;
left: 24px;
width: min(326px, calc(100vw - 48px));
padding: 21px;
border: 1px solid var(--line);
border-radius: 20px;
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.035), transparent 45%),
var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(18px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--accent);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 18px;
height: 1px;
background: currentColor;
}
h1 {
margin: 13px 0 9px;
font-size: clamp(25px, 3vw, 34px);
line-height: 1.02;
letter-spacing: -0.04em;
font-weight: 760;
}
.objective {
min-height: 54px;
margin: 0;
color: #a9bab5;
font-size: 13px;
line-height: 1.55;
}
.progress-row {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-top: 20px;
margin-bottom: 8px;
}
.progress-label {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.progress-value {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
color: var(--text);
}
.progress-track {
position: relative;
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.progress-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0%;
border-radius: inherit;
background: linear-gradient(90deg, #9db54a, var(--accent));
box-shadow: 0 0 15px rgba(217, 246, 111, 0.35);
transition: width 450ms cubic-bezier(0.22, 1, 0.36, 1);
}
.chain-wrap {
margin-top: 19px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.chain-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.chain-state {
color: var(--accent);
}
.chain {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 6px;
}
.chain-cell {
height: 29px;
display: grid;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 7px;
background: rgba(255, 255, 255, 0.025);
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 800;
transition: 220ms ease;
}
.chain-cell.filled {
color: var(--accent);
border-color: rgba(217, 246, 111, 0.35);
background: rgba(217, 246, 111, 0.08);
}
.chain-cell.released {
color: #071116;
border-color: var(--accent);
background: var(--accent);
}
.tip {
display: flex;
gap: 10px;
margin-top: 17px;
color: #839792;
font-size: 11px;
line-height: 1.45;
}
.tip-key {
flex: 0 0 auto;
padding: 2px 6px;
height: fit-content;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 5px;
color: #c4d2ce;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
}
.controls {
position: absolute;
right: 24px;
bottom: 23px;
display: flex;
align-items: center;
gap: 9px;
color: #819590;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control-chip {
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 8px;
background: rgba(8, 17, 21, 0.6);
backdrop-filter: blur(10px);
}
.toast {
position: absolute;
top: 84px;
left: 50%;
width: min(420px, calc(100vw - 36px));
padding: 13px 16px;
display: flex;
align-items: center;
gap: 12px;
border: 1px solid rgba(217, 246, 111, 0.25);
border-radius: 13px;
background: rgba(12, 25, 29, 0.94);
box-shadow: 0 16px 60px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(18px);
opacity: 0;
transform: translate(-50%, -12px);
transition: 220ms ease;
pointer-events: none;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.toast.error {
border-color: rgba(255, 116, 108, 0.4);
}
.toast.hint {
border-color: rgba(255, 180, 92, 0.45);
}
.toast-icon {
flex: 0 0 auto;
width: 27px;
height: 27px;
display: grid;
place-items: center;
border-radius: 8px;
color: var(--accent-dark);
background: var(--accent);
font-size: 12px;
font-weight: 900;
}
.toast.error .toast-icon {
color: #2a0d0b;
background: var(--danger);
}
.toast.hint .toast-icon {
color: #2b1805;
background: var(--orange);
}
.toast-title {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
}
.toast-message {
margin-top: 3px;
color: #9cb0aa;
font-size: 11px;
line-height: 1.35;
}
.modal {
position: fixed;
inset: 0;
z-index: 5;
display: grid;
place-items: center;
padding: 24px;
background: rgba(2, 7, 9, 0.58);
backdrop-filter: blur(9px);
opacity: 1;
transition: opacity 220ms ease;
}
.modal.hidden {
opacity: 0;
pointer-events: none;
}
.win-card {
position: relative;
width: min(430px, 100%);
padding: 31px;
border: 1px solid rgba(217, 246, 111, 0.28);
border-radius: 24px;
background:
radial-gradient(circle at 50% 0%, rgba(217, 246, 111, 0.09), transparent 45%),
var(--panel-strong);
box-shadow: 0 30px 110px rgba(0, 0, 0, 0.55);
text-align: center;
}
.win-emblem {
width: 65px;
height: 65px;
margin: 0 auto 19px;
display: grid;
place-items: center;
border: 1px solid rgba(217, 246, 111, 0.45);
border-radius: 20px;
color: var(--accent);
background: rgba(217, 246, 111, 0.07);
font-size: 28px;
transform: rotate(45deg);
}
.win-emblem span {
transform: rotate(-45deg);
}
.win-card h2 {
margin: 0;
font-size: 31px;
letter-spacing: -0.04em;
}
.win-card p {
margin: 12px auto 22px;
max-width: 320px;
color: #9eb0ab;
font-size: 13px;
line-height: 1.55;
}
.win-stats {
display: flex;
justify-content: center;
gap: 9px;
margin-bottom: 23px;
}
.stat {
min-width: 100px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.stat-value {
color: var(--accent);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 17px;
font-weight: 800;
}
.stat-label {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.modal-actions {
display: flex;
justify-content: center;
gap: 9px;
}
.primary-button,
.secondary-button {
min-height: 43px;
padding: 0 18px;
border-radius: 11px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.primary-button {
border-color: var(--accent);
color: var(--accent-dark);
background: var(--accent);
}
.primary-button:hover {
background: #e5ff89;
}
@media (max-width: 720px) {
.topbar {
top: 14px;
left: 14px;
right: 14px;
}
.brand-sub,
.phase-pill {
display: none;
}
.brand {
min-width: 0;
}
.brand-name {
font-size: 12px;
}
.brief {
top: 70px;
left: 14px;
width: calc(100vw - 28px);
padding: 16px;
}
h1 {
margin: 9px 0 6px;
font-size: 23px;
}
.objective {
min-height: 0;
font-size: 12px;
}
.progress-row {
margin-top: 13px;
}
.chain-wrap,
.tip {
display: none;
}
.controls {
display: none;
}
.toast {
top: auto;
bottom: 18px;
}
}
@media (max-height: 640px) and (min-width: 721px) {
.brief {
top: 84px;
padding: 15px;
}
.chain-wrap,
.tip {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly enclosure puzzle"></canvas>
<div class="hud">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="brand-name">LOCKS / SIX</div>
<div class="brand-sub">Low-poly enclosure puzzle</div>
</div>
</div>
<div class="top-actions">
<div class="phase-pill">
<span class="phase-dot"></span>
<span id="phaseLabel">Assembly</span>
</div>
<button class="icon-button" id="hintButton" type="button">Hint</button>
<button class="icon-button" id="resetButton" type="button">Reset</button>
</div>
</header>
<section class="brief" aria-labelledby="objectiveTitle">
<div class="eyebrow" id="objectiveEyebrow">Phase 01 / Assembly</div>
<h1 id="objectiveTitle">Close the shell.</h1>
<p class="objective" id="objectiveText">
Click the floating panels to seat them. The enclosure remembers the exact order in which you lock them.
</p>
<div class="progress-row">
<span class="progress-label" id="progressLabel">Panels seated</span>
<span class="progress-value" id="progressValue">0 / 6</span>
</div>
<div class="progress-track">
<div class="progress-fill" id="progressFill"></div>
</div>
<div class="chain-wrap">
<div class="chain-heading">
<span id="chainTitle">Seal sequence</span>
<span class="chain-state" id="chainState">Recording</span>
</div>
<div class="chain" id="chain"></div>
</div>
<div class="tip">
<span class="tip-key">DRAG</span>
<span>Orbit around the enclosure. Scroll to zoom. Click a panel or its orange release tab.</span>
</div>
</section>
<div class="controls">
<span class="control-chip">Drag — orbit</span>
<span class="control-chip">Wheel — zoom</span>
<span class="control-chip">H — hint</span>
<span class="control-chip">R — reset</span>
</div>
<div class="toast" id="toast" role="status" aria-live="polite">
<div class="toast-icon" id="toastIcon">✓</div>
<div>
<div class="toast-title" id="toastTitle">Ready</div>
<div class="toast-message" id="toastMessage"></div>
</div>
</div>
</div>
<div class="modal hidden" id="winModal" role="dialog" aria-modal="true" aria-labelledby="winTitle">
<div class="win-card">
<div class="win-emblem"><span>⌁</span></div>
<div class="eyebrow" style="justify-content: center">Sequence verified</div>
<h2 id="winTitle">Enclosure released.</h2>
<p>
All six tabs were released in the exact reverse of the panel seating order. The core is free.
</p>
<div class="win-stats">
<div class="stat">
<div class="stat-value" id="mistakeStat">0</div>
<div class="stat-label">Lock errors</div>
</div>
<div class="stat">
<div class="stat-value">6 / 6</div>
<div class="stat-label">Tabs released</div>
</div>
</div>
<div class="modal-actions">
<button class="secondary-button" id="dismissButton" type="button">Inspect</button>
<button class="primary-button" id="rebuildButton" type="button">Rebuild shell</button>
</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";
const canvas = document.getElementById("scene");
const ui = {
phaseLabel: document.getElementById("phaseLabel"),
objectiveEyebrow: document.getElementById("objectiveEyebrow"),
objectiveTitle: document.getElementById("objectiveTitle"),
objectiveText: document.getElementById("objectiveText"),
progressLabel: document.getElementById("progressLabel"),
progressValue: document.getElementById("progressValue"),
progressFill: document.getElementById("progressFill"),
chain: document.getElementById("chain"),
chainTitle: document.getElementById("chainTitle"),
chainState: document.getElementById("chainState"),
toast: document.getElementById("toast"),
toastIcon: document.getElementById("toastIcon"),
toastTitle: document.getElementById("toastTitle"),
toastMessage: document.getElementById("toastMessage"),
winModal: document.getElementById("winModal"),
mistakeStat: document.getElementById("mistakeStat")
};
const PANEL_COUNT = 6;
const PANEL_APOTHEM = 1.42;
const PANEL_SIDE = 2 * PANEL_APOTHEM * Math.tan(Math.PI / PANEL_COUNT);
const TAU = Math.PI * 2;
const clamp = THREE.MathUtils.clamp;
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071116, 0.028);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.03, 0);
let desiredTheta = 0.62;
let desiredPhi = 1.13;
let desiredRadius = 6.75;
let currentTheta = desiredTheta;
let currentPhi = desiredPhi;
let currentRadius = desiredRadius;
const hemisphere = new THREE.HemisphereLight(0xc6e7ee, 0x172028, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffedcf, 3.1);
keyLight.position.set(4.5, 7.5, 4.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x75d9dc, 18, 9, 2);
cyanLight.position.set(-3.4, 1.4, 2.2);
scene.add(cyanLight);
const violetLight = new THREE.PointLight(0xb79bff, 12, 8, 2);
violetLight.position.set(3.8, 0.5, -3.2);
scene.add(violetLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x071015,
roughness: 0.94,
metalness: 0.05
});
const floor = new THREE.Mesh(new THREE.CircleGeometry(15, 64), floorMaterial);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.25;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 32, 0x31505a, 0x172d34);
grid.position.y = -1.235;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
const platformGroup = new THREE.Group();
scene.add(platformGroup);
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x17252a,
roughness: 0.72,
metalness: 0.38,
flatShading: true
});
const platformTopMaterial = new THREE.MeshStandardMaterial({
color: 0x263a3e,
roughness: 0.58,
metalness: 0.48,
flatShading: true
});
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.72, 2.94, 0.28, 6),
platformMaterial
);
platform.position.y = -1.08;
platform.rotation.y = Math.PI / 6;
platform.receiveShadow = true;
platform.castShadow = true;
platformGroup.add(platform);
const platformTop = new THREE.Mesh(
new THREE.CylinderGeometry(2.49, 2.49, 0.065, 6),
platformTopMaterial
);
platformTop.position.y = -0.905;
platformTop.rotation.y = Math.PI / 6;
platformTop.receiveShadow = true;
platformGroup.add(platformTop);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(2.56, 0.025, 5, 6),
new THREE.MeshStandardMaterial({
color: 0x667d72,
emissive: 0x18271d,
emissiveIntensity: 0.4,
roughness: 0.4
})
);
platformRing.rotation.x = Math.PI / 2;
platformRing.rotation.z = Math.PI / 6;
platformRing.position.y = -0.865;
platformGroup.add(platformRing);
const bottomCap = new THREE.Mesh(
new THREE.CylinderGeometry(1.66, 1.66, 0.15, 6),
new THREE.MeshStandardMaterial({
color: 0x24363b,
roughness: 0.55,
metalness: 0.52,
flatShading: true
})
);
bottomCap.position.y = -0.77;
bottomCap.rotation.y = Math.PI / 6;
bottomCap.castShadow = true;
bottomCap.receiveShadow = true;
scene.add(bottomCap);
const lidGroup = new THREE.Group();
lidGroup.visible = false;
lidGroup.position.y = 1.65;
scene.add(lidGroup);
const lid = new THREE.Mesh(
new THREE.CylinderGeometry(1.67, 1.67, 0.15, 6),
new THREE.MeshStandardMaterial({
color: 0x30474a,
roughness: 0.52,
metalness: 0.55,
flatShading: true
})
);
lid.rotation.y = Math.PI / 6;
lid.castShadow = true;
lid.receiveShadow = true;
lidGroup.add(lid);
const lidInset = new THREE.Mesh(
new THREE.CylinderGeometry(1.37, 1.37, 0.045, 6),
new THREE.MeshStandardMaterial({
color: 0x466063,
roughness: 0.58,
metalness: 0.42,
flatShading: true
})
);
lidInset.position.y = 0.095;
lidInset.rotation.y = Math.PI / 6;
lidInset.castShadow = true;
lidGroup.add(lidInset);
const lidHandle = new THREE.Mesh(
new THREE.TorusGeometry(0.23, 0.035, 5, 12),
new THREE.MeshStandardMaterial({
color: 0xd9f66f,
emissive: 0x53651d,
emissiveIntensity: 0.45,
roughness: 0.35,
metalness: 0.5
})
);
lidHandle.rotation.x = Math.PI / 2;
lidHandle.position.y = 0.16;
lidGroup.add(lidHandle);
const coreGroup = new THREE.Group();
coreGroup.position.y = 0;
scene.add(coreGroup);
const coreMaterial = new THREE.MeshStandardMaterial({
color: 0xffb75f,
emissive: 0xff7b25,
emissiveIntensity: 1.15,
roughness: 0.3,
metalness: 0.38,
flatShading: true
});
const coreMesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.43, 0),
coreMaterial
);
coreMesh.castShadow = true;
coreGroup.add(coreMesh);
const coreCage = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.IcosahedronGeometry(0.58, 0)),
new THREE.LineBasicMaterial({
color: 0xffe2a6,
transparent: true,
opacity: 0.52
})
);
coreGroup.add(coreCage);
const coreLight = new THREE.PointLight(0xff9f48, 10, 6, 2);
coreGroup.add(coreLight);
const orbiters = [];
for (let i = 0; i < 3; i++) {
const shard = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.1),
new THREE.MeshStandardMaterial({
color: 0xd9f66f,
emissive: 0x4b5b18,
emissiveIntensity: 0.6,
roughness: 0.4,
flatShading: true
})
);
shard.userData.phase = (i / 3) * TAU;
coreGroup.add(shard);
orbiters.push(shard);
}
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(210 * 3);
for (let i = 0; i < 210; i++) {
const radius = 3.2 + Math.random() * 6.5;
const angle = Math.random() * TAU;
dustPositions[i * 3] = Math.cos(angle) * radius;
dustPositions[i * 3 + 1] = -0.7 + Math.random() * 5.4;
dustPositions[i * 3 + 2] = Math.sin(angle) * radius;
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x8eb0aa,
size: 0.025,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
scene.add(dust);
const shardMaterial = new THREE.MeshStandardMaterial({
color: 0x203238,
roughness: 0.85,
metalness: 0.25,
flatShading: true
});
for (let i = 0; i < 15; i++) {
const angle = (i / 15) * TAU + Math.random() * 0.2;
const radius = 4.4 + Math.random() * 3.4;
const shard = new THREE.Mesh(
new THREE.ConeGeometry(0.12 + Math.random() * 0.12, 0.35 + Math.random() * 0.45, 3),
shardMaterial
);
shard.position.set(
Math.sin(angle) * radius,
-1.08 + Math.random() * 0.1,
Math.cos(angle) * radius
);
shard.rotation.set(
Math.random() * 0.3,
Math.random() * TAU,
Math.random() * 0.3
);
shard.castShadow = true;
scene.add(shard);
}
const palette = [
0x3f6b70,
0x506783,
0x76576f,
0x826849,
0x477366,
0x5b5d7f
];
const pickMeshes = [];
const panels = [];
function tagMesh(mesh, panelIndex, isTab = false) {
mesh.userData.panelIndex = panelIndex;
mesh.userData.isTab = isTab;
pickMeshes.push(mesh);
return mesh;
}
function makeBadge(number) {
const badgeCanvas = document.createElement("canvas");
badgeCanvas.width = 128;
badgeCanvas.height = 64;
const ctx = badgeCanvas.getContext("2d");
ctx.clearRect(0, 0, 128, 64);
ctx.fillStyle = "rgba(7, 17, 22, 0.92)";
ctx.strokeStyle = "rgba(255, 180, 92, 0.85)";
ctx.lineWidth = 4;
const x = 12;
const y = 8;
const w = 104;
const h = 48;
const r = 12;
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = "#ffd091";
ctx.font = "800 34px ui-monospace, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(number), 64, 34);
const texture = new THREE.CanvasTexture(badgeCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.48, 0.24, 1);
sprite.renderOrder = 5;
return sprite;
}
function panelTarget(index) {
const angle = (index / PANEL_COUNT) * TAU;
return {
angle,
position: new THREE.Vector3(
Math.sin(angle) * PANEL_APOTHEM,
0,
Math.cos(angle) * PANEL_APOTHEM
)
};
}
function createPanels() {
for (let i = 0; i < PANEL_COUNT; i++) {
const target = panelTarget(i);
const group = new THREE.Group();
const visual = new THREE.Group();
group.add(visual);
scene.add(group);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x18282d,
roughness: 0.45,
metalness: 0.65,
flatShading: true
});
const faceMaterial = new THREE.MeshStandardMaterial({
color: palette[i],
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.56,
metalness: 0.28,
flatShading: true
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x9aaca2,
roughness: 0.35,
metalness: 0.7,
flatShading: true
});
const body = tagMesh(
new THREE.Mesh(
new THREE.BoxGeometry(PANEL_SIDE - 0.025, 1.42, 0.17),
bodyMaterial
),
i
);
body.castShadow = true;
body.receiveShadow = true;
visual.add(body);
const face = tagMesh(
new THREE.Mesh(
new THREE.BoxGeometry(PANEL_SIDE - 0.16, 1.17, 0.085),
faceMaterial
),
i
);
face.position.z = 0.115;
face.castShadow = true;
face.receiveShadow = true;
visual.add(face);
const verticalRailGeometry = new THREE.BoxGeometry(0.065, 1.34, 0.08);
const horizontalRailGeometry = new THREE.BoxGeometry(PANEL_SIDE - 0.09, 0.065, 0.08);
for (const x of [-PANEL_SIDE / 2 + 0.065, PANEL_SIDE / 2 - 0.065]) {
const rail = tagMesh(
new THREE.Mesh(verticalRailGeometry, frameMaterial),
i
);
rail.position.set(x, 0, 0.145);
rail.castShadow = true;
visual.add(rail);
}
for (const y of [-0.665, 0.665]) {
const rail = tagMesh(
new THREE.Mesh(horizontalRailGeometry, frameMaterial),
i
);
rail.position.set(0, y, 0.145);
rail.castShadow = true;
visual.add(rail);
}
const triangleMaterial = new THREE.MeshStandardMaterial({
color: i % 2 === 0 ? 0xd7dfcb : 0xe3c68f,
roughness: 0.58,
metalness: 0.18,
flatShading: true
});
const triangle = tagMesh(
new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.036, 3),
triangleMaterial
),
i
);
triangle.rotation.x = Math.PI / 2;
triangle.rotation.z = Math.PI / 2;
triangle.position.set(-0.1, -0.04, 0.18);
triangle.castShadow = true;
visual.add(triangle);
for (const x of [-PANEL_SIDE / 2 + 0.02, PANEL_SIDE / 2 - 0.02]) {
const connector = tagMesh(
new THREE.Mesh(
new THREE.BoxGeometry(0.105, 0.25, 0.23),
frameMaterial
),
i
);
connector.position.set(x, -0.08, 0.01);
connector.castShadow = true;
visual.add(connector);
}
const tabPivot = new THREE.Group();
tabPivot.position.set(PANEL_SIDE * 0.25, 0.45, 0.19);
visual.add(tabPivot);
const tabMaterial = new THREE.MeshStandardMaterial({
color: 0xffa94d,
emissive: 0x6e2d05,
emissiveIntensity: 0.35,
roughness: 0.38,
metalness: 0.35,
flatShading: true
});
const tab = tagMesh(
new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.17, 0.13),
tabMaterial
),
i,
true
);
tab.castShadow = true;
tabPivot.add(tab);
const tabRing = tagMesh(
new THREE.Mesh(
new THREE.TorusGeometry(0.145, 0.024, 4, 12),
new THREE.MeshStandardMaterial({
color: 0x72847e,
emissive: 0x15201e,
emissiveIntensity: 0.25,
roughness: 0.42,
metalness: 0.58
})
),
i,
true
);
tabRing.position.z = 0.055;
tabPivot.add(tabRing);
const badge = makeBadge(i + 1);
badge.position.set(0, 0.3, 0.07);
badge.userData.panelIndex = i;
badge.userData.isTab = true;
pickMeshes.push(badge);
tabPivot.add(badge);
const panel = {
index: i,
group,
visual,
target,
faceMaterial,
tabMaterial,
tabPivot,
snapped: false,
released: false,
snapAnim: null,
releaseAnim: null,
wrongUntil: 0,
explodePosition: new THREE.Vector3(),
explodeYaw: 0,
explodeRoll: 0
};
panels.push(panel);
}
}
createPanels();
let mode = "assembly";
let assemblyOrder = [];
let releaseOrder = [];
let releaseStep = 0;
let mistakes = 0;
let hoveredPanel = -1;
let toastTimer = 0;
let winTimer = 0;
let lidTargetY = 0.82;
let coreTargetY = 0;
function showToast(title, message, type = "success", duration = 2600) {
clearTimeout(toastTimer);
ui.toast.className = "toast show";
if (type === "error") {
ui.toast.classList.add("error");
ui.toastIcon.textContent = "!";
} else if (type === "hint") {
ui.toast.classList.add("hint");
ui.toastIcon.textContent = "?";
} else {
ui.toastIcon.textContent = "✓";
}
ui.toastTitle.textContent = title;
ui.toastMessage.textContent = message;
toastTimer = setTimeout(() => {
ui.toast.classList.remove("show");
}, duration);
}
function updateUI() {
if (mode === "assembly") {
ui.phaseLabel.textContent = "Assembly";
ui.objectiveEyebrow.textContent = "Phase 01 / Assembly";
ui.objectiveTitle.textContent = "Close the shell.";
ui.objectiveText.textContent =
"Click the floating panels to seat them. The enclosure remembers the exact order in which you lock them.";
ui.progressLabel.textContent = "Panels seated";
ui.progressValue.textContent = `${assemblyOrder.length} / 6`;
ui.progressFill.style.width = `${(assemblyOrder.length / 6) * 100}%`;
ui.chainTitle.textContent = "Seal sequence";
ui.chainState.textContent = "Recording";
ui.chain.innerHTML = Array.from({ length: 6 }, (_, index) => {
const value = assemblyOrder[index];
return `<div class="chain-cell ${value !== undefined ? "filled" : ""}">${
value !== undefined ? value + 1 : "·"
}</div>`;
}).join("");
} else if (mode === "sealing") {
ui.phaseLabel.textContent = "Sealing";
ui.objectiveEyebrow.textContent = "Phase 02 / Seal check";
ui.objectiveTitle.textContent = "Shell sealed.";
ui.objectiveText.textContent =
"The six locks are engaged. Memorize the sequence shown below before the release chain is masked.";
ui.progressLabel.textContent = "Shell status";
ui.progressValue.textContent = "SEALED";
ui.progressFill.style.width = "100%";
ui.chainTitle.textContent = "Seal sequence";
ui.chainState.textContent = "Memorize";
ui.chain.innerHTML = Array.from({ length: 6 }, (_, index) => {
const value = assemblyOrder[index];
return `<div class="chain-cell filled">${value + 1}</div>`;
}).join("");
} else if (mode === "release" || mode === "won") {
const releasedSet = new Set(releaseOrder.slice(0, releaseStep));
ui.phaseLabel.textContent = mode === "won" ? "Open" : "Release";
ui.objectiveEyebrow.textContent =
mode === "won" ? "Phase 03 / Complete" : "Phase 03 / Release";
ui.objectiveTitle.textContent =
mode === "won" ? "Enclosure open." : "Unwind the locks.";
ui.objectiveText.textContent =
mode === "won"
? "Every tab was released in the exact reverse of the seating order. The core is free."
: "Rotate around the shell and click the orange tabs in the reverse order that the panels were seated. The sequence is now masked.";
ui.progressLabel.textContent = "Tabs released";
ui.progressValue.textContent = `${releaseStep} / 6`;
ui.progressFill.style.width = `${(releaseStep / 6) * 100}%`;
ui.chainTitle.textContent = "Release sequence";
ui.chainState.textContent = mode === "won" ? "Verified" : "Masked";
ui.chain.innerHTML = Array.from({ length: 6 }, (_, index) => {
const released = releasedSet.has(index);
return `<div class="chain-cell ${released ? "released" : ""}">${
released ? index + 1 : "?"
}</div>`;
}).join("");
}
}
function snapPanel(panel) {
if (mode !== "assembly" || panel.snapped) return;
panel.snapped = true;
assemblyOrder.push(panel.index);
panel.snapAnim = {
start: performance.now(),
duration: 720,
fromPosition: panel.group.position.clone(),
toPosition: panel.target.position.clone(),
fromYaw: panel.group.rotation.y,
toYaw: panel.target.angle,
fromRoll: panel.group.rotation.z,
toRoll: 0
};
updateUI();
showToast(
`Panel ${panel.index + 1} seated`,
`${assemblyOrder.length} of 6 locks engaged. The shell remembers this position in the sequence.`
);
if (assemblyOrder.length === PANEL_COUNT) {
mode = "sealing";
lidGroup.visible = true;
lidGroup.position.y = 1.65;
lidTargetY = 0.82;
updateUI();
showToast(
"Shell closed",
"Memorize the seal sequence. It will be masked when the release chain begins.",
"hint",
4300
);
winTimer = setTimeout(() => {
if (mode === "sealing") enterReleaseMode();
}, 1500);
}
}
function enterReleaseMode() {
mode = "release";
releaseOrder = assemblyOrder.slice().reverse();
releaseStep = 0;
lidTargetY = 1.48;
coreTargetY = 0.38;
updateUI();
showToast(
"Release chain active",
"Begin with the panel you seated last. Each successful release unlocks the next tab in reverse.",
"hint",
4200
);
}
function attemptRelease(panel) {
if (mode !== "release" || panel.released) return;
const expected = releaseOrder[releaseStep];
if (panel.index !== expected) {
mistakes++;
panel.wrongUntil = performance.now() + 620;
updateUI();
showToast(
"Tab locked",
`Tab ${panel.index + 1} is not next in the reverse release chain.`,
"error"
);
return;
}
panel.released = true;
releaseStep++;
const outward = new THREE.Vector3(
Math.sin(panel.target.angle),
0,
Math.cos(panel.target.angle)
);
const tangent = new THREE.Vector3(
Math.cos(panel.target.angle),
0,
-Math.sin(panel.target.angle)
);
const destination = panel.target.position
.clone()
.addScaledVector(outward, 2.35)
.addScaledVector(tangent, panel.index % 2 === 0 ? 0.22 : -0.22);
destination.y = 0.64 + (panel.index % 3) * 0.09;
panel.releaseAnim = {
start: performance.now(),
duration: 900,
fromPosition: panel.group.position.clone(),
toPosition: destination,
fromYaw: panel.group.rotation.y,
toYaw: panel.target.angle + 0.64,
fromScale: panel.group.scale.x
};
lidTargetY = 1.48 + releaseStep * 0.14;
coreTargetY = 0.38 + releaseStep * 0.17;
updateUI();
showToast(
`Tab ${panel.index + 1} released`,
releaseStep === 6
? "Final lock disengaged. The enclosure is opening."
: `${6 - releaseStep} lock${6 - releaseStep === 1 ? "" : "s"} remaining in the release chain.`
);
if (releaseStep === PANEL_COUNT) {
winTimer = setTimeout(showWin, 1100);
}
}
function showWin() {
if (mode !== "release") return;
mode = "won";
mistakes = 0;
updateUI();
ui.mistakeStat.textContent = String(mistakes);
ui.winModal.classList.remove("hidden");
}
function resetGame(showMessage = true) {
clearTimeout(winTimer);
mode = "assembly";
assemblyOrder = [];
releaseOrder = [];
releaseStep = 0;
mistakes = 0;
hoveredPanel = -1;
lidTargetY = 0.82;
coreTargetY = 0;
lidGroup.visible = false;
lidGroup.position.y = 1.65;
coreGroup.position.y = 0;
coreGroup.scale.setScalar(1);
coreLight.intensity = 10;
ui.winModal.classList.add("hidden");
panels.forEach((panel) => {
const scatter = 2.78 + (panel.index % 2) * 0.22;
panel.explodePosition.set(
Math.sin(panel.target.angle) * scatter,
-0.24 + (panel.index % 3) * 0.17,
Math.cos(panel.target.angle) * scatter
);
panel.explodeYaw = panel.target.angle + (panel.index % 2 === 0 ? 0.34 : -0.34);
panel.explodeRoll = panel.index % 2 === 0 ? 0.055 : -0.055;
panel.group.position.copy(panel.explodePosition);
panel.group.rotation.set(0, panel.explodeYaw, panel.explodeRoll);
panel.group.scale.setScalar(1);
panel.snapped = false;
panel.released = false;
panel.snapAnim = null;
panel.releaseAnim = null;
panel.wrongUntil = 0;
panel.faceMaterial.emissive.setHex(0x000000);
panel.faceMaterial.emissiveIntensity = 0;
panel.tabMaterial.color.setHex(0xffa94d);
panel.tabMaterial.emissive.setHex(0x6e2d05);
panel.tabMaterial.emissiveIntensity = 0.35;
panel.tabPivot.rotation.z = 0;
});
desiredTheta = 0.62;
desiredPhi = 1.13;
desiredRadius = 6.75;
updateUI();
if (showMessage) {
showToast(
"Shell reset",
"Seat all six panels again. A new seating order creates a new release chain."
);
}
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function raycastAt(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(pickMeshes, false);
}
function updateHover(event) {
const hits = raycastAt(event);
hoveredPanel = -1;
if (mode === "assembly" && hits.length) {
hoveredPanel = hits[0].object.userData.panelIndex;
canvas.style.cursor = "pointer";
} else if (mode === "release" && hits.length) {
const first = hits[0].object;
hoveredPanel = first.isTab ? first.userData.panelIndex : -1;
canvas.style.cursor = hoveredPanel >= 0 ? "pointer" : "default";
} else {
canvas.style.cursor = "default";
}
}
let dragging = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(event.clientX - lastPointerX) + Math.abs(event.clientY - lastPointerY) > 3) {
pointerMoved = true;
}
desiredTheta -= dx * 0.006;
desiredPhi = clamp(desiredPhi + dy * 0.005, 0.48, 1.38);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else {
updateHover(event);
}
});
canvas.addEventListener("pointerup", (event) => {
const wasDragging = dragging;
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (wasDragging && pointerMoved) return;
const hits = raycastAt(event);
if (!hits.length) return;
const hit = hits[0].object;
const panelIndex = hit.userData.panelIndex;
if (panelIndex === undefined) return;
const panel = panels[panelIndex];
if (mode === "assembly") {
snapPanel(panel);
} else if (mode === "release" && hit.userData.isTab) {
attemptRelease(panel);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = clamp(desiredRadius + event.deltaY * 0.005, 4.55, 10.5);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetGame();
} else if (event.key.toLowerCase() === "h") {
showHint();
} else if (event.key === "ArrowLeft") {
desiredTheta -= 0.12;
} else if (event.key === "ArrowRight") {
desiredTheta += 0.12;
} else if (event.key === "ArrowUp") {
desiredRadius = clamp(desiredRadius - 0.25, 4.55, 10.5);
} else if (event.key === "ArrowDown") {
desiredRadius = clamp(desiredRadius + 0.25, 4.55, 10.5);
}
});
function showHint() {
if (mode === "assembly") {
showToast(
"Sequence tip",
"Seat the panels in an order you can remember. The numbered strip records each click.",
"hint",
4300
);
} else if (mode === "release") {
const expected = releaseOrder[releaseStep];
showToast(
"Interlock hint",
`Release tab ${expected + 1} next. It is the panel you seated most recently.`,
"hint",
4300
);
} else if (mode === "sealing") {
showToast(
"Memorize now",
"The six-cell strip shows the exact seating order for a moment longer.",
"hint"
);
}
}
document.getElementById("hintButton").addEventListener("click", showHint);
document.getElementById("resetButton").addEventListener("click", () => resetGame());
document.getElementById("rebuildButton").addEventListener("click", () => resetGame());
document.getElementById("dismissButton").addEventListener("click", () => {
ui.winModal.classList.add("hidden");
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
const damping = 1 - Math.exp(-dt * 9);
currentTheta += (desiredTheta - currentTheta) * damping;
currentPhi += (desiredPhi - currentPhi) * damping;
currentRadius += (desiredRadius - currentRadius) * damping;
const spherical = new THREE.Spherical(currentRadius, currentPhi, currentTheta);
camera.position.setFromSpherical(spherical);
camera.position.add(cameraTarget);
camera.lookAt(cameraTarget);
dust.rotation.y += dt * 0.012;
dust.position.y = Math.sin(now * 0.00018) * 0.12;
coreMesh.rotation.x += dt * 0.24;
coreMesh.rotation.y += dt * 0.34;
coreCage.rotation.x -= dt * 0.15;
coreCage.rotation.y += dt * 0.2;
orbiters.forEach((shard) => {
const phase = shard.userData.phase + now * 0.0011;
shard.position.set(
Math.cos(phase) * 0.73,
Math.sin(phase * 1.4) * 0.38,
Math.sin(phase) * 0.73
);
shard.rotation.x += dt * 0.7;
shard.rotation.y += dt * 0.9;
});
lidGroup.position.y += (lidTargetY - lidGroup.position.y) * (1 - Math.exp(-dt * 5));
coreGroup.position.y += (coreTargetY - coreGroup.position.y) * (1 - Math.exp(-dt * 4.5));
panels.forEach((panel) => {
if (panel.snapAnim) {
const anim = panel.snapAnim;
const t = clamp((now - anim.start) / anim.duration, 0, 1);
const eased = 1 - Math.pow(1 - t, 3);
panel.group.position.lerpVectors(anim.fromPosition, anim.toPosition, eased);
panel.group.rotation.y = THREE.MathUtils.lerp(anim.fromYaw, anim.toYaw, eased);
panel.group.rotation.z = THREE.MathUtils.lerp(anim.fromRoll, anim.toRoll, eased);
if (t >= 1) panel.snapAnim = null;
} else if (panel.releaseAnim) {
const anim = panel.releaseAnim;
const t = clamp((now - anim.start) / anim.duration, 0, 1);
const eased = 1 - Math.pow(1 - t, 3);
panel.group.position.lerpVectors(anim.fromPosition, anim.toPosition, eased);
panel.group.position.y += Math.sin(t * Math.PI) * 0.18;
panel.group.rotation.y = THREE.MathUtils.lerp(anim.fromYaw, anim.toYaw, eased);
panel.group.rotation.z = Math.sin(t * Math.PI) * 0.08;
const scale = THREE.MathUtils.lerp(anim.fromScale, 0.76, eased);
panel.group.scale.setScalar(scale);
panel.tabPivot.rotation.z = -eased * 0.95;
if (t >= 1) panel.releaseAnim = null;
} else if (!panel.snapped) {
const bob = Math.sin(now * 0.0012 + panel.index * 1.7) * 0.055;
panel.group.position.copy(panel.explodePosition);
panel.group.position.y += bob;
panel.group.rotation.y = panel.explodeYaw + Math.sin(now * 0.0007 + panel.index) * 0.025;
panel.group.rotation.z = panel.explodeRoll;
} else {
panel.group.position.copy(panel.target.position);
panel.group.rotation.y = panel.target.angle;
panel.group.rotation.z *= 1 - dt * 5;
}
if (panel.wrongUntil > now) {
const shake = Math.sin(now * 0.075) * 0.025;
panel.visual.position.x = shake;
panel.tabMaterial.color.setHex(0xff665f);
panel.tabMaterial.emissive.setHex(0x8b1712);
panel.tabMaterial.emissiveIntensity = 0.9;
} else {
panel.visual.position.x *= 1 - dt * 12;
panel.tabMaterial.color.setHex(0xffa94d);
panel.tabMaterial.emissive.setHex(0x6e2d05);
panel.tabMaterial.emissiveIntensity =
mode === "release" ? 0.42 + Math.sin(now * 0.003 + panel.index) * 0.1 : 0.3;
}
const isHovered = mode === "assembly" && hoveredPanel === panel.index;
panel.faceMaterial.emissive.setHex(isHovered ? 0x245057 : 0x000000);
panel.faceMaterial.emissiveIntensity = isHovered ? 0.52 : 0;
});
if (mode === "won") {
coreLight.intensity = 12 + Math.sin(now * 0.004) * 3;
coreGroup.scale.setScalar(1 + Math.sin(now * 0.002) * 0.035);
}
renderer.render(scene, camera);
}
resetGame(false);
animate();
</script>
</body>
</html>
```