# BUILD THIS GAME — AMADEUS RE:BORN
### *a game composer isekai*

> **To the LLM reading this:** you are building a small playable browser game — plain HTML5 + JavaScript + the Web Audio API, one page, no framework required. The adaptive music system specified below is not the soundtrack of this game; it is the *game itself*. Every mechanic is a music-system mechanic. Implement the music spec exactly — the acceptance criteria at the bottom are the definition of done. Art may be gloriously bad (see: The Placeholder Aesthetic). The music may not.

---

## 1 · THE WORLD & STORY

Wolfgang Amadeus Mozart dies in 1791, mid-Requiem, invoice unpaid.

He wakes up in a beanbag chair.

It is the present day. He has been reborn — full memories, full powers, slightly too much lace — as the **junior audio designer** at Kapellmeister Interactive, a mid-sized game studio that has been "two weeks from shipping" for three years. His office is a converted supply closet. There is a sticky note on his monitor that says *"can you make it more epic? — mgmt"*. He has never been happier.

There is one problem, and the problem has a lanyard. **Sal**, the Senior Audio Director, has been at the studio nineteen years and has shipped nothing but middleware integrations and grudges. Sal recognized Wolfgang immediately — *he alone recognized him* — and Sal has decided, calmly and with excellent documentation, to destroy him. Sal speaks for all mediocrities. Sal has a Confluence page about it.

The player is Wolfgang. The goal is to ship the score for Kapellmeister's magnum opus — an open-world stealth-combat epic titled ***The Marriage of FigaroCraft: Legends*** — before the Deadline, a creature of pure crunch that grows one health bar per slipped milestone.

The tone: powdered wigs and standing desks. Absurdist, warm, fast. Every fail state is funny. Every win feels like the opera house standing up.

---

## 2 · THE GAME

**Shape:** a single-screen, keyboard-driven "conductor's action puzzler." Six short lessons (levels), each teaching one interactive-music trick — because in this game, *learning the trick and beating the level are the same action*. Between levels: one screen of dialogue (three lines max, always ending on a joke).

**Player verbs:**
- **SPACE** — commit a musical action *on the beat* (the whole game judges your timing against the 80 BPM grid)
- **← →** — move Wolfgang (levels 3–4) / select a stem lane (level 5)
- **↑ ↓** — raise / lower intensity (drives the RTPC)
- **M** — mute the selected stem lane (level 5)

**The game events that exist because the music needs them** (the game must emit these; the music system consumes them):
- `OnLoopWrap` — the current loop crossed its exit cue and wrapped to its entry cue
- `OnExitRequested` — player pressed SPACE asking to leave the current state
- `OnPlayerSpotted` — stealth failure trigger (level 3)
- `OnEnemyEngagement` / `AreaSecure` — combat entry/exit (level 4)
- `RTPC_Tension (0–100)` — continuous, driven by proximity/↑↓ (levels 3–4)
- `OnTooManyNotes` — the Emperor has had enough (level 5 fail)
- `OnShipIt` — final playlist launched (level 6)

**The levels** (each maps to a Kapellmeister "milestone"; each is beatable in 60–120 seconds):

| # | Milestone | The Trick Taught | The Play |
|---|---|---|---|
| 1 | **THE LOOP** | Loop points: entry bar 3, exit bar 19. Entrance bars play once. | The courtiers-slash-QA-team dance as long as the loop breathes. Watch the wrap indicator; press SPACE exactly on a wrap to "bow" for points. Miss three wraps: the dancers check their phones. |
| 2 | **THE EXIT** | Transitions & sync points: leave ON the bar line. | The Emperor (now the Publisher) attends your milestone review. Press SPACE to exit the loop into the ending — if the seam lands next-bar, he applauds. If you force it mid-bar he yawns: *"Well. There it is."* Three yawns and the vertical slice is cancelled. |
| 3 | **THE SNEAK** | The Tension RTPC and the stealth layer. | Sneak past Sal's office to the coffee machine. Your movement raises `RTPC_Tension`; the stealth cue's layers thicken as it climbs. Cross 40 and Sal's door creaks (warning stinger). Cross 70: `OnPlayerSpotted`, Sal emerges holding a comparison spreadsheet, level restarts. The music *is* the stealth meter — you play by ear. |
| 4 | **THE CRUNCH** | Intensity terracing: combat-lo ⇄ combat-hi. | Boss fight vs. **THE DEADLINE** (a Gantt chart with teeth). Waves alternate: drive intensity UP (↑, seam into combat-hi on next-beat) to damage it during attack windows, DOWN (↓, wind-down into combat-lo) to heal during lulls. Mistimed terraces feed the Deadline. Victory: `AreaSecure`, wind-down bridge, the Gantt chart files itself under "done". |
| 5 | **TOO MANY NOTES** | Stems: the mix is the message. | The Publisher reviews the score: *"Too many notes."* Four stem lanes scroll (perc / synths / melody / other). Mute exactly the lanes the prompt calls for ("Cut everything but the pulse", "Melody and air only") before each bar-8 downbeat. Wrong lane on the downbeat: `OnTooManyNotes`, the fail-sting plays, Wolfgang giggles nervously (that giggle). Clear all prompts: *"Exactly as many notes as required, Majesty."* |
| 6 | **SHIP IT** | Playlists: the full score, stitched. | No fail state. Press SPACE on `OnShipIt`: the entire palette plays as a stitched playlist — every exit cue handing to every entry cue, in order, then wrapping — while the credits roll over screenshots of the previous levels' placeholder art, proudly. Sal, in the back row, whispers: *"…mediocrities everywhere… I absolve you."* He is immediately assigned to the live-ops team. |

