/* =====================================================================
   Photo page: 35mm film on a light table.
   - One number, --light (0 = lamp off, 1 = on), mixes every colour of the
     table and the film: the page arrives dark and lights up as the films
     come in. The photos themselves stay true positives.
   - Sizes are real millimetres (--mm), so the film keeps 35mm proportions.
   - Desktop: a roll per project type, each coming out of its own cassette
     at the screen's edge; it scrolls sideways, pulling more film out.
   - Phones: every roll taped into one film, hanging from one cassette.
   ===================================================================== */

/* --light = --dimmer (the page's own, see the lamp) x --power (the slider
   on the frame; photo.js writes it on the body). */
@property --light {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
}

@property --dimmer {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
}

@property --power {
    syntax: "<number>";
    inherits: true;
    initial-value: 1;
}

/* ---------- The lamp ---------- */
.page-photo {
    --lamp: #ffffffb2;                    /* the lit diffuser */
    --light: calc(var(--dimmer) * var(--power));
    /* The frame round the table; its top band also holds the slider. */
    --frame: clamp(1.25rem, 2.2vw, 2.25rem);
    --band: max(var(--frame), 2.25rem);
    /* Where the fixed navbar ends: its padding round the pills. */
    --frame-top: calc(2 * var(--header-pad) + var(--pill-h));
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='1 0 0 0 0  1 0 0 0 0  1 0 0 0 0  0 0 0 0 .32'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
    /* Dark on arrival; the lamp warms up (0.9s) when the films are half out
       of their cassettes, 0.65s after they arrive. */
    animation: lamp-dim 0.9s cubic-bezier(0.4, 0, 0.2, 1) 0.65s both;
    /* The full-bleed film never makes the page scroll sideways. */
    overflow-x: clip;
}

/* The lamp's clock starts with the films, which come with the Sanity data. */
.page-photo:not(:has(.reel)) {
    animation: none;
}

@keyframes lamp-dim {
    from { --dimmer: 0; }
    to   { --dimmer: 1; }
}

@media (max-width: 47.99em) {
    .page-photo {
        --frame: 0.9rem;
        /* Taller navbar: logo row (3.75rem less its 0.5rem margins), gap, pills. */
        --frame-top: calc(2 * var(--header-pad) + 2.75rem + 0.5rem + var(--pill-h));
    }
}

/* Lamp on, films out and cassettes down from the start. */
@media (prefers-reduced-motion: reduce) {
    .page-photo {
        animation: none;
        --dimmer: 1;
        --film-in-time: 0s;
        --film-in-delay: 0s;
        --can-in-time: 0s;
        --can-in-delay: 0s;
    }
}

/* The table: edge to edge, lit by the lamp. The unlit strip behind the navbar
   and the top band only shows when the page rubber-bands past its top. */
