(Body Snatcher) Pass 4

This commit is contained in:
AlexKucera committed 2026-08-13 15:23:35 +02:00
1 parent 00f4c34da0
commit a219ad17d5
36 files changed
+7693

No files matched your search

@@ -0,0 +1,20 @@
You are the final QA reviewer for "Body Snatcher" (single index.html in this directory). @AGENTS.md is the full spec; read it and read the complete index.html.
Your job: find bugs, missing features, and spec violations, and FIX each one directly in index.html (edit, do not rewrite). Do not stop at a list — apply the fixes. Then run `node verify.js 1`, `node verify.js 2`, `node verify.js 3`, `node verify.js 4`, `node verify.js 5` and ensure ALL print PASSED (exit 0). If any fails, fix until green.
Focus areas (verify each by reading the code AND by reasoning about behavior):
1. CRASHES: any unguarded access that throws in a real browser or under the mock-canvas/mock-audio harness. localStorage/save/load edge cases (missing key, corrupt JSON, missing fields).
2. CALM PACING (the most important gameplay rule): NO friendly fire between enemies (enemy melee/AoE/charge/projectile damage the PLAYER only); enemies idle outside their ~6-tile aggro radius + line of sight so the floor does NOT swarm on spawn; ranged Sentinel/Turret OVERHEAT into a forced multi-turn no-fire window.
3. ENEMIES: all 12 implemented and functional as both AI and possessed kit; (hp,damage,speed) tuples distinct; pathfinder goes AROUND walls; AoE never hits other enemies.
4. ABANDON (X): host survives, pacified, re-possess lockout; ghost timer resumes (not reset) and stays >0.
5. GHOST TIMER: base cap 15 seconds; Ghost Tree T1 raises it to 20. tick(n) drains it deterministically; expiring -> 'lost'.
6. WIN: floor 10 exit -> 'won'. 10 floors with escalating enemies. Procedural layouts differ each run.
7. SHOP: 3 choices, buy applies an upgrade, appears between the right floors.
8. ACHIEVEMENTS: at least the deterministic ones (First Possession, Deep Diver at floor 7, Essence Hoarder at 30 essence) fire.
9. FOG OF WAR: unexplored hidden, explored dimmed, no rendering crash.
10. AUDIO: procedural Web Audio tones actually call AudioContext methods; guarded so it never crashes if unavailable.
11. IN-GAME GUIDANCE: title explains WASD/arrows, SPACE, Q/E, X, ENTER, ESC before play; HUD shows contextual SPACE + X hints; shop and pause show their controls; a bestiary is reachable from title and pause and lists all 12 enemies (behavior + possessed kit).
12. VISUAL POLISH: entities and tiles are intricate layered/shaded canvas-vector art (gradients, bevels, eyes, idle bob, possession aura) — NOT flat single-rect placeholders or bare-text overlays.
13. Save file is single index.html, zero external dependencies, no ES modules.
For each issue you fix, note it briefly. When all five `node verify.js N` gates pass, report DONE with the list of fixes. Preserve everything that already works; make targeted edits.
+42
View File
@@ -0,0 +1,42 @@
You are implementing PHASE 1 ONLY of the game "Body Snatcher" in a single file: index.html (in this same directory). @AGENTS.md is the FULL game spec — read it completely before writing anything. @verify.js is the automated test harness and the exact contract for this phase; run `node verify.js 1` and make it pass (exit 0).
SCOPE for Phase 1 — build ONLY these systems (later phases add the rest, so keep the code organized and extensible but do not implement enemies/posession/shop/procgen/audio yet):
1. Single index.html, HTML5 Canvas 800x576 + a HUD bar, ALL CSS and JS inline, ZERO external dependencies (no CDN, no src=, no import/export). Open the file in a browser and it works.
2. A game loop. The core model is ONE-TILE-PER-TURN and deterministic. Expose window.GAME.tick(n) which advances the simulation exactly n turns. A real-time loop may call tick(1) on a ~600ms cadence for liveliness, but NEVER tie core state to wall-clock — the harness drives everything via tick(n) and input().
3. A 25x18 tile grid. Store it on window.GAME.grid as grid[y][x]. Each cell is a NUMBER: 0=floor, 1=wall, 2=door, 3=exit-stairs, 4=shop-pad, 5=chest. (For this phase use a hand-authored static test dungeon with rooms, walls, and at least one exit tile.)
4. Tile rendering: dark beveled stone walls (gradients, mortar/crack lines, soft drop shadow onto floor), subtly lit floor flagstones, a glowing runic exit, warm torch color grade + soft vignette, faint grid lines. NO flat single-rect placeholders — layered/shaded canvas primitives per AGENTS.md §Visual Style.
5. Ghost player. window.GAME.player = { x, y, ghost:true, timer, host:null, facing:{x,y} }. Movement via WASD / Arrow keys, one tile per turn, BLOCKED by walls. Snappy ~85ms interpolation between tiles; hold-to-move continuous at the turn cadence (presentation only).
6. Ghost timer: timer is a NUMBER of SECONDS. Base cap = 15. After a fresh run (newRun()) the timer equals the cap (15). tick(n) decrements it deterministically (e.g. by n * 0.6). When it reaches 0 the game is lost (you may stub the lost screen for now; full lose is Phase 5).
7. Fog of war: radial soft-gradient visibility around the player; explored-but-unseen tiles dimmed with a cool memory tint. Unexplored tiles hidden.
8. HUD at top showing current body HP (N/A as ghost), the ghost timer, essence (0 for now), floor number (1), and a contextual SPACE hint ("SPACE: Possess" while ghost).
9. TITLE screen shown on load. GAME.start() must reset to the TITLE screen and the game MUST NOT auto-start into play (wait for Enter). The title screen MUST visibly explain the controls: WASD/Arrows (move), SPACE (possess/attack), Q/E (rotate facing), X (abandon host), ENTER (start/confirm), ESC (pause). Pressing ENTER starts a run (state -> "playing"). Pressing lowercase 'l' opens an ENEMY LEGEND / BESTIARY overlay that lists each enemy with its color/shape, its enemy behavior, and its possessed player kit (HP/damage/special). For Phase 1 you only need the 3 enemies that exist later (Brute, Skitterer, Sentinel) described, but structure the bestiary as data so all 12 can be added later.
EXPOSE on window.GAME exactly (the harness reads these — see @verify.js):
state // one of: title, playing, possessed, shop, paused, won, lost
player // { x, y, ghost, timer(seconds), host, facing:{x,y} }
grid // grid[y][x] numeric tiles
floor // 1
essence // 0
enemies // [] for now
projectiles // [] for now
upgrades // {}
achievements // {}
log // []
start() // -> title screen, no auto-start
input(key) // accept ArrowUp/Down/Left/Right, w a s d, ' ' and 'Space', q e, x, Enter, Escape, l
tick(n) // deterministic; advances n turns; decrements ghost timer
newRun() // start a fresh floor-1 run with the test dungeon; player is a ghost at spawn; timer reset to cap (15); state 'playing'
setFloor(n) // (stub OK for now, but must not throw)
spawn(type,x,y) // (stub OK for now, but must not throw)
CONTRACT DETAILS the harness asserts (match them exactly):
- After GAME.start(), state === 'title'.
- After newRun(), player.timer >= 15.
- grid contains both wall (1) and floor (0) tiles.
- input('ArrowRight') etc. moves the ghost; the ghost never lands on a wall tile.
- The title screen canvas text (drawn via ctx.fillText) or DOM text includes the words: wasd, arrow, space, q, e, enter, esc.
- Pressing 'l' then rendering shows a bestiary containing the words brute, skitterer, sentinel, and an HP/damage description.
CRITICAL: The game MUST NOT crash if Canvas getContext('2d') returns a mock with no-op methods, and MUST NOT crash if AudioContext is a mock constructor. The harness mocks these. Do NOT call any real browser-only API at load time without guarding.
When done, run `node verify.js 1` yourself. Fix every failure until it prints "PHASE 1 PASSED" and exits 0. Do not rewrite from scratch on retry — make targeted fixes. Write LESS code, not more; no stubs/TODOs/placeholders; everything you ship works.
+37
View File
@@ -0,0 +1,37 @@
You are implementing PHASE 2 ONLY of "Body Snatcher" in index.html (already exists in this directory from Phase 1). @AGENTS.md is the full spec — read it. @verify.js is the gate; run `node verify.js 2` until it prints "PHASE 2 PASSED" (exit 0). PRESERVE everything from Phase 1; EDIT index.html, do not rewrite from scratch.
SCOPE for Phase 2 — possession + the first 3 enemies + pathfinding + pacing rules. Do NOT add the other 9 enemies, procgen, shop, or save/load (later phases).
1. ENEMY DATA MODEL. Each enemy is an object: { type, hp, maxHp, damage, speed, x, y, facing:{x,y}, aggroed:false, overheatLeft:0, lockout:0, ... }. Add enemies to window.GAME.enemies. speed = number of turns BETWEEN moves (2 = moves every 2 turns; 0 = immobile). Implement spawn(type,x,y) to create and return the enemy at tile coords and push it into enemies[].
- Brute: maxHp 8, damage 3, speed 2. Slow A* chase; heavy melee 2 dmg to the PLAYER when adjacent.
- Skitterer: maxHp 2, damage 1, speed 2. Loose swarm/flank; weak melee 1 dmg to the PLAYER.
- Sentinel: maxHp 4, damage 1, speed 2 (repositions slowly). NO melee. RANGED: keeps ~4 tile distance, fires a BURST of 3 projectiles (one per turn) toward the player, then sets overheatLeft = 3 and CANNOT fire while overheatLeft > 0 (it only repositions slowly during overheat). Projectiles hit the PLAYER ONLY.
Make (maxHp, damage, speed) distinct across whatever enemies exist (Brute/Skitterer/Sentinel here).
2. POSSESSION. While the player is a GHOST and presses SPACE (' ' or 'Space') with an enemy on an adjacent tile, begin possession; it completes within 1 turn. On completion: state -> 'possessed'; player.host = that enemy object; player.ghost = false; the player uses the host's hp/damage/speed/abilities. SPACE while possessed = the host's attack/special (for these 3: Brute melee swing in facing dir, Skitterer rapid weak hit, Sentinel fires a projectile in facing dir with the SAME 3-shot-burst-then-overheat rhythm so it can't stunlock). The ghost timer PAUSES while possessed.
3. VOLUNTARY ABANDON (X). While possessed, input('x') ejects the player as a ghost: state -> 'playing'; player.host = null; player.ghost = true; the timer RESUMES from where it paused (do NOT reset it to 15 — only a host death resets the timer). The abandoned host SURVIVES at its current HP, stays in enemies[], is pacified/stunned for 2 turns, and gets a re-possess lockout: set enemy.lockout = 2 (or similar) so it CANNOT be re-possessed for 2 turns (prevent i-frame spam). The harness checks timer did not increase after abandon.
4. PATHFINDING (A* or BFS). Enemies navigate AROUND walls toward the player — never through them. Aggro: every enemy starts DOCILE (idle/wander, does NOT path to the player). It only begins to chase/attack when the player is within its aggro radius (~6 tiles) AND has line of sight (not through walls). Track this on enemy.aggroed (bool). Outside aggro / without LOS, an enemy stays put or wanders; it must NOT beeline across the map.
5. NO FRIENDLY FIRE (THE MOST IMPORTANT RULE). Enemy melee, AoE, and projectiles ONLY ever damage the PLAYER (the ghost or your current host). Enemies NEVER reduce each other's HP. (Your possessed host's attacks still damage enemies normally.) Without this rule the game is broken.
6. ESSENCE. When an enemy dies, drop essence by type (Brute=3, Skitterer=1, Sentinel=3) into window.GAME.essence. Add a helper addEssence(n) if convenient. Essence persists for the run.
7. HUD. While possessed, the HUD shows the host's HP and a contextual SPACE hint naming the current body's action ("SPACE: Heavy swing", "SPACE: Fire burst", etc.) and an "X: Abandon host" hint. While ghost, "SPACE: Possess".
8. Place a few Brutes/Skitterers/Sentinels on the Phase-1 test dungeon at newRun() so the player has something to possess. Keep the player's spawn area clear of enemies (>=5 tiles).
HARNESS CONTRACT (read @verify.js phase2; match exactly):
- spawn('brute',x,y).maxHp===8 (or hp===8), damage===3, speed>=2.
- spawn('skitterer',...).maxHp/hp===2, damage===1, speed===2.
- spawn('sentinel',...).maxHp/hp===4.
- input(' ') on an adjacent enemy -> state 'possessed' within a few ticks; player.host.type is that enemy.
- input('x') while possessed -> state 'playing', host null, timer>0, timer not increased, former host still in enemies[], lockout field>0 on it.
- An enemy within ~2-5 tiles with clear LOS closes distance over ticks (aggro+pathfind).
- An enemy far away (>=7 tiles) with LOS blocked stays docile (does not close distance); its .aggroed===false if exposed.
- Two enemies adjacent to each other, far from the player: neither loses HP over 12 ticks (no friendly fire).
- A Sentinel within 3-5 tiles with clear LOS: fires projectiles (G.projectiles grows), then enters a multi-turn no-fire window (sentinel.overheatLeft>0 observable, OR a >=3-turn stretch with no new projectiles).
- Killing an enemy via the possessed host's attack increases G.essence.
When done, run `node verify.js 2` yourself and fix every failure until "PHASE 2 PASSED". Also re-run `node verify.js 1` to ensure no regression. Write less code; everything ships working.
+32
View File
@@ -0,0 +1,32 @@
You are implementing PHASE 3 ONLY of "Body Snatcher" in index.html (exists from Phases 1-2). @AGENTS.md is the full spec — read the §Enemy Roster. @verify.js is the gate; run `node verify.js 3` until "PHASE 3 PASSED" (exit 0). PRESERVE everything; EDIT index.html, do not rewrite.
SCOPE for Phase 3 — add the remaining 9 enemy types: Shielder, Bomber, Healer, Phaser, Turret, Charger, Siren, Mimic, Leech. Each needs BOTH an enemy AI (how it fights you) AND a player kit (what you get when you possess it), exactly as in @AGENTS.md §Enemy Roster. Each gets an intricate layered/shaded canvas-vector sprite per its Sprite line.
ALL 12 enemies must follow these inviolable rules (already established in Phase 2, keep them true):
- speed = turns BETWEEN moves (0 = immobile). Keep (maxHp, damage, speed) DISTINCT for all 12 — no two enemies share the same (hp,damage,speed) tuple.
- NO FRIENDLY FIRE: enemy melee/AoE/charge/projectiles damage the PLAYER only, never other enemies. Your possessed host's attacks still damage enemies.
- Aggro radius (~6 tiles) + line of sight; docile otherwise.
- RANGED enemies OVERHEAT: Sentinel and Turret fire a short burst then enter a forced multi-turn no-fire window (expose turret.overheatLeft / sentinel.overheatLeft, >0 during the window) so the player can close the distance.
Per-enemy essentials (full detail in @AGENTS.md):
- Shielder (maxHp 5, dmg 2, speed 2): frontal shield blocks frontal damage; takes damage from sides/back; Q/E to rotate when possessed.
- Bomber (maxHp 3, dmg 4 suicide, speed 2): chases; explodes 3x3 AoE on death/adjacency damaging the PLAYER only. Possessed: SPACE detonates (suicide, 3x3 AoE 4 dmg to enemies), ejects you as ghost.
- Healer (maxHp 3, dmg 1, speed 2): stays near other enemies, heals them +1/turn within 3 tiles, flees player. Possessed: SPACE AoE heal pulse (self +2, allies +1 within 3).
- Phaser (maxHp 4, dmg 2, speed 3): teleports toward player every 3 turns within LOS, materializes & attacks. Possessed: SPACE blink 5 tiles in facing (through walls), 2-turn cooldown.
- Turret (maxHp 4, dmg 1, speed 0 immobile): stationary; 360° burst of 3 shots (1 every 2 turns) then overheatLeft=3 (silenced + vulnerable). Possessed: rooted; SPACE fires in facing (Q/E rotate); same overheat rhythm.
- Charger (maxHp 5, dmg 2, speed 2): telegraphs 1 turn then charges in a straight line; collision with player = 3 dmg; hits wall = stunned 2 turns; charge does NOT damage other enemies. Possessed: SPACE dash-charge 4 tiles in facing, damaging enemies in path (2 each).
- Siren (maxHp 3, dmg 1, speed 0/3 drift): emits pull field dragging the PLAYER 1 tile/turn within 5 tiles; weak melee. Possessed: SPACE pulls all enemies within 4 tiles one tile toward you.
- Mimic (maxHp 4, dmg 2, speed 0 disguised): looks like a chest; reveals + bursts (2 dmg cross) when player adjacent. Possessed: passive disguise (enemies don't aggro you); SPACE surprise burst (2 dmg 3x3 cross).
- Leech (maxHp 4, dmg 1, speed 2): slow chase; on hit drains 1 from player & heals self +1. Possessed: every hit deals 1 and heals you +1.
SPRITES: each enemy is drawn with many layered canvas primitives (gradients, beveled shell, eyes that track facing, equipment, idle bob). See each Sprite line in @AGENTS.md. Never flat single rects.
HARNESS CONTRACT (read @verify.js phase3; match exactly):
- spawn(type,...) works for all 12 types; each has numeric hp>0, damage, speed.
- The 12 (hp,damage,speed) tuples are all DISTINCT.
- For EACH type: possess it (spawn adjacent + input(' ') + a few ticks) then input(' ') to trigger its special; NO error/throw.
- Pathfinder navigates AROUND a wall: with one wall dropped on the direct line between an enemy and the player (within aggro+LOS), the enemy still closes distance over ticks and never stands on the wall tile.
- Bomber AoE does NOT reduce other enemies' HP (place a victim adjacent to a bomber, aggro, tick; victim hp unchanged).
- Turret within 3-6 tiles & LOS: fires projectiles then enters a multi-turn no-fire window (turret.overheatLeft>0 observable, or a >=3-turn stretch with no new projectiles).
When done run `node verify.js 3` and fix all failures to "PHASE 3 PASSED". Re-run `node verify.js 1` and `node verify.js 2` to ensure no regression. Write less code; everything ships working.
+30
View File
@@ -0,0 +1,30 @@
You are implementing PHASE 4 ONLY of "Body Snatcher" in index.html (exists from Phases 1-3). @AGENTS.md is the full spec — read §Procedural Dungeon Generation, §Essence + Economy, §Shop, §Save/Load. @verify.js is the gate; run `node verify.js 4` until "PHASE 4 PASSED" (exit 0). PRESERVE everything; EDIT index.html.
SCOPE for Phase 4 — procedural generation, 10 floors with escalating enemies, between-floor shop with 3 upgrades, save/load via localStorage.
1. PROCEDURAL DUNGEON GENERATION (random walk + room carving). Start all walls. Carve 5-8 rooms (4x4 to 8x6), connect with 1-tile L-shaped corridors (never diagonal). Place the exit stairs (tile 3) in the room FARTHEST from spawn. Use Math.random so each newRun()/setFloor() produces a DIFFERENT layout. Keep the player's spawn room clear of enemies (>=5 tiles). Every floor 1..10 MUST have an exit tile.
2. setFloor(n): generate floor n with procgen, place the player (ghost) at spawn, set G.floor=n, state 'playing'. Spawn enemies scaled by floor: count = 4 + floor. Difficulty tiers — floors 1-3: Brute/Skitterer/Sentinel; floors 4-6: add Shielder/Bomber/Charger; floors 7-9: add Healer/Phaser/Siren/Turret; floor 10: all 12 types including Mimic/Leech, higher density. Place 1-2 chests (tile 5) with random essence.
3. SHOP between floors. When the player steps on the exit, the NEXT floor may be a shop floor. Specifically: if (currentFloor+1) is in {3,5,7,9}, open the SHOP before generating the next floor. So exiting floor 2 -> shop -> floor 3; exiting floor 4 -> shop -> floor 5; etc. Other exits just descend.
- In the shop, present exactly 3 random upgrade choices from the pool below. Expose them as window.GAME.choices (an Array of length 3). Player picks one with buy(index) (or skips). openShop() debug must also enter shop state with 3 fresh choices.
- buy(index): applies the chosen upgrade, adds it to window.GAME.upgrades (an object), and descends to the next floor (or returns to play). The harness checks G.upgrades CHANGED after buy(0).
4. UPGRADE POOL (3 trees; each tier requires the previous tier in its tree):
Ghost: T1 ghost timer 15->20 (cost 5); T2 possess range +1 (cost 8); T3 phase through walls 1s/5s cd (cost 12); T4 ghost dash 3 tiles/3s cd (cost 15).
Body: T1 retain one ability from previous host (cost 10); T2 overclock +50% stats 5 turns on fresh possess (cost 12); T3 dual-wield two abilities (cost 18).
Meta: T1 start each floor with a random body (cost 8); T2 see enemy types through fog (cost 10); T3 shop 30% discount (cost 6).
Respect prerequisites (T1->T2->T3->T4 within a tree). Ghost T1 must raise the timer cap from 15 to 20 (G.player.timer reflects 20 after purchase on a fresh run).
5. SAVE/LOAD via localStorage key 'bodysnatcher_save'.
- save(): serialize { floor, essence, upgrades, player state, current floor layout } and call localStorage.setItem('bodysnatcher_save', JSON). Auto-save on floor transition, shop purchase, and possession change.
- load(): read the key and RESTORE G.floor, G.essence, G.upgrades, player, grid. The harness sets essence/floor/upgrades, calls save(), mutates, then load() and checks they are restored exactly.
HARNESS CONTRACT (read @verify.js phase4; match exactly):
- Every floor has an exit tile; setFloor(1..10) all have exits.
- 3 generated floors have >=2 distinct wall layouts (Math.random used, not a fixed seed).
- Exiting floor 2 by walking the ghost onto the exit -> state 'shop'. (openShop() also works and sets state 'shop'.)
- G.choices is an Array of length 3 in shop; buy(0) changes JSON.stringify(G.upgrades).
- save() calls localStorage.setItem('bodysnatcher_save', ...). load() restores floor, essence, and upgrades exactly.
When done run `node verify.js 4` and fix all failures to "PHASE 4 PASSED". Re-run phases 1-3 to ensure no regression. Write less code; everything ships working.
+37
View File
@@ -0,0 +1,37 @@
You are implementing PHASE 5 ONLY of "Body Snatcher" in index.html (exists from Phases 1-4). @AGENTS.md is the full spec — read §Game Feel, §Achievements, §Controls, §Visual Style. @verify.js is the gate; run `node verify.js 5` until "PHASE 5 PASSED" (exit 0). PRESERVE everything; EDIT index.html.
SCOPE for Phase 5 — polish, audio, achievements, win/lose, pause, full in-game controls, and a complete bestiary. This is the completeness pass.
1. AUDIO via Web Audio API (no files). Build a small sound module: createOscillator()+createGain() envelopes for hit, possess, death, pickup, explosion, and UI blips. Expose window.GAME.playSound(name) and actually wire the calls into game events. The harness counts AudioContext method calls (createOscillator/createGain/etc.) after a possess/attack — they must be >0. Guard if AudioContext is unavailable/mock. NEVER call new AudioContext() at load time unconditionally (the harness mocks AudioContext; only create it lazily on first sound or user gesture).
2. GAME FEEL. Snappy ~85ms tile movement interpolation; hold-to-move continuous travel; ~600ms live-tick cadence (presentation only — tick(n) stays deterministic). Screen shake on explosions/big hits (scaled intensity). Particles on death, possession, essence pickup, footstep dust. Hit flash (entity flashes white ~100ms) + hit sparks / small floating damage numbers. Polished possession VFX: aura on the current host; dissolve/flash on possess and eject. NONE of this may break the deterministic tick(n) model or the mock-canvas/mock-audio safety.
3. ACHIEVEMENTS (localStorage-tracked on G.achievements as an object of unlocked ids). Implement and grant:
- First Possession (possess first enemy)
- Body Hopper (possess 5 different enemy types in one run)
- Pacifist Ghost (reach floor 3 without taking host damage)
- Essence Hoarder (accumulate >=30 essence) <-- grant when G.essence >= 30
- Deep Diver (reach floor 7) <-- grant when G.floor >= 7 (including via setFloor)
- Escape Artist (win: reach floor 10 exit)
- Bomberman (kill 3 enemies with one Bomber detonation)
- Dual Wield (unlock Body Tree T3)
The harness triggers First Possession (possess), Deep Diver (setFloor(7)), Essence Hoarder (essence=30) and asserts >=3 unlocked. So those three MUST fire deterministically.
4. WIN / LOSE.
- LOSE: when the ghost timer reaches 0 (tick drains it), state -> 'lost' and show a game-over screen with run stats. The harness ticks a ghost ~300 times and expects 'lost'.
- WIN: stepping the ghost onto the exit tile on FLOOR 10 -> state -> 'won' and a victory screen. (Lower floors descend/shop.) The harness walks the ghost to the floor-10 exit and expects 'won'.
5. PAUSE (ESC). Toggle state between 'playing'/'possessed' and 'paused'. The pause overlay is a bordered panel showing Save + Quit and the relevant controls (ESC resume, etc.). From pause, also allow opening the bestiary.
6. CONTROLS EVERYWHERE. Title screen explains WASD/arrows, SPACE, Q/E, X, ENTER, ESC (already from Phase 1 — keep it). HUD shows the contextual SPACE action and the X abandon hint while possessed. Shop overlay shows how to pick/skip/back. Pause overlay shows resume/quit controls.
7. BESTIARY (complete). Pressing 'l' on the title screen (and from pause) opens the legend listing ALL 12 enemies with color/shape, enemy behavior, and possessed kit (HP/damage/special). Draw it as a polished bordered panel.
HARNESS CONTRACT (read @verify.js phase5; match exactly):
- A ghost ticking ~300 times reaches state 'lost'.
- setFloor(10) then walking the ghost onto the exit reaches state 'won'.
- >=3 achievements unlock after possess + setFloor(7) + essence=30.
- AudioContext methods (createOscillator/createGain/...) are called >0 after a possess/attack.
- A ~200-tick stress test (move, possess, attack, descend 3 floors) throws NO error.
When done run `node verify.js 5` and fix all failures to "PHASE 5 PASSED". Re-run ALL of verify.js 1..5 to ensure no regression. Then do a final self-review for spec compliance. Write less code; everything ships working.