/* ===========================================================================
   LAYOUT — v3. v1's split column, v2's glass.

   v1 gave the scene its own column so it could never argue with the copy. v2
   ran the stage full bleed and floated the copy on glass over it. v3 keeps
   both halves of that: the copy lives in one standing pane of glass in one
   column, the icon lives in the empty column beside it, and the two never
   overlap.

   Which column is which alternates down the page — see `data-side` below. What
   does not alternate is the rule: one column holds copy, the other holds the
   object, and nothing is ever in both.

   The canvas still runs edge to edge underneath, which looks redundant until
   you remember what glass is for — the pane needs something behind it to blur
   or it is a dark card. So the 3D grid spans the whole frame and only the
   *icon* is fenced into a column.

   One pane, not a card per act. v2 gave every act its own sheet, so the box
   changed size on every hand-off; here the pane stands still and only its
   contents cross-fade.
   =========================================================================== */

/* ---------------------------------------------------------------------------
   Which way round a film stands.

   The page zig-zags: the copy is on the right for one film and on the left for
   the next, and the object crosses to the empty column to meet it. The side is
   declared once, in the markup, as `data-side` on the film — because it is a
   fact about that film and not about the stylesheet, and because reordering
   the films should reorder the zig-zag without anyone editing CSS.

   `data-side` names where the *copy* goes. Everything else — the object, the
   glow behind it, the scroll hint, the act index — takes the other column.

   Every one of these lands as a custom property rather than as a direct
   `left`/`right`, so the narrow-screen block further down can go on setting
   the property itself and win: a media query adds no specificity, and
   `.film[data-side="left"] .pane` would otherwise outrank `.pane` inside it.
   --------------------------------------------------------------------------- */
.film{
  position: relative;
  /* Above the fixed stage, which is z-index 0 and would otherwise paint over
     the pane on any browser that resolves the two differently. */
  z-index: 1;
  /* The acts, plus the one screen the pin itself occupies — which stays a full
     screen whatever an act costs, or the handover in main.js loses the scroll
     it dissolves over. */
  height: calc(var(--acts) * var(--act-scroll) + 100svh);

  --pane-left:  calc(var(--gutter) + var(--frame-w) * var(--split));
  --pane-right: var(--gutter);
  --hint-x:     calc(var(--gutter) + var(--frame-w) * var(--split) / 2);
}
.film[data-side="left"]{
  --pane-left:  var(--gutter);
  --pane-right: calc(var(--gutter) + var(--frame-w) * var(--split));
  --hint-x:     calc(100% - var(--gutter) - var(--frame-w) * var(--split) / 2);
}

.film-pin{
  position: sticky;
  top: 0;
  height: 100svh;
  overflow: hidden;
}

/* ---------------------------------------------------------------------------
   Stage — fixed to the viewport, outside every pin.

   It used to live inside the one film's pin, which was fine while there was
   one film. There are now three, with static sections between them, and an
   object that lives inside a pin dies with the pin. Fixed, it outlives all
   three and keeps one continuous run through them.

   Two opacities, doing different jobs. `is-live` is the one-time fade-in when
   three.js has finished loading — a transition, because it happens once and at
   no particular scroll position. STAGE-FADE is the handover, written every
   frame by main.js from how much of the viewport the nearest 3D film still
   occupies: a transition cannot do that job, because what it has to keep pace
   with is the arriving section's top edge, and that moves at whatever speed
   the reader scrolls.

   STAGE-MAX is what the fade is allowed to reach, and exists only so the
   narrow-screen dimming can stay in the stylesheet where it belongs instead of
   being multiplied into the number JS writes.
   --------------------------------------------------------------------------- */
.scene{
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  --stage-fade: 0;
  --stage-max: 1;
  opacity: calc(var(--stage-fade) * var(--stage-max));

  /* STAGE-MIRROR is +1 while the object is in the left column and -1 while it
     is in the right one, and main.js writes every value between as it crosses.
     The stage is one fixed layer shared by three films standing different ways
     round, so it cannot take the side from a selector the way a film can. */
  --stage-mirror: 1;
  --stage-x:  calc(50% - var(--frame-w) * .22 * var(--stage-mirror));
  --stage-x2: calc(50% - var(--frame-w) * .34 * var(--stage-mirror));
}
.scene canvas{
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 1.4s var(--ease);
}
.scene.is-live canvas { opacity: 1; }

.scene-fallback{
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 32% 40% at var(--stage-x) 46%, var(--accent-tint), transparent 70%),
    radial-gradient(ellipse 30% 36% at var(--stage-x2) 80%, var(--violet-tint), transparent 72%),
    linear-gradient(to right,  var(--line) 1px, transparent 1px) 0 0 / 72px 72px,
    linear-gradient(to bottom, var(--line) 1px, transparent 1px) 0 0 / 72px 72px;
  -webkit-mask-image: radial-gradient(ellipse 58% 58% at var(--stage-x) 52%, #000, transparent 78%);
          mask-image: radial-gradient(ellipse 58% 58% at var(--stage-x) 52%, #000, transparent 78%);
  transition: opacity 1s var(--ease);
}
.scene.is-live .scene-fallback { opacity: 0; }

/* Screen light bleeding out of the dark, over the canvas but under the pane.
   Mirrored bodily for a left-standing film: the two ellipses are aimed at the
   column the object is in, and reaiming them one stop at a time is four more
   numbers to keep in step with `--split`. */
.film[data-side="left"] .film-pin::after { transform: scaleX(-1); }

.film-pin::after{
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 40% 46% at 26% 46%, var(--accent-tint), transparent 72%),
    radial-gradient(ellipse 34% 40% at 12% 84%, var(--violet-tint), transparent 74%);
}

