# End Game — Closure & Epilogue

## When the Story Ends

The game ends when one of these conditions is reached:

1. **Death** — The character dies and is not revived. The story ends with their final moments.
2. **Quest Complete** — The main story arc reaches a definitive conclusion (the Darkmal is defeated, the Realm is saved or lost, etc.).
3. **Player Retires** — The player decides their character's journey is over and invokes the end.
4. **Mutual TPK** — All party members (if any) have fallen. The Realm's fate is sealed.

## The End Marker

When the story ends, the LLM must include this exact string as a level-3 heading in the narrative:

```
### THE END
```

Everything after this marker is the **epilogue**, which contains:

1. **Why** — A brief statement of why the story ended (death, quest completion, retirement, etc.).
2. **What Happened** — A summary of the final events.
3. **The World After** — At least 2-3 paragraphs describing how the world and its key characters evolved and moved on after the event. This is the closing of the book.

## Example Epilogue Structure

```
### THE END

**Why:** Dillion fell in the final battle against the Darkmal.

**What Happened:** Dillion faced the Darkmal in the heart of the Spire. The battle was fierce — Dillion's blade found its mark, but the Darkmal's final curse was fatal. Both fell.

**The World After:**

The Realm mourned. In the years that followed, the scars of the Darkmal's reign slowly healed. The villages rebuilt, and the wilds grew quiet once more...

Rina took up Dillion's cause, traveling the Realm to protect those who could not protect themselves. She spoke often of the weaver who stood against the darkness...

The Reaper, denied his prize, vanished into the eastern wastes. Some say he still searches for a path to lichdom, but without the Darkmal's power, his reach is broken...
```

## After the End

Once the marker is detected, the TUI shows a "Close the Book and Start a New One" button. Clicking it:

1. Archives the current session folder into `archive/<hero-name>/` with a timestamp.
2. Clears all session state for a fresh start.
3. Presents the character creation flow again.

## Technical Notes

- The LLM must output `### THE END` exactly as shown — case-sensitive, with a space before "THE".
- Only the narrative tool block should contain the marker. No other tool blocks are needed for ending.
- The LLM should **not** call any state-changing tools after the marker — the epilogue is narrative-only.
