Prompt specification
Build or customize the Three.js 3D scene "Habitat Restoration Strategy Island" 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: Habitat Restoration Strategy Island
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/habitat-restoration-strategy-island-x3535
Scene Description Prompt:
Build a voxel island strategy game where restored habitats affect fictional species populations under explicit game rules. Three.js from cdnjs, one HTML file.
Working Three.js Starter (habitat-restoration-strategy-island-x3535):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Verdant Archipelago</title>
<style>
:root {
--ink: #172a28;
--ink-2: #203936;
--panel: #f5f1e6;
--panel-2: #ebe5d6;
--line: rgba(29, 55, 49, 0.14);
--muted: #68756e;
--green: #326c58;
--green-2: #4d8b6e;
--mint: #a9c9a5;
--gold: #d4a94e;
--coral: #c96f56;
--blue: #4f8fa8;
--shadow: 0 18px 45px rgba(14, 38, 33, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d4e0d7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
width: 100%;
height: 100vh;
display: grid;
grid-template-columns: 270px minmax(420px, 1fr) 340px;
grid-template-rows: 72px minmax(0, 1fr);
}
header {
grid-column: 1 / -1;
display: flex;
align-items: center;
gap: 20px;
min-width: 0;
padding: 0 22px;
color: #edf4e8;
background:
linear-gradient(90deg, rgba(255,255,255,0.025), transparent 28%),
#18342f;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
z-index: 20;
box-shadow: 0 6px 22px rgba(10, 30, 26, 0.2);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 260px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
transform: rotate(-8deg);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
inset: 5px;
border-radius: 5px;
background: #9fc08d;
box-shadow: inset -7px -7px 0 rgba(27, 71, 54, 0.4);
}
.brand-mark::after {
inset: 11px 13px 13px 11px;
background: #d1b65e;
box-shadow: none;
}
.brand h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 600;
letter-spacing: 0.055em;
line-height: 1;
}
.brand small {
display: block;
margin-top: 5px;
color: #9db2a7;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.21em;
text-transform: uppercase;
}
.header-spacer {
flex: 1;
}
.header-stat {
display: flex;
align-items: center;
gap: 10px;
min-height: 38px;
padding: 0 14px;
border-left: 1px solid rgba(255, 255, 255, 0.11);
}
.header-stat .label {
color: #91a99f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.header-stat .value {
font-family: Georgia, serif;
font-size: 20px;
font-variant-numeric: tabular-nums;
}
.season-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 4px rgba(212, 169, 78, 0.12);
}
.header-button,
.primary-button {
border: 0;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}
.header-button {
padding: 10px 13px;
color: #d8e5db;
background: rgba(255, 255, 255, 0.06);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.header-button:hover {
background: rgba(255, 255, 255, 0.1);
}
.primary-button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 10px;
min-height: 42px;
padding: 0 18px;
color: #17332b;
background: #c5d69e;
border-radius: 8px;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.065em;
text-transform: uppercase;
box-shadow: 0 5px 16px rgba(6, 20, 16, 0.22);
}
.primary-button:hover:not(:disabled) {
transform: translateY(-1px);
background: #d7e3b8;
}
.primary-button:disabled {
opacity: 0.45;
cursor: not-allowed;
}
.advance-button {
color: #17332b;
background: #d6b968;
}
.advance-button:hover:not(:disabled) {
background: #e3ca82;
}
aside {
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: rgba(50, 108, 88, 0.25) transparent;
}
.left-panel {
padding: 22px 19px;
background: #eee9dc;
border-right: 1px solid var(--line);
z-index: 5;
}
.right-panel {
padding: 22px;
background: var(--panel);
border-left: 1px solid var(--line);
z-index: 5;
}
.eyebrow {
margin: 0 0 8px;
color: var(--green-2);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.mission-title {
margin: 0;
font-family: Georgia, serif;
font-size: 25px;
font-weight: 600;
line-height: 1.08;
}
.mission-copy {
margin: 10px 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.objective {
margin-bottom: 23px;
padding-bottom: 21px;
border-bottom: 1px solid var(--line);
}
.objective-row {
margin-top: 13px;
}
.objective-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 6px;
color: #4a5d55;
font-size: 10px;
font-weight: 700;
}
.objective-label strong {
color: var(--ink);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.progress-track {
height: 5px;
overflow: hidden;
background: #d8d4c8;
border-radius: 8px;
}
.progress-fill {
width: 0;
height: 100%;
background: var(--green-2);
border-radius: inherit;
transition: width 350ms ease;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.section-heading h3 {
margin: 0;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.tiny-note {
color: var(--muted);
font-size: 9px;
}
.species-list {
display: grid;
gap: 8px;
}
.species-card {
display: grid;
grid-template-columns: 36px 1fr auto;
align-items: center;
gap: 10px;
padding: 10px;
background: rgba(255, 255, 255, 0.47);
border: 1px solid rgba(30, 59, 51, 0.09);
border-radius: 9px;
}
.species-icon {
display: grid;
place-items: center;
width: 36px;
height: 36px;
color: white;
border-radius: 8px;
font-family: Georgia, serif;
font-size: 11px;
font-weight: 800;
letter-spacing: -0.03em;
box-shadow: inset -6px -6px 0 rgba(0, 0, 0, 0.09);
}
.species-name {
font-size: 12px;
font-weight: 800;
}
.species-biome {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.species-number {
text-align: right;
font-family: Georgia, serif;
font-size: 18px;
font-variant-numeric: tabular-nums;
}
.trend {
display: block;
margin-top: 2px;
color: var(--green-2);
font-family: Inter, sans-serif;
font-size: 9px;
font-weight: 800;
}
.trend.down {
color: var(--coral);
}
.journal {
margin-top: 22px;
}
.journal-list {
display: grid;
gap: 10px;
margin: 0;
padding: 0;
list-style: none;
}
.journal-list li {
position: relative;
padding-left: 15px;
color: #68736d;
font-size: 10px;
line-height: 1.45;
}
.journal-list li::before {
content: "";
position: absolute;
left: 0;
top: 5px;
width: 5px;
height: 5px;
background: var(--gold);
border-radius: 50%;
}
.journal-time {
display: block;
margin-bottom: 2px;
color: #9a9f94;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #bcd4ca;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.stage-top {
position: absolute;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
z-index: 3;
}
.stage-chip {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
color: #25483f;
background: rgba(248, 245, 233, 0.82);
border: 1px solid rgba(255, 255, 255, 0.52);
border-radius: 7px;
box-shadow: 0 6px 20px rgba(25, 57, 48, 0.08);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.stage-chip .dot {
width: 6px;
height: 6px;
background: var(--green-2);
border-radius: 50%;
}
.stage-actions {
display: flex;
gap: 7px;
pointer-events: auto;
}
.stage-button {
padding: 8px 10px;
color: #315149;
background: rgba(248, 245, 233, 0.85);
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 7px;
cursor: pointer;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.stage-button.active {
color: white;
background: var(--green);
}
.stage-bottom {
position: absolute;
left: 18px;
right: 18px;
bottom: 17px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
pointer-events: none;
z-index: 3;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
max-width: 460px;
padding: 9px 11px;
color: #36564e;
background: rgba(248, 245, 233, 0.78);
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 8px;
backdrop-filter: blur(8px);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-swatch {
width: 8px;
height: 8px;
border-radius: 2px;
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.1);
}
.control-hint {
padding: 8px 10px;
color: rgba(30, 60, 51, 0.72);
background: rgba(248, 245, 233, 0.55);
border-radius: 7px;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
#toast {
position: absolute;
left: 50%;
bottom: 78px;
z-index: 8;
max-width: 90%;
padding: 11px 16px;
color: #eff6e9;
background: rgba(24, 52, 47, 0.92);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 650;
text-align: center;
opacity: 0;
transform: translate(-50%, 10px);
transition: opacity 180ms ease, transform 180ms ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.dossier-title {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.dossier-title h2 {
margin: 0;
font-family: Georgia, serif;
font-size: 26px;
font-weight: 600;
line-height: 1.05;
}
.coordinate {
flex: 0 0 auto;
padding: 5px 7px;
color: var(--muted);
background: #e5e0d3;
border-radius: 5px;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.1em;
}
.biome-description {
margin: 10px 0 18px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.quality-card {
display: grid;
grid-template-columns: 84px 1fr;
align-items: center;
gap: 15px;
padding: 14px;
background: #e8e5d9;
border: 1px solid rgba(27, 54, 47, 0.08);
border-radius: 10px;
}
.quality-score {
font-family: Georgia, serif;
font-size: 36px;
line-height: 1;
}
.quality-score small {
color: var(--muted);
font-family: Inter, sans-serif;
font-size: 9px;
font-weight: 800;
}
.quality-caption {
margin-bottom: 7px;
color: #53665e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.detail-section {
margin-top: 21px;
padding-top: 19px;
border-top: 1px solid var(--line);
}
.detail-section h3 {
margin: 0 0 12px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.meter-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #53655d;
font-size: 10px;
font-weight: 700;
}
.meter-label strong {
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.population-panel {
display: grid;
grid-template-columns: 44px 1fr;
gap: 12px;
align-items: center;
padding: 13px;
background: white;
border: 1px solid var(--line);
border-radius: 9px;
}
.population-panel .species-icon {
width: 44px;
height: 44px;
}
.population-main {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
.population-main strong {
font-family: Georgia, serif;
font-size: 23px;
font-variant-numeric: tabular-nums;
}
.forecast {
padding: 3px 7px;
color: var(--green-2);
background: #e4eee1;
border-radius: 4px;
font-size: 9px;
font-weight: 850;
}
.forecast.down {
color: var(--coral);
background: #f3e3dc;
}
.population-meta {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.restore-card {
margin-top: 20px;
padding: 15px;
color: #eaf2e7;
background:
linear-gradient(135deg, rgba(255,255,255,0.045), transparent),
var(--ink-2);
border-radius: 10px;
box-shadow: 0 10px 24px rgba(23, 42, 40, 0.12);
}
.restore-card h3 {
margin: 0 0 5px;
color: white;
font-family: Georgia, serif;
font-size: 17px;
font-weight: 600;
}
.restore-card p {
margin: 0 0 13px;
color: #aebfb6;
font-size: 10px;
line-height: 1.5;
}
.restore-button {
width: 100%;
color: #19352c;
background: #c4d79b;
}
.restore-button:hover:not(:disabled) {
background: #d5e1b9;
}
.cost-note {
margin-top: 9px;
color: #9fb2a9;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.07em;
text-align: center;
text-transform: uppercase;
}
.empty-dossier {
display: grid;
place-items: center;
min-height: 70vh;
color: var(--muted);
text-align: center;
}
.modal {
position: fixed;
inset: 0;
z-index: 100;
display: none;
align-items: center;
justify-content: center;
padding: 24px;
background: rgba(13, 32, 28, 0.58);
backdrop-filter: blur(8px);
}
.modal.open {
display: flex;
}
.modal-card {
width: min(720px, 100%);
max-height: 90vh;
overflow: auto;
padding: 28px;
background: #f6f1e5;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 14px;
box-shadow: 0 30px 90px rgba(9, 27, 23, 0.4);
}
.modal-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
margin-bottom: 18px;
}
.modal-header h2 {
margin: 0;
font-family: Georgia, serif;
font-size: 29px;
font-weight: 600;
}
.modal-header p {
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.close-button {
width: 34px;
height: 34px;
flex: 0 0 auto;
color: var(--ink);
background: #e6e1d4;
border: 0;
border-radius: 50%;
cursor: pointer;
font-size: 19px;
}
.rule-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.rule-card {
padding: 15px;
background: rgba(255, 255, 255, 0.5);
border: 1px solid var(--line);
border-radius: 9px;
}
.rule-card h3 {
margin: 0 0 8px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.rule-card p,
.rule-card li {
color: #5b6b63;
font-size: 10px;
line-height: 1.6;
}
.rule-card p {
margin: 0;
}
.rule-card ul {
margin: 0;
padding-left: 16px;
}
.formula {
display: block;
margin-top: 10px;
padding: 9px;
color: #29483f;
background: #e4eadc;
border-radius: 6px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
line-height: 1.5;
}
.modal-footer {
display: flex;
justify-content: flex-end;
margin-top: 18px;
}
.result-card {
text-align: center;
}
.result-seal {
display: grid;
place-items: center;
width: 76px;
height: 76px;
margin: 0 auto 18px;
color: #f8f2df;
background: var(--green);
border-radius: 18px;
font-size: 32px;
box-shadow: 0 12px 30px rgba(38, 91, 72, 0.25);
}
@media (max-width: 1120px) {
#app {
grid-template-columns: 230px minmax(380px, 1fr) 300px;
}
.right-panel {
padding: 18px;
}
.brand {
min-width: 220px;
}
}
@media (max-width: 900px) {
#app {
grid-template-columns: minmax(380px, 1fr) 300px;
}
.left-panel {
display: none;
}
.brand {
min-width: auto;
}
.header-stat {
display: none;
}
}
@media (max-width: 680px) {
#app {
display: block;
overflow: auto;
}
header {
position: sticky;
top: 0;
height: 64px;
}
.brand small,
.header-button {
display: none;
}
.stage {
height: 62vh;
min-height: 430px;
}
.right-panel {
min-height: 600px;
border-left: 0;
}
.rule-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark"></div>
<div>
<h1>VERDANT ARCHIPELAGO</h1>
<small>Island restoration strategy</small>
</div>
</div>
<div class="header-spacer"></div>
<div class="header-stat">
<span class="season-dot"></span>
<div>
<div class="label">Season</div>
<div class="value" id="season-value">1</div>
</div>
</div>
<div class="header-stat">
<div>
<div class="label">Stewardship credits</div>
<div class="value" id="credit-value">240</div>
</div>
</div>
<button class="header-button" id="rules-button">Rules</button>
<button class="primary-button advance-button" id="advance-button">Advance season →</button>
</header>
<aside class="left-panel">
<section class="objective">
<p class="eyebrow">Council brief · Season <span id="brief-season">1</span></p>
<h2 class="mission-title">Bring the island back.</h2>
<p class="mission-copy">
Restore damaged habitats, reconnect neighboring ecosystems, and keep all four
fictional species populations stable.
</p>
<div class="objective-row">
<div class="objective-label">
<span>Habitats restored</span>
<strong id="restore-progress-text">0 / 8</strong>
</div>
<div class="progress-track">
<div class="progress-fill" id="restore-progress"></div>
</div>
</div>
<div class="objective-row">
<div class="objective-label">
<span>Average habitat quality</span>
<strong id="quality-progress-text">0 / 57</strong>
</div>
<div class="progress-track">
<div class="progress-fill" id="quality-progress"></div>
</div>
</div>
<div class="objective-row">
<div class="objective-label">
<span>Stable species</span>
<strong id="species-progress-text">0 / 4</strong>
</div>
<div class="progress-track">
<div class="progress-fill" id="species-progress"></div>
</div>
</div>
</section>
<section>
<div class="section-heading">
<h3>Species census</h3>
<span class="tiny-note">Island totals</span>
</div>
<div class="species-list" id="species-list"></div>
</section>
<section class="journal">
<div class="section-heading">
<h3>Field journal</h3>
<span class="tiny-note">Latest entries</span>
</div>
<ul class="journal-list" id="journal-list"></ul>
</section>
</aside>
<main class="stage">
<div id="viewport"></div>
<div class="stage-top">
<div class="stage-chip">
<span class="dot"></span>
Living island · 12 × 12 survey
</div>
<div class="stage-actions">
<button class="stage-button" id="population-toggle">Populations</button>
<button class="stage-button" id="reset-camera">Reset view</button>
</div>
</div>
<div class="stage-bottom">
<div class="legend">
<span class="legend-item"><i class="legend-swatch" style="background:#78975a"></i>Meadow</span>
<span class="legend-item"><i class="legend-swatch" style="background:#426748"></i>Forest</span>
<span class="legend-item"><i class="legend-swatch" style="background:#5f9382"></i>Wetland</span>
<span class="legend-item"><i class="legend-swatch" style="background:#d2bd88"></i>Coast</span>
<span class="legend-item"><i class="legend-swatch" style="background:#898778"></i>Ruins</span>
</div>
<div class="control-hint">Drag to orbit · Scroll to zoom · Click a tile</div>
</div>
<div id="toast"></div>
</main>
<aside class="right-panel" id="inspector"></aside>
</div>
<div class="modal" id="rules-modal" role="dialog" aria-modal="true" aria-labelledby="rules-title">
<div class="modal-card">
<div class="modal-header">
<div>
<p class="eyebrow">Field manual</p>
<h2 id="rules-title">How the island responds</h2>
<p>
All species and numerical relationships in this game are fictional. The rules
are deterministic so every restoration can be traced to a population change.
</p>
</div>
<button class="close-button" id="close-rules" aria-label="Close rules">×</button>
</div>
<div class="rule-grid">
<section class="rule-card">
<h3>Restoration</h3>
<ul>
<li>Select any island tile to inspect it.</li>
<li>Each restoration adds 25 restoration points, up to 100.</li>
<li>Repeating an action costs 8 additional credits.</li>
<li>Clearing ruins converts that tile to meadow and sets restoration to 50.</li>
<li>Restoration changes habitat quality immediately; populations change next season.</li>
</ul>
</section>
<section class="rule-card">
<h3>Credits and seasons</h3>
<p>
Start with 240 credits. Each season grants
<strong>16 + 3 × stable species</strong> credits.
There is no credit limit. Advancing seasons is always allowed.
</p>
</section>
<section class="rule-card">
<h3>Habitat quality</h3>
<p>Quality is calculated for every tile from its biome, restoration, and neighbors.</p>
<span class="formula">
Q = clamp(base + 0.60R + 2S − 2U, 0, 100)<br>
R = restoration points<br>
S = matching-biome orthogonal neighbors<br>
U = adjacent ruins
</span>
</section>
<section class="rule-card">
<h3>Carrying capacity</h3>
<p>
Each species has one preferred biome. Capacity is the species’ tile capacity
multiplied by habitat quality.
</p>
<span class="formula">
C = species capacity × Q / 100<br>
P is always constrained to 0 ≤ P ≤ C
</span>
</section>
<section class="rule-card">
<h3>Population change</h3>
<p>
Growth depends on quality. A matching neighbor provides immigration, and new
restoration produces a temporary population pulse.
</p>
<span class="formula">
If Q ≥ 45:<br>
ΔP = round(P × growth × (Q − 45) / 100)<br>
If Q < 45:<br>
ΔP = −round(P × growth × (45 − Q) / 100)<br>
Add +1 for a matching neighbor with P ≥ 4<br>
Add floor(R / 25), maximum +3
</span>
</section>
<section class="rule-card">
<h3>Council victory</h3>
<ul>
<li>Restore at least 8 different tiles.</li>
<li>Reach an average island habitat quality of 57.</li>
<li>Keep every species population at or above 60.</li>
<li>Finish within 8 seasons for the best stewardship rating.</li>
</ul>
</section>
</div>
<div class="modal-footer">
<button class="primary-button" id="rules-done">Return to island</button>
</div>
</div>
</div>
<div class="modal" id="result-modal" role="dialog" aria-modal="true">
<div class="modal-card result-card">
<div class="result-seal">✓</div>
<p class="eyebrow">Council commendation</p>
<h2>The island is recovering.</h2>
<p class="mission-copy">
Your restoration plan has reconnected enough habitats to support all four species.
Continue playing to build a larger, more resilient population.
</p>
<div class="modal-footer">
<button class="primary-button" id="result-done">Keep restoring</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";
// ---------------------------------------------------------------------------
// Game data and deterministic map generation
// ---------------------------------------------------------------------------
const GRID_SIZE = 12;
const CELL_SIZE = 1.18;
const species = {
sunhopper: {
id: "sunhopper",
name: "Sunhopper",
short: "SH",
biome: "meadow",
color: "#d19c3f",
capacity: 16,
growth: 0.30,
description: "A tall-eared grazer that favors flowering meadow."
},
mossback: {
id: "mossback",
name: "Mossback",
short: "MB",
biome: "forest",
color: "#39765f",
capacity: 12,
growth: 0.24,
description: "A slow forest browser with a moss-colored shell."
},
reedling: {
id: "reedling",
name: "Reedling",
short: "RL",
biome: "wetland",
color: "#4d91a8",
capacity: 14,
growth: 0.27,
description: "A wading bird that nests among dense reeds."
},
shellwing: {
id: "shellwing",
name: "Shellwing",
short: "SW",
biome: "coast",
color: "#bf6d58",
capacity: 11,
growth: 0.22,
description: "A shoreline crustacean that shelters in shell banks."
}
};
const biomeInfo = {
meadow: {
name: "Sunlit Meadow",
species: "sunhopper",
color: "#78975a",
baseQuality: 48,
action: "Sow native meadow mix",
description: "Open grassland with scattered flowers and warm soil.",
cost: 28
},
forest: {
name: "Mosswood Forest",
species: "mossback",
color: "#426748",
baseQuality: 58,
action: "Plant native grove",
description: "Dense old-growth trees with a cool, shaded understory.",
cost: 32
},
wetland: {
name: "Reed Wetland",
species: "reedling",
color: "#5f9382",
baseQuality: 54,
action: "Reconnect water channels",
description: "Shallow pools and reed beds divided by old embankments.",
cost: 34
},
coast: {
name: "Shell Coast",
species: "shellwing",
color: "#d2bd88",
baseQuality: 44,
action: "Restore nesting bank",
description: "Pale sand and shell fragments along the island’s outer rim.",
cost: 30
},
ruins: {
name: "Abandoned Works",
species: null,
color: "#898778",
baseQuality: 12,
action: "Clear ruins and replant",
description: "Old civic structures now occupy a once-productive habitat.",
cost: 36
}
};
const state = {
season: 1,
credits: 240,
populationLayer: false,
selected: null,
hovered: null,
won: false,
lastDelta: {
sunhopper: 0,
mossback: 0,
reedling: 0,
shellwing: 0
},
journal: []
};
const tiles = [];
const tileMap = new Map();
const terrainMeshes = [];
function hash(i, j, salt = 0) {
const value = Math.sin(i * 127.1 + j * 311.7 + salt * 74.7) * 43758.5453123;
return value - Math.floor(value);
}
function keyFor(i, j) {
return `${i},${j}`;
}
function generateTiles() {
for (let i = 0; i < GRID_SIZE; i++) {
for (let j = 0; j < GRID_SIZE; j++) {
const nx = (i - (GRID_SIZE - 1) / 2) / 5.75;
const nz = (j - (GRID_SIZE - 1) / 2) / 4.85;
const edge = nx * nx + nz * nz + (hash(i, j, 1) - 0.5) * 0.13;
if (edge > 1.04) continue;
let height;
if (edge > 0.79) height = 0.28;
else if (edge > 0.60) height = 0.73;
else height = 1.05 + Math.floor(hash(i, j, 2) * 3) * 0.38;
const moisture = hash(i, j, 3);
const ruinsChance = hash(i, j, 4);
let biome;
if (edge < 0.84 && ruinsChance > 0.935) {
biome = "ruins";
} else if (edge > 0.79) {
biome = "coast";
} else if (moisture > 0.70) {
biome = "wetland";
} else if (moisture > 0.42) {
biome = "forest";
} else {
biome = "meadow";
}
const tile = {
i,
j,
x: (i - (GRID_SIZE - 1) / 2) * CELL_SIZE,
z: (j - (GRID_SIZE - 1) / 2) * CELL_SIZE,
height,
biome,
restoration: 0,
timesRestored: 0,
population: 0,
group: null,
terrain: null,
terrainMaterial: null,
decor: null,
marker: null,
label: null,
labelCanvas: null,
labelContext: null,
labelTexture: null
};
tiles.push(tile);
tileMap.set(keyFor(i, j), tile);
}
}
}
function getNeighbors(tile) {
const offsets = [
[1, 0],
[-1, 0],
[0, 1],
[0, -1]
];
return offsets
.map(([di, dj]) => tileMap.get(keyFor(tile.i + di, tile.j + dj)))
.filter(Boolean);
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function habitatQuality(tile) {
const neighbors = getNeighbors(tile);
const matching = neighbors.filter((neighbor) => neighbor.biome === tile.biome).length;
const ruins = neighbors.filter((neighbor) => neighbor.biome === "ruins").length;
const quality =
biomeInfo[tile.biome].baseQuality +
tile.restoration * 0.60 +
matching * 2 -
ruins * 2;
return Math.round(clamp(quality, 0, 100));
}
function carryingCapacity(tile, speciesId) {
const animal = species[speciesId];
if (!animal || tile.biome !== animal.biome) return 0;
return Math.floor(animal.capacity * habitatQuality(tile) / 100);
}
function initializePopulations() {
for (const tile of tiles) {
const speciesId = biomeInfo[tile.biome].species;
if (!speciesId) {
tile.population = 0;
continue;
}
const capacity = carryingCapacity(tile, speciesId);
tile.population = Math.max(1, Math.floor(capacity * 0.48));
}
}
function populationTotals() {
const totals = {
sunhopper: 0,
mossback: 0,
reedling: 0,
shellwing: 0
};
for (const tile of tiles) {
const speciesId = biomeInfo[tile.biome].species;
if (speciesId) totals[speciesId] += tile.population;
}
return totals;
}
function averageQuality() {
if (!tiles.length) return 0;
const sum = tiles.reduce((total, tile) => total + habitatQuality(tile), 0);
return Math.round(sum / tiles.length);
}
function stableSpeciesCount() {
const totals = populationTotals();
return Object.values(totals).filter((population) => population >= 60).length;
}
function restorationCost(tile) {
const base = biomeInfo[tile.biome].cost;
return base + Math.max(0, tile.timesRestored - 1) * 8;
}
// ---------------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#bcd3c8");
scene.fog = new THREE.Fog("#bcd3c8", 24, 48);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.8));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.6, 0);
let cameraAzimuth = 0.67;
let cameraElevation = 0.76;
let cameraZoom = 0.90;
function updateCamera() {
const radius = 28;
camera.position.set(
cameraTarget.x + Math.sin(cameraAzimuth) * Math.cos(cameraElevation) * radius,
cameraTarget.y + Math.sin(cameraElevation) * radius,
cameraTarget.z + Math.cos(cameraAzimuth) * Math.cos(cameraElevation) * radius
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resizeRenderer() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
const aspect = width / height;
const frustum = 16.5;
camera.left = -frustum * aspect / 2;
camera.right = frustum * aspect / 2;
camera.top = frustum / 2;
camera.bottom = -frustum / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
updateCamera();
}
new ResizeObserver(resizeRenderer).observe(viewport);
const hemisphere = new THREE.HemisphereLight("#eff8e9", "#36544a", 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cc", 3.1);
sun.position.set(9, 15, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight("#8ec7c3", 0.85);
fill.position.set(-10, 7, -8);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
})
);
}
return materialCache.get(color);
}
function addBox(parent, color, x, y, z, sx, sy, sz, customMaterial = null) {
const mesh = new THREE.Mesh(unitBox, customMaterial || material(color));
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const waterMaterial = new THREE.MeshStandardMaterial({
color: "#4b939c",
roughness: 0.35,
metalness: 0.08,
transparent: true,
opacity: 0.92
});
const water = new THREE.Mesh(new THREE.PlaneGeometry(36, 36), waterMaterial);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.08;
water.receiveShadow = true;
scene.add(water);
const deepWater = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({ color: "#75aeb0", roughness: 1 })
);
deepWater.rotation.x = -Math.PI / 2;
deepWater.position.y = -0.28;
scene.add(deepWater);
const waveMaterial = new THREE.MeshBasicMaterial({
color: "#d3e3d4",
transparent: true,
opacity: 0.23,
depthWrite: false
});
for (let i = 0; i < 75; i++) {
const x = (hash(i, 19, 1) - 0.5) * 24;
const z = (hash(i, 23, 2) - 0.5) * 21;
const width = 0.25 + hash(i, 29, 3) * 0.85;
const wave = addBox(scene, "#ffffff", x, 0.015, z, width, 0.018, 0.12, waveMaterial);
wave.castShadow = false;
wave.receiveShadow = false;
}
function drawLabel(tile) {
const context = tile.labelContext;
const texture = tile.labelTexture;
const speciesId = biomeInfo[tile.biome].species;
context.clearRect(0, 0, 160, 80);
context.fillStyle = "rgba(22, 47, 41, 0.88)";
context.beginPath();
context.roundRect(6, 8, 148, 64, 18);
context.fill();
context.fillStyle = speciesId ? species[speciesId].color : "#d4a94e";
context.fillRect(16, 24, 12, 32);
context.fillStyle = "#f6f0df";
context.font = "700 30px Georgia";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(
speciesId ? String(tile.population) : "RESTORE",
speciesId ? 91 : 88,
41
);
texture.needsUpdate = true;
}
function buildTile(tile) {
const group = new THREE.Group();
group.position.set(tile.x, 0, tile.z);
scene.add(group);
tile.group = group;
const terrainMaterial = new THREE.MeshStandardMaterial({
color: biomeInfo[tile.biome].color,
roughness: 0.96,
metalness: 0
});
const boxHeight = tile.height + 0.55;
const terrain = addBox(
group,
biomeInfo[tile.biome].color,
0,
(tile.height - 0.55) / 2,
0,
CELL_SIZE * 0.975,
boxHeight,
CELL_SIZE * 0.975,
terrainMaterial
);
terrain.userData.tile = tile;
terrainMeshes.push(terrain);
tile.terrain = terrain;
tile.terrainMaterial = terrainMaterial;
tile.decor = new THREE.Group();
group.add(tile.decor);
tile.marker = new THREE.Group();
group.add(tile.marker);
const markerPost = addBox(tile.marker, "#e5c767", 0.39, tile.height + 0.21, 0.39, 0.055, 0.42, 0.055);
markerPost.castShadow = false;
const markerFlag = addBox(tile.marker, "#f0d778", 0.48, tile.height + 0.39, 0.39, 0.23, 0.12, 0.055);
markerFlag.castShadow = false;
tile.marker.visible = false;
tile.labelCanvas = document.createElement("canvas");
tile.labelCanvas.width = 160;
tile.labelCanvas.height = 80;
tile.labelContext = tile.labelCanvas.getContext("2d");
tile.labelTexture = new THREE.CanvasTexture(tile.labelCanvas);
tile.labelTexture.colorSpace = THREE.SRGBColorSpace;
tile.label = new THREE.Sprite(
new THREE.SpriteMaterial({
map: tile.labelTexture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
tile.label.position.set(0, tile.height + 0.82, 0);
tile.label.scale.set(1.22, 0.61, 1);
tile.label.renderOrder = 20;
tile.label.visible = state.populationLayer;
group.add(tile.label);
drawLabel(tile);
updateTileVisual(tile, false);
}
function rebuildDecor(tile) {
tile.decor.clear();
const top = tile.height;
const vitality = tile.restoration / 100;
if (tile.biome === "forest") {
const treeCount = tile.restoration >= 25 ? 2 : 1;
for (let k = 0; k < treeCount; k++) {
const px = (hash(tile.i, tile.j, 10 + k) - 0.5) * 0.56;
const pz = (hash(tile.i, tile.j, 20 + k) - 0.5) * 0.56;
const size = 0.76 + hash(tile.i, tile.j, 30 + k) * 0.18 + vitality * 0.20;
addBox(tile.decor, "#654936", px, top + 0.27 * size, pz, 0.13 * size, 0.54 * size, 0.13 * size);
addBox(tile.decor, "#315b40", px, top + 0.61 * size, pz, 0.56 * size, 0.44 * size, 0.56 * size);
addBox(tile.decor, "#47734b", px, top + 0.90 * size, pz, 0.39 * size, 0.33 * size, 0.39 * size);
addBox(tile.decor, "#628b54", px - 0.08, top + 1.05 * size, pz + 0.03, 0.24 * size, 0.17 * size, 0.25 * size);
}
} else if (tile.biome === "meadow") {
for (let k = 0; k < 5; k++) {
const px = (hash(tile.i, tile.j, 40 + k) - 0.5) * 0.78;
const pz = (hash(tile.i, tile.j, 50 + k) - 0.5) * 0.78;
const h = 0.18 + hash(tile.i, tile.j, 60 + k) * 0.16;
addBox(tile.decor, "#547b47", px, top + h / 2, pz, 0.045, h, 0.045);
if (k % 2 === 0 || tile.restoration >= 25) {
const flowerColor = k % 3 === 0 ? "#e2bd58" : "#d8d6b7";
addBox(tile.decor, flowerColor, px, top + h + 0.045, pz, 0.10, 0.075, 0.10);
}
}
} else if (tile.biome === "wetland") {
addBox(tile.decor, "#6ca69a", 0, top + 0.02, 0, 0.88, 0.035, 0.88);
for (let k = 0; k < 7; k++) {
const px = (hash(tile.i, tile.j, 70 + k) - 0.5) * 0.72;
const pz = (hash(tile.i, tile.j, 80 + k) - 0.5) * 0.72;
const h = 0.28 + hash(tile.i, tile.j, 90 + k) * 0.27;
addBox(tile.decor, "#6f8448", px, top + h / 2, pz, 0.045, h, 0.045);
addBox(tile.decor, "#9b8350", px, top + h + 0.035, pz, 0.08, 0.12, 0.08);
}
} else if (tile.biome === "coast") {
for (let k = 0; k < 5; k++) {
const px = (hash(tile.i, tile.j, 100 + k) - 0.5) * 0.72;
const pz = (hash(tile.i, tile.j, 110 + k) - 0.5) * 0.72;
const size = 0.08 + hash(tile.i, tile.j, 120 + k) * 0.11;
addBox(tile.decor, k % 2 ? "#e9dfc4" : "#b3a98f", px, top + size / 2, pz, size, size * 0.7, size);
}
} else if (tile.biome === "ruins") {
addBox(tile.decor, "#6d6d65", -0.24, top + 0.34, -0.12, 0.28, 0.68, 0.28);
addBox(tile.decor, "#858276", 0.22, top + 0.24, 0.18, 0.27, 0.48, 0.27);
addBox(tile.decor, "#b0aa95", -0.24, top + 0.73, -0.12, 0.38, 0.12, 0.37);
addBox(tile.decor, "#79786e", 0.25, top + 0.51, 0.18, 0.34, 0.10, 0.34);
addBox(tile.decor, "#64675f", 0.02, top + 0.08, 0.03, 0.78, 0.12, 0.62);
}
}
function updateTileVisual(tile, rebuild = true) {
const baseColor = new THREE.Color(biomeInfo[tile.biome].color);
const restoredColor = new THREE.Color("#a4bd70");
baseColor.lerp(restoredColor, tile.restoration / 180);
tile.terrainMaterial.color.copy(baseColor);
tile.marker.visible = tile.restoration > 0;
if (rebuild) rebuildDecor(tile);
drawLabel(tile);
}
const highlightMaterial = new THREE.MeshBasicMaterial({
color: "#f2d477",
transparent: true,
opacity: 0.94,
depthTest: false
});
const hoverMaterial = new THREE.MeshBasicMaterial({
color: "#f5f0d7",
transparent: true,
opacity: 0.48,
depthTest: false
});
function makeHighlight(material) {
const group = new THREE.Group();
group.visible = false;
scene.add(group);
const thickness = 0.035;
const length = CELL_SIZE * 0.99;
addBox(group, "#ffffff", 0, 0, -length / 2, length, thickness, thickness, material).castShadow = false;
addBox(group, "#ffffff", 0, 0, length / 2, length, thickness, thickness, material).castShadow = false;
addBox(group, "#ffffff", -length / 2, 0, 0, thickness, thickness, length, material).castShadow = false;
addBox(group, "#ffffff", length / 2, 0, 0, thickness, thickness, length, material).castShadow = false;
return group;
}
const selectedHighlight = makeHighlight(highlightMaterial);
const hoverHighlight = makeHighlight(hoverMaterial);
function positionHighlight(group, tile) {
if (!tile) {
group.visible = false;
return;
}
group.position.set(tile.x, tile.height + 0.055, tile.z);
group.visible = true;
}
// ---------------------------------------------------------------------------
// Game mechanics
// ---------------------------------------------------------------------------
function addJournal(text) {
state.journal.unshift({
season: state.season,
text
});
state.journal = state.journal.slice(0, 6);
}
function restorationAction(tile) {
const cost = restorationCost(tile);
if (state.credits < cost) {
showToast("Not enough stewardship credits for this restoration.");
return;
}
if (tile.biome === "ruins") {
tile.biome = "meadow";
tile.restoration = 50;
tile.timesRestored = 1;
tile.population = 0;
} else {
tile.restoration = Math.min(100, tile.restoration + 25);
tile.timesRestored += 1;
}
state.credits -= cost;
updateTileVisual(tile);
addJournal(`${biomeInfo[tile.biome].action} completed in sector ${tile.i + 1}-${tile.j + 1}.`);
showToast(`${biomeInfo[tile.biome].action} · −${cost} credits`);
renderUI();
}
function forecastTile(tile) {
const speciesId = biomeInfo[tile.biome].species;
if (!speciesId) return { delta: 0, capacity: 0, quality: habitatQuality(tile) };
const animal = species[speciesId];
const quality = habitatQuality(tile);
const capacity = carryingCapacity(tile, speciesId);
const oldPopulation = tile.population;
let delta = quality >= 45
? Math.round(oldPopulation * animal.growth * (quality - 45) / 100)
: -Math.round(oldPopulation * animal.growth * (45 - quality) / 100);
const hasMigrantNeighbor = getNeighbors(tile).some(
(neighbor) =>
neighbor.biome === tile.biome &&
neighbor.population >= 4
);
if (hasMigrantNeighbor) delta += 1;
delta += Math.min(3, Math.floor(tile.restoration / 25));
const nextPopulation = clamp(oldPopulation + delta, 0, capacity);
return {
delta: nextPopulation - oldPopulation,
capacity,
quality,
speciesId
};
}
function advanceSeason() {
const before = populationTotals();
for (const tile of tiles) {
const speciesId = biomeInfo[tile.biome].species;
if (!speciesId) {
tile.population = 0;
continue;
}
const animal = species[speciesId];
const quality = habitatQuality(tile);
const capacity = carryingCapacity(tile, speciesId);
const oldPopulation = tile.population;
let delta = quality >= 45
? Math.round(oldPopulation * animal.growth * (quality - 45) / 100)
: -Math.round(oldPopulation * animal.growth * (45 - quality) / 100);
const hasMigrantNeighbor = getNeighbors(tile).some(
(neighbor) =>
neighbor.biome === tile.biome &&
neighbor.population >= 4
);
if (hasMigrantNeighbor) delta += 1;
delta += Math.min(3, Math.floor(tile.restoration / 25));
tile.population = clamp(oldPopulation + delta, 0, capacity);
drawLabel(tile);
}
const after = populationTotals();
state.lastDelta = {
sunhopper: after.sunhopper - before.sunhopper,
mossback: after.mossback - before.mossback,
reedling: after.reedling - before.reedling,
shellwing: after.shellwing - before.shellwing
};
state.season += 1;
const grant = 16 + stableSpeciesCount() * 3;
state.credits += grant;
addJournal(`Season ${state.season} began. The council issued ${grant} stewardship credits.`);
renderUI();
if (
!state.won &&
restoredTileCount() >= 8 &&
averageQuality() >= 57 &&
stableSpeciesCount() === 4
) {
state.won = true;
document.getElementById("result-modal").classList.add("open");
} else {
showToast(`Season ${state.season} · Population update complete`);
}
}
function restoredTileCount() {
return tiles.filter((tile) => tile.restoration > 0).length;
}
// ---------------------------------------------------------------------------
// UI rendering
// ---------------------------------------------------------------------------
function renderHeader() {
document.getElementById("season-value").textContent = state.season;
document.getElementById("credit-value").textContent = state.credits;
document.getElementById("brief-season").textContent = state.season;
}
function renderSpecies() {
const totals = populationTotals();
const container = document.getElementById("species-list");
container.innerHTML = Object.values(species).map((animal) => {
const delta = state.lastDelta[animal.id] || 0;
const trendClass = delta < 0 ? "down" : "";
const trend = delta === 0 ? "— stable" : `${delta > 0 ? "↑" : "↓"} ${Math.abs(delta)}`;
return `
<div class="species-card">
<div class="species-icon" style="background:${animal.color}">${animal.short}</div>
<div>
<div class="species-name">${animal.name}</div>
<div class="species-biome">${biomeInfo[animal.biome].name}</div>
</div>
<div class="species-number">
${totals[animal.id]}
<span class="trend ${trendClass}">${trend}</span>
</div>
</div>
`;
}).join("");
}
function renderObjectives() {
const restored = restoredTileCount();
const quality = averageQuality();
const stable = stableSpeciesCount();
document.getElementById("restore-progress-text").textContent = `${restored} / 8`;
document.getElementById("quality-progress-text").textContent = `${quality} / 57`;
document.getElementById("species-progress-text").textContent = `${stable} / 4`;
document.getElementById("restore-progress").style.width = `${Math.min(100, restored / 8 * 100)}%`;
document.getElementById("quality-progress").style.width = `${Math.min(100, quality / 57 * 100)}%`;
document.getElementById("species-progress").style.width = `${stable / 4 * 100}%`;
}
function renderJournal() {
const list = document.getElementById("journal-list");
list.innerHTML = state.journal.map((entry) => `
<li>
<span class="journal-time">Season ${entry.season}</span>
${entry.text}
</li>
`).join("");
}
function renderInspector() {
const inspector = document.getElementById("inspector");
const tile = state.selected;
if (!tile) {
inspector.innerHTML = `
<div class="empty-dossier">
<div>
<p class="eyebrow">Habitat dossier</p>
<h2 class="mission-title">Select an island tile</h2>
<p class="mission-copy">Choose a habitat to inspect its quality, species, and restoration options.</p>
</div>
</div>
`;
return;
}
const info = biomeInfo[tile.biome];
const quality = habitatQuality(tile);
const forecast = forecastTile(tile);
const animal = forecast.speciesId ? species[forecast.speciesId] : null;
const cost = restorationCost(tile);
const canRestore = state.credits >= cost && tile.restoration < 100;
const speciesMarkup = animal ? `
<div class="population-panel">
<div class="species-icon" style="background:${animal.color}">${animal.short}</div>
<div>
<div class="population-main">
<strong>${tile.population}</strong>
<span class="forecast ${forecast.delta < 0 ? "down" : ""}">
${forecast.delta >= 0 ? "+" : ""}${forecast.delta} next season
</span>
</div>
<div class="population-meta">
${animal.name} · local capacity ${forecast.capacity} · Q ${quality}
</div>
</div>
</div>
` : `
<div class="population-panel">
<div class="species-icon" style="background:#8a8677">—</div>
<div>
<div class="population-main"><strong>No habitat</strong></div>
<div class="population-meta">Restore this tile to reconnect a species.</div>
</div>
</div>
`;
inspector.innerHTML = `
<div class="dossier-title">
<div>
<p class="eyebrow">Habitat dossier</p>
<h2>${info.name}</h2>
</div>
<span class="coordinate">${String.fromCharCode(65 + tile.i)}-${tile.j + 1}</span>
</div>
<p class="biome-description">${info.description}</p>
<div class="quality-card">
<div class="quality-score">${quality}<small>/100</small></div>
<div>
<div class="quality-caption">Habitat quality</div>
<div class="progress-track">
<div class="progress-fill" style="width:${quality}%"></div>
</div>
</div>
</div>
<section class="detail-section">
<h3>Restoration score</h3>
<div class="meter-label">
<span>Restoration points</span>
<strong>${tile.restoration} / 100</strong>
</div>
<div class="progress-track">
<div class="progress-fill" style="width:${tile.restoration}%"></div>
</div>
</section>
<section class="detail-section">
<h3>Preferred species</h3>
${speciesMarkup}
</section>
<section class="detail-section">
<h3>Ecology notes</h3>
<p class="biome-description">
${animal
? animal.description
: "The ruined structures suppress habitat quality and block neighboring ecosystems."}
</p>
</section>
<div class="restore-card">
<h3>${info.action}</h3>
<p>
${tile.biome === "ruins"
? "Clear the structures, restore the soil, and convert this sector into native meadow."
: `Adds 25 restoration points. Current forecast: ${forecast.delta >= 0 ? "+" : ""}${forecast.delta} local population next season.`}
</p>
<button class="primary-button restore-button" data-action="restore" ${canRestore ? "" : "disabled"}>
${tile.restoration >= 100 ? "Fully restored" : `${info.action} · ${cost} cr`}
</button>
<div class="cost-note">
${tile.biome === "ruins"
? "New habitat species: Sunhopper"
: "Population changes are applied when you advance the season"}
</div>
</div>
`;
}
function renderUI() {
renderHeader();
renderSpecies();
renderObjectives();
renderJournal();
renderInspector();
}
let toastTimer;
function showToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2400);
}
function selectTile(tile) {
state.selected = tile;
positionHighlight(selectedHighlight, tile);
renderInspector();
}
// ---------------------------------------------------------------------------
// Direct camera controls and picking
// ---------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
let lastPointerX = 0;
let lastPointerY = 0;
function pickTile(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(terrainMeshes, false);
return hits.length ? hits[0].object.userData.tile : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerMoved = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(event.clientX - pointerStartX) + Math.abs(event.clientY - pointerStartY) > 5) {
pointerMoved = true;
}
cameraAzimuth -= dx * 0.008;
cameraElevation = clamp(cameraElevation + dy * 0.006, 0.38, 1.28);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
return;
}
const hovered = pickTile(event.clientX, event.clientY);
if (hovered !== state.hovered) {
state.hovered = hovered;
positionHighlight(hoverHighlight, hovered);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
renderer.domElement.classList.remove("dragging");
renderer.domElement.releasePointerCapture(event.pointerId);
if (!pointerMoved) {
const tile = pickTile(event.clientX, event.clientY);
if (tile) selectTile(tile);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) {
state.hovered = null;
positionHighlight(hoverHighlight, null);
}
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraZoom = clamp(cameraZoom * (event.deltaY > 0 ? 0.9 : 1.1), 0.62, 1.55);
updateCamera();
}, { passive: false });
// ---------------------------------------------------------------------------
// Interface events
// ---------------------------------------------------------------------------
document.getElementById("advance-button").addEventListener("click", advanceSeason);
document.getElementById("inspector").addEventListener("click", (event) => {
if (event.target.closest('[data-action="restore"]') && state.selected) {
restorationAction(state.selected);
}
});
document.getElementById("population-toggle").addEventListener("click", (event) => {
state.populationLayer = !state.populationLayer;
for (const tile of tiles) {
tile.label.visible = state.populationLayer;
}
event.currentTarget.classList.toggle("active", state.populationLayer);
});
document.getElementById("reset-camera").addEventListener("click", () => {
cameraAzimuth = 0.67;
cameraElevation = 0.76;
cameraZoom = 0.90;
updateCamera();
});
const rulesModal = document.getElementById("rules-modal");
document.getElementById("rules-button").addEventListener("click", () => rulesModal.classList.add("open"));
document.getElementById("close-rules").addEventListener("click", () => rulesModal.classList.remove("open"));
document.getElementById("rules-done").addEventListener("click", () => rulesModal.classList.remove("open"));
document.getElementById("result-done").addEventListener("click", () => {
document.getElementById("result-modal").classList.remove("open");
});
rulesModal.addEventListener("click", (event) => {
if (event.target === rulesModal) rulesModal.classList.remove("open");
});
document.getElementById("result-modal").addEventListener("click", (event) => {
if (event.target.id === "result-modal") event.target.classList.remove("open");
});
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
rulesModal.classList.remove("open");
document.getElementById("result-modal").classList.remove("open");
}
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
advanceSeason();
}
if (event.key.toLowerCase() === "r" && state.selected && !rulesModal.classList.contains("open")) {
restorationAction(state.selected);
}
});
// ---------------------------------------------------------------------------
// Initialize
// ---------------------------------------------------------------------------
generateTiles();
initializePopulations();
for (const tile of tiles) {
buildTile(tile);
}
const initialTile =
tiles.find((tile) => tile.biome === "forest") ||
tiles.find((tile) => tile.biome === "wetland") ||
tiles[0];
state.selected = initialTile;
positionHighlight(selectedHighlight, initialTile);
addJournal(`Survey complete: ${tiles.length} island habitats mapped.`);
addJournal("Select a tile to begin a restoration plan.");
renderUI();
resizeRenderer();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```