/* ---------------------------------------------------------------------------
   The pane — one standing column of copy, in whichever column is its own

   It was a sheet of glass. Dropped: the copy now stands free over the room, so
   the only thing left of the pane is its geometry — the column, the fixed
   height the panels cross-fade inside, and one size held still.
   --------------------------------------------------------------------------- */
.pane{
  position: absolute;
  z-index: 2;
  left: var(--pane-left);
  right: var(--pane-right);
  top: 50%;
  transform: translateY(-50%);
  height: min(74svh, 40rem);
  /* No box to read against any more, so the type carries its own dark. */
  text-shadow: 0 1px 28px var(--bg), 0 0 2px rgba(11,10,18,.6);
}

/* Loose copy has no glass to be inset from, so it sits on the frame's edge,
   flush with the text of the static bands. */
.film:not(.film-flow) .panel { padding-inline: 0; }
.film:not(.film-flow) .run-title { left: 0; }

/* The diagram film keeps its glass. There is no object behind it to stand
   over, and six lit nodes next to loose copy read as two unrelated things —
   the sheet is what makes the copy the caption of the diagram. */
.film-flow .pane{
  text-shadow: none;
  border-radius: var(--radius);
  background: var(--pane-sheen), var(--pane-scrim);
  backdrop-filter: blur(26px) saturate(1.7);
  -webkit-backdrop-filter: blur(26px) saturate(1.7);
  border: 1px solid var(--glass-line);
  box-shadow: var(--glass-edge);
  overflow: hidden;
}
/* The specular streak along the top edge. Two stops, off centre, so it reads
   as light catching a curve rather than as a border. */
.film-flow .pane::before{
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent, rgba(255,255,255,.55) 20%, rgba(255,255,255,.12) 60%, transparent);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))){
  .film-flow .pane { background: var(--pane-sheen), rgba(13,11,22,.94); }
}

.panels{
  position: absolute;
  inset: 0;
}

.panel{
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: start;
  padding: clamp(1.8rem, 3vw, 3.25rem);
  opacity: 0;
  will-change: opacity, transform, filter;
}

/* In v2 this was the glass. Here the pane is, so the sheet is only a content
   box — it still carries the scale, which is what makes a panel read as
   coming forward rather than merely appearing. */
.sheet{
  width: min(100%, 34rem);
  transform-origin: left center;
}

.run-title{
  position: absolute;
  z-index: 3;
  top: clamp(1.4rem, 2.2vw, 2rem);
  left: clamp(1.8rem, 3vw, 3.25rem);
  opacity: 0;
  pointer-events: none;
  will-change: opacity, transform;
}
.run-title span{
  display: inline-block;
  padding: .38rem .9rem;
  border-radius: var(--radius-pill);
  background: var(--glass);
  border: 1px solid var(--glass-line);
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .06em;
  color: var(--soft);
}

/* ---------------------------------------------------------------------------
   Narrow: the split collapses. The pane takes the whole frame and the stage
   goes behind it, dimmed and masked from the top — the copy always wins.
   --------------------------------------------------------------------------- */
@media (max-width: 960px){
  /* Direct `left`/`right`, not the properties — there is one column here, so
     the zig-zag is off rather than mirrored, and setting `--pane-left` would
     lose to `.film[data-side="left"]`, which is the more specific selector
     whatever media query it is read inside. */
  .pane{
    left: var(--wrap-pad);
    right: var(--wrap-pad);
    height: min(72svh, 34rem);
  }
  .panel{
    justify-items: stretch;
    padding: clamp(1.4rem, 5vw, 2rem);
  }
  .sheet{ width: 100%; }

  /* One column, so the split turns vertical: loose copy at the top, the
     object below it. With the glass gone, an object standing behind the text
     is an object printed over it — scene.js drops the frustum by the same
     amount this leaves free, and the mask fades out whatever of the object
     still reaches up into the copy. The top padding clears film two's run
     title. */
  .film:not(.film-flow) .pane{
    top: var(--header-h);
    transform: none;
    height: min(54svh, 32rem);
  }
  .film:not(.film-flow) .panel{
    align-content: start;
    padding: 3.75rem 0 0;
  }
  .scene{
    --stage-max: .9;
    -webkit-mask-image: linear-gradient(180deg, transparent 44%, #000 64%);
            mask-image: linear-gradient(180deg, transparent 44%, #000 64%);
  }
  .run-title{ left: clamp(1.4rem, 5vw, 2rem); }
}
