/* ============================================================
   SINGLE WORK — PAGE LAYOUT
   ============================================================ */

/* ============================================================
   PROJECT INTRO
   ============================================================ */

.sw-intro {
    padding-top: 132px; /* Clears fixed header + breathing room */
    padding-bottom: 60px;
    align-items: start;
}

/* area: lines 4→7  |  align: stretch (fills 3 columns)  |  width: fill */
.sw-intro__main {
    grid-column: 4 / 7;
}

.sw-intro__title {
    font-weight: 500;
    font-size: 11px;
    color: var(--color-text-primary);
    margin-bottom: 16px;
    line-height: 1.4;
}

.sw-intro__description {
    color: var(--color-text-secondary);
}

.sw-intro__description p {
    color: var(--color-text-secondary);
    font-size: 11px;
    line-height: 1.6;
    margin-bottom: 4px;
}

.sw-intro__description p:last-child {
    margin-bottom: 0;
}

/* area: lines 8→10  |  align: stretch (fills 2 columns)  |  width: fill */
.sw-intro__roles {
    grid-column: 8 / 10;
}

/* area: col 10  |  align: end (intrinsic width, right-aligned)  |  width: intrinsic
   Right edge at grid line 11 = gallery right edge. LINK + URL stay left-aligned inside. */
.sw-intro__link-area {
    grid-column: 10 / 11;
    justify-self: end;
}

.sw-intro__label {
    display: block;
    font-weight: 500;
    font-size: 11px;
    color: var(--color-text-primary);
    margin-bottom: 8px;
    line-height: 1;
}

.sw-intro__roles-list {
    list-style: none;
}

.sw-intro__roles-list li {
    color: var(--color-text-secondary);
    font-size: 11px;
    line-height: 1.6;
}

.sw-intro__link {
    display: block;
    color: var(--color-text-secondary);
    font-size: 11px;
    line-height: 1.4;
    white-space: nowrap;
}

/* ============================================================
   PROJECT CONTENT — MINIMAP + GALLERY
   ============================================================ */

.sw-content {
    padding-bottom: 80px;
    align-items: start;
}

/* ============================================================
   STICKY MINIMAP
   ============================================================ */

/* area: line 2→3 (column 2)  |  align: stretch  |  width: fill column 2 */
.sw-minimap {
    grid-column: 2 / 3;
    position: sticky;
    top: 60px; /* Clears fixed header — provisional */
    align-self: start;
}

.sw-minimap__track {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 17px;
    width: 100%;
}

/* Item is now a <button> — reset browser defaults while keeping layout identical */
.sw-minimap__item {
    width: 100%;
    flex-shrink: 0;
    display: block;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    text-align: left;
}

.sw-minimap__img {
    display: block;
    width: 100%;
    height: auto;
}

/* Two-image row: both thumbnails in one item, mirroring the gallery row —
   equal halves, top-aligned. Gap = the grid gutter at the minimap's scale
   (one column vs the 7-column gallery ≈ 1 : 8). */
.sw-minimap__item--pair {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: calc(var(--grid-gutter) / 8);
    align-items: start;
}

/* Video item: static first frame (never plays). Neutral UI tone while loading
   or if the URL fails, so the thumbnail sequence keeps its rhythm. */
.sw-minimap__video {
    background-color: var(--color-ui-background);
    pointer-events: none;
}

.sw-minimap__video:not([width]) {
    aspect-ratio: auto 16 / 9;
}

/* Horizontal progress line — moved vertically by JS
   Extends 6px beyond thumbnail on each side (intentional local detail). */
.sw-minimap__indicator {
    position: absolute;
    left: -6px;
    right: -6px;
    height: 2px;
    background-color: #D9D9D9;
    top: 0;
    will-change: transform;
    pointer-events: none;
}

/* Minimap track — accepts pointer events for scrubbing.
   touch-action: none allows pointer capture to work cleanly on touch devices. */
.sw-minimap__track {
    touch-action: none;
}

/* Cursor override while actively scrubbing the minimap progress line */
.sw-scrubbing,
.sw-scrubbing * {
    cursor: ns-resize !important;
    user-select: none;
    -webkit-user-select: none;
}

/* ============================================================
   MAIN GALLERY
   ============================================================ */

/* area: lines 4→11 (7 columns)  |  align: stretch  |  width: fill
   Image inside is width:100% — fills the 7-column grid area exactly.
   Right edge at grid line 11 = CONTACT pill's right edge. Col 1 minimap,
   cols 2-3 empty, cols 4-10 gallery, col 11-12 intentional negative space. */
.sw-gallery {
    grid-column: 4 / 11;
}

.sw-gallery__block {
    margin-bottom: 52px;
}

.sw-gallery__block:last-child {
    margin-bottom: 0;
}

