# Prompt 0: set up the video pipeline (run once)

Paste this into Claude Code in an empty folder. It builds the toolkit that the product prompts (1–5) use.
You need Node 20+, Python 3 with numpy, ffmpeg, and Chromium installed by Playwright (`npx playwright install chromium`).
For the voiceover version you also need an ElevenLabs API key in the `ELEVENLABS_API_KEY` environment variable.

---

Build a small pipeline that turns a product brief into a 60-second, 1920×1080, 30 fps explainer video in two versions:
one with music and sound effects only, one with an ElevenLabs voiceover over the same music.

**Rendering**

- One web page (`engine/stage.html`) draws the video with Three.js (installed from npm, loaded with an import map).
  The page loads `products/<name>/timeline.json` and `products/<name>/scene.js`, and exposes `window.renderAt(t)`
  that draws the exact frame for time `t` in seconds. Every animation must be a pure function of `t`: no
  `requestAnimationFrame`, no real clock, no randomness without a fixed seed.
- `tools/render.mjs <name>` serves the folder over a local HTTP port, opens the page in Playwright Chromium
  (headed, window moved off-screen, so WebGL gets the GPU; headless falls back to software rendering),
  calls `renderAt(i / 30)` for every frame, takes a JPEG screenshot and pipes it into
  `ffmpeg -f image2pipe ... -c:v libx264 -crf 18` → `build/<name>/silent.mp4`.
- `--stills 2,10,25` renders single frames to `build/<name>/still-<t>.jpg` instead, and `tools/sheet.py` puts
  them on one contact sheet. Always show me a contact sheet before rendering the full video.

**Look** (put this in a shared `engine/kit.js`)

- ACES tone mapping, a room environment map for reflections, an UnrealBloom pass with threshold 1.0 so only
  colours deliberately pushed above 1.0 glow (accent lines, particles, rings), never white text or UI cards.
- A final shader pass: subtle vignette, light film grain (±0.016), slight chromatic aberration, and a zoom-blur
  punch with a quick flash on every scene cut.
- A gradient sky sphere, an optional glowing floor grid, slow dust particles, an eased camera rig from keyframes
  with a gentle handheld drift, light streaks rushing past the camera before the reveal.
- Helpers: floating UI cards drawn on a 2D canvas (with a glowing edge, redrawn per frame when they animate),
  glossy extruded logo marks from a `THREE.Shape`, GPU particles that morph from a scattered cloud into a shape.
- Captions are HTML on top of the canvas: a small uppercase kicker, a big headline whose words rise in with a
  blur one by one (words wrapped in `*stars*` get the accent gradient), a sub line, and stat counters that count up.
  Layouts: left, right, center, top, bottom. Put a soft dark radial scrim behind each caption so it stays readable.

**Sound** (`audio/score.py`, numpy only, no samples or stock music)

- Read the music key, tempo and four chords from `timeline.json`. Before the first cut: low pads, a soft pulse on
  each beat and ticking eighths that build. Put a downbeat exactly on the reveal. After it: kick on every beat with a
  sidechain pump on pads and bass, off-beat hats, a snare from the first feature scene, and a plucked 16th-note
  arpeggio of the chord tones. Ring out on a last chord.
- Effects from the cue list: whoosh into every scene cut, swish, riser before the reveal, impact plus crash on the
  reveal, a glassy shimmer when the logo lands, pops when cards appear, a tap for button presses, a scanner sweep,
  blip counters for numbers. Short reverb on everything. Write `build/<name>/music.wav`.

**Voice** (`audio/voice.py`)

- For every scene with a `voice` line, call ElevenLabs text-to-speech (`eleven_multilingual_v2`, the voice id and
  settings from `timeline.json`), cache each clip by a hash of its text, trim silence, and place it at the scene's
  `voiceAt` (default: scene start + 0.35 s). If a line runs past the next cut, speed it up by at most 12 %, otherwise
  stop and ask me for a shorter line.
- Duck the music about 10 dB under the narration with smooth attack and release, and write `build/<name>/voice.wav`.

**Finish** (`tools/mux.sh <name>`)

- Mux the video with each soundtrack, normalise loudness to −14 LUFS, AAC 160k, `+faststart`, and save
  `out/<name>-music.mp4`, `out/<name>-voice.mp4` and a poster frame.

Test the toolkit with a tiny two-scene product and show me the contact sheet and both files.
