/* ============================================================
   HOME / WORK — FULL VIEWPORT EXPERIENCE
   ============================================================ */

body.home {
    overflow: hidden;
}

/* Footer is fixed to viewport bottom on the homepage only */
body.home .site-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    pointer-events: none;
}

body.home .site-footer__inner > * {
    pointer-events: auto;
}

/* ============================================================
   HOME MAIN CONTAINER
   ============================================================ */

.home-work {
    position: relative;
    height: 100vh;
    /* Visible height on mobile (browser bars shown) — the reel centres the
       active project in it. Same as 100vh on desktop. */
    height: 100dvh;
    overflow: hidden;
    /* Max box of a project's media (image or video): its natural size,
       scaled down to fit — the width/composition rule of the reel. */
    --work-media-max-w: 40vw;
    --work-media-max-h: 50vh;
}

/* ============================================================
   LEFT: PROJECT TITLE LIST
   ============================================================ */

.work-titles {
    position: absolute;
    left: 20px;   /* Provisional — to be confirmed from Figma */
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    pointer-events: auto;
}

.work-titles__list {
    list-style: none;
}

.work-title-item {
    line-height: 1;
    margin-bottom: 12px;
}

.work-title-item:last-child {
    margin-bottom: 0;
}

.work-title-item__link {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    /* Color driven continuously by JS — no CSS transition */
}

.work-title-item--active .work-title-item__link {
    color: var(--color-text-primary); /* fallback for reduced-motion / no-JS */
}

/* ============================================================
   RIGHT: PROJECT NUMBER LIST
   ============================================================ */

.work-numbers {
    position: absolute;
    right: 20px;  /* Provisional — to be confirmed from Figma */
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
}

.work-numbers__list {
    list-style: none;
    text-align: right;
}

.work-number-item {
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-secondary);
    line-height: 1;
    margin-bottom: 12px;
    /* Color driven continuously by JS — no CSS transition */
}

.work-number-item:last-child {
    margin-bottom: 0;
}

.work-number-item--active {
    color: var(--color-text-primary); /* fallback for reduced-motion / no-JS */
    cursor: default;
}

/* ============================================================
   CENTER: PROJECT IMAGE VIEWER
   ============================================================ */

.work-viewer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    /* Touch: vertical drags drive the reel (home.js touch input), so the
       browser must not claim them as a native pan (it would cancel the
       gesture). Horizontal pans and pinch-zoom stay with the browser.
       No effect on mouse/wheel. */
    touch-action: pan-x pinch-zoom;
}

/* Touch: no long-press callout / link or image drag / selection / tap flash
   on the reel — a press-and-hold must stay a reel gesture. */
@media (hover: none), (pointer: coarse) {
    .work-viewer {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }

    .work-project__link,
    .work-project__image {
        -webkit-user-drag: none;
    }
}

.work-track {
    display: flex;
    flex-direction: column;
    align-items: center;
    will-change: transform; /* GPU compositor layer for continuous reel animation */
}

/*
 * Each project occupies its image height plus vertical gap.
 * Reduced from 48px to 32px — tighter editorial rhythm while
 * preserving the intentional negative space between projects.
 */
.work-project {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 100%;
    padding: 32px 0;
}

.work-project__link {
    display: block;
    pointer-events: none; /* Only the active project image is clickable */
}

.work-project--active .work-project__link {
    pointer-events: auto;
}

/*
 * Unit = the media + its caption (the caption is mobile only): one box that
 * carries the depth field (home.js applyDepth: scale + displacement), so the
 * caption can never drift from its image. On desktop the caption is not
 * rendered and the unit is exactly the figure's box.
 */
.work-project__unit {
    will-change: transform;
}

/*
 * overflow: hidden clips the scaled-up overscan that enables parallax.
 * The figure is sized by the image's layout dimensions (before transform),
 * so the overscan is invisible — the user sees only the clipped interior.
 */
.work-project__figure {
    margin: 0;
    overflow: hidden;
}

/* Caption (title + number under the media) — mobile reel only, see RESPONSIVE. */
.work-project__meta {
    display: none;
}

/*
 * Images preserve their natural aspect ratio.
 * max-height: 50vh, max-width: 40vw — ~13% reduction from previous values,
 * creating more surrounding negative space without changing composition.
 * JS applies scale (overscan) + translateY (parallax) via GSAP.
 * will-change promotes the element for continuous transform animation.
 */
.work-project__image {
    display: block;
    width: auto;
    height: auto;
    max-height: var(--work-media-max-h);
    max-width: var(--work-media-max-w);
    will-change: transform;
}

