/* The opening film: a real room behind the headline. The photograph is the
   stage until the story takes over; the cast already sits in it, so the
   studio bots appear only as the camera pushes in. */
.hero-film {
  position: absolute;
  inset: 0 0 auto;
  height: 100svh;
  min-height: 500px;
  z-index: 1;
  overflow: hidden;
  background: #0d1014;
  pointer-events: none;
  will-change: opacity;
}
.hero-film > img,
.hero-film > canvas,
.hero-film > video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 71% 50%;
}
.hero-film > canvas,
.hero-film > video {
  opacity: 0;
  transition: opacity 900ms var(--ease-out);
}
.hero-film.is-live > canvas {
  opacity: 1;
}
/* The filmed take sits over the depth film; script owns its opacity and push
   once it plays. */
.hero-film > video {
  transform-origin: 70% 58%;
}
.hero-film.is-video > video {
  opacity: 1;
}
/* Without WebGL the still takes the same drift to the lamp by CSS. */
.hero-film > img {
  transform-origin: 41% 30%;
  transition:
    filter 1.2s var(--ease-out),
    transform 1.2s var(--ease-out);
}
.hero-film.is-backdrop:not(.is-live) > img {
  filter: blur(28px) brightness(0.42);
  transform: scale(1.9);
}
.hero-film.is-backdrop.is-return:not(.is-live) > img {
  filter: brightness(0.74);
  transform: none;
}
/* The same room on the evening without BotBento, laid exactly over the film
   so the two register. Script sets --before (0..1, fade in), --tidy (0..1)
   and, while the depth film runs, the film's own framing (--before-x/y/w/h).
   Without the depth film the still is placed as the fallback photo is:
   cover, anchored on the cast. */
.hero-film-before {
  position: absolute;
  inset: 0;
  overflow: hidden;
  container-type: size;
  opacity: calc(var(--before, 0) * (1 - clamp(0, (var(--tidy, 0) - 0.82) * 5.6, 1)));
  visibility: hidden;
}
.is-film-return .hero-film-before {
  visibility: visible;
}
.hero-film-before > img {
  position: absolute;
  top: 50%;
  left: 71%;
  width: 100%;
  max-width: none;
  height: 100%;
  object-fit: cover;
  object-position: 71% 50%;
  /* Duller and dimmer than the bots' evening, and a touch closer: the camera
     settles back as the desk is tidied. */
  filter: saturate(0.72) brightness(0.66);
  transform: translate(-71%, -50%) scale(calc(1 + (1 - var(--before, 0)) * 0.06));
  transform-origin: 71% 56%;
}
/* A sized box instead of object-fit, so the openings below can be given in
   the photograph's own coordinates. */
@supports (width: 1cqw) {
  .hero-film-before > img {
    width: auto;
    height: max(100cqh, calc(100cqw * 768 / 1376));
    aspect-ratio: 1376 / 768;
    object-fit: fill;
  }
}
.hero-film.is-live .hero-film-before > img {
  top: var(--before-y, 0%);
  left: var(--before-x, 0%);
  width: var(--before-w, 100%);
  height: var(--before-h, 100%);
  aspect-ratio: auto;
  object-fit: fill;
  /* The film rests a few percent closer than its framing. */
  transform: scale(calc(1.03 + (1 - var(--before, 0)) * 0.06));
}
/* Tidying. Three soft openings grow over the clutter in turn (the notes, the
   laptop, the phones and cables) and show the tidy desk and the bots in the
   film underneath; the last of the old evening then fades. */
