/* ========================= PRELOADER ========================= */

/*
 * Covers the Home page from the first render until
 * js/hero-intro.js has put the hero in its starting
 * state, so the finished hero never flashes before
 * the intro. A counter (inline script in index.html)
 * runs from 0% while the page loads and on to 100%
 * when the hero is ready; hero-intro.js then fades
 * the preloader out (.is-hidden).
 *
 * Failsafe without JavaScript: after 8s it fades out
 * on its own, and hero-intro.js then skips the intro.
 * No JavaScript at all: hidden by a <noscript> style
 * in index.html.
 */

.preloader {
    position: fixed;
    inset: 0;
    z-index: 1000;

    display: flex;
    align-items: center;
    justify-content: center;

    background-color: var(--color-background);

    animation: preloader-failsafe 0.5s ease 8s forwards;
}

/*
 * Counter: always as wide as "100%" (4 characters of
 * Geist Mono), so it never changes width. The digits
 * sit to the right, so the % sign and the units stay
 * in place while the tens and hundreds arrive.
 *
 * Geist Mono 350 with its plain zero (ss09) matches
 * the reference. Shown once the font is ready (or
 * after 2.5s), so no fallback font ever flashes.
 *
 * Sized like the Geist Mono subtitles (.hero__subtitle):
 * min(24px, 2.34svh) on Desktop, 22px on Tablet and
 * 16px on Mobile (below).
 */

.preloader__counter {
    position: relative;

    width: 4ch;

    font-family: var(--font-mono);
    font-size: min(var(--font-subtitle-desktop), 2.34svh);
    font-weight: 350;
    font-feature-settings: "ss09";
    font-variant-numeric: tabular-nums;
    line-height: 1;

    text-align: right;
    white-space: nowrap;

    color: var(--color-text);

    opacity: 0;

    transition: opacity 0.2s ease;
}

.preloader__counter.is-ready {
    opacity: 1;
}

@media (min-width: 768px) and (max-width: 1024.98px) {
    .preloader__counter {
        font-size: var(--font-subtitle-tablet);
    }
}

@media (max-width: 767.98px) {
    .preloader__counter {
        font-size: 16px;
    }
}

/*
 * The line under the number, in the reference's
 * proportions at every size: 1.5px at 26px, 9.5px
 * under the baseline, reaching 2px past the "100%"
 * ink on each side. All of it is set in em, so it
 * scales with the counter. It grows from the left in
 * step with the count (scaleX, set by the counter
 * script).
 *
 * Drawn twice as tall and halved with scaleY: a
 * transform is not snapped to whole pixels, so the
 * line keeps its exact weight on every screen density.
 */

.preloader__line {
    position: absolute;
    top: 1.225em;
    left: -0.017em;
    right: -0.067em;

    height: calc(3em / 26);

    background-color: currentColor;

    transform: scaleX(0) scaleY(0.5);
    transform-origin: left top;
}

.preloader.is-hidden {
    opacity: 0;
    visibility: hidden;

    pointer-events: none;

    animation: none;

    transition:
        opacity 0.5s ease,
        visibility 0s linear 0.5s;
}

@keyframes preloader-failsafe {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

/*
 * Reduced motion has no intro to cover (the hero is
 * shown as it is), and high contrast keeps the page
 * colours: no preloader for either.
 */

@media (prefers-reduced-motion: reduce), (forced-colors: active) {
    .preloader {
        display: none;
    }
}


/* ========================= HERO ========================= */

.hero {
    height: 100svh;

    display: grid;

    grid-template-rows:
        80px
        1fr
        auto
        1fr
        auto
        48px;

    overflow: hidden;
}


/* ========================= HERO — MAIN CONTENT ========================= */

.hero__content {
    grid-row: 3;

    width: fit-content;

    display: flex;
    align-items: center;
    gap: var(--space-16);

    margin-inline: auto;
}


/* Media */

.hero__media {
    width: min(353px, 34.5svh);
    aspect-ratio: 353 / 470;

    flex-shrink: 0;

    overflow: hidden;
    border-radius: 24px;
}

.hero__media video {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
}


/* Text */

.hero__text {
    display: flex;
    flex-direction: column;
}

.hero__title {
    margin: 0;

    font-family: var(--font-display);
    font-size: min(var(--font-display-desktop), 10.94svh);
    font-weight: var(--weight-bold);

    line-height: 0.85;
    letter-spacing: 0;
}

.hero__subtitle {
    margin: var(--space-8) 0 0;

    font-family: var(--font-mono);
    font-size: min(var(--font-subtitle-desktop), 2.34svh);
    font-weight: var(--weight-regular);

    line-height: 1.2;
}


/* ========================= HERO — MARQUEE ========================= */

.hero__marquee {
    grid-row: 5;

    width: 100%;

    overflow: hidden;
}

.hero__marquee-track {
    width: max-content;

    display: flex;
    align-items: center;

    /*
     * One loop is 1299px at 16px, so 21.605s keeps
     * the Desktop speed of about 60.1px/s.
     */

    animation: hero-marquee 21.605s linear infinite;
}

.hero__marquee-group {
    display: flex;
    align-items: center;

    gap: var(--marquee-gap);
    padding-right: var(--marquee-gap);

    flex-shrink: 0;
}

.hero__marquee span {
    font-family: var(--font-mono);
    font-size: var(--font-label-desktop);
    font-weight: var(--weight-regular);

    line-height: 1.2;
    white-space: nowrap;
}


/*
 * Infinite movement. The track holds three copies
 * of the tags and moves by exactly one per loop,
 * so the strip stays covered on screens up to two
 * copies wide (about 2600px at 16px). With only
 * two copies, a loop shorter than the strip left a
 * gap at its end.
 */

@keyframes hero-marquee {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(calc(-100% / 3));
    }
}

.hero__marquee {
    opacity: 0;
    visibility: hidden;
}

/* Accessibility */

/*
 * Reduced motion starts the loop paused; the
 * motion toggle (js/motion-toggle.js) pauses
 * or plays it for everyone.
 */

@media (prefers-reduced-motion: reduce) {
    .hero__marquee-track {
        animation-play-state: paused;
    }
}

[data-motion="paused"] .hero__marquee-track {
    animation-play-state: paused;
}

[data-motion="playing"] .hero__marquee-track {
    animation-play-state: running;
}

/* ========================= HERO — INTRO ANIMATION ========================= */

.hero__media {
    position: relative;
    z-index: 2;

    will-change: transform, clip-path;
}

.hero__text {
    position: relative;
    z-index: 1;

    will-change: transform, clip-path;
}

/* =========================
   DESKTOP
========================= */

@media (min-width: 1025px) {

    /*
     * The marquee has its own Desktop size: 16px on
     * shorter screens, growing with the screen height
     * to 18px at 1024px tall. Its row in the Hero
     * grid keeps the height of the 16px label line it
     * was laid out with (16px × 1.2), so the media,
     * the text and the Hero height stay where they
     * are.
     *
     * The line keeps that line's leading (16px × 0.2)
     * and grows upward from the row's bottom edge, so
     * the text stays on the same baseline.
     */

    .hero__marquee-track {
        height: calc(var(--font-label-desktop) * 1.2);

        align-items: flex-end;
    }

    .hero__marquee span {
        font-size: clamp(
            var(--font-label-desktop),
            1.76svh,
            var(--font-marquee-desktop)
        );
        line-height: calc(1em + var(--font-label-desktop) * 0.2);
    }
}

/* =========================
   TABLET
========================= */

@media (min-width: 768px) and (max-width: 1024.98px) {

    .hero {
        grid-template-rows:
            72px
            1fr
            auto
            1fr
            auto
            40px;
    }


    /* =========================
       MAIN CONTENT
    ========================= */

    .hero__content {
        gap: 14px;

        max-width: calc(100% - 64px);
    }


    /* Media */

    .hero__media {
        width: 300px;

        border-radius: 20px;
    }


    /* Text */

    .hero__title {
        font-size: var(--font-display-tablet);

        line-height: 0.85;
    }


    .hero__subtitle {
        margin-top: 6px;

        font-size: var(--font-subtitle-tablet);

        line-height: 1.2;
    }


    /* =========================
       MARQUEE
    ========================= */

    /*
     * The marquee row keeps the height of the 12px
     * line the Tablet Hero was laid out with (12px ×
     * 1.2), so the Hero content stays where it is.
     * The 16px line keeps that line's leading (12px ×
     * 0.2) and grows upward from the row's bottom
     * edge, so the text stays on the same baseline.
     *
     * Its tallest letters reach just past that row,
     * so the strip only clips sideways, where the
     * track moves. A clipping (non-scrolling) box
     * loses the zero minimum width of a scroll
     * container, so it is set back here; otherwise
     * the track would widen the Hero's grid column.
     *
     * The 16px loop is 1235.27px long, so it runs
     * for 26.989s (1235.27 / 45.77) and keeps the
     * Tablet speed of about 45.8px/s.
     */

    .hero__marquee {
        min-width: 0;

        overflow-x: clip;
        overflow-y: visible;
    }

    .hero__marquee-track {
        height: calc(12px * 1.2);

        align-items: flex-end;

        animation-duration: 26.989s;
    }

    .hero__marquee-group {
        gap: var(--marquee-gap);

        padding-right: var(--marquee-gap);
    }


    .hero__marquee span {
        font-size: var(--font-marquee-tablet);

        line-height: calc(1em + 12px * 0.2);
    }
}

/* =========================
   MOBILE
========================= */

@media (max-width: 767.98px) {

    /*
     * The heading runs from 48px (up to 393px wide)
     * to 54px (430px).
     *
     * The title, subtitle and video stay one group,
     * centred in the height the browser leaves
     * visible (100svh: the screen with its bars
     * shown). The first row is as tall as the
     * marquee row and the space under it, so the two
     * 1fr rows around the group are equal and its
     * middle sits at 50svh on every screen.
     *
     * The marquee sits 24px above the bottom edge,
     * plus the bottom safe area wherever the browser
     * reports one (0 in a normal Safari page), so it
     * stays clear of the browser's bottom bar. The
     * open menu covers the page (nav.css), so the
     * Hero needs no room for it.
     */

    .hero {
        --hero-title-size: clamp(48px, calc(16.22vw - 15.73px), 54px);

        --hero-bottom-space: calc(
            var(--space-24) + env(safe-area-inset-bottom, 0px)
        );

        height: 100svh;

        grid-template-rows:
            calc(11px * 1.2 + var(--hero-bottom-space))
            1fr
            auto
            1fr
            auto
            var(--hero-bottom-space);
    }


    /* =========================
       MAIN CONTENT
    ========================= */

    .hero__content {
        grid-row: 3;

        width: 234px;
        max-width: none;

        flex-direction: column;
        align-items: flex-start;

        gap: var(--space-12);

        margin-inline: auto;
    }


    /* =========================
       TEXT
    ========================= */

    .hero__text {
        order: 1;

        width: 100%;
    }

    .hero__title {
        font-size: var(--hero-title-size);

        line-height: 0.86;
    }

    .hero__subtitle {
        margin-top: var(--space-8);

        font-size: 16px;

        line-height: 1.1;
    }


    /* =========================
       MEDIA
    ========================= */

    .hero__media {
        order: 2;

        width: 234px;

        border-radius: 20px;
    }


    /* =========================
       MARQUEE
    ========================= */

    /*
     * The marquee row keeps the height of the 11px
     * line the Mobile Hero was laid out with (11px x
     * 1.2), so the Hero content stays where it is.
     * The 14px line keeps that line's leading (11px x
     * 0.2) and grows upward from the row's bottom
     * edge, so the text stays on the same baseline.
     *
     * Its tallest letters reach just past that row,
     * so the strip only clips sideways, where the
     * track moves. A clipping (non-scrolling) box
     * loses the zero minimum width of a scroll
     * container, so it is set back here; otherwise
     * the track would widen the Hero's grid column.
     *
     * The 14px loop is 1048.84px long, so it runs
     * for 26.105s (1048.84 / 40.18) and keeps the
     * Mobile speed of about 40.2px/s.
     */

    .hero__marquee {
        grid-row: 5;

        min-width: 0;

        overflow-x: clip;
        overflow-y: visible;
    }

    .hero__marquee-track {
        height: calc(11px * 1.2);

        align-items: flex-end;

        animation-duration: 26.105s;
    }

    .hero__marquee-group {
        gap: var(--marquee-gap);
        padding-right: var(--marquee-gap);
    }

    .hero__marquee span {
        font-size: var(--font-marquee-mobile);
        line-height: calc(1em + 11px * 0.2);
    }
}

/* =========================
   HERO — PHONE LANDSCAPE
========================= */

/*
 * The 300px Tablet video is taller than a phone held
 * sideways. Here it takes the height left by the nav
 * row, the marquee and the bottom row (72 + 14.4 + 40,
 * plus 16px around the composition), at its own
 * 353:470 shape, and never grows past 300px.
 */

@media (min-width: 768px) and (max-width: 1024.98px) and (orientation: landscape) and (max-height: 500px) {

    .hero__media {
        width: min(
            300px,
            calc((100svh - 158.4px) * 353 / 470)
        );
    }
}


/*
 * A Mobile-width phone held sideways takes the row
 * composition as well: the video beside the title, as on
 * Tablet and Desktop, at the Mobile type sizes. The video
 * takes the height left by the Mobile nav row, the marquee
 * and the bottom row (48 + 13.2 + 32, plus 16px around the
 * composition), at its own 353:470 shape, and never grows
 * past the 234px Mobile video.
 */

@media (max-width: 767.98px) and (orientation: landscape) and (max-height: 500px) {

    /*
     * The row composition keeps its own rows: the
     * 48px nav row above it, the marquee 32px from
     * the bottom.
     */

    .hero {
        grid-template-rows:
            48px
            1fr
            auto
            1fr
            auto
            32px;
    }

    .hero__content {
        width: fit-content;

        flex-direction: row;
        align-items: center;
    }

    .hero__text {
        order: 0;

        width: auto;
    }

    .hero__media {
        order: 0;

        width: min(
            234px,
            calc((100svh - 125.2px) * 353 / 470)
        );
    }
}
