/* rustsega shell (M7-02, #135).
 *
 * Plain CSS, loaded by trunk through `<link data-trunk rel="css">` in
 * `index.html`. No framework, no downloaded fonts, no JavaScript: the layout is
 * here and the markup that uses it is in `src/`.
 *
 * Sections, in order: tokens, reset, buttons and form controls, app shell
 * (top bar / screen / drawer / toasts), motion.
 */

/* ---------------------------------------------------------------- tokens -- */

:root {
  --bg: #0b0d12;
  --bg-screen: #05060a;
  --surface: #141821;
  --surface-2: #1c2230;
  /* Every component boundary in the shell, and the only cue for where one ends:
   * `--surface-2` on `--bg` is 1.22:1, so a control cannot rely on its fill. It is
   * the value 1.4.11 asks for (#407) - moved the minimum distance along the
   * original hue to reach 3:1 against every surface it can sit on, and checked by
   * tests/contrast.rs rather than by eye. */
  --border: #686d79;
  --text: #e8ecf4;
  --text-muted: #8b93a7;
  --accent: #5b8cff;
  --accent-2: #ff5c7a;
  --ok: #3ddc97;
  --warn: #ffb547;
  --danger: #ff5c5c;
  /* Text on top of --accent. Dark on both themes: the accent is light enough
     that white text on it fails contrast. */
  --on-accent: #071021;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);

  /* Spacing, on a 4px grid. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Radii: controls, cards, drawer. */
  --radius-control: 6px;
  --radius-card: 10px;
  --radius-drawer: 16px;

  /* Type scale: 12, 14, 16 (base), 20, 28. Weights 400 and 600. */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 20px;
  --text-xl: 28px;
  --weight-regular: 400;
  --weight-emphasis: 600;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Shell geometry. */
  /* One row of the ROM library, and the number `crate::library::ROW_HEIGHT_PX`
     positions the virtualized list by. The two have to agree - a row drawn at one
     height and placed at another is a list with holes in it - and
     `tests/library_row.rs` is what keeps them so. */
  --library-row: 56px;
  --topbar-height: 56px;
  --drawer-width: 380px;
  --bottom-sheet-height: 70dvh;

  /* The touch overlay (M7-09, #142). 56px is the smallest thing a thumb is asked
     to hit, so no control is drawn under it - and the band is the strip of
     portrait screen the controls live in below the picture. */
  --touch-key: 64px;
  --touch-key-small: 48px;
  --touch-dpad: 148px;
  --touch-band: 248px;

  /* Motion. Every transition that uses these sits behind the
     prefers-reduced-motion query at the bottom of this file. */
  --duration: 170ms;
  /* The one thing that takes shorter than a transition: the picture arriving.
     Long enough to read as a fade, short enough that nobody waits on it. */
  --duration-enter: 150ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  color-scheme: dark;
}

/* The light theme, written twice on purpose: once for an explicit
   `data-theme="light"` (which the settings drawer sets), and once for a
   `data-theme`-less `<html>` on a machine that prefers light. `Theme::System`
   writes no attribute at all - see `src/theme.rs` - so this is how following
   the OS works. Keep the two blocks in step.

   The four colours after `--text-muted` are here because of M7-19 (#152), and they
   are not optional decoration: `--accent`, `--danger` and `--warn` are painted as
   *text* by `.keycap--capturing`, `.btn--danger` and `.slot-card__ask`, and in the
   dark theme's values they are 3.16:1, 3.03:1 and 1.76:1 on white - under half the
   4.5:1 WCAG AA asks of text. `--on-accent` comes with them because it is the other
   half of `--accent`, and a dark navy on a dark blue is 1.5:1. The values below are
   the ones tests/contrast.rs checks; run it rather than trusting these numbers. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f5f6fa;
    --bg-screen: #e9ebf2;
    --surface: #ffffff;
    --surface-2: #eef0f6;
    --border: #84868c;
    --text: #141821;
    --text-muted: #5b6275;
    --accent: #2f56cf;
    /* The light theme redefines the other three and forgot this one, so a success
     * toast kept the dark theme's mint on near-white: 1.55:1, and 1.4.11 asks 3:1 of
     * the stripe that says which kind a toast is (#407). Only ever a `border-color`,
     * so it is not a text colour and `contrast.rs` does not read it as one. */
    --ok: #2a9868;
    --danger: #c0202a;
    --warn: #7a5300;
    --on-accent: #f7f9ff;
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-screen: #e9ebf2;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #84868c;
  --text: #141821;
  --text-muted: #5b6275;
  --accent: #2f56cf;
  /* 1.4.11 on the toast's kind stripe, as above - `--ok` has to be in both light
   * blocks or the two light themes disagree about it. */
  --ok: #2a9868;
  --danger: #c0202a;
  --warn: #7a5300;
  --on-accent: #f7f9ff;
  color-scheme: light;
}

