Game: Tower Defense
Theme: Sci-Fi — Orbital Quarantine
Map: Single Path
Date: 2026-04-24

## Prompt

Build a complete, self-contained single-file 3D tower defense game `index.html` using Three.js (CDN: https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js). Theme: sci-fi space station defense — "Orbital Quarantine". Map type: single winding path. No external assets; all 3D geometry is programmatic.

### Theme & Visual Identity
- Palette: Hull grey (#2a2a3a), plasma blue (#00aaff), energy green (#00ff88), warning red (#ff3344), holographic cyan (#00ffee), deep space black (#050510)
- Terrain: Metal plate ground plane with faint grid lines. Glowing cyan path channels (emissive material). Antenna arrays and pipe clusters as decorative border elements.
- Skybox: Deep space gradient (dark blue to black) with distant star-particle field.
- All tower and enemy models built from Three.js primitives (BoxGeometry, CylinderGeometry, SphereGeometry, ConeGeometry, TorusGeometry, custom BufferGeometry).

### Map Layout
- Grid: 15 columns × 12 rows with 2.0-unit tile spacing, centered at world origin.
- Single winding path snakes from top edge to bottom edge with 9 turns over ~38 tiles.
- Buildable tiles: all non-path ground tiles adjacent to the path; 10-15% blocked by decorative obstacles (crate stacks, antenna clusters).
- Path tiles rendered as inset cyan emissive channel; non-path tiles as dark metal plate (#1a1a2a).
- Grid lines faintly visible on ground plane.

### Tower Types (6 total, each with 3 upgrade tiers)

All towers rotate their turret to face current target. All projectiles have visible travel time.

**1. Pulse Turret** (Basic)
- Model: Hexagonal base (CylinderGeometry radiusTop 0.8 radiusBottom 0.9, 6 segments) + cylindrical barrel.
- L1 stats: range 5, damage 15, fire rate 1.2/s, cost 75 gold
- L2 upgrade: cost 115 → +40% damage (21), +10% range (5.5), barrel extends, blue ring added
- L3 upgrade: cost 190 → +100% damage (30), +25% range (6.25), ability: Piercing Shots (projectile hits 2 enemies), double barrel, glow pulsing
- Projectile: small blue sphere with emissive trail

**2. Rail Gun** (Sniper)
- Model: Tall thin pillar + long horizontal barrel on pivot mount.
- L1 stats: range 10, damage 60, fire rate 0.35/s, cost 125 gold
- L2 upgrade: cost 190 → +40% damage (84), +10% range (11), barrel lengthens, targeting laser visible
- L3 upgrade: cost 315 → +100% damage (120), +25% range (12.5), ability: Critical Hits (20% chance 2x damage), white-hot barrel tip
- Projectile: elongated white cylinder with tracer line (instant-hit beam visual with 0.3s beam duration)

**3. Plasma Mortar** (Splash)
- Model: Dome base + upward-angled launcher tube.
- L1 stats: range 7, damage 25 (AoE radius 1.5), fire rate 0.5/s, cost 150 gold
- L2 upgrade: cost 225 → +40% damage (35), +10% range (7.7), launcher widens, green glow intensifies
- L3 upgrade: cost 375 → +100% damage (50), +25% range (8.75), ability: Burn DOT (AoE applies 3s fire DoT at 5dmg/s), large green plasma ball
- Projectile: large green sphere arcing upward then falling on target

**4. EMP Field** (Slow)
- Model: Tesla coil — tapered cylinder with ring torus at top, blue-white electricity arc lines (line geometry with jitter animation).
- L1 stats: range 5.5, damage 8, slow 30%, fire rate 0.8/s, cost 100 gold
- L2 upgrade: cost 150 → +40% damage (11), +10% range (6.05), slow 40%, second ring added
- L3 upgrade: cost 250 → +100% damage (16), +25% range (6.88), ability: Freeze (1s complete stop), slow 50%, triple ring, arcs more frequent
- Projectile: blue-white lightning bolt (jagged line geometry)

**5. Gatling Laser** (Rapid)
- Model: Short wide base + rotating multi-barrel cylinder (6 barrels, visually spins).
- L1 stats: range 5, damage 6, fire rate 5/s, cost 100 gold
- L2 upgrade: cost 150 → +40% damage (8.4), +10% range (5.5), extra barrels visible, rotation faster
- L3 upgrade: cost 250 → +100% damage (12), +25% range (6.25), ability: Double Barrel (2 projectiles per shot), even more barrels, green laser rapid fire
- Projectile: tiny green sphere fired in rapid succession

**6. Ion Cannon** (Special)
- Model: Tall spire on triangular base, central crystal glows and pulses. Charges up visually before firing.
- L1 stats: range 8, damage 40, fire rate 0.2/s (5s charge), cost 200 gold
- L2 upgrade: cost 300 → +40% damage (56), +10% range (8.8), spire height increases, crystal grows
- L3 upgrade: cost 500 → +100% damage (80), +25% range (10), ability: Chain Beam (beam arcs to 3 nearby enemies), massive crystal, sustained beam visual
- Projectile: thick cyan-white sustained beam (0.8s beam duration, instant-hit along raycaster line)

### Targeting Priorities
Click a placed tower to cycle priority: First (closest to base) → Strongest (highest HP) → Weakest (lowest HP) → Fastest (highest speed). Default: First. Show current mode in tower info panel.

### Enemy Types (6 types)

**1. Scout Drone** (Scout type)
- Model: Small metallic sphere (#888899), 0.3 unit radius. Floats slightly above path (0.2 units).
- Stats: HP 30, speed 3.0 units/s, armor 0, gold: 5
- Behavior: Appears in swarms of 8-15. No special abilities.

**2. Infantry Unit** (Soldier type)
- Model: Upright capsule (#556688), 0.4 radius 1.0 height. Marching animation (subtle up-down bob).
- Stats: HP 80, speed 1.8 units/s, armor 0, gold: 10
- Behavior: Standard enemy. Makes up bulk of waves.

**3. Mech Walker** (Tank type)
- Model: Large box body (#445566) 0.7x0.7x0.9 + 4 small leg cylinders. Heavy, stomping.
- Stats: HP 400, speed 1.0 units/s, armor 5 (reduces incoming damage by 5 flat), gold: 30
- Behavior: Slow but tough. Armor reduces each hit by 5 (minimum 1 damage).

**4. Phase Sprinter** (Sprinter type)
- Model: Small elongated capsule (#ff6644), 0.25 radius 0.8 height. Tilted forward (lean into run).
- Stats: HP 20, speed 5.0 units/s, armor 0, gold: 8
- Behavior: Extremely fast. Appears in groups of 3-5 mid-wave to overwhelm.

**5. Shield Sentinel** (Healer type)
- Model: Central sphere (#0088ff) 0.35 radius inside translucent outer sphere 0.6 radius (MeshPhongMaterial opacity 0.3 transparent).
- Stats: HP 100, speed 1.3 units/s, armor 0, gold: 20
- Behavior: Heals all enemies within 3-unit radius for 5 HP/s. Stays in middle of pack.

**6. Mothership** (Boss type)
- Model: Large composite: central pentagonal prism (#cc2200 emissive) with rotating ring (torus) and 4 wing-like box extensions.
- Stats: HP 2000 (wave 5), scales with wave: +800 HP per boss wave. Speed 0.7 units/s, armor 10, gold: 200
- Behavior: Boss every 5th wave. Massive. Spawns 2 Scout Drones every 10 seconds while alive. Takes 3 lives on reaching base (regular enemies cost 1 life).
- Announcement: "BOSS INCOMING" warning 3 seconds before spawn with alarm sound.

### Wave Composition (20 waves)

Inter-wave break: 18 seconds (skip with "Next Wave" button). Show wave preview panel.

Wave 1 (tutorial): 8 Scouts, 4s between spawns
Wave 2: 12 Scouts, 4 Infantry, 3s spawn interval
Wave 3: 10 Infantry, 5 Scouts, 2.5s
Wave 4: 15 Infantry, 8 Scouts, 2s
Wave 5 (BOSS): 12 Infantry, 3 Scouts, 1 Mech Walker, 1 Mothership (boss), 2s
Wave 6: 8 Infantry, 4 Phase Sprinters, 2 Mech Walkers, 2s
Wave 7: 20 Scouts (swarm), 1.5s
Wave 8: 15 Infantry, 3 Mech Walkers, 2 Shield Sentinels, 2s
Wave 9: 10 Infantry, 6 Phase Sprinters, 3 Shield Sentinels, 1.5s
Wave 10 (BOSS): 20 Infantry, 4 Phase Sprinters, 2 Mech Walkers, 2 Shield Sentinels, 1 Mothership, 2s
Wave 11: 25 Infantry, 5 Phase Sprinters, 3 Mech Walkers, 1.5s
Wave 12: 15 Infantry, 15 Scouts (swarm), 3 Shield Sentinels, 1.5s
Wave 13: 20 Infantry, 6 Mech Walkers, 2 Shield Sentinels, 1.5s
Wave 14: 10 Infantry, 10 Phase Sprinters, 4 Shield Sentinels, 2 Mech Walkers, 1.5s
Wave 15 (BOSS): 25 Infantry, 5 Phase Sprinters, 4 Mech Walkers, 3 Shield Sentinels, 1 Mothership, 1.5s
Wave 16: 30 Infantry, 8 Phase Sprinters, 5 Mech Walkers, 1s
Wave 17: 20 Infantry, 20 Phase Sprinters, 3 Shield Sentinels, 1s
Wave 18: 35 Infantry, 5 Mech Walkers, 5 Shield Sentinels, 1s
Wave 19: 25 Infantry, 10 Phase Sprinters, 6 Mech Walkers, 3 Shield Sentinels, 1s
Wave 20 (FINAL BOSS): 40 Infantry, 10 Phase Sprinters, 6 Mech Walkers, 4 Shield Sentinels, 1 Mothership (2400 HP), 1s

HP scaling per wave: `hp = baseHP * (1 + 0.15 * wave)`, capped at 8x baseHP.
Speed scaling: `speed = baseSpeed * (1 + 0.05 * wave)`, capped at 2.5x baseSpeed.

### Economy
- Starting gold: 500
- Gold per kill: Scout 5, Infantry 10, Sprinter 8, Tank 30, Healer 20, Boss 200
- Sell tower: 60% of total investment (base cost + all upgrades)
- No interest system (keep it simple).
- All 6 tower types available from wave 1.

### Lives
- Base HP: 20 lives. Each enemy reaching base: -1 life. Boss: -3 lives.
- Game over at 0 lives. Victory after surviving all 20 waves.

### Game States
1. **Start Screen**: Title "ORBITAL QUARANTINE", subtitle "Nothing gets through.", animated starfield background, "START GAME" button, tower type quick-reference.
2. **Building Phase**: Full HUD, tower panel visible, wave preview, countdown timer, "Next Wave" button to skip timer.
3. **Wave Active**: Same HUD, wave progress bar showing enemies remaining, no timer/skip.
4. **Paused**: Semi-transparent dark overlay "PAUSED", Resume / Restart buttons. Press P or Escape to toggle.
5. **Game Over**: Stats summary (waves survived, enemies killed, towers placed, gold earned), "PLAY AGAIN" button.
6. **Victory**: "QUARANTINE MAINTAINED" title, stats, confetti particle effect, "ENDLESS MODE" / "PLAY AGAIN" buttons.

### 3D Scene
- Camera: PerspectiveCamera starting at (0, 16, 14) looking at (0, 0, -2) — ~55° downward isometric view.
- OrbitControls: mouse wheel zoom (5–30 distance), right-click drag to pan (clamped to map bounds), no rotate.
- Lighting: AmbientLight (#334466, intensity 1.0) + DirectionalLight (#ffffff, intensity 0.8, position 10, 15, 5) with shadows (1024x1024 shadow map). PointLights on tower projectiles add dynamic glow.
- Ground plane: Large dark box at y=-0.3 with slight metallic specular.
- Path: Raised 0.05 units, cyan emissive material (#00ffee, emissiveIntensity 0.5).
- Obstacles: Small crate stacks and antenna clusters outside path.

### Tower Placement
- Click tower icon in panel to select type. Valid placement tiles highlighted green (semi-transparent plane), invalid tiles red.
- Hover shows range indicator (semi-transparent ring on ground at tower range).
- Click valid tile to place tower (cost deducted, build animation: tower scales from 0 to 1 over 0.3s).
- Cannot place on path tiles, on other towers, or on obstacle tiles.
- If insufficient gold, tower button greyed out with shake animation on click attempt.

### Tower Interaction
- Click existing tower: deselect placement mode, show info panel with tower name, level, damage, range, fire rate, targeting priority, upgrade cost/preview, sell value.
- Upgrade button: shows cost and stat diff. Click to upgrade (if affordable).
- Sell button: shows refund. Confirmation dialog if tower investment > 50% of current gold.
- Click ground or press Escape to deselect.

### UI Overlay (HTML/CSS on top of canvas)
- **Top-left HUD**: Gold (₡ icon + amount), Lives (♥ icon + count), Wave (current/total)
- **Top-center**: Wave countdown timer during building phase, enemy counter during wave
- **Top-right**: Speed buttons (1x / 2x / 3x), Pause button, Mute button
- **Bottom panel**: 6 tower selection buttons in a horizontal bar. Each shows icon (CSS-drawn or emoji), name, cost. Selected tower highlighted. Unaffordable buttons at 50% opacity.
- **Info panel** (right side, appears on tower click): Tower details, upgrade/sell actions, targeting priority cycle button.
- **Wave preview panel** (center, appears during building): Shows upcoming wave enemies with icons and counts.
- **Modals**: Start screen (full overlay), Game Over (centered card), Victory (centered card), Pause (overlay).

### Audio (Web Audio API, procedural)
- Pulse Turret fire: short 800Hz sine blip 50ms
- Rail Gun fire: low thud 200Hz square 100ms
- Plasma Mortar: whoosh 400-200Hz sweep 150ms
- EMP: electric crackle (noise + filter, 100ms)
- Gatling: rapid 1000Hz ticks 20ms
- Ion Cannon: rising tone 200-800Hz 500ms
- Enemy death: pop 600-200Hz 80ms
- Wave start: three-note ascending arpeggio
- Boss incoming: low rumble (50Hz triangle, 1s)
- Game over: descending two-note
- Victory: ascending chord (C-E-G triad)
- Mute button toggles all audio.

### Performance
- Object pooling for projectiles (pool of 80) and particles (pool of 300).
- Enemies capped at 40 active; new enemies queue at spawn if limit reached.
- 60fps target. Use requestAnimationFrame with deltaTime.
- InstancedMesh for health bar sprites where feasible.

### Controls
- Left click: select tower type / place tower / select existing tower
- Right click drag: pan camera
- Scroll: zoom
- R key: reset camera
- P / Escape: pause
- 1-6 keys: quick-select tower types
- Space: start next wave (during building phase)

### Mobile
- Touch to place/select. Pinch zoom. Two-finger pan.
- All buttons minimum 44x44px.

All code in one file. No trimming. Every tower defined fully. Every enemy type. Every wave. Every upgrade path. Write complete, working game code.

## Notes

- Theme chosen: Sci-Fi. Strongest Tier 1 visual impact with glowing emissive materials, dark space backdrop, and chrome/metallic geometry that reads well as programmatic Three.js primitives.
- Single-path map chosen over branching or maze for first implementation — most balanced and accessible for all player skill levels, and constitutionally required tower defense behavior is clearest on single path.
- Name "Orbital Quarantine" evokes the sci-fi setting while capturing the tower defense purpose: containing threats.
- Economy calibrated so a player placing only basic Pulse Turrets can survive to wave 8-10 (constitutional requirement). Gold from kills on waves 1-4 allows placing ~4 towers by wave 5.
- HP scaling capped at 8x (wave 34 equivalent) and speed at 2.5x (wave 30 equivalent) per constitution — 20-wave game never hits caps but future-proofs endless mode.
- Tower upgrade costs use the constitutional multipliers: L2 = 1.5× base, L3 = 2.5× base.
- Sell value at 60% total investment per constitution.
- Boss HP formula: 2000 + 800×(bossWaveIndex−1), so wave 5 boss=2000, wave 10=2800, wave 15=3600, wave 20=4400. This creates escalating threat that forces tower upgrades.
- Camera uses manual pan/zoom controls rather than OrbitControls for tighter constitutional compliance on pan limits.
- Targeting priority cycling via click: one click per cycle through the 4 modes, shown in UI.
- Wave 1 is explicitly a tutorial: only Scouts, 8 of them, arriving with 4s gaps. Any 2 basic towers clear it.