/*
 * Home thumbnail VIDEO (Work → Home Thumbnail: Video). Decorative moving
 * image, never a player — see media.js.
 * The video dictates its own shape: --sized gives the figure the video's
 * native ratio (--media-ratio / --media-w, from the size the admin read in
 * its metadata) and sizes it exactly as an image is sized — natural width,
 * scaled down into the same max box; the height follows from the ratio.
 * Video and featured image both fill that box (same box + same transform
 * origin → overscan/parallax applied by home.js match). The image is only
 * the loading state, fallback (.is-failed) and reduced-motion still: cover
 * crops it if its ratio differs — never the video, whose ratio IS the box.
 * Size unknown (not detected yet) → home.js adds --sized from the video's
 * metadata; until then the image keeps the box.
 * pointer-events: none → clicks/drags go to the project link, no native video UI.
 */
.work-project__figure--video {
    position: relative;
}

/* Images use the same box (ratio from the attachment's size, front-page.php),
   so every reel box is final from the first paint — image or video. */
.work-project__figure--sized {
    position: relative;
    width: min(
        var(--media-w),
        var(--work-media-max-w),
        calc(var(--work-media-max-h) * var(--media-ratio))
    );
    aspect-ratio: var(--media-ratio);
}

.work-project__figure--sized > .work-project__media {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    object-fit: cover;
}

.work-project__video {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
    will-change: transform;
}

.work-project__video.is-ready {
    opacity: 1;
}

.work-project__video.is-failed {
    display: none;
}

/* No featured image and size not known yet: the video sizes itself like an image would. */
.work-project__video--standalone {
    position: static;
    width: auto;
    height: auto;
    max-height: var(--work-media-max-h);
    max-width: var(--work-media-max-w);
    opacity: 1;
    transition: none;
}

/* Unbuilt reel (first load, before home.js clones and centres it): hidden,
   so the raw stack — first project at the top — is never painted and never
   counted as a layout shift. html.tb-reel-pending is only added by the early
   <head> script (with a failsafe) and removed by home.js once positioned. */
.tb-reel-pending .work-track {
    visibility: hidden;
}

/* ============================================================
   CURSOR LABEL — "OPEN" beside the native pointer
   ============================================================
   One element per Home, positioned by home.js (translate3d) and
   shown with .is-visible while the pointer is over the clickable
   (active) project link. The native cursor is never replaced.
   z-index 15: above the reel and side lists (10), below every
   PJAX surface (19/20), the intro loader (30) and persistent UI.
   ============================================================ */

.work-cursor-label {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 15;
    pointer-events: none;
    font-weight: 500;
    line-height: 1;
    color: var(--color-text-primary);
    white-space: nowrap;
    visibility: hidden;
    transition: visibility 0s linear 0.2s; /* hidden once the exit fade ends */
}

.work-cursor-label.is-visible {
    visibility: visible;
    transition: none;
}

.work-cursor-label__text {
    display: block;
    opacity: 0;
    transform: scale(0.95);
    transform-origin: 0 50%;
    transition:
        opacity   0.2s ease,
        transform 0.2s ease;
}