@supports (mask-composite: intersect) or (-webkit-mask-composite: source-in) {
  .hero-film-before > img {
    --notes: clamp(0, var(--tidy, 0) * 2.86, 1);
    --laptop: clamp(0, (var(--tidy, 0) - 0.22) * 2.63, 1);
    --phones: clamp(0, (var(--tidy, 0) - 0.45) * 2.86, 1);
    -webkit-mask-image:
      radial-gradient(ellipse calc(var(--notes) * 16%) calc(var(--notes) * 22%) at 45% 75%, transparent 55%, #000 100%),
      radial-gradient(ellipse calc(var(--laptop) * 21%) calc(var(--laptop) * 31%) at 72% 52%, transparent 55%, #000 100%),
      radial-gradient(ellipse calc(var(--phones) * 25%) calc(var(--phones) * 15%) at 71% 81%, transparent 55%, #000 100%);
    mask-image:
      radial-gradient(ellipse calc(var(--notes) * 16%) calc(var(--notes) * 22%) at 45% 75%, transparent 55%, #000 100%),
      radial-gradient(ellipse calc(var(--laptop) * 21%) calc(var(--laptop) * 31%) at 72% 52%, transparent 55%, #000 100%),
      radial-gradient(ellipse calc(var(--phones) * 25%) calc(var(--phones) * 15%) at 71% 81%, transparent 55%, #000 100%);
    -webkit-mask-composite: source-in;
    mask-composite: intersect;
  }
}
/* Centred copy sits over the room on narrow screens, so the room dims under it. */
@media (max-width: 900px) {
  .hero-film-before::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
      180deg,
      rgb(14 11 9 / 66%) 0%,
      rgb(14 11 9 / 44%) 42%,
      rgb(14 11 9 / 0%) 70%
    );
  }
}
/* Reading light for the headline: the room falls into shadow on the left and
   at the floor, the way a film frame holds a title. */
.hero-film-grade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      90deg,
      rgb(14 11 9 / 88%) 0%,
      rgb(14 11 9 / 72%) 26%,
      rgb(14 11 9 / 30%) 46%,
      rgb(14 11 9 / 0%) 62%
    ),
    linear-gradient(0deg, rgb(14 11 9 / 70%) 0%, rgb(14 11 9 / 0%) 26%),
    linear-gradient(180deg, rgb(14 11 9 / 55%) 0%, rgb(14 11 9 / 0%) 18%);
}
/* Right-to-left pages set the headline on the right, so the room is mirrored
   and the cast sits opposite it; the reading shadow mirrors with it. */
[dir="rtl"] .hero-film {
  transform: scaleX(-1);
}
.has-hero-film .actor > img.is-active,
.has-hero-film .actor > .contact-shadow {
  opacity: var(--actor-reveal, 0);
}
.is-film-return .actor {
  visibility: hidden;
}
.has-hero-film .hero-scene::before {
  display: none;
}
/* Phones: the headline holds the top of the screen and the room opens below
   it, fading up into the dark so the cast reads whole. */
@media (max-width: 700px) {
  .hero-film > img,
  .hero-film > canvas,
  .hero-film > video {
    inset: auto 0 0;
    height: 58%;
    -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 22%);
    mask-image: linear-gradient(180deg, transparent 0%, #000 22%);
  }
  .hero-film.is-backdrop > canvas,
  .hero-film.is-backdrop > img {
    height: 100%;
    -webkit-mask-image: none;
    mask-image: none;
  }
  .hero-film-grade {
    background: linear-gradient(0deg, rgb(14 11 9 / 55%) 0%, rgb(14 11 9 / 0%) 22%);
  }
}
@media (prefers-reduced-motion: reduce) {
  .hero-film > canvas,
  .hero-film > video {
    transition: none;
  }
}
/* Title-card legibility: the opening copy carries a soft shadow of the room's
   own dark, so thin scripts (Arabic, Chinese) hold up where it meets the cast. */
.has-hero-film .narrative--hero h1,
.has-hero-film .narrative--hero p,
.has-hero-film .narrative--close h2 {
  text-shadow: 0 1px 22px rgb(14 11 9 / 72%);
}
/* Chapter lighting. Each middle chapter is lit like its own shot: access
   closes down to one pool of light on Bento and its card, the revision lets
   the lamp swell warm over Drop as the plan changes. The cast keeps its side
   on right-to-left pages while the film is mirrored, so the light is
   counter-mirrored there to stay on the cast. */
.hero-film::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 900ms var(--ease-standard),
    background 0s 900ms;
}
.is-access .hero-film::after {
  opacity: 1;
  transition: opacity 900ms var(--ease-standard);
  background: radial-gradient(
    46% 62% at 76% 72%,
    rgb(14 11 9 / 0%) 0%,
    rgb(14 11 9 / 38%) 55%,
    rgb(14 11 9 / 72%) 100%
  );
}
.is-revision .hero-film::after {
  opacity: 1;
  transition: opacity 900ms var(--ease-standard);
  background:
    radial-gradient(55% 60% at 88% 18%, rgb(255 170 96 / 16%) 0%, rgb(255 170 96 / 0%) 70%),
    radial-gradient(40% 50% at 88% 92%, rgb(255 190 120 / 10%) 0%, rgb(255 190 120 / 0%) 70%);
}
[dir="rtl"] .is-access .hero-film::after {
  background: radial-gradient(
    46% 62% at 24% 72%,
    rgb(14 11 9 / 0%) 0%,
    rgb(14 11 9 / 38%) 55%,
    rgb(14 11 9 / 72%) 100%
  );
}
[dir="rtl"] .is-revision .hero-film::after {
  background:
    radial-gradient(55% 60% at 12% 18%, rgb(255 170 96 / 16%) 0%, rgb(255 170 96 / 0%) 70%),
    radial-gradient(40% 50% at 12% 92%, rgb(255 190 120 / 10%) 0%, rgb(255 190 120 / 0%) 70%);
}
@media (prefers-reduced-motion: reduce) {
  .hero-film::after {
    transition: none;
  }
}
/* Phones stage the chapters in a column, so the shot lighting stays off. */
@media (max-width: 700px) {
  .hero-film::after {
    display: none;
  }
}
