/* How the works column hands over on scroll (works-scroll.js). "Selected
   works" takes the first screen whole; everything after it is one sheet. On
   desktop the works hold still and fall out of focus while the sheet rises
   over them, and the charts of "The grind" draw themselves as it arrives. */

/* Registered so it stays on the element that reads it: an inherited value
   would restyle every row of the works on every scroll frame. */
@property --recede {
    syntax: "<number>";
    inherits: false;
    initial-value: 0;
}

/* The works' own height, from JS. Kept on the section for the same reason. */
@property --projects-h {
    syntax: "<length>";
    inherits: false;
    initial-value: 0px;
}

/* Bleeds to the column's edges and repeats its inset, so the sheet's own
   background covers whatever it rises over. */
.works__sheet {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    margin: calc(80px - var(--works-pad-top)) calc(-1 * var(--works-pad-x)) 0;
    padding: var(--works-pad-top) var(--works-pad-x) var(--works-pad-bottom);
    background: var(--bg);
}

.works__sheet .grind {
    flex: 1;
}

@media (min-width: 901px) {
    /* A screen of its own: the sheet starts below the fold, and the body
       under the heading takes the whole height that leaves (the stage layout
       spreads its index over it, project-stage.css). */
    .projects {
        display: flex;
        flex-direction: column;
        min-height: calc(100dvh - var(--works-pad-top));
        padding-bottom: var(--works-pad-bottom);
    }

    .projects__body {
        flex: 1;
    }

    /* Pinned where it sat. Taller than the window (--projects-h, from JS), it
       scrolls until its last row is on screen and holds there instead. */
    .works.has-sheet .projects {
        position: sticky;
        top: min(var(--works-pad-top), calc(100dvh - var(--projects-h)));
    }

    .works.has-sheet .works__sheet {
        min-height: 100dvh;
        margin-top: 0;
        border-top: 1px solid var(--line);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        box-shadow: 0 -32px 64px -24px rgb(0 0 0 / 0.6);
        /* The shadow falls on the works above, never sideways onto the bio. */
        clip-path: inset(-96px 0 0);
    }

    /* --recede runs 0 to 1 with the sheet's rise. The class is only on while
       it is above 0, so a works list at rest carries no filter at all. Out of
       focus it is out of reach too: a pointer crossing it on the way to the
       sheet moves no row and changes no project on the stage. */
    .works.has-sheet .projects.is-receding {
        pointer-events: none;
        filter: blur(calc(var(--recede) * 6px));
        opacity: calc(1 - var(--recede) * 0.65);
        transform: scale(calc(1 - var(--recede) * 0.025));
    }

    /* Fully under the sheet: nothing left to draw behind its round corners. */
    .works.has-sheet .projects.is-covered {
        visibility: hidden;
    }
}

/* ── the grind's arrival (grind-reveal.js) ──
   The two charts draw themselves as they come up the screen; the words and
   the lists around them are simply there. A chart starts unlit (.is-staged)
   and JS marks its pieces .is-lit in order; these transitions are all the
   motion there is, so scrolling back simply unlights them. They wait for the
   arrival to begin (.is-arriving): on from the start, they would play the
   charts going dark, off screen, while the page is still coming in. */

/* A week lights top to bottom (--row), so the year sweeps in on a slant. */
.grind.is-arriving .heatmap__cell {
    transition:
        background-color 600ms var(--ease-smooth-out) calc(var(--row, 0) * 30ms),
        opacity 200ms ease,
        box-shadow 120ms ease-out;
}

.grind.is-staged .heatmap__cell:not(.is-lit) {
    background-color: var(--raised);
}

/* The hours come up one after another, clockwise from midnight, each growing
   out of the rim to its height. */
.grind.is-arriving .dial__bar {
    transition:
        stroke 200ms var(--ease-smooth-out),
        opacity 400ms var(--ease-smooth-out),
        stroke-dashoffset var(--duration-very-slow) var(--ease-smooth-out);
}

.grind.is-staged .dial__bar:not(.is-lit) {
    opacity: 0;
    stroke-dashoffset: 1;
}