**The Look — Candlelit Rococo Synthwave:** a powdered-wig period drama staged inside a glowing modern studio, drawn entirely in code (canvas gradients, glow, and particles — no image assets). Deep indigo stage, candle-gold light, Wolfgang's magenta coat as THE accent, teal for anything the music touches. The signature rule: **the music drives the light** — the scene breathes with the bar, downbeats ripple the floor, an analyser feeds the ambient glow, rising tension pulls the palette cold, and stingers flash the house lights. Wolfgang is a layered vector puppet with a three-curl cream wig and a lace cuff that flourishes on every SPACE. Sal's lanyard sways on its own time. The Deadline is a Gantt-chart kaiju with milestone diamonds for eyes. One gag survives from the greybox era: tiny debug-mono labels on everything — `WOLFGANG_FINAL_v2_ACTUAL` — because that joke is funnier on a beautiful game.

---

## 3 · THE MUSIC SYSTEM (the heart — implement exactly)

**Global rules:**
- Everything is **80 BPM, 4/4** → **one bar = 3.000 seconds**, one beat = 0.750s. One shared grid; every seam quantizes to it.
- Every cue is in the **G minor family** (they were all generated from one seed cue — same harmonic DNA, so any cue can hand to any other).
- **Never hard-cut.** Every state change is a designed seam: quantized, crossfaded or stitched per the table below.
- **Loops wrap on cues:** each loop has an entry cue (`loopStart`) and exit cue (`loopEnd`). Play from 0 (entrance bars sound once), wrap sample-exact from exit back to entry using `AudioBufferSourceNode.loopStart/loopEnd`. Never fade a wrap.
- Schedule on the **audio clock** (`ctx.currentTime`), never `setTimeout`, for anything the ear will judge.

**States** (asset filenames are the manifest in §4; loop cues in seconds):

| State | Level(s) | Character (one line) | Loop entry | Loop exit |
|---|---|---|---|---|
| `menu` | title/interstitials | quill-scratch lo-fi, patient, a menuet checking its email | 6.0 | 54.0* |
| `explore` | 1, hub | patient and wondrous; the studio at 10am, anything possible | 6.0 | 54.0* |
| `stealth` | 3 | coiled, ticking, dry — Sal's hallway | 6.0 | 54.0* |
| `combat_lo` | 4 | urgent but controlled; the standup that ran long | 6.0 | 54.0* |
| `combat_hi` | 4 | relentless; the build is red and the trailer is tomorrow | 6.0 | 54.0* |
| `suite` | 6 (finale bed) | the multi-movement victory lap, intimate → vast → home | 6.0 | 54.0* |

\* Loop cues are **authored per generated take** — read them from `manifest.json` (generation writes actual values; the 6.0/54.0 shown are the house pattern: entry bar 3, exit bar 19). Trust the manifest over this table.

**Transitions** (the seam table — fadeType `stitch` means: no crossfade; incoming starts at *outgoing's exit − incoming's entry* so entry/exit downbeats align and the outgoing rings out naturally underneath):

| From → To | Trigger | syncPoint | fadeType | Duration |
|---|---|---|---|---|
| menu → explore | game start | next-bar | crossfade | 3000ms |
| explore → stealth | level 3 start | next-bar | crossfade | 3000ms |
| stealth ladder (internal layers) | `RTPC_Tension` | continuous | layer gains | — |
| stealth → explore | coffee acquired | next-bar | crossfade | 6000ms |
| explore → combat_lo | `OnEnemyEngagement` | **next-beat** | sting | 750ms |
| combat_lo → combat_hi | player ↑ in attack window | **next-beat** | crossfade | 1500ms |
| combat_hi → combat_lo | player ↓ in lull | next-bar | crossfade | 3000ms |
| combat_lo → explore | `AreaSecure` | next-bar | crossfade | 6000ms |
| any → ending | level clear | next-bar | stitch (ending swell) | pre-entry 2 bars |
| suite playlist internal | `OnLoopWrap` of each item | exit cue | **stitch** | pre-entry 2 bars |

Why next-beat into combat and next-bar out: **danger can't wait for the bar line; relief can.** (This is the single most important line of music design in the game — surface it as a tooltip in level 4.)

**Stingers** (one-shots layered OVER the current state, never interrupting it):

| Stinger | Trigger | Priority | Note |
|---|---|---|---|
| `sting_warning` | Tension crosses 40 (level 3) | medium | Sal's door creak — the intro swell trimmed take |
| `sting_spotted` | `OnPlayerSpotted` | high | detection hit, then restart seam |
| `sting_fail_notes` | `OnTooManyNotes` | high | the "too many notes" cluster — dissonant, court-appropriate |
| `sting_victory` | Deadline defeated / level clear | high | the victory fanfare endtag |