.sw-gallery__image {
    display: block;
    width: 100%;
    height: auto;
}

/* Two images on one row: two equal halves of the gallery area separated by
   the canonical gutter. Each image keeps its own ratio (width 100%, height
   auto — never cropped or stretched); different ratios are top-aligned. */
.sw-gallery__block--pair {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: var(--grid-gutter);
    align-items: start;
}

/* Gallery video (external MP4): same box as an image — full width, natural
   ratio (width/height attributes from the admin; 16:9 only if unknown).
   Fades in on its first frame (.is-ready, media.js). */
.sw-gallery__video {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.sw-gallery__video:not([width]) {
    aspect-ratio: auto 16 / 9;
}

.sw-gallery__video.is-ready {
    opacity: 1;
}

.sw-gallery__empty {
    color: var(--color-text-secondary);
    font-size: 11px;
}

/* ============================================================
   PROJECT HEADER CONTROLS (close + title pill)
   Injected into .site-header__inner grid by header.php
   ============================================================ */

/* ── Project controls layer ────────────────────────────────────────────
   Separate position:fixed element, z-index 40 — below the About backdrop
   (z-index 50) so the backdrop can visually cover these controls when
   About opens, while the site-header (z-index 100) stays above it for
   global controls (TB., close X, CONTACT, SANDBOX).
   Uses the same 12-column grid geometry as .site-header__inner.
   --sw-controls-drop: the whole group sits a little below the header pill
   row (more breathing room from the top edge); global pills don't move. */
.site-work-controls-layer {
    --sw-controls-drop: 8px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40;
    pointer-events: none;
    display: grid;
    grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr));
    column-gap: var(--grid-gutter);
    padding-top: calc(var(--header-inset-top) + var(--sw-controls-drop));
    align-items: center;
}

/* area: lines 4→8  |  align: start (intrinsic width, left-aligned)  |  width: intrinsic
   Left edge of × pill at grid line 4 — aligns with intro text and gallery left edge. */
.site-header__project-controls {
    grid-column: 4 / 8;
    display: flex;
    align-items: center;
    gap: 4px;
    pointer-events: auto;
    justify-self: start;
    min-width: 0;
}

/* Close pill — tighter horizontal padding than standard pill */
.sw-header-close {
    flex-shrink: 0;
    padding: 0 10px 1px;
}

/* Project title pill — fixed 110px: 10px left + 69px track + 8px gap + 13px thumb + 10px right */
.sw-header-title {
    display: inline-flex;
    align-items: center;
    background-color: var(--color-ui-background);
    border-radius: 999px;
    height: 24px;
    width: 110px;
    flex-shrink: 0;
    overflow: hidden;
    padding: 0 10px;
    gap: 8px;
}

/* Title viewport — clips scrolling text to 69px */
.sw-header-title__text-track {
    width: 69px;
    flex-shrink: 0;
    overflow: hidden;
    padding-bottom: 1px;
}

.sw-header-title__text {
    display: block;
    white-space: nowrap;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-weight: 500;
    font-size: 11px;
    color: var(--color-text-primary);
    line-height: 1;
}

/* Fixed thumbnail — 13×13px, does NOT move with the marquee */
.sw-header-title__thumb {
    width: 13px;
    height: 13px;
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
}

