/* =========================
   WORKS INTRO
========================= */

.works-intro {
    position: relative;

    width: 100%;
    height: 145svh;

    margin-top: -100svh;

    z-index: 4;

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


/* =========================
   STICKY PANEL
========================= */

.works-intro__inner {
    position: sticky;
    top: 0;

    width: 100%;
    height: 100svh;

    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;

    padding-inline: 7.5vw;

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

    /*
     * Dá a sensação de um painel novo
     * chegando por cima da About.
     */
    border-radius: 16px 16px 0 0;

    box-shadow:
        0 -12px 40px rgba(33, 33, 33, 0.045);

    overflow: hidden;
}


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

.works-intro__text-mask {
    overflow: hidden;
}

.works-intro__text {
    margin: 0;

    font-family: var(--font-mono);

    font-size: min(
        var(--font-body-desktop),
        1.95svh
    );

    font-weight: var(--weight-regular);

    line-height: 1.35;

    color: var(--color-text);
}


/* =========================
   IMAGE
========================= */

.works-intro__image-mask {
    width: 312px;

    overflow: hidden;
}

.works-intro__image {
    display: block;

    width: 100%;
    height: auto;

    object-fit: cover;
}

/* =========================
   TYPEWRITER CURSOR
========================= */

.works-intro__text.is-typing::after {
    content: "";

    display: inline-block;

    width: 1px;
    height: 1em;

    margin-left: 3px;

    background-color: currentColor;

    vertical-align: -0.08em;

    animation:
        works-intro-cursor 0.75s
        steps(1)
        infinite;
}


@keyframes works-intro-cursor {
    0%,
    49% {
        opacity: 1;
    }

    50%,
    100% {
        opacity: 0;
    }
}

/* =========================
   WORKS INTRO — DESKTOP
========================= */

@media (min-width: 1025px) {

    /*
     * 145svh stage + hold, the section gap Works
     * used to sit below (global.css), then one more
     * screen for Works to slide over the stage.
     *
     * Works takes that screen back with its own
     * -100svh overlap, so it starts and docks
     * exactly where it did, and the stage releases
     * on the same frame Works docks.
     */

    .works-intro {
        height: calc(
            145svh +
            min(120px, 11.72svh) +
            100svh
        );
    }
}

/* =========================
   WORKS INTRO — TABLET
========================= */

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

    /*
     * 100svh sticky stage + 18svh hold, then one
     * more screen for Works to slide over it.
     *
     * Works takes that screen back with its own
     * -100svh overlap, so the page length and the
     * point where Works docks are unchanged, and
     * the stage releases exactly as Works docks.
     */

    .works-intro {
        height: calc(118svh + 100svh);
    }

    .works-intro__text {
        font-size: 18px;
    }
}

/* =========================
   WORKS INTRO — MOBILE
========================= */

@media (max-width: 767.98px) {

    /*
     * The section itself is the panel.
     *
     * It rises over About through the shared
     * -100svh overlap, and its height is made of:
     *
     *   rest   offset that centers the composition
     *          once the panel covers the screen
     *   block  the composition itself
     *   hold   scroll distance the composition stays
     *          uncovered after the panel has docked
     *   cover  one screen for Works to slide over it
     *
     * The composition sits at `rest` inside the panel
     * and sticks at `rest` in the viewport, so it
     * reaches its final position at the exact moment
     * the panel docks and the typewriter starts, and
     * stays there until Works has covered it.
     */

    .works-intro {
        /*
         * Composition: one text line, the gap and
         * the image. works-intro.png is 312 x 297.
         */

        --works-intro-line: calc(var(--font-body-mobile) * 1.35);
        --works-intro-gap: 84px;

        --works-intro-image-width: 234px;
        --works-intro-image-height: calc(
            var(--works-intro-image-width) * 297 / 312
        );

        --works-intro-block: calc(
            var(--works-intro-line) +
            var(--works-intro-gap) +
            var(--works-intro-image-height)
        );


        /*
         * Resting offset, shared by the panel padding
         * and the sticky top.
         */

        --works-intro-rest: max(
            0px,
            calc((100svh - var(--works-intro-block)) / 2)
        );


        /*
         * How long the composition stays fully
         * visible after the panel docks, before
         * Works starts covering it. Adjust freely.
         *
         * Works' top edge enters the screen `hold`
         * minus `rest` after docking, so adding `rest`
         * back makes that 70svh on every screen. The
         * line and the image are tied to the first 70%
         * of it (js/works-intro-transition.js); the last
         * 30% shows them complete before Works arrives,
         * which also absorbs iOS momentum scrolling,
         * where scripts trail the screen.
         */

        --works-intro-hold: calc(var(--works-intro-rest) + 70svh);


        /*
         * The last 100svh is the cover screen. Works
         * takes it back with its own -100svh overlap,
         * so the page length and the point where
         * Works docks are unchanged.
         */

        height: calc(
            var(--works-intro-rest) +
            var(--works-intro-block) +
            var(--works-intro-hold) +
            100svh
        );

        padding-top: var(--works-intro-rest);


        /*
         * The panel edge belongs to the section.
         *
         * Same upward shadow edge as before; the
         * negative spread keeps it from bleeding
         * below the panel onto Works.
         */

        border-radius: 16px 16px 0 0;

        box-shadow:
            0 -40px 40px -28px rgba(33, 33, 33, 0.045);
    }


    /* =========================
       COMPOSITION
    ========================= */

    .works-intro__inner {
        top: var(--works-intro-rest);

        height: auto;

        grid-template-columns: 1fr;

        /*
         * Both rows are reserved up front, so the empty
         * text line and the image, before it loads or
         * reveals, already take their final size.
         */

        grid-template-rows:
            var(--works-intro-line)
            var(--works-intro-image-height);

        align-items: stretch;
        justify-items: start;

        row-gap: var(--works-intro-gap);

        padding-inline: 20px;

        border-radius: 0;
        box-shadow: none;
    }


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

    .works-intro__text {
        font-size: var(--font-body-mobile);
        line-height: 1.35;
    }


    /* =========================
       IMAGE
    ========================= */

    .works-intro__image-mask {
        width: var(--works-intro-image-width);
    }
}
