# Default system screens

These are the engine's default system screens (`packages/web/src/system/`), used when the project's plugins don't replace them.
This page covers what the player sees and does. The look comes from the CSS variables in `default.css` (`--lm-*`), and the text from `strings.ts` (English in `strings-en.ts`).
Each project changes the look and controls with `ui` in liminalia.json (see "Game settings" below; you can edit them on the "Game settings" tab in Studio while watching a preview).

## Flow

"Click to start" ("Tap to start" on touch devices; not shown in the desktop version) → title → game. When the game ends, it returns to the title.

The title screen buttons are "New Game," "Continue" (when there is save data; an autosave alone is enough), "Extras" (once anything is unlocked), "Settings" and "Quit" (only in the desktop version and the Android app).

## Controls

| | Mouse and keyboard | Touch | Gamepad |
|---|---|---|---|
| Advance | Click, Enter, Space, wheel down | Tap | A |
| Back a page, forward a page | PageUp, PageDown (wheel down rolls forward from a page you went back to) | Swipe right, swipe left | LB, LT |
| Menu | Right-click, Esc | Long press, the menu button at the top right | START, B |
| Close a screen | Right-click, Esc | Close button | B |
| Log (backlog) | Wheel up, B | Swipe down | Y |
| Hide window | H, Delete, middle click, "Hide" in the quick menu | Swipe up | X |
| Skip | Hold Ctrl, Tab (each press toggles it) | — | Hold RB, L3 (each press toggles it) |
| Auto | A | From the menu | RT |
| Choose an option | 1 to 9 (the option with that number) | Tap | A |
| Settings | C, "Settings" in the quick menu | From the menu | SELECT |
| Quick save / load | S / L | From the menu | D-pad right, left (while playing; loading asks first) |
| Previous choice, next choice | From the menu (assign keys with `ui.keys`) | From the menu | — |
| Select a button | Arrow keys | — | D-pad, left stick |
| Scroll an open screen (Log, Save, Extras and so on) | Wheel | Swipe | Right stick |
| Fullscreen | Alt+Enter, F11 (desktop version), "Display" in Settings | "Display" in Settings | — |
| Mute | M (if that key is assigned to another action, that action comes first) | "Mute" in Settings | R3 |

- When the player (the "Controls" tab in Settings) or the project (`ui.keys`) assigns one of the default keys (B, H, Delete, A, Tab, C and so on) to another action,
  that action comes first (the key is removed from the default). To turn off a default key, write the action in `ui.keys` with an empty array (`"skip": []`).
  Turn off middle click with `ui.input.middleClick: "none"`, and choosing with the number keys with `ui.input.numberKeys: false`
- Gamepad buttons use the names of the standard layout (A is the bottom button, B the right one). The labels on the "Controls" screen and in the "Controls" tab of Settings change with "Button labels" in Settings
  ("Automatic," "Xbox," "PlayStation," "Switch"). "Automatic" decides from the name of the connected gamepad. RT was mute in earlier versions
  (you can swap it in the "Controls" tab of Settings). When a gamepad that the browser can't read as the standard layout (one whose `mapping` in the Gamepad API isn't `standard`) is connected,
  the buttons may not match, so the game tells the player once, at first, to swap them in the "Controls" tab of Settings
- **Text input** (`@text-input`): `mode=number` uses a numeric keyboard and accepts digits only (full-width digits become half-width), `mode=password` hides the typed characters,
  and with `pattern=` (a regular expression), the input can't be confirmed until the whole text matches it. On touch devices, the input frame moves up into the visible area above the on-screen keyboard.
  When a gamepad is connected, an on-screen keyboard (hiragana, katakana, alphanumeric; digits only for `mode=number`; alphanumeric only for English games) appears below the frame,
  and the player selects keys with the D-pad and enters them with A (in the desktop version, Steam's on-screen keyboard is used when it's available). While the frame is shown, the D-pad selects the frame's buttons and doesn't quick save and so on
- Advancing during auto or skip only stops it. Auto and skip also stop at choices (set "Auto after choices" and "Skip after choices" in Settings
  to "Keep going" to start them again after choosing). While the window is hidden, any input only brings the window back
- During auto and skip (including while Ctrl or RB is held), a small "Auto" or "Skip" appears at the top left (not while a screen is open or while the window is hidden).
  Set its position with `ui.indicator` (top-left, top-right, bottom-left, bottom-right, hidden). Its color is the same as the quick menu's (`ui.menuBar.color`, `shadow` and the theme).
  Style it with `.lm-indicator` in CSS (`data-state` is auto or skip); to make the project's own, use `screens.indicator` in a plugin (docs/plugins.md).
  When the project replaces the quick menu, it doesn't appear unless you write `ui.indicator` or replace it with `screens.indicator`
- Advancing while waiting for an effect (background change, fade to black, camera, `@wait` and so on) skips the running effect to the end (sound doesn't stop;
  [format.md](design/format.md) chapter 5). `ui.input.skipEffects: false` turns this off
- The arrow keys and the D-pad select buttons on the open screen, the title and choices, nearest in that direction first (the selected button gets an outline).
  Sliders in Settings change value with left and right. While playing, up and down on the arrow keys and the D-pad select HUD buttons (`@hud-button`); Enter and A press them, and Esc and B stop selecting
- On touch devices, a menu button appears at the top right instead of the quick menu. When a landscape game is held upright, it asks the player to turn the device sideways.
  On touch devices and in portrait games, the text and buttons of the codex, investigations, map choices and stacked notices are made larger (text at least 12px on screen, buttons at least 44px; in portrait games, the map choice panel goes at the bottom).
  On devices where the game screen, fitted upright, would be narrower than 560px (CSS px) (phones), the notice covers the whole screen, and while it does, sound, videos, auto and the choice time limit
  are paused, the same as when going to the background. On devices where it's wide enough (tablets), only a notice appears at the top, and "Keep playing" closes it (it isn't shown again during that session)
- Swiping to the right goes back a page, and swiping to the left rolls forward from a page you went back to (you can go back even while choices are shown; swipes that start at the left or right edge of the screen
  are ignored so they don't clash with the browser's back gesture). `ui.input.swipeSide: "none"` turns this off (for example, when the project uses sideways swipes on the screen)
- Back (the back button and back gesture in the Android app, and back in mobile browsers) depends on the situation. An input frame (`@dialog`) is canceled (`@text-input` does nothing),
  an open screen is closed, a hidden window comes back, and during the game the menu opens. On the title, the Android app, which can close itself, asks whether to quit,
  and browsers go back to the previous page. Mobile browsers and PWAs added to the home screen push one history entry (when back is pressed) so that back doesn't leave the game.
  If the project replaces the system screens, handle it with `system.back()` (return true when it's handled)
- In the iOS app and in browsers, which can't close the game themselves, `@quit` says so and returns to the title screen (the Android app closes). "Quit" on the title and in the menu
  appears only in the desktop version and the Android app. The confirmation is a frame inside the game, in the language being played. In the mobile apps, `@open-url` opens in the device's browser
  (http, https and mailto only). Links in the project's HTML that lead outside the game also open in the device's browser
- During auto and while `@movie` plays, the screen doesn't turn off (it doesn't sleep; Screen Wake Lock in browsers, `FLAG_KEEP_SCREEN_ON` in the Android app,
  `isIdleTimerDisabled` in the iOS app). `@vibrate` vibrates the device in the Android app, uses haptics in the iOS app (on iPads and other devices without haptics it does nothing),
  and uses the Vibration API in browsers; it also vibrates a connected gamepad
