BUILD REQUEST - PL-188 Orbit Dock - 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-188-orbit-dock.html. ===== BEGIN SPEC ===== ORBIT DOCK: a Playable Spacecraft Docking Game on Real Two-Body Orbital Mechanics HOOK OBJECT: window.__dock Build "ORBIT DOCK": a Canvas 2D game (no libraries). You fly a small chaser spacecraft to the docking port of a space station that orbits the made-up planet Marlow. Both craft are integrated in a real inertial two-body gravity field, and you watch from the station's rotating frame (radial direction up, direction of travel to the right), where thrust does not behave like on the ground: speed up and you climb to a higher, slower orbit and fall behind, and a craft left "at rest" drifts away. A soft dock needs patience, a crash needs only haste. It is fun to keep watching because the autopilot has to fly the real curved paths too. LOOK - Style: mission-control vector look. Palette: space #04070F, 140 seeded stars #FFFFFF in 3 sizes (1, 2 and 3 px), planet glow band along the bottom 18% of the window from #0B3A66 (top) to #6FB4F0 (bottom) with a thin limb line #9FD4FF, station hull #D8DEE8, solar panels #2C4A8C with cells #3E66C8, docking port ring #FFB020, chaser body #FFFFFF with nose #FF4D4D, thruster puffs #9FE8FF, HUD text #BFE6FF and warnings #FF6B6B. - Units and view: 1 unit = 1 m. View scale s = min(height / 40, width / 66) px per m (18 at 1280x720, 5.909 at 390x844). The station center (0, 0) is drawn at the window center. With x = radial offset (up on screen) and y = along-track offset (right on screen), screen position = (width / 2 + y s, height / 2 - x s). - Station "Lantern Hub": hull rectangle x -7 to 7, y -6 to 6 with a docking-port stub and ring on its left face at y = -6; two solar wings x 7 to 11 and x -11 to -7, both y -5 to 5. The whole station is x -11 to 11 and y -6 to 6 (22 m tall, 12 m wide). Capture target P = (0, -8): the chaser's center when docked, its nose touching the port face. Chaser: a body 4 m long (along y) and 2 m tall (along x), nose toward +y. - HUD panel: top-left, x 12 to 270 and y 12 to 126, six lines of 14 px monospace (about 8.4 px per character, the longest line below is 28 characters = 235 px, which fits the 258 px panel and a 390 px window): "DOCK 1 CRASH 0", "RANGE 24.2 m SPEED 0.25 m/s", "FUEL 19.34 m/s RCS 2", "T+ 116 s APPROACH" (the last word is APPROACH, DOCKED or CRASH), "UP = RADIAL OUT", "RIGHT = PROGRADE". - Touch pad (64 x 64 px buttons, drawn on the canvas, pointer events): UP at x 78 to 142 and y (height - 210) to (height - 146); LEFT at x 10 to 74, DOWN at x 78 to 142 and RIGHT at x 146 to 210, all three at y (height - 142) to (height - 78); RESET at x (width - 80) to (width - 16), y (height - 80) to (height - 16). - FIRST FRAME (t = 0, no input): the chaser at rest in the rotating frame at (x = 10, y = -30), which at 1280x720 is the 72 x 36 px body centered at (100, 180), fully inside the window and clear of the HUD panel (its top edge is at y = 162, the panel ends at y = 126); the station 396 x 216 px (55% of the window height) at x 532 to 748, y 162 to 558; the planet band at the bottom; the stars; the pad. On a phone in portrait the 66 m wide lane must fit the width, so the station is only 130 px tall (15.4% of the height) and the chaser body is centered at (17.7, 363): that is an accepted exception. Nothing overlaps the station or the chaser. MOTION / PLAY - Physics (exact). mu = 3.986e14 m^3/s^2. The station moves on a circular orbit of radius 6,771,000 m in a 2D inertial plane: at t = 0 it is at (6,771,000, 0) with velocity (0, sqrt(mu / 6,771,000)). The chaser is a second inertial point mass in the same gravity (acceleration -mu * r / |r|^3). Both are integrated with velocity Verlet (kick, drift, kick), a fixed step dt = 0.1 s of simulation time, ONE step per 1/60 s tick (6 simulation seconds per real second); thrust acceleration is held constant over a step. advance(seconds) runs round(seconds x 60) ticks. The station is never thrusted. - Rotating frame (what you see and what every hook reports). rhat = station position / |station position|; that = rhat turned +90 degrees (prograde). rho = chaser position - station position (inertial vector, components (rho1, rho2)). x = rho . rhat and y = rho . that. omega = (station position x station velocity) / |station position|^2. u = (chaser velocity - station velocity) - omega * (-rho2, rho1). vx = u . rhat and vy = u . that. setChaser(x, y, vx, vy) builds the chaser's inertial state from exactly these formulas inverted. Start: the chaser at x = 10, y = -30, vx = 0, vy = 0. - Thrusters: ArrowUp or W = +x acceleration (radial out), ArrowDown or S = -x, ArrowRight or D = +y (prograde), ArrowLeft or A = -y, on window keydown and keyup (ignore key repeats), or the pad buttons. Each held axis applies 0.1 m/s^2 along that axis of the rotating frame (rhat and that of that step), on or off instantly; the chaser never rotates; two axes can be held together. Fuel budget 20.0 m/s: fuelUsed grows by (|ax| + |ay|) x 0.1 per step; at 20.0 the thrusters do nothing. R or the RESET button restarts the try (counters keep their values); the hook's reset() restores everything including the counters. - Docking, evaluated after each integration step in this order. (1) Capture: if not docked, |(x, y) - P| <= 0.5, the relative speed sqrt(vx^2 + vy^2) <= 0.3 and vy >= 0: dockings += 1, docked = true, and from then on the chaser is held at (x = 0, y = -8) with zero relative velocity (it rides rigidly with the station, thrust is ignored) until a reset. (2) Crash: otherwise, if not docked and the chaser center is strictly inside the rectangle |x| < 12 and -8 < y < 8 (the hull grown by the chaser's half size): crashes += 1; push the chaser back out through the nearest face (set x to +12 or -12, or y to -8 or 8, whichever penetration is smallest), reverse the relative velocity component along that face's normal and multiply it by 0.3. After the push the chaser is on the boundary, not inside, so one contact counts once. - Camera: no pointer camera is needed; setCameraOrbit(azimuthDeg, elevationDeg, scale) applies the CSS 3D transform perspective(1400px) rotateY(azimuth) rotateX(-elevation) scale(scale) to the canvas, default (0, 0, 1). Stars are drawn turned by frameAngle() degrees clockwise about the window center, so the sky visibly turns once per orbit. - ATTRACT MODE: with no input, a hands-free autopilot demo starts on load and loops every 28 s. The craft coast for 1.5 s. Then every tick the autopilot reads the rotating-frame state and commands, on each axis, a = clamp((v_des - v) / 4 - cw, -0.1, 0.1) with err = (0 - x, -8 - y), v_des = err x 0.05 scaled down to length 0.25 if longer, and cw = (3 n^2 x + 2 n vy, -2 n vx), n = sqrt(mu / 6,771,000^3). It uses the same thruster path (rcsOn and fuelUsed count). It captures about 19.4 s after it starts, and the docked pair stays on screen until the loop cut: 1.5 s coast + 26.5 s flight and docked hold = 28.0 s. At 28.0 s everything cuts back to the t = 0 state (chaser at (10, -30) at rest, docked false, simTime 0, same orbit) with dockings, crashes, rcsOn and fuelUsed keeping their values. Any input takes over; the demo restarts from the t = 0 state after 8 s with no input. Hook calls are not user input. - The hook also exposes: reset(), setChaser(x, y, vx, vy), burn(dvx, dvy) (an instant velocity change of the chaser along rhat and that; adds |dvx| + |dvy| to fuelUsed), rel() returning {x, y, vx, vy}, orbit() returning {mu, radius (the station's current distance from the planet center), n (sqrt(mu / 6,771,000^3), a constant), period (2 pi / n), energy (v^2 / 2 - mu / r of the station now), h (the station's angular momentum x * vy - y * vx, inertial)}, docked(), simTime(), fuel() (20 - fuelUsed, at least 0), frameAngle() (n x simTime x 180 / pi degrees, not wrapped), attract(on) (false turns the demo off), and layout() returning {station, chaser, hud, pad: {up, down, left, right, reset}} where each is {x, y, w, h} in CSS px at the default camera. SOUND - Any thruster on -> a hiss (noise through a 2 kHz high-pass, gain 0.05) while it stays on, plus a click (1 kHz, 15 ms) each time an axis switches on. - Capture -> a latch clunk (square 120 Hz, 80 ms) followed by a chime (sine 880 Hz, 0.3 s). - Crash -> a thud (noise through a 200 Hz low-pass for 0.4 s plus a sine at 60 Hz). - With no AudioContext (before the first tap, and in ?test=1) nothing is played, but the triggers are still counted. COUNTERS stats() returns { fps, dockings, crashes, rcsOn, fuelUsed, simTime }. - dockings: +1 at a capture. crashes: +1 each time the chaser enters the hull rectangle without a capture. Never on load. - rcsOn: +1 each time a thruster axis command goes from exactly 0 to not 0 (keys, pad or autopilot); it equals the number of click triggers. - fuelUsed: m/s spent, as defined above (thrusting steps and burn() calls). simTime: simulation seconds since the last reset (0.1 per step). - On screen: dockings, crashes, range, speed, fuel, rcsOn and simTime in the HUD panel, readable in a paused frame and never over the station or the chaser. 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: Each check starts from a fresh load; advance() steps in 1/60 s increments. 1. After attract(false) at t = 0: stats() is {dockings 0, crashes 0, rcsOn 0, fuelUsed 0, simTime 0}; fuel() is 20.0 and frameAngle() is 0; orbit() has mu 3.986e14, radius 6,771,000 (within 1), n 0.0011331553 (within 1e-8) and period 5544.86 (within 0.05); rel() is x 10, y -30, vx 0, vy 0 (each within 0.001); docked() is false; at 1280x720 layout().station.h is at least 374 (expected 396), at 390x844 it is between 0.14 and 0.17 of 844; layout().chaser lies fully inside the window at both sizes; layout().station, layout().chaser and layout().hud do not overlap each other; every pad button in layout() is at least 56 x 56. 2. After attract(false), advance(924.2) (55,452 ticks, simTime 5545.2 s, no thrust): orbit().energy and orbit().h each differ from their t = 0 values by at most 1e-8 relative; orbit().radius is within 1.0 of 6,771,000; with t = simTime() and n = orbit().n, rel().x is within 0.5 of 10 (4 - 3 cos(n t)) and rel().y is within 2.0 of -30 + 60 (sin(n t) - n t) (about 10.0 and -407.0); frameAngle() is within 0.01 of n t 180 / pi (about 360.022); fuelUsed and crashes are 0. 3. (a) After attract(false), reset(), setChaser(0, -300, 0, 0), burn(0, 0.5) and advance(462.07) (27,724 ticks, simTime 2772.4 s): with t = simTime(), rel().x is within 15 of (2 x 0.5 / n)(1 - cos(n t)) (about 1,765) and rel().y is within 45 of -300 + (4 x 0.5 / n) sin(n t) - 3 x 0.5 t (about -4,458.5); fuelUsed is 0.5 (within 1e-6). (b) Then reset() and setChaser(10, -30, 0, 0), a real keydown of ArrowRight on window, advance(2.0), a real keyup: rel().vy is 1.2 (within 0.02), fuelUsed is 1.2 (within 0.01) and rcsOn is 1; after advance(1.0) more, rel().vy is within 0.01 of its value at the keyup and fuelUsed is unchanged. 4. After attract(false): (a) reset(), setChaser(0, -9.5, 0, 0.1), advance(3.0): dockings 1, crashes 0, docked() true, rel() within 0.001 of (0, -8, 0, 0), and on the frame dockings became 1 simTime() was between 9.5 and 10.5. (b) reset(), setChaser(0, -9.5, 0, 0.8), step frame by frame (at most 5 s) until crashes is 1: on that frame simTime() is between 1.8 and 2.0, rel().y is within 0.001 of -8.0 and rel().vy is within 0.02 of -0.24; after advance(5.0) more crashes is still 1, dockings 0 and rel().y is below -12. (c) reset(), setChaser(3, -9.5, 0, 0.2), advance(2.0): crashes 1 and dockings 0. 5. On a fresh load with the demo running: at t = 1.4 dockings, crashes and rcsOn are 0 and rel() is within 0.05 of (10, -30); at t = 3.0 rcsOn is at least 1 and fuelUsed is above 0; at t = 10.0 the distance from rel() to (0, -8) is between 9 and 16 and the relative speed is between 0.15 and 0.35; at t = 12.0 dockings is 0; at t = 26.5 dockings is 1, crashes 0, docked() true, rel() within 0.01 of (0, -8, 0, 0) and fuelUsed between 0.3 and 1.2; at t = 28.3 dockings is still 1, docked() is false, rel() is within 0.05 of (10, -30) and simTime() is between 1.5 and 2.1; and the run has zero 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 - Flat game physics: a chaser that stays still, stops when thrust stops, or speeds ahead of the station when you thrust prograde. The rotating-frame drift (a chaser above the station falls behind, a prograde burn ends far behind after half an orbit) must really appear. - A crude integrator: plain Euler makes the orbit spiral outward. Energy and angular momentum must hold to 1e-8 over a full orbit. - Relative velocity computed without subtracting the frame's rotation (omega x rho), so setChaser and rel() do not match. - Docking by distance alone: capture must need the 0.5 m window AND speed at most 0.3 m/s AND vy >= 0; a fast arrival must crash, not dock. - A crash that counts every step while the chaser sits inside the hull, a chaser that passes through the station, or a docked chaser that still drifts. - Thrust that does not stop when a key is released, fuel that is not counted, or counters stuck at 0 or ticking on a timer. - An autopilot that overshoots, crashes, never docks, or only works because it teleports the chaser. - A tiny station in the middle of empty space (it must be 55% of the height on a wide window), a chaser that starts off screen, or HUD text over the station or the chaser. - Keys that only work after clicking, pad buttons smaller than 56 px, or touch that scrolls the page. - 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.