/* ----------------------------------------------------------------- reset -- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
  font-weight: inherit;
}

canvas {
  display: block;
}

/* The focus ring the whole shell uses - gamepad and keyboard users depend on it
   being the same everywhere, so it is one rule rather than per component. */
:focus-visible {
  box-shadow: var(--focus);
  outline: none;
}

/* --------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-emphasis);
  cursor: pointer;
  appearance: none;
  text-align: center;
}

.btn:hover {
  border-color: var(--accent);
}

.btn--primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--on-accent);
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text);
}

.btn--ghost:hover {
  background: var(--surface-2);
}

.btn--danger {
  border-color: var(--danger);
  background: transparent;
  color: var(--danger);
}

.btn--danger:hover {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

/* An icon-only button is square, so the glyph has room to breathe. */
.btn--icon {
  min-width: 36px;
  padding: 0;
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* -------------------------------------------------------- form controls -- */

.field {
  display: grid;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.field__label {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* The button of a listbox: what a `<select>` used to look like, because a native
 * popup cannot be driven by a gamepad (M7-11, #144). */
.listbox__button {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 36px;
  padding: 0 var(--space-5) 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  /* Inline caret, so the control looks the same in every browser and in both
     themes without shipping an image or a font. */
  background-color: var(--surface-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b93a7' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-2) center;
  background-size: 16px 16px;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  appearance: none;
  cursor: pointer;
  text-align: left;
}

/* The list behind that button: a panel of options, mounted only while it is open
 * so that its buttons are in the tab order and in the spatial walk only while
 * they are on screen. */
.listbox {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  box-shadow: 0 8px 24px rgb(0 0 0 / 35%);
}

.listbox__option {
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: calc(var(--radius-control) - 2px);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.listbox__option:hover {
  background: var(--surface);
}

.listbox__option[aria-selected="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) 0;
  border: 0;
  border-radius: var(--radius-control);
  background: none;
  color: inherit;
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.toggle__track {
  position: relative;
  display: block;
  width: 40px;
  height: 22px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}

/* The 2px here and on `left` is not a space between things and is not on the 4px
 * scale: it is what centres a 16px circle in a 22px pill (tests/spacing.rs
 * therefore reads margins, paddings and gaps, and not this). */
.toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
}

.toggle[aria-checked="true"] .toggle__track {
  border-color: transparent;
  background: var(--accent);
}

.toggle[aria-checked="true"] .toggle__thumb {
  left: 20px;
  background: var(--on-accent);
}

/* ------------------------------------------------------------ app shell -- */

.app {
  display: grid;
  grid-template-rows: var(--topbar-height) 1fr;
  /* `minmax(0, 1fr)`, not the implicit `auto`: a content-sized column lets a
     wide canvas widen the whole shell past the viewport, which `overflow:
     hidden` then hides from the scrollbar rather than fixing. */
  grid-template-columns: minmax(0, 1fr);
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

/* The top bar: wordmark, current game, actions. */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  font-size: var(--text-lg);
  font-weight: var(--weight-emphasis);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.wordmark__dot {
  width: 8px;
  height: 8px;
  margin-left: var(--space-1);
  border-radius: 50%;
  background: var(--accent);
}

.now-playing {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.now-playing--loaded {
  color: var(--text);
}

/* The region the header claims, beside the title: a fact, so smaller and
   monospaced rather than part of the name (M7-03, #136). */
.now-playing__region {
  margin-left: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.topbar__actions {
  display: flex;
  gap: var(--space-1);
}

/* The actions come in two halves, of which exactly one is on screen (M7-19,
   #152): the six icon buttons where the bar has room for them, and on a phone the
   single menu button that opens the drawer they have moved into - the Console
   section at the head of the sheet is where Pause lives once the bar has no room
   for it.

   Which half is CSS and not a width read at mount, because a rotation is not a
   mount and a signal read once would hold the old answer. The 640px is the
   drawer's own phone width, so the actions collapse into the menu at exactly the
   width the menu becomes a bottom sheet. A hidden half is `display: none` rather
   than moved off screen: that is what takes it out of the tab order and out of the
   spatial walk, which ignores a box with no size (`menu::visible_box`). */
.topbar__wide {
  display: flex;
  gap: var(--space-1);
}

.topbar__narrow {
  display: none;
}

@media (max-width: 639px) {
  .topbar__wide {
    display: none;
  }

  .topbar__narrow {
    display: flex;
  }
}

/* The autoplay nudge (M7-05, #138): no browser will start an AudioContext until
   a person does something, and while it is holding the sound back the honest
   thing to say is that the sound is waiting. A pill rather than a toast: it is
   a state of the console, not an event that happened. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: var(--text-xs);
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
}

.chip:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* The save confirmation (M7-14, #147): the same pill as the autoplay nudge, for
   the one moment a save has actually reached IndexedDB. It is a fact that
   happened rather than a thing to click, so it borrows the pill's shape and none
   of its pointer affordances, and it is the green of a toast that went well. */
.chip--saved {
  border-color: var(--ok);
  cursor: default;
}

/* The fast forward badge (M7-17, #150): the same pill for the same kind of fact -
   something the console is doing right now rather than a thing to click - in the
   accent colour, because unlike a save it is about to stop. */
.chip--fast-forward {
  border-color: var(--accent);
  cursor: default;
}

/* The movie chip (M7-18, #365): the same pill again, for the same kind of fact -
   a recording or a replay is on, and during a replay the pads the game sees are
   not the pads the player is pressing. Accent, like the badge it sits beside. */
.chip--movie {
  border-color: var(--accent);
  cursor: default;
}

/* The screen is the hero: it fills what is left of the page, and the canvas is
   centred in it with a soft accent glow behind. */
.screen-area {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: var(--space-4);
  background: var(--bg-screen);
  overflow: hidden;
}

.screen-area::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    55% 55% at 50% 45%,
    color-mix(in srgb, var(--accent) 8%, transparent),
    transparent 70%
  );
  pointer-events: none;
}

/* The canvas's box, in both dimensions, comes from `crate::screen`: the largest
   integer multiple of the frame that fits the screen area, or a 4:3 / square box
   that fits, according to the Scale and Aspect settings (M7-12, #145).

   Which is why `width`, `height` and `aspect-ratio` must not appear here. They
   would be a second answer to "what size is the picture", and the two answers
   disagree on every frame the core is not 320 wide: an H32 program is 256,
   interlace is 448 lines tall, and a menu-driven frame can be either. A canvas
   with two answers is a stretched one - and a player cannot tell a bad scaler
   from a bad PPU, so the one thing a scaler may never do is lie about the size
   it settled on. `style` belongs to the JS writer; `max-*` stays because a limit
   is not a size, and it is what stops a rounding error from scrolling the page.
   M7-04 (#137) draws into this canvas. */
.screen {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--bg-screen);
  box-shadow: 0 12px 32px rgb(0 0 0 / 45%);
  /* Point samples: the alternative is the browser's smooth filter over hard
     320x224 pixels, which is grey soup. `Smoothing` is the deliberate
     exception. */
  image-rendering: pixelated;
}

/* The Smoothing setting, off by default (M7-12, #145): the soft, CRT-adjacent
   look, bought with every pixel edge in the picture. */
.screen--smooth {
  image-rendering: auto;
}

/* `canvas { display: block }` above is an author rule, and author rules beat the
   UA's `[hidden] { display: none }` whatever the specificity, so a hidden canvas
   would otherwise stay laid out: the pair would stack and the live one would be
   pushed out of view. Hiding is how the drawer's Renderer setting puts the
   unused canvas out of the way, so it has to actually hide it. */
.screen[hidden] {
  display: none;
}

/* Fullscreen is the app shell, not the screen area. The ticket asks for the top
   bar to go away and come back on mouse move, and only the fullscreen element and
   its descendants are rendered - a bar outside the subtree could not be shown
   again at all. The shell is the smallest element holding both (#145).

   `:fullscreen`, the browser's own state, carries all of the structure, so a class
   that the JS failed to clear can never hide a bar that should be seen:
   `app--bar-shown` only says which half of this rule is in force. */
.app:fullscreen {
  /*
   * One row, because the bar leaves the flow below: leaving the `--topbar-height`
   * track in place puts the screen area - and so the canvas - in a 56px row, which
   * is the whole reason this rule is here rather than the transform alone
   * (M7-12, #145; found in the browser, not in the arithmetic).
   */
  grid-template-rows: 1fr;
  background: var(--bg-app);
}

.app:fullscreen .topbar {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1;
  transform: translateY(-100%);
  transition: transform var(--duration) var(--ease);
}

.app--bar-shown:fullscreen .topbar {
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .app:fullscreen .topbar {
    transition: none;
  }
}

/* While a file is over the page the whole screen area is the drop target, and
   says so (M7-03, #136). An outline rather than a border: `border` would add
   3px to a grid cell whose content is sized from the space left to it. */
.screen-area--drag {
  outline: 3px dashed var(--accent);
  outline-offset: -8px;
}

/* The loading state (M7-19, #152): a ROM has been chosen and the console is not
   painting yet - the `File` is still being read, then IndexedDB is still handing
   over the cart's saved RAM (see `emulator::start`).

   Absolutely positioned over the middle of the screen area rather than another row
   of its grid, because "no layout shift when loading a ROM" is an acceptance
   criterion and a grid row would push the empty state out of the way as it
   arrived. It says "Loading" in words as well as drawing a ring: with motion
   reduced the ring is still (see the motion section at the foot of this file), and
   the word is the one thing left that knows something is happening. */
.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  margin: 0;
  transform: translate(-50%, -50%);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.loading__spinner {
  width: var(--space-7);
  height: var(--space-7);
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
}

/* The crash card (M7-19, #152): what replaces the picture once the core has
   panicked, when the frame loop has stopped and the frozen last frame is the only
   thing left to look at. It is a card over the screen area rather than a toast - a
   toast is something that happened and went by, and this has not gone by - and it
   covers `z-index: 2`, where the loading spinner is, because a panic during a load
   has left that spinner waiting for a console that is never arriving.

   `inset` rather than a width: the card is the screen area with one unit of space
   around it, so it works at desktop and at phone width without a second number to
   keep in step. */
.crash {
  position: absolute;
  inset: var(--space-4);
  z-index: 3;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: var(--space-3);
  padding: var(--space-5);
  overflow: auto;
  border: 1px solid var(--danger);
  border-radius: var(--radius-card);
  background: var(--surface);
  text-align: center;
}

.crash__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-emphasis);
}

.crash__text {
  max-width: 48ch;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* The panic's own words, quoted for the person who is going to file the bug -
   monospace, and broken anywhere rather than widening the card, because a Rust
   path is longer than any screen. */
.crash__detail {
  max-width: 100%;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
}

/* The FPS overlay (M7-17, #150): the console's own frame rate and frame cost, in
   the top-left corner of the picture where it can be read without covering the
   part of the screen a game draws in.

   `--surface` at 70% so the game shows through it - the reading is over the
   picture, not a window on it - and monospace because the line changes sixty times
   a second and a proportional font would make it jiggle. It is not a control: no
   focus, no pointer, and `role="status"` on the markup says so to a reader. */
.fps-overlay {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 2;
  margin: 0;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-control);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  pointer-events: none;
}

/* The empty screen as one block: the recent games above the drop zone (M7-19,
   #152). They were two children of the screen area before, each sized by its own
   implicit grid row, which is how a dozen cards pushed the drop zone past the
   bottom of a container that clips its overflow - and the drop zone is the one
   thing the empty state cannot be without.

   One grid, one gap, one scroller. The screen area's own `place-items: center`
   centres this block, so nothing here needs to centre itself: when the content is
   shorter than the screen it sits in the middle at desktop width and at phone
   width, and when it is not - landscape on a phone - it scrolls from the top and
   the dashed card stays inside it. */
.start-screen {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--space-5);
  width: min(680px, 100%);
  max-height: 100%;
  padding: var(--space-1);
  overflow-y: auto;
}

/* The empty state: what the screen area shows in place of the canvas until a
   ROM arrives. It is a card, not a frame, so that the dashed edge reads as
   "drop here" and not as a broken screen. */
.empty-state {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  width: min(320px, 100%);
  padding: var(--space-6) var(--space-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
  text-align: center;
}

.empty-state__icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
}

.empty-state__icon .icon {
  width: 24px;
  height: 24px;
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-emphasis);
}

.empty-state__hint {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* The recent games grid (M7-16, #149): the cards above the drop zone, one per
   game this browser still holds the image of. A grid rather than a list because
   what a player is deciding is which of these to play, and twelve of them in a
   column is a scroll. Wider than the 320px drop zone because a card with no
   picture needs the width for a title to mean anything, and it scrolls rather
   than pushing the drop zone out of a screen area that clips its overflow. */
.recents {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  width: 100%;
}

.recents__heading {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.recents__list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-2);
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.recent-card {
  position: relative;
}

/* The card is the button: clicking it is the whole of what a player means, and
   the (x) beside it is the only other thing there is to mean. Beside rather than
   inside, because a button inside a button is markup no browser does anything
   sensible with - and a (x) that is a third of the card's width is a (x) that is
   pressed by accident on a phone. */
.recent-card__launch {
  display: grid;
  align-content: start;
  gap: var(--space-1);
  width: 100%;
  height: 100%;
  padding: var(--space-3);
  padding-right: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.recent-card__launch:hover {
  border-color: var(--accent);
}

/* A header title is up to 48 characters of caps and a card is 180px. */
.recent-card__title {
  overflow: hidden;
  font-size: var(--text-sm);
  font-weight: var(--weight-emphasis);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-card .btn--icon {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  min-width: 28px;
  height: 28px;
  color: var(--text-muted);
}

.recent-card .btn--icon .icon {
  width: 14px;
  height: 14px;
}

.recent-card__region {
  justify-self: start;
  padding: 0 var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.recent-card__time {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* The file input every "Open ROM" button drives (see `rom_picker::open_picker`).
   Off the layout but not `display: none`, which a scripted `click()` cannot be
   relied on to open in every browser. */
.file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* -------------------------------------------------------------- library -- */

/* The ROM library (M8-04, #158): an overlay over the screen area, not a replacement
   for it. The canvas underneath belongs to `crate::emulator` by `NodeRef`, and a
   component that unmounted it would stop a running console.

   The same `z-index` as the loading spinner and later in the document, which is what
   puts the library over it: a row that is downloading a ROM says so itself, and the
   spinner belongs to the picture that arrives after. The crash card is `z-index: 3`
   and still wins, as it must. */
.library {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--bg);
}

.library__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* The search box is a control of the same weight as a `.btn`, because it is the
   first thing the view wants and the second thing a phone's keyboard covers. */
.library__search {
  flex: 1 1 160px;
  min-width: 0;
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
}

.library__search:hover,
.library__search:focus {
  border-color: var(--accent);
}

.library__chips {
  display: flex;
  gap: var(--space-1);
}

/* The region chips: a filter is not a mode, so it is `--text-muted` until it is on -
   and `--on-accent` on `--accent` when it is, the same pair the primary button uses. */
.library__chip {
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

.library__chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.library__chip--on {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.library__count {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* The scroller is what `crate::library::visible_window` measures: its scroll offset
   and its own height choose the rows that exist, and its track is what they are
   positioned in, so that the scrollbar says how big the whole list is rather than how
   big the eleven rows currently on screen are. */
.library__scroller {
  position: relative;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.library__track {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
}

.library-row {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--library-row);
}

/* A row is a `<button>` and nothing else, which is what makes the shell's spatial
   walk the keyboard and d-pad support for this list - see `crate::menu`. */
.library-row__launch {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  height: 100%;
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.library-row__launch:hover:not(:disabled) {
  background: var(--surface-2);
}

/* The row whose ROM is on its way: still the row the player pressed, so it stays
   legible, but it cannot be pressed twice. */
.library-row__launch:disabled {
  cursor: progress;
  opacity: 0.6;
}

.library-row__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--text-sm);
}

.library-row__tags {
  display: flex;
  gap: var(--space-1);
  overflow: hidden;
}

.library-row__tag {
  padding: 0 var(--space-1);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  white-space: nowrap;
}

/* `Beta` and `Proto` are a warning about the dump, not a fact to choose on. */
.library-row__tag--muted {
  opacity: 0.5;
}

.library-row__size,
.library-row__loading {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.library__empty {
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* Under the top bar's own width the title is the only thing a row has room to be
   read by, and a tag that has to be read is a tag that is in the way. */
@media (max-width: 639px) {
  .library-row__tags {
    display: none;
  }
}

/* The library's way in from the empty state (M8-04, #158), which is also a phone's
   only way in: the top bar has no room for the button below 640px. */
.library-entry {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--space-1);
  width: 100%;
}

.library-entry__count {
  font-size: var(--text-xl);
  font-weight: var(--weight-emphasis);
}

.library-entry__hint {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ----------------------------------------------------- drawer and toasts -- */

/* One fixed, clipped layer for the drawer and its backdrop. Clipping matters:
   the closed drawer sits off-screen, and without this it would be scrollable. */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  pointer-events: none;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  opacity: 0;
  pointer-events: none;
}

.drawer-backdrop--open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  width: min(var(--drawer-width), 100%);
  height: 100%;
  border-left: 1px solid var(--border);
  border-radius: var(--radius-drawer) 0 0 var(--radius-drawer);
  background: var(--surface);
  box-shadow: -12px 0 32px rgb(0 0 0 / 35%);
  transform: translateX(100%);
  /* Hidden rather than merely off-screen: `visibility: hidden` takes the
     drawer's own controls out of the tab order while it is shut. */
  visibility: hidden;
}

.drawer--open {
  transform: translateX(0);
  visibility: visible;

  /* `pointer-events`, and the reason it is here: `.overlay` above shuts the
     whole layer to the pointer and each child that wants clicks opens itself
     again - `.drawer-backdrop--open` does, and this did not, so every control in
     the drawer was hit-tested against the backdrop, which closed the drawer
     instead of being clicked. Found in #143, where it stood between a player and
     the binding table. */
  pointer-events: auto;
}

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.drawer__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-emphasis);
}

.drawer__body {
  flex: 1;
  padding: var(--space-4);
  overflow-y: auto;
}

/* The hint bar at the foot of the menu: `sticky` to the bottom of the scrolled
 * body, so it says what the buttons do while the player is still reading the
 * middle of the page (M7-11, #144). */
.hint {
  position: sticky;
  bottom: calc(var(--space-4) * -1);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin: var(--space-4) calc(var(--space-4) * -1) calc(var(--space-4) * -1);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.hint__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.hint__key {
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius-control) - 2px);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* Under 640px the drawer is a bottom sheet, not a side panel. */
@media (max-width: 639px) {
  .drawer {
    top: auto;
    bottom: 0;
    width: 100%;
    height: min(var(--bottom-sheet-height), 100%);
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: var(--radius-drawer) var(--radius-drawer) 0 0;
    transform: translateY(100%);
  }

  .drawer--open {
    transform: translateY(0);
  }
}

.settings-section {
  margin-bottom: var(--space-5);
}

/* The console actions in the drawer (M7-19, #152): the top bar's controls, for the
   width that has no room for a top bar. Words rather than glyphs, because the
   drawer is read rather than scanned and a word says whether it is Pause or Play
   without a hover to ask it. */
.console-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.settings-section__title {
  margin-bottom: var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-emphasis);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.settings-section__note {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* The About section's link (M7-19, #152): the shell's only anchor, so it is the
   one thing that has to be recognisable as one without relying on the UA's blue -
   which is not a token and would not change with the theme. */
.settings-section__link {
  color: var(--accent);
  font-size: var(--text-sm);
}

/* The save state panel (M7-15, #148): four cards, two across, in the drawer the
   settings drawer is. A card is the game's own 10:7 picture at the width a 380px
   drawer allows two of, its slot number, how long ago it was written, and its two
   buttons - which is the whole of what a player is deciding. */
.slots {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
  padding: 0;
  list-style: none;
}

.slot-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-2);
}

/* The slot the quick keys answer to. Outlined rather than tinted, because in the
   light theme a second tint reads as a hover state on a card that is not being
   hovered. */
.slot-card--current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.slot-card__thumb {
  width: 100%;
  aspect-ratio: 10 / 7;
  background: var(--bg-screen);
  border-radius: calc(var(--radius-card) - 4px);
  /* The thumbnail is a 2x downscale of the game's own pixels and is scaled back
     up by a card that is wider than it: nearest, so a card looks like the game
     and not like a blurred photograph of it. */
  image-rendering: pixelated;
}

/* An empty slot has no picture, and the frame says so. `display: none` rather
   than the `hidden` attribute, because `canvas { display: block }` above beats
   the UA's `[hidden]` rule and a canvas hidden by attribute stays laid out
   anyway (#146). */
.slot-card--empty .slot-card__thumb {
  display: none;
}

.slot-card--empty {
  border-style: dashed;
  background: transparent;
}

.slot-card__name {
  font-size: var(--text-sm);
  font-weight: var(--weight-emphasis);
}

.slot-card__time {
  margin-top: calc(-1 * var(--space-2));
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.slot-card__ask {
  font-size: var(--text-sm);
  color: var(--warn);
}

.slot-card__row {
  display: flex;
  gap: var(--space-2);
}

.slot-card__row .btn {
  flex: 1;
  padding: var(--space-2);
  font-size: var(--text-sm);
}

/* The controls page (M7-10, #143): one keycap table per player, in a drawer
   that is 380px wide on the desktop and the full width of a phone below 640px.
   Three columns - the button, its key, its pad button - and the row names stay
   on one line however narrow the drawer gets. */
.binding-player {
  margin-bottom: var(--space-4);
}

.binding-player__title {
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-emphasis);
}

.bindings {
  width: 100%;
  margin-bottom: var(--space-3);
  border-collapse: collapse;
  font-size: var(--text-xs);
}

.bindings th,
.bindings td {
  padding: var(--space-1);
  text-align: left;
}

.bindings thead th {
  color: var(--text-muted);
  font-weight: var(--weight-regular);
  border-bottom: 1px solid var(--border);
}

.bindings tbody th {
  width: 30%;
  padding-right: var(--space-2);
  font-weight: var(--weight-regular);
  white-space: nowrap;
}

/* A binding is a keycap, so it is drawn as one: raised surface, monospaced
   label, and the 32px of height a pointer needs to hit it reliably. */
.keycap {
  display: block;
  width: 100%;
  min-height: 32px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-align: center;
  cursor: pointer;
}

.keycap:hover {
  border-color: var(--accent);
}

.keycap:focus-visible {
  box-shadow: var(--focus);
}

/* The cell that is waiting for a key says so in the accent colour, because the
   player has to see which of twenty-four cells is listening. */
.keycap--capturing {
  border-color: var(--accent);
  color: var(--accent);
}

/* The paste box of the Input movie section (M7-18, #365): a .rsm is text, so
   the box it is pasted into is the keycap's surface, border and mono font, at
   reading size and as tall as a few lines of a file need. */
.movie-paste {
  display: block;
  width: 100%;
  min-height: 96px;
  margin-bottom: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  resize: vertical;
}

.movie-paste:focus-visible {
  box-shadow: var(--focus);
}

.movie-paste::placeholder {
  color: var(--text-muted);
}

.toasts {
  position: fixed;
  bottom: var(--space-4);
  left: 50%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(420px, calc(100% - (var(--space-4) * 2)));
  transform: translateX(-50%);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-card);
  background: var(--surface-2);
  box-shadow: 0 8px 24px rgb(0 0 0 / 35%);
}

.toast__text {
  flex: 1;
  font-size: var(--text-sm);
}

.toast--info {
  border-left-color: var(--accent);
}

.toast--ok {
  border-left-color: var(--ok);
}

.toast--warn {
  border-left-color: var(--warn);
}

.toast--danger {
  border-left-color: var(--danger);
}

/* ---------------------------------------------------------- touch overlay -- */

/* The on-screen controller (M7-09, #142).
 *
 * One fixed layer over the shell whose own pointer events are off, so that the
 * space between the controls stays the page: only the controls are touchable.
 * `touch-action: none` is the whole of the "no scrolling, no zooming, no text
 * selection" rule, and it is not an inherited property - so every control carries
 * it as well as the layer.
 *
 * In landscape the controls float over the picture, which is all a landscape phone
 * leaves you. In portrait they get a band of their own below the screen, and the
 * screen area shrinks to sit above them - see the `app--touch` rules below.
 */
.touch {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* The controls: a translucent disc each, `--surface-2` at 55% behind a hairline
 * border, filled with `--accent` at 70% and scaled to 0.94 while held. The held
 * state is `aria-pressed`, written by the pointer handlers and by nothing else, so
 * there is one answer to "is this control down" and no class list to keep in step
 * with the tracker. */
.touch__dpad,
.touch__key,
.touch__pill,
.touch__menu {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
  /* The ticket's white label: `--text` is white on the dark theme, and on the
     light one a white label on 55% `--surface-2` over a bright game is
     unreadable. */
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-emphasis);
  text-shadow: 0 1px 2px rgb(0 0 0 / 45%);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  /* Deliberately no transition: a control that takes 170ms to look pressed is a
     control that looks unpressed. */
}

.touch__dpad[aria-pressed="true"],
.touch__key[aria-pressed="true"],
.touch__pill[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 70%, transparent);
  color: var(--on-accent);
  transform: scale(0.94);
}

/* Bottom left, where a left thumb already is. */
.touch__dpad {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + var(--space-4));
  left: calc(env(safe-area-inset-left) + var(--space-4));
  width: var(--touch-dpad);
  height: var(--touch-dpad);
}

/* The moulding, drawn rather than written so that it scales with the disc: two
   rounded bars, one of them turned through a right angle. */
.touch__dpad::before,
.touch__dpad::after {
  content: "";
  position: absolute;
  inset: 16%;
  border-radius: var(--radius-control);
  background: color-mix(in srgb, currentcolor 22%, transparent);
}

.touch__dpad::after {
  transform: rotate(90deg);
}

/* Bottom right: the Genesis arc, `A` `B` `C` along the bottom and the smaller `X`
   `Y` `Z` above them, the cluster bowed so that a thumb rolls from one to the next
   without leaving the glass. */
.touch__faces {
  position: absolute;
  right: calc(env(safe-area-inset-right) + var(--space-4));
  bottom: calc(env(safe-area-inset-bottom) + var(--space-4));
  width: calc(var(--touch-key) * 3 + var(--space-4));
  height: 196px;
}

.touch__key {
  position: absolute;
  width: var(--touch-key);
  height: var(--touch-key);
}

.touch__key--a {
  left: 0;
  bottom: var(--space-5);
}

.touch__key--b {
  left: calc(var(--touch-key) + var(--space-3));
  bottom: calc(var(--space-5) + var(--space-2));
}

.touch__key--c {
  right: 0;
  bottom: var(--space-5);
}

.touch__key--x,
.touch__key--y,
.touch__key--z {
  width: var(--touch-key-small);
  height: var(--touch-key-small);
  font-size: var(--text-xs);
}

.touch__key--x {
  left: var(--space-5);
  top: 44px;
}

.touch__key--y {
  left: calc(var(--touch-key) + var(--space-3) + var(--space-2));
  top: var(--space-5);
}

.touch__key--z {
  right: var(--space-3);
  top: 44px;
}

/* Start and Mode, the small pills. Bottom centre in landscape; a phone in portrait
   has no room for them between the d-pad and the face buttons, so they move up one
   row and stay the middle of the band. */
.touch__middle {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: var(--space-3);
  bottom: calc(env(safe-area-inset-bottom) + var(--space-4));
}

.touch__pill {
  min-width: 72px;
  height: 56px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

/* Top right of the overlay, clear of the top bar: the only way into the settings
   for a player with no keyboard, and not a control of the pad. */
.touch__menu {
  position: absolute;
  top: calc(var(--topbar-height) + var(--space-3));
  right: calc(env(safe-area-inset-right) + var(--space-3));
  width: 48px;
  height: 48px;
}

@media (orientation: portrait) {
  /* A phone in portrait has no room for the pills between the d-pad and the face
     buttons - they would land on `Y` - so they sit above the d-pad, which is where
     the left thumb already is. */
  .touch__middle {
    left: calc(env(safe-area-inset-left) + var(--space-4));
    transform: none;
    bottom: calc(env(safe-area-inset-bottom) + var(--touch-dpad) + var(--space-1));
  }

  /* Portrait: the screen on top, the controls in the band under it rather than
     lying over the picture. `align-items: start` is what puts the screen there,
     and `width: 100%` what keeps it inside the band - `.screen` takes its own
     width from the height of the whole viewport, which in portrait is not the axis
     that binds. */
  .app--touch .screen-area {
    padding-bottom: calc(var(--touch-band) + env(safe-area-inset-bottom));
    align-items: start;
  }
}

/* --------------------------------------------------------------- motion -- */

@media (prefers-reduced-motion: no-preference) {
  .btn,
  .listbox__button,
  .toggle__track,
  .toggle__thumb {
    transition:
      background-color var(--duration) var(--ease),
      border-color var(--duration) var(--ease),
      color var(--duration) var(--ease);
  }

  .toggle__track {
    transition: background-color var(--duration) var(--ease);
  }

  .toggle__thumb {
    transition: left var(--duration) var(--ease);
  }

  .drawer-backdrop {
    transition: opacity var(--duration) var(--ease);
  }

  /* `visibility` is transitioned so the drawer stays painted while it slides back
     off-screen - and `step-end` is what makes that work, holding the value it is
     leaving (`visible`) for the whole transition and jumping to `hidden` at the
     end. Read literally, that timing is the wrong way round for opening: it would
     hold `hidden` for `--duration` after `.drawer--open` is set, and an open
     drawer whose computed `visibility` is still `hidden` cannot hold the focus at
     all. So the transition is declared on the closed state and taken back off on
     the open one below, which is the direction a transition is read from. */
  .drawer {
    transition:
      transform var(--duration) var(--ease),
      visibility var(--duration) step-end;
  }

  /* A transition is taken from the state being transitioned *to*, so opening
     uses this list - transform alone, with `visibility` flipping on the first
     frame - and closing falls back to `.drawer`'s, which keeps the wait. Named
     as a full `transition` rather than `transition-property` because the
     shorthand is what clears the `visibility` entry (#394). */
  .drawer--open {
    transition: transform var(--duration) var(--ease);
  }

  .toast {
    transition:
      opacity var(--duration) var(--ease),
      transform var(--duration) var(--ease);
  }

  /* The loading ring of M7-19 (#152) is the only thing in the shell that moves
     for no reason other than to say "wait": it turns at a speed slow enough not to
     draw the eye, and with motion reduced it simply sits there while the word
     beside it carries the message. */
  .loading__spinner {
    animation: spin 900ms linear infinite;
  }

  /* The screen fade-in of M7-19 (#152), on the class `app.rs` puts on the canvas
     the moment the console is ready: `both` so the canvas cannot show its own bare
     background between the class arriving and the first keyframe. The empty screen
     area is not faded - it has had time enough, and a fade on a drop zone reads as
     a page still loading. */
  .screen--enter {
    animation: screen-in var(--duration-enter) var(--ease) both;
  }

  /* The "Saved" chip of M7-14 (#147) is taken off the page 1.5 s after a write
     lands; this spends the last third of that time going away, so the chip fades
     out rather than being cut off. With motion reduced it is simply there for
     1.5 s and then not, which is the same fact said less prettily. */
  .chip--saved {
    animation: chip-saved 1.5s var(--ease) both;
  }
}

@keyframes screen-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes chip-saved {
  0%,
  65% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}
