Prompt specification
Build or customize the Three.js 3D scene "Cooperative Settlement Search" 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: Cooperative Settlement Search
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cooperative-settlement-search-x3216
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows negotiated resolution of shared-space conflicts. Create a bounded puzzle with four community requests and limited space. Let users explore arrangements, then explain unmet constraints instead of presenting a single moral winner. Voxel style.
Working Three.js Starter (cooperative-settlement-search-x3216):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Common Ground — Shared-Space Negotiation</title>
<style>
:root {
--ink: #24313a;
--muted: #647078;
--paper: #f5f0e5;
--panel: #fffdf7;
--line: #d9d1c2;
--quiet: #ef8354;
--play: #35a7a0;
--garden: #7b9b48;
--arrival: #617bea;
--good: #347a52;
--bad: #b94c3e;
--shadow: 4px 4px 0 #24313a;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Arial, Helvetica, sans-serif;
}
button,
select {
font: inherit;
}
button {
color: inherit;
}
.app-header {
min-height: 74px;
display: grid;
grid-template-columns: 270px minmax(320px, 1fr) 310px;
align-items: center;
gap: 20px;
padding: 10px 18px;
border-bottom: 3px solid var(--ink);
background: #fffdf7;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 42px;
height: 42px;
position: relative;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
display: block;
width: 16px;
height: 16px;
background: var(--ink);
box-shadow: 2px 2px 0 rgba(0, 0, 0, .14);
}
.brand-mark i:nth-child(1) { left: 0; top: 0; background: var(--quiet); }
.brand-mark i:nth-child(2) { left: 17px; top: 0; background: var(--garden); }
.brand-mark i:nth-child(3) { left: 0; top: 17px; background: var(--play); }
.brand-mark i:nth-child(4) { left: 17px; top: 17px; background: var(--arrival); }
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1;
letter-spacing: .08em;
text-transform: uppercase;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
}
.steps {
display: flex;
justify-content: center;
align-items: center;
gap: 7px;
}
.step {
display: flex;
align-items: center;
gap: 7px;
border: 0;
background: transparent;
padding: 6px 8px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: .06em;
text-transform: uppercase;
cursor: pointer;
}
.step b {
display: grid;
place-items: center;
width: 24px;
height: 24px;
border: 2px solid var(--line);
background: #fff;
font-size: 11px;
}
.step.active {
color: var(--ink);
}
.step.active b {
border-color: var(--ink);
background: var(--ink);
color: white;
}
.step.done b {
border-color: var(--good);
color: var(--good);
}
.header-meta {
justify-self: end;
text-align: right;
font-family: "Courier New", monospace;
font-size: 11px;
line-height: 1.5;
color: var(--muted);
}
.header-meta strong {
color: var(--ink);
}
.workspace {
display: grid;
grid-template-columns: 270px minmax(450px, 1fr) 310px;
min-height: calc(100vh - 77px);
}
.left-panel,
.right-panel {
min-width: 0;
background: var(--panel);
overflow: auto;
}
.left-panel {
border-right: 3px solid var(--ink);
padding: 18px 14px;
}
.right-panel {
border-left: 3px solid var(--ink);
display: flex;
flex-direction: column;
padding: 18px 16px 16px;
}
.eyebrow {
margin: 0 0 6px;
color: var(--muted);
font-family: "Courier New", monospace;
font-size: 10px;
font-weight: 700;
letter-spacing: .13em;
text-transform: uppercase;
}
.panel-title {
margin: 0 0 14px;
font-size: 21px;
line-height: 1.05;
}
.request-list {
display: grid;
gap: 10px;
}
.request-card {
width: 100%;
position: relative;
display: grid;
grid-template-columns: 36px 1fr;
gap: 10px;
padding: 12px 10px;
border: 2px solid var(--line);
border-left-width: 7px;
background: white;
text-align: left;
cursor: pointer;
transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.request-card:hover {
transform: translateY(-2px);
box-shadow: 3px 3px 0 #c8bfaf;
}
.request-card.selected {
border-color: var(--ink);
box-shadow: 4px 4px 0 var(--ink);
transform: translate(-2px, -2px);
}
.request-card[data-request="quiet"] { border-left-color: var(--quiet); }
.request-card[data-request="play"] { border-left-color: var(--play); }
.request-card[data-request="garden"] { border-left-color: var(--garden); }
.request-card[data-request="arrival"] { border-left-color: var(--arrival); }
.request-icon {
width: 34px;
height: 34px;
display: grid;
place-items: center;
border: 2px solid var(--ink);
background: #f5f0e5;
}
.request-icon svg {
width: 23px;
height: 23px;
display: block;
}
.request-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.request-top strong {
font-size: 13px;
}
.size-tag,
.card-state {
padding: 3px 5px;
border: 1px solid var(--line);
font-family: "Courier New", monospace;
font-size: 9px;
white-space: nowrap;
}
.card-state.good {
color: var(--good);
border-color: var(--good);
}
.card-state.bad {
color: var(--bad);
border-color: var(--bad);
}
.request-description {
display: block;
margin: 6px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.request-need,
.request-location {
display: block;
font-family: "Courier New", monospace;
font-size: 10px;
line-height: 1.35;
}
.request-need {
color: var(--ink);
}
.request-location {
margin-top: 4px;
color: var(--muted);
}
.selection-tools {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.small-button,
.ghost-button,
.primary-button,
.tool-button {
border: 2px solid var(--ink);
background: white;
font-weight: 800;
cursor: pointer;
}
.small-button,
.ghost-button {
min-height: 38px;
padding: 8px;
font-size: 11px;
}
.small-button:hover,
.ghost-button:hover,
.tool-button:hover {
background: #f1eadc;
}
.selection-help {
margin: 12px 0 0;
padding: 11px;
border: 2px dashed #bdb4a5;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.selection-help strong {
color: var(--ink);
}
.stage {
position: relative;
min-height: 660px;
overflow: hidden;
background: #dcd5c5;
isolation: isolate;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.stage-heading {
position: absolute;
z-index: 3;
top: 16px;
left: 16px;
pointer-events: none;
background: rgba(255, 253, 247, .9);
border-left: 6px solid var(--ink);
padding: 9px 12px;
box-shadow: 3px 3px 0 rgba(36, 49, 58, .18);
}
.stage-heading strong {
display: block;
font-size: 13px;
letter-spacing: .08em;
text-transform: uppercase;
}
.stage-heading span {
display: block;
margin-top: 4px;
color: var(--muted);
font-family: "Courier New", monospace;
font-size: 10px;
}
.stage-tools {
position: absolute;
z-index: 4;
top: 16px;
right: 16px;
display: flex;
gap: 7px;
}
.tool-button {
min-height: 34px;
padding: 6px 9px;
box-shadow: 3px 3px 0 rgba(36, 49, 58, .8);
font-size: 10px;
text-transform: uppercase;
}
.tool-button:active,
.small-button:active,
.primary-button:active {
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 var(--ink);
}
.stage-legend {
position: absolute;
z-index: 3;
left: 16px;
bottom: 16px;
display: flex;
flex-wrap: wrap;
gap: 7px;
max-width: calc(100% - 32px);
pointer-events: none;
}
.legend-chip {
padding: 6px 8px;
border: 1px solid rgba(36, 49, 58, .3);
background: rgba(255, 253, 247, .9);
font-family: "Courier New", monospace;
font-size: 9px;
}
.legend-chip i {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 5px;
background: var(--chip);
}
.stage-instruction {
position: absolute;
z-index: 3;
left: 50%;
bottom: 58px;
transform: translateX(-50%);
width: max-content;
max-width: calc(100% - 40px);
padding: 9px 12px;
border: 2px solid var(--ink);
background: #fffdf7;
box-shadow: 3px 3px 0 var(--ink);
font-size: 11px;
text-align: center;
pointer-events: none;
}
#panelContent {
flex: 1;
min-height: 0;
overflow: auto;
padding-right: 3px;
}
.panel-intro {
margin: 0 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.brief-card,
.result-card,
.schedule-card {
margin-bottom: 10px;
border: 2px solid var(--line);
background: white;
}
.brief-card {
padding: 12px;
}
.brief-card strong {
display: block;
margin-bottom: 5px;
font-size: 12px;
}
.brief-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.placed-meter {
margin: 15px 0;
padding: 12px;
border: 2px solid var(--ink);
background: #f1eadc;
}
.placed-meter strong {
display: block;
font-size: 24px;
}
.placed-meter span {
font-family: "Courier New", monospace;
font-size: 10px;
}
.fairness-note {
margin-top: 16px;
padding: 12px;
border-left: 5px solid var(--garden);
background: #edf1e4;
font-size: 11px;
line-height: 1.5;
}
.fairness-note strong {
display: block;
margin-bottom: 4px;
}
.summary-banner {
margin-bottom: 13px;
padding: 13px;
border: 2px solid var(--ink);
background: #f1eadc;
}
.summary-banner strong {
display: block;
font-size: 20px;
}
.summary-banner span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.result-card {
padding: 11px;
}
.result-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 8px;
}
.result-heading strong {
font-size: 12px;
}
.outcome {
padding: 3px 5px;
border: 1px solid var(--good);
color: var(--good);
font-family: "Courier New", monospace;
font-size: 9px;
text-transform: uppercase;
}
.outcome.bad {
border-color: var(--bad);
color: var(--bad);
}
.constraint {
display: grid;
grid-template-columns: 17px 1fr;
gap: 7px;
padding: 7px 0;
border-top: 1px solid #ece6da;
}
.constraint:first-of-type {
border-top: 0;
}
.constraint-mark {
width: 15px;
height: 15px;
display: grid;
place-items: center;
margin-top: 1px;
border: 2px solid var(--good);
color: var(--good);
font-size: 10px;
font-weight: 900;
}
.constraint.miss .constraint-mark {
border-color: var(--bad);
color: var(--bad);
}
.constraint strong {
display: block;
font-size: 10px;
line-height: 1.3;
}
.constraint small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.report-note {
margin: 13px 0 0;
padding: 10px;
border: 2px dashed #c8bfaf;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.schedule-card {
padding: 11px;
}
.schedule-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 8px;
}
.schedule-top strong {
font-size: 11px;
}
.schedule-top span {
font-family: "Courier New", monospace;
font-size: 9px;
color: var(--muted);
}
.schedule-card select {
width: 100%;
padding: 7px 8px;
border: 2px solid var(--line);
border-radius: 0;
background: #faf7ef;
color: var(--ink);
font-family: "Courier New", monospace;
font-size: 10px;
}
.collision-box {
margin: 13px 0;
padding: 11px;
border-left: 5px solid var(--quiet);
background: #f8e8df;
font-size: 10px;
line-height: 1.5;
}
.collision-box strong {
display: block;
margin-bottom: 3px;
}
.primary-button {
flex: 0 0 auto;
width: 100%;
min-height: 48px;
margin-top: 15px;
padding: 10px 12px;
background: var(--ink);
color: white;
box-shadow: var(--shadow);
text-transform: uppercase;
letter-spacing: .06em;
font-size: 11px;
}
.primary-button:hover {
background: #34454f;
}
.back-button {
width: 100%;
margin-top: 9px;
padding: 8px;
border: 0;
background: transparent;
color: var(--muted);
text-decoration: underline;
cursor: pointer;
font-size: 10px;
}
.toast {
position: fixed;
z-index: 20;
left: 50%;
bottom: 24px;
transform: translate(-50%, 20px);
max-width: min(460px, calc(100% - 30px));
padding: 10px 14px;
border: 2px solid var(--ink);
background: var(--ink);
color: white;
box-shadow: 4px 4px 0 rgba(0, 0, 0, .2);
opacity: 0;
pointer-events: none;
transition: opacity .18s ease, transform .18s ease;
font-size: 11px;
text-align: center;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.modal {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(36, 49, 58, .74);
}
.modal[hidden] {
display: none;
}
.modal-paper {
width: min(720px, 100%);
max-height: calc(100vh - 40px);
overflow: auto;
border: 4px solid var(--ink);
background: var(--panel);
box-shadow: 8px 8px 0 rgba(0, 0, 0, .35);
}
.modal-header {
padding: 20px;
border-bottom: 3px solid var(--ink);
background: #f1eadc;
}
.modal-header h2 {
margin: 0;
font-size: 26px;
line-height: 1.05;
}
.modal-header p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.modal-body {
padding: 20px;
}
.agreement-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 14px;
}
.agreement-section {
padding: 13px;
border: 2px solid var(--line);
background: white;
}
.agreement-section h3 {
margin: 0 0 10px;
font-size: 13px;
text-transform: uppercase;
letter-spacing: .05em;
}
.agreement-list {
margin: 0;
padding-left: 18px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.agreement-list li + li {
margin-top: 6px;
}
.schedule-summary {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
margin-top: 14px;
}
.schedule-summary div {
padding: 9px;
border: 2px solid var(--line);
background: #faf7ef;
font-size: 10px;
line-height: 1.4;
}
.schedule-summary strong {
display: block;
margin-bottom: 3px;
}
.modal-footer {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 15px 20px;
border-top: 3px solid var(--ink);
}
.modal-footer button {
min-height: 42px;
padding: 9px 14px;
}
@media (max-width: 1050px) {
.app-header {
grid-template-columns: 240px 1fr;
}
.header-meta {
display: none;
}
.workspace {
grid-template-columns: 240px minmax(420px, 1fr);
}
.right-panel {
grid-column: 1 / -1;
min-height: 520px;
border-left: 0;
border-top: 3px solid var(--ink);
}
#panelContent {
overflow: visible;
}
}
@media (max-width: 720px) {
.app-header {
grid-template-columns: 1fr;
gap: 8px;
padding: 12px;
}
.steps {
justify-content: flex-start;
overflow-x: auto;
}
.workspace {
display: flex;
flex-direction: column;
}
.stage {
order: -1;
min-height: 560px;
border-bottom: 3px solid var(--ink);
}
.left-panel {
border-right: 0;
border-bottom: 3px solid var(--ink);
}
.request-list {
grid-template-columns: 1fr 1fr;
}
.right-panel {
min-height: 600px;
}
.agreement-grid {
grid-template-columns: 1fr;
}
.modal-footer {
flex-direction: column;
}
}
@media (max-width: 470px) {
.request-list {
grid-template-columns: 1fr;
}
.stage {
min-height: 500px;
}
.stage-heading {
top: 10px;
left: 10px;
}
.stage-tools {
top: 10px;
right: 10px;
}
.tool-button {
padding: 5px 7px;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div>
<h1>Common Ground</h1>
<p>Shared-space negotiation puzzle</p>
</div>
</div>
<nav class="steps" aria-label="Puzzle steps">
<button class="step active" data-step="0"><b>1</b> Arrange</button>
<button class="step" data-step="1"><b>2</b> Check</button>
<button class="step" data-step="2"><b>3</b> Charter</button>
</nav>
<div class="header-meta">
<strong>8 × 8 COMMONS</strong><br>
64 tiles · 4 requests · finite space
</div>
</header>
<main class="workspace">
<aside class="left-panel" aria-labelledby="requestsTitle">
<p class="eyebrow">Four community requests</p>
<h2 class="panel-title" id="requestsTitle">Choose what to move</h2>
<div class="request-list">
<button class="request-card selected" data-request="quiet" aria-pressed="true">
<span class="request-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M5 12h14v5H5zM7 12V7h5v5M14 8h4v4"/>
<path d="M4 17v2M20 17v2"/>
</svg>
</span>
<span>
<span class="request-top">
<strong>Quiet nook</strong>
<span class="size-tag">2 × 2</span>
</span>
<span class="request-description">A shaded place to read and rest.</span>
<span class="request-need">Needs shade + acoustic separation</span>
<span class="request-location">Position: west-north · 07–10</span>
<span class="card-state">Selected</span>
</span>
</button>
<button class="request-card" data-request="play" aria-pressed="false">
<span class="request-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M3 7h18v10H3zM3 7l3-3M21 7l-3-3M12 7v10"/>
<path d="M8 12h8"/>
</svg>
</span>
<span>
<span class="request-top">
<strong>Play & movement</strong>
<span class="size-tag">3 × 2</span>
</span>
<span class="request-description">Space for active play and passing through.</span>
<span class="request-need">Needs one clear three-tile edge</span>
<span class="request-location">Position: north-east · 16–19</span>
<span class="card-state">Placed</span>
</span>
</button>
<button class="request-card" data-request="garden" aria-pressed="false">
<span class="request-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M4 10h16v10H4zM12 10v10"/>
<path d="M12 10C8 10 7 7 8 4c4 0 5 3 4 6ZM12 10c4 0 5-3 4-6-4 0-5 3-4 6Z"/>
</svg>
</span>
<span>
<span class="request-top">
<strong>Food garden</strong>
<span class="size-tag">2 × 3</span>
</span>
<span class="request-description">Raised beds for shared food growing.</span>
<span class="request-need">Needs west light + access edge</span>
<span class="request-location">Position: west-middle · 10–13</span>
<span class="card-state">Placed</span>
</span>
</button>
<button class="request-card" data-request="arrival" aria-pressed="false">
<span class="request-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M3 20h18M5 20l7-7 7 7M12 13V4M9 7l3-3 3 3"/>
<path d="M8 20v-3h8v3"/>
</svg>
</span>
<span>
<span class="request-top">
<strong>Step-free arrival</strong>
<span class="size-tag">2 × 2</span>
</span>
<span class="request-description">A clear, accessible route from the entry.</span>
<span class="request-need">Needs south edge + two-tile lane</span>
<span class="request-location">Position: south-middle · 10–13</span>
<span class="card-state">Placed</span>
</span>
</button>
</div>
<div class="selection-tools">
<button class="small-button" id="rotateButton">Rotate selected</button>
<button class="small-button" id="removeButton">Remove selected</button>
</div>
<div class="selection-help">
<strong>How to explore:</strong><br>
Select a request, then click a courtyard tile to place it. Drag empty space to orbit; scroll to zoom.
</div>
</aside>
<section class="stage" aria-label="Interactive voxel courtyard">
<div id="viewport"></div>
<div class="stage-heading">
<strong>The shared courtyard</strong>
<span>drag to orbit · scroll to zoom · click to place</span>
</div>
<div class="stage-tools">
<button class="tool-button" id="resetView">Reset view</button>
<button class="tool-button" id="resetLayout">Reset layout</button>
</div>
<div class="stage-instruction" id="stageInstruction">
Quiet nook selected — click a tile to move it.
</div>
<div class="stage-legend" aria-label="Request color legend">
<span class="legend-chip"><i style="--chip:var(--quiet)"></i>Quiet</span>
<span class="legend-chip"><i style="--chip:var(--play)"></i>Play</span>
<span class="legend-chip"><i style="--chip:var(--garden)"></i>Garden</span>
<span class="legend-chip"><i style="--chip:var(--arrival)"></i>Arrival</span>
<span class="legend-chip">☀ west light</span>
<span class="legend-chip">↓ building entry</span>
</div>
</section>
<aside class="right-panel" aria-labelledby="panelTitle">
<p class="eyebrow" id="phaseEyebrow">Step 1 · Arrange</p>
<h2 class="panel-title" id="panelTitle">Finite space, several needs</h2>
<div id="panelContent"></div>
<button class="primary-button" id="primaryButton">Test arrangement</button>
</aside>
</main>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div class="modal" id="agreementModal" hidden>
<section class="modal-paper" role="dialog" aria-modal="true" aria-labelledby="agreementTitle">
<header class="modal-header">
<p class="eyebrow">Shared-space charter</p>
<h2 id="agreementTitle">A workable agreement — with trade-offs</h2>
<p>
This draft records what the current arrangement can support. It does not rank
one community request above another. Unmet conditions remain explicit next steps.
</p>
</header>
<div class="modal-body">
<div class="agreement-grid">
<section class="agreement-section">
<h3>Supported now</h3>
<ul class="agreement-list" id="supportedList"></ul>
</section>
<section class="agreement-section">
<h3>Still to negotiate</h3>
<ul class="agreement-list" id="remainingList"></ul>
</section>
</div>
<div class="schedule-summary" id="scheduleSummary"></div>
<div class="fairness-note">
<strong>No moral winner is declared.</strong>
A fair process makes each constraint visible, tests whether it can coexist,
and records who must adjust space or time next.
</div>
</div>
<footer class="modal-footer">
<button class="ghost-button" id="keepExploring">Keep exploring</button>
<button class="primary-button" id="exportAgreement" style="margin:0; width:auto">
Export agreement notes
</button>
</footer>
</section>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const N = 8;
const CELL = 1;
const HALF = (N - 1) / 2;
const TREE_CELL = { x: 0, z: 0 };
const TIME_SLOTS = ["07–10", "10–13", "13–16", "16–19"];
const requests = {
quiet: {
id: "quiet",
name: "Quiet nook",
color: 0xef8354,
css: "#ef8354",
baseColor: 0xf2c6aa,
x: 1,
z: 0,
rot: 0,
schedule: "07–10",
need: "Shade + separation from overlapping noise"
},
play: {
id: "play",
name: "Play & movement",
color: 0x35a7a0,
css: "#35a7a0",
baseColor: 0x94d5ca,
x: 5,
z: 1,
rot: 0,
schedule: "16–19",
need: "One completely open three-tile edge"
},
garden: {
id: "garden",
name: "Food garden",
color: 0x7b9b48,
css: "#7b9b48",
baseColor: 0x9d6a43,
x: 0,
z: 2,
rot: 0,
schedule: "10–13",
need: "Western light + a clear access edge"
},
arrival: {
id: "arrival",
name: "Step-free arrival",
color: 0x617bea,
css: "#617bea",
baseColor: 0xb7c0d6,
x: 3,
z: 6,
rot: 0,
schedule: "10–13",
need: "South-edge entry + a two-tile clear lane"
}
};
const selectedId = "quiet";
let phase = 0;
let hoverCell = null;
let toastTimer = null;
const viewport = document.getElementById("viewport");
const panelContent = document.getElementById("panelContent");
const panelTitle = document.getElementById("panelTitle");
const phaseEyebrow = document.getElementById("phaseEyebrow");
const primaryButton = document.getElementById("primaryButton");
const stageInstruction = document.getElementById("stageInstruction");
const toast = document.getElementById("toast");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdcd5c5);
scene.fog = new THREE.Fog(0xdcd5c5, 22, 38);
const camera = new THREE.OrthographicCamera(-8, 8, 8, -8, 0.1, 100);
let cameraYaw = 0.72;
let cameraPitch = 0.73;
let cameraZoom = 1;
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff8df, 0x6c7a73, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0c0, 3.1);
sun.position.set(-7, 12, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.03;
scene.add(sun);
const boardGroup = new THREE.Group();
const modelsGroup = new THREE.Group();
const ghostGroup = new THREE.Group();
const environmentGroup = new THREE.Group();
scene.add(boardGroup, modelsGroup, ghostGroup, environmentGroup);
const groundCells = [];
const requestModels = {};
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function worldX(cellX) {
return (cellX - HALF) * CELL;
}
function worldZ(cellZ) {
return (cellZ - HALF) * CELL;
}
function dimensions(req) {
const base = req.id === "play" ? [3, 2] :
req.id === "garden" ? [2, 3] :
[2, 2];
return req.rot % 2 ? [base[1], base[0]] : base;
}
function footprint(req) {
if (req.x === null || req.z === null) return [];
const [w, d] = dimensions(req);
const cells = [];
for (let dz = 0; dz < d; dz++) {
for (let dx = 0; dx < w; dx++) {
cells.push({ x: req.x + dx, z: req.z + dz });
}
}
return cells;
}
function cellKey(x, z) {
return `${x},${z}`;
}
function occupiedAt(x, z, exceptId = null) {
if (x === TREE_CELL.x && z === TREE_CELL.z) return "the courtyard tree";
for (const req of Object.values(requests)) {
if (req.id === exceptId) continue;
if (footprint(req).some(c => c.x === x && c.z === z)) return req.name;
}
return null;
}
function placementProblem(req, x, z) {
const [w, d] = dimensions(req);
if (x < 0 || z < 0 || x + w > N || z + d > N) {
return "That footprint would extend beyond the 8 × 8 courtyard.";
}
for (const cell of footprint({ ...req, x, z })) {
const blocker = occupiedAt(cell.x, cell.z, req.id);
if (blocker) {
return `${blocker} already occupies that footprint.`;
}
}
return null;
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children[0];
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material) ? object.material : [object.material];
materials.forEach(material => material.dispose());
}
});
group.remove(child);
}
}
function addVoxel(parent, size, position, color, outlined = true) {
const geometry = new THREE.BoxGeometry(size[0], size[1], size[2]);
const material = new THREE.MeshLambertMaterial({ color });
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (outlined) {
const edgeGeometry = new THREE.EdgesGeometry(geometry);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x26343b,
transparent: true,
opacity: 0.28
});
const edges = new THREE.LineSegments(edgeGeometry, edgeMaterial);
mesh.add(edges);
}
parent.add(mesh);
return mesh;
}
function buildBoard() {
for (let z = 0; z < N; z++) {
for (let x = 0; x < N; x++) {
const shaded = (x === 1 && (z === 0 || z === 1));
const color = shaded ? 0xb9bca9 :
(x + z) % 2 === 0 ? 0xded3b8 : 0xd5c9ad;
const cell = addVoxel(
boardGroup,
[0.96, 0.18, 0.96],
[worldX(x), -0.1, worldZ(z)],
color,
false
);
cell.userData.cellX = x;
cell.userData.cellZ = z;
cell.castShadow = false;
groundCells.push(cell);
}
}
const borderColor = 0x4a5557;
addVoxel(boardGroup, [8.35, 0.32, 0.22], [0, -0.22, -4.13], borderColor);
addVoxel(boardGroup, [8.35, 0.32, 0.22], [0, -0.22, 4.13], borderColor);
addVoxel(boardGroup, [0.22, 0.32, 8.35], [-4.13, -0.22, 0], borderColor);
addVoxel(boardGroup, [0.22, 0.32, 8.35], [4.13, -0.22, 0], borderColor);
// Fixed tree occupies one buildable tile.
const tree = new THREE.Group();
tree.position.set(worldX(TREE_CELL.x), 0, worldZ(TREE_CELL.z));
addVoxel(tree, [0.34, 1.25, 0.34], [0, 0.55, 0], 0x76543b);
addVoxel(tree, [1.05, 0.72, 1.05], [0, 1.38, 0], 0x567c43);
addVoxel(tree, [0.78, 0.62, 0.78], [0.16, 1.92, -0.1], 0x6e914c);
addVoxel(tree, [0.58, 0.55, 0.58], [-0.42, 1.65, 0.26], 0x7fa257);
environmentGroup.add(tree);
// West-light marker.
const sunMarker = new THREE.Group();
for (let i = 0; i < 4; i++) {
addVoxel(sunMarker, [0.25, 0.12, 0.25], [-5.15 + i * 0.28, 0, 2.25], 0xf2b94b);
}
addVoxel(sunMarker, [0.25, 0.12, 0.7], [-4.08, 0, 2.25], 0xf2b94b);
addVoxel(sunMarker, [0.25, 0.12, 0.25], [-3.9, 0, 2.25], 0xf2b94b);
environmentGroup.add(sunMarker);
// Building entry threshold.
addVoxel(environmentGroup, [1.9, 0.22, 0.7], [0, -0.03, 4.28], 0x667078);
addVoxel(environmentGroup, [1.35, 0.06, 0.22], [0, 0.11, 4.35], 0xe0b94c);
addVoxel(environmentGroup, [1.65, 0.72, 0.24], [0, 0.35, 4.68], 0x49565c);
const label = makeLabel("ENTRY", "#f5df86");
label.position.set(0, 0.95, 4.7);
label.scale.set(1.7, 0.42, 1);
environmentGroup.add(label);
const lightLabel = makeLabel("WEST LIGHT", "#f5df86");
lightLabel.position.set(-4.85, 0.42, 3.35);
lightLabel.scale.set(1.9, 0.46, 1);
environmentGroup.add(lightLabel);
}
function makeLabel(text, background) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 64;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "#24313a";
context.lineWidth = 6;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
context.fillStyle = "#24313a";
context.font = "bold 25px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 33);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({ map: texture });
return new THREE.Sprite(material);
}
function buildRequestModel(req) {
const oldGroup = requestModels[req.id];
if (oldGroup) {
clearGroup(oldGroup);
modelsGroup.remove(oldGroup);
}
if (req.x === null || req.z === null) {
delete requestModels[req.id];
return;
}
const [w, d] = dimensions(req);
const group = new THREE.Group();
group.position.set(
worldX(req.x + (w - 1) / 2),
0,
worldZ(req.z + (d - 1) / 2)
);
const cells = footprint(req);
cells.forEach(cell => {
const lx = cell.x - (req.x + (w - 1) / 2);
const lz = cell.z - (req.z + (d - 1) / 2);
addVoxel(group, [0.9, 0.1, 0.9], [lx, 0.025, lz], req.baseColor, false);
});
if (req.id === "quiet") buildQuietModel(group, w, d);
if (req.id === "play") buildPlayModel(group, w, d);
if (req.id === "garden") buildGardenModel(group, w, d);
if (req.id === "arrival") buildArrivalModel(group, w, d);
group.traverse(object => {
object.userData.requestId = req.id;
});
requestModels[req.id] = group;
modelsGroup.add(group);
}
function buildQuietModel(group, w, d) {
const benchZ = -d / 2 + 0.23;
addVoxel(group, [w - 0.55, 0.25, 0.34], [0, 0.43, benchZ], 0x7b5138);
addVoxel(group, [w - 0.55, 0.38, 0.13], [0, 0.68, benchZ - 0.13], 0x9b6442);
[-1, 1].forEach(sign => {
const x = sign * (w / 2 - 0.28);
addVoxel(group, [0.28, 0.36, 0.28], [x, 0.22, -benchZ], 0x6d8a4c);
addVoxel(group, [0.5, 0.34, 0.5], [x, 0.45, -benchZ], 0x7b9b48);
});
addVoxel(group, [0.3, 0.08, 0.42], [0.25, 0.61, benchZ], 0xf5efe0);
}
function buildPlayModel(group, w, d) {
const endX = w / 2 - 0.2;
const goalZ = -d / 2 + 0.22;
[-1, 1].forEach(sign => {
addVoxel(group, [0.16, 0.9, 0.16], [sign * endX, 0.48, goalZ], 0xf4efe0);
});
addVoxel(group, [endX * 2, 0.15, 0.16], [0, 0.93, goalZ], 0xf4efe0);
addVoxel(group, [0.34, 0.34, 0.34], [0.2, 0.28, 0.15], 0xf2b94b);
addVoxel(group, [0.48, 0.08, 0.13], [-0.65, 0.12, 0.42], 0xf8f3e6);
addVoxel(group, [0.13, 0.08, 0.48], [-0.65, 0.12, 0.42], 0xf8f3e6);
}
function buildGardenModel(group, w, d) {
const cells = footprint(reqForGroupSize(group));
// Use the actual footprint offsets centered on the group.
const req = requests.garden;
const [rw, rd] = dimensions(req);
const cx = req.x + (rw - 1) / 2;
const cz = req.z + (rd - 1) / 2;
for (let dz = 0; dz < rd; dz++) {
for (let dx = 0; dx < rw; dx++) {
const lx = req.x + dx - cx;
const lz = req.z + dz - cz;
addVoxel(group, [0.18, 0.25, 0.18], [lx - 0.18, 0.23, lz], 0x47713e, false);
addVoxel(group, [0.35, 0.25, 0.35], [lx + 0.18, 0.25, lz], 0x5f8d46, false);
addVoxel(group, [0.17, 0.17, 0.17], [lx - 0.18, 0.43, lz], 0xe48a3a, false);
}
}
}
function reqForGroupSize(group) {
return requests.garden;
}
function buildArrivalModel(group, w, d) {
addVoxel(group, [1.45, 0.07, 1.45], [0, 0.11, 0], 0xd7dce5, false);
for (let i = 0; i < 6; i++) {
const z = 0.1 + i * 0.16;
const height = 0.05 + i * 0.035;
addVoxel(group, [1.2, height, 0.16], [0, 0.12 + height / 2, z], 0x8d9baa, false);
}
[-1, 1].forEach(sign => {
for (let i = 0; i < 4; i++) {
addVoxel(group, [0.16, 0.035, 0.22], [sign * 0.48, 0.17, -0.45 + i * 0.34], 0xf1c452, false);
}
});
addVoxel(group, [0.42, 0.08, 0.32], [-0.38, 0.18, -0.54], 0x617bea, false);
}
function buildAllModels() {
Object.values(requests).forEach(buildRequestModel);
}
function updateGhost(cell = hoverCell) {
clearGroup(ghostGroup);
hoverCell = cell;
if (!cell) return;
const req = requests[selectedId];
const [w, d] = dimensions(req);
const problem = placementProblem(req, cell.x, cell.z);
const color = problem ? 0xd84d43 : 0x2c9c69;
for (let dz = 0; dz < d; dz++) {
for (let dx = 0; dx < w; dx++) {
const geometry = new THREE.BoxGeometry(0.88, 0.08, 0.88);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.38,
depthWrite: false
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(
worldX(cell.x + dx),
0.07,
worldZ(cell.z + dz)
);
mesh.renderOrder = 5;
ghostGroup.add(mesh);
}
}
}
function updateCamera() {
const radius = 18;
camera.position.set(
Math.sin(cameraYaw) * Math.cos(cameraPitch) * radius,
Math.sin(cameraPitch) * radius,
Math.cos(cameraYaw) * Math.cos(cameraPitch) * radius
);
camera.lookAt(0, 0.2, 0);
camera.updateProjectionMatrix();
}
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
const aspect = width / height;
const halfHeight = Math.max(6.15, 6 / aspect) / cameraZoom;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
updateCamera();
}
window.addEventListener("resize", resize);
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function groundHit(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(groundCells, false);
if (!hits.length) return null;
const point = hits[0].point;
return {
x: Math.max(0, Math.min(N - 1, Math.floor(point.x + N / 2))),
z: Math.max(0, Math.min(N - 1, Math.floor(point.z + N / 2)))
};
}
function requestHit(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const groups = Object.values(requestModels);
const hits = raycaster.intersectObjects(groups, true);
for (const hit of hits) {
if (hit.object.userData.requestId) return hit.object.userData.requestId;
}
return null;
}
let pointerStart = null;
let pointerMoved = false;
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
pointerStart = { x: event.clientX, y: event.clientY };
pointerMoved = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
const cell = groundHit(event);
updateGhost(cell);
if (!pointerStart) return;
const dx = event.clientX - pointerStart.x;
const dy = event.clientY - pointerStart.y;
if (Math.hypot(dx, dy) > 5) {
pointerMoved = true;
renderer.domElement.classList.add("dragging");
cameraYaw -= dx * 0.007;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.005, 0.42, 1.18);
updateCamera();
}
});
renderer.domElement.addEventListener("pointerup", event => {
renderer.domElement.classList.remove("dragging");
if (!pointerMoved && pointerStart) {
const hitRequest = requestHit(event);
if (hitRequest) {
selectRequest(hitRequest);
} else {
const cell = groundHit(event);
if (cell) placeSelected(cell.x, cell.z);
}
}
pointerStart = null;
pointerMoved = false;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerStart = null;
pointerMoved = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerStart) updateGhost(null);
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(cameraZoom - event.deltaY * 0.001, 0.72, 1.65);
resize();
}, { passive: false });
function selectRequest(id) {
const oldSelected = selectedId;
selectedId = id;
document.querySelectorAll(".request-card").forEach(card => {
const selected = card.dataset.request === id;
card.classList.toggle("selected", selected);
card.setAttribute("aria-pressed", String(selected));
});
if (oldSelected !== id) {
const req = requests[id];
stageInstruction.textContent = `${req.name} selected — click a tile to move it.`;
updateGhost(hoverCell);
renderUI();
}
}
function placeSelected(x, z) {
const req = requests[selectedId];
const problem = placementProblem(req, x, z);
if (problem) {
showToast(problem);
return;
}
req.x = x;
req.z = z;
phase = 0;
buildRequestModel(req);
updateGhost(hoverCell);
renderUI();
showToast(`${req.name} moved. Test the arrangement when ready.`);
}
function rotateSelected() {
const req = requests[selectedId];
const oldDimensions = dimensions(req);
const nextRotation = (req.rot + 1) % 2;
const candidate = { ...req, rot: nextRotation };
if (req.x !== null) {
const problem = placementProblem(candidate, req.x, req.z);
if (problem) {
showToast(`Rotation blocked: ${problem}`);
return;
}
}
req.rot = nextRotation;
buildRequestModel(req);
updateGhost(hoverCell);
renderUI();
showToast(`${req.name} rotated to ${dimensions(req)[0]} × ${dimensions(req)[1]}.`);
}
function removeSelected() {
const req = requests[selectedId];
req.x = null;
req.z = null;
phase = 0;
buildRequestModel(req);
updateGhost(hoverCell);
renderUI();
showToast(`${req.name} removed. Click a tile to place it again.`);
}
function minDistance(a, b) {
let minimum = Infinity;
for (const ca of a) {
for (const cb of b) {
minimum = Math.min(minimum, Math.abs(ca.x - cb.x) + Math.abs(ca.z - cb.z));
}
}
return minimum;
}
function sideIsClear(req, side) {
const [w, d] = dimensions(req);
const cells = [];
if (side === "left") {
for (let z = req.z; z < req.z + d; z++) cells.push({ x: req.x - 1, z });
}
if (side === "right") {
for (let z = req.z; z < req.z + d; z++) cells.push({ x: req.x + w, z });
}
if (side === "north") {
for (let x = req.x; x < req.x + w; x++) cells.push({ x, z: req.z - 1 });
}
if (side === "south") {
for (let x = req.x; x < req.x + w; x++) cells.push({ x, z: req.z + d });
}
if (!cells.length) return false;
if (cells.some(c => c.x < 0 || c.z < 0 || c.x >= N || c.z >= N)) return false;
if (cells.some(c => occupiedAt(c.x, c.z, req.id))) return false;
return true;
}
function evaluateArrangement() {
const constraints = [];
const byRequest = {};
Object.values(requests).forEach(req => {
byRequest[req.id] = [];
});
function add(req, key, label, ok, detail) {
const item = { requestId: req.id, key, label, ok, detail };
constraints.push(item);
byRequest[req.id].push(item);
}
Object.values(requests).forEach(req => {
const cells = footprint(req);
if (!cells.length) {
add(req, "placed", "Footprint placed", false, "Place this request in the courtyard.");
return;
}
const overlapping = Object.values(requests).some(other =>
other.id !== req.id &&
footprint(other).some(a => cells.some(b => a.x === b.x && a.z === b.z))
);
if (overlapping) {
add(req, "overlap", "No overlapping footprints", false, "Two requests occupy the same courtyard tiles.");
}
if (req.id === "quiet") {
const treeDistance = minDistance(cells, [TREE_CELL]);
add(
req,
"shade",
"Shade from the courtyard tree",
treeDistance <= 2,
treeDistance <= 2
? `The nook is ${treeDistance} tile${treeDistance === 1 ? "" : "s"} from the tree shade.`
: `The nearest tile is ${treeDistance} steps from the tree shade; the nook needs to be within 2.`
);
const sharesQuietHoursWithPlay = req.schedule === requests.play.schedule;
const sharesQuietHoursWithArrival = req.schedule === requests.arrival.schedule;
const needsBuffer = sharesQuietHoursWithPlay || sharesQuietHoursWithArrival;
const playDistance = minDistance(cells, footprint(requests.play));
const arrivalDistance = minDistance(cells, footprint(requests.arrival));
const nearestDistance = Math.min(playDistance, arrivalDistance);
const bufferMet = !needsBuffer || nearestDistance >= 3;
add(
req,
"buffer",
"Separation from shared noise",
bufferMet,
!needsBuffer
? "The quiet hours do not overlap the play or arrival slots, so a full acoustic buffer is not required."
: bufferMet
? `The nearest active use is ${nearestDistance} tiles away; the three-tile separation is met.`
: `Only ${nearestDistance} tiles separate the nook from an overlapping noisy use; three are required.`
);
}
if (req.id === "play") {
const [w, d] = dimensions(req);
const sides = [
{ name: "north", cells: w, clear: sideIsClear(req, "north") },
{ name: "south", cells: w, clear: sideIsClear(req, "south") },
{ name: "west", cells: d, clear: sideIsClear(req, "west") },
{ name: "east", cells: d, clear: sideIsClear(req, "east") }
];
const eligible = sides.filter(side => side.cells >= 3);
const clearSides = eligible.filter(side => side.clear);
add(
req,
"edge",
"A clear three-tile edge",
clearSides.length > 0,
clearSides.length
? `The ${clearSides[0].name} edge provides a clear three-tile run.`
: "No three-tile edge is completely open. Move or rotate the play area."
);
}
if (req.id === "garden") {
const hasWestLight = cells.some(cell => cell.x <= 1);
add(
req,
"sun",
"Access to western light",
hasWestLight,
hasWestLight
? "At least one garden tile reaches the western light band."
: "No garden tile reaches the western light band; shift the beds toward the west."
);
const clearGardenSides = ["north", "south", "west", "east"].filter(side => sideIsClear(req, side));
add(
req,
"access",
"A clear working edge",
clearGardenSides.length > 0,
clearGardenSides.length
? `The ${clearGardenSides[0]} edge can remain open for tending and deliveries.`
: "Every garden edge is blocked by another request or the courtyard boundary."
);
}
if (req.id === "arrival") {
const [w] = dimensions(req);
const touchesSouth = cells.some(cell => cell.z === N - 1);
add(
req,
"edge",
"Connection to the south entry",
touchesSouth,
touchesSouth
? "The arrival pad meets the building entry at the south edge."
: "Move the arrival pad to touch the south edge."
);
const maxZ = req.z + dimensions(req)[1] - 1;
const routeCells = [];
for (let z = 2; z <= maxZ - 1; z++) {
for (let x = req.x; x < req.x + w; x++) {
routeCells.push({ x, z });
}
}
const routeClear = routeCells.length > 0 && routeCells.every(cell => !occupiedAt(cell.x, cell.z, req.id));
add(
req,
"route",
"A two-tile accessible lane",
routeClear,
routeClear
? "A two-tile-wide route remains clear into the courtyard."
: "The two-tile route into the courtyard is blocked. Keep the lane directly north of the arrival pad open."
);
}
});
const supported = Object.values(byRequest).filter(items =>
items.length && items.every(item => item.ok)
).length;
return {
constraints,
byRequest,
supported,
total: Object.keys(requests).length,
remaining: constraints.filter(item => !item.ok)
};
}
function scheduleCollisions() {
const groups = {};
Object.values(requests).forEach(req => {
(groups[req.schedule] ||= []).push(req);
});
return Object.entries(groups).filter(([, items]) => items.length > 1);
}
function renderCards(report = null) {
document.querySelectorAll(".request-card").forEach(card => {
const req = requests[card.dataset.request];
const selected = card.dataset.request === selectedId;
card.classList.toggle("selected", selected);
card.setAttribute("aria-pressed", String(selected));
const location = card.querySelector(".request-location");
const state = card.querySelector(".card-state");
location.textContent = req.x === null
? "Not placed · choose a time later"
: `Position: ${req.x + 1}, ${req.z + 1} · ${req.schedule}`;
state.classList.remove("good", "bad");
if (selected) {
state.textContent = "Selected";
} else if (report) {
const items = report.byRequest[req.id];
const ok = items.length && items.every(item => item.ok);
state.textContent = ok ? "Supported" : "Needs work";
state.classList.add(ok ? "good" : "bad");
} else {
state.textContent = req.x === null ? "Needs placement" : "Placed";
}
});
}
function renderPanel(report = evaluateArrangement()) {
if (phase === 0) {
phaseEyebrow.textContent = "Step 1 · Arrange";
panelTitle.textContent = "Finite space, several needs";
const placed = Object.values(requests).filter(req => req.x !== null).length;
panelContent.innerHTML = `
<p class="panel-intro">
Move the four request blocks, then test whether their stated conditions can coexist.
There is no hidden “correct” arrangement.
</p>
<div class="placed-meter">
<strong>${placed} / 4</strong>
<span>request footprints placed</span>
</div>
<div class="brief-card">
<strong>Quiet nook</strong>
<p>Within two tiles of the tree shade. When its hours overlap active uses, keep three tiles of separation.</p>
</div>
<div class="brief-card">
<strong>Play & movement</strong>
<p>Keep one complete three-tile edge open for movement and safe passing space.</p>
</div>
<div class="brief-card">
<strong>Food garden</strong>
<p>Reach the western light band and leave one complete edge open for tending and deliveries.</p>
</div>
<div class="brief-card">
<strong>Step-free arrival</strong>
<p>Meet the south entry and preserve a two-tile-wide accessible route inward.</p>
</div>
<div class="fairness-note">
<strong>Trade-offs, not a winner.</strong>
The check reports which conditions are met and which are not. It never labels one request
as less important because its footprint is smaller or quieter.
</div>
`;
}
if (phase === 1) {
phaseEyebrow.textContent = "Step 2 · Check";
panelTitle.textContent = "Constraint report";
const resultCards = Object.values(requests).map(req => {
const items = report.byRequest[req.id];
const ok = items.length && items.every(item => item.ok);
return `
<section class="result-card">
<div class="result-heading">
<strong style="color:${req.css}">${req.name}</strong>
<span class="outcome ${ok ? "" : "bad"}">${ok ? "Supported" : "Needs work"}</span>
</div>
${items.map(item => `
<div class="constraint ${item.ok ? "" : "miss"}">
<span class="constraint-mark">${item.ok ? "✓" : "!"}</span>
<div>
<strong>${item.label}</strong>
<small>${item.detail}</small>
</div>
</div>
`).join("")}
</section>
`;
}).join("");
panelContent.innerHTML = `
<div class="summary-banner">
<strong>${report.supported} of ${report.total} supported</strong>
<span>${report.remaining.length
? `${report.remaining.length} stated condition${report.remaining.length === 1 ? "" : "s"} still need attention.`
: "All stated spatial conditions currently fit together."}</span>
</div>
${resultCards}
<div class="report-note">
The report does not choose a winner. It exposes the constraints that would require
another move, a different use time, or an explicit concession.
</div>
`;
}
if (phase === 2) {
phaseEyebrow.textContent = "Step 3 · Charter";
panelTitle.textContent = "Negotiate time as well as space";
const collisions = scheduleCollisions();
const collisionText = collisions.length
? collisions.map(([time, items]) => {
const names = items.map(req => req.name).join(" + ");
return `<strong>${time}:</strong> ${names} share the courtyard. Their access and noise limits still need coordination.`;
}).join("<br><br>")
: `<strong>No simultaneous slots.</strong> Each request currently has a separate time window.`;
panelContent.innerHTML = `
<p class="panel-intro">
If space cannot meet every need at once, try sharing the courtyard across time.
Change any slot, then write a draft agreement.
</p>
${Object.values(requests).map(req => `
<div class="schedule-card">
<div class="schedule-top">
<strong style="color:${req.css}">${req.name}</strong>
<span>${req.need}</span>
</div>
<label>
<span class="eyebrow">Use this courtyard slot</span>
<select data-schedule="${req.id}" aria-label="${req.name} time slot">
${TIME_SLOTS.map(slot => `
<option value="${slot}" ${slot === req.schedule ? "selected" : ""}>${slot}</option>
`).join("")}
</select>
</label>
</div>
`).join("")}
<div class="collision-box">${collisionText}</div>
<div class="report-note">
Time-sharing can reduce simultaneous conflict, but it does not erase accessibility,
shade, light, or safe-space requirements. The final draft will show what remains.
</div>
<button class="back-button" id="backToArrange">← Return to spatial arrangement</button>
`;
panelContent.querySelectorAll("[data-schedule]").forEach(select => {
select.addEventListener("change", event => {
const req = requests[event.target.dataset.schedule];
req.schedule = event.target.value;
renderUI();
showToast(`${req.name} now uses the courtyard during ${req.schedule}.`);
});
});
const backButton = document.getElementById("backToArrange");
if (backButton) {
backButton.addEventListener("click", () => {
phase = 0;
renderUI();
});
}
}
}
function renderUI() {
const report = evaluateArrangement();
renderCards(phase > 0 ? report : null);
renderPanel(report);
document.querySelectorAll(".step").forEach((step, index) => {
step.classList.toggle("active", index === phase);
step.classList.toggle("done", index < phase);
});
primaryButton.textContent = [
"Test arrangement",
"Open time charter",
"Write shared agreement"
][phase];
const selected = requests[selectedId];
stageInstruction.textContent = phase === 2
? "Change use times in the charter, then write the draft agreement."
: `${selected.name} selected — click a tile to move it.`;
}
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("visible"), 2600);
}
function openAgreement() {
const report = evaluateArrangement();
const supported = report.constraints.filter(item => item.ok);
const remaining = report.remaining;
const modal = document.getElementById("agreementModal");
document.getElementById("agreementTitle").textContent = remaining.length
? "Draft agreement — trade-offs remain"
: "A workable shared agreement";
document.getElementById("supportedList").innerHTML = supported.length
? supported.map(item => {
const req = requests[item.requestId];
return `<li><strong>${req.name}:</strong> ${item.label.toLowerCase()}.</li>`;
}).join("")
: "<li>No stated condition is currently supported.</li>";
document.getElementById("remainingList").innerHTML = remaining.length
? remaining.map(item => {
const req = requests[item.requestId];
return `<li><strong>${req.name}:</strong> ${item.detail}</li>`;
}).join("")
: "<li>No stated spatial condition is currently unmet. Monitor how the shared schedule works in practice.</li>";
document.getElementById("scheduleSummary").innerHTML = Object.values(requests).map(req => `
<div style="border-left:5px solid ${req.css}">
<strong>${req.name}</strong>
${req.schedule}
</div>
`).join("");
modal.hidden = false;
document.getElementById("keepExploring").focus();
}
function exportAgreement() {
const report = evaluateArrangement();
const supported = report.constraints.filter(item => item.ok);
const remaining = report.remaining;
const lines = [
"COMMON GROUND — SHARED-SPACE AGREEMENT",
"",
`Supported requests: ${report.supported} of ${report.total}`,
"",
"SUPPORTED CONDITIONS",
...supported.map(item => `- ${requests[item.requestId].name}: ${item.label}`),
"",
"REMAINING NEGOTIATIONS",
...(remaining.length
? remaining.map(item => `- ${requests[item.requestId].name}: ${item.detail}`)
: ["- No stated spatial condition is currently unmet."]),
"",
"SHARED TIMES",
...Object.values(requests).map(req => `- ${req.name}: ${req.schedule}`),
"",
"No request was ranked above another. Remaining limits are the next conversation."
];
const blob = new Blob([lines.join("\n")], { type: "text/plain;charset=utf-8" });
const url = URL.createObjectURL(blob);
const anchor = document.createElement("a");
anchor.href = url;
anchor.download = "common-ground-agreement.txt";
document.body.appendChild(anchor);
anchor.click();
anchor.remove();
URL.revokeObjectURL(url);
}
document.querySelectorAll(".request-card").forEach(card => {
card.addEventListener("click", () => selectRequest(card.dataset.request));
});
document.querySelectorAll(".step").forEach(step => {
step.addEventListener("click", () => {
phase = Number(step.dataset.step);
renderUI();
});
});
document.getElementById("rotateButton").addEventListener("click", rotateSelected);
document.getElementById("removeButton").addEventListener("click", removeSelected);
document.getElementById("resetView").addEventListener("click", () => {
cameraYaw = 0.72;
cameraPitch = 0.73;
cameraZoom = 1;
resize();
});
document.getElementById("resetLayout").addEventListener("click", () => {
requests.quiet.x = 1;
requests.quiet.z = 0;
requests.quiet.rot = 0;
requests.quiet.schedule = "07–10";
requests.play.x = 5;
requests.play.z = 1;
requests.play.rot = 0;
requests.play.schedule = "16–19";
requests.garden.x = 0;
requests.garden.z = 2;
requests.garden.rot = 0;
requests.garden.schedule = "10–13";
requests.arrival.x = 3;
requests.arrival.z = 6;
requests.arrival.rot = 0;
requests.arrival.schedule = "10–13";
phase = 0;
buildAllModels();
updateGhost(hoverCell);
renderUI();
showToast("The starting arrangement has been restored.");
});
primaryButton.addEventListener("click", () => {
if (phase === 0) {
phase = 1;
renderUI();
showToast("Constraint report ready. Unmet needs are explained below.");
} else if (phase === 1) {
phase = 2;
renderUI();
showToast("Time-sharing is now available in the charter.");
} else {
openAgreement();
}
});
document.getElementById("keepExploring").addEventListener("click", () => {
document.getElementById("agreementModal").hidden = true;
phase = 0;
renderUI();
});
document.getElementById("exportAgreement").addEventListener("click", exportAgreement);
document.getElementById("agreementModal").addEventListener("click", event => {
if (event.target === event.currentTarget) {
event.currentTarget.hidden = true;
}
});
document.addEventListener("keydown", event => {
if (event.key === "Escape") {
document.getElementById("agreementModal").hidden = true;
}
});
buildBoard();
buildAllModels();
resize();
renderUI();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```