BUILD REQUEST - PL-164 Trebuchet Yard - please build this now I'm sending you this as my request: please build the one-file HTML app described below. Start now and do the whole build in your answer to this message. - This is a build job, not a document to summarize, review or discuss. Don't ask me anything first: if a detail is unclear, pick the most sensible option and keep going. - The spec is everything between the BEGIN SPEC and END SPEC lines. Follow all of it exactly. - If your tool can create files, also save the finished file as PL-164-trebuchet-yard.html. ===== BEGIN SPEC ===== TREBUCHET YARD: Counterweight Castle Siege HOOK OBJECT: window.__trebuchet Build "TREBUCHET YARD": a stylized medieval engineering yard in Three.js where a wooden trebuchet launches polished stone balls over a crenellated practice wall. The long beam, sling, counterweight and projectile form a real linked mechanism; changing the counterweight and release pin changes the arc. The scene is about satisfying timing, dust and impact, not random cannon fire. LOOK - Style: handcrafted miniature siege diorama, palette oak #795036, iron #4A5057, linen sling #D7C49A, limestone #C9C1AF, meadow #708B58, sky #A7C4D2, ember #D87838. - Subject: a 9 m trebuchet with braced oak frame, iron axle, long throwing beam, hanging counterweight box, rope sling and stone projectile, plus a 12 m distant crenellated limestone wall with 24 blocks and a straw target. - FIRST FRAME (t = 0, no input): a low three-quarter view of the cocked trebuchet and distant wall filling at least 55% of the screen height, with a small top-left range/weight panel outside the beam and projectile. MOTION / PLAY - Controls: A/D adjusts counterweight mass; W/S adjusts sling release angle; Space releases the firing pin; R resets the loaded stone; drag outside the engine or setCameraOrbit(azimuthDeg, elevationDeg, distance) to orbit the yard. - Hand-written linked mechanics: the beam is a rigid lever rotating about its axle under counterweight torque and sling tension. The projectile remains attached until the measured sling angle reaches the release threshold; then it follows ballistic gravity, air drag and wall/ground collision. Beam, sling and counterweight must not teleport independently. - Wall damage: a stone hitting a wall block above 8 m/s removes or fractures that block with a dust puff, while lower-speed hits rebound. Blocks above an unsupported gap may tumble into a small rubble pile. - ATTRACT MODE: no input runs a 28–30 s range test: light counterweight short shot, medium counterweight wall hit, heavy counterweight high arc and second wall impact, then reload. Any input takes over; after 8 s idle it resumes. SOUND - Winch ratchet clicks while the beam is cocked. - Counterweight drop gives a low wooden groan; sling release gives a sharp rope snap. - Stone flight has a brief whoosh; wall impact gives a limestone crack and dust rumble, ground impact a dull earth thud. COUNTERS stats() returns { fps, shots, wallHits, blocksBroken, bestRangeM, releaseAngleDeg, counterweightKg }. - shots: +1 only when a projectile is actually released from the sling. - wallHits: +1 for a real projectile contact with the wall. - blocksBroken: +1 for each block visibly fractured or knocked free by a high-speed impact. - bestRangeM: maximum measured horizontal distance traveled by a released stone. - releaseAngleDeg: measured sling angle at release. - counterweightKg: actual selected counterweight mass. - On screen: top-left pill with shots, wall hits, blocks broken and range, never over the engine. CHECKS for ?test=1 With ?test=1, run an accelerated self-test that measures real positions and real events (not self-set flags) and logs "TEST n PASS" or "TEST n FAIL: reason" to the console and to window.__testResults: 1. First frame: trebuchet, sling and wall span at least 50% of screen height; beam and sling are connected and the counterweight is above the axle. 2. Linked motion: during the first 1.5 s after firing, beam angle, counterweight height and sling endpoint change continuously without a position jump greater than 0.5 m per 1/120 s step. 3. Range response: increasing counterweight mass by 50% increases measured first-shot range by at least 20% for the same release angle. 4. Real impact: a projectile hitting a wall block above 8 m/s increments wallHits once and blocksBroken once; a low-speed rebound does not increment blocksBroken. 5. Attract range test: advancing 30 s produces at least 3 shots, 1 wall hit and 1 broken block, then reloads with zero console errors and no NaN projectile state. KEEP IT SHORT - Keep the whole file under about 1,500 lines (soft target) so you can write it in one pass and finish well inside 15 minutes. - Save lines with helpers, loops and instancing, not by dropping features. Everything above must really work: no placeholders, no TODOs. BUILD RULES (all required): - Deliver ONE self-contained HTML file: inline CSS and JS, no build step, no local assets. Libraries only from a CDN. If you use Three.js, use exactly this import map: {"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"}} - It must open straight from disk in desktop Chrome and on an iPhone (Safari), fill the full screen, handle resize and touch, and stay smooth (target 60 fps). - It must look stunning in the very FIRST frame: no black screen, no loading wait, no tiny subject. The main subject fills at least 50% of the screen height. - SOUND (required): all sound is made in code with Web Audio (no audio files). Show a small "🔊 TAP FOR SOUND" chip; on the first tap create ONE AudioContext, route everything through a master gain of 0.6 into a DynamicsCompressor, and hide the chip. Also expose enableAudio() on the hook object named at the top. - Expose the hook object named at the top with: setCameraOrbit(azimuthDeg, elevationDeg, distance) (or an equivalent camera setter), advance(seconds) that steps the simulation exactly that much for still captures, enableAudio(), and stats() returning {fps, ...the counters named above}. Use a fixed random seed of 360 so every run is the same. - Every on-screen counter must count a real event you can see happen. No fake numbers. - No text overlapping the subject; any label must be readable in a paused frame. - No brand logos, no real people, no copyrighted characters, brand names or logos. FAILURE MODES TO AVOID - A cannon-like instant launch with no visible lever rotation, sling swing or counterweight drop. - Projectile range independent of counterweight mass or release angle. - Wall hit counters incrementing without contact, or blocks breaking from gentle touches. - Beam, sling or projectile teleporting instead of following the linked mechanism. - Tiny trebuchet, cropped wall or labels across the flight path. - The same variable declared twice, or methods called on objects that don't exist yet. SELF-TEST LOOP - If you can run code: build the file, open it, read the console, run ?test=1, and take screenshots at 3 s, 10 s and 30 s at 1280x720 and 390x844. Look at the screenshots and fix what looks wrong. Fix and retest until all 5 checks pass with zero console errors. Mark anything you could not run as UNMEASURED; never invent results. - If you are chat-only: go through this prompt line by line, check your code against each line, and fix anything that would fail. Then write one corrected, complete file. - Final answer: ONE complete HTML file in ONE code block, then the 5 checks marked PASS, FAIL or UNMEASURED. No snippets, no "rest unchanged". ===== END SPEC ===== Now build it. Reply with ONE complete HTML file in ONE code block, then the 5 checks marked PASS, FAIL or UNMEASURED.