/* Home film: a fixed stage holds the three screens. Each transition takes 55lvh
   of native scrolling; film.js maps that shorter travel onto the full animation.
   Adding the visible height keeps the range stable as Safari's toolbar moves.
   No scroll snap or input interception: the page rests wherever the reader stops. */

/* Everything below applies once film-boot.js has run in the head (it sets .film-on on <html>, so the
   first paint is already the stage). It takes the class off again if film.js fails to load or run, and
   film.js does too if its first layout throws: the page is then an ordinary scrolling page, and --film-p
   stays undefined so home-builds' parts show in place. */
html.film-on {
    scrollbar-gutter: stable;
    scrollbar-width: none;
    overflow-x: clip;
    overscroll-behavior: none;
}

html.film-on::-webkit-scrollbar {
    display: none;
}

html.film-on body {
    height: calc(110lvh + 100dvh);
}

/* An open dialog or a Talk press waiting for the page to reach the top locks the page scroll: scrollY and the frame stay */
html.film-on:has(dialog[open]),
html.film-on[data-nova-opening] {
    overflow: hidden;
}

.film-on .film {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 100lvh;
    overflow: hidden;
    touch-action: pan-y pinch-zoom;
}

/* Keep tap targets and typed text comfortable as the surrounding scene gets smaller. */
.film-on :is(.hero-talk, .hero-builds, .builds-talk, .builds-all-link,
    .live-talk, .live-email-input, .live-email-button, .live-follow) {
    min-height: calc(44px / var(--film-page-scale, 1));
}

.film-on .live-email-input {
    font-size: calc(16px / var(--film-page-scale, 1));
}

.film-on .live-email-note {
    padding-bottom: max(0px, calc((44px / var(--film-page-scale, 1) - 1.5em) / 2));
}

.film-on .live-email-note a {
    padding-block: calc((44px / var(--film-page-scale, 1) - 1.2em) / 2);
}

/* Screens: one stage height tall, stacked from the top. Each screen's own id rule sets its
   position and height, so these selectors carry an id as well. The translate is the first
   frame's place until film.js writes the live one. */
.film-on .film > #hero,
.film-on .film > #builds,
.film-on .film > #live {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    transform-origin: top center;
}

/* Bundles leave about a point 50% across and 30% down the screen. */
.film-on .film > #builds {
    translate: 0 100%;
    transform-origin: 50% 30%;
}

/* The wordmark is clear and 8 px left of its place until film.js writes it (it comes in over 260 to 700 px) */
.film-on .au-bar-name {
    opacity: 0;
    translate: -8px 0;
}

/* The first screen's words fade with --head-op. It is a filter, not opacity: the open conversation fades the words with
   an opacity rule and a .3s transition (nova-stage.css), and the transition would lag the scroll's own fade behind the
   scroll. Both stack, and they are the same fade. */
.film-on .hero-words {
    filter: opacity(var(--head-op, 1));
}

/* The star field moves 0.25 of the position as one layer, so it is drawn 1.5 windows tall (1 + 0.25 x 2): no band without
   stars shows at the last stop, where it has moved up half a window */
.film-on .au-stars {
    height: 150lvh;
}

/* One quiet sky across the whole film. Depth comes from small stars rather
   than section-sized light pools or unrelated drifting pixel clouds. */
.film-on .au-stars-far {
    opacity: .55;
}

.film-on .au-stars-mid {
    opacity: .75;
}

.film-on .au-stars-near {
    opacity: .9;
}

.film-on .film > #live {
    translate: 0 200%;
}

/* Readable content arrives independently of the figures' full-screen travel.
   Its existing small rises and fades still run inside these shared layers. */
.builds-content {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.builds-content > * {
    pointer-events: auto;
}

.live-arrival {
    display: flex;
    flex-direction: inherit;
    align-items: inherit;
    gap: inherit;
    width: 100%;
}

/* The fixed film clips to the viewport, so a screen need not clip as well. The fit counts a screen's overflow (home-scroll-film
   [GHC9MP]), which scales the box smaller than the content it holds: with the screen's own clip kept (builds.css overflow: clip), the
   scaled box ended above its lower controls and left their last pixels dead (844 by 390: box 0 to 375.6, "See all bundles" to 390.3).
   So the box never clips what the fit counted. Incoming words may also paint above their travelling screen instead of waiting
   below it after the old one fades. */
.film-on #builds[style*="--film-p"],
.film-on #live[style*="--film-p"] {
    overflow: visible;
}

