/*
  The introduction (js/intro.js): a few cards, one at a time, on the board's own background,
  before Start. The cards are made of what the board is made of: a tray with a sheet set in
  it, the board's surface, hairline, radius and shadow. So the introduction and the board are
  one world, and at Start one set of cards gives way to the other on a page that has not moved.

  Type is quiet. A statement is set in the regular weight at a calm display size with tight
  tracking; what follows it is smaller and greyer. Hierarchy comes from size, tone and space,
  never from weight. A card carries at most one emphasis: the word it sets in quotes, in the
  firm's serif.

  This is seen once, and it explains, so its fades run longer than the board's. Only opacity
  and transform move. They are transitions, so going on in the middle of one turns it around.
  Tokens are the board's own (css/base.css).
*/

/* ---------- the stage: the board's background, with none of the board on it ---------- */
/* Out of sight, out of the tab order and out of a screen reader's reach until Start. */
body.is-staged .world,
body.is-staged .trail,
body.is-staged .due,
body.is-staged .chrome,
body.is-staged .panel,
body.is-staged .panel-ring,
body.is-staged .scrim { visibility: hidden; }
/* The welcome's backdrop gives way to the page itself: no blur, no tint, only the small wheel. */
.gate.is-solid .gate-scrim { background: none; -webkit-backdrop-filter: none; backdrop-filter: none; animation: none; }
.gate.is-solid:not(.is-ready) .gate-shell, .gate.is-solid:not(.is-ready) .gate-card { background: none; box-shadow: none; }
.gate.is-intro .gate-shell { display: none; }

.intro {
  position: fixed; inset: 0; z-index: 72;
  opacity: 0;
  transition: opacity 420ms var(--ease-out);
  outline: none;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  /* A click here is a step, never a selection: nothing on the cards or the foot can be selected. */
  -webkit-user-select: none;
  user-select: none;
}
.intro.is-up { opacity: 1; }
.intro.is-leaving { opacity: 0; pointer-events: none; transition-duration: 520ms; }
.intro-stage { position: absolute; inset: 0; }

/* Every card lies on the same spot. Only the one that is on can be seen or touched. */
.intro-card {
  position: absolute; inset: 0;
  display: grid;
  place-items: center;
  padding: 72px 24px 96px;
  overflow-y: auto;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 280ms;
}
.intro-card.is-on { visibility: visible; pointer-events: auto; transition-delay: 0s; }
.intro-fit { width: 100%; max-width: 760px; }

/* A piece waits a little below, comes up into place, and leaves upward. Leaving is quick.
   The card itself is one such piece, and so is each line on it. */
.intro-line {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 240ms var(--ease-out), transform 240ms var(--ease-out);
}
.intro-card.is-past .intro-line { transform: translateY(-10px); }
.intro-card.is-on .intro-line {
  opacity: 1;
  transform: none;
  transition: opacity 760ms var(--ease-out) var(--d, 0ms), transform 760ms var(--ease-out) var(--d, 0ms);
}
.intro-tray.intro-line { transform: translateY(16px) scale(0.985); }
.intro-card.is-past .intro-tray.intro-line { transform: translateY(-10px) scale(0.99); }
.intro-card.is-on .intro-tray.intro-line { transform: none; transition-duration: 620ms; }

/* ---------- the card: a tray, and the sheet set inside it ---------- */
.intro-tray {
  padding: 7px;
  border-radius: 30px;
  background: var(--slot);
  box-shadow: 0 0 0 1px var(--line);
}
.intro-sheet {
  position: relative;
  border-radius: 23px;
  background: var(--surface);
  box-shadow: var(--panel-shadow);
  overflow: hidden;
}
/* Every card of words is the same size, so only the words change. */
.intro-inner {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 460px;
  padding: 56px 72px;
  text-align: center;
  transition: opacity 400ms var(--ease-out);
}

