/* The stylesheet of the whole game. The page asks for it without waiting for it (index.html): the title card is painted
   at once from a copy of the few rules it needs, kept in the page's own head. Those rules lie here between the marks
   `first paint: from here` and `first paint: to here`; after changing anything between two such marks, run
   `node tools/first.js`, which copies them into index.html (tests/page.test.js fails until the copy is fresh). */
/* first paint: from here */
/* ---- tokens and type (P10) ----
   Two materials: paper (cards, tiles, buttons, sheets) with ink on it, and the dark table with chalk on it. Both are
   near-neutral, warmed a little toward the lamplight, like paper and chalk by a lamp; never brown. Colour belongs to the
   heroes, their traits and the rooms of the dungeon; the interface's only true colour is one red (--danger), for damage.
   One typeface, Averia Serif Libre, served as Quest Serif: only the letters and marks the game shows, in two weights
   (the page asks for both before it reads this file, index.html). Its licence keeps the name Averia for the whole font. */
@font-face {
  font-family: "Quest Serif";
  src: url("assets/fonts/quest-serif-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Quest Serif";
  src: url("assets/fonts/quest-serif-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --table: #030303; --rule: #2c2a27;
  --chalk: #ccc5bd; --chalk-dim: #9d9892; --chalk-faint: #6e6a66;
  --paper: #c7bdb0; --ink: #1d1b19; --ink-dim: #4e4b47;
  --danger: #e5484d;
  /* The tooth of the paper: light and dark specks on a clear ground, laid over any colour. tools/grain.js writes it
     (and --hatch, further down). It stays short on purpose: the browser reads the whole value again for every
     element that uses it. */
  --grain: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAAADFBMVEUAAAAAAAD////////F8ns1AAAABHRSTlMHAgIHgZJ9bAAABEtJREFUeNoBQAS/+wDsqs07pxIsxbjDf2eERfy0ANj7NJ3Sf2Kubp1MCYywI/8A7QQnSDsXNmHLxi0EqI5ipAAKfI5a8ioIYSr9bO0lVqBOAJMSDMcHPUOZd5fKoEFAUiEAQcYh1gXd7dLCJxf0nimGGwDbUJ34WurCm0n7EkC11WH/ANQibbPxJw2K5ieC9ryd1KIAXNO6EKONAM9hwK/dtVtzuAAw193fjgTkzQmkgoeoq3SAAMovas5slRfBa7LUQuMC2GAA0sJqY3zsoTRAppb3+a1yTQDUOgiQOQEH0i4IJE2vrh10AJ5xIDL//4Yn98IEcaV1wi8AlMlSWUqvoe3GuEnmJVuqbAADv44eHEbFwA/wzgNhJ2hZAIjU5ykz9bW/V8Vt8Jq0NaMA7BkPhqTMdFCRb/+xJHeIPABcb5hNHAubH2ygp0qsv2H2ABHVMV5kBF0+ihZe/sGhRL4AOl+TtRAWswun47jkHhFJ0ACkqyAzH0cGpacZRgSp46oeADsUGWur7+0OhSfFyiuEYJ4AFL5vgVAo8s1G5Jx8DwsjvgBH21AlGLwi963TnRFHZb54AKbgiM4QecdwjdSkK3mI0nUASc4Ip0jvwudDAp7NNQqXEAAv0sgNBgk0HT18rv7KGv0ZACAT2mP80nfkl0WvJte6JIkA1b4ulAN25+mOcOwE003HkgBt4OLwcAmc1oOv6gRbf1ByAGhUHCpXt0j0bBnc/V+klMAAD4Q++F+siYZqmTUfo74LtgA0tWs1tveGrALUX6J8GWL7AHQuVRcd7g78th9Vgi56s7oAST0ZiGToLdyWWWoDrx2SewCSjzDvt1cqQa1ZBeWCWyL+AGsUJrYkxjWIRtqDh63mIr4AgfCoFTq60hbzr9srBEjXjADE3WA/pR+Yx8Lm8w9lAfNBAKaAmBLHjo3yMVSg6h7hI50AWd8HEI3X1L9J8JFQfHTGsQBq4owsoDPWrzXrC0/YQIVSAOjZ1gVG9JnY+Sjo1zQGVVMAnjiKbnNJWab6H1ggjwVXEQDpAC45xJ7x0jlRsQJILlD4ADEoaOnFG2xX4LPzTB7sYp4AwmXY+YPTm+R95B5tC9ciDgBw+j6dzV5yKQAYovD6YJPMAPb3o9TuqxZd/UwcEvjrCiwABG67RS5Uiiw6BlHuov9ljAAfJy9MbAjDPxUISBcvnwulAPZ4pP8MEiZ2YUKJOIs/MqQAIrGdvp+XB5Q9eeQm2/0+CQD0Tn3Sbu0OwMBnkDbpcavZAIaxBKXnBAxOZF38DS8fLBsALDuLnmWRwjX3QjkQVYlvlgAalwkJYaPLqpz/hMD8ICvnACRnjxI1s6/Fyn64bl788GgAX6K3b1IGI83W8Lcm0VpzuABF8e4G0aeGinjTaD005kBKAG6nu0yt0b7oEntm39cYDcIAo6a9Xh1n2DlXuqIqchXLXgCbNtf84loU3U+NCLkLfGU/9a31SvRt97kAAAAASUVORK5CYII=");
  --serif: "Quest Serif", Georgia, serif;
  --r: 4px;
  --lift: 0 2px 0 rgba(0, 0, 0, .55), 0 10px 20px rgba(0, 0, 0, .45);
  --spring: cubic-bezier(.3, 1.5, .5, 1);
  --press: 90ms;
  --beat: 100ms;                                            /* one beat of a screen coming in (P9) */
  --console-left: 26px; --console-right: 42px;              /* the console's margins, where the window is wide (P1) */
}

/* ---- page: a game screen, so no text selection, no image menus on a long press, no double-tap zoom ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; touch-action: manipulation; }
h1, h2, h3, h4, p { margin: 0; }
body {
  background: var(--table);
  color: var(--chalk);
  font: 15px/1.45 var(--serif);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  overflow: hidden;
}
:focus-visible { outline: 2px solid var(--chalk); outline-offset: 3px; }
.defs { position: absolute; width: 0; height: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.dim { color: var(--chalk-dim); }
.small { font-size: 13px; }
/* The note for a browser that cannot draw the cellar, without scripts or WebGL 2 (index.html, P13): it shows alone. */
.needs { display: none; position: fixed; inset: 0; z-index: 30; place-content: center; justify-items: center; gap: 14px;
  padding: 24px; text-align: center; }
.cannot-draw .needs { display: grid; }
.cannot-draw body > :not(.needs) { display: none !important; }    /* the table keeps its lamplight */
.needs h1 { font: 700 44px/1 var(--serif); letter-spacing: .08em; }
.needs p { max-width: 34em; }
/* first paint: to here */

/* The faint hatching of rock on the dark table (the notes drawer, the Guild Book's cover), written by tools/grain.js;
   --hatched lays it twice, at two sizes, over the grain: one small tile then never shows as a pattern. */
:root {
  --hatched: var(--hatch) 0 0 / 128px, var(--hatch) 37px 61px / 181px, var(--grain) #0f0e0d;
  --hatch: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='128'%3E%3Cg fill='none' stroke='%23ccc5bd' stroke-width='1.1' stroke-linecap='round'%3E%3Cpath opacity='0.02' d='M15.7 2.7l37 25.6M40 17.9l41.4 22.6M35.1 26.8l41.4 22.6M-28.7 5.1l32.6 22.4M99.3 5.1l32.6 22.4M-12.9 54.1l23.8 25.2M115.1 54.1l23.8 25.2M62.2 46.2l-27.8 29.6M0.3 44.8l-40.5 38.6M128.3 44.8l-40.5 38.6M47 -27.4l-27.4 51.8M47 100.6l-27.4 51.8M37.9 -32.2l-27.4 51.8M37.9 95.8l-27.4 51.8M28.9 -36.9l-27.4 51.8M28.9 91.1l-27.4 51.8M39 99.5l30.7 23.9M116.4 104.7l-32.1 12.7M108.8 85.7l-32.1 12.7'/%3E%3Cpath opacity='0.028' d='M9.9 11.1l37 25.6M4 19.5l37 25.6M-1.8 27.9l37 25.6M126.2 27.9l37 25.6M45 8.9l41.4 22.6M-17.1 -11.8l32.6 22.4M-17.1 116.2l32.6 22.4M110.9 -11.8l32.6 22.4M110.9 116.2l32.6 22.4M-22.9 -3.4l32.6 22.4M-22.9 124.6l32.6 22.4M105.1 -3.4l32.6 22.4M105.1 124.6l32.6 22.4M69.7 53.3l-27.8 29.6M54.7 39.2l-27.8 29.6M121.2 37.4l-40.5 38.6M114.2 30l-40.5 38.6M57.9 75.3l30.7 23.9M51.6 83.3l30.7 23.9M112.6 95.2l-32.1 12.7'/%3E%3Cpath opacity='0.036' d='M49.9 -0.1l41.4 22.6M49.9 127.9l41.4 22.6M9.4 33.1l23.8 25.2M2 40.1l23.8 25.2M-5.5 47.1l23.8 25.2M122.5 47.1l23.8 25.2M77.1 60.3l-27.8 29.6M19.8 -41.7l-27.4 51.8M19.8 86.3l-27.4 51.8M147.8 -41.7l-27.4 51.8M147.8 86.3l-27.4 51.8M45.3 91.4l30.7 23.9'/%3E%3C/g%3E%3C/svg%3E");
}

/* Scrollbars, for the notes' descents and a screen too tall for the window (nothing else scrolls): thin chalk on the
   table. Scrollers never drag the page behind. */
* { scrollbar-width: thin; scrollbar-color: var(--chalk-faint) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 10px; background: var(--chalk-faint) padding-box; }
.descents { overscroll-behavior: contain; }
/* A soft fade at whichever edge still has more to scroll (where scroll-driven animation exists; elsewhere, no fade). */
@property --fade-top { syntax: "<length>"; inherits: false; initial-value: 0px; }
@property --fade-end { syntax: "<length>"; inherits: false; initial-value: 0px; }
@keyframes edge-fade { from { --fade-top: 0px; --fade-end: 22px; } 12% { --fade-top: 22px; } 88% { --fade-end: 22px; } to { --fade-top: 22px; --fade-end: 0px; } }
@supports (animation-timeline: scroll()) {
  .fades { mask-image: linear-gradient(#0000, #000 var(--fade-top), #000 calc(100% - var(--fade-end)), #0000);
    animation: edge-fade linear both; animation-timeline: scroll(self); }
}

/* Pen-drawn glyphs, and the room symbols as the notes draw them (icons.js): a shape filled and lines stroked in
   chalk, and the cuts in the dark of the table. */
.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 4.5;
  stroke-linecap: round; stroke-linejoin: round; filter: url(#pen); }
.symbol .shape { fill: currentColor; fill-rule: evenodd; stroke: none; }
.symbol .lines { stroke-width: 3.4; }
.symbol .cuts { stroke: var(--table); stroke-width: 2.2; }

/* ---- layout (P1): the dungeon fills the window and everything else lies on it, with no rules between its parts ----
   The canvas is fixed behind the page; #stage is the free cell of the grid the dungeon is framed in (board.js). Nothing
   on the page scrolls but the notes' descents. The page's parts are the HUD (#hud: the readouts in .run, the menu in
   .hud-buttons), the route coins (#routes), the notes (#notes), the party (#party: its slots and the action) and the
   hand (#hand: the trait coins and the cards). The window's shape picks one of three arrangements, and these three
   media queries are the only places it is decided:
   - tall, the default (phones and tablets held upright, narrow windows): the HUD along the top, the dungeon, the hand
     with the trait coins two to a row beside it, and at the foot, in reach of a thumb, the route coins and the action.
     The notes are a drawer;
   - wide, (orientation: landscape) and (min-width: 960px) and (min-height: 501px) (desktops, tablets on their side):
     three columns, each the full height of the window: a thin rail on the left (the menu, the trait coins), the world
     in the middle (the dungeon, the hand beneath it) and the console on the right, three things one under another:
     where you are (one line: the readouts, and the route coins between them), what you know (the notes) and what you
     do (the party and the action). Five rows keep the columns from sharing heights: a part that spans two rows takes
     only what the other row leaves, so each part ends where its content does and the notes take the rest;
   - short, (orientation: landscape) and (max-height: 500px) (phones on their side): the dungeon, and beside it a
     console holding what the tall arrangement puts round it: the HUD, the trait coins, the hand, the route coins and
     the action.
   The HUD and the hand give their boxes up (display: contents) where their parts take separate cells. */
body {
  height: 100dvh;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "hud hud" "stage stage" "hand hand" "routes party";
}
#stage { grid-area: stage; min-height: 0; pointer-events: none; }
#hand { grid-area: hand; display: flex; justify-content: center; gap: 8px; min-width: 0; padding: 10px 12px 2px; }
#shade { display: none; }
#hud, .run, .hud-buttons, #routes, #notes, #party, #hand, .trait-coins, .cards { position: relative; z-index: 2; }
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {
  body {
    --top: 29px;            /* where the console's first line starts: its coins lie level with the rail's first button */
    grid-template-columns: 80px minmax(0, 1fr) clamp(352px, 27vw, 420px);
    grid-template-rows: calc(var(--top) + 51px) auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "menu   stage hud"
      "menu   stage notes"
      "traits stage notes"
      "traits hand  notes"
      "traits hand  party";
  }
  #hand { display: contents; }
  /* the console: no frame and no panel, its parts lie on the same dark as the dungeon, like the rail on the left; the
     water and the mist run on under them, only a little darker there, so the chalk stays easy to read */
  #shade {
    display: block; position: relative; z-index: 1; grid-column: 3; grid-row: 1 / -1;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .4) 38%, rgba(0, 0, 0, .55));
  }
}
@media (orientation: landscape) and (max-height: 500px) {
  body {
    grid-template-columns: minmax(0, 1fr) auto minmax(176px, 220px);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "stage hud    hud"
      "stage traits traits"
      "stage hand   hand"
      "stage routes party";
  }
  #hand { display: contents; }
  #shade {
    display: block; position: relative; z-index: 1; grid-column: 2 / -1; grid-row: 1 / -1;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .45) 30%, rgba(0, 0, 0, .55));
  }
}