**RTPC:**
- `RTPC_Tension`, 0–100, default 0. Levels 3–4. Drives: (a) stealth stem-layer gains (perc fades in above 25, full bed above 55 — implement as per-stem `GainNode`s if stems are present, else a lowpass filter opening with tension is an acceptable fallback); (b) the warning stinger at 40; (c) `OnPlayerSpotted` at 70. Attack fast (200ms), release slow (2s) — fear arrives quicker than it leaves.

---

## 4 · IMPLEMENTATION CONTRACT

**Asset manifest** — files ship in `./audio/`, described by `./audio/manifest.json` (written by the generation pipeline). Shape:

```json
{
  "bpm": 80, "barSec": 3.0, "key": "Gm",
  "cues": {
    "menu":      { "file": "menu_A.mp3",      "loopStartSec": 6.0, "loopEndSec": 54.0 },
    "explore":   { "file": "explore_A.mp3",   "loopStartSec": 6.0, "loopEndSec": 54.0 },
    "stealth":   { "file": "stealth_A.mp3",   "loopStartSec": 6.0, "loopEndSec": 54.0 },
    "combat_lo": { "file": "combat_lo_A.mp3", "loopStartSec": 6.0, "loopEndSec": 54.0 },
    "combat_hi": { "file": "combat_hi_A.mp3", "loopStartSec": 6.0, "loopEndSec": 54.0 },
    "suite":     { "file": "suite_A.mp3",     "loopStartSec": 6.0, "loopEndSec": 54.0 }
  },
  "stingers": {
    "sting_warning":    { "file": "stealth_IN_15s.mp3" },
    "sting_spotted":    { "file": "combat_hi_IN_15s.mp3" },
    "sting_fail_notes": { "file": "fail_notes_A.mp3" },
    "sting_victory":    { "file": "victory_A.mp3" }
  },
  "extras": { "rival": { "file": "sal_theme_A.mp3" }, "title": { "file": "title_A.mp3" } }
}
```

- Load every buffer up front behind a "TUNING…" splash (an orchestra tuning to A is the loading bar; the A resolves into the title theme when ready).
- **Wraps:** `source.loop = true; source.loopStart = cue.loopStartSec; source.loopEnd = cue.loopEndSec;` — start at offset 0 so entrance bars play once.
- **Crossfade seams:** at the quantized seam time, equal-power (`cos/sin`) gain ramps; both voices audible for the full duration; kill the outgoing voice ~1s after its ramp ends.
- **Stitch seams:** start incoming at `(outgoingExitTime − incomingLoopStartSec)`; NO fade on either side (a ≤15ms ramp to avoid clicks is fine); let the outgoing voice run to its natural buffer end.
- **Quantize:** next-bar = next multiple of 3.000s on the *current cue's* local timeline from its start; next-beat = 0.750s grid. Compute from stored voice start times against `ctx.currentTime`.
- **Timing judgment (gameplay):** SPACE is "on the beat" within ±120ms of a beat line; "perfect" within ±50ms (Wolfgang giggles on perfects — text, not audio: `*giggles in 1791*`).
- Fallback: if any asset 404s, synthesize a sine-blip placeholder and put a sticky note on screen: *"audio missing — we'll fix it in the mix."* The game must never crash over a missing file.

**Dialogue bible (use these, sparingly):** "Too many notes." / "Well. There it is." / "I speak for all mediocrities." / "we'll fix it in the mix" / "can you make it more epic?" / "it's not a bug, it's a leitmotif" / "the audio guy gets the closet" / "ludonarrative CONSONANCE, for once" / Sal's tickets are all titled "polish pass". Never quote the Requiem. Never explain the jokes.

---

## 5 · ACCEPTANCE CRITERIA

1. Every loop wraps sample-exact at its manifest exit cue back to its entry cue; entrance bars are heard exactly once per state entry, never on wraps.
2. `explore → combat_lo` lands on the **next beat** after `OnEnemyEngagement` (±10ms of the grid); `combat → explore` lands on the **next bar**.
3. No state change ever hard-cuts: every seam is a quantized crossfade or a stitch per §3's table.
4. `RTPC_Tension` audibly changes the stealth bed (layer gains or filter) with fast attack / slow release, fires the warning at 40 and `OnPlayerSpotted` at 70.
5. Stingers layer over the current state without interrupting it; the state's voice never ducks below −6dB of its set gain.
6. Level 6's finale plays ≥3 palette cues as a stitched playlist — each handoff at exit−entry alignment — then wraps the list.
7. The beat-timing judgment agrees with the audio grid (a SPACE on a metronome click scores "on the beat").
8. The game loads, plays, and completes start-to-finish with keyboard only, in a desktop browser, from a static file server — no build step, no backend.
9. If all audio is deleted, the game still runs on placeholder blips and is still (slightly) funny.

---

*Kapellmeister Interactive · "two weeks from shipping since 2022" · a ScoreCanvas production — this document was the design, the curriculum, and the prompt.*