/* The statement: regular weight, calm size, tight tracking. Nothing on a card is bold. */
.intro-big {
  margin: 0 auto;
  max-width: 19ch;
  font-size: clamp(29px, 3.1vw, 42px);
  line-height: 1.16;
  font-weight: 400;
  letter-spacing: -0.028em;
  color: var(--text);
  text-wrap: balance;
}
.intro-big.is-long { max-width: 25ch; font-size: clamp(25px, 2.5vw, 34px); line-height: 1.22; letter-spacing: -0.024em; }
/* A statement of a few clauses: a size smaller again, still one statement, on a wider measure. */
.intro-big.is-longer { max-width: 33ch; font-size: clamp(21px, 2vw, 28px); line-height: 1.3; letter-spacing: -0.02em; }
/* The one emphasis: the word a statement sets in quotes, in the firm's serif. */
.intro-em {
  font-family: "Instrument Serif", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-style: italic;
  font-size: 1.1em;
  letter-spacing: -0.012em;
}
/* What follows a statement explains it: smaller, greyer, never a second headline. */
.intro-sub {
  margin: 22px auto 0;
  max-width: 34ch;
  font-size: 17.5px;
  line-height: 1.5;
  font-weight: 400;
  letter-spacing: -0.006em;
  color: var(--text-2);
  text-wrap: balance;
}
.intro-kicker { margin: 0 0 18px; font-size: 15px; font-weight: 400; letter-spacing: -0.003em; color: var(--text-3); }

/* The last card: how long they have, the one button, and that nothing is running yet. */
.intro-terms { margin: 40px auto 0; max-width: 28ch; font-size: 16px; line-height: 1.5; letter-spacing: -0.004em; color: var(--text-2); text-wrap: balance; }
.intro-go { margin: 22px 0 0; }
.intro.is-replay .intro-go { margin-top: 40px; }
.intro-note { min-height: 20px; margin: 14px 0 0; font-size: 13px; line-height: 20px; color: var(--text-3); }

/* Start has been pressed: what is on the card fades away (400ms, most of it at once), the
   send off begins as that leaves (900ms), stands, and then it and the card go (600ms). The
   moments are in js/intro.js (BEAT). */
.intro-card.is-sending .intro-inner { opacity: 0; pointer-events: none; }
.intro-sendoff {
  position: absolute; inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0 24px;
  /* The statement face, as on every card of words: regular weight, tight tracking. */
  font-size: clamp(29px, 3.1vw, 42px);
  line-height: 1.16;
  font-weight: 400;
  letter-spacing: -0.028em;
  text-align: center;
  color: var(--text);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 900ms var(--ease-out), transform 900ms var(--ease-out);
  pointer-events: none;
}
.intro-card.is-sendoff .intro-sendoff { opacity: 1; transform: none; }
.intro-card.is-sent .intro-tray.intro-line { opacity: 0; transform: translateY(-8px) scale(0.985); transition: opacity 600ms var(--ease-out), transform 600ms var(--ease-out); }

/* ---------- a silent film is the card's face ---------- */
/* The film is not set on the card: it is the card's whole inner face, edge to edge. The sheet
   takes the film's own ground (the logo film's is #fdfdfd throughout), so there is no seam.
   The film has photographs in it, so it is never inverted: in the dark theme this one card
   keeps its light face, the way a printed card would.
   The card's one line belongs to the film's last picture: it comes up directly under the
   wordmark the film ends on (--line-at, the share of the film's height where the line begins,
   from `lineAt` in the data file), and its size follows the card's width as the wordmark's does. */