/* With reduced motion the screens stay stacked at full opacity, so what a screen draws above its own top edge (the bundles screen's
   star field reaches 600 px above it) would paint on the screen above it. The clip stays at the top edge; the sides and the bottom are open. */
@media (scripting: enabled) and (prefers-reduced-motion: reduce) {
    .film-on #builds[style*="--film-p"],
    .film-on #live[style*="--film-p"] {
        clip-path: inset(0 -100vmax -100vmax);
    }
}

@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
    .film-on #builds[style*="--film-p"] .builds-content {
        translate: 0 calc(-1 * max(0, 1 - var(--film-p)) * 100lvh / var(--film-fit));
    }

    /* Let the outgoing title rise at half speed: it stays readable in a
       short window, while clearing the incoming Live heading. */
    .film-on #builds[style*="--film-p"] .builds-head {
        translate: 0 calc((1 - var(--v)) * var(--rise) * var(--bu) + max(0, var(--film-p) - 1) * 50lvh / var(--film-fit));
    }

    /* Loading and error messages keep their original screen-local position. */
    .film-on #builds[style*="--film-p"] .builds-status {
        translate: 0 calc(max(0, 1 - var(--film-p)) * 100lvh / var(--film-fit));
    }

    /* The whole final screen arrives together, including its footer. */
    .film-on #live[style*="--film-p"] .live-arrival,
    .film-on #live[style*="--film-p"] .live-foot {
        translate: 0 calc(-1 * max(0, 2 - var(--film-p)) * 100lvh / var(--film-fit));
    }
}

/* Once the scroll has faded the star art out (film.js marks it data-film-off) its endless pixel animations stop; the
   one-shot intro animations are not touched, so scrolling back finds the art as it was. */
.film-on .nova-stage[data-film-off] :is(.nova-dot-twinkle, .nova-dot-drift, .nova-px-twinkle, .nova-px-drift) {
    animation-play-state: paused;
}

/* The star field holds its twinkle while the page moves (film.js marks <html> data-film-moving from a frame that
   changed S to the first one that did not), so a scroll frame restyles no star */
html[data-film-moving] .au-star {
    animation-play-state: paused;
}

/* The bar's 3D logo and eyes run only while the page rests on a screen: film.js marks <html> data-film-rest while S is within
   1 px of 0, H or 2H and the page is not moving, and data-film-moving while it moves (so the first rule is the second's
   moving case). The twinkle and the shooting stars keep running at a rest. */
html[data-film-ready][data-film-moving] :is(.au-logo-float, .au-logo-sway, .au-logo-ring, .au-eye),
html[data-film-ready]:not([data-film-rest]) :is(.au-logo-float, .au-logo-sway, .au-logo-ring, .au-eye) {
    animation-play-state: paused;
}

/* Pixel flow: 266 dots over the screens, never hit, never read */
[data-film-dots] {
    display: none;
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    perspective: 900px;
}

/* The board's .au-flow rule (Final.dc.html:111), selector only changed */
[data-film-dots] > div{position:absolute;left:0;top:0;--a:clamp(0, (var(--s) - var(--da)) / 0.56, 1);--b:clamp(0, (var(--s) - var(--db)) / 0.5, 1);--ea:calc(var(--a) * var(--a) * (3 - 2 * var(--a)));--eb:calc(var(--b) * var(--b) * (3 - 2 * var(--b)));--ma:calc(4 * var(--ea) * (1 - var(--ea)));--mb:calc(4 * var(--eb) * (1 - var(--eb)));transform:translate(calc((var(--x0) + (var(--x1) - var(--x0)) * var(--ea) + (var(--x2) - var(--x1)) * var(--eb) + var(--ma) * var(--qx) + var(--mb) * var(--rx)) * 1px), calc((var(--y0) - 0.48 * var(--sy) + (var(--y1) + var(--H) - var(--y0) - 0.52 * var(--sy)) * var(--ea) + (var(--y2) + var(--H) - var(--y1)) * var(--eb) + var(--ma) * var(--qy) + var(--mb) * var(--ry)) * 1px)) rotate(calc((var(--ma) + var(--mb)) * var(--r) * 1deg)) scale(calc(1 + (var(--k1) - 1) * var(--ea) + (var(--k2) - var(--k1)) * var(--eb) + 0.5 * (var(--ma) + var(--mb))));opacity:calc(var(--o) * var(--po))}