- **Next choice**: Jumps to the next choice (without advancing the text; it rebuilds the state at the choice, the same way as loading. The skipped text goes into the backlog,
  and things that happen when skipping through, such as unlocking CGs and chapters, still happen. The text isn't marked as read. If there are no more choices ahead, it only says so).
  Unread text follows the skip setting in Settings; with "Read only," it jumps to the first unread page before the choice and stops there.
  With `ui.nextChoice.readOnly: true`, it jumps only when everything up to the next choice has been read (if there is unread text, it only says so).
  It first runs ahead without showing anything to check, and if there are no more choices ahead, it says so and doesn't jump
- **Rollback**: Goes back one page at a time (without asking). The text of the page you go back to appears all at once. If a choice was shown just before the current page, it goes back to that choice.
  From a page you went back to, you can roll forward (along the option you chose before), and if you read on and reach the same place, you can keep rolling forward. Choosing a different option discards the pages to roll forward to.
  You can go back up to 100 pages from the newest. Save data holds the return points of the newest 20 pages, as differences from the save, so you can go back that far after loading too
  (save data made by earlier versions doesn't have them, so you can't go back from the loaded page. If space runs short, this record is trimmed first).
  Read status, unlocked extras and settings aren't rolled back. The BGM becomes the one at the page you went back to.
  `ui.rollback.fixChoices: true` lets the player choose only the previous option after going back, and `ui.rollback.enabled: false` turns rollback off.
  `ui.input.wheelUp: "rollback"` makes wheel up go back a page instead of opening the backlog. Rollback goes in the quick menu only when you write it (`rollback`, `rollforward`)
- **Next unread**: Skips read pages and stops at an unread page (it stops even when the skip target in Settings is "All"; it also stops at choices).
  It first runs ahead without showing anything to check, and if everything to the end has been read, it says so and doesn't skip. The quick menu button and the key exist only when you write them (`next-unread`, `ui.keys.nextUnread`)
- **Read choices**: Options whose target's first page has been read (following up to three `@jump`s at the start of the target) are shown slightly faded
  (if you set a color with `ui.choice.readColor`, they're shown in that color instead). The targets are worked out from the script, so the project doesn't need to write anything
- **Screenshot** (in the menu; the quick menu button and the key exist only when you write them: `screenshot`, `ui.keys.screenshot`): The desktop version captures the window
  as it is and puts it in a "<title>" folder in the Pictures folder. The browser version saves the game screen (without the message window and system screens) as a PNG. The mobile app passes the same PNG to
  the share sheet (Save to Photos, Save to Files and so on; exporting save data works the same way)
- **Going to the background**: When the browser tab goes to the background (switching to another tab, minimizing the window, going back to the home screen on a phone), the game autosaves
  (see "Autosave" below) and then pauses playing sounds, playing videos, text-to-speech, auto and the choice time limit, and resumes them when the player comes back
  (auto counts its wait again from the start). If the project doesn't want them paused, use `ui.screen.pauseInBackground: false`.
  In the desktop version, the player can choose on the "Sound" tab of Settings what happens "When minimized" and "When inactive" (while another window is selected):
  "Pause," "Mute" (only the sound is silenced, and the game goes on) or "Keep playing" (by default, "When minimized" follows the project's setting (pause), and "When inactive" keeps playing.
  The settings are `whenHidden` and `whenUnfocused`). With "Mute" or "Keep playing," rendering and timers aren't throttled even when minimized (Electron's backgroundThrottling; throttling would stop the text from appearing and auto from advancing)
- **Screen sleep**: The desktop version keeps the display from sleeping during auto and while a video plays (`@movie`, except looping videos) (Electron's powerSaveBlocker)
- **Replay voice**: Plays the current page's voice again (the V key. It appears in the menu only when the current page has a voice.
  In the quick menu only when you write it: `replay-voice`. It can't be pressed on pages without a voice. The key is `ui.keys.replayVoice`)
- **Copy text**: Ctrl+C (⌘+C on Mac) copies the current page's text (with the speaker) when no text is selected (when text is selected, the browser copies as usual).
  Text in the backlog can be selected and copied. To use another key, set `ui.keys.copyText`
- **Search the log**: The field at the top of the Log screen searches speakers and text (only matching pages are listed; Esc while typing only clears the text)
- **Previous choice**: Choose again from an earlier choice (while choosing, the choice before this one; asks first, and progress after it is lost).
  You can go back to the newest 50 choices shown in this playthrough. Save data holds the newest 10, so you can go back from there after loading too
  (if save data runs short of space, the choice records are trimmed first)
- These go in the quick menu only when you write them (`prev-choice`, `next-choice` in `ui.menuBar.items`). From plugins, use `system.perform("prev-choice")` and so on

Even when the project replaces the system screens, it can use the same touch, gamepad and arrow-key controls with `bindPlayerInput` (docs/plugins.md).

## Tools during development

- **Variable watch** (dev server only; F9 shows and hides it): Watch the game, temp and system variables while playing. Filter by name; items pinned with ☆ go to the top
  (saved in this browser). Click a value to rewrite it in JSON notation (it only goes into the variables of the current playthrough and isn't saved). It isn't included in exports
- **Performance monitor** (dev server only; F10 shows and hides it): At the top left, it shows the frame rate (over the last second), the number of long frames (over 50ms) and the longest one,
  the number of long tasks (in browsers with the Long Tasks API), JS memory (only in Chromium, which has `performance.memory`; elsewhere it says the value can't be read),
  the number of DOM elements, the number and size of loaded assets (images, sounds, videos, fonts, others), and the assets that took long to load.
  Frames are counted only while it's shown, and the reset button sets the frame count back to 0. Assets are counted from Resource Timing; the dev server checks assets again every time,
  so it may show more than an exported game. It isn't included in exports
- **Test play tools** (dev server only: "Test play" in Studio and `lim dev`): When you fix the script during play, "The script changed" and
  "Reload from here" appear on top of the game screen. Reloading keeps the current state (including the history, the record of choices and play time), reloads the scripts and continues from the current page (also with ⇧R.
  Games that replace the system screens do the same if they have `SystemController.reloadHere`; otherwise the current page's save is reloaded with `loadSave`).
  ⇧E and "Open this page in the script" in the menu at the top right open the current page's line in Studio. Runtime problems (missing screens, errors in expressions and so on) appear small at the top right as "N warnings,"
  and pressing it shows a list (pressing an item opens that line in Studio; they're also listed in Studio's Check as "Found in test play"). ⇧R and ⇧E aren't in the default key bindings,
  and even if the game assigns them, test play receives them first. The menu at the top right isn't shown with `?autostart=1`. It isn't included in exports
- **`lim profile`**: Takes the measurements above while opening the player in Chromium and advancing a set number of pages, and makes a report (below)

```bash
lim profile [project] [file[#label]] [--pages 30] [--wait 500] [--choose 0,1] [--out folder] [--json]
```

- If you leave out the starting point, it starts from `entry` in `liminalia.json`. After each page is fully shown, it waits `--wait` milliseconds, takes the numbers and advances
  (it also advances click waits in the middle of a line; the numbers for the same page are combined into one). At choices, it picks the numbers in `--choose` (0-based) in order, and the first option once they run out
- It writes `計測.md` (summary, slow assets, and the frame rate, memory, DOM elements and asset counts per page) and
  `計測.json` to `exports/profile` (change it with `--out`; the file names are Japanese for "measurement") and prints the summary. `--json` only prints JSON
- Chromium is the same one `lim shot` uses (`LIMINALIA_CHROMIUM` or Playwright's chrome-headless-shell)
- "Measure performance" on Studio's "Check" screen takes the same measurements (the code is shared in `server/profile.ts` of `@liminalia/studio`; [studio.md](studio.md)).
  In Studio, it picks the first option at choices and waits 500 milliseconds. The desktop app measures with its own Electron, so it doesn't need Chromium

## Screens

The game screen is drawn at the size of `screen` in `liminalia.json` (1280×720 by default; it's scaled down or up to fit the player's window). Coordinates of backgrounds, sprites, `@image` and so on are in `screen` coordinates.

- **Text and window size**: The px values of the message window, choices, system screens and `ui` are set for a base size (1280×720 for landscape, 720×1280 for portrait). If `screen` differs from the base, they're scaled by the same ratio (1920×1080 is 1.5 times and looks the same as 1280×720. 1024×768 is 0.8 times, and the extra height leaves more room for the layout on screen)
- **Portrait games** (a `screen` taller than it is wide): The game screen gets the class `lm-portrait`, and the default layout changes (`packages/web/src/system/portrait.css`). Values you write in `ui` are applied as they are
  - Message window: 24px margins on the left and right, 64px at the bottom (for the quick menu), at least 250px tall. Text 28px, names 24px. The margins of sound novel mode (NVL) are narrower too
  - Choices: 600px wide, 26px text. Even if `ui.choice.width` is wider than the game screen, they fit inside the game screen and the text wraps
  - Title: The title and buttons are larger, and the buttons are 400px wide. Even with a horizontal layout, they wrap if they don't fit
  - Save, Load: 8 slots in one column. The image is cropped to the slot's height. Thumbnails are made in the game screen's aspect ratio (256px on the long side)
  - Settings: Item names go above the controls. Log: The speaker goes above the text. Menu: Stays in 2 columns, with a height that's easy to tap. Extras: Images in 3 columns, in the game screen's aspect ratio
  - Standing positions: If `frame` in `cast.json` has the standing positions, sprites are placed as written. If not, the centers of left / center / right are placed at 30%, 50% and 70% of the width, at the bottom of the screen (`auto` divides the width equally by the number of characters, as before). The tool for adding standing positions uses the same ratios for the initial position and size, with sprites up to about 70% of the screen height
  - Camera: `@camera` moves are kept within the range where the edges of the background don't show (portrait is narrower, so moving the same amount as in landscape would show the edges. When `@bg-place` places a background larger than the screen, this limit doesn't apply). Shake amounts for `@quake` and so on are as written
  - Transition effects (`method` of `@bg`, rules) adapt to the size of the game screen, so you write them the same way
- **Background focus** (`ui.backgroundFocus`): The position kept when a background is cropped. Background file name → `object-position` value, where `"*"` means everything else (`{ "*": "62% 50%", "hill_night.webp": "30% 50%" }`). Without it, the center is kept. It applies only when cropping happens (backgrounds whose aspect ratio differs from the game screen's, or when placed in a frame with a different aspect ratio). It also applies to the title background (`ui.title.background`) and thumbnails, but thumbnails of 1280×720 games aren't cropped, so they don't change
- **Portrait template**: `lim new --size 720x1280` (also "720×1280 (portrait, for phones)" in New Project in the desktop app) makes the sample sprites about 70% of the screen height, aligned to the bottom, and writes a focus for the sample background

- **Save, Load**: Save slots with a thumbnail and the beginning of the text. They also show the chapter name and play time (not in save data made by earlier versions).
  The chapter name is decided in this order: the project plugin's `slotChapter` → `ui.chapterNames` (`"file#label"` or `"file"` → name; looked up by the current label first, then the file) → the number and title in `chapters` in `liminalia.json` →
  the title of the last extras chapter (`extra.chapters`) reached in this playthrough → the file name. Play time counts from "New Game" or
  from the play time of the loaded save (only during the game; not on the title, in replays or while in the background).
  Quick saves are listed on the "Q" tab of the Load screen, newest first. Used slots have "Memo" (adds a one-line memo),
  "Lock" (the slot can't be overwritten, deleted or used as a move destination), "Copy" and "Move" (click, then choose the destination slot, on other pages too; only Move carries the lock along) and "Delete"
- **Autosave**: Listed on the first tab of the Load screen ("A"), newest first (not shown on the Save screen; the only button is "Delete"). There are `ui.autosave.slots` slots (3 by default), and
  once they're full, the oldest is replaced. An autosave that would resume from the same place as the newest one overwrites that slot (so going to the background many times on the same page doesn't use up the slots).
  It saves at `@autosave` (resuming from the command after it), and when quitting or going to the background (switching tabs, going back to the home screen on a phone, closing the window in the desktop version.
  At a click wait or a choice, it saves that point; in the middle of an effect, it resumes from the start of the last page or choice shown. It doesn't save on the title, in replays or in Studio's preview), and
  at the times set in `ui.autosave.on` (when choices are shown (on by default; turn it off with `choice: false`), at the start of a chapter (`chapter: true`; the first page where the chapter in `chapters` changes, and
  the start of an extras chapter), and every set number of pages read (`pages`). These resume from the start of the page, and the text in the list is that page's. It doesn't save at a choice returned to by rollback,
  or in a playthrough started partway for development).
  The Android app keeps save data in the app's files and, when going to the background, waits until the autosave is saved (the mobile version section of the README).
  The iOS app also asks to keep running in the background when going to the background, until the autosave is in the app's files (up to 2 seconds; see "Where saves are kept" below).
  When the screen's process in a mobile app dies (for example, when it's stopped to free memory while in the background), the game doesn't stay on a black screen; it reloads
  and continues from the autosave made when going to the background (after "Tap to start." If it had already come back from the background, it starts as usual. If it dies 3 times in a minute, it doesn't reload).
  If the project replaces the system screens, handle it with `system.resumeLeft()`
  `@autoload` continues from the newest autosave. Turn off autosaving when quitting and going to the background with `ui.autosave.leave: false`
  (when the project replaces the Load screen, it's off unless you write it. A project's Load screen can list autosaves with `system.autoSlots()`)
- **Log (backlog)**: The speaker (in the character's name color) and the text, including ruby (small reading aids above characters), styling and line breaks. Each character's text look and the font the player chose also apply. Pages with voice can be replayed with the play button.
  Chosen options are kept too ("Choice" in the speaker column, and the chosen text in the accent color; also when `default` is chosen because time ran out. Options with `call=true`,
  image buttons without text and clickable areas aren't kept). To not keep them, use `ui.backlogChoices: false`
  For the newest 100 pages, "Go back" returns to that page (asks first; progress after it is lost. After loading, up to the newest 20 pages kept in the save)
- **Settings (config)**: The "Text" tab has "Text speed," "Auto delay," "Skip" (Read only / All), "Skip speed" (Fast / Fastest. Fast moves on at a speed where each page can be seen; Fastest by default), auto and skip after choices
  (Stop / Keep going; Stop by default. A skip started with "Next choice" or "Next unread" doesn't keep going), "Choice time limits" (when off,
  `@choice timeout=` doesn't time out either and no remaining-time bar appears, for people who can't read when rushed; on by default), "Language" (when the game has several languages) and
  a preview of the text speed. The "Display" tab has "Text box opacity" (the opacity of the message window's background color and image; the text isn't faded), "Text size" (80–200%. Applies to the text, choices, name box, backlog and system screens. Above 100%, system screens are laid out more tightly, Save and Load become one column that scrolls inside, and Settings scrolls as a whole. Title buttons go up to 1.5 times. If the project sets `ui.screen.textScale: "message"`, only the text and choices),
  "Font" (Default / Serif / Sans / Rounded / UD. UD is a font designed for readability; if it isn't available, Sans), "Screen shake" (Full / Reduced. When Reduced, @quake (including its decaying shake) and @chara-shake don't shake),
  "Flashing lights" (Full / Reduced. When Reduced, @flash puts a faint veil over the screen once instead of flashing. Screen shake and Flashing lights are set separately and are kept when resetting to defaults), "Read text color" (Off / On. If not set, it follows the game's `ui.text.readColor`;
  On adds a default color even if the game doesn't set one), "Line spacing" (Normal / Wide / Wider; 1.25 and 1.5 times the game's line height), "Text outline" (Default / None / Shadow / Outline; Default keeps the game's shadow and outline) and, where fullscreen can be switched, "Display" (Window / Fullscreen; in the desktop version, kept for the next launch).
  The "Sound" tab has "Master volume" (applied to all BGM, sound effects, voice and video) and "Mute" (also toggled with the M key and R3 on a gamepad, with a notice), "Music volume," "Sound volume," "Voice volume," a voice volume for each speaker heard so far (characters whose voice hasn't been heard yet
  aren't shown. If the game sets `ui.settings.voiceSpeakers` to `all`, the speakers in cast.json are listed from the start; with `masked`, they're listed but the names of characters not heard yet are hidden as "???"), whether to stop the voice when advancing ("On advance"), and whether to lower the BGM while a voice plays ("BGM during voice"; lowered by default).
  The "Display" tab also has "Read aloud" (once a page is fully shown, the device's voice reads the speaker and text. Characters with ruby are read by their ruby (ruby made only of "・", which marks emphasis dots, reads the base characters),
  and lines with voice aren't read. Auto advances after reading. It also reads choices and screen buttons selected with keys or a gamepad), "High contrast" (makes the message window opaque black and the text white, and gives choices and system screens sharp edges. If the OS is set to increase contrast,
  it starts on), "Window size" in the desktop version ("Default," plus the sizes from 0.5 to 2 times the game size that fit on the current display), "Confirmation messages"
  (when off, skips the confirmations for returning to the title, quitting, loading, overwriting and jumping. Deleting saves, importing, carrying over and sending reports are still confirmed),
  "Hide the idle mouse cursor" (during the game, hides it after 3 seconds without movement), "Color vision" (Protan, Deutan, Tritan. A color matrix that shifts color differences that are hard to tell apart
  to ones that are easier, applied to the whole game screen, including the text and screen buttons) and "Sound captions" (`ui.captions` and `@se caption=`).
  The "Controls" tab changes key bindings (click "Change" for an action, then press a key. These are layered on top of the project's `ui.keys` and the defaults) and swaps gamepad
  buttons (click "Change" for a role, then press a button. The role that button had moves to the button that had this role before). The text is built from one element per character, so screen readers are given the continuous text of the page, once it's fully shown, in a hidden place (aria-live)
  (dialogue is passed as written, such as ソウ「おはよう」; dialogue without brackets becomes "ソウ：…", or "Sou: …" in English. The text of `@describe` and of `alt=` on images comes before the text;
  chapter 7 of [format.md](design/format.md)). Chapter cards and chapter ends (`@chapter-card`, `@chapter-end`) pass their number and title to screen readers and text-to-speech when they appear (not while skipping). System screens open as dialogs (`role="dialog"`, `aria-modal`, named by their heading), focus moves into the screen,
  and Tab cycles only within the screen. When the screen closes, focus goes back to where it was before it opened.
  Project CSS can match its own parts with `--window-opacity`, `--text-scale` (text and choices), `--lm-text-scale` (name box, backlog, system screens), `--player-font`, and the game screen classes `lm-high-contrast`, `lm-text-large` (text size above 100%) and `lm-touch` (a touch device or a portrait game; it also has `--lm-touch`, the factor that makes text larger, and `--lm-touch-target`, the smallest size of something to tap).
  At the bottom are "Export saves" and "Import saves" (saves, read history, settings and system variables in one .json file. For backups and for moving to another
  computer or browser. Files from another game aren't imported)
- **Extras**: CG ("Gallery"; only the unlocked variants, advanced by clicking), replays ("Scenes"; a replay plays and returns to Extras when it ends. You can't save during a replay),
  "Music," "Achievements" (achievements that count show "current / goal") and "Endings" (`extra.endings: true`; the same list as the "Endings" tab of the flowchart.
  Only endings reached show their name and the scene title, and if there's a record of reaching one, pressing it reads again from there). Under the heading is the completion ("Completion": the completion rate, and the counts of read text, CGs, replays, endings and achievements).
  If there are two or more `group`s (without them, chapter numbers or titles from `chapter`), CGs are split into tabs, with the number and share of unlocked ones in each group ("4 / 5 (80%)").
  The large view opens as a screen of its own (the tabs and the list behind it can't be pressed), with the title and `description` below. Click, Enter, Space and A on a gamepad show the next variant
  (closing after the last one), ← → and left and right on the D-pad the previous and next CG, ↑ ↓ and up and down on the D-pad the previous and next variant, and the wheel goes back and forward (through the variants, then on to the next CG).
  The wheel while holding Ctrl (a pinch on a trackpad), a finger pinch, + and -, and RT and LT on a gamepad zoom in (up to 4 times; 0 and X on a gamepad reset it),
  and while zoomed in, dragging, the wheel and the right stick move the image. Swiping sideways with a finger shows the previous or next CG. Esc, right-click and B on a gamepad close it
  The lists are in `extra` of `liminalia.json` (extras in chapter 10 of [format.md](design/format.md)). Plugins can also read the completion with `system.completion()`
- **Music room** (`extra.music`: an array of `{ file, title?, artist?, description? }`. Only tracks played at least once with `@bgm` can be chosen): The player area at the bottom has the current track,
  artist, description, a seek bar, play and pause, previous and next track, repeat ("Repeat all," "Repeat one," "No repeat") and "Shuffle." "Repeat all" and "No repeat" play each
  track without repeating it and move on to the next track the player has heard when one ends ("No repeat" stops after the last track). "Repeat one" repeats at the loop points embedded in the track
- **Glossary** (`extra.glossary`: an array of `{ id, term, reading?, aliases?, description, group?, link? }`): When a `term` or one of its `aliases` appears in the text,
  it's unlocked with a notice, and the word gets a dotted underline in the text (clicking it shows the description without advancing the text. `link: false` only unlocks it, without the underline.
  There's no underline where characters and their positions don't line up, such as grouped digits in vertical writing). `@glossary-unlock id` also unlocks a term. Terms are listed in "Glossary" in Extras, sorted by reading
- **Codex** (`data/codex.json`; "Codex" in chapter 10 of [format.md](design/format.md)): Listed in the menu and in Extras. Category tabs, a list of entries (marked "New" until read), an image and text in paragraphs, and related entries.
  During play, it shows what this playthrough has unlocked; in Extras, the record shared across all saves. When a new entry is unlocked, a notice appears at the edge of the screen
- **Investigation** (`@investigate`, `data/investigation.json`): A screen where the player clicks spots on the background to investigate them. Viewpoint tabs, marks on investigated spots, a description on mouse over, and "Finish" (`finish: "button"`)
- **Chapter select** (`extra.chapters`: an array of `{ id, title, target, synopsis?, thumb? }`): A chapter is unlocked the first time the first page of its `target` is reached,
  and that point is recorded. From "Chapters" in Extras, the player can see the title, synopsis and image, and read again from that chapter (asks first)
- **Flowchart** (available when `extra.flowchart` is `true` or `{ "titles": { "file#label": "title" } }`; opened from the title and the menu):
  It builds the connections between scenes from the script (the project doesn't need to write anything). Scenes are split at the start, at choice targets and where routes merge; linear stretches and
  jump targets of custom commands (such as investigation spots) are merged into the scene they came from. Only read scenes show a title (the first text, or `titles`); unread scenes are hidden.
  The first time a scene is reached, that point is recorded (shared across all saves), and the player can read again from there (asks first). At the top are the read rate (the share of text pages read) and
  the number of endings, and the "Endings" tab lists the endings (the wording of the kind in ending= of @title-screen and the name in title=, or "Ending n").
  In multilingual projects, scene titles (the first text and the speaker name) and choice text are shown with the translations in the translation files (the text lines and choices in `lang/<language>.json`)
  (`titles` are translated as text of the project settings. `flow.json` in exports from earlier versions, which has nothing to look up translations from, stays in the original language)

Read history, settings and system variables (including the records of unlocked extras) are saved once, shared across all saves.

**Where saves are kept**: The browser version uses IndexedDB (the `saves` store of the `liminalia` database, with keys `liminalia:<game id>:<name>`),
the mobile apps use the app's files (one file per key: `saves/` in the app's files on Android, and `liminalia-saves/` in Application Support on iOS,
because WKWebView's IndexedDB can be cleared when the device runs low on space and so on), and the desktop version uses files in the save location.
What earlier versions of the Android app put in SharedPreferences and of the iOS app put in IndexedDB is moved once, at the first launch (the originals aren't deleted).
Saves in the phone apps are included in the device's backup and carry over to a new device (iCloud backup on iOS; on Android, backup to the Google account and
device-to-device transfer. On Android, only `saves/`, where saves are kept, is included so it stays under the 25 MB limit). There's no cloud save for using two devices at the same time (Steam has Auto-Cloud; see "Steam" below).
When the app can't write (not enough space and so on), it shows "Could not save". Saves, read history, settings and variables shared across all saves (including unlocked extras and the records of the flowchart and chapters)
all go in the same place. localStorage (about 5MB, which a few dozen save slots with thumbnails fill up) isn't used.
- At startup, it loads everything for the game (and for the games in `saves.carryFrom`), then answers from a copy in memory, and writes what's saved to IndexedDB in the background
- Data that earlier versions put in localStorage is moved to IndexedDB when found at startup, and removed from localStorage
- If the page closes before writing finishes (what was saved while in the background, and writes not finished when closing), it's also put in `liminalia-journal` in localStorage,
  and applied at the next startup. If the same game is open in other tabs, they tell each other what was saved
- On the first save, it asks the browser not to delete the data (`navigator.storage.persist()`; Firefox asks the player). Safari may delete the data of pages not added to the home screen
  after 7 days without use (if the request isn't granted). Keep important save data with "Export saves" in Settings
- Where IndexedDB isn't available (such as browsers that block site data), it uses localStorage as before
- If writing to IndexedDB fails (not enough space and so on), it shows "Could not save". The desktop version shows the same when it can't write a file
  (on Windows, antivirus or sync software holding the file, not enough space, a location that can't be written to and so on). When the file is held (EPERM, EBUSY),
  it waits a little and tries again before giving up, and leaves the reason in `logs/` in the save location. Before closing and before restarting, it waits for writes to finish
- Tools for screenshots and automated checks can see the contents with `window.__liminalia.saves` (`entries`, `set`, `remove`, `clear`) and `flushSaves()`
Read status is recorded with a key for the file and page (made from the page's speaker and text, plus the speaker and text of the page before it). Even if editing the script shifts lines
or labels are renamed, read status stays put, and newly added pages stay unread (read-only skip doesn't skip them). The page right after an added or rewritten page
also becomes unread again, because the page before it changed. Read status that earlier versions recorded by line position is moved to keys using the current script's lines when that file is loaded
(lines that had already shifted because the game was updated before the move can't be recovered).
If `saves.protect` in liminalia.json is true, everything is saved in an unreadable form, and anything rewritten is treated as missing.
If there's an `afterLoad` (`file#label`), right after loading, the game calls it and then returns (with `@return`) to the loaded page
(for recalculating `temp.` values, which aren't in saves, and so on). Save data includes the version of the game that made it (`version` in `liminalia.json`), which expressions read as
`save.version` (for a loaded playthrough, the version of that save data; for a new playthrough, the current version; empty for save data from before versions were included).
When an update changes the names or meanings of variables, convert save data from earlier versions in `afterLoad` ("Save versions" in [format.md](design/format.md)).
Save data keeps a marker for the page (the line, and a key made from the text or choice text) along with the page position. Even if updating the game shifts script lines,
loading finds the page with the same text and resumes there (if not found, the page nearest the original line; both are reported with the diagnostic `save-relocated`).
Saves made inside `@call` or a macro adjust their return points the same way (returning to the command after the call; "Save versions" in [format.md](design/format.md)).

## Sound

- **Loops with intros**: Reads the `LOOPSTART` and `LOOPLENGTH` (or `LOOPEND`; both in samples) embedded in OGG (Vorbis, Opus) tracks
  and repeats the section after the intro (a format widely used for game music). If you write `loop-start` and `loop-end` on `@bgm`, those take priority.
  When the mobile version compresses audio (`build.mobile.audio`), AAC (.m4a) loses the tags, and Opus changes the sample rate to 48000 so the counts no longer match,
  so the export puts the positions (in seconds) read from the original track in `project/audio-loops.json`, and the player uses them before the embedded tags
  (tracks converted to Opus also get tags converted to counts at 48000). Studio's BGM loop markers are written to `loop-start` and `loop-end` (in milliseconds) of `@bgm`, so they don't depend on the format
- **Cross-fade**: `@bgm theme crossfade=2s` loads the new track first, then fades the current track out while fading the new one in (the current track keeps playing while loading)
- **Streaming long BGM**: BGM larger than 1MB isn't decoded all at once; it plays with `<audio>`, loading a little at a time, and goes through Web Audio for volume, panning,
  fades, cross-fades and lowering during voice (a 4-minute track takes about 90MB when decoded). Loop points (`loop-start` and `loop-end` of `@bgm`,
  `project/audio-loops.json`, and embedded tags, read from the first 256KB), pause and resume, save and load, and the music room's seek bar all work the same way.
  For the loop section, it checks the end position every 10ms and jumps back to the start of the section, so the seam isn't as precise as with decoded playback (off by about 10ms).
  The host of the browser version, the desktop version (encrypted or not) and the Android app respond to range requests (Range). When the host doesn't respond, and
  when playback fails (because of autoplay restrictions and so on), it decodes and plays as before. `ui.sound.streamBgm: false` turns this off (for games that need precise seams)
- **Cache of decoded sounds**: Each kind has its own limit, and when it's exceeded, the sounds unused for the longest are discarded (BGM 48MB, sound effects 32MB, voice 24MB; previously 192MB in total).
  Sounds played as text appears (`@text-sound`) are limited to 16
- **Panning and playback speed**: `pan` (-100 is left, 100 is right) and `rate` (1 is normal speed; the pitch changes too) of `@bgm` and `@se`. They're kept through save and load, and after pausing
- **Pause**: The position where `@pause-bgm` stopped is kept in saves (`bgm.pausedAt` in the state), and `@resume-bgm` after loading continues from there
  (saves from earlier versions and `@resume-se` play from the start)
- **System voice** (`ui.systemVoice`): Lists candidate sounds from the `voice` folder for `title` (when the title screen appears; a title call), `actions` (when the player does something: the title's
  `start`, `load`, `extra`, `flowchart`, `config`, `exit`, and menu actions such as `save`, `load`, `auto`, `skip` and `backlog`) and `confirm` (confirmation dialogs).
  A candidate is a file or `{ "file": …, "if": "system.cleared", "character": "A" }`, and one is picked from those whose `if` is true
  (such as a title call only after the game is cleared). If you write `character`, "System voice" ("Random," each character, "Off") appears on the "Sound" tab of Settings.
  `volume` (0–100) is the overall volume. System voices follow the voice volume and don't stop voices in the script
- **System sound effects** (`ui.sound.ui`): Write sounds from the `sound` folder for `hover` (when the mouse moves over a button, and when one is selected with keys or a gamepad), `select` (when one is pressed),
  `cancel` (when going back with a close button, "No" in a confirmation, Esc, right-click or B on a gamepad), `open` and `close` (when a screen opens or closes; not right after a press sound),
  `page` (when switching tabs) and `choice` (when choosing an option). They play at the sound effect volume.
  They play both on the default system screens and on plugin parts (`ui.button`, `ui.toggle`, `ui.choice`; `sound` changes the kind, and `false` silences them),
  and project screens can play them with `ui.playSound("open")`
- **Volume preview** (`ui.settings.samples`): When the player finishes moving the BGM, sound effect or voice volume in Settings, the sound written in `bgm`, `se` or `voice` plays once at that volume
  (the master volume uses the sound effect's). The BGM preview plays only when no BGM is playing (on the title and so on), and stops when Settings closes

## Loading and performance

- **Preloading**: Each time a page is shown, it loads the backgrounds, sprites, images, sounds and numbered voices used in the next 40 commands (both sides of branches).
  If an `@jump`, `@call` or choice target in that range is in another file, it loads that file and also the assets of the first 24 commands at the target
  (for a label in the same file but outside the range, it loads its assets). Up to 4 new jump targets are loaded per page. Targets given as expressions (`@jump (game.next)`) aren't loaded.
  Errors in preloaded files are reported when the game actually jumps to that file (errors beyond branches that aren't taken don't appear)
- **High-resolution displays**: The game screen is built in px of game coordinates and scaled up to fit the display. The top-left of the scaled game screen is aligned to the display's pixels
  (placing it at fractional positions blurs text and images. It's aligned again when the window moves to a display with a different pixel density). What's drawn on canvases
  (`@particles`, WebGL effects of `@effect`, swaying sprites) is drawn at the display's resolution, multiplied by the scale and devicePixelRatio (particles and
  WebGL effects up to 2x, swaying sprites up to 3x and 2048px). The shader's `u_resolution` stays in game screen px.
  Nothing gets sharper than the asset images themselves, so for games played on large displays, prepare backgrounds and sprites as images larger than the screen
- **Offline**: The exported browser version can be played offline once it has been opened (it caches with a Service Worker; `build.browser.offline`; [distribution.md](distribution.md))
- **Startup**: The small files read at startup (the asset list, the export version, the pack list and the characters) are fetched all at once. While they load,
  after 0.5 seconds a thin-line loading indicator appears in the center of the screen (`#lm-boot` in `index.html`; removed when the game screen appears)
- **Waiting for assets**: When showing a background, sprite and so on has to wait more than 0.5 seconds for loading, a small waiting mark (`.lm-busy`) appears at the bottom right of the game screen,
  and disappears when loading finishes (not for preloading). Change its look by writing `.lm-busy` in the project's CSS
- **New version**: When a new export is put up while someone is playing the exported browser version, "A new version is available" and "Reload" appear at the top
  (offline in [distribution.md](distribution.md))
- **Lower resolution for phones**: In the asset compression settings (`build.mobile`, `build.browser.compress`, `build.desktop.compress`), set `images.scale` to a factor greater than 0 and less than 1
  to export backgrounds and sprites (`images.scaleFolders`; `bgimage` and `fgimage` by default) with their width and height scaled by that factor
  (WebP assets are re-encoded too; cwebp is needed). The game shows them at their original size, so sprite layout, `@image` sizes and crops, the face window
  and save thumbnails don't change (the export writes the original sizes to `project/assets-scale.json`, and `<img>` gets a srcset width and sizes).
  UI images (`image`) aren't scaled by default, because the size of their frame corners (`imageSlice`) is written in pixels. Pictures shown with CSS `url()` are stretched to fit, so they stay as they are

```json
"build": { "mobile": { "images": { "quality": 80, "scale": 0.5 } } }
```

## Language

If the game is multilingual (`languages` in `liminalia.json`), the player can choose the language in Settings. If none is chosen, the game starts in the language that matches the browser (device),
or in the original language if none matches. Writing `?lang=en` in the URL starts that session in that language, if it's in `languages` (the language remembered in Settings isn't changed; for example, when opening from per-language pages of a website). The system screens have built-in Japanese and English text, and other languages override it with `ui` in the translation file
([format.md](design/format.md) chapter 10, multilingual). Changing the language also changes the page's `<html lang>` (so that screen readers read it correctly).

## Game settings (ui in liminalia.json)

Every item can be left out, and leaving it out gives the default look and controls described above. The shape is `UiConfig` in `@liminalia/lang` (checked by `lim check` and Studio's check).
Lengths are in px of the game screen, and colors are CSS colors. Paths are from the `image` folder for images, `bgimage` for backgrounds, `bgm` for BGM and `others` for font files.

| Key | What it holds |
|---|---|
| `fonts` | Fonts to load (`[{ "family": …, "file": …, "weight": … }]`; paths from `others`). Each item's `font` uses them by name |
| `text` | The text's font (`font`. If you don't set it, a Japanese Mincho font is used when the game is played in Japanese, Chinese or Korean, and in other languages a Latin serif font (such as Iowan Old Style, Palatino or Georgia) comes first, with Japanese characters shown in the Mincho font after it. Earlier versions used the Japanese Mincho font in every language, so to get the same result, set it to something like `"\"Hiragino Mincho ProN\", \"Yu Mincho\", serif"`. To match the text on the system screens too, set `--font-fallback` on `:root` in your project's CSS), font file (`fontFile`), size, color, line height, decoration (`decoration`: none / shadow / edge, and `decorationColor`), color of read pages (`readColor`), alignment (`align`: left / center / right; even when centered, lines don't move while the text appears), and values for Japanese typesetting (the ruby size `rubySize` (a multiple of the base characters; 0.45 by default), the gap between ruby and the base characters `rubyGap` (a multiple of the base characters; 0 by default, which attaches the ruby at the top of one base character's height; negative values bring it closer; in vertical writing, the gap to the right), characters per line `lineChars` (per column in vertical writing. Each character counts as 1em, so for vertical writing the font must have vertical advance widths; `lim check` reports font files that don't), the strength of the line-breaking rules (kinsoku, which keep certain characters from starting or ending a line) `lineBreak` (strict / normal / loose / anywhere / auto. If it isn't written, it's strict when the language being played is Japanese or Chinese, so small ッ and ゃ and ー don't start a line; other languages use auto, which leaves it to the browser. Earlier versions used auto regardless of the language, so write auto to break lines as before. The same value applies to the name box, choices, the backlog, the system screens and the screens of the standard commands such as the codex and chat, not just the text), hanging punctuation at line ends `hangingPunctuation` (Safari and iOS only), and the gap between paragraphs in NVL `paragraphGap` (a multiple of the text size; 0.5 by default, and 0 moves down by exactly one line)). Text shadow `shadow`, outline `stroke`, letter spacing `letterSpacing`, weight `weight`, and space above the text `topGap`. The outer brackets and quotation marks of dialogue `quotes` (`keep` shows them as written and is the default. `strip` removes the outer pair of `「…」` `『…』` `“…”` `"…"` around the dialogue text, and works the same in the message window, NVL, the backlog, balloons and the chat screen. `（…）` stays. It can be set per language. How they're removed is in chapter 4 of [format.md](design/format.md)). How each character appears `reveal` (`fade` fades it in and is the default, `none` shows characters one by one without fading, `rise` floats them up slightly) and the time for each character to appear `revealTime` (milliseconds; 120 by default). From the project's CSS, use `--lm-reveal-animation`, `--lm-reveal-time` and `--lm-reveal-easing` (one character of text in [plugins.md](plugins.md)) |
| `message` | The message window's position and size (`x` `y` `width` `height`; writing any one of them places it by its top-left corner and size), inner padding, background color, image, border color, corner radius, `scroll` (instead of starting a new page, text that doesn't fit scrolls inside the message window, following the text down; the wheel over the text is used for reading back), and `vertical` (vertical writing; the script can also switch it with `@vertical`). `padding` is a number or a CSS value. `imageSlice` (slicing so the corners don't stretch). `backdrop` and `backdropHeight` (a CSS background laid under the window). `none` for `borderColor` removes the line. With `keepText` set to `true`, the first command after a click turns the page doesn't clear the previous page's name and text, which stay until the next text (the behavior before 0.4.1; for one line, `keep-text=true` on `@bg`) |
| `name` | The name box's position (from the top-left of the message window), size, color, background, image and border color. `imageSlice`, font `font`, weight `weight`, letter spacing `letterSpacing`, shadow `shadow`, padding `padding`, line height `lineHeight`, and a vertical rule on the left `rule`. `none` for `borderColor` removes the line |
| `face` | The face window. Shows the speaking character's face inside the message window and shifts the text over by that much. `show` (always: always. offstage: only when that character's sprite isn't shown. explicit: regardless of the speaker, only what `@face` shows, hidden with `@face-off`), `x` `y` (from the top-left of the message window; when written, the text isn't shifted), `side` (left / right), and `width` `height` (180 by default). The face image is the character's `face` (cast.json in chapter 10 of docs/design/format.md). Not shown during vertical writing, NVL or speech balloons |
| `chara` | How sprites are shown. Speaker focus `focus` (tones down the sprites of characters who aren't speaking: `none` (the default), `dim`, `lower`, `dim-lower`, `blur`, `dim-blur`) with its strengths `dim` (brightness 0–1; 0.6 by default) and `lower` (how far down in px; 12 by default), and `jump`, which makes a character who starts speaking hop. With `keepText` set to `true`, the previous speaker's name and text stay while `wait=true` on `@chara` waits for a new character to appear (they're cleared by default; whether the first command after a page turn clears them is set by `message.keepText`). `@chara-config` in the script takes priority ("Reducing flicker" in chapter 6 of [format.md](design/format.md)) |
| `help` | The "Controls" screen ("Controls" in the menu and `@open-screen help`). The table of controls is built from the current bindings (the player's bindings, `keys`, the defaults and gamepad swaps). `pages` adds tabs with `[{ "title": …, "image": …, "text": … }]` (such as an explanation of how to play), and with `title: true`, the screen is also shown on the title screen |
| `captions` | Captions for sound effects and BGM (shown briefly at the top right of the screen to players who turn on "Sound captions" in Settings). `sounds` maps sound effect files → captions (`caption=` of `@se` takes priority), and with `music: true`, the title from the extras music list is shown when the BGM changes |
| `tones` | Names of sprite color tones (`@tone`) → `{ color, amount, saturation, brightness, contrast }`. Multiplies by `color` at a strength of `amount` (0–1); saturation, brightness and contrast stay unchanged at 1. Names that match a built-in one (sepia, mono, night, evening, dark, plain) replace it. `lim check` reports names written in the script that don't exist |
| `backgroundTones` | Background color tones. Background file names (paths from `bgimage`) → tone names (from `tones` or built-in), written like `{ "room_night.webp": "night" }`. While that background is shown, the tone is applied to sprites without `@tone`, so sprites don't stand out bright against a dark room or an evening background. When `@bg` changes the background, the sprites' tone changes over the same time as the background, and changing to a background without a tone removes it. `tone=` on `@bg` comes first (`tone=none` applies none). For sprites given a tone with `@tone`, that tone comes first; `@tone none` goes back to the background's tone, and `@tone plain` applies no background tone either. `lim check` reports background and tone names that don't exist |
| `glyph` | The click-wait icon's character or image, color, animation (bounce / blink / none), size `size` (a multiple of the text; 0.7 by default), and gap from the text `gap` (a multiple of the icon size; 0.3 by default; above and below in vertical writing). Shape `shape` (diamond, triangle, dot, bar). `breathe` as an animation |
| `choice` | Choice buttons' width, text size, spacing, color, background, background on mouse over, border color, image, image on mouse over, height `height`, the top of the first button `y`, and an image laid under the text while choices are shown `backdrop`. `imageSlice`, font `font`, weight `weight`, letter spacing `letterSpacing`, line height `lineHeight`, alignment `align`, `padding`, `margin`, minimum height `minHeight`, a fixed width with wrapping `fixedWidth`, corner radius `radius`, background blur `blur` (px or a backdrop-filter), shadow `shadow`, `hoverColor`, `hoverBorderColor` and `hoverShadow` on mouse over, ornament `ornament` (brackets, underline) and `ornamentColor`, and hiding the message window during choices `hideMessage`. `background` and `hoverBackground` can be gradients too. Placement `position` (see below) |
| `chat` | Colors and shapes of the chat screen (`@chat-open`, `@chat`; see "Chat screen" below). If `dialogue` is `true`, regular dialogue becomes bubbles too. Without it, `@chat` keeps its default look |
| `system` | The look of the system screens (the menu, Save, Load, Settings, Log, confirmations and the title buttons). Color scheme `theme` (dark / light), accent color `accent`, font `font`, text color `fg`, screen background color `screenBg`, button background color `controlBg`, line color `border`, corner radius `radius` (px; 4 by default), and title screen background `titleBg` (a color or gradient; the image of `title.background` goes on top). Faint text, thin lines and mouse-over backgrounds are made from the chosen colors. `images` holds images: `screen` (the background of full-screen screens; from `bgimage`), and `button`, `buttonHover` (button backgrounds; `button` if there's no mouse-over image) and `frame` (the background of the menu and confirmation frames), from `image`. Button and frame images are stretched to fit, and then the background color and lines are removed. `preset` is the name of the theme chosen in Studio (see "Themes" below) and doesn't affect the look. For players who choose "High contrast" in Settings, high contrast takes priority over these colors and images. Title button background `titleButtonBg` and title text shadow `titleShadow`. In `images`, `buttonSlice` and `frameSlice` (slicing so the corners don't stretch), and `sliderThumb` (the image of the slider knob). The lines and buttons of the dialog and text input (`@dialog`, `@text-input`), notifications (`@notify`) and short messages ("Saved" and so on) also follow `border`, `controlBg`, `fg`, `screenBg` and `accent` (dark colors if not set) |
| `ending` | The look of the ending-name screen (shown when play ends with `@title-screen ending=`). Backdrop `background` (a color or gradient), a picture laid on it `image` (from `bgimage`), font `font`, name color `color`, size `size` (px; 48 by default), letter spacing `letterSpacing`, kind label color `kindColor`, color of the rule between the name and the closing mark `rule` (`none` draws no rule), closing mark color `markColor`, size `markSize` (px; 26 by default) and placement `mark` (`below`: under the name, the default; `above`: above the name; `none`: not shown, and no rule either). Anything not set uses `titleBg`, `fg` and `accent` of `system` and the text font (see the example in [screens.md](screens.md)) |
| `nvl` `nvlStyles` | The NVL (`@nvl on`) look, and named looks chosen with `@nvl on style=` (name → look). Background `background`, picture `image` (from `image`), padding `padding`, alignment `align`, where paragraphs pile up `valign`, font `font`, color `color`, size `size`, line height `lineHeight`, paragraph fade `fade` (milliseconds) and whether to show names `names` (chapter 4 of [format.md](design/format.md)) |
| `chapter` | The look of chapter cards and chapter ends (`@chapter-card`, `@chapter-end`). Backdrop `background` (a color or gradient), a picture laid on it `image` (from `bgimage`; the command's `image=` comes first), font `font`, text color `color`, title size `size` (px; 52 by default. The title of a chapter end is 8/13 of it, and the card title in a portrait game 10/13), title letter spacing `letterSpacing` (0.12em by default), color of the number and the rule `accent`, number size `numberSize` (px; 22 by default), subtitle color `subtitleColor` and size `subtitleSize` (px; 18 by default), color of the rule between the title and the subtitle `rule` (`none` draws no rule), and the color `endColor` and size `endSize` (px; 44 by default) of the closing mark of a chapter end. Anything not set uses `titleBg`, `fg` and `accent` of `system` and the text font (see the example in [screens.md](screens.md)) |
| `title` | The title screen's background, BGM, title image (`logo`), whether to show the title text (`showName`), and whether "Continue" resumes from the newest save (among saves, quick saves and autosaves) without opening the Load screen (`resume`; false by default). With `variants`, such as `[{ "if": "(system.cleared)", "background": …, "bgm": …, "logo": … }]`, the first entry whose condition on variables shared across all saves is true replaces only the items it lists (a title that changes after the game is cleared). `menu` sets the button layout (`align`, `direction`, `gap`, `width`) |
| `menuBar` | The buttons in the quick menu and their order (`items`; these can also include `prev-choice`, `next-choice`, `replay-voice` for replaying the voice, `items` for the inventory, `fullscreen` to switch between fullscreen and a window, and `screen:<name>` to open a project screen (registered with the plugin's `system.defineScreen`; the text is its `label`)), position (`position`: bottom-right / bottom-left / bottom-center / top-right / top-left / hidden), the left and top edges (`x` `y`, in px; an axis you write takes precedence over `position`, and `hidden` still hides it), and the menu button on touch devices (`touchButton`). `images` and `activeImages` (images per action, and while active), `labels` (replacement text), `color`, `shadow` |
| `indicator` | Position of the auto and skip indicator (top-left, top-right, bottom-left, bottom-right, hidden. top-left by default; hidden when the project replaces the quick menu) |
| `cursor` | The mouse cursor's image and hotspot. With `animated`, the image is drawn on the game screen and moved with the mouse (GIF and APNG animate) |
| `tap` | The tap effect's image (`image`), size (`size`), time until it disappears (`time`) and sound effect to play (`se`; from `sound`) |
| `screen` | Set `fullscreen` to false to prevent fullscreen ("Display" in Settings, Alt+Enter, F11 and `@fullscreen` stop working). `textScale` is the range "Text size" in Settings applies to (`all`: text, choices, name box, backlog and system screens; the default. `message`: text and choices only). `pauseScenario` is whether to stop the script's next command while standard screens (Settings, Save, Load, Log, confirmations and so on) are open (the rest of a `@wait` and effects that advance with time don't move on behind the screen; it stops by default. Set it to false to not stop, as in earlier versions). Only the next command stops; the remaining time of choices with a time limit (`@choice timeout=`) doesn't go down while a screen (including project screens) is open, regardless of this setting (the remaining-time bar stops too, and continues from where it was when the screen closes). Set `pauseInBackground` to false to keep sound, video, auto and the choice time limit going when the tab is in the background (paused by default) |
| `input` | Mouse and advance bindings. `rightClick` (`menu` or `hide`), `wheelUp` (`backlog` or `rollback`), `swipeSide` (`rollback` or `none`; for sideways swipes), `middleClick` (pressing the wheel; `hide` or `none`), `numberKeys` (false to not choose options with the number keys). Set `skipEffects` to false so that advancing while waiting for an effect doesn't skip it to the end (skipped by default; per command, `skip=false`) |
| `saveSlots` | Number of save slots (rounded up to a multiple of 8, 8–200; 48 by default) |
| `autosave` | Autosave (see "Autosave" above). `slots` is the number of slots (0–10; 3 by default. With 0, there are none and `@autosave` does nothing), `leave` is whether to also save when quitting and going to the background (true by default; false when the project replaces the Load screen), and `on` sets other times to save (`choice`: when choices are shown, true by default; `chapter`: at the start of a chapter, false by default; `pages`: every this many pages read, 0 by default, which doesn't) |
| `chapterNames` | Chapter names shown in save slots (`"file#label"` or `"file"` → name). See "Save, Load" above |
| `quickSave` | Quick save. `slots` is the number of slots (1–10; 3 by default). Quick save saves to an empty slot or the oldest slot, and quick load loads the newest slot. With 1, it keeps overwriting a single slot, as in earlier versions |
| `backlog` | Number of pages kept in the backlog (10–2000; 300 by default) |
| `sound` | `movie` is the volume from Settings applied to the sound of videos (`@movie`, `@bg-movie`, `@blend-movie`, movies in Extras) (`bgm`: the music volume, the default; `se`; `voice`; `none`: the master volume only). The video volume is "the command's volume × that volume × the master volume," and mute applies too. Where the volume of videos can't be changed, as on iOS, it's applied through Web Audio. Set `streamBgm` to false to decode long BGM too before playing it (see streaming in "Sound" above). `ui` is the system sound effects (see "Sound" above) |
| `backlogChoices` | Whether to keep chosen options in the backlog (true by default) |
| `defaults` | Settings values for players playing for the first time (text speed, auto delay, master volume `master`, BGM, sound effect and voice volumes, whether skip also skips unread text, whether auto and skip keep going after choices `autoAfterChoice` and `skipAfterChoice`, text box opacity `windowOpacity`, text size `textScale`, and whether to lower the BGM while a voice plays `duckBgm`) |
| `css` | The list of project CSS files (paths from the project folder, such as `["ui/screens.css"]`). See "Project CSS" below |
| `keys` | Key bindings (advance, menu, backlog, hide, auto, skip, quickSave, quickLoad, save, load, config, rollback, rollforward, prevChoice, nextChoice, nextUnread, screenshot, mute, replayVoice, copyText → arrays of `KeyboardEvent.key` names). Only the actions you write replace their defaults, and the keys you write are removed from the defaults of other actions. An empty array turns off that action's keys |

The placement of choices, `ui.choice.position`, is `avoid-faces` (the default; centered vertically, but moved to the nearest height that doesn't overlap only when it would overlap a sprite's face. If it fits neither above nor below, the height with the least overlap),
`center` (vertically centered, even over a face), `top` or `bottom` (just above the message window; at the bottom if the window isn't shown), or `inline` (written into the text flow; see below).
The face area is `face` of the sprite set in cast.json (the area cut out for the face window); without it, it's estimated from the skin and outline in the sprite image (from the forehead to the chin).
When `y` is written, `y` is used instead of `top` and `bottom`, and `avoid-faces` moves from the `y` position (with only `y` and no `position`, the choices stay at `y`). Choices with `x=` `y=` on their buttons and choices shown on the chat screen don't move. Portrait games work the same way.

With `inline`, no button layer is overlaid; the options are written as text lines continuing the current text (sound-novel style). A ▶ marker at the start of a line points to the line being chosen, and once chosen the options stay as part of the text with a mark left on the chosen line. While `@nvl on` they're stacked like paragraphs, so they are redrawn after saving and loading (in a message window they disappear together with the next page). `x=` `y=` placement, `ornament`, `backdrop` and `hideMessage` have no effect. Choices from the game's own screen (`screens.choice`, separate from `ui.templates.choice`) and choices on the chat screen (`ui.chat.dialogue`) keep their usual layer and band.

```json
"ui": { "choice": { "position": "center" } }
```

The player applies the look (text, message window, name box, click-wait icon, choices, cursor) to the game screen (`DomHost.setUi`), so it works with replaced system screens too.
Save slots, the backlog, initial settings, keys, the title screen and the quick menu are read by the default system screens (replaced system screens can read them from `SystemEnv.project.ui`).
On the dev server, changes to `ui` are reflected in open players right away (without restarting).

### Project CSS

The CSS files listed in `ui.css` are loaded after the theme and plugin CSS (CSS a plugin `import`s and `<style>` added in `setup`), in the listed order.
The engine's CSS sits in the cascade layer `liminalia`, so project CSS wins without fighting over selector specificity, and at equal specificity a later file wins.
The selectors and variables of the parts are in the tables in [screens.md](screens.md). You can restyle the standard screens by selector without writing a plugin.

```json
"ui": { "css": ["ui/screens.css"] }
```

- **Export**: included in browser, desktop and mobile exports. Files that `url()` and `@import` inside point to are included too (small images inside the CSS, others in `engine/`)
- **Dev server**: saving swaps the CSS in open players and in Studio's preview without reloading. Adding a file to `ui.css` or removing one works the same way
- **Nothing outside the project is read**: the paths in `ui.css` and the `url()` and `@import` inside are relative paths that point inside the project folder (`url()` is relative to the CSS file.
  Going up like `../assets/image/frame.png` is fine, but not above the project folder). `data:` is allowed too.
  Absolute URLs such as `http:` and paths starting with `/` aren't exported and can't be read under the exported game's rules (Content-Security-Policy), so `lim check` reports them as errors (`ui-css-outside`)
- **Check**: missing files (`ui-css-missing`), unclosed comments or brackets (`ui-css-syntax`) and files `url()` points to that don't exist (`ui-css-asset`) are reported by `lim check`, Studio and VS Code too
- Clicking a part in Studio's "Game screens" lets you write lines for that part's selector from fields ([studio.md](studio.md)). They go to the first file in `ui.css` (if there is none, `ui/screens.css` is created and added to `ui.css`)

### Themes

Open "Change theme" at the very top of "Game settings" in Studio to choose a theme for the look of the whole game (Default, Washi, Night, Pastel, Terminal, Mansion, Near Future, School, and Chat for portrait games). Settings and assets don't change until you choose a card and click "Apply."
A theme changes the text, message window, name box, click-wait icon, choices, system screens, ending-name screen and quick menu together. What each screen can change with values is in the table in [screens.md](screens.md). From an AI assistant, apply one with `set_theme` in MCP.

| When you choose one | What |
|---|---|
| Replaced | The look of `text` (font, size, color, decoration and so on), `message`, `name`, `glyph`, `choice`, `chat` (except `me` and `title`), `system`, `ending`, `chapter`, the look of `menuBar` (`images`, `activeImages`, `labels`, `color`, `shadow`), `title.menu` |
| Kept | Items for controls and environment (`keys`, `defaults`, `saveSlots` and so on), text layout (`rubySize`, `lineChars`, `lineBreak` and so on), `message.scroll`, `message.vertical`, `chat.me`, `chat.title`, the quick menu's `items`, `position`, `x`, `y` and `touchButton`, the title's picture and sound (`background`, `bgm`, `logo`). Fonts and `system.images` that the theme doesn't set |
| Copied | The theme's assets (SVG), to `assets/image/themes/<id>/` |

The game reads the values and draws from them, so after choosing a theme, you can edit each field one by one. Choosing another theme after editing asks for confirmation.
When you apply a theme in Studio, assets that the previous preset copied and that are still unchanged and unused anywhere else go to the trash. Assets changed in the project, assets that are referenced and assets of original themes are kept. They can be restored from the trash.
The built-in themes are in `packages/lang/src/themes/` (Studio loads them too, so they're in lang rather than on the rendering side).

**Orientation**: Writing `orientation: "portrait"` in a theme (for a project theme, in `theme.json`) makes it for portrait games only. It isn't listed for landscape games, and for portrait games it's grouped at the top of the list under the heading "Portrait only." `set_theme` in MCP and `POST /ui/theme` in Studio refuse to apply it to a landscape game and give the reason (`themeFitsScreen` in `@liminalia/lang`).

**Themes in the project**: Writing `{ "name": …, "nameEn": …, "orientation": …, "engines": { "liminalia": ">=2" }, "ui": { … } }` in `themes/<id>/theme.json` adds the theme to the list (`nameEn`, `orientation` and `engines` can be left out). Assets put in `themes/<id>/assets/` are copied to `assets/image/themes/<id>/`.
`engines.liminalia` is the range of engine interface versions the theme works with, written the same way as for plugins ("Declaring compatible engines" in [plugins.md](plugins.md)). If it doesn't match this engine, `lim check` and Studio's check warn (`theme-engine-version`).
Screens and effects that can't be written as values can be registered with the same `<id>` in a plugin's `themes` ([plugins.md](plugins.md)); they're active only while that theme is chosen.

**Making the current look a theme**: In the theme section of "Game settings," "Save the current look as a theme" saves `themes/<id>/theme.json` under the name you enter and adds it to the list (`<id>` is made from the name. A project theme with the same name is overwritten after confirmation. The names of built-in themes can't be used).
The saved `theme.json` gets `engines.liminalia` from the current engine interface version (such as `">=2"`). Only the "Replaced" items in the table above are saved (`uiThemeValues` in `@liminalia/lang`, the same definition as `applyUiTheme`); the "Kept" items and `ui.system.preset` aren't included. A theme saved in a portrait game gets `orientation: "portrait"` (because window positions and widths are set in coordinates for the game screen's orientation; this applies to themes without chat settings too). Saving doesn't change the name of the theme currently chosen (`preset`), because plugin `themes` are applied by name. To use the saved theme, choose it from the list.
References to images and fonts keep pointing at the project's assets (`assets/`), so use the theme within the project where you made it (to take it to another project, copy the assets along with it).
A project theme can be moved to the trash (`.liminalia/trash/`) with the button at the top right of its card, and restored with "Undo" in the notice (values written in `ui` stay as they are). Built-in themes can't be deleted.

### Chat screen

The look of the screen for `@chat-open` and `@chat` ([commands.md](commands.md)) is set with `ui.chat`. Every item can be left out; without them, the colors and shapes stay as they were.
The chat theme (`packages/lang/src/themes/chat.ts`; portrait only) fills these in and sets `dialogue` to `true`.

| Key | What it holds |
|---|---|
| `dialogue` | Shows regular dialogue, narration and choices on a chat screen that fills the game screen (below) |
| `me`, `title` | Your own speaker name (this speaker's bubbles appear on the right) and the name in the header (no header without it). `me=` and the title of `@chat-open` take priority. Kept when the theme changes |
| `size`, `font`, `color` | Text size (px. 16 by default for the `@chat` screen and 26 for `dialogue`; with `dialogue`, the "Text size" setting applies too), font and color |
| `background`, `image` | The screen's background (CSS `background`) and an image tiled over it (from `image`) |
| `headBackground`, `headColor` | The header's background color and text color |
| `otherBackground`, `otherColor`, `meBackground`, `meColor` | Background and text colors of the other person's bubbles and your own |
| `radius`, `tailRadius` | The bubbles' corner radius (16 by default) and the corner on the speaker's side (4 by default) |
| `nameColor`, `noteColor` | The color of names, and of the one-line narration |
| `showName` | How the other person's name is shown. `always` (every time; the default), `first` (only when the speaker changes), `none` |
| `showFace`, `faceSize` | Shows the face in a circle next to the other person's bubbles (56 in diameter by default). The image is the character's face, the same as in the face window (the variant's `face`, or the crop from the sprite set's `face`); without one, the first character of the name |
| `choiceBackground` | Background of the choice area in `dialogue` (the buttons use `ui.choice`) |
| `typing` | How long "…" is shown before the other person's bubble (milliseconds; 0 by default, which doesn't show it. 420 in the chat theme). Clicking skips it. Not shown while skipping, on read pages, on pages returned to by rollback, or in Studio's preview |

**Putting regular dialogue in bubbles** (`dialogue`): Without changing how the script is written, dialogue (`Name「…」`, `Name "…"`) becomes a bubble (the outer Japanese quotation brackets `「」` and `『』` are removed, while quotation marks are removed only when `ui.text.quotes` is `strip`; `（…）` stays), and narration becomes a small line in the center, stacked up with the bubbles. The message window isn't shown.

- Text is shown with the same parts as the message window, so ruby, styling, inline commands, `{click}`, the text speed settings, `@text-sound`, auto, skip, read detection, the glossary and voice all work as they are. The backlog keeps the usual text (with the brackets)
- Read pages are stacked in `std.chat` of `stage.extra` (at the same point as paragraphs in NVL. This is in save data, so the thread is restored on load, rollback and in Studio's preview). The newest 60 are kept (`CHAT_KEEP`)
- Choices are lined up in the area at the bottom of the screen (image buttons and clickable areas stay in their own positions), and the chosen text is stacked as your own bubble (image buttons and clickable areas of `@choice` aren't stacked)
- During `@nvl on`, `@vertical on` and `@balloon on`, it goes back to the usual message window and hides the chat screen (the thread stays). `@window hide` and "Hide" hide it (a screen opened with `@chat-open` isn't hidden by `@window hide`). `@clear` clears the thread. `@chat-close` closes the screen, and the next text starts a new thread. `@mask` covers the whole screen
- Bubbles don't get the read color (`ui.text.readColor` applies only to text in the message window, because the other person's bubbles and yours have different background colors). Lines of read pages get the class `is-read`
- If you remove `ui.chat.dialogue`, threads started from regular dialogue aren't shown even if they're in a save. A screen opened with `@chat-open` appears in the earlier terminal-like form

For image frames, writing `imageSlice` (a number, or four numbers for the top, right, bottom and left) keeps the corners from stretching (CSS `border-image`). If an SVG is stretched into a frame with a different aspect ratio without slicing, the default `preserveAspectRatio` draws it small in the middle, so use slicing for SVGs.

## Asset and scenario encryption (desktop version)

Set `build.encrypt` in `liminalia.json` to true ("Encrypt assets and scenario (desktop)" in Studio's project settings), and the desktop version's
assets, scenarios, data, characters, translations, flowchart and the packs included in the export are encrypted (AES-256-CTR), and the app decrypts them when it reads them
(it also handles reading sound and video from the middle). Opening the bundled file (asar) doesn't give usable files as is. The key has to be inside the app,
so someone who puts in the effort can break it (this is true of every engine).
- There's one key per project, saved in `.liminalia/encrypt-key` (the same key for the exports for every OS). Patches (`lim patch`) decrypt the contents with the key inside the app of the previous export
  to compare them, and encrypt the patch with the same key
- The browser and mobile versions aren't encrypted (they're delivered to the player's device, so they can't be fully hidden)
- The export screen shows the current settings for encryption, the save location and save protection (clicking one opens that field in the project settings)

## Font subsetting

Write `{ "files": ["others/fonts/main.otf"], "text": "characters to add" }` in `build.subsetFonts` of `liminalia.json`, and on export the font is subset
to only the characters the game uses (ASCII, kana, and full-width letters, digits and symbols are always kept; characters are collected from scenarios, data, translations, liminalia.json, the source of project plugins,
the text of the engine's system screens, and the packs included in the export (scenarios, data, translations and characters in `packs/<id>/`)). If characters come from elsewhere, such as name input, add them to `text`. The format (ttf, otf, woff, woff2) is kept.

## Including only the assets in use

With `lim build … --only-used`, or `"build": { "onlyUsed": true }` in `liminalia.json` ("Include only the assets in use" in the Studio's export settings),
the export leaves out the assets `lim unused` lists (those whose names appear nowhere in the scripts, data, `cast.json`, `liminalia.json`, the project's plugins
(including ones in folders outside the project or in `node_modules`), the project CSS (`ui.css`) and screen templates (`ui.templates` and `ui/screens/`) with the files next to them,
packs, translations or character models. Drafts and backups elsewhere in the project folder aren't read).
The export log shows how many were left out, their size and their names. Voices (`voice/`) and the assets of the selected theme are never left out. Nor are assets matching a
numbered `@flipbook` pattern (`slash_{nn}.png`), or assets whose name begins or ends with text joined in an expression (`"radio_" + n`). A folder with a command whose asset argument is
an expression (such as `@bg (game.place)`, or `{@se (…)}` inside text), or whose `folder=` is an expression, is kept whole, since the script doesn't say which assets it uses.
The check (asset existence and the plugins' checks) is then run again as if the left-out assets were gone, and any asset that would cause a problem is put back. Names built inside plugin code can't be traced,
so after exporting, run `lim playtest` to the end and check that no asset failed to load.
If you ship updates with `lim patch`, set `build.onlyUsed` rather than passing `--only-used` (the export made for the patch reads only the settings,
so with `--only-used` alone the left-out assets would be added to the patch).

## Steam (desktop version)

- **Cloud saves**: The desktop version keeps saves, read history and settings in a file per key (data earlier versions put in localStorage is moved at the first
  launch). In Steamworks Auto-Cloud, with the default (the OS's standard location), set the root to "WinAppDataRoaming" on Windows and "Mac Application Support" on Mac
  with the subdirectory `<title>/saves`, and on Linux set the root to "LinuxHome" with the subdirectory `.config/<title>/saves`; the pattern is `*.json`.
  If you set `saves.location` to `"portable"`, set the root to "App Install Directory" and the subdirectory to `savedata` on Windows and Linux
  (the default of earlier engine versions on Windows and Linux; a game shipped with Auto-Cloud set up that way keeps the same place by writing `"portable"`)
- **Rich Presence**: Show it with `@presence "Chapter 1: The Hill of Stars"` and clear it with an empty string. When a chapter in `extra.chapters` is reached, its title is shown automatically,
  and it's cleared on returning to the title. In the Rich Presence localization in Steamworks, provide `"#Status"` as `"%status%"`
- **Steam Deck and gamepads**: Text input (`@text-input`) shows Steam's on-screen keyboard when the game is played on Steam Deck or a gamepad is connected
  (entering text confirms it. If the player cancels, they can type in the game's field)
- **Workshop** (`build.steam.workshop`): Loads subscribed items as packs
- **Steam Input** (`build.steam.input`): Binds actions to gamepad buttons and system screen controls
- **DLC**: With `steam` (the DLC's App ID) in `build.store.products`, `@purchase` and `system.purchases` work.
  For the Workshop, Steam Input and DLC settings, see [distribution.md](distribution.md)

## Crash reports

Exported games keep one uncaught exception, along with the version, the position being played and the environment (the desktop version also keeps it as a file in `logs/` in the save location, and
if the renderer process crashes, records it and reopens the window). The desktop version's `logs/` also keeps uncaught exceptions and rejected Promises in the main process, and failures to write saves
(once per launch), and keeps only the newest 20 `crash-*.log` files. If the renderer process crashes 3 times within a minute, it stops reopening the window and tells the player
(who chooses to restart or quit), and from the next launch on, it displays without the GPU (`gpu.json` in the save location; the GPU is used again when the game's version changes, or when the file is deleted).
If it stops before showing the window, it tells the player and quits. If you write `build.crashReport.url` in `liminalia.json`, the player is asked at the next launch,
and if they answer "Yes," the crash report is sent as a JSON POST (`project`, `message`, `stack`, `at`, `version`, `userAgent`, `date`, plus `kind`, `source`, `step`, `trail`,
`diagnostics`, `build`, `engine`, `platform`, `language` and `screen`, which tell what happened and on which line). The fields, and how to map positions back with source maps (`build.sourcemap`), are in
"Crash records and source maps" in [distribution.md](distribution.md).

If the project sets `build.analytics.url`, the game asks at its first launch whether it may send play statistics, and Settings gets "Send play statistics"
("Play statistics (optional)" in [distribution.md](distribution.md)).

## Content warnings, content filtering and editions

- **Content warning** (`ui.contentWarning`: `{ title?, text, button?, always? }`): Shown at startup, before the title. Once the player agrees, it isn't shown again
  (it's shown again when the text changes; with `always`, every time). In the desktop version, "Quit" closes the game
- **Startup splash** (`ui.splash`): After "Click to start," logos and a notice are shown once before the title. If a plugin has `splash`, that's used instead
  ```json
  "splash": {
    "logos": [{ "image": "brand/logo.png", "background": "#ffffff", "time": 2500 }],
    "notice": { "title": "Please read first", "blocks": [{ "label": "01 — FICTION", "text": "This story is fiction.\nIt has no connection to real people or events." }], "time": 6000, "auto": true },
    "skip": true,
    "fade": 600
  }
  ```
  `logos` are the logos shown in order (an image in the image folder, the background color, and how long it's shown), and `notice` is the notice (the heading, and a list of `label` and `text`, where `text` splits lines at line breaks;
  the background color `background`, text color `color`, the time until it moves on automatically `time`, and with `auto: false`, it waits for a press). Pressing (click, Enter, Space) moves on to the next (not with `skip: false`).
  `fade` is the time it takes to fade out at the end, leaving the background color. Change the look with `.lm-splash`, `.lm-splash-logo`, `.lm-splash-notice`, `.lm-splash-block` and `.lm-splash-text` in CSS.
  In Studio, "Startup splash" in "Game settings" lets you edit each item without writing JSON
- **Toning down content** (`ui.contentFilter`: `{ label?, default?, assets? }`): Adds an item to the "Display" tab of Settings. The script
  branches on `system.content_filter`, and `assets` replaces assets (paths from the folder for each kind, like `"bgimage/a.png": "a_safe.png"`).
  When the setting changes, the screen during the game is rebuilt
- **Editions** (`build.variants` and `lim build … --variant name`): For each edition, add `forbid` (stop the export if these are included, so that adult assets don't
  get into an all-ages version) and `exclude` (leave these out), and `contentFilter: true` keeps the content toned down without letting the player change it. The script reads the edition's
  name with `system.variant`. Each edition is exported to its own folder.
  The export screen of the authoring app also lets you choose one under "Edition," below the platforms (shown only for projects with `build.variants`. "Standard" exports without an edition.
  The previous choice is remembered per project. `packages/studio-desktop/src/pages/export.ts`)

## Carrying over from a demo

In `saves.carryFrom` of `liminalia.json`, map the ids of games whose saves can be carried over (such as a demo) to their titles (`{ "my_game_demo": "My Story Demo" }`).
- At the first launch, if this game has no save data yet and save data for that game is found, it asks once whether to carry it over. The browser version reads from the same storage
  (so both must be hosted at the same place), and the desktop version reads from the save location of the app with that title. Save data in an unreadable form (saves.protect) can be carried over too
- "Import saves" in Settings can also load save data exported from that game

## Additional content and fixes (packs)

Put `pack.json` (`id`, `title`, `version`, `requires` (the required version of the base game), `order` (loading order), `extra`) along with
`scenario/`, `data/` and `assets/<kind>/` in `packs/<id>/` in the project folder, and `lim build` includes them in `packs/` of the export. To distribute one later, export it with `lim pack packs/<id>`
and put it in the game's `packs/` (`Resources/packs/` in the desktop version; for example, a Steam DLC depot).
- Packs are loaded at startup; scenarios, data and assets with the same name as the base game's are used first (replacements for fixes). Those with new names are added
- `extra` (CG, replays, music, achievements, glossary, chapters) is added after the base game's lists. The flowchart uses the one with the packs merged in (made by lim pack)
- The script can check whether a pack is installed with `system.packs.<id>` (the value is the version) (`@if (system.packs.dlc1)`)
- Packs whose `requires` doesn't match the base game's version (`version` in `liminalia.json`) aren't loaded. Packs aren't loaded on the dev server
- The desktop version looks in `packs/` in the save location (installed by updates), `Resources/packs/`, items subscribed in the Steam Workshop (`build.steam.workshop`)
  and those included in the export, in that order, and for the same id uses the one found first

## Updates (desktop version)

Write the URL of the manifest made by `lim update-manifest` in `build.update.url` of `liminalia.json`, and the desktop version checks for new packs or a new version of the game at startup (not with `checkOnStartup: false`)
and with "Check for Updates" in the menu (`@check-update` from the script).
- The check at startup runs without making the player wait, and asks on the title screen when no other screen is open. Updates the player declines aren't asked about again at later launches (the menu still asks)
- Packs: If the player answers "Yes," it downloads the pack, checks its sha256, puts it in `packs/<id>/` in the save location and asks whether to restart (restarting, like closing,
  finishes the autosave and saving first)
- The game itself: If the player answers "Yes," it downloads and checks the file for that OS, if there is one; for a Windows installer, it starts the installer and quits the game.
  For a Mac zip or a Linux tar.gz, it extracts and checks it, shows "Replacing the game with the new version and restarting," quits, swaps the files and starts again
  (other files, and installs in places where the files can't be swapped, are opened instead). If there's no file, it opens the download page
- The questions use the standard confirmation dialog (or `screens.confirm`, if the project replaces it; the kinds are `update` and `update-restart`).
  For how to make the manifest and its shape, see [distribution.md](distribution.md)
