Game: Tower Defense
Theme: Sci-Fi — Orbital Quarantine
Map: Single-path winding corridor through a space station
Date: 2026-04-25

## Prompt

Build a complete single-file 3D tower defense game using Three.js (loaded from CDN via importmap). Theme: sci-fi space station defense titled "Orbital Quarantine". The game must be fully playable, visually polished, and self-contained in one HTML file with no external images or models.

### Map
A 14x10 grid (world coordinates -14 to +14 in X, -10 to +10 in Z). Cell size 2 units. A winding single path from left entry to right exit: Entry(-14,0) → (-8,0) → (-8,-4) → (0,-4) → (0,0) → (6,0) → (6,6) → (12,6) → Exit(14,6). Path tiles are marked; all non-path tiles with at least one path neighbor are buildable. The ground plane shows a grid with subtle alternating colors. Path edges glow with cyan emissive strips.

### Towers — 6 Types, 3 Upgrade Tiers Each

All towers available from wave 1. Upgrades: Level 2 costs 1.5x base, Level 3 costs 2.5x base. Sell returns 60% of total investment. Level 3 unlocks a special ability.

1. **Pulse Turret** (Basic) — Cost: 30, Range: 8, Damage: 8, Rate: 1.0s. Hexagonal blue base + rotating barrel. Lv3: Piercing shots hit 2 enemies.
2. **Rail Gun** (Sniper) — Cost: 50, Range: 14, Damage: 35, Rate: 2.5s. Long barrel on gimbal. Lv3: Critical hits (2x damage, 20% chance).
3. **Plasma Mortar** (Splash) — Cost: 65, Range: 7, Damage: 20, Rate: 2.0s, AoE radius 3. Dome shape with upward-firing arc. Lv3: Larger blast + burning DoT (5dps for 3s).
4. **EMP Field** (Slow) — Cost: 45, Range: 7, Damage: 5, Rate: 1.5s. Tesla coil with electric arcs. Slow effect: -50% speed for 2s. Lv3: Freeze (complete stop for 1s).
5. **Gatling Laser** (Rapid) — Cost: 50, Range: 7, Damage: 5, Rate: 0.15s. Multi-barrel rotating cylinder, green lasers. Lv3: Double barrel (2 projectiles per shot).
6. **Ion Cannon** (Special) — Cost: 90, Range: 10, Damage: 25, Rate: 3.0s. Tall spire that charges up (glow intensifies) then fires devastating beam. Lv3: Chain lightning to 3 nearby enemies on hit.

Towers can cycle targeting priority: First (closest to exit), Strongest (highest HP), Weakest (lowest HP), Fastest (highest speed). Default: First.

### Enemies — 6 Types

| Type | Base HP | Speed | Reward | Special |
|---|---|---|---|---|
| Scout | 30 | 2.0 | 5 | Appears in swarms |
| Soldier | 80 | 1.2 | 10 | Standard threat |
| Tank | 300 | 0.6 | 25 | Heavy armor (-20% damage taken) |
| Sprinter | 20 | 3.5 | 8 | Rushes through defenses |
| Healer | 60 | 1.0 | 15 | Heals nearby enemies 5 HP/s |
| Boss | 1000 | 0.4 | 100 | Unique per wave, 2x size, announced |

HP scaling: baseHP * (1 + 0.15 * wave), capped at 8x baseHP.
Speed scaling: baseSpeed * (1 + 0.05 * wave), capped at 2.5x baseSpeed.
Enemies are colored spheres/boxes/capsules with size proportional to HP. Health bars above each enemy.

### Waves — 20 Waves
Wave 1: 5 scouts (tutorial). Waves 2-4,6-9,11-14,16-19: Mixed compositions with escalating difficulty. Waves 5,10,15,20: Boss waves with swarm support. Occasional swarm waves (20+ scouts). 15-second inter-wave timer with "Next Wave" button. Wave preview shows upcoming composition.

### Economy
Starting gold: 100. Gold per kill as above. Sell: 60% refund. No interest.

### Lives
20 lives. Each enemy reaching the exit costs 1 life (bosses cost 3). Game over at 0.

### 3D Rendering
- Isometric perspective camera angled ~50 degrees, looking down.
- Ambient + directional light with shadows. Point lights on towers.
- Ground: dark hull-grey grid with glowing path.
- Towers: built from cylinders, boxes, cones, spheres. Each type visually distinct. Upgrades add elements (larger barrel, glowing top, extra geometry).
- Enemies: colored geometric shapes, color-coded by type.
- Projectiles: small spheres/elongated shapes with emissive materials (glow).
- Tower barrels rotate to face target.
- Projectiles visibly travel (lerp toward target). Beam weapons show visible beam.
- Particle bursts on enemy death, themed to tower type.
- Range indicator (semi-transparent circle) on tower hover or placement preview.
- Enemy health bars as billboard sprites.
- Camera: mouse wheel zoom, right-click drag pan. Touch: pinch zoom, two-finger pan. Clamp to map bounds.

### UI (HTML/CSS overlay)
- Gold counter, lives display, wave counter, wave timer.
- Game speed: 1x/2x/3x buttons.
- Tower selection panel (bottom bar) with name, cost, greyed-out if unaffordable.
- Click tower to show info panel (stats, targeting mode, upgrade, sell buttons).
- Sell confirmation for expensive towers (>50% of current gold).
- Start screen with "Start Game" button.
- Pause overlay (Escape key).
- Game Over screen with stats and "Play Again".
- Victory screen with option to continue endless mode.
- All elements themed to sci-fi (dark background, neon cyan/blue accents, monospace fonts).

### Performance
Object pool for projectiles and particles. Max 50 enemies, 100 projectiles, 500 particles at once. Frustum culling. InstancedMesh where helpful.

### Audio (procedural via Web Audio API)
Tower fire sounds (short oscillator bursts), enemy death pops, wave start alert, boss warning rumble, game over tone, victory chord. Mute button in HUD.

## Notes

- Sci-fi theme chosen for strong visual contrast and dramatic neon effects in 3D.
- Pulse Turret is the basic workhorse — affordable and reliable.
- Rail Gun rewards players who place towers on long straight path sections.
- Plasma Mortar AoE is critical for swarm waves but expensive to upgrade.
- EMP Field's freeze at L3 is the hard counter to sprinters and bosses.
- Gatling Laser with double barrel at L3 shreds single targets.
- Ion Cannon chain lightning provides the satisfying "ultimate tower" feel.
- Wave scaling caps exist to prevent late-game impossibility.
- Sell confirmation prevents catastrophic misclicks on high-value towers.
