BUILD REQUEST - PL-162 Angle of Repose - 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-162-angle-of-repose.html. ===== BEGIN SPEC ===== ANGLE OF REPOSE: Sandpile Avalanche Observatory HOOK OBJECT: window.__repose Build "ANGLE OF REPOSE": a side-view granular-physics observatory in Canvas 2D (no libraries) where 3,000 warm mineral grains fall onto a sloped glass cell, form a growing heap, and cascade in visible avalanches when the slope exceeds its angle of repose. The experiment compares dry sand, damp sand and angular gravel under a controlled tilt and shows that gravity, not a canned animation, causes the collapse. LOOK - Style: precise geology field notebook with warm backlight, palette parchment #E9E1CC, graphite #27323A, glass #BFE4E5, dry sand #D9A34B, damp sand #956844, gravel #68757C, warning coral #D95842. - Subject: a 48 x 28 cm transparent tilt cell holding at least 3,000 individually rendered grains in three size classes, a protractor arc and digital tilt readout, falling feed nozzle, and a catch tray below the cell. - FIRST FRAME (t = 0, no input): the transparent cell with a seeded heap, grains, protractor and falling stream fills at least 55% of the screen height, readable top-left counters and a small material legend outside the cell. MOTION / PLAY - Controls: A/D or horizontal drag tilts the cell between -25 and +25 degrees; W/S changes feed rate; keys 1–3 select dry sand, damp sand or angular gravel; Space drops a measured burst of 120 grains; R resets the heap. setCamera(panX, tiltDeg, zoom) adjusts the observation camera. - Hand-written granular physics: fixed-step particle integration with gravity, friction, rolling resistance, particle-particle separation and cell-wall collision. Grains must not merge or tunnel through the glass; a spatial hash grid is required for performance. - Avalanche mechanics: when the local surface slope exceeds the material's repose angle (dry 34°, damp 46°, gravel 39°), unstable grains roll downslope under gravity. At least 80 grains moving through the lower third within 0.6 s counts as one avalanche, then the detector must cool down for 1.5 s. - ATTRACT MODE: no input runs a 28–30 s experiment: build a dry heap to 35°, trigger a slide, reset, build damp sand to 45°, then tilt gravel past 39° for a second slide. Any input takes over; after 8 s idle it resumes. SOUND - Falling grains produce a fine granular hiss proportional to feed rate. - Grain contacts make sparse soft ticks with pitch based on size class. - An avalanche produces a low sandy rush; glass wall contact gives a faint glassy ping. COUNTERS stats() returns { fps, grains, avalanches, reposeDeg, tiltDeg, feedRate, settledRatio }. - grains: exact current number of live grains in the cell or catch tray. - avalanches: +1 when the moving-grain detector sees the measured avalanche criterion. - reposeDeg: selected material's actual repose angle in degrees. - tiltDeg: measured cell tilt in degrees. - settledRatio: fraction of grains whose speed is below 0.08 m/s for 0.5 s. - On screen: top-left pill with grain count, avalanches, tilt and repose angle, never over the heap. 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: cell and heap span at least 55% of screen height, grains >= 3000, and at least three grain size classes are visible. 2. Containment and separation: after 15 s at 0° tilt, no grain is outside the glass cell or below the floor and fewer than 2% of same-size neighbors overlap by more than 20% of a grain diameter. 3. Repose threshold: dry sand remains stable below 32° but produces a measured avalanche after crossing 34°, with avalanches +1; damp sand remains stable at 40° and avalanches after crossing 46°. 4. Feed conservation: 120 added grains increase grains by exactly 120; grains lost through the open outlet appear in the catch tray, so cell + catch + outlet = initial + fed. 5. Attract experiment: advancing 30 s visits all three materials, records at least two avalanches, and leaves no NaN grain positions or console errors. 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 single animated mound or random falling particles instead of individually colliding grains and a real repose threshold. - Grains escaping the glass, merging into one blob or passing through the floor at high feed rate. - Avalanche counters firing on a timer without the measured moving-grain criterion. - Material buttons changing only a label while the repose angle and friction stay identical. - HUD covering the heap or a cell too small to read the avalanche. - 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.