/*
 * The intro (#intro): a film that fills a phone screen; on wider screens it
 * sits in a phone-shaped frame on the night sky. Its colours are fixed in
 * both themes, like the app's stickers, so the film's periwinkle is the
 * card's. Pip is the app's own (pip.js); while it flies, its layers are set
 * frame by frame, so its idle animations are switched off here.
 */
.film {
  --film-ink: #16161a;
  --film-ink-muted: #33333f;
  --film-periwinkle: #9bb9fd;
  --film-night: #0d0d14;
  --film-white: #ffffff;
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  background: var(--film-night);
  color: var(--film-ink);
}
.film-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(120% 75% at 50% 46%, #1c1c2e 0%, var(--film-night) 70%);
}
.film-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

/* Skip and Sound sit over every scene, so they carry their own dark glass. */
.film-hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top, 0px));
  left: max(14px, env(safe-area-inset-left, 0px));
  right: max(14px, env(safe-area-inset-right, 0px));
  z-index: 3;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.film-chip {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin-left: auto;
  padding: 6px 16px;
  border: 0;
  border-radius: 999px;
  background: rgb(22 22 26 / 0.55);
  color: var(--film-white);
  font: 700 0.86rem/1 var(--font-ui);
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.film-chip + .film-chip { margin-left: 0; }
.film-chip#film-sound { margin-left: 0; margin-right: auto; }
.film-chip svg { width: 16px; height: 16px; }
.film-chip[aria-pressed="false"] svg { opacity: 0.55; }
.film-chip:focus-visible { outline: 3px solid var(--film-white); outline-offset: 2px; }

.film-text-button {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: 700 0.94rem/1 var(--font-ui);
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}
a.film-text-button { display: inline-flex; align-items: center; }
.film-text-button:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; border-radius: 4px; }