.work-cursor-label.is-visible .work-cursor-label__text {
    opacity: 1;
    transform: scale(1);
    transition:
        opacity   0.25s cubic-bezier(0.25, 0.1, 0.25, 1),
        transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Touch / coarse pointers: never shown (home.js does not bind it either). */
@media (hover: none), (pointer: coarse) {
    .work-cursor-label {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .work-cursor-label__text,
    .work-cursor-label.is-visible .work-cursor-label__text {
        transform: none;
        transition: opacity 0.15s linear;
    }
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.work-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
    font-size: 11px;
}

/* ============================================================
   RESPONSIVE — PROVISIONAL BREAKPOINT: 768px
   ============================================================ */

@media (max-width: 768px) {

    body.home {
        overflow: hidden;
    }

    /*
     * MOBILE REEL — about three projects on screen, each one a unit:
     *
     *     [ MEDIA ]            natural ratio, own width, placed left / centre / right
     *     TITLE         01     caption under it, exactly as wide as the media
     *
     * The reel shows through a WINDOW (the viewer) that keeps the header
     * band clear — logo / ABOUT / CONTACT never sit over a project — with an
     * equal band at the bottom, so the window stays centred on the viewport:
     * the reel's focus (home.js, viewer centre) and the intro's convergence
     * point (viewport centre) are unchanged. Projects slide out of view at
     * the window's edges.
     * Every project gets the same SLOT (article height): a third of the
     * window. The media max height is a fixed share of the slot; the rest is
     * the caption and the space between projects. Below a 120px slot (very
     * short / landscape phones) fewer projects show rather than tiny media.
     * The reel engine is unchanged: it snaps article centres, so equal
     * slots = an even rhythm, whatever the media formats.
     */
    .home-work {
        /* Header band: down to the logo GIF's box bottom (box centred on the
           pill row axis, ~0.92 × its width tall) + any safe area. */
        --home-reel-clear: calc(
            var(--header-inset-top) + var(--pill-height) / 2 + var(--header-gif-width) / 2
            + max(env(safe-area-inset-top, 0px), env(safe-area-inset-bottom, 0px))
        );
        --home-reel-slot: max(120px, calc((100dvh - 2 * var(--home-reel-clear)) / 3));
        --home-meta-gap: 8px;
        /* Media box: the existing rule (natural size scaled into this box) —
           wide media reach the full column, tall ones the slot's height share. */
        --work-media-max-w: calc(100vw - 2 * var(--page-inset-x));
        --work-media-max-h: calc(var(--home-reel-slot) * 0.68);
    }

    @supports not (height: 100dvh) {
        .home-work {
            --home-reel-slot: max(120px, calc((100vh - 2 * var(--home-reel-clear)) / 3));
        }
    }

    .work-viewer {
        top: var(--home-reel-clear);
        bottom: var(--home-reel-clear);
    }

    /* Desktop side lists → replaced by the caption under each media. */
    .work-titles,
    .work-numbers {
        display: none;
    }

    /* One slot per project; the unit is centred in it vertically and placed
       in the column (--page-inset-x, the logo / CONTACT edge) horizontally.
       Placement comes from the project's position in the list (front-page.php):
       centre, left, centre, right… — fixed, never random. */
    .work-project {
        height: var(--home-reel-slot);
        padding: 0 var(--page-inset-x);
    }

    .work-project--align-start {
        justify-content: flex-start;
    }

    .work-project--align-end {
        justify-content: flex-end;
    }

    /* Several projects are on screen: a tap on any of them opens it
       (desktop keeps the active project only). Drags never click (home.js). */
    .work-project__link {
        pointer-events: auto;
    }

    /* Caption — title on the media's left edge, number on its right edge.
       width 0 + min-width 100%: it takes the media's width and never widens
       the unit (a long title wraps instead). */
    .work-project__meta {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 12px;
        width: 0;
        min-width: 100%;
        margin-top: var(--home-meta-gap);
        line-height: 1.2;
        color: var(--color-text-primary);
    }

    .work-project__title {
        min-width: 0;
        overflow-wrap: break-word;
    }

    .work-project__number {
        flex: none;
    }

}

/* ============================================================
   EXIT TRANSITION — INITIAL HIDDEN STATE
   .home-trans-in is added to <html> by an early inline <script>
   in <head> when returning from a Single Work exit transition.
   It hides the viewport-visible content until transition.js
   places the white cover over it, then removes the class.
   Without this guard a brief flash of the home reel can appear
   before the footer script has a chance to run.
   ============================================================ */

.home-trans-in .site-header,
.home-trans-in .home-work {
    visibility: hidden;
}

/* ============================================================
   HOME FIRST-LOAD INTRO — temporary state (assets/js/intro.js)
   ============================================================
   Every rule is scoped to html.tb-intro, which only JS adds (early
   <head> script, with a failsafe). Without JS, Home renders normally.
   intro.js animates the REAL Home elements with inline styles and
   removes the class in the same frame as clearing them — the final
   intro frame and the first live Home frame are identical.
   ============================================================ */

/* GIF layer — transparent (the body is the white), below all persistent UI. */
.tb-intro-loader {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

/* Rendered at half its pixel size (375×344 asset) — matches the reference scale. */
.tb-intro-loader__gif {
    width: 187.5px;
    height: auto;
    max-width: none;
    transform-origin: 50% 50%;
}

/* Hidden until intro.js reveals them (inline opacity overrides these). */
.tb-intro .site-header,
.tb-intro .site-nav-under-layer,
.tb-intro .site-footer,
.tb-intro .work-title-item,
.tb-intro .work-number-item,
.tb-intro .work-project__link,
.tb-intro .work-project__meta {
    opacity: 0;
}

/* Input lock — wheel/click/hover cannot reach the reel or UI mid-intro. */
.tb-intro .site-header *,
.tb-intro .site-nav-under-layer *,
.tb-intro .site-footer *,
.tb-intro .home-work,
.tb-intro .home-work * {
    pointer-events: none !important;
}

/* Seed: the first project image starts as a dark point (same black as the
   GIF) and "develops" into the real image. Driven by --tb-intro-seed (1 → 0). */
.tb-intro .work-project__figure {
    position: relative;
}

.tb-intro .work-project__figure::after {
    content: '';
    position: absolute;
    inset: 0;
    background: #000;
    opacity: var(--tb-intro-seed, 0);
    pointer-events: none;
}
