/* Main video integration. Load LAST, after all selected/type/motion CSS.
   Body: .main-video; controller vars: --hero-copy, --hero-exit.
   Media URLs remain in the HTML. The approved 16:9 clip was inspected through its final frame.
   Default framing preserves the complete frame. Only opt into
   data-hero-framing="right-safe" after verifying the ENTIRE action stays in
   the rightmost 56.25% of the source on a square portrait video box. */

body.main-video .hero-track { height:350svh; min-height:0; }
body.main-video .hero-stage { height:100svh; min-height:0; }
body.main-video .hero-scene {
  --scene-scale:1; --scene-x:0px; --scene-y:0px;
  transform:none; will-change:auto; background:#06080a;
}
body.main-video .scene-counter { transform:none; will-change:auto; }
body.main-video .character-motion { transform:none!important; filter:none!important; }
body.main-video .hero-video {
  position:absolute; inset:100px 0 0; z-index:1;
  pointer-events:none; background:transparent;
}
body.main-video .hero-video-poster,
body.main-video .hero-scroll-video {
  position:absolute; inset:0; display:block; width:100%; height:100%;
  object-fit:contain; object-position:right bottom;
}
body.main-video .hero-video-poster { opacity:1; }
body.main-video .hero-scroll-video { opacity:0; }
body.main-video[data-hero-video="ready"] .hero-scroll-video { opacity:1; }
body.main-video[data-hero-video="ready"] .hero-video-poster { opacity:0; }
body.main-video:is([data-hero-poster="ready"],[data-hero-video="ready"]) .hero-scene>.backdrop,
body.main-video:is([data-hero-poster="ready"],[data-hero-video="ready"]) .character-position { visibility:hidden; }
body.main-video .scene-type-plane { z-index:2; }
body.main-video .hero-copy { text-shadow:0 2px 20px #0004; }
body.main-video .hero-copy,
body.main-video .film-cue { opacity:var(--hero-copy,1); }
body.main-video .hero-shade { opacity:var(--hero-exit,0); background:#080909; }
body.main-video .hero-bottom { opacity:1; }
body.main-video .hero-media-status {
  position:absolute;left:var(--gutter);top:112px;z-index:8;margin:0;
  max-width:calc(100% - 2*var(--gutter));font:11px/1.5 var(--font-ui);color:#c7c4bb;
  pointer-events:none;
}
body.main-video .hero-media-status[hidden] { display:none; }
body.main-video :is(.dollar-rain,.noir-card-field,.noir-card-shadow,.noir-pose-frame,.light-falloff) { display:none!important; }

/* The text column sits farther right and uses a tighter two-line rhythm.
   Keep the selected display face and the type plane's existing z-index. */
body.main-video {
  --main-copy-left:clamp(52px,6.9vw,146px);
  --main-title-top:20.8svh;
  --main-title-size:clamp(150px,min(20.4vw,32.7svh),336px);
}
body.main-video.type-study .hero-copy {
  left:var(--main-copy-left); top:var(--main-title-top); width:58vw;
}
body.main-video.type-study .hero-copy h1 {
  font-size:var(--main-title-size); line-height:.84; letter-spacing:.018em;
}
body.main-video.type-study .film-cue {
  left:var(--main-copy-left);
  top:calc(var(--main-title-top) + var(--main-title-size)*1.77 + 24px);
  bottom:auto;
}
body.main-video.type-study .hero-bottom { left:var(--main-copy-left); }
@media(min-width:1001px) and (max-height:750px) {
  body.main-video {
    --main-title-top:16svh;
    --main-title-size:min(20.4vw,30svh,calc((79.6svh - 135px)/1.77));
  }
}
@media(min-width:701px) and (max-width:1000px) {
  body.main-video { --main-title-size:min(19vw,30svh); }
}
@media(max-width:700px) {
  body.main-video .hero-media-status { top:78px; }
  body.main-video {
    --main-copy-left:clamp(26px,7.7vw,32px);
    --main-title-top:88px;
    --main-title-size:clamp(56px,min(23.8vw,12.2svh),112px);
    --main-control-rail:calc(52px + env(safe-area-inset-bottom,0px));
  }
  body.main-video .hero-track { height:340svh; }
  body.main-video.type-study .hero-copy {
    top:var(--main-title-top); left:var(--main-copy-left);
    width:calc(100% - var(--main-copy-left) - var(--gutter,24px));
  }
  body.main-video.type-study .hero-copy h1 {
    font-size:var(--main-title-size); line-height:.88;
  }
  body.main-video .hero-video {
    inset:auto 0 var(--main-control-rail);
    width:100%; height:auto; aspect-ratio:9/10;
    max-height:calc(100svh - var(--main-title-top) - var(--main-title-size)*1.85 - 76px - var(--main-control-rail));
  }
  body.main-video.type-study .film-cue {
    top:calc(var(--main-title-top) + var(--main-title-size)*1.85 + 12px);
    bottom:auto; left:var(--main-copy-left);
    max-width:none; min-height:48px;
  }
  body.main-video.type-study .hero-bottom {
    left:var(--main-copy-left); right:var(--gutter,24px);
    bottom:calc(8px + env(safe-area-inset-bottom,0px));
    height:44px; align-items:center;
  }
  body.main-video.type-study .hero-bottom .motion-toggle {
    position:static; min-height:44px; padding:8px 0;
  }
  body.main-video .scroll-cue { min-height:44px; justify-content:center; }
  body.main-video .scroll-line { display:none; }
  /* Optional portrait crop. Default contain remains safe before pixel review. */
  body.main-video[data-hero-framing="right-safe"] .hero-video-poster,
  body.main-video[data-hero-framing="right-safe"] .hero-scroll-video {
    object-fit:cover; object-position:100% 50%;
  }
}

/* Short landscape needs columns: stacking would leave no useful video area.
   At 667x375 the video box is y64..323 and about438px wide after the stable
   scrollbar gutter. Title/control column stays to its left. */
@media(max-width:1000px) and (max-height:500px) and (orientation:landscape) {
  body.main-video .hero-media-status { top:60px; }
  body.main-video { --gutter:20px; }
  body.main-video .header,
  body.main-video .header.is-scrolled { height:56px; }
  body.main-video .hero-stage { height:100svh; min-height:0; }
  body.main-video.type-study .hero-copy {
    top:78px; left:26px; width:30vw;
  }
  body.main-video.type-study .hero-copy h1 {
    font-size:clamp(48px,min(14.4vw,21svh),94px); line-height:.88;
  }
  body.main-video .hero-video {
    inset:64px 12px calc(52px + env(safe-area-inset-bottom,0px)) 31%;
    width:auto; height:auto; max-height:none; aspect-ratio:auto;
  }
  body.main-video .hero-video-poster,
  body.main-video .hero-scroll-video,
  body.main-video[data-hero-framing="right-safe"] .hero-video-poster,
  body.main-video[data-hero-framing="right-safe"] .hero-scroll-video {
    object-fit:contain; object-position:right bottom;
  }
  body.main-video.type-study .film-cue {
    top:auto; bottom:calc(68px + env(safe-area-inset-bottom,0px));
    left:26px; max-width:30vw; min-height:48px; gap:10px;
  }
  body.main-video.type-study .hero-bottom {
    left:26px; right:20px;
    bottom:calc(8px + env(safe-area-inset-bottom,0px));
    height:44px; align-items:center;
  }
  body.main-video.type-study .hero-bottom .motion-toggle { position:static; padding:8px 0; }
  body.main-video .scroll-line { display:none; }
}

/* JS static/reduced-motion uses the matching poster. Without JavaScript,
   use the existing legacy still so a missing new poster cannot blank the hero.
   Reset inherited 560/580/600px minimums in all static paths. */
html.no-motion body.main-video .hero-track,
body.main-video.no-motion .hero-track { height:100svh; min-height:0; }
html.no-motion body.main-video .hero-stage,
body.main-video.no-motion .hero-stage { position:relative; height:100svh; min-height:0; }
body.main-video.no-js .hero-scroll-video,
html.no-motion body.main-video .hero-scroll-video,
body.main-video.no-motion .hero-scroll-video { opacity:0!important; }
body.main-video.no-js .hero-video-poster,
html.no-motion body.main-video .hero-video-poster,
body.main-video.no-motion .hero-video-poster { opacity:1!important; }
body.main-video.no-js .hero-video { display:none; }
body.main-video.no-js .hero-scene>.backdrop,
body.main-video.no-js .character-position { visibility:visible; }
html.no-motion body.main-video .hero-shade,
body.main-video.no-motion .hero-shade { opacity:0; }
html.no-motion body.main-video :is(.hero-copy,.film-cue),
body.main-video.no-motion :is(.hero-copy,.film-cue) { opacity:1; }

body.main-video[data-hero-poster="error"][data-hero-video="error"] .hero-video,
html.no-motion body.main-video[data-hero-poster="error"] .hero-video,
body.main-video.no-motion[data-hero-poster="error"] .hero-video { display:none; }
body.main-video[data-hero-poster="error"][data-hero-video="error"] :is(.hero-scene>.backdrop,.character-position),
html.no-motion body.main-video[data-hero-poster="error"] :is(.hero-scene>.backdrop,.character-position),
body.main-video.no-motion[data-hero-poster="error"] :is(.hero-scene>.backdrop,.character-position) { visibility:visible; }

@media(prefers-reduced-motion:reduce) {
  body.main-video .hero-track { height:100svh; min-height:0; }
  body.main-video .hero-stage { position:relative; height:100svh; min-height:0; }
  body.main-video .hero-scroll-video { opacity:0!important; }
  body.main-video .hero-video-poster { opacity:1!important; }
  body.main-video .hero-shade { opacity:0; }
  body.main-video :is(.hero-copy,.film-cue) { opacity:1; }
  body.main-video[data-hero-poster="error"] .hero-video { display:none; }
  body.main-video[data-hero-poster="error"] :is(.hero-scene>.backdrop,.character-position) { visibility:visible; }
}