.intro-card.has-face .intro-sheet { background: #fdfdfd; container-type: inline-size; }
.intro-card.has-face .intro-inner {
  position: absolute; left: 0; right: 0;
  top: calc(var(--line-at, 0.565) * 100%);
  display: block;
  min-height: 0;
  padding: 0;
  pointer-events: none;
}
.intro-card.has-face .intro-big {
  max-width: none;
  font-size: 14px;
  font-size: clamp(11.5px, 1.95cqw, 15px);
  line-height: 1.3;
  letter-spacing: 0.004em;
  color: rgba(22, 22, 20, 0.56);
}
/* It waits until the wordmark has landed. */
.intro-card.has-face.is-on:not(.is-landed) .intro-inner .intro-line { opacity: 0; transform: translateY(6px); }
.intro-card.has-face.is-on.is-landed .intro-inner .intro-line { transition-duration: 520ms; transition-delay: 0ms; }
/* The face arrives with its card, already moving. */
.intro-card.has-face.is-on .intro-face.intro-line { transition-delay: 0ms; }
.intro-face { position: relative; aspect-ratio: 1200 / 630; }
.intro-face video, .intro-face .intro-still {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.intro-face .intro-still { display: none; }
.intro-face.is-still .intro-still { display: block; }
.intro-face.is-still video { display: none; }

/* ---------- a film with sound has the one larger card, because the film is the centre ---------- */
/* Its width follows from the height the screen leaves, so the whole picture is in view. */
.intro-card.has-film { padding-top: 56px; padding-bottom: 88px; }
.intro-card.has-film .intro-fit:not(.intro-after) { max-width: min(1120px, calc((100vh - 264px) * 16 / 9)); }
.intro-card.has-film .intro-fit:not(.intro-after) .intro-inner { min-height: 0; padding: 24px 40px 22px; }
.intro-card.has-film .intro-fit:not(.intro-after) .intro-big { max-width: none; font-size: clamp(17px, 1.5vw, 21px); line-height: 1.3; letter-spacing: -0.012em; color: var(--text); }
.intro-film {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  background: var(--slot);
}
.intro-frame-note { margin: 0; max-width: 30ch; padding: 24px; font-size: 16px; line-height: 1.45; color: var(--text-3); text-align: center; text-wrap: balance; }
.intro-film video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
  opacity: 0;
  transition: opacity 320ms var(--ease-out);
}
.intro-film.has-film video { opacity: 1; }
.intro-film.has-film .intro-frame-note { visibility: hidden; }
.intro-film .intro-still { display: none; }
/* The film never takes the pointer: a click on it is a click on its card. */
.intro-film video, .intro-face video, .intro-film .intro-still, .intro-face .intro-still { pointer-events: none; }
/* The words under a film: "Sound" when the browser would not play its sound, and the word
   that starts it again when something outside the page has stopped it. They take no room on
   the card, so the card sits where it would without them. */
.intro-fit { position: relative; }
.intro-film-ctl { position: absolute; left: 0; right: 0; top: 100%; display: flex; justify-content: center; gap: 22px; margin: 8px 0 0; }

/* ---------- the film's card becomes its statement ---------- */
/* One card, which changes. When the film has played, it and its title fade, the card settles
   to the size of a card of words, and the statement arrives on it. The statement's own card
   lies in the same place as the film's the whole time, unseen; at the turn it starts exactly
   on the film card's outline (--sx, --sy, --tx, --ty, measured in js/intro.js) and settles to
   its own. Opacity and transform only, as transitions, so going on in the middle of it turns
   it around. */
.intro-card.has-after > .intro-fit { grid-area: 1 / 1; }
/* The statement's card stands exactly where every other card of words stands: the film's card
   has its own margins, and this takes the difference back (4px down here, 4px a side on a
   narrow screen), so nothing shifts between this card and the next. */
.intro-after { pointer-events: none; position: relative; top: 4px; }
.intro-card.is-turned .intro-after { pointer-events: auto; }
.intro-card.is-turned .intro-before { pointer-events: none; }
.intro-turn {
  opacity: 0;
  transform: translateY(16px) scale(0.985);
  transform-origin: 50% 50%;
  transition: opacity 240ms var(--ease-out), transform 240ms var(--ease-out);
}
.intro-card.is-past .intro-turn { transform: translateY(-10px) scale(0.99); }
/* While the film runs: in place over the film's card, not yet seen. */
.intro-card.is-on:not(.is-turned) .intro-turn {
  opacity: 0;
  transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(var(--sx, 1), var(--sy, 1));
  transition: none;
}
.intro-card.is-on:not(.is-turned) .intro-after .intro-line { opacity: 0; transform: translateY(14px); transition: none; }
/* Turned: the statement's card, as any card of words arrives. */
.intro-card.is-on.is-turned .intro-turn { opacity: 1; transform: none; transition: opacity 620ms var(--ease-out), transform 620ms var(--ease-out); }
.intro-card.is-on.is-turned .intro-before .intro-tray.intro-line { opacity: 0; transform: none; transition: opacity 240ms var(--ease-out); }
.intro-card.is-turned .intro-before .intro-sheet > * { opacity: 0; transition: opacity 320ms var(--ease-out); }
.intro-card.is-turned .intro-film-ctl { display: none; }
/* The turn itself, seen once: the film and its title go (320ms), the two cards change places
   on one outline (260ms, from 240ms) while that outline settles (760ms), and the words come
   when it has all but arrived. */
.intro-card.is-on.is-turning .intro-turn { transition: opacity 260ms var(--ease-out) 240ms, transform 760ms var(--ease-out) 240ms; }
.intro-card.is-on.is-turning .intro-before .intro-tray.intro-line { transition: opacity 260ms var(--ease-out) 240ms; }
.intro-card.is-on.is-turning .intro-after .intro-inner .intro-line { transition-delay: calc(560ms + var(--d, 0ms)); }

/* ---------- plain words that do something: Previous, Sound, Play, Close ---------- */
.intro-plain {
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--text-3);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.intro-plain[hidden] { display: none; }
.intro-plain:focus-visible { outline: 2px solid var(--edge-hot); outline-offset: 2px; border-radius: 4px; }
@media (hover: hover) and (pointer: fine) { .intro-plain:hover { color: var(--text); } }
.intro-top {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(22px, env(safe-area-inset-right));
  display: flex;
  gap: 18px;
  margin: 0;
}
/* The foot: how to go on, said small, and beside it the one word that goes back a card. */
.intro-foot {
  position: absolute; left: 0; right: 0;
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 26px;
  min-height: 36px;
  margin: 0;
  font-size: 15px;
  pointer-events: none;
}
.intro-foot .intro-plain { pointer-events: auto; }
.intro-hint { color: var(--text-3); transition: opacity 500ms var(--ease-out); }
/* Said once: on the first card only. */
.intro.is-last .intro-hint, .intro.is-locked .intro-hint, .intro.is-told .intro-hint { display: none; }
/* On a card that opens with a film, the hint arrives with the film's last picture. */
.intro.is-waiting .intro-hint { opacity: 0; }
/* While a film that has to be watched is running: a hairline that fills. No number. */
.intro-wait {
  display: none;
  width: 132px;
  height: 1px;
  background: var(--line-strong);
  overflow: hidden;
}
.intro.is-locked .intro-wait { display: block; }
.intro-wait i {
  display: block;
  height: 100%;
  background: var(--text-2);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 320ms linear;
}

@media (max-width: 700px) {
  .intro-card { padding: 64px 12px 84px; }
  .intro-tray { padding: 5px; border-radius: 26px; }
  .intro-sheet { border-radius: 21px; }
  .intro-inner { min-height: 400px; padding: 44px 28px; }
  .intro-big { font-size: clamp(26px, 7.2vw, 32px); }
  .intro-big.is-long { font-size: clamp(23px, 6.2vw, 27px); }
  .intro-big.is-longer { font-size: clamp(19.5px, 5.3vw, 22px); }
  .intro-after { top: 0; padding: 0 4px; }
  .intro-sub { margin-top: 18px; font-size: 16.5px; }
  .intro-terms { margin-top: 32px; }
  .intro-sendoff { font-size: clamp(26px, 7.2vw, 32px); }
  /* On a phone the film's card takes the full width. */
  .intro-card.has-film { padding: 64px 8px 84px; }
  .intro-card.has-film .intro-fit:not(.intro-after) { max-width: none; }
  .intro-card.has-film .intro-fit:not(.intro-after) .intro-inner { padding: 20px 20px 18px; }
  .intro-card.has-film .intro-fit:not(.intro-after) .intro-big { font-size: 17px; }
}
/* Reduced motion: the same order and the same beats, as a plain cross fade. */
@media (prefers-reduced-motion: reduce) {
  .intro-line, .intro-tray.intro-line, .intro-card.is-past .intro-line, .intro-card.is-past .intro-tray.intro-line { transform: none; transition: opacity 200ms ease; }
  .intro-card.is-on .intro-line, .intro-card.is-on .intro-tray.intro-line { transform: none; transition: opacity 260ms ease var(--d, 0ms); }
  .intro-card.has-face.is-on:not(.is-landed) .intro-inner .intro-line { transform: none; }
  /* The send off keeps its beats; only the movement goes. */
  .intro-sendoff, .intro-card.is-sendoff .intro-sendoff { transform: none; transition: opacity 900ms ease; }
  .intro-card.is-sent .intro-tray.intro-line { transform: none; transition: opacity 600ms ease; }
  .intro-wait i { transition: none; }
  /* The film's card and its statement change places as a plain cross fade. */
  .intro-turn, .intro-card.is-past .intro-turn, .intro-card.is-on:not(.is-turned) .intro-turn, .intro-card.is-on.is-turned .intro-turn { transform: none; }
  .intro-card.is-on.is-turned .intro-turn, .intro-card.is-on.is-turning .intro-turn { transition: opacity 320ms ease 200ms; }
  .intro-card.is-on.is-turning .intro-after .intro-inner .intro-line { transition-delay: calc(360ms + var(--d, 0ms)); }
  .intro, .intro.is-leaving { transition-duration: 200ms; }
}
