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.