/* Next-project pill */
.sw-header-next {
    flex-shrink: 0;
    padding: 0 10px 1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sw-header-title__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ============================================================
   MARQUEE LAYOUT
   JS (single-work.js) drives the animation via Web Animations API.
   Structure: [original text][gap spacer][clone] inside a flex track.
   Animation translates by -(textWidth + gap) — at the reset the clone
   sits at exactly position 0, making the loop invisible.
   ============================================================ */

.sw-header-title__marquee-wrapper {
    display: flex;
    align-items: center;
    white-space: nowrap;
}

/* ============================================================
   PAGE TRANSITION — INITIAL HIDDEN STATE
   .sw-trans-in is added to <html> by an early inline <script>
   in <head> when arriving from the Home transition. JS in
   transition.js removes the class to trigger the CSS reveal.
   Per-element transition properties are set inline by JS
   (staggered delays) — no transition is declared here.
   ============================================================ */

/* .site-header is intentionally omitted — it is persistent and must never
   be hidden or made invisible during any page transition. */
.sw-trans-in .site-work-controls-layer,
.sw-trans-in .sw-intro,
.sw-trans-in .sw-minimap,
.sw-trans-in .sw-gallery {
    opacity: 0;
    transform: translateY(10px);
}

/* ============================================================
   MOBILE COMPOSITION — max-width: 768px (provisional breakpoint)
   ============================================================
   Mobile is its own composition, not the desktop grid squeezed:
   one column on the shared mobile inset (--page-inset-x, the same
   edge as TB. / MENU), no minimap, and the project controls as a
   floating group centred at the bottom of the viewport.
   Reference: mobile Single Work mockup (402px frame).
   Desktop rules above are untouched — everything lives here.

   Vertical rhythm (two steps only):
     --sw-m-gap        title → description, label → value
     --sw-m-block-gap  between intro blocks, and intro → first media
   ============================================================ */

@media (max-width: 768px) {

    :root {
        /* Bottom offset of the project controls. 32px (mockup) above the
           viewport bottom; clears the iOS home indicator when the browser
           reports a safe area (standalone / viewport-fit). */
        --sw-nav-bottom: max(32px, calc(env(safe-area-inset-bottom, 0px) + 16px));
        /* Height of the three project controls — taller than the 24px header
           pills: a thumb-sized bar. × and → are circles of this diameter. */
        --sw-nav-height: 40px;
        /* Space kept free under the last media (the page ends there — no
           mobile footer) so the floating controls never sit on it:
           controls + their offset + one --sw-m-gap. */
        --sw-nav-clearance: calc(var(--sw-nav-bottom) + var(--sw-nav-height) + 16px);
    }

    .sw {
        --sw-m-leading:   1.2;
        --sw-m-gap:       16px;
        --sw-m-block-gap: 36px;
        --sw-m-media-gap: 20px;
        --sw-m-text-max:  400px; /* line length cap — only bites above ~430px */
    }

    /* ── Intro: one editorial column ─────────────────────────────────── */

    /* Header row (16px inset + 24px pills) + 52px breathing room. */
    .sw-intro {
        display: flex;
        flex-direction: column;
        row-gap: var(--sw-m-block-gap);
        padding: calc(var(--header-inset-top) + var(--pill-height) + 52px) var(--page-inset-x) var(--sw-m-block-gap);
    }

    .sw-intro__main,
    .sw-intro__roles,
    .sw-intro__link-area {
        max-width: var(--sw-m-text-max);
    }

    .sw-intro__title {
        line-height: var(--sw-m-leading);
        margin-bottom: var(--sw-m-gap);
    }

    .sw-intro__description p,
    .sw-intro__roles-list li {
        line-height: var(--sw-m-leading);
    }

    .sw-intro__label {
        line-height: var(--sw-m-leading);
        margin-bottom: var(--sw-m-gap);
    }

    /* Long URLs wrap instead of overflowing the viewport. */
    .sw-intro__link {
        line-height: var(--sw-m-leading);
        white-space: normal;
        overflow-wrap: anywhere;
    }

    /* ── Media: full mobile column, natural ratios, no minimap ───────── */

    .sw-content {
        display: block;
        padding: 0 var(--page-inset-x) var(--sw-nav-clearance);
    }

    /* Not rendered at all on mobile — no column, no sticky box. single-work.js
       does not initialise the minimap below the breakpoint either. */
    .sw-minimap {
        display: none;
    }

    .sw-gallery__block {
        margin-bottom: var(--sw-m-media-gap);
    }

    /* Two-image rows stack (left, then right) with the mobile media gap. */
    .sw-gallery__block--pair {
        grid-template-columns: minmax(0, 1fr);
        row-gap: var(--sw-m-media-gap);
    }

    /* ── Project controls: floating group, bottom centre ─────────────── */

    .site-work-controls-layer {
        top: auto;
        bottom: var(--sw-nav-bottom);
        display: flex;
        justify-content: center;
        padding: 0 var(--page-inset-x);
    }

    .site-header__project-controls {
        gap: 10px;
        max-width: 100%;
    }

    /* × and → : 40px circles, icon centred (icons keep their size). */
    .sw-header-close,
    .sw-header-next {
        position: relative;
        width: var(--sw-nav-height);
        height: var(--sw-nav-height);
        padding: 0 0 1px;
        justify-content: center;
    }

    /* Touch hit area: 48px tall, meets the neighbour halfway across the gap. */
    .sw-header-close::after,
    .sw-header-next::after {
        content: '';
        position: absolute;
        inset: -4px -5px;
    }

    /* Title pill: 210px, may shrink on narrow screens (≤ 330px wide).
       The marquee viewport takes whatever the thumbnail leaves; the thumbnail
       sits 10px from the right end, like a dot inside the round cap. */
    .sw-header-title {
        width: 210px;
        height: var(--sw-nav-height);
        padding: 0 10px 0 16px;
        gap: 10px;
        flex-shrink: 1;
        min-width: 0;
    }

    .sw-header-title__text-track {
        width: auto;
        flex: 1 1 0;
        min-width: 0;
    }

    .sw-header-title__thumb {
        width: 20px;
        height: 20px;
        border-radius: 3px;
    }

}