.page-photo main {
    margin-inline: calc(-1 * var(--page-margin));
    padding-inline: var(--page-margin);
    background:
        linear-gradient(var(--c-bg) 0 0) top / 100% calc(var(--frame-top) + var(--band)) no-repeat,
        color-mix(in oklab, var(--c-bg), var(--lamp) calc(var(--light) * 100%));
    /* Light text in the dark, dark on the lit table: it switches at 29%, where
       both read about as well. */
    --text-dark: clamp(0, (var(--light) - 0.29) * 100, 1);
    color: color-mix(in oklab, var(--c-text), #1d1e25 calc(var(--text-dark) * 100%));
}

/* ---------- The table's frame ---------- */
/* Sticky, not fixed: the last thing in <main> and a window tall, it stays put
   while the table scrolls under it and leaves with the table's end. Above
   everything on the table, below the navbar (z-index 10). */
.table-frame {
    --frame-h: calc(100dvh - var(--frame-top));
    position: sticky;
    z-index: 8;
    bottom: 0;
    height: var(--frame-h);
    /* Takes no room: it lies over the table's last screen, full width. */
    margin: calc(-1 * var(--frame-h)) calc(-1 * var(--page-margin)) 0;
    pointer-events: none;
}

/* The profile: the page colour with a fine grain, its middle cut away. */
.table-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    box-sizing: border-box;
    padding: var(--band) var(--frame) var(--frame);
    background:
        var(--grain) 0 0 / 180px 180px,
        var(--c-bg);
    /* The noise is grey round 50%: in overlay it adds texture, not light. */
    background-blend-mode: overlay;
    mask:
        linear-gradient(#000 0 0),
        linear-gradient(#000 0 0) content-box;
    mask-composite: exclude;
    pointer-events: none;
}

/* The opening's edge: a dark seam, a chamfer (lit below, dark above), the
   lip's shadow on the diffuser and the light falling off just inside. */
.table-frame::before {
    content: "";
    position: absolute;
    z-index: 1;
    inset: var(--band) var(--frame) var(--frame);
    border-radius: 2px;
    box-shadow:
        0 0 0 1px rgb(0 0 0 / 0.75),
        0 2px 0 2px rgb(255 255 255 / 0.08),
        0 -2px 0 2px rgb(0 0 0 / 0.45),
        inset 0 calc(0.15 * var(--frame)) calc(0.35 * var(--frame)) rgb(0 0 0 / calc(0.2 + 0.2 * var(--light))),
        inset 0 0 calc(2.5 * var(--frame)) rgb(0 0 0 / calc(0.04 + 0.08 * var(--light)));
    pointer-events: none;
}

/* ---------- Film tokens ---------- */
.film-section {
    /* Desktop: big, yet a roll's first photos still show at rest. */
    --film-h: clamp(15.84rem, min(44.35svh, 38.02vw), 28.51rem);
    --mm: calc(var(--film-h) / 35);
    --pitch: calc(38 * var(--mm));      /* one frame + gap = 8 perforations */
    --perf: calc(4.75 * var(--mm));     /* perforation pitch */

    /* The cassette is media/rullino.webp: 570 x 1025px, lip on the right, its
       edge at x 555. At 19.7px to the mm it is a real 135 cassette; --px is
       one of its pixels on screen. */
    --px: calc(var(--mm) / 19.7);
    /* The film's end tucks this far in: past the 3.3mm lip, under the body. */
    --lip-in: calc(4 * var(--mm));
    /* Only the 180px slice by the lip shows: the screen's edge cuts the rest. */
    --can-show: 180;
    --can-w: calc(var(--can-show) * var(--px) - var(--lip-in));
    --can-h: calc(1025 * var(--px));
    /* The side a roll's cassette is on: 1 right, -1 left (every other roll). */
    --side: 1;

    /* Colour negative: near-black olive in the dark, orange when lit, and 20%
       translucent then, so the lamp shows through. */
    --film-off: #1e1502;
    --film-on: #9b3e00da;
    --film-opacity: calc(100% - 20% * var(--light));
    /* The lamp round the strip: a warm amber rim and a wide orange halo. */
    --film-light: color-mix(in srgb,
        color-mix(in oklab, var(--film-on), #ffd27a 55%) calc(var(--light) * 85%),
        transparent);
    --film-halo: color-mix(in srgb, var(--film-on) calc(var(--light) * 45%), transparent);
    /* The strip's contact shadow: clear in the dark, faint when lit. */
    --film-shadow: color-mix(in srgb,
        rgb(0 0 0 / calc(0.8 - 0.6 * var(--light))) var(--film-opacity),
        transparent);
    /* Room round the strip for the glow: more than the halo's 8mm reach. */
    --halo: calc(9 * var(--mm));
    --ink-off: #3f321a;         /* unlit print: a dark ochre */
    --ink-on: #93330a;          /* edge print and barcode */
    --ink-strong-on: #5a1d00;   /* leader text */
    --code-on: #3f6f62;         /* batch code, in a second ink */
    --film-base: color-mix(in oklab, var(--film-off), var(--film-on) calc(var(--light) * 100%));
    --film-ink: color-mix(in oklab, var(--ink-off), var(--ink-on) calc(var(--light) * 100%));
    --film-ink-strong: color-mix(in oklab, var(--ink-off), var(--ink-strong-on) calc(var(--light) * 100%));
    --film-code: color-mix(in oklab, var(--ink-off), var(--code-on) calc(var(--light) * 100%));
    /* Blank film after a project: 0.75 pitch, so the barcode jumps at every
       splice, like two strips taped together. */
    --tail-len: calc(0.75 * var(--pitch));
    /* The free end, cut 5mm before the title (as far as frame 1 is from it). */
    --head-len: calc(1 * var(--mm));
    --tape: calc(4 * var(--mm));        /* splice tape, each side of the joint */

    /* Gloss: a soft reflection along the strip, under the photos. */
    --film-sheen: linear-gradient(180deg,
        rgb(255 255 255 / 0) 4%,
        rgb(255 255 255 / calc(0.2 * var(--light))) 11%,
        rgb(255 255 255 / calc(0.07 * var(--light))) 17%,
        rgb(255 255 255 / 0) 30%,
        rgb(255 255 255 / 0) 84%,
        rgb(255 255 255 / calc(0.08 * var(--light))) 92%,
        rgb(255 255 255 / 0) 98%);

    /* DX barcode, one tile per frame, with gaps cut round the printed numbers. */
    --gap-num: calc(3 * var(--mm));
    --gap-sub: calc(4.6 * var(--mm));
    --dx-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 38 3' preserveAspectRatio='none'%3E%3Cpath d='M.15 .3h.28V3h-.28ZM.88 .3h.9V3h-.9ZM2.08 .3h.28V3h-.28ZM2.66 .3h.55V3h-.55ZM3.51 1.5h.9V3h-.9ZM4.71 .3h.28V3h-.28ZM5.29 .3h.28V3h-.28ZM6.02 .3h.28V3h-.28ZM6.6 1.5h.28V3h-.28ZM7.18 .3h.28V3h-.28ZM7.91 .3h.28V3h-.28ZM8.49 .3h.28V3h-.28ZM9.07 1.5h.28V3h-.28ZM9.65 .3h.28V3h-.28ZM10.23 .3h.55V3h-.55ZM11.08 .3h.28V3h-.28ZM11.66 .3h.55V3h-.55ZM12.51 1.5h.28V3h-.28ZM13.09 1.5h.28V3h-.28ZM13.67 .3h.55V3h-.55ZM14.52 .3h.28V3h-.28ZM15.1 .3h.28V3h-.28ZM15.68 .3h.28V3h-.28ZM16.41 .3h.28V3h-.28ZM16.99 1.5h.55V3h-.55ZM17.84 .3h.28V3h-.28ZM18.57 1.5h.28V3h-.28ZM19.15 .3h.55V3h-.55ZM20.15 .3h.28V3h-.28ZM20.73 .3h.55V3h-.55ZM21.58 1.5h.28V3h-.28ZM22.16 1.5h.9V3h-.9ZM23.51 .3h.28V3h-.28ZM24.09 .3h.28V3h-.28ZM24.67 .3h.9V3h-.9ZM25.87 .3h.9V3h-.9ZM27.07 .3h.28V3h-.28ZM27.65 .3h.28V3h-.28ZM28.38 .3h.9V3h-.9ZM29.73 1.5h.28V3h-.28ZM30.31 .3h.9V3h-.9ZM31.51 .3h.28V3h-.28ZM32.09 .3h.28V3h-.28ZM32.67 .3h.28V3h-.28ZM33.4 .3h.28V3h-.28ZM34.13 .3h.9V3h-.9ZM35.33 .3h.28V3h-.28ZM35.91 .3h.55V3h-.55ZM36.76 1.5h.28V3h-.28Z'/%3E%3C/svg%3E");
    --dx-y: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 3 26' preserveAspectRatio='none'%3E%3Cpath d='M.3 .15H3v.9H.3ZM1.5 1.35H3v.28H1.5ZM.3 1.93H3v.55H.3ZM.3 2.78H3v.9H.3ZM.3 3.98H3v.28H.3ZM.3 4.56H3v.9H.3ZM.3 5.76H3v.28H.3ZM1.5 6.49H3v.28H1.5ZM.3 7.07H3v.28H.3ZM1.5 7.8H3v.28H1.5ZM.3 8.38H3v.9H.3ZM1.5 9.58H3v.55H1.5ZM.3 10.43H3v.28H.3ZM.3 11.01H3v.55H.3ZM.3 12.01H3v.28H.3ZM1.5 12.59H3v.28H1.5ZM1.5 13.32H3v.28H1.5ZM.3 13.9H3v.28H.3ZM.3 14.48H3v.28H.3ZM1.5 15.21H3v.9H1.5ZM.3 16.41H3v.55H.3ZM.3 17.26H3v.28H.3ZM1.5 17.84H3v.28H1.5ZM1.5 18.42H3v.55H1.5ZM1.5 19.42H3v.9H1.5ZM.3 20.77H3v.28H.3ZM.3 21.35H3v.55H.3ZM.3 22.2H3v.55H.3ZM.3 23.05H3v.55H.3ZM.3 23.9H3v.28H.3ZM.3 24.48H3v.9H.3Z'/%3E%3C/svg%3E");

    /* Perforations, one tile per pitch: the holes are real transparency. */
    --perf-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4.75 35' preserveAspectRatio='none'%3E%3Cpath fill-rule='evenodd' d='M0 0H4.75V35H0Z M1.885 2h.98a.5.5 0 0 1 .5.5v1.79a.5.5 0 0 1-.5.5h-.98a.5.5 0 0 1-.5-.5v-1.79a.5.5 0 0 1 .5-.5Z M1.885 30.21h.98a.5.5 0 0 1 .5.5v1.79a.5.5 0 0 1-.5.5h-.98a.5.5 0 0 1-.5-.5v-1.79a.5.5 0 0 1 .5-.5Z'/%3E%3C/svg%3E");
    --perf-y: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 47 4.75' preserveAspectRatio='none'%3E%3Cpath fill-rule='evenodd' d='M0 0H47V4.75H0Z M2.5 1.385h1.79a.5.5 0 0 1 .5.5v.98a.5.5 0 0 1-.5.5h-1.79a.5.5 0 0 1-.5-.5v-.98a.5.5 0 0 1 .5-.5Z M42.71 1.385h1.79a.5.5 0 0 1 .5.5v.98a.5.5 0 0 1-.5.5h-1.79a.5.5 0 0 1-.5-.5v-.98a.5.5 0 0 1 .5-.5Z'/%3E%3C/svg%3E");
}

/* ---------- Layout (desktop first) ---------- */
/* At least a screen tall, even before the films arrive: the frame sits round
   the window and the footer stays below the fold. */
.film-section {
    position: relative;
    box-sizing: border-box;
    min-height: 100dvh;
}

/* The rolls run from screen edge to screen edge. */
.film-rig {
    display: flex;
    flex-direction: column;
    margin-inline: calc(-1 * var(--page-margin));
}

.film {
    display: flex;
    flex-direction: column;
    /* The first row: a little below the frame. */
    padding-top: calc(clamp(1rem, 4svh, 2.5rem) + 5svh);
}

/* Why there are no films (none yet, or no connection), in the middle of the
   table's opening. While they load the table just stays empty. */
.film__status {
    position: absolute;
    top: calc(50% + (var(--frame-top) + var(--band) - var(--frame)) / 2);
    left: 50%;
    width: max-content;
    max-width: calc(100% - 2 * var(--page-margin));
    margin: 0;
    translate: -50% -50%;
    text-align: center;
}

/* ---------- Rolls (desktop) ---------- */
/* Cuts the cassette at the screen's edge (clip, unlike hidden, leaves the
   other axis alone). */
.reel__body {
    display: flex;
    align-items: center;
    overflow-x: clip;
}

/* The roll's own scroll box, ending inside the cassette: scrolling on pulls
   film out. A size container, for the arrival (cqw). */
.reel__track {
    container-type: inline-size;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    /* No bounce (it slid the film's end out of the cassette), no swipe back,
       no sideways scroll of the page. */
    overscroll-behavior-x: none;
    /* A frame brought into view by keyboard stays clear of the cassette. */
    scroll-padding-inline: var(--page-margin) var(--lip-in);
    scrollbar-width: none;
}

.reel__track::-webkit-scrollbar {
    display: none;
}

/* The strip, in a box with room for the glow above, below and ahead of the
   free end, at least as long as the track. The mask punches the perforations
   through film and glow alike; the room stays whole (1px overlaps, so no
   seam shows). */
.reel__film {
    position: relative;
    display: flex;
    box-sizing: border-box;
    width: max-content;
    min-width: 100%;
    height: calc(35 * var(--mm) + 2 * var(--halo));
    padding-block: var(--halo);
    padding-inline-start: var(--page-margin);
    mask:
        var(--perf-x) 0 var(--halo) / var(--perf) calc(100% - 2 * var(--halo)) repeat-x,
        linear-gradient(#000 calc(var(--halo) + 1px), transparent 0 calc(100% - var(--halo) - 1px), #000 0),
        linear-gradient(calc(90deg * var(--side)), #000 calc(var(--page-margin) + 1px), transparent 0);
    /* On arrival it is pulled out of the cassette (0.3-1.3s), on transform so
       it never fights the roll's own scrolling. */
    animation: reel-in var(--film-in-time, 1s) cubic-bezier(0.45, 0, 0.2, 1) var(--film-in-delay, 0.3s) both;
}

/* The lamp round the strip and its shadow: a layer the strip's size, under it
   (phones: .film::before). Round it the contact shadow, an amber rim and the
   orange halo; inside, the same light filled in, which the translucent base
   lets through. Box shadows, not drop-shadow() filters: a filter re-blurs the
   whole strip on every frame of the lamp, and the films stuttered. */
.reel__film::before,
.film::before {
    position: absolute;
    z-index: -1;
    background: var(--film-halo);
    box-shadow:
        0 calc(1 * var(--mm)) calc(2.8 * var(--mm)) var(--film-shadow),
        0 0 calc(1 * var(--mm)) var(--film-light),
        0 0 calc(5 * var(--mm)) calc(0.5 * var(--mm)) var(--film-halo),
        inset 0 0 0 100vmax var(--film-shadow),
        inset 0 0 0 100vmax var(--film-light);
    pointer-events: none;
}

.reel__film::before {
    content: "";
    inset-block: var(--halo);
    inset-inline: var(--page-margin) 0;
}

/* Starts with the free end at the track's end, inside the cassette. */
@keyframes reel-in {
    from { transform: translateX(calc(var(--side) * (100cqw - var(--page-margin)))); }
}

@media (min-width: 48em) {
    /* Rows overlap by their glow room, leaving 10mm of table between films;
       the cassettes take turns left and right, so they never meet. */
    .reel + .reel {
        margin-top: calc(1 * var(--mm) - var(--halo));
    }

    /* A leader is as wide as its title, so the first photos show at rest:
       never so short its "00" falls off, never longer than a frame. */
    .reel__film .film__leader {
        width: max-content;
        min-width: calc(0.5 * var(--pitch) + var(--gap-num));
        max-width: var(--pitch);
    }

    /* On a big film the printed titles stop growing. */
    .reel__film .film__leader-title {
        font-size: min(3.6 * var(--mm), 1.75rem);
    }

    .reel__film .film__label {
        padding-right: min(8 * var(--mm), 3rem);
    }

    .reel__film .film__label-title {
        font-size: min(4.4 * var(--mm), 2.25rem);
    }

    /* Each roll has its own cassette here: the page's one is for phones. */
    .film-rig > .canister {
        display: none;
    }

    /* A roll shorter than the screen: its last tail runs on to the cassette. */
    .reel__film > .film__segment:last-child,
    .reel__film > .film__segment:last-child .film__tail {
        flex-grow: 1;
    }

    /* The cassette turned half a turn (lip on the left, label reading down),
       the lip centred on the film (its edge is 270px from the photo's centre,
       the lip 26px off it), sliding in from off the screen. --side -1 mirrors
       it: the photo as shot, lip on the right. */
    .reel {
        --can-turn: calc(90deg + 90deg * var(--side));
        --can-dx: calc(var(--side) * ((270 - var(--can-show) / 2) * var(--px) - var(--lip-in) / 2));
        --can-dy: calc(var(--side) * -26 * var(--px));
        --can-from: calc(var(--side) * 3rem) 0;
    }

    /* ---------- Every other roll: cassette on the left ---------- */
    /* Laid out right to left (text and photos stay as they are). */
    .reel:nth-child(even) {
        --side: -1;
        direction: rtl;
    }

    .reel:nth-child(even) :is(.film__label, .film__leader, .edge) {
        direction: ltr;
    }

    /* Barcode: frame 1 left of its leader, the tail left of the last frame,
       the head right of the label. */
    .reel:nth-child(even) .film__label::before {
        right: calc(-1 * var(--head-len));
        left: 0;
        mask: var(--dx-x) 0 0 / var(--pitch) 100% repeat-x;
    }

    .reel:nth-child(even) .film__leader::before {
        mask:
            var(--dx-x) 0 0 / var(--pitch) 100% repeat-x,
            linear-gradient(#000 0 0) calc(0.5 * var(--pitch) - var(--gap-num) / 2) 0 / var(--gap-num) 100% no-repeat;
        mask-composite: subtract;
    }

    .reel:nth-child(even) .film__tail::before {
        mask: var(--dx-x) right 0 top 0 / var(--pitch) 100% repeat-x;
    }

    .reel:nth-child(even) .frame::before {
        mask:
            var(--dx-x) 0 0 / var(--pitch) 100% repeat-x,
            linear-gradient(#000 0 0) 50% 0 / var(--gap-num) 100% no-repeat,
            linear-gradient(#000 0 0) 0 0 / var(--gap-sub) 100% no-repeat;
        mask-composite: subtract, add;
    }

    /* "nA" next to frame n+1, on the left; the leader's "00" by frame 1. */
    .reel:nth-child(even) .edge--sub {
        right: auto;
        left: calc(var(--gap-sub) / 2);
        translate: -50% 0;
    }

    .reel:nth-child(even) .film__leader .edge--num {
        right: auto;
        left: calc(0.5 * var(--pitch));
        translate: -50% 0;
    }
}

/* ---------- The cassette ---------- */
.canister {
    position: relative;
    z-index: 2;
    flex: none;
    width: var(--can-w);
    height: var(--can-h);
    /* Opaque: it only shows once the lamp lights the room. */
    filter: brightness(calc(0.35 + 0.65 * var(--light)));
    /* Set down on arrival (0.1-0.7s); the film is pulled out as it settles. */
    animation: can-in var(--can-in-time, 0.6s) cubic-bezier(0.2, 0.8, 0.2, 1) var(--can-in-delay, 0.1s) both;
}

@keyframes can-in {
    from {
        opacity: 0;
        translate: var(--can-from);
    }
}

/* The photo, placed by its centre; its lip covers the film's end. */
.canister__photo {
    position: absolute;
    top: calc(50% + var(--can-dy));
    left: calc(50% + var(--can-dx));
    width: calc(570 * var(--px));
    max-width: none;
    height: auto;
    translate: -50% -50%;
    rotate: var(--can-turn, none);
    pointer-events: none;
}

/* ---------- The film strip ---------- */
/* The translucent base under a glossy sheen. */
.film__segment {
    position: relative;
    display: flex;
    flex: none;
    background:
        var(--film-sheen),
        color-mix(in srgb, var(--film-base) var(--film-opacity), transparent);
}

/* Clear splice tape between two projects, half on each side of the joint
   (none at a roll's two ends). */
.film__segment::before,
.film__segment::after {
    content: "";
    position: absolute;
    z-index: 1;
    inset-block: 0;
    width: var(--tape);
    background: linear-gradient(180deg, rgb(255 252 244 / 0.26), rgb(255 252 244 / 0.1) 45%, rgb(255 252 244 / 0.2));
    opacity: calc(0.25 + 0.75 * var(--light));
    pointer-events: none;
}

.film__segment:first-child::before,
.film__segment:last-child::after {
    content: none;
}

/* The cut: a hairline of light where the two ends almost touch. */
.film__segment::before {
    inset-inline-start: 0;
    box-shadow: inset calc(var(--side) * 0.1 * var(--mm)) 0 calc(0.05 * var(--mm)) rgb(255 250 238 / 0.6);
}

.film__segment::after {
    inset-inline-end: 0;
}

.film__head {
    position: relative;
    flex: none;
    width: var(--head-len);
}

/* A project's leader: its title and meta, ahead of frame 1. */
.film__leader {
    position: relative;
    display: flex;
    flex: none;
    flex-direction: column;
    justify-content: center;
    gap: calc(1.2 * var(--mm));
    box-sizing: border-box;
    width: calc(1.5 * var(--pitch));
    padding: calc(6.5 * var(--mm)) calc(4 * var(--mm));
}

/* The type: the roll's label says it on desktop, phones show it here. */
.film__leader-type {
    display: none;
}

/* Emulsion batch code, in the second ink; decorative, so hidden from screen
   readers (the plain declaration is the fallback). */
.film__leader::after {
    content: "MT 2611 4G";
    content: "MT 2611 4G" / "";
    position: absolute;
    top: 0;
    right: calc(4 * var(--mm));
    color: var(--film-code);
}

/* The roll's label, between its free end and the first project: the type
   and the roll's counts, with a wider gap after it. */
.film__label {
    position: relative;
    display: flex;
    flex: none;
    flex-direction: column;
    justify-content: center;
    gap: calc(1.4 * var(--mm));
    box-sizing: border-box;
    width: max-content;
    max-width: calc(1.5 * var(--pitch));
    padding: calc(6.5 * var(--mm)) calc(8 * var(--mm)) calc(6.5 * var(--mm)) calc(4 * var(--mm));
}

.film__leader-title,
.film__leader-meta,
.film__label-title,
.film__label-meta {
    margin: 0;
    color: var(--film-ink-strong);
    text-transform: uppercase;
}

.film__leader-title {
    font-size: calc(3.6 * var(--mm));
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: 0.06em;
    text-wrap: balance;
}

.film__label-title {
    font-size: calc(4.4 * var(--mm));
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.04em;
    text-wrap: balance;
}

.film__leader-meta,
.film__label-meta {
    font-size: calc(1.4 * var(--mm));
    line-height: 1.25;
    letter-spacing: 0.1em;
}

.film__tail {
    position: relative;
    flex: none;
    width: var(--tail-len);
}

/* ---------- Frames ---------- */
.frame {
    position: relative;
    flex: none;
    width: var(--pitch);
    height: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: zoom-in;
}

.frame:focus-visible {
    outline: none;
}

/* Lamp off: dim and flat. Lamp on: the photo exactly as shot. */
.frame img {
    position: absolute;
    top: calc(5.5 * var(--mm));
    left: calc(1 * var(--mm));
    width: calc(36 * var(--mm));
    max-width: none;
    height: calc(24 * var(--mm));
    object-fit: cover;
    filter:
        brightness(calc(0.2 + 0.8 * var(--light)))
        saturate(calc(0.5 + 0.5 * var(--light)));
}

.frame:focus-visible img {
    outline: 2px solid var(--c-accent);
    outline-offset: calc(0.5 * var(--mm));
}

/* DX barcode along the bottom edge, unbroken along a roll: each piece starts
   the tile where the one before left off. 3mm deep: the long bars reach the
   perforations, which cut them. */
.frame::before,
.film__label::before,
.film__leader::before,
.film__tail::before {
    content: "";
    position: absolute;
    inset: auto 0 0;
    height: calc(3 * var(--mm));
    background: var(--film-ink);
    mask: var(--dx-x) 0 0 / var(--pitch) 100% repeat-x;
    pointer-events: none;
}

/* Gaps round the numbers (bars minus gaps): a frame's number under the photo
   and "nA" at its right edge; the leader's "00" half a pitch from frame 1,
   where its tile ends. The label's bars line up from its right edge and run
   on under the head. */
.frame::before {
    mask:
        var(--dx-x) 0 0 / var(--pitch) 100% repeat-x,
        linear-gradient(#000 0 0) 50% 0 / var(--gap-num) 100% no-repeat,
        linear-gradient(#000 0 0) 100% 0 / var(--gap-sub) 100% no-repeat;
    mask-composite: subtract, add;
}

.film__label::before {
    left: calc(-1 * var(--head-len));
    mask: var(--dx-x) right calc(-0.5 * var(--pitch)) top 0 / var(--pitch) 100% repeat-x;
}

.film__leader::before {
    mask:
        var(--dx-x) right 0 top 0 / var(--pitch) 100% repeat-x,
        linear-gradient(#000 0 0) right calc(0.5 * var(--pitch) - var(--gap-num) / 2) top 0 / var(--gap-num) 100% no-repeat;
    mask-composite: subtract;
}

/* ---------- Edge print ---------- */
/* Bold capitals in the 2mm band between the perforations and the edge. */
.edge,
.film__leader::after {
    position: absolute;
    font-size: calc(1.55 * var(--mm));
    font-weight: 700;
    line-height: calc(2 * var(--mm));
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
    pointer-events: none;
}

.edge {
    color: var(--film-ink);
}

.edge--top {
    top: 0;
    left: calc(2 * var(--mm));
    max-width: calc(34 * var(--mm));
    overflow: hidden;
    text-overflow: ellipsis;
}

/* In the barcode's gaps: the frame number under the photo... */
.edge--num {
    bottom: 0;
    left: 50%;
    translate: -50% 0;
}

/* ...and "nA" at the frame's right edge, next to frame n+1. */
.edge--sub {
    right: calc(var(--gap-sub) / 2);
    bottom: 0;
    translate: 50% 0;
}

.film__leader .edge--num {
    right: calc(0.5 * var(--pitch));
    left: auto;
    translate: 50% 0;
}

/* ---------- Phones: cassette on top, the film hangs down ---------- */
@media (max-width: 47.99em) {
    .film-section {
        /* Film and cassette span the full width, past the page margin. */
        --mm: calc(100vw / 47);
        --pitch: calc(26 * var(--mm));   /* landscape frame (24mm) + gap */
        /* Just under the lip: the first title starts right below it. */
        --lip-in: calc(2 * var(--mm));
        /* The lip (763px) is 10% wider than the film, so the cassette runs off
           both sides. Turned a quarter: lip down over the film, label across;
           only the slice by the lip shows, cut at the box's top. */
        --px: calc(1.1 * 47 * var(--mm) / 763);
        --can-turn: 90deg;
        --can-w: 100%;
        --can-h: calc(var(--can-show) * var(--px) - var(--lip-in));
        --can-dx: calc(-26 * var(--px));
        --can-dy: calc((var(--can-show) / 2 - 270) * var(--px) + var(--lip-in) / 2);
        --can-from: 0 -2rem;
        /* The sheen runs down the sides here. */
        --film-sheen: linear-gradient(90deg,
            rgb(255 255 255 / 0) 4%,
            rgb(255 255 255 / calc(0.2 * var(--light))) 9%,
            rgb(255 255 255 / calc(0.07 * var(--light))) 14%,
            rgb(255 255 255 / 0) 24%,
            rgb(255 255 255 / 0) 87%,
            rgb(255 255 255 / calc(0.08 * var(--light))) 93%,
            rgb(255 255 255 / 0) 98%);
        /* The cassette at the top of the table, below the navbar and the band. */
        padding-top: calc(var(--frame-top) + var(--band));
    }

    .film-rig {
        margin: clamp(1.5rem, 5vw, 2.5rem) calc(-1 * var(--page-margin)) 0;
    }

    /* Cut at the screen's edges (clip also keeps them out of the layout) and
       at the box's top; the lip hangs over the film. */
    .canister {
        overflow-x: clip;
        clip-path: inset(0 0 calc(-2 * var(--lip-in)) 0);
    }

    /* The cut fades in, so the cassette rises out of the table. In the photo's
       pixels (turned, its x runs down the screen): clear where the slice
       starts, solid a little past halfway to the lip's edge (555). */
    .canister__photo {
        mask-image: linear-gradient(to right,
            transparent calc((555 - var(--can-show)) / 570 * 100%),
            #000 calc((555 - 0.45 * var(--can-show)) / 570 * 100%));
    }

    /* One film: the rolls' wrappers step aside. */
    .reel,
    .reel__body,
    .reel__track,
    .reel__film {
        display: contents;
    }

    .reel__can,
    .reel__film::before {
        display: none;
    }

    /* The roll's label is for screen readers only; the leaders show the type. */
    .film__label {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: 0;
        padding: 0;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .film__leader-type {
        display: inline;
    }

    /* Cut at the cassette's mouth, so film pulled in on arrival stays out of
       sight; the glow still spreads past the sides and the end. */
    .film-window {
        flex: none;
        width: 100%;
        height: auto;
        overflow: visible;
        clip-path: inset(0 -100vw -100vh);
    }

    .film {
        width: 100%;
        /* Glow room only past the free end: the sides run off the screen. */
        padding: 0 0 var(--halo);
    }

    /* Once the film is in (a mask before would hide the messages too): the
       perforations, the glow layer, and the pull down out of the cassette. */
    .film:has(.film__segment) {
        position: relative;
        mask:
            var(--perf-y) 0 0 / 100% var(--perf) repeat-y,
            linear-gradient(to top, #000 calc(var(--halo) + 1px), transparent 0);
        animation: film-down var(--film-in-time, 1s) cubic-bezier(0.45, 0, 0.2, 1) var(--film-in-delay, 0.3s) both;
    }

    .film:has(.film__segment)::before {
        content: "";
        inset: 0 0 var(--halo);
    }

    @keyframes film-down {
        from { transform: translateY(-45svh); }
    }

    .film__segment {
        flex-direction: column;
    }

    /* The rolls are taped together too: only the film's own ends are bare. */
    .reel:not(:first-child) .film__segment:first-child::before,
    .reel:not(:last-child) .film__segment:last-child::after {
        content: "";
    }

    .film__segment::before,
    .film__segment::after {
        inset: auto 0;
        width: auto;
        height: var(--tape);
    }

    .film__segment::before {
        top: 0;
        box-shadow: inset 0 calc(0.1 * var(--mm)) calc(0.05 * var(--mm)) rgb(255 250 238 / 0.6);
    }

    .film__segment::after {
        bottom: 0;
    }

    /* The free end hangs at the bottom, cut 5mm after the last photo. */
    .film__head {
        display: none;
    }

    .film__leader {
        width: 100%;
        height: calc(1.5 * var(--pitch));
        padding: calc(4 * var(--mm)) calc(7 * var(--mm));
    }

    .film__tail {
        width: 100%;
        height: var(--tail-len);
    }

    .reel:last-child .film__segment:last-child .film__tail {
        height: calc(4 * var(--mm));
    }

    .frame {
        width: 100%;
        height: var(--pitch);
    }

    .frame img {
        top: calc(1 * var(--mm));
        left: calc(5.5 * var(--mm));
    }

    /* The barcode runs down the right-hand band. */
    .frame::before,
    .film__leader::before,
    .film__tail::before {
        inset: 0 0 0 auto;
        width: calc(3 * var(--mm));
        height: auto;
        mask: var(--dx-y) 0 0 / 100% var(--pitch) repeat-y;
    }

    /* Gaps: the frame number beside the photo, "nA" at its bottom edge; the
       leader's bars start half a pitch in, its "00" a pitch down. */
    .frame::before {
        mask:
            var(--dx-y) 0 0 / 100% var(--pitch) repeat-y,
            linear-gradient(#000 0 0) 0 50% / 100% var(--gap-num) no-repeat,
            linear-gradient(#000 0 0) 0 100% / 100% var(--gap-sub) no-repeat;
        mask-composite: subtract, add;
    }

    .film__leader::before {
        mask:
            var(--dx-y) 0 calc(0.5 * var(--pitch)) / 100% var(--pitch) repeat-y,
            linear-gradient(#000 0 0) 0 calc(var(--pitch) - var(--gap-num) / 2) / 100% var(--gap-num) no-repeat;
        mask-composite: subtract;
    }

    /* Edge print runs down the side bands. */
    .edge,
    .film__leader::after {
        writing-mode: vertical-rl;
    }

    .edge--top {
        top: calc(2 * var(--mm));
        left: 0;
        max-width: none;
        max-height: calc(22 * var(--mm));
    }

    .edge--num {
        top: 50%;
        right: 0;
        bottom: auto;
        left: auto;
        translate: 0 -50%;
    }

    .edge--sub {
        right: 0;
        bottom: calc(var(--gap-sub) / 2);
        left: auto;
        translate: 0 50%;
    }

    .film__leader .edge--num {
        top: var(--pitch);
        right: 0;
        translate: 0 -50%;
    }

    .film__leader::after {
        top: auto;
        right: auto;
        bottom: calc(4 * var(--mm));
        left: 0;
    }
}

/* ---------- Title ---------- */
/* Printed on the frame's top band, left, across from the slider. */
.table-frame__title {
    position: absolute;
    z-index: 2;
    top: 0;
    left: calc(var(--frame) + 0.75rem);
    display: flex;
    align-items: center;
    height: var(--band);
    margin: 0;
    color: var(--c-text);
    font-family: var(--f-sans);
    font-size: 0.9rem;
    font-weight: 400;
    text-transform: uppercase;
    white-space: nowrap;
    letter-spacing: 0.12em;
}

/* ---------- Light table slider ---------- */
/* Built into the frame's top band, like a light table's own dimmer. photo.js
   shows it and hands its value to --power: without scripts it stays hidden. */
.lamp-switch {
    position: absolute;
    z-index: 2;
    top: calc((var(--band) - 1.5rem) / 2);
    right: calc(var(--frame) + 0.75rem);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    height: 1.5rem;
    user-select: none;
    pointer-events: auto;
}

.lamp-switch[hidden] {
    display: none;
}

/* Printed on the profile: small grey capitals. */
.lamp-switch__label {
    color: var(--c-text);
    font-size: 0.9rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* A groove lit in the accent up to the current power, and a pale knob. */
.lamp-switch__slider {
    --fill: linear-gradient(to right,
        var(--c-accent) calc(var(--power) * 100%),
        #050507 0);
    appearance: none;
    width: 6.5rem;
    height: 1.5rem;
    margin: 0;
    background: none;
    cursor: pointer;
}

.lamp-switch__slider::-webkit-slider-runnable-track {
    height: 0.3rem;
    border-radius: 1rem;
    background: var(--fill);
    box-shadow: inset 0 1px 1px rgb(0 0 0 / 0.8), 0 1px 0 rgb(255 255 255 / 0.08);
}

.lamp-switch__slider::-moz-range-track {
    height: 0.3rem;
    border-radius: 1rem;
    background: var(--fill);
    box-shadow: inset 0 1px 1px rgb(0 0 0 / 0.8), 0 1px 0 rgb(255 255 255 / 0.08);
}

.lamp-switch__slider::-webkit-slider-thumb {
    appearance: none;
    width: 0.95rem;
    height: 0.95rem;
    margin-top: calc((0.3rem - 0.95rem) / 2);
    border: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #f4f4f6, #b9bac2);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.7);
}

.lamp-switch__slider::-moz-range-thumb {
    width: 0.95rem;
    height: 0.95rem;
    border: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #f4f4f6, #b9bac2);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.7);
}

.lamp-switch__slider:focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: 2px;
    border-radius: 1rem;
}

/* ---------- Back to top ---------- */
/* A plain link to #top: it works without scripts and moves focus too. */
@media (prefers-reduced-motion: no-preference) {
    html:has(.to-top) {
        scroll-behavior: smooth;
    }
}

/* Dark and round: it reads on the lit table and in the dark alike. */
.to-top {
    position: absolute;
    z-index: 2;
    right: calc(var(--frame) + clamp(0.75rem, 2vw, 1.5rem));
    bottom: calc(var(--frame) + clamp(0.75rem, 2vw, 1.5rem));
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border: 1px solid rgb(191 192 209 / 0.25);
    border-radius: 50%;
    background: rgb(49 50 62 / 0.8);
    color: var(--c-text);
    pointer-events: auto;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.to-top:hover {
    border-color: var(--c-accent);
    background: var(--c-accent);
    color: #fff;
}

.to-top svg {
    width: 1.4rem;
    height: 1.4rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* It rises in between 40% and 70% of a screen of scroll and is gone (and
   unfocusable) back at the top; without scroll-driven animations it stays. */
@supports (animation-timeline: scroll()) {
    .to-top {
        animation: to-top-in linear both;
        animation-timeline: scroll(root block);
        animation-range: 40vh 70vh;
    }
}

@keyframes to-top-in {
    from {
        visibility: hidden;
        opacity: 0;
        translate: 0 1rem;
    }
}

/* ---------- Full-screen viewer ---------- */
html:has(.viewer[open]) {
    overflow: hidden;
}

.viewer {
    position: fixed;
    inset: 0;
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: clamp(4rem, 8svh, 5rem) clamp(4.5rem, 8vw, 7rem) clamp(1rem, 3svh, 2rem);
    border: 0;
    background: transparent;
    color: var(--c-text);
    overscroll-behavior: contain;
    touch-action: pan-y;
    opacity: 0;
    transition: opacity 0.3s ease, display 0.3s allow-discrete, overlay 0.3s allow-discrete;
}

/* The viewer takes focus when it opens: no ring round the whole screen. */
.viewer:focus {
    outline: none;
}

.viewer[open] {
    display: grid;
    opacity: 1;
}

@starting-style {
    .viewer[open] { opacity: 0; }
}

/* Dark, but the film stays faintly visible underneath. */
.viewer::backdrop {
    background: rgba(0, 0, 0, 0);
    transition: background 0.3s ease, display 0.3s allow-discrete, overlay 0.3s allow-discrete;
}

.viewer[open]::backdrop {
    background: rgba(0, 0, 0, 0.938);
}

@starting-style {
    .viewer[open]::backdrop { background: rgb(49 50 62 / 0); }
}

/* Photo and caption centred together. */
.viewer__figure {
    display: grid;
    align-content: center;
    gap: 1rem;
    min-height: 0;
    margin: 0;
}

.viewer__img {
    width: 100%;
    max-width: none;
    height: auto;
    /* Room for the caption and the close button. */
    max-height: calc(100svh - 17rem);
    object-fit: contain;
    transition: opacity 0.25s ease;
}

.viewer__img[data-loading] {
    opacity: 0;
    transition: none;
}

.viewer__caption {
    display: grid;
    gap: 0.5rem;
    justify-self: center;
    max-width: 70ch;
    text-align: center;
}

.viewer__caption > :empty {
    display: none;
}

/* Top left, mirroring the X: same top and height, inset like its glyph. */
.viewer__count {
    position: fixed;
    top: clamp(0.75rem, 2vw, 1.5rem);
    left: calc(clamp(0.75rem, 2vw, 1.5rem) + 1rem);
    display: flex;
    align-items: center;
    height: 3rem;
    margin: 0;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    opacity: 0.7;
}

.viewer__title {
    margin: 0;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    line-height: 1.2;
}

.viewer__meta {
    margin: 0;
    font-size: 0.875rem;
    opacity: 0.85;
}

/* Bare icons: only the colour changes on hover (round for the focus ring). */
.viewer__nav,
.viewer__close {
    position: fixed;
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--c-text);
    cursor: pointer;
    transition: color 0.2s ease;
}

.viewer__nav:hover,
.viewer__close:hover {
    color: var(--c-accent-hi);
}

.viewer__nav svg,
.viewer__close svg {
    width: 1.75rem;
    height: 1.75rem;
    /* Legible over a light photo (phones). */
    filter: drop-shadow(0 0 0.35rem rgb(0 0 0 / 0.6));
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.viewer__nav {
    top: 50%;
    translate: 0 -50%;
}

.viewer__nav--prev { left: clamp(0.5rem, 2vw, 1.5rem); }
.viewer__nav--next { right: clamp(0.5rem, 2vw, 1.5rem); }

.viewer__close {
    top: clamp(0.75rem, 2vw, 1.5rem);
    right: clamp(0.75rem, 2vw, 1.5rem);
}

.viewer[data-single] .viewer__nav {
    display: none;
}

/* Phones: the arrows float over the photo, which takes the full width. */
@media (max-width: 47.99em) {
    .viewer {
        padding-inline: 0.75rem;
    }

    .viewer__nav {
        width: 2.5rem;
        height: 2.5rem;
    }
}