/* Before the film: two ways to play, over the constellation drifting. Sound needs a tap, so the choice is the tap. */
.film-gate {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 14px;
  padding: 28px max(24px, env(safe-area-inset-right, 0px)) max(36px, calc(env(safe-area-inset-bottom, 0px) + 24px)) max(24px, env(safe-area-inset-left, 0px));
  background: linear-gradient(to top, rgb(13 13 20 / 0.92) 0%, rgb(13 13 20 / 0.55) 38%, transparent 70%);
  color: var(--film-white);
}
.film-eyebrow { color: var(--film-periwinkle); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.film-gate-title { margin-bottom: 8px; color: var(--film-white); font: 500 clamp(2rem, 9vw, 2.5rem)/1.06 var(--font-display); letter-spacing: -0.04em; }
.film-gate-title b, .film-end h1 b { font-weight: 800; }
.film .button[data-variant="highlight"] { width: 100%; justify-content: center; }
.film-gate .film-text-button { align-self: center; }

/* The last card: Pip, the pace those words went by at, and the way into the speed test. */
.film-end {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding: 76px max(22px, env(safe-area-inset-right, 0px)) max(28px, env(safe-area-inset-bottom, 0px)) max(22px, env(safe-area-inset-left, 0px));
  background: var(--film-periwinkle);
  color: var(--film-ink);
}
/* While Pip flies in, the card lets the film show through; by the time it settles, the film is the same periwinkle. */
.film-end[data-staged] { background: transparent; }
.film-end > * { opacity: 0; transform: translateY(16px); transition: opacity 0.45s ease, transform 0.65s var(--ease-press); transition-delay: calc(var(--rise, 0) * 70ms); }
.film-end.is-shown > * { opacity: 1; transform: none; }
.film-end > :nth-child(2) { --rise: 1; }
.film-end > :nth-child(3) { --rise: 2; }
.film-end > :nth-child(4) { --rise: 3; }
.film-end > :nth-child(n+5) { --rise: 4; }
/* Pip and the bubble arrive their own way, so they don't rise with the rest. */
.film-end > .film-guide { opacity: 1; transform: none; transition: none; }
.film-end h1 { color: var(--film-ink); font-size: clamp(2.3rem, 10.6vw, 2.9rem); line-height: 1.04; letter-spacing: -0.045em; }
.film-end h1:focus { outline: none; }
.film-lead { max-width: 34ch; color: var(--film-ink-muted); }
.film-fine { color: var(--film-ink-muted); font-size: 0.82rem; line-height: 1.45; }
.film-links { display: flex; flex-wrap: wrap; gap: 4px 22px; }

.film-guide { display: flex; align-items: flex-end; gap: 6px; }
.film-perch { flex: none; display: grid; place-items: end center; width: 84px; height: 84px; border-radius: 50%; background: rgb(255 255 255 / 0.42); overflow: hidden; transform: scale(0); transition: transform 0.42s var(--ease-spring); }
.film-perch.is-in { transform: none; }
.film-perch .pip { --pip-size: 72px; margin-bottom: -2px; visibility: hidden; }
.film-perch.has-pip .pip { visibility: visible; }
.film-bubble {
  position: relative;
  margin-bottom: 14px;
  padding: 12px 16px;
  border-radius: 20px;
  background: var(--film-white);
  color: var(--film-ink);
  font-size: 0.92rem;
  line-height: 1.45;
  box-shadow: 0 14px 26px -18px rgb(22 22 26 / 0.6);
  opacity: 0;
  transform: scale(0.4);
  transform-origin: 0% 100%;
  transition: transform 0.45s var(--ease-spring), opacity 0.2s ease;
}
.film-bubble::before { content: ""; position: absolute; left: -7px; bottom: 16px; border: 8px solid transparent; border-right-color: var(--film-white); border-left: 0; }
.film-bubble strong { font-weight: 800; font-variant-numeric: tabular-nums; }
.film-guide.has-bubble .film-bubble { opacity: 1; transform: none; }

/* The flying Pip, placed and posed frame by frame from its feet. */
.film-actor { position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none; transform-origin: 50% 92%; }
.film-actor-body { width: 100%; height: 100%; transform-origin: 50% 92%; }
.film-actor .pip { --pip-size: 100%; }
.film-actor .pip-shadow { display: none; }
.film-hi {
  position: absolute;
  left: 74%;
  top: 0;
  padding: 7px 13px;
  border-radius: 999px 999px 999px 4px;
  background: var(--film-white);
  color: var(--film-ink);
  font: 800 clamp(0.95rem, 4.4vw, 1.2rem)/1 var(--font-ui);
  white-space: nowrap;
  box-shadow: 0 10px 22px -14px rgb(22 22 26 / 0.6);
  transform: scale(0);
  transform-origin: 0% 100%;
}
/* Pip's own idles would fight the frames; on the perch it only breathes and flutters. */
.film .pip-art, .film .pip-art * { animation: none !important; transition: none !important; }
:is(.film-actor, .film .pip)[data-face="happy"] .pip-eyes-open { display: none; }
:is(.film-actor, .film .pip)[data-face="happy"] .pip-eyes-happy { display: inline; }
.film-actor[data-face="blink"] .pip-eyes-open { display: none; }
.film-actor[data-face="blink"] .pip-blink-lines { display: inline; }
.film-actor[data-beak="open"] .pip-beak { display: none; }
.film-actor[data-beak="open"] .pip-beak-open { display: inline; }
@media (prefers-reduced-motion: no-preference) {
  .film-perch.has-pip .pip-body { animation: film-breathe 3.4s ease-in-out infinite !important; }
  @keyframes film-breathe { 50% { transform: scale(1.02, 0.98) translateY(0.6px); } }
}

/* The landing page's way back to the film. */
.landing-intro-link { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; color: var(--on-pastel); font-weight: 700; font-size: 0.92rem; text-decoration: underline; text-underline-offset: 4px; }
.landing-intro-link svg { width: 18px; height: 18px; }

@media (min-width: 720px) {
  .film-stage { width: 390px; height: min(844px, calc(100dvh - 48px)); min-height: 600px; border-radius: 44px; box-shadow: 0 0 0 1px rgb(255 255 255 / 0.08), 0 40px 80px -40px rgb(0 0 0 / 0.8); }
}
@media (prefers-reduced-motion: reduce) {
  .film-end > *, .film-perch, .film-bubble { transition: none; }
  /* The film never plays under reduced motion, so there is nothing to watch. */
  .landing-intro-link { display: none; }
}
