/* Desktop works layout (project-stage.js): with a hovering pointer and room
   for both, the list turns into a compact index and a stage beside it shows
   the current project. Narrower, or on touch, the list keeps its full rows.
   `has-stage` is on the root from before the first paint (index.html), so the
   list opens in this layout instead of switching to it. */

.projects {
    container: projects / inline-size;
}

.project-stage {
    display: none;
}

@container projects (min-width: 640px) {
    .has-stage .projects__body {
        display: grid;
        grid-template-columns: minmax(250px, 0.75fr) minmax(0, 1.25fr);
        gap: clamp(28px, 5cqi, 48px);
        align-items: start;
        padding-top: 28px;
    }

    /* ── the index: number, name, status dot, year ── */

    /* The index takes whatever height the section gives it (a full screen
       on desktop, works-scroll.css) and its rows share that evenly. */
    .has-stage .project-list {
        counter-reset: project;
        display: grid;
        grid-auto-rows: 1fr;
        align-self: stretch;
    }

    .has-stage .project-list > li {
        display: grid;
    }

    .has-stage .project-card {
        grid-template-columns: 28px minmax(0, 1fr) auto;
        align-content: center;
        align-items: baseline;
        gap: 12px;
        padding: 9px 0;
        color: var(--muted);
    }

    .has-stage .project-card::before {
        counter-increment: project;
        content: counter(project, decimal-leading-zero);
        font-size: 12px;
        font-variant-numeric: tabular-nums;
        transition: color 200ms var(--ease-smooth-out);
    }

    /* The line is taller than the type, so clipping the name to one line
       does not also cut its descenders. */
    .has-stage .project-card h3 {
        overflow: hidden;
        color: inherit;
        font-size: clamp(16px, 2.3cqi, 20px);
        line-height: 1.2;
        letter-spacing: -0.015em;
        white-space: nowrap;
        text-overflow: ellipsis;
        transition: color 200ms var(--ease-smooth-out), transform 280ms var(--ease-smooth-out);
    }

    /* The stage carries these for the current row. */
    .has-stage .project-card .project-tags,
    .has-stage .project-card__desc,
    .has-stage .project-role {
        display: none;
    }

    .has-stage .project-meta {
        display: flex;
        align-items: center;
        gap: 12px;
        font-size: 12px;
    }

    /* The dot alone; its label is still read out. */
    .has-stage .project-meta .status {
        gap: 0;
        font-size: 0;
    }

    .has-stage a.project-card:hover .project-card__main {
        transform: none;
    }

    .has-stage .project-card.is-current h3 {
        color: var(--fg);
        transform: translateX(6px);
    }

    .has-stage .project-card.is-current::before {
        color: var(--accent);
    }

    /* ── the stage ── */

    /* As tall as the index beside it: the picture and the words at the top,
       the way out along the bottom. It stays hidden until its module has a
       project to put on it, and comes in then. */
    .has-stage .project-stage:not([hidden]) {
        display: flex;
        flex-direction: column;
        align-self: stretch;
        animation: rise-in var(--stagger-dur) var(--stagger-ease) 160ms both;
    }
}

.project-stage:not([href]) {
    cursor: default;
}

/* One fixed shape for every project, so nothing resizes between them. */
.project-stage__frame {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--panel);
    outline: 1px solid var(--line);
    outline-offset: -1px;
    container-type: inline-size;
}

.project-stage__shots {
    position: absolute;
    inset: 0;
}

/* What fills the frame, a shot or the poster, sharpens quickly after a skim. */
.project-stage__shots,
.project-stage__poster {
    transition: opacity 250ms var(--ease-smooth-out), filter 380ms var(--ease-smooth-out);
}

/* Skimming (project-stage.js): the pointer is running down the index, and the
   frame drifts out of focus on what it already shows. The drift starts late
   and slowly, so a hop to a nearby row lands before any of it is seen and
   only a real run blurs the stage. */
.project-stage.is-skimming :is(.project-stage__shots, .project-stage__poster) {
    filter: blur(12px) brightness(0.7);
    transition: opacity 250ms var(--ease-smooth-out), filter 520ms ease-in-out 80ms;
}

@media (prefers-reduced-motion: reduce) {
    .project-stage.is-skimming :is(.project-stage__shots, .project-stage__poster) {
        filter: brightness(0.7);
    }
}

/* Each shot fits whole, and what margin is left carries on from its edges:
   the layer's background is the shot's two outer rows of pixels, or columns
   (set from JS), each drawn out over its half of the frame. */
.project-stage__shots .preview-shot {
    object-fit: contain;
    object-position: center;
    background: var(--panel) no-repeat;
}

.project-stage__shots .preview-shot[data-fill="rows"],
.project-shot img[data-fill="rows"] {
    background-position: top, bottom;
    background-size: 100% 50%;
}

.project-stage__shots .preview-shot[data-fill="columns"],
.project-shot img[data-fill="columns"] {
    background-position: left, right;
    background-size: 50% 100%;
}

/* Loading sweep while a shot decodes. */
.project-stage__frame::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 25%, rgb(255 255 255 / 0.08) 45%, transparent 65%);
    transform: translateX(-120%);
    opacity: 0;
}

.project-stage[data-state="loading"] .project-stage__frame::after {
    opacity: 1;
    animation: stage-sweep 1.2s linear infinite;
}

@keyframes stage-sweep {
    to { transform: translateX(130%); }
}

/* No screenshot, or one that would not load: the name fills the frame. */
.project-stage__poster {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: end start;
    padding: 28px;
    color: var(--raised-hover);
    font-size: 13cqi;
    font-weight: 800;
    font-stretch: 112%;
    line-height: 0.9;
    letter-spacing: -0.03em;
    text-wrap: balance;
    opacity: 0;
}

.project-stage__poster span {
    display: inline-block;
}

.project-stage:not(.has-shot) .project-stage__shots,
.project-stage[data-state="error"] .project-stage__shots {
    opacity: 0;
}

.project-stage:not(.has-shot) .project-stage__poster,
.project-stage[data-state="error"] .project-stage__poster {
    opacity: 1;
}

.project-stage__info {
    flex: 1;
    display: grid;
    align-content: start;
    gap: 14px;
    padding: 28px 4px 0;
}

.project-stage__title {
    font-size: clamp(32px, 5.2cqi, 46px);
    font-weight: 800;
    font-stretch: 112%;
    line-height: 1.05;
    letter-spacing: -0.02em;
    transition: color 200ms var(--ease-smooth-out);
}

.project-stage[href]:hover :is(.project-stage__title, .project-stage__domain) {
    color: var(--accent);
}

.project-stage__desc {
    max-width: 58ch;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.5;
}

.project-stage .project-tags {
    margin-top: 0;
}

/* The stage's last row: as tall as a row of the index (--rows of them share
   the same height, set from JS) and ruled like one, so the two columns end
   level. */
.project-stage__foot {
    flex: none;
    display: grid;
    align-content: center;
    height: calc(100% / var(--rows));
    min-height: 42px;
    padding: 0 4px;
    border-bottom: 1px solid var(--line);
    /* The rule above sits where the index draws its own: under the row before. */
    box-shadow: 0 -1px 0 var(--line);
}

.project-stage__meta {
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

/* Where the project lives leads the row; status and year keep to the right. */
.project-stage__domain {
    min-width: 0;
    margin-right: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--fg);
    font-size: 15px;
    font-weight: 600;
    transition: color 200ms var(--ease-smooth-out);
}

.project-stage:not([href]) .project-stage__domain {
    color: inherit;
    font-weight: 400;
}