/* The fixed layer: the streaks and the shooting stars, above the star field and under every screen
   (it is first in the stage). Its frame units are the hero's (hero.css), so a shooting star starts where the board puts it.
   Nothing here takes a press, and none of it shows under reduced motion. */
.film-fx {
    --hu: min(1px, 100vw / 1440, 100lvh / 900);
    --fx: calc(50% - 720 * var(--hu));
    --fy: calc(50% - 450 * var(--hu));
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

@media not all and (min-width: 900px) {
    .film-fx {
        --hu: min(1px, 100vw / 390, 100lvh / 844);
        --fx: calc(50% - 195 * var(--hu));
        --fy: calc(50% - 422 * var(--hu));
    }
}

@media (prefers-reduced-motion: reduce) {
    .film-fx {
        display: none;
    }
}

/* film.js writes --v (the smoothed speed) on the layer and each streak's place, --k and --o (the board's .hs-str) */
.film-streaks {
    position: absolute;
    inset: 0;
    --v: 0;
}

.film-streak {
    position: absolute;
    width: 1.6px;
    height: 5px;
    margin: -2.5px 0 0 -.8px;
    border-radius: 2px;
    background: linear-gradient(180deg, rgba(214, 219, 255, 0) 0%, rgba(240, 242, 255, .95) 50%, rgba(214, 219, 255, 0) 100%);
    transform: scaleY(calc(1 + var(--v) * var(--k)));
    opacity: calc(var(--v) * var(--o));
}

/* Shooting stars (the board's .hs-shoot and au-shoot): film.js sets each one's start, length, period and first delay.
   Each flies 560 px left and 250 px down in the first 9% of its loop. */
.film-shoot {
    position: absolute;
    height: 1.2px;
    border-radius: 1px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(220, 224, 255, .9));
    opacity: 0;
    transform: rotate(-24deg);
    animation: film-shoot linear infinite;
}

.film-shoot::after {
    content: "";
    position: absolute;
    right: -2px;
    top: -1.4px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 0 10px 3px rgba(170, 176, 255, .75);
}

@keyframes film-shoot{0%{transform:translate(0,0) rotate(-24deg);opacity:0}2%{opacity:1}9%{transform:translate(calc(-560 * var(--hu)),calc(250 * var(--hu))) rotate(-24deg);opacity:0}100%{transform:translate(calc(-560 * var(--hu)),calc(250 * var(--hu))) rotate(-24deg);opacity:0}}

/* The open conversation hides the shooting stars */
html[data-au-overlay="voice"] .film-shoots {
    visibility: hidden;
}

/* The board's radial vignette and grain, laid once over the whole window above the screens and the dots (z 6) and under the bar (z 10).
   Two siblings with their own z-index, so the grain's screen blend reaches the screens behind it. */
.film-vignette,
.film-grain {
    position: fixed;
    inset: 0;
    z-index: 7;
    pointer-events: none;
}

.film-vignette {
    background: radial-gradient(ellipse 75% 70% at 50% 45%, rgba(3, 3, 10, 0) 55%, rgba(3, 3, 10, 0.55) 100%);
}

/* The vignette dims a lime pill's keyboard ring to about 1.6-2.9:1, so it steps aside while a lime pill holds keyboard focus. */
.film:has(.hero-talk:focus-visible) > .film-vignette,
.film:has(.hero-builds:focus-visible) > .film-vignette,
.film:has(.builds-all-link:focus-visible) > .film-vignette,
.film:has(.builds-talk:focus-visible) > .film-vignette,
.film:has(.live-talk:focus-visible) > .film-vignette,
.film:has(.live-email-button:focus-visible) > .film-vignette {
    opacity: 0;
}

.film-grain {
    opacity: .018;
    mix-blend-mode: screen;
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 160px 160px;
}

/* The film moves focus to the new screen's heading after a key or button move; no ring marks it */
[data-film-heading]:focus-visible {
    outline: none;
}