/* first paint: from here */
/* ---- buttons: chalk outlines on the table, paper for the main action; all sink when pressed (P0) ---- */
.btn {
  position: relative; font: inherit; color: var(--chalk); background: transparent; border: 0; border-radius: var(--r);
  min-height: 44px; min-width: 44px; padding: 8px 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 220ms var(--spring), box-shadow 160ms, background 160ms;
}
.btn::before {
  content: ""; position: absolute; inset: 0; border: 1.5px solid var(--chalk-faint); border-radius: inherit;
  filter: url(#pen); pointer-events: none; transition: border-color 160ms;
}
.btn:hover:not(:disabled)::before { border-color: var(--chalk-dim); }
.btn:active:not(:disabled) { transform: translateY(2px); transition-duration: var(--press); }
.btn:disabled { cursor: default; opacity: .5; }
.btn.icon-btn { padding: 0; width: 44px; }
.btn.paper, .btn[aria-pressed="true"] { background: var(--paper) var(--grain); color: var(--ink); box-shadow: var(--lift); }
.btn.paper::before, .btn[aria-pressed="true"]::before { border-color: transparent; }
.btn.paper { font-weight: 700; }
.btn.paper:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 rgba(0, 0, 0, .55), 0 3px 8px rgba(0, 0, 0, .4); }
/* first paint: to here */
.btn.paper:disabled { opacity: 1; background: transparent; color: var(--chalk-dim); box-shadow: none; }
.btn.paper:disabled::before { inset: 0; border: 1.5px dashed var(--chalk-faint); }
.btn.round { width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.label { font: 700 11px/1.2 var(--serif); letter-spacing: .16em; text-transform: uppercase; color: var(--chalk-faint); }

/* ---- ui/panels.js: the HUD: the level and HP, each a chalk label and its reading, and the menu ----
   The label and the reading share a line, but where the window is wide: there the two readings stand at the ends of
   the console's first line, each label over its reading, and the route coins lie between them. */
#hud { grid-area: hud; display: flex; align-items: center; gap: 12px; padding: calc(8px + env(safe-area-inset-top)) 12px 0; }
.run { display: flex; align-items: center; gap: 20px; min-width: 0; }
.stat { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.stat.level b { font: 700 19px/1 var(--serif); }
.stat.level small { margin-left: 2px; font-size: 13px; color: var(--chalk-faint); }
.stat.hp { align-items: center; }
.hearts { display: flex; gap: 3px; align-items: center; }
.hearts .icon { width: 19px; height: 19px; stroke-width: 5; }
.hearts .full { fill: var(--danger); color: var(--danger); }
.hearts .lost { color: var(--chalk-faint); }
.hearts .lost:is(b) { color: var(--danger); font-size: 15px; }
/* A heart lost cracks; a new level refills them and its number rolls in. */
.hearts .icon.breaking { animation: break 560ms ease-out backwards; }
.hearts .icon.filling { animation: fill-in 460ms var(--spring) backwards; animation-delay: calc(380ms + var(--k, 0) * 120ms); }
.stat.level b.rolling { display: inline-block; animation: roll 520ms var(--spring) backwards 260ms; }
@keyframes break { 0% { transform: scale(1.4); fill: var(--danger); color: var(--danger); } 30% { transform: scale(.82) rotate(-14deg); }
  55% { transform: scale(1.05) rotate(9deg); fill: var(--danger); } 100% { transform: none; } }
@keyframes fill-in { from { transform: scale(.2); opacity: 0; } }
@keyframes roll { from { transform: translateY(-80%); opacity: 0; } }
.hud-buttons { margin-left: auto; display: flex; gap: 6px; }
@media (max-width: 379px) { .stat.hp .label { display: none; } }   /* a narrow phone: the hearts say it */
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {
  #hud { display: contents; }                         /* its readouts head the console, its buttons the rail */
  .run { grid-area: hud; align-self: start; height: 44px; margin-top: var(--top); justify-content: space-between;
    align-items: flex-start; padding: 3px var(--console-right) 0 var(--console-left); }
  .stat { flex-direction: column; align-items: flex-start; gap: 5px; }
  .stat.hp { align-items: flex-end; }
  .stat .reading { display: flex; align-items: center; height: 21px; }   /* so the two labels stand on one line */
  .stat.level .reading { align-items: baseline; }
  .hud-buttons { grid-area: menu; flex-direction: column; align-items: flex-start; gap: 10px; margin: 0; padding: 28px 0 16px 18px; }
  .hud-buttons .btn.round { width: 46px; height: 46px; }
  .hud-buttons::after { content: ""; position: absolute; bottom: 0; left: 27px; width: 28px; border-top: 1px dashed var(--chalk-faint); }
  .notes-btn { display: none; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #hud { padding: calc(4px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 0 8px; }
  .run { gap: 12px; }
  .stat { gap: 6px; }
  .stat.hp .label { display: none; }
}

/* ---- ui/panels.js: the route coins, numbered like the plates on the stairs, each with its descents ----
   A pip (a small diamond) for each descent, filled once spent; while a route has one left, that one is red. A solved
   route's coin wears a check where its pips were. Where the window is wide the coins lie in the middle of the
   console's first line, between the two readings. */
#routes { grid-area: routes; display: flex; align-items: center; gap: 14px; min-width: 0;
  padding: 6px 0 calc(10px + env(safe-area-inset-bottom)) 12px; }
.route-coins { display: grid; grid-template-columns: repeat(3, 44px); gap: 6px; flex: none; }
.btn.route-coin { width: 44px; height: 44px; padding: 0 0 2px; border-radius: 50%; flex-direction: column; gap: 3px;
  font: 700 14px/1 var(--serif); letter-spacing: .04em; }
.pips { display: grid; grid-template-columns: repeat(var(--pips), 4px); gap: 2px; }
.pips i { width: 4px; height: 4px; transform: rotate(45deg); border: 1px solid currentColor; opacity: .75; }
.pips i.spent { background: currentColor; }
.btn.route-coin.last .pips i:not(.spent) { border-color: var(--danger); background: var(--danger); opacity: 1; }
.btn.route-coin .icon { width: 12px; height: 12px; margin-top: -3px; stroke-width: 8; }
.btn.route-coin.solved:not([aria-pressed="true"]) { color: var(--chalk-dim); }
/* A route just solved: its coin is stamped (the puff is with the level coins'). */
.btn.route-coin.fresh { animation: stamp 520ms var(--spring) backwards; }
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {
  body:has(.route-coin:nth-child(4)) { grid-template-rows: calc(var(--top) + 101px) auto minmax(0, 1fr) auto auto; }
  #routes { grid-area: hud; align-self: start; justify-self: center; margin: var(--top) var(--console-right) 0 var(--console-left); padding: 0; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #routes { padding: 4px 0 calc(10px + env(safe-area-inset-bottom)) 4px; }
}

/* ---- ui/board.js: the whole window, the dungeon over the dark; its only light is its lamps' (board.js, deep.js) ---- */
#board {
  position: fixed; inset: 0; z-index: 0; display: block; width: 100vw; height: 100dvh; touch-action: manipulation;
  transition: opacity 200ms ease;
}
#board.rising { animation: rising 450ms ease-out; }      /* a level's dungeon comes up out of the dark (board.js show) */
@keyframes rising { from { opacity: 0; } }
/* The mist over the water: two faint layers of cloud drifting slowly apart, lying low under the dungeon. Its picture is
   made once the game is up (panels.js `mist`, which sets --mist-tex here and nowhere else), and then it comes in slowly.
   It moves on the compositor (transforms only), so the board itself still draws only when something on it moves; and it
   moves a pixel or two a few times a second, not every frame: cloud this soft and this slow looks the same, and the
   screen is left alone in between. */
#mist { position: fixed; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; opacity: 0; transition: opacity 1.6s ease-out;
  mask-image: radial-gradient(ellipse 80vmax 46vmax at var(--glow-x, 40%) calc(var(--glow-y, 45%) + 26vh), #000 10%, transparent 70%); }
#mist.risen { opacity: 1; }
#mist::before, #mist::after { content: ""; position: absolute; top: -10%; left: 0; width: calc(100% + 1024px); height: 120%;
  background: var(--mist-tex, none) repeat; will-change: transform; }
#mist::before { background-size: 1024px 1024px; opacity: .085; animation: drift 150s steps(600) infinite; }
#mist::after { left: -1400px; width: calc(100% + 1400px); background-size: 1400px 1400px; opacity: .06; animation: drift-back 230s steps(920) infinite; }
@keyframes drift { to { transform: translate3d(-1024px, 0, 0); } }
@keyframes drift-back { to { transform: translate3d(1400px, 0, 0); } }
/* Nameplates (nameplates.js): the one place the board says what is known of a room's key. A plate hangs from its
   room's front edge, over the room's own front, and is never wider than the step to the next room (--cell).
   Open (.on: a room of the lit route; .focus: the pointed room): each trait told with its icon, or ★ and the hero.
   Only the pointed room adds its name in chalk capitals.
   Folded (every other room): only the icons of the traits told (.told), small and dim, so the lit route's plates
   lead; a room with nothing told shows no plate. Where rooms are too small for names (.tight: a phone) every plate
   stays folded but the pointed room's. */
.board-labels { position: fixed; pointer-events: none; overflow: hidden; z-index: 1; }
.nameplate {
  --size: clamp(9px, calc(var(--cell, 96px) * .095), 12px);
  position: absolute; transform: translate(-50%, calc(var(--size) * -1.5)); display: grid; justify-items: center; gap: .3em;
  width: max-content; max-width: var(--cell, 96px); padding: .35em .7em .3em; border-radius: 4px; text-align: center;
  font: 700 var(--size)/1.15 var(--serif); color: var(--chalk);
  background: rgba(9, 8, 7, .72); box-shadow: 0 0 .5em .25em rgba(9, 8, 7, .72);
  opacity: 0; transition: opacity 160ms;
}
.nameplate b { letter-spacing: .09em; text-transform: uppercase; text-wrap: balance; }
.nameplate:not(.focus) > b { display: none; }
.nameplate.on:not(.focus):not(:has(.known)) { opacity: 0; }
.nameplate .known { display: flex; flex-wrap: wrap; justify-content: center; gap: .3em .7em; font: 400 1.15em/1 var(--serif); }
.nameplate .known span { display: flex; align-items: center; gap: .3em; white-space: nowrap; }
.nameplate .known i { font-style: normal; }
.nameplate .trait { width: 1.35em; height: 1.35em; }
.nameplate .known .new { animation: told 300ms var(--spring) both; }   /* a trait told just now pops in */
@keyframes told { from { transform: scale(.4); opacity: 0; } }
.nameplate.on, .nameplate.focus { opacity: 1; }
.nameplate.focus { z-index: 1; }
.tight .nameplate { --size: 10px; max-width: 132px; }
/* folded: no name, no words, a smaller patch */
:is(.nameplate:not(.on, .focus), .tight .nameplate:not(.focus)) :is(b, i) { display: none; }
:is(.nameplate:not(.on, .focus), .tight .nameplate:not(.focus)) { padding: .22em .4em; gap: 0; background: rgba(9, 8, 7, .5); box-shadow: 0 0 .4em .15em rgba(9, 8, 7, .5); }
:is(.nameplate:not(.on, .focus), .tight .nameplate:not(.focus)) .known { gap: .3em; }
:is(.nameplate:not(.on, .focus), .tight .nameplate:not(.focus)).told { opacity: .82; }
.tight .nameplate.on:not(.focus):not(.told) { opacity: 0; }
#hand.playing ~ .board-labels .nameplate { opacity: 0; }   /* during a descent the party and their words have the board */

/* ---- ui/hand.js: the party (#party: its slots and the action), the trait coins and the hand of hero cards (.cards) ----
   The action is the one button of the map phase: paper when a press sends the party down, an outline while there is
   nothing to send yet (.choose) and for the lesser things it does (.next, .skip). On a route's last descent (.force)
   it is ringed in red and names what is at risk, in one small line. */
#party { grid-area: party; min-width: 0; display: flex; justify-content: flex-end; padding: 6px 12px calc(10px + env(safe-area-inset-bottom)) 6px; }
.btn.action { flex: 1 1 auto; max-width: 340px; min-height: 52px; padding: 6px 12px; flex-direction: column; gap: 4px;
  font: 700 18px/1.1 var(--serif); letter-spacing: .03em; }
.btn.action .says { display: flex; align-items: center; gap: 8px; }
.btn.action .icon { width: 17px; height: 17px; stroke-width: 6; }
.btn.action small { display: flex; align-items: center; gap: 5px; font: 700 10.5px/1 var(--serif); letter-spacing: .14em; text-transform: uppercase; }
.btn.action small .icon { width: 12px; height: 12px; fill: var(--danger); color: var(--danger); filter: none; }
.btn.action.force { box-shadow: 0 0 0 2px var(--danger), var(--lift); }
.btn.action.choose, .btn.action.next, .btn.action.skip { font-size: 16px; }
.btn.action.lit { animation: lit 360ms var(--spring); }   /* the fourth hero joined: the action lights (hand.js) */
@keyframes lit { from { transform: translateY(5px) scale(.985); filter: brightness(1.3); } }
/* The slots: four heroes standing on the table as they are, with no card under them (the cards are in the hand); an
   empty slot is a chalk outline of somebody still to come. They show only where the window is wide: elsewhere the
   raised cards show the party (P3). */
.slots { display: none; }
.slot { position: relative; display: grid; align-items: end; justify-items: center; min-width: 0; aspect-ratio: 1.6 / 1.8; padding: 0; border: 0;
  background: none; color: var(--chalk-faint); font: inherit; }
.slot .bust { width: 100%; }
.slot .icon { width: 84%; height: auto; aspect-ratio: 1; stroke-width: 2; stroke-dasharray: 3.5 5.5; opacity: .8;
  mask-image: linear-gradient(#000 55%, transparent 96%); }
.slot.full { transition: transform 220ms var(--spring), filter 160ms; }
.slot.full:is(button) { cursor: pointer; }             /* during playback the party cannot change (hand.js) */
.slot.full:is(button):hover { transform: translateY(-3px); filter: brightness(1.12); }
.slot.full:is(button):active { transform: translateY(2px); transition-duration: var(--press); }
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {   /* four slots across the console */
  #party { align-self: end; flex-direction: column; justify-content: flex-start; padding: 10px var(--console-right) 34px var(--console-left); }
  .slots { display: grid; grid-template-columns: repeat(4, minmax(0, 78px)); justify-content: space-between; padding: 0 6px; }
  .btn.action { flex: none; max-width: none; min-height: 54px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #party { padding: 4px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) 6px; }
  .btn.action { min-height: 48px; padding: 4px 8px; font-size: 16px; }
  .btn.action.choose, .btn.action.next, .btn.action.skip { font-size: 15px; }
}

/* The trait coins: seven, which highlight the heroes of a trait. Beside the hand (tall) they lie in two columns, four
   and three, the second set half a coin lower and closer in, like coins pushed together on a table, so none is left
   over; down the rail beside the dungeon (wide) they are a column, and over the hand (short) a row. */
.trait-coins { grid-area: traits; display: grid; grid-template-columns: repeat(2, 44px); align-content: center; gap: 4px 0;
  margin-right: -6px; flex: none; }
.trait-coins .trait-coin:nth-child(even) { top: 24px; left: -6px; }
.trait-coin { border-radius: 50%; }
.trait-coin .trait { width: 26px; height: 26px; }
#hand.playing .trait-coins { opacity: .25; pointer-events: none; }
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {
  .trait-coins { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin: 0; padding: 16px 0 22px 18px; }
  .trait-coins .trait-coin:nth-child(even) { top: 0; left: 0; }
}
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) and (max-height: 569px) {
  /* a wide window that is low: the rail closes up, so that its last coin stays in the window, and the console's
     first line rises with the rail's first button */
  body { --top: 12px; }
  .hud-buttons { gap: 6px; padding: 12px 0 10px 18px; }
  .hud-buttons .btn.round { width: 44px; height: 44px; }
  .trait-coins { gap: 2px; padding: 8px 0 8px 18px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .trait-coins { display: flex; justify-content: space-between; gap: 2px; margin: 0; padding: 2px calc(10px + env(safe-area-inset-right)) 0 8px; }
  .trait-coins .trait-coin { flex: 0 1 44px; width: auto; min-width: 0; }   /* a narrow console: the coins give a little */
  .trait-coins .trait-coin:nth-child(even) { top: 0; left: 0; }
}

/* The hand. On a touch screen every card is in sight and nothing scrolls: two rows of as many columns as the roster
   needs, each card as large as the window allows and never larger. A phone held upright fills the room the trait coins
   leave instead: two rows, or three rows of four once the roster outgrows them, as high as the coins stand. Otherwise,
   where there is room, the hand is held (hand.js lays it out where --held is 1): a fan, as cards are held, each
   overlapping the last and parting around the card under the mouse. The cards grow with the window (--u is one pixel
   of a 196 px card), and the box is as wide as the fan. */
.cards {
  --cols: 4; --rows: 2; --card-h: clamp(62px, 12dvh, 140px);
  grid-area: hand; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, calc(var(--card-h) * .68)));
  grid-auto-rows: var(--card-h); gap: 8px 6px; justify-content: center; min-width: 0;
}
.cards:has(> :nth-child(9)) { --cols: 5; }
.cards:has(> :nth-child(11)) { --cols: 6; }
@media (max-width: 599px) and (orientation: portrait) {
  .cards { flex: 1 1 0; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); grid-template-rows: repeat(var(--rows), minmax(0, 1fr)); }
  .cards:has(> :nth-child(11)) { --cols: 4; --rows: 3; }
}
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {
  .cards { --card-h: clamp(88px, 15dvh, 130px); align-self: end; padding: 14px 36px 18px; }
}
@media (orientation: landscape) and (max-height: 500px) {   /* the rows share the console's height */
  .cards { grid-template-columns: repeat(var(--cols), minmax(0, 64px)); grid-template-rows: repeat(2, minmax(0, 1fr));
    min-height: 0; gap: 6px; padding: 8px calc(10px + env(safe-area-inset-right)) 0 8px; }
}
@media (not (pointer: coarse)) and (min-width: 600px) and ((orientation: portrait) or (min-height: 501px)) {
  .cards { --held: 1; --card-h: clamp(150px, 21dvh, 300px); --u: calc(var(--card-h) / 196); position: relative; display: block;
    justify-self: center; align-self: end; flex: 0 1 auto; height: calc(var(--card-h) + 56px); max-width: calc(100% - 72px);
    padding: 0; margin: 4px 0 10px; }
}

/* A hero card: a little tarot card of the guild. A spine on its left (the trait icons, then the name written upward)
   stays in sight however the hand overlaps, like the corner of a playing card; the portrait fills the rest. On a card
   too narrow for both (a phone's), the spine keeps the name, the full height of the card, and the trait icons become
   the portrait's corner index; on one too short for the name to stand (three rows on a phone), the name runs along its
   foot and the portrait shows the face. */
.card.hero {
  --x: 0px; --shift: 0px; --rot: 0deg; --arc: 0px; --lift: 0px; --scale: 1; --tx: 0deg; --ty: 0deg;
  container-type: size;
  position: relative; display: grid; grid-template-columns: 12px minmax(0, 1fr); gap: 2px; min-width: 0; padding: 4px;
  border: 0; border-radius: 6px; font: inherit; color: var(--ink); cursor: pointer; text-align: left;
  background: var(--paper) var(--grain); box-shadow: var(--lift);
  transform: translateY(calc(var(--arc) + var(--lift)));
  transition: transform 300ms var(--spring), box-shadow 200ms, opacity 160ms, filter 200ms;
}
.card.hero::before { content: ""; position: absolute; inset: 3px; border: 1.5px solid var(--ink); border-radius: 4px; filter: url(#pen); pointer-events: none; }
.card.hero .spine { display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 0; padding: 2px 0; }
.card.hero .traits { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.card.hero .trait { width: 11px; height: 11px; }
.card.hero .trait.big { width: 12px; height: 12px; }
.card.hero .name { writing-mode: vertical-rl; transform: rotate(180deg); min-height: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 3px 1px; border-radius: 2px; font: 700 9px/1 var(--serif); letter-spacing: .03em; text-transform: uppercase; }
.card.hero .star { margin-top: auto; font-size: 11px; line-height: 1; }
.card.hero .art { display: block; min-height: 0; overflow: hidden; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(29, 27, 25, .4); }
.card.hero .portrait { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 0; mix-blend-mode: multiply; }
.card.hero:active:not(:disabled) { transition-duration: var(--press); }
.card.hero.in-party { --lift: -6px; box-shadow: 0 0 0 2px var(--chalk), 0 0 24px rgba(204, 197, 189, .18), 0 16px 28px rgba(0, 0, 0, .6); }
.card.hero.in-party .name { background: var(--ink); color: var(--paper); }
.card.hero .order { position: absolute; top: -8px; left: -8px; z-index: 1; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font: 700 12px/1 var(--serif); background: var(--ink); color: var(--paper); box-shadow: 0 0 0 2px var(--chalk); }
.card.hero.faded { opacity: .3; }
.card.hero:disabled { cursor: default; }
.card.hero.excluded .art, .card.hero.excluded .traits { opacity: .3; }
.card.hero .stamp { position: absolute; left: 58%; top: 45%; transform: translate(-50%, -50%) rotate(-12deg); padding: 5px 6px 4px; white-space: nowrap;
  font: 700 10px/1 var(--serif); letter-spacing: .12em; border: 2px solid var(--ink); background: var(--paper); filter: url(#pen); }
.shake { animation: shake 320ms ease-out; }
@keyframes shake { 20% { translate: -5px 0; } 40% { translate: 5px 0; } 60% { translate: -3px 0; } 80% { translate: 3px 0; } }
@container (max-width: 76px) {
  .card.hero .spine { display: contents; }
  .card.hero .name { grid-column: 1; grid-row: 1; align-self: stretch; text-align: center; font-size: 8px; letter-spacing: .02em; }
  .card.hero .art { grid-column: 2; grid-row: 1; }
  .card.hero .traits { grid-column: 2; grid-row: 1; z-index: 1; align-self: start; justify-self: start; gap: 2px; padding: 2px 3px 3px 1px;
    border-radius: 0 0 4px 0; background: var(--paper) var(--grain); }
  .card.hero .star { grid-column: 2; grid-row: 1; z-index: 1; align-self: end; justify-self: end; margin: 0; padding: 2px 2px 0 3px;
    border-radius: 4px 0 0 0; font-size: 10px; background: var(--paper) var(--grain); }
  .card.hero .order { display: none; }                 /* the slots are display only; the raised card says enough */
  .card.hero .stamp { left: 56%; padding: 3px 3px 2px; font-size: 7px; letter-spacing: .04em; border-width: 1.5px; }
}
@container (max-width: 76px) and (max-height: 74px) {
  .card.hero .art { grid-column: 1 / -1; margin-bottom: 11px; }
  .card.hero .portrait { object-position: 50% 4%; transform: scale(1.3); transform-origin: 50% 0; }
  .card.hero .name { grid-area: auto; position: absolute; left: 3px; right: 3px; bottom: 3px; padding: 2px 0 1px; writing-mode: horizontal-tb;
    transform: none; text-transform: none; letter-spacing: 0; }
  .card.hero .traits, .card.hero .star { grid-column: 1 / -1; }
  .card.hero .star { margin-bottom: 11px; }
}

/* The held hand: each card placed by --x, fanned by --rot and --arc; the card in focus rises, grows a little,
   straightens and tilts toward the pointer while the others part (--shift) and dim. A card's parts keep their size
   on a small card and grow with a large one. */
@media (not (pointer: coarse)) and (min-width: 600px) and ((orientation: portrait) or (min-height: 501px)) {
  .card.hero {
    position: absolute; left: 0; bottom: 14px; width: calc(var(--card-h) * .653); height: var(--card-h); transform-origin: 50% 100%;
    grid-template-columns: max(18px, calc(var(--u, 1px) * 18)) minmax(0, 1fr); gap: 4px; padding: max(7px, calc(var(--u, 1px) * 7));
    transform: translate(calc(var(--x) + var(--shift)), calc(var(--arc) + var(--lift)))
      perspective(800px) rotateX(var(--tx)) rotateY(var(--ty)) rotate(var(--rot)) scale(var(--scale));
  }
  .card.hero .spine { gap: max(6px, calc(var(--u, 1px) * 6)); }
  .card.hero .trait { width: max(14px, calc(var(--u, 1px) * 14)); height: max(14px, calc(var(--u, 1px) * 14)); }
  .card.hero .trait.big { width: max(17px, calc(var(--u, 1px) * 17)); height: max(17px, calc(var(--u, 1px) * 17)); }
  .card.hero .name { padding: 5px 2px; font-size: max(11px, calc(var(--u, 1px) * 11)); letter-spacing: .12em; }
  .card.hero .star { font-size: max(11px, calc(var(--u, 1px) * 11)); }
  .card.hero.in-party { --lift: -14px; }
  .card.hero .order { top: -10px; left: -10px; width: 26px; height: 26px; font-size: 14px; }
  .card.hero.focus { --lift: -28px; --rot: 0deg; --scale: 1.07; z-index: 30;
    box-shadow: 0 2px 0 rgba(0, 0, 0, .5), 0 28px 46px rgba(0, 0, 0, .65); }
  .card.hero.in-party.focus { --lift: -34px; box-shadow: 0 0 0 2px var(--chalk), 0 0 26px rgba(204, 197, 189, .2), 0 28px 46px rgba(0, 0, 0, .65); }
  .card.hero.focus:active:not(:disabled) { --lift: -23px; }
  /* The lamps hang over the dungeon, not the hand: a held card is lit at its head and falls into the table's dark toward
     its foot, so the hand does not outshine the board. A card in the party or under the pointer comes into the light. */
  .card.hero::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; mix-blend-mode: multiply;
    background: linear-gradient(rgba(16, 12, 9, 0) 30%, rgba(16, 12, 9, .34)); transition: opacity 200ms; }
  .card.hero.in-party::after, .card.hero.focus::after { opacity: .3; }
  .cards.parted .card.hero:not(.focus) { filter: brightness(.78); }
  .cards.settling .card.hero { transition: none; }     /* fresh cards take their places at once (hand.js settle) */
}

/* ---- ui/dom.js: a hero's picture, cut to a window round the face. dom.js says where the window lies in the portrait:
   --x and --y are its corner and --zoom the portrait's height, all in windows. A coin is the face alone on a round of
   paper (in the notes, a speech bubble); a bust is the hero from the hat to the chest with nothing behind
   (a slot of the party), who sinks into the table's dark at the foot. ---- */
.coin { position: relative; display: inline-block; flex: none; width: 24px; height: 24px; border-radius: 50%; overflow: hidden;
  background: var(--paper) var(--grain); box-shadow: 0 0 0 1.5px var(--ink), 0 0 0 2.5px var(--chalk-faint); }
.bust { position: relative; display: block; overflow: hidden;
  mask-image: linear-gradient(#000 60%, transparent 98%), linear-gradient(90deg, transparent, #000 9%, #000 91%, transparent);
  mask-composite: intersect; }
.coin .portrait, .bust .portrait { position: absolute; left: calc(var(--x) * -100%); top: calc(var(--y) * -100%);
  height: calc(var(--zoom) * 100%); width: auto; max-width: none; }
.coin .portrait { mix-blend-mode: multiply; }

/* ---- ui/notes.js: the notes on the selected route: a drawer from the right (Notes), or the middle of the console (wide) ----
   The strip (.strip) is the route: its stair, then its four rooms in walk order, each with its symbol (or its hero's
   coin), what is known of its key right under that (as it lies beside the coin on the board), and its name as the
   caption. Under it each descent (.descent) is a trail (.trail: the party's coins under the stair, then a line through
   the rooms it passed, .walk) and what was said on it (.said). The strip and the trails share their columns (--who for
   the party, then four rooms), so a trail's marks stand under their rooms. Only the descents scroll; the strip keeps
   the same gutter, so the columns stay true. A room's name is never broken: the longest word fits the narrowest column. */
#notes {
  --who: 68px; --hang: 20px;
  position: fixed; top: 0; right: 0; bottom: 0; width: min(88%, 380px); z-index: 15; display: flex; flex-direction: column;
  padding: calc(16px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) 24px;
  background: var(--hatched); box-shadow: -20px 0 40px rgba(0, 0, 0, .6);
  transform: translateX(105%); visibility: hidden; transition: transform 220ms ease-out, visibility 0s 220ms;
}
body.notes-open #notes { transform: none; visibility: visible; transition: transform 220ms ease-out; }
.notes-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 14px; padding-right: 6px; }
.notes-head h2 { font: 700 19px/1.2 var(--serif); letter-spacing: .04em; }
.strip, .trail { display: grid; grid-template-columns: var(--who) repeat(4, minmax(0, 1fr)); }
.strip, .descents { overflow: hidden auto; scrollbar-gutter: stable; }
.strip { flex: none; align-items: start; padding: 3px 0 8px; }
.stair { position: relative; justify-self: start; display: grid; place-items: center; width: 24px; height: 24px; margin: 1px 0 0 19px;
  color: var(--chalk-dim); }
.stair .icon { width: 20px; height: 20px; stroke-width: 5; }
.room { position: relative; display: grid; justify-items: center; gap: 4px; min-width: 0; text-align: center; }
.room .symbol, .room .coin { width: 26px; height: 26px; }
.room .symbol { color: var(--chalk); stroke-width: 5; }
.room b { order: 1; font: 400 10px/1.15 var(--serif); color: var(--chalk-dim); }   /* the caption comes last */
.known { display: flex; align-items: center; justify-content: center; gap: 4px; height: 18px; }
.known .trait { width: 17px; height: 17px; }
.known i { font: 700 11.5px/1 var(--serif); font-style: normal; color: var(--chalk); }
.known i.unknown { font-size: 15px; color: var(--chalk-faint); }
/* the route itself: a faint line from the stair through the rooms, broken where a symbol lies */
.stair::after, .room::before { content: ""; position: absolute; top: 13px; height: 1px; opacity: .5; pointer-events: none; }
.stair::after { left: calc(100% + 5px); width: calc(var(--who) - 48px); background: var(--chalk-faint); top: 12px; }
.room::before { left: 0; right: 0; --dash: linear-gradient(var(--chalk-faint), var(--chalk-faint));
  background: var(--dash) left / calc(50% - 19px) 1px no-repeat, var(--dash) right / calc(50% - 19px) 1px no-repeat; }
.room:last-of-type::before { background: var(--dash) left / calc(50% - 19px) 1px no-repeat; }
/* The descents. Each one's number hangs in the margin (--hang), so its trail and its words keep the strip's columns.
   Each lies on a wash of chalk dust, strongest at its number and gone before the far edge: it has no edge there for
   the words to run into, and its other edges wobble with the pen. */
.descents { flex: 1 1 auto; min-height: 0; display: grid; align-content: start; gap: 8px; margin-left: calc(-1 * var(--hang)); padding: 2px 0 12px; }
.descent { position: relative; isolation: isolate; display: grid; grid-template-columns: var(--hang) minmax(0, 1fr); row-gap: 5px; padding: 8px 0 10px; }
.descent::before { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: 7px; filter: url(#pen);
  background: linear-gradient(90deg, rgba(204, 197, 189, .075), rgba(204, 197, 189, .035) 55%, rgba(204, 197, 189, 0) 96%); }
.descent > * { grid-column: 2; }
.descent > .nth { grid-column: 1; grid-row: 1; padding-left: 7px; font: 700 12px/24px var(--serif); color: var(--chalk-dim); }
.trail { align-items: center; min-height: 24px; }
.who { display: flex; }
.who .coin { width: 20px; height: 20px; box-shadow: 0 0 0 1.5px var(--ink); }   /* no chalk ring: the coins are small and lie close */
.who .coin + .coin { margin-left: -6px; }
.who .coin.left { filter: grayscale(1) brightness(.42); }      /* sent home before the descent: not one who walked */
.who:has(.coin:nth-child(5)) .coin + .coin { margin-left: -9px; }   /* a hero joined: five coins close up */
/* the walk: the line runs to the middle of each room reached and on through a room passed (a dot); it ends in a cross
   where the party stopped, and breaks round the red −1 of a room forced. A solved route's line runs off the end. */
.walk { grid-column: 2 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); height: 22px; color: var(--chalk-dim);
  --line: linear-gradient(currentColor, currentColor); filter: url(#pen); }
.walk i { display: grid; place-items: center; }
.walk .passed { background: var(--line) center / 100% 1.5px no-repeat; }
.walk .passed::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--chalk); }
.walk .stopped { background: var(--line) left / calc(50% - 10px) 1.5px no-repeat; }
.walk .stopped .icon { width: 13px; height: 13px; color: var(--chalk); stroke-width: 9; filter: none; }
.walk .forced { background: var(--line) left / calc(50% - 12px) 1.5px no-repeat, var(--line) right / calc(50% - 12px) 1.5px no-repeat; }
.walk .forced b { font: 700 12px/1 var(--serif); font-style: normal; color: var(--danger); }
/* One voice, two tones: the telling (what happened, who said) is dim, and the heroes' own words are bright. */
.said { font-size: 13.5px; line-height: 1.42; text-wrap: pretty; }
.said .by, .said.event { color: var(--chalk-dim); }
.notes-empty { margin-left: var(--hang); font-size: 13.5px; color: var(--chalk-faint); }
@media (max-width: 359px) { .room b { font-size: 9px; } }   /* a small phone's drawer */
body:has(#hand.playing) .notes-empty { visibility: hidden; }   /* the first descent is on its way: the line would be false */
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {
  #notes { grid-area: notes; position: static; width: auto; min-height: 0; padding: 20px calc(var(--console-right) - 10px) 0 var(--console-left);
    background: none; box-shadow: none; transform: none; visibility: visible; transition: none; }
  .notes-head { display: none; }
}

/* first paint: from here */
/* ---- screens (P9): the title and the question before starting over. No sheet: chalk words on a pool of shade over
   the board, and one paper button, as the action is. Both overlays cover the window. ---- */
#talk, #overlay { position: fixed; inset: 0; z-index: 20; }
.scrim {
  position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden auto; overscroll-behavior: contain;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
  background: rgba(3, 3, 3, .94);
}
.screen { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(100%, 500px); text-align: center;
  text-shadow: 0 0 4px #030303, 0 0 16px #030303; }
.screen h1 { font: 700 56px/1 var(--serif); letter-spacing: .16em; margin: 0 -.16em 6px 0; }
.screen p { max-width: 34ch; text-wrap: balance; }
.screen .blurb { max-width: 46ch; font-size: 17px; text-wrap: balance; }
.screen.title { width: min(100%, 1060px); }
/* P9: four small examples teach the rules with the same portraits and chalk as the table. All are present at first paint. */
.howto { list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 28px;
  width: 100%; margin: 10px 0 2px; padding: 0; text-align: left; }
.howto li { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.title-picture { width: min(100%, 160px); flex: none; }
.title-picture svg { display: block; width: 100%; }
.title-leaving { opacity: .4; }
.title-ink { fill: none; stroke: var(--chalk); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; filter: url(#pen); }
.title-picture text { fill: var(--chalk); font: 700 20px var(--serif); }
.title-faint { stroke: var(--chalk-faint); }
.title-danger { stroke: var(--danger); }
.title-picture text.title-danger { fill: var(--danger); stroke: none; }
.title-rule { width: 100%; }
.title .title-rule h2 { font: 700 clamp(16px, 1.3vw, 18px)/1.2 var(--serif); letter-spacing: 0; margin: 0 0 4px; }
.title-rule p, .title-goal p { max-width: none; font-size: 14px; line-height: 1.3; color: var(--chalk-dim); }
.title-goal strong { display: block; margin-bottom: 4px; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 10px; }
.actions .btn { min-width: 160px; min-height: 52px; padding: 8px 26px; font-size: 18px; text-shadow: none; }
.actions .btn.paper { min-width: 210px; }
/* A short window (a small phone, a phone on its side): the words close up so that nothing scrolls. */
@media (max-height: 640px) {
  .screen { gap: 10px; }
  .screen h1 { font-size: 42px; margin-bottom: 0; }
  .actions { margin-top: 4px; }
  .actions .btn { min-height: 48px; }
}
@media (max-width: 959px) and (min-height: 501px) {
  .howto { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 540px) and (min-height: 501px) {
  .scrim { padding: calc(14px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom)); }
  .screen.title { gap: 10px; }
  .screen.title h1 { font-size: 38px; }
  .screen.title .blurb { font-size: 14px; max-width: 36ch; }
  .howto { grid-template-columns: minmax(0, 1fr); gap: 13px; margin: 4px 0 0; }
  .howto li { flex-direction: row; gap: 14px; }
  .title-picture { width: 84px; }
  .title-rule p { font-size: 13px; }
  .title-goal p { font-size: 12px; }
  .title .actions { margin-top: 2px; }
  .title .actions .btn { min-width: 150px; min-height: 44px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .scrim { padding: calc(10px + env(safe-area-inset-top)) 16px calc(10px + env(safe-area-inset-bottom)); }
  .screen.title { display: grid; grid-template-columns: 180px minmax(0, 1fr); column-gap: 22px; row-gap: 8px;
    justify-items: center; }
  .screen.title > * { grid-column: 1; }
  .screen.title h1 { font-size: 30px; }
  .screen.title .blurb { font-size: 13px; }
  .screen.title .howto { grid-column: 2; grid-row: 1 / span 6; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; }
  .howto li { gap: 4px; }
  .title-picture { width: 96px; }
  .title .title-rule h2 { font-size: 14px; }
  .title-rule p, .title-goal { font-size: 12px; }
  .title-goal p { font-size: inherit; }
  .title .actions { width: 100%; gap: 4px; margin-top: 0; }
  .title .actions .btn { flex: 1; min-width: 80px; min-height: 44px; font-size: 16px; padding: 5px 8px; }
}

/* The title card is on the page before the game is (index.html). Its buttons are not shown until the game has said
   which ones a run kept in this browser needs (.saved); a button pressed before the game was up stays down until it
   is (.pressed). */
.saved .title .actions { visibility: hidden; }
.pressed .title .btn.paper { transform: translateY(3px); box-shadow: 0 0 0 rgba(0, 0, 0, .55), 0 3px 8px rgba(0, 0, 0, .4); opacity: .72; }
/* first paint: to here */

/* ---- ui/book.js: the Guild Book: a small stitched book; two pages to a spread on a wide window, one on a phone ----
   The chapters flow through CSS columns (one column, one page) and a spread slides into view (book.js). */
#book { position: fixed; inset: 0; z-index: 25; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: calc(66px + env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(8, 8, 8, .86);
  backdrop-filter: blur(3px); }
.book { position: relative; width: min(960px, 100%); height: min(620px, calc(100dvh - 150px)); padding: 14px; border-radius: 10px 12px 12px 10px;
  background: var(--hatched); box-shadow: inset 0 0 0 1px rgba(204, 197, 189, .07), 0 30px 70px rgba(0, 0, 0, .75);
  animation: book-in 280ms var(--spring) both; }
.book::before { content: ""; position: absolute; inset: 6px; border: 1px dashed rgba(204, 197, 189, .18); border-radius: 7px; pointer-events: none; }
@keyframes book-in { from { transform: translateY(18px) scale(.98); opacity: 0; } }
.pages {
  position: relative; height: 100%; overflow: hidden; border-radius: 3px; color: var(--ink); touch-action: pan-y;
  background:
    linear-gradient(to right, rgba(0, 0, 0, .16), transparent 3%, transparent 45%, rgba(0, 0, 0, .2) 50%, transparent 55%, transparent 97%, rgba(0, 0, 0, .16)),
    var(--paper) var(--grain);
  box-shadow: 0 1px 0 #b6aca0, 0 2px 0 #756f66, 0 3px 0 #b6aca0, 0 4px 0 #756f66, 0 5px 0 #aba297;   /* the pages beneath */
}
.flow { position: absolute; inset: 54px 48px 50px; column-count: 2; column-gap: 96px; column-fill: auto;
  transition: transform 360ms cubic-bezier(.25, .8, .25, 1); }
.flow .chapter { break-before: column; margin: 0 0 16px; font: 700 28px/1.1 var(--serif); }
.flow .chapter:first-child { break-before: auto; }
.flow .chapter small { display: block; margin-bottom: 8px; font-size: 12px; letter-spacing: .24em; color: var(--ink-dim); }
.flow .chapter::after { content: ""; display: block; width: 56px; margin-top: 12px; border-top: 1.5px solid var(--ink); filter: url(#pen); }
.flow p { margin: 0 0 12px; font-size: 15px; line-height: 1.55; }
.flow p.lead::first-letter { float: left; margin: 5px 7px 0 0; font: 700 3.3em/.8 var(--serif); }
.flow .entry { break-inside: avoid; margin: 0 0 12px; padding-bottom: 10px; border-bottom: 1px dashed rgba(29, 27, 25, .28); }
.flow .entry p { margin: 4px 0 0; font-size: 14px; line-height: 1.45; color: var(--ink-dim); }
.entry-head { display: flex; align-items: center; gap: 8px; }
.entry-head b { font-size: 15px; }
.entry-head .trait { width: 24px; height: 24px; }
.entry-mark { margin-left: auto; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; text-align: right; color: var(--ink-dim); }
.running, .folio { position: absolute; font: 700 10px/1 var(--serif); letter-spacing: .22em; text-transform: uppercase; color: var(--ink-dim); }
.running { top: 22px; }
.folio { bottom: 20px; font-size: 12px; letter-spacing: .1em; }
.running.left, .folio.left { left: 48px; }
.running.right, .folio.right { right: 48px; }
.ribbons { position: absolute; left: 40px; bottom: 100%; display: flex; gap: 6px; }
.ribbon { min-height: 44px; padding: 12px 14px 10px; border: 0; border-radius: 6px 6px 0 0; cursor: pointer;
  font: 700 12px/1 var(--serif); letter-spacing: .12em; text-transform: uppercase; color: var(--ink);
  background: #6e6355 var(--grain); box-shadow: inset 0 -9px 10px -8px rgba(0, 0, 0, .4);
  transform: translateY(8px); transition: transform 220ms var(--spring), background-color 160ms; }
.ribbon small { margin-right: 6px; font-size: 10px; opacity: .6; }
.ribbon:hover { transform: translateY(4px); }
.ribbon[aria-current="true"] { background-color: #9b8c79; transform: translateY(3px); }
.ribbon:active { transform: translateY(7px); transition-duration: var(--press); }
.book-close { position: absolute; right: 0; bottom: calc(100% + 6px); }
.book-foot { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--chalk-dim); }
.page-count { min-width: 120px; text-align: center; }
@media (max-width: 760px) {
  .book { height: min(680px, calc(100dvh - 146px)); padding: 9px; }
  .pages { background: linear-gradient(to right, rgba(0, 0, 0, .14), transparent 5%, transparent 95%, rgba(0, 0, 0, .1)), var(--paper) var(--grain); }
  .flow { inset: 46px 24px 44px; column-count: 1; column-gap: 48px; }
  .running.left, .folio.right { display: none; }
  .running.right { left: 24px; right: auto; }
  .folio.left { left: 50%; transform: translateX(-50%); }
  .ribbons { left: 8px; }
  .ribbon { padding-inline: 12px; }
  .ribbon small { display: none; }
}
@media (orientation: landscape) and (max-height: 500px) {   /* a phone on its side: the book takes the height, its foot beside it */
  #book { flex-direction: row; padding: calc(56px + env(safe-area-inset-top)) 12px 10px; }
  .book { height: calc(100dvh - 70px); }
  .book-foot { flex-direction: column; gap: 6px; }
  .page-count { min-width: 0; }
  .flow { inset: 38px 40px 36px; }
  .running { top: 14px; }
  .folio { bottom: 12px; }
}

/* ---- ui/talk.js: a clue or a hint, told the Hades way with no box: the speaker's portrait stands in the dark, fading
   at its foot as a bust does, and their name and words are chalk under it, on a shade that rises from the foot. ---- */
body.talking #board { opacity: .6; }
.talk-scrim { position: absolute; inset: 0; display: flex; justify-content: center;
  background: linear-gradient(rgba(3, 3, 3, .1) 22%, rgba(3, 3, 3, .82) 62%, rgba(3, 3, 3, .95)); }
.talk-stage { position: relative; width: min(100%, 820px); height: 100%; cursor: pointer; }
.talk-portrait { position: absolute; bottom: calc(12vh + 44px); height: 42vh; display: flex; animation: slide-in 320ms ease-out both; pointer-events: none;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, .7)); mask-image: linear-gradient(#000 72%, transparent 99%); }
.talk-portrait.left { left: 12px; --from: -60px; }
.talk-portrait.right { right: 12px; --from: 60px; }
.talk-portrait .portrait { height: 100%; width: auto; max-width: 70vw; }
@keyframes slide-in { from { transform: translateX(var(--from)); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }
.talk-box { position: absolute; left: 24px; right: 24px; bottom: calc(26px + env(safe-area-inset-bottom)); min-height: 12vh; padding-right: 26px;
  color: var(--chalk); text-shadow: 0 0 4px #030303, 0 0 14px #030303; }
.talk-box::before { content: ""; position: absolute; inset: -46px -70px -30px; z-index: -1; pointer-events: none;
  background: radial-gradient(closest-side, rgba(3, 3, 3, .82) 55%, rgba(3, 3, 3, 0)); }
.talk-box .speaker { margin-bottom: 10px; font: 700 12px/1 var(--serif); letter-spacing: .22em; text-transform: uppercase; color: var(--chalk-dim); }
.talk-box[data-side="right"] .speaker { text-align: right; }
.talk-box .line { font: 21px/1.45 var(--serif); text-wrap: pretty; }
.rest { visibility: hidden; }
.caret { position: absolute; right: 0; bottom: 3px; visibility: hidden; }
.talk-box.done .caret { visibility: visible; animation: bob 800ms ease-in-out infinite; }
@keyframes bob { 50% { transform: translateX(4px); } }
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {
  .talk-scrim { padding: 0 clamp(352px, 27vw, 420px) 0 80px; }      /* the console stays in sight */
  .talk-portrait { height: 54vh; bottom: calc(12vh + 52px); }
  .talk-box { left: 36px; right: 36px; bottom: calc(40px + env(safe-area-inset-bottom)); }
  .talk-box .line { font-size: 23px; }
}
@media (orientation: landscape) and (max-height: 500px) {   /* the portrait stands beside the words, not over them */
  .talk-scrim { background: linear-gradient(rgba(3, 3, 3, .2), rgba(3, 3, 3, .88) 55%, rgba(3, 3, 3, .97)); }
  .talk-portrait { height: 78vh; bottom: 0; }
  .talk-portrait.left { left: 0; }
  .talk-portrait.right { right: 0; }
  .talk-box { left: 26%; right: 26%; bottom: calc(18px + env(safe-area-inset-bottom)); min-height: 0; }
  .talk-box .line { font-size: 18px; }
}
/* Speech bubbles on the board (talk.js chat): paper, inked round, the tail on the speaker's head. A hero about to join
   speaks from beside the party, in a dashed bubble. */
.bubbles { position: absolute; inset: 0; cursor: pointer; }
.bubble {
  position: fixed; left: 50%; top: 50%; width: max-content; max-width: min(300px, calc(100vw - 20px)); padding: 9px 15px 12px;
  border-radius: 14px; background: var(--paper) var(--grain); color: var(--ink); box-shadow: 0 12px 28px rgba(0, 0, 0, .55);
  transform: translate(-50%, -100%); transform-origin: calc(50% + var(--tail, 0px)) calc(100% + 10px);
}
.bubble::before { content: ""; position: absolute; inset: 3px; border: 1.5px solid var(--ink); border-radius: 11px; filter: url(#pen); pointer-events: none; }
.bubble::after { content: ""; position: absolute; left: calc(50% + var(--tail, 0px)); bottom: -8px; width: 16px; height: 16px;
  background: var(--paper) var(--grain); border: solid var(--ink); border-width: 0 1.5px 1.5px 0; transform: translateX(-50%) rotate(45deg); }
.bubble.clamped::after { display: none; }
.bubble.offstage::before { border-style: dashed; }
.bubble .who { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; font: 700 11px/1 var(--serif); letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-dim); }
.bubble .who .coin { width: 24px; height: 24px; }
.bubble .line { font: 16px/1.38 var(--serif); padding-right: 6px; }
.bubble .caret { right: 11px; bottom: 6px; font-size: 11px; }
.bubble.done .caret { visibility: visible; animation: bob 800ms ease-in-out infinite; }
.bubble.pop { animation: pop 300ms var(--spring) both; }
@keyframes pop { from { transform: translate(-50%, -100%) scale(.6); opacity: 0; } }
@media (max-width: 600px) { .bubble { max-width: min(250px, calc(100vw - 20px)); } .bubble .line { font-size: 15px; } }

/* ---- toast (P9) and the debrief's line (P5): chalk just above the hand on a dark halo (wide: the line over the slots) */
#toast, .ask-line {
  position: fixed; left: var(--stage-x, 50%); top: var(--stage-bottom, 70%); z-index: 30; width: max-content;
  max-width: min(calc(var(--stage-w, 100vw) - 24px), 32em); transform: translate(-50%, calc(-100% - 14px));
  text-align: center; text-wrap: balance; pointer-events: none; font: 700 16px/1.4 var(--serif); letter-spacing: .02em; color: var(--chalk);
  text-shadow: 0 0 3px #030303, 0 0 10px #030303, 0 0 22px #030303;
}
#toast.in { animation: write 560ms cubic-bezier(.45, .05, .3, 1) backwards; mask-image: linear-gradient(90deg, #000 45%, transparent 55%);
  mask-size: 250% 100%; mask-position: 0 0; }
#toast.out { opacity: 0; filter: blur(3px); transition: opacity 420ms ease-in, filter 420ms ease-in; }
.ask-line .trait { width: 22px; height: 22px; margin: 0 8px 0 0; vertical-align: -5px; filter: drop-shadow(0 0 3px #030303); }
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {
  .ask-line { position: static; z-index: auto; display: grid; place-items: center; width: auto; max-width: none; min-height: 46px; margin: 0 0 6px;
    transform: none; font-size: 15px; }
}

/* ---- the debrief (P5): a hero is asked on their own slot or card; the one chosen stands forward ---- */
.slot.askable { cursor: pointer; transition: transform 220ms var(--spring), filter 160ms; }
.slot .trait.clue { position: absolute; left: 50%; bottom: -6px; width: 24px; height: 24px; transform: translateX(-50%);
  filter: drop-shadow(0 0 2px #030303) drop-shadow(0 0 6px #030303); }
.slot.askable.chosen { transform: translateY(-7px); filter: brightness(1.15); }
.slots:has(.chosen) .slot.askable:not(.chosen) { filter: brightness(.6); }
.slot.gone { opacity: .2; }
.card.hero.askable { cursor: pointer; }
.card.hero.chosen { --lift: -12px; box-shadow: 0 0 0 2.5px var(--chalk), 0 0 30px rgba(204, 197, 189, .3), 0 18px 30px rgba(0, 0, 0, .6); }
.cards:has(.chosen) .card.hero.askable:not(.chosen) { filter: brightness(.68); }
.btn.action.ask { visibility: hidden; }
/* The last descent is held (hand.js): a red wash soaks the paper, peeks in under the mouse, drains if let go. */
.btn.action.force::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; background: var(--danger);
  mix-blend-mode: multiply; opacity: .5; filter: url(#pen); transform: scaleX(0); transform-origin: left; transition: transform 200ms ease-out; }
.btn.action.force:hover::after { transform: scaleX(.12); transition: transform 300ms ease-out; }
.btn.action.force.holding::after { transform: none; transition: transform 800ms linear; }
.ask-line small { display: block; margin-top: 4px; font: 400 13px/1.3 var(--serif); color: var(--chalk-dim); }
@media (not (pointer: coarse)) and (min-width: 600px) and ((orientation: portrait) or (min-height: 501px)) {
  .card.hero.chosen { --lift: -26px; }
}

.screen h2 { font: 700 30px/1.15 var(--serif); letter-spacing: .14em; margin-right: -.14em; text-wrap: balance; }   /* the restart question */
/* ---- a moment comes in beat by beat (--beat): its heading written, then each line in turn (--n) ---- */
#moment :is(.head, .foot) > * { animation: rise 440ms ease-out backwards; animation-delay: calc(var(--beat) * (2.6 + var(--n, 0) * 1.1)); }
#moment .head > h2 { animation: write 620ms cubic-bezier(.45, .05, .3, 1) backwards; animation-delay: calc(var(--beat) * 1.2);
  mask-image: linear-gradient(90deg, #000 45%, transparent 55%); mask-size: 250% 100%; mask-position: 0 0; }
@keyframes shade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes write { from { mask-position: 100% 0; } }
#overlay.leaving { opacity: 0; transition: opacity 260ms ease-in; pointer-events: none; }

/* ---- the moments of a run (P9): the table's things step aside; a scene over the water, words left, the guild right ---- */
body.aside :is(#hud, #routes, #notes, #party, #hand, #shade) { animation: step-away 420ms ease forwards; pointer-events: none; }
body.returning :is(#hud, #routes, #notes, #party, #hand, #shade) { animation: step-back 520ms ease backwards; }
@keyframes step-away { to { opacity: 0; visibility: hidden; } }
@keyframes step-back { from { opacity: 0; } }
body:is(.aside, .under) .board-labels { opacity: 0; }
#moment { position: fixed; inset: 0; z-index: 18; display: grid; place-items: center; overflow: hidden auto; overscroll-behavior: contain;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  background: radial-gradient(ellipse 80% 70% at 50% 45%, rgba(3, 3, 3, .25), rgba(3, 3, 3, .72)); animation: shade 500ms ease-out backwards; }
#moment.leaving { opacity: 0; transition: opacity 280ms ease-in; }
#moment .scene { display: grid; grid-template-areas: "head" "guild" "foot"; gap: 24px; justify-items: start; width: 100%;
  text-shadow: 0 0 4px #030303, 0 0 16px #030303; }
#moment :is(.head, .foot) { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }
#moment .head { grid-area: head; }
#moment .foot { grid-area: foot; align-self: end; justify-self: stretch; }
#moment h2 { font: 700 clamp(34px, 11vw, 80px)/.95 var(--serif); letter-spacing: .1em; margin-right: -.1em; text-transform: uppercase; }
#moment h2 small { display: block; margin: 0 0 .55em .1em; font: 700 clamp(11px, 1vw, 15px)/1 var(--serif); letter-spacing: .34em; color: var(--chalk-dim); }
#moment p { max-width: 30ch; text-wrap: balance; }
#moment .foot .btn { align-self: stretch; min-height: 54px; font-size: 18px; text-shadow: none; }
#moment .guild { grid-area: guild; justify-self: center; display: grid; grid-template-columns: repeat(var(--narrow), var(--w)); gap: 8px;
  --w: clamp(48px, min(calc((100vw - 48px - (var(--narrow) - 1) * 8px) / var(--narrow)), calc((100dvh - 360px) / var(--narrow-rows) * .653 - 6px)), 140px); }
#moment .guild .card.hero { position: relative; left: auto; bottom: auto; width: var(--w); height: calc(var(--w) / .653); transform: none; transition: none;
  animation: rise 460ms ease-out backwards; animation-delay: calc(var(--beat) * 3 + var(--i, 0) * 30ms); }
#moment .guild .card.hero::after { display: none; }
#moment .guild .card.hero.joined { z-index: 2; animation: none; }
#moment.interlude .guild .card.hero:not(.joined) { animation: rise 460ms ease-out backwards, dim 600ms ease forwards;
  animation-delay: calc(var(--beat) * 3 + var(--i, 0) * 30ms), 900ms; }
@keyframes dim { to { filter: brightness(.62); } }
#moment .guild .card.hero.cheer { animation: rise 460ms ease-out backwards, cheer 640ms var(--spring); animation-delay: calc(var(--beat) * 3 + var(--i, 0) * 30ms),
  calc(var(--beat) * 17 + var(--i, 0) * 70ms); }
.card.hero .back { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; border-radius: inherit; background: var(--paper) var(--grain); opacity: 0; }
.card.hero .back::before { content: ""; position: absolute; inset: 3px; border: 1.5px solid var(--ink); border-radius: 4px; filter: url(#pen); }
.card.hero .back b { display: grid; place-items: center; width: 54%; aspect-ratio: 1; border-radius: 50%; font: 700 30cqw/1 var(--serif); color: var(--ink);
  box-shadow: 0 0 0 1.5px var(--ink), inset 0 0 0 3cqw var(--paper), inset 0 0 0 4.2cqw var(--ink); }
@keyframes cheer { 35% { translate: 0 -22px; } }
/* the foot comes once the hero has joined, or the five levels are stamped */
#moment.interlude .foot > * { animation-delay: calc(var(--beat) * (24 + var(--n, 0) * 1.4)); }
#moment.won .foot > * { animation-delay: calc(var(--beat) * 18); }
#moment.lost .scene { grid-template-areas: "head" "foot"; justify-items: center; text-align: center; max-width: 34em; }
#moment.lost :is(.head, .foot) { align-items: center; }
#moment.lost .foot .btn { align-self: center; min-width: 220px; }
@media (orientation: landscape) and (min-width: 960px) and (min-height: 501px), (orientation: landscape) and (max-height: 500px) {
  #moment .scene { grid-template-columns: auto auto; grid-template-areas: "head guild" "foot guild"; column-gap: clamp(32px, 6vw, 96px); width: auto; }
  #moment .foot { justify-self: start; }
  #moment .foot .btn { align-self: flex-start; min-width: 220px; }
  #moment h2 { font-size: clamp(34px, 5.4vw, 80px); }
  #moment .guild { grid-template-columns: repeat(var(--wide), var(--w)); gap: 12px; align-self: center;
    --w: clamp(48px, min(calc((58vw - (var(--wide) - 1) * 12px) / var(--wide)), calc((100dvh - 60px) / var(--rows) * .653 - 9px)), 140px); }
}
@media (orientation: landscape) and (max-height: 500px) { #moment .scene { column-gap: 28px; } #moment .head { gap: 10px; } }

/* The level coins: the run's levels as the route coins show a level's routes; a red cross where a run was lost. */
.level-coins { display: flex; justify-content: center; gap: 10px; }
.level-coin { position: relative; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  font: 700 14px/1 var(--serif); color: var(--chalk-faint); text-shadow: none; }
.level-coin::before { content: ""; position: absolute; inset: 0; border: 1.5px solid currentColor; border-radius: 50%; filter: url(#pen); }
.level-coin.done { color: var(--chalk); }
.level-coin.now { background: var(--paper) var(--grain); color: var(--ink); box-shadow: var(--lift); }
.level-coin.now::before { border-color: transparent; }
.level-coin.fell { color: var(--danger); }
.level-coin .icon { width: 16px; height: 16px; stroke-width: 8; }
/* stamped, with a puff of chalk (--k: its turn) */
.level-coin.stamp { --at: calc(var(--beat) * (7 + var(--k, 0) * 2.2)); animation: stamp 520ms var(--spring) backwards var(--at); }
.level-coin.stamp::after, .btn.route-coin.fresh::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, transparent 42%, rgba(204, 197, 189, .5) 54%, transparent 70%); opacity: 0;
  animation: puff 760ms ease-out; animation-delay: calc(var(--at, 0ms) + 200ms); }
.level-coin.next { animation: light 420ms ease-out backwards; animation-delay: calc(var(--beat) * 10.5); }
.level-coin.next::before { animation: ring 420ms ease-out backwards; animation-delay: calc(var(--beat) * 10.5); }
@keyframes stamp { 0% { transform: scale(2) rotate(-14deg); opacity: 0; } 45% { transform: scale(.86) rotate(2deg); opacity: 1; } 100% { transform: none; } }
@keyframes puff { 0% { opacity: 0; transform: scale(.55); } 25% { opacity: 1; } 100% { opacity: 0; transform: scale(1.6); } }
@keyframes light { from { background-color: transparent; color: var(--chalk-faint); box-shadow: none; } }
@keyframes ring { from { border-color: var(--chalk-faint); } }

/* ---- reduced motion: shakes and bounces stop, slides become fades (P10) ---- */
@media (prefers-reduced-motion: reduce) {
  .shake, .talk-box.done .caret, .bubble.done .caret, .bubble.pop, #mist::before, #mist::after, .btn.action.lit, .nameplate .known .new,
    .level-coin.stamp::after, .btn.route-coin.fresh::after { animation: none; }
  .talk-portrait, #moment :is(.head, .foot) > *, #toast.in, .level-coin.stamp,
    #moment .guild .card.hero, .btn.route-coin.fresh, .hearts .icon:is(.breaking, .filling), .stat.level b.rolling { animation-name: fade-in; }
  .btn, .card.hero, .slot.full, .flow, .ribbon { transition: none; }
  .book { animation: none; }
  .btn:active:not(:disabled) { transform: none; }
  #notes { transform: none; opacity: 0; transition: opacity 200ms ease-out, visibility 0s 200ms; }
  body.notes-open #notes { opacity: 1; transition: opacity 200ms ease-out; }
}
@media (prefers-reduced-motion: reduce) and (orientation: landscape) and (min-width: 960px) and (min-height: 501px) {
  #notes { opacity: 1; transition: none; }
}
/* ?fast=1 (P12): every animation ends at once. */
.fast *, .fast *::before, .fast *::after { animation-duration: 0s !important; animation-delay: 0s !important; }
