Prompt specification
Build or customize the Three.js 3D scene "Reaction-balancing puzzle table" 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: Reaction-balancing puzzle table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/reaction-balancing-puzzle-table-x1988
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows atom conservation in balanced chemical reactions. Let users adjust whole-number coefficients for a few simple predefined reactions; verify every element count and reject changes to chemical formulas as a balancing shortcut. Voxel style.
Working Three.js Starter (reaction-balancing-puzzle-table-x1988):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#07111f">
<title>Atom Conservation Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: #0b1728;
--panel-2: #101e32;
--panel-3: #14253b;
--line: #233750;
--text: #eef6ff;
--muted: #91a7bf;
--cyan: #55d9f5;
--green: #63e6a8;
--red: #ff7285;
--amber: #ffc766;
--purple: #a98cff;
--radius: 16px;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
width: 100%;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input,
select {
font: inherit;
}
button,
select {
color: inherit;
}
button {
cursor: pointer;
}
button:focus-visible,
select:focus-visible,
input:focus-visible,
canvas:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
[hidden] {
display: none !important;
}
#app {
height: 100vh;
display: grid;
grid-template-rows: 68px minmax(0, 1fr);
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(7, 17, 31, 0.94);
position: relative;
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
position: relative;
flex: 0 0 auto;
filter: drop-shadow(0 5px 10px rgba(85, 217, 245, 0.15));
}
.brand-mark span {
position: absolute;
width: 14px;
height: 14px;
background: var(--cyan);
border: 1px solid rgba(255, 255, 255, 0.45);
box-shadow: inset -3px -3px 0 rgba(3, 14, 28, 0.35);
}
.brand-mark span:nth-child(1) {
left: 0;
top: 10px;
opacity: 0.68;
}
.brand-mark span:nth-child(2) {
left: 10px;
top: 0;
}
.brand-mark span:nth-child(3) {
left: 20px;
top: 10px;
opacity: 0.82;
}
.brand-copy {
line-height: 1.05;
}
.brand-copy strong {
display: block;
font-size: 15px;
letter-spacing: 0.12em;
}
.brand-copy small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.locked-badge {
display: inline-flex;
align-items: center;
gap: 8px;
border: 1px solid rgba(99, 230, 168, 0.28);
background: rgba(99, 230, 168, 0.08);
color: var(--green);
border-radius: 999px;
padding: 8px 12px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
white-space: nowrap;
}
.locked-badge svg {
width: 13px;
height: 13px;
}
main {
min-height: 0;
display: grid;
grid-template-columns: 390px minmax(0, 1fr);
}
.sidebar {
min-height: 0;
overflow-y: auto;
padding: 24px 22px 28px;
border-right: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(18, 34, 55, 0.35), transparent 220px),
var(--panel);
scrollbar-width: thin;
scrollbar-color: #304966 transparent;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 8px 0 8px;
font-size: 26px;
line-height: 1.12;
letter-spacing: -0.03em;
}
.description {
margin: 0 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.reaction-picker {
position: relative;
margin-bottom: 24px;
}
.reaction-picker label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.reaction-picker select {
width: 100%;
appearance: none;
border: 1px solid var(--line);
border-radius: 11px;
background:
linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 17px) 50% / 5px 5px no-repeat,
linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 12px) 50% / 5px 5px no-repeat,
var(--panel-2);
padding: 11px 36px 11px 12px;
font-size: 13px;
font-weight: 650;
cursor: pointer;
}
.section-title {
display: flex;
align-items: center;
gap: 9px;
margin: 0 0 12px;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.04em;
}
.step-number {
display: grid;
width: 21px;
height: 21px;
place-items: center;
border: 1px solid rgba(85, 217, 245, 0.3);
border-radius: 6px;
background: rgba(85, 217, 245, 0.08);
color: var(--cyan);
font-size: 10px;
}
.equation-card {
border: 1px solid var(--line);
border-radius: var(--radius);
background:
radial-gradient(circle at 50% 0, rgba(85, 217, 245, 0.055), transparent 55%),
var(--panel-2);
padding: 14px 12px 12px;
}
.equation-line {
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
min-height: 94px;
}
.side-group {
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
flex: 0 1 auto;
}
.species-card {
width: 70px;
flex: 0 0 70px;
text-align: center;
}
.coefficient-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.coefficient-control {
display: flex;
align-items: center;
justify-content: center;
gap: 3px;
margin-bottom: 6px;
}
.coefficient-control .times {
color: var(--muted);
font-size: 13px;
}
.coefficient-control input {
width: 47px;
height: 31px;
border: 1px solid #34506e;
border-radius: 8px;
background: #091525;
color: var(--text);
text-align: center;
font-size: 15px;
font-weight: 800;
font-variant-numeric: tabular-nums;
appearance: textfield;
-moz-appearance: textfield;
}
.coefficient-control input::-webkit-inner-spin-button,
.coefficient-control input::-webkit-outer-spin-button {
margin: 0;
appearance: none;
-webkit-appearance: none;
}
.coefficient-control input.invalid {
border-color: var(--red);
background: rgba(255, 114, 133, 0.08);
box-shadow: 0 0 0 2px rgba(255, 114, 133, 0.09);
}
.formula-card {
position: relative;
min-height: 48px;
display: grid;
place-items: center;
padding: 6px 4px 5px;
border: 1px solid #2b425d;
border-radius: 9px;
background: #0a1727;
user-select: none;
pointer-events: none;
}
.formula-card::after {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
box-shadow: inset 0 -2px 0 rgba(255, 255, 255, 0.025);
pointer-events: none;
}
.formula {
display: block;
color: #f6fbff;
font-size: 20px;
font-weight: 760;
letter-spacing: -0.03em;
line-height: 1;
user-select: none;
pointer-events: none;
}
.atom-breakdown {
display: block;
margin-top: 5px;
color: #718ba5;
font-size: 8px;
font-weight: 650;
white-space: nowrap;
}
.formula-lock {
position: absolute;
right: 3px;
top: 3px;
width: 9px;
height: 9px;
color: var(--green);
opacity: 0.8;
}
.formula-lock svg {
width: 100%;
height: 100%;
}
.reaction-arrow {
flex: 0 0 27px;
color: var(--cyan);
font-size: 25px;
font-weight: 300;
text-align: center;
text-shadow: 0 0 16px rgba(85, 217, 245, 0.3);
}
.lock-note {
display: flex;
align-items: flex-start;
gap: 8px;
margin: 11px 1px 0;
color: #8ca4bc;
font-size: 10px;
line-height: 1.45;
}
.lock-note svg {
flex: 0 0 auto;
width: 13px;
height: 13px;
margin-top: 1px;
color: var(--green);
}
.count-section {
margin-top: 23px;
}
.count-summary {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 10px;
}
.total-box {
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(16, 30, 50, 0.78);
padding: 9px 10px;
}
.total-box span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.total-box strong {
display: block;
margin-top: 4px;
font-size: 18px;
font-variant-numeric: tabular-nums;
}
.table-wrap {
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(8, 20, 35, 0.72);
}
table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
th,
td {
padding: 9px 8px;
border-bottom: 1px solid rgba(35, 55, 80, 0.72);
text-align: right;
}
th {
color: #7890a8;
background: rgba(20, 37, 59, 0.62);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
th:first-child,
td:first-child {
text-align: left;
}
tbody tr:last-child td {
border-bottom: 0;
}
.element-cell {
display: inline-flex;
align-items: center;
gap: 7px;
font-weight: 750;
}
.element-dot {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.18);
}
.delta.match {
color: var(--green);
font-weight: 800;
}
.delta.mismatch {
color: var(--red);
font-weight: 800;
}
.table-note {
margin: 8px 1px 0;
color: #738ba4;
font-size: 9px;
line-height: 1.45;
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 18px;
}
.button {
min-height: 40px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel-3);
color: var(--text);
padding: 0 15px;
font-size: 11px;
font-weight: 800;
transition:
transform 120ms ease,
border-color 120ms ease,
background 120ms ease;
}
.button:hover {
transform: translateY(-1px);
border-color: #426383;
}
.button:active {
transform: translateY(0);
}
.button.primary {
border-color: #49cce9;
background: var(--cyan);
color: #04111c;
box-shadow: 0 8px 24px rgba(85, 217, 245, 0.13);
}
.message {
display: grid;
grid-template-columns: 28px 1fr;
gap: 10px;
margin-top: 12px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(16, 30, 50, 0.72);
}
.message-icon {
display: grid;
width: 27px;
height: 27px;
place-items: center;
border-radius: 8px;
background: rgba(145, 167, 191, 0.1);
color: var(--muted);
font-size: 13px;
font-weight: 900;
}
.message strong {
display: block;
font-size: 11px;
}
.message p {
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.message.success {
border-color: rgba(99, 230, 168, 0.35);
background: rgba(99, 230, 168, 0.075);
}
.message.success .message-icon {
background: rgba(99, 230, 168, 0.14);
color: var(--green);
}
.message.warning,
.message.failure {
border-color: rgba(255, 114, 133, 0.35);
background: rgba(255, 114, 133, 0.075);
}
.message.warning .message-icon,
.message.failure .message-icon {
background: rgba(255, 114, 133, 0.14);
color: var(--red);
}
.hint-area {
margin-top: 12px;
}
.hint-button {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
border: 0;
background: transparent;
color: #8da5bd;
padding: 9px 2px;
font-size: 10px;
font-weight: 750;
}
.hint-button:hover {
color: var(--text);
}
.hint-button span:last-child {
color: var(--cyan);
}
.hint-text {
margin: 0;
border-left: 2px solid var(--purple);
border-radius: 0 8px 8px 0;
background: rgba(169, 140, 255, 0.065);
color: #b9c9da;
padding: 10px 11px;
font-size: 10px;
line-height: 1.55;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 42%, rgba(24, 62, 88, 0.18), transparent 46%),
var(--bg);
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas.dragging {
cursor: grabbing;
}
.stage-top {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.stage-title {
color: #dceaf8;
font-size: 12px;
font-weight: 750;
}
.stage-subtitle {
margin-top: 5px;
color: #718ba4;
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.stage-status {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 31px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(9, 22, 38, 0.86);
padding: 0 12px;
color: var(--amber);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
backdrop-filter: blur(10px);
}
.stage-status .status-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.stage-status.success {
color: var(--green);
border-color: rgba(99, 230, 168, 0.25);
}
.stage-status.warning {
color: var(--red);
border-color: rgba(255, 114, 133, 0.25);
}
.field-label {
position: absolute;
top: 82px;
color: #637c96;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
pointer-events: none;
}
.field-label.left {
left: 9%;
}
.field-label.right {
right: 9%;
}
.legend {
position: absolute;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px 13px;
max-width: 360px;
border: 1px solid rgba(35, 55, 80, 0.8);
border-radius: 11px;
background: rgba(7, 17, 31, 0.76);
padding: 9px 12px;
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
color: #a9bdd0;
font-size: 9px;
font-weight: 700;
}
.legend-item i {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.18);
}
.viewer-tools {
position: absolute;
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: none;
}
.viewer-help {
color: #6f879f;
font-size: 9px;
text-align: right;
line-height: 1.45;
}
.reset-view {
pointer-events: auto;
min-height: 32px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(7, 17, 31, 0.82);
padding: 0 11px;
color: #9eb4c9;
font-size: 9px;
font-weight: 800;
}
.reset-view:hover {
color: var(--text);
border-color: #3d5a78;
}
@media (max-width: 900px) {
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100vh;
}
main {
display: flex;
flex-direction: column;
}
.stage {
order: -1;
height: 58vh;
min-height: 430px;
border-bottom: 1px solid var(--line);
}
.sidebar {
overflow: visible;
border-right: 0;
}
.topbar {
padding: 0 16px;
}
.brand-copy small {
display: none;
}
}
@media (max-width: 520px) {
.locked-badge {
padding: 7px 9px;
font-size: 8px;
}
.brand-copy strong {
font-size: 12px;
}
.stage {
height: 52vh;
min-height: 380px;
}
.stage-top {
top: 15px;
left: 15px;
right: 15px;
}
.stage-subtitle,
.field-label {
display: none;
}
.stage-status {
font-size: 8px;
}
.legend {
left: 12px;
bottom: 12px;
right: 12px;
max-width: none;
}
.viewer-tools {
right: 12px;
bottom: 65px;
}
.viewer-help {
display: none;
}
.sidebar {
padding: 22px 16px 30px;
}
.equation-card {
padding-inline: 8px;
}
.equation-line {
gap: 3px;
}
.species-card {
width: 66px;
flex-basis: 66px;
}
.reaction-arrow {
flex-basis: 22px;
font-size: 21px;
}
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<div class="brand-copy">
<strong>ATOM CONSERVATION LAB</strong>
<small>Balance matter. Not symbols.</small>
</div>
</div>
<div class="locked-badge">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M7 10V8a5 5 0 0 1 10 0v2" stroke="currentColor" stroke-width="2.3"/>
<rect x="4" y="10" width="16" height="11" rx="2" fill="currentColor" opacity=".18"/>
<rect x="4" y="10" width="16" height="11" rx="2" stroke="currentColor" stroke-width="2"/>
</svg>
FORMULAS LOCKED
</div>
</header>
<main>
<aside class="sidebar" aria-label="Reaction controls">
<div class="eyebrow">Reaction deck</div>
<h1 id="reactionTitle">Water formation</h1>
<p id="reactionDescription" class="description"></p>
<div class="reaction-picker">
<label for="reactionSelect">Choose a reaction</label>
<select id="reactionSelect"></select>
</div>
<section aria-labelledby="coefficientHeading">
<h2 id="coefficientHeading" class="section-title">
<span class="step-number">1</span>
Adjust whole-number coefficients
</h2>
<div class="equation-card">
<div id="equation" class="equation-line"></div>
</div>
<p class="lock-note">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M7 10V8a5 5 0 0 1 10 0v2" stroke="currentColor" stroke-width="2.3"/>
<rect x="4" y="10" width="16" height="11" rx="2" stroke="currentColor" stroke-width="2"/>
</svg>
Chemical formulas are read-only. Change only the numbers in front of each molecule.
</p>
</section>
<section class="count-section" aria-labelledby="countsHeading">
<h2 id="countsHeading" class="section-title">
<span class="step-number">2</span>
Check every element
</h2>
<div class="count-summary">
<div class="total-box">
<span>Reactant atoms</span>
<strong id="leftTotal">0</strong>
</div>
<div class="total-box">
<span>Product atoms</span>
<strong id="rightTotal">0</strong>
</div>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Element</th>
<th>Left</th>
<th>Right</th>
<th>Δ L−R</th>
</tr>
</thead>
<tbody id="elementCounts"></tbody>
</table>
</div>
<p class="table-note">
Matching totals is not enough: every individual element must have the same count on both sides.
</p>
</section>
<div class="actions">
<button id="verifyButton" class="button primary" type="button">Verify balance</button>
<button id="resetButton" class="button" type="button">Reset</button>
</div>
<div id="message" class="message" role="status" aria-live="polite">
<div id="messageIcon" class="message-icon">i</div>
<div>
<strong id="messageTitle">Set your coefficients</strong>
<p id="messageText">The atom counts update live. Verify when you are ready.</p>
</div>
</div>
<div class="hint-area">
<button
id="hintButton"
class="hint-button"
type="button"
aria-expanded="false"
aria-controls="hintText"
>
<span>Need a stoichiometric hint?</span>
<span id="hintToggle">Show</span>
</button>
<p id="hintText" class="hint-text" hidden></p>
</div>
</aside>
<section class="stage" aria-label="Three-dimensional molecular viewer">
<div id="scene"></div>
<div class="stage-top">
<div>
<div id="stageTitle" class="stage-title">Water formation</div>
<div class="stage-subtitle">Interactive voxel molecule field</div>
</div>
<div id="stageStatus" class="stage-status">
<span class="status-dot"></span>
<span id="stageStatusText">CHECKING COUNTS</span>
</div>
</div>
<div class="field-label left">Reactants</div>
<div class="field-label right">Products</div>
<div id="legend" class="legend" aria-label="Element color legend"></div>
<div class="viewer-tools">
<div class="viewer-help">
Drag to orbit · Scroll to zoom<br>
Arrow keys rotate · Double-click resets
</div>
<button id="resetView" class="reset-view" type="button">Reset view</button>
</div>
</section>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/*
Chemical data
----------------
Formulas are stored as immutable species definitions. The only editable
values are the integer coefficients generated in the equation UI.
*/
const ELEMENT_COLORS = {
H: "#eef4fa",
C: "#62ddb0",
N: "#62a9ff",
O: "#ff7185"
};
const SPECIES = {
H2: {
formula: "H₂",
atoms: { H: 2 },
layout: {
atoms: [
{ element: "H", position: [-0.48, 0, 0] },
{ element: "H", position: [0.48, 0, 0] }
],
bonds: [[0, 1]]
}
},
O2: {
formula: "O₂",
atoms: { O: 2 },
layout: {
atoms: [
{ element: "O", position: [-0.60, 0, 0] },
{ element: "O", position: [0.60, 0, 0] }
],
bonds: [[0, 1]]
}
},
H2O: {
formula: "H₂O",
atoms: { H: 2, O: 1 },
layout: {
atoms: [
{ element: "H", position: [-0.62, 0.45, 0] },
{ element: "H", position: [0.62, 0.45, 0] },
{ element: "O", position: [0, -0.15, 0] }
],
bonds: [[0, 2], [1, 2]]
}
},
CH4: {
formula: "CH₄",
atoms: { C: 1, H: 4 },
layout: {
atoms: [
{ element: "C", position: [0, 0, 0] },
{ element: "H", position: [-0.66, 0.55, 0.22] },
{ element: "H", position: [0.66, 0.55, 0.22] },
{ element: "H", position: [0, -0.66, 0.28] },
{ element: "H", position: [0, 0.04, -0.82] }
],
bonds: [[0, 1], [0, 2], [0, 3], [0, 4]]
}
},
CO2: {
formula: "CO₂",
atoms: { C: 1, O: 2 },
layout: {
atoms: [
{ element: "O", position: [-1.05, 0, 0] },
{ element: "C", position: [0, 0, 0] },
{ element: "O", position: [1.05, 0, 0] }
],
bonds: [[0, 1], [1, 2]]
}
},
N2: {
formula: "N₂",
atoms: { N: 2 },
layout: {
atoms: [
{ element: "N", position: [-0.62, 0, 0] },
{ element: "N", position: [0.62, 0, 0] }
],
bonds: [[0, 1]]
}
},
NH3: {
formula: "NH₃",
atoms: { N: 1, H: 3 },
layout: {
atoms: [
{ element: "N", position: [0, -0.04, 0] },
{ element: "H", position: [-0.66, 0.54, 0.25] },
{ element: "H", position: [0.66, 0.54, 0.25] },
{ element: "H", position: [0, -0.10, -0.78] }
],
bonds: [[0, 1], [0, 2], [0, 3]]
}
}
};
const REACTIONS = [
{
id: "water",
name: "Water formation",
description: "Combine hydrogen and oxygen to form water. Hydrogen appears on both sides, so count it carefully.",
reactants: ["H2", "O2"],
products: ["H2O"],
solution: [2, 1, 2],
hint: "Each water molecule needs one oxygen atom. Oxygen comes only from O₂, while hydrogen must also appear in every product molecule."
},
{
id: "methane",
name: "Methane combustion",
description: "Carbon and hydrogen rearrange during complete combustion. Every C, H, and O atom must be tracked.",
reactants: ["CH4", "O2"],
products: ["CO2", "H2O"],
solution: [1, 2, 1, 2],
hint: "One methane molecule produces one carbon dioxide and two water molecules. Count the oxygen needed for both products."
},
{
id: "ammonia",
name: "Ammonia synthesis",
description: "Nitrogen and hydrogen form ammonia in the Haber process. The product contains three hydrogen atoms.",
reactants: ["N2", "H2"],
products: ["NH3"],
solution: [1, 3, 2],
hint: "Each NH₃ molecule needs three H atoms and one N atom. Hydrogen comes in pairs, so its coefficient may need to be even."
}
];
const MAX_COEFFICIENT = 12;
const state = {
reaction: REACTIONS[0],
coefficients: [],
invalid: false,
hintVisible: false
};
const equationElement = document.getElementById("equation");
const reactionSelect = document.getElementById("reactionSelect");
const reactionTitle = document.getElementById("reactionTitle");
const reactionDescription = document.getElementById("reactionDescription");
const elementCountsElement = document.getElementById("elementCounts");
const leftTotalElement = document.getElementById("leftTotal");
const rightTotalElement = document.getElementById("rightTotal");
const messageElement = document.getElementById("message");
const messageIcon = document.getElementById("messageIcon");
const messageTitle = document.getElementById("messageTitle");
const messageText = document.getElementById("messageText");
const stageStatus = document.getElementById("stageStatus");
const stageStatusText = document.getElementById("stageStatusText");
const legendElement = document.getElementById("legend");
const lockSvg = `
<svg class="formula-lock" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M7 10V8a5 5 0 0 1 10 0v2"
stroke="currentColor" stroke-width="2.6"/>
<rect x="4" y="10" width="16" height="11" rx="2"
fill="currentColor" fill-opacity=".16"
stroke="currentColor" stroke-width="2.2"/>
</svg>
`;
function allSpeciesFor(reaction) {
return [...reaction.reactants, ...reaction.products];
}
function reactionElements(reaction) {
const elements = new Set();
for (const key of allSpeciesFor(reaction)) {
for (const element of Object.keys(SPECIES[key].atoms)) {
elements.add(element);
}
}
return [...elements];
}
function setMessage(type, title, text) {
messageElement.className = `message ${type}`;
messageIcon.textContent =
type === "success" ? "✓" :
type === "failure" || type === "warning" ? "!" : "i";
messageTitle.textContent = title;
messageText.textContent = text;
}
function buildReactionOptions() {
for (const reaction of REACTIONS) {
const option = document.createElement("option");
option.value = reaction.id;
option.textContent = reaction.name;
reactionSelect.appendChild(option);
}
}
function speciesMarkup(key, coefficient, index) {
const species = SPECIES[key];
const breakdown = Object.entries(species.atoms)
.map(([element, count]) => `${element}:${count}`)
.join(" · ");
return `
<div class="species-card" data-side-group>
<span class="coefficient-label">Coefficient</span>
<label class="coefficient-control">
<span class="times">×</span>
<input
type="number"
min="1"
max="${MAX_COEFFICIENT}"
step="1"
inputmode="numeric"
value="${coefficient}"
data-index="${index}"
aria-label="Coefficient for ${species.formula}"
>
</label>
<div
class="formula-card"
title="${species.formula} is locked. Change its coefficient instead."
aria-label="Locked formula ${species.formula}"
>
<span
class="formula"
contenteditable="false"
spellcheck="false"
draggable="false"
data-formula="${key}"
>${species.formula}</span>
<span class="atom-breakdown">${breakdown}</span>
${lockSvg}
</div>
</div>
`;
}
function renderEquation() {
const keys = allSpeciesFor(state.reaction);
state.coefficients = keys.map(() => 1);
const left = state.reaction.reactants
.map((key, sideIndex) => {
const index = sideIndex;
return speciesMarkup(key, 1, index);
})
.join("");
const right = state.reaction.products
.map((key, productIndex) => {
const index = state.reaction.reactants.length + productIndex;
return speciesMarkup(key, 1, index);
})
.join("");
equationElement.innerHTML = `
<div class="side-group">${left}</div>
<div class="reaction-arrow" aria-label="produces">→</div>
<div class="side-group">${right}</div>
`;
equationElement.querySelectorAll("input[data-index]").forEach((input) => {
const index = Number(input.dataset.index);
input.addEventListener("input", () => {
const raw = input.value.trim();
const valid = /^\d+$/.test(raw);
const value = Number(raw);
if (
!valid ||
value < 1 ||
value > MAX_COEFFICIENT
) {
state.invalid = true;
input.classList.add("invalid");
input.setCustomValidity(
`Enter a whole-number coefficient from 1 to ${MAX_COEFFICIENT}.`
);
setMessage(
"warning",
"Invalid coefficient",
`Coefficients must be positive whole numbers from 1 to ${MAX_COEFFICIENT}.`
);
updateBalance();
return;
}
state.invalid = false;
state.coefficients[index] = value;
input.classList.remove("invalid");
input.setCustomValidity("");
setMessage(
"neutral",
"Coefficients updated",
"The atom counts update live. Verify when your equation is ready."
);
updateBalance();
renderMolecules();
});
input.addEventListener("blur", () => {
if (input.classList.contains("invalid")) {
input.value = state.coefficients[index];
input.classList.remove("invalid");
input.setCustomValidity("");
state.invalid = false;
setMessage(
"neutral",
"Invalid entry discarded",
"The previous valid coefficient was restored."
);
updateBalance();
}
});
});
/*
Formulas are static elements rather than editable controls.
A MutationObserver also restores them if external code attempts to
change their text, keeping formula editing from being a shortcut.
*/
const restoreFormulas = () => {
equationElement
.querySelectorAll(".formula[data-formula]")
.forEach((formulaElement) => {
const expected = SPECIES[formulaElement.dataset.formula].formula;
if (formulaElement.textContent !== expected) {
formulaElement.textContent = expected;
}
});
};
const observer = new MutationObserver(restoreFormulas);
observer.observe(equationElement, {
childList: true,
subtree: true,
characterData: true
});
}
function computeCounts() {
const left = {};
const right = {};
const elements = reactionElements(state.reaction);
for (const element of elements) {
left[element] = 0;
right[element] = 0;
}
state.reaction.reactants.forEach((key, index) => {
const coefficient = state.coefficients[index] || 1;
for (const [element, count] of Object.entries(SPECIES[key].atoms)) {
left[element] += count * coefficient;
}
});
state.reaction.products.forEach((key, productIndex) => {
const index = state.reaction.reactants.length + productIndex;
const coefficient = state.coefficients[index] || 1;
for (const [element, count] of Object.entries(SPECIES[key].atoms)) {
right[element] += count * coefficient;
}
});
return { left, right, elements };
}
function updateBalance() {
const { left, right, elements } = computeCounts();
elementCountsElement.innerHTML = elements.map((element) => {
const delta = left[element] - right[element];
const deltaText = delta > 0 ? `+${delta}` : `${delta}`;
return `
<tr>
<td>
<span class="element-cell">
<span
class="element-dot"
style="background:${ELEMENT_COLORS[element]}"
></span>
${element}
</span>
</td>
<td>${left[element]}</td>
<td>${right[element]}</td>
<td>
<span class="delta ${delta === 0 ? "match" : "mismatch"}">
${deltaText}
</span>
</td>
</tr>
`;
}).join("");
const leftTotal = Object.values(left).reduce((sum, count) => sum + count, 0);
const rightTotal = Object.values(right).reduce((sum, count) => sum + count, 0);
leftTotalElement.textContent = leftTotal;
rightTotalElement.textContent = rightTotal;
const conserved = elements.filter(
(element) => left[element] === right[element]
).length;
stageStatus.className = "stage-status";
if (state.invalid) {
stageStatus.classList.add("warning");
stageStatusText.textContent = "CHECK COEFFICIENTS";
} else if (conserved === elements.length) {
stageStatus.classList.add("success");
stageStatusText.textContent = "ALL ELEMENTS MATCH";
} else {
stageStatusText.textContent =
`${conserved}/${elements.length} ELEMENTS MATCH`;
}
legendElement.innerHTML = elements.map((element) => `
<span class="legend-item">
<i style="background:${ELEMENT_COLORS[element]}"></i>
${element}
</span>
`).join("");
}
function verifyBalance() {
if (state.invalid) {
setMessage(
"warning",
"Fix the highlighted coefficient",
"Verification requires positive whole-number coefficients."
);
return;
}
const { left, right, elements } = computeCounts();
const mismatches = elements.filter(
(element) => left[element] !== right[element]
);
if (mismatches.length === 0) {
const details = elements
.map((element) => `${element}: ${left[element]} = ${right[element]}`)
.join(" · ");
setMessage(
"success",
"Balanced — every element is conserved",
details
);
} else {
const details = mismatches.map((element) => {
const delta = left[element] - right[element];
if (delta > 0) {
return `${element}: reactants have ${delta} extra atom${delta === 1 ? "" : "s"}`;
}
const amount = Math.abs(delta);
return `${element}: products have ${amount} extra atom${amount === 1 ? "" : "s"}`;
}).join(" · ");
setMessage(
"failure",
"Not balanced yet",
details
);
}
}
function resetCoefficients() {
const inputs = equationElement.querySelectorAll("input[data-index]");
state.coefficients = state.coefficients.map(() => 1);
state.invalid = false;
inputs.forEach((input) => {
input.value = "1";
input.classList.remove("invalid");
input.setCustomValidity("");
});
setMessage(
"neutral",
"Coefficients reset",
"All coefficients are back to 1. Build the ratio from atom counts."
);
updateBalance();
renderMolecules();
}
function switchReaction(reactionId) {
const nextReaction = REACTIONS.find(
(reaction) => reaction.id === reactionId
) || REACTIONS[0];
state.reaction = nextReaction;
state.invalid = false;
state.hintVisible = false;
reactionTitle.textContent = nextReaction.name;
reactionDescription.textContent = nextReaction.description;
document.getElementById("stageTitle").textContent = nextReaction.name;
document.getElementById("hintText").textContent = nextReaction.hint;
document.getElementById("hintText").hidden = true;
document.getElementById("hintToggle").textContent = "Show";
document.getElementById("hintButton").setAttribute("aria-expanded", "false");
renderEquation();
updateBalance();
renderMolecules();
setMessage(
"neutral",
"Set your coefficients",
"The atom counts update live. Verify when you are ready."
);
}
/* ---------------------------------------------------------------
Three.js voxel scene
--------------------------------------------------------------- */
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 20, 42);
const camera = new THREE.PerspectiveCamera(
43,
1,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D molecular field. Use pointer drag or arrow keys to rotate, and scroll or plus and minus keys to zoom."
);
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xbfe7ff,
0x142033,
2.15
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(5, 9, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x55d9f5, 1.8);
rimLight.position.set(-7, 2, -6);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa86b, 11, 20, 2);
warmLight.position.set(7, -1, 4);
scene.add(warmLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(44, 44),
new THREE.ShadowMaterial({ opacity: 0.24 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.05;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(36, 36, 0x23405a, 0x12283d);
grid.position.y = -3.02;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
const moleculeRoot = new THREE.Group();
scene.add(moleculeRoot);
const unitBoxGeometry = new THREE.BoxGeometry(1, 1, 1);
const unitEdgesGeometry = new THREE.EdgesGeometry(unitBoxGeometry);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x06101d,
transparent: true,
opacity: 0.62
});
const bondMaterial = new THREE.MeshStandardMaterial({
color: 0x91a5b9,
roughness: 0.5,
metalness: 0.22
});
const atomMaterials = {};
const atomSizes = {
H: 0.48,
C: 0.62,
N: 0.62,
O: 0.66
};
for (const [element, color] of Object.entries(ELEMENT_COLORS)) {
const baseColor = new THREE.Color(color);
const emissive = baseColor.clone().multiplyScalar(0.11);
atomMaterials[element] = new THREE.MeshStandardMaterial({
color: baseColor,
emissive,
emissiveIntensity: 0.72,
roughness: 0.29,
metalness: 0.08
});
}
function addAtom(parent, element, position) {
const atom = new THREE.Mesh(
unitBoxGeometry,
atomMaterials[element]
);
atom.position.set(...position);
atom.scale.setScalar(atomSizes[element]);
atom.castShadow = true;
atom.receiveShadow = true;
const edges = new THREE.LineSegments(
unitEdgesGeometry,
edgeMaterial
);
atom.add(edges);
parent.add(atom);
}
function addBond(parent, start, end) {
const from = new THREE.Vector3(...start);
const to = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(to, from);
const length = direction.length();
if (length < 0.001) return;
const geometry = new THREE.BoxGeometry(0.12, 0.12, length);
const bond = new THREE.Mesh(geometry, bondMaterial);
bond.userData.ownGeometry = true;
bond.position.copy(from).add(to).multiplyScalar(0.5);
bond.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
bond.castShadow = true;
parent.add(bond);
}
function addMolecule(parent, speciesKey) {
const species = SPECIES[speciesKey];
const molecule = new THREE.Group();
for (const atom of species.layout.atoms) {
addAtom(molecule, atom.element, atom.position);
}
for (const [startIndex, endIndex] of species.layout.bonds) {
addBond(
molecule,
species.layout.atoms[startIndex].position,
species.layout.atoms[endIndex].position
);
}
parent.add(molecule);
return molecule;
}
function roundedRect(context, x, y, width, height, radius) {
if (typeof context.roundRect === "function") {
context.roundRect(x, y, width, height, radius);
} else {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
}
function makeLabelSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(7, 17, 31, 0.88)";
context.strokeStyle = "rgba(91, 126, 158, 0.48)";
context.lineWidth = 3;
roundedRect(context, 12, 12, 488, 88, 18);
context.fill();
context.stroke();
context.fillStyle = "#eaf6ff";
context.font = "700 43px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 57);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.45, 0.54, 1);
sprite.renderOrder = 20;
sprite.userData.ownMaterial = true;
return sprite;
}
function disposeMoleculeGroup(group) {
group.traverse((object) => {
if (object.userData.ownGeometry && object.geometry) {
object.geometry.dispose();
}
if (object.userData.ownMaterial && object.material) {
if (object.material.map) {
object.material.map.dispose();
}
object.material.dispose();
}
});
group.clear();
}
function rowPositions(count) {
if (count === 1) return [0];
if (count === 2) return [1.48, -1.48];
return Array.from(
{ length: count },
(_, index) => 1.48 - index * (2.96 / (count - 1))
);
}
function buildSide(sideKeys, side, coefficientOffset) {
const rows = rowPositions(sideKeys.length);
const baseX = side === "left" ? -4.25 : 4.25;
sideKeys.forEach((key, sideIndex) => {
const species = SPECIES[key];
const coefficient = state.coefficients[coefficientOffset + sideIndex];
const group = new THREE.Group();
const xPositions = species.layout.atoms.map((atom) => atom.position[0]);
const moleculeWidth =
Math.max(...xPositions) - Math.min(...xPositions) + 1.1;
const spacing = moleculeWidth + 0.72;
for (let copyIndex = 0; copyIndex < coefficient; copyIndex++) {
const molecule = addMolecule(group, key);
const xOffset =
(copyIndex - (coefficient - 1) / 2) * spacing;
molecule.position.x = xOffset;
}
const labelText =
`${species.formula} ×${coefficient}`;
const label = makeLabelSprite(labelText);
label.position.set(0, 1.18, 0);
group.add(label);
group.position.set(baseX, rows[sideIndex], 0);
moleculeRoot.add(group);
});
}
function renderMolecules() {
disposeMoleculeGroup(moleculeRoot);
buildSide(
state.reaction.reactants,
"left",
0
);
buildSide(
state.reaction.products,
"right",
state.reaction.reactants.length
);
}
/* Voxel reaction arrow */
const arrowGroup = new THREE.Group();
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0x55d9f5,
emissive: 0x1a819c,
emissiveIntensity: 1.1,
roughness: 0.34,
metalness: 0.08
});
const arrowPixels = [
[-0.78, 0],
[-0.48, 0],
[-0.18, 0],
[0.12, 0],
[0.42, 0],
[0.72, 0],
[0.42, 0.30],
[0.12, 0.60],
[0.42, -0.30],
[0.12, -0.60]
];
for (const [x, y] of arrowPixels) {
const pixel = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.25, 0.25),
arrowMaterial
);
pixel.position.set(x, y, 0);
pixel.castShadow = true;
arrowGroup.add(pixel);
}
scene.add(arrowGroup);
/* ---------------------------------------------------------------
Direct camera controls — no examples or addons
--------------------------------------------------------------- */
const view = {
target: new THREE.Vector3(0, 0, 0),
radius: 16,
theta: 0,
phi: 1.22,
userAdjusted: false
};
function fittedRadius() {
const aspect = camera.aspect || 1;
const halfFovRadians = THREE.MathUtils.degToRad(camera.fov / 2);
const desiredHalfWidth = 8.6;
return Math.max(
14.5,
desiredHalfWidth / (Math.tan(halfFovRadians) * aspect)
);
}
function applyCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
function resetView() {
view.theta = 0;
view.phi = 1.22;
view.radius = fittedRadius();
view.userAdjusted = false;
applyCamera();
}
function resizeRenderer() {
const width = Math.max(sceneHost.clientWidth, 1);
const height = Math.max(sceneHost.clientHeight, 1);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
if (!view.userAdjusted) {
view.radius = fittedRadius();
}
applyCamera();
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
view.userAdjusted = true;
view.theta -= deltaX * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi + deltaY * 0.005,
0.42,
2.55
);
applyCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.userAdjusted = true;
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
9,
42
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
view.theta -= 0.12;
break;
case "ArrowRight":
view.theta += 0.12;
break;
case "ArrowUp":
view.phi = Math.max(0.42, view.phi - 0.08);
break;
case "ArrowDown":
view.phi = Math.min(2.55, view.phi + 0.08);
break;
case "+":
case "=":
view.radius = Math.max(9, view.radius - 1);
break;
case "-":
case "_":
view.radius = Math.min(42, view.radius + 1);
break;
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
view.userAdjusted = true;
applyCamera();
}
});
document.getElementById("resetView").addEventListener("click", resetView);
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(sceneHost);
/* ---------------------------------------------------------------
UI wiring and animation
--------------------------------------------------------------- */
buildReactionOptions();
reactionSelect.addEventListener("change", () => {
switchReaction(reactionSelect.value);
});
document.getElementById("verifyButton").addEventListener(
"click",
verifyBalance
);
document.getElementById("resetButton").addEventListener(
"click",
resetCoefficients
);
document.getElementById("hintButton").addEventListener("click", () => {
state.hintVisible = !state.hintVisible;
document.getElementById("hintText").hidden = !state.hintVisible;
document.getElementById("hintToggle").textContent =
state.hintVisible ? "Hide" : "Show";
document.getElementById("hintButton").setAttribute(
"aria-expanded",
String(state.hintVisible)
);
});
switchReaction(state.reaction.id);
resizeRenderer();
function animate(time) {
requestAnimationFrame(animate);
arrowGroup.position.y = Math.sin(time * 0.0022) * 0.075;
arrowGroup.children.forEach((pixel, index) => {
const pulse =
0.94 +
Math.sin(time * 0.003 + index * 0.35) * 0.055;
pixel.scale.setScalar(pulse);
});
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```