/* ==========================================================================
   NewLine Break — notes and films. The one dark chapter: an edge-to-edge cut to neutral
   black, where the colour comes from the films themselves. Scrolling down
   walks sideways along them; the one in the middle plays.
   ========================================================================== */

.films {
  --tile-h: clamp(17rem, 100dvh - 25.5rem, 31rem);
  --tile-w: calc(var(--tile-h) * 9 / 16);
  --tile-gap: 1rem;
  --n: 11;
  --rail-w: calc(var(--n) * var(--tile-w) + (var(--n) - 1) * var(--tile-gap) + 2 * var(--edge));
  --pan: max(0px, calc(var(--rail-w) - 100vw));
  background: var(--night);
  color: var(--on-night);
}

.films .nl--return::before { border-color: var(--break-night); }
.films :focus-visible { outline-color: var(--on-night); }

.films__pin { padding-top: clamp(5.5rem, 12vh, 7rem); }

.films__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 26rem);
  align-items: end;
  gap: 1.5rem 3rem;
  padding-inline: var(--edge);
}

.films__head .lede { color: var(--on-night-dim); font-size: 1.0625rem; }

/* By hand first: the rail scrolls sideways and snaps. Where the scroll
   position can drive it, the block at the end of this file takes over. */
.rail {
  display: flex;
  gap: var(--tile-gap);
  margin-top: clamp(1.75rem, 4vh, 2.75rem);
  padding-inline: var(--edge);
  padding-bottom: 0.5rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: var(--edge);
  scrollbar-width: none;
}

.rail::-webkit-scrollbar { display: none; }
.film { scroll-snap-align: start; }

.film { flex: none; width: var(--tile-w); }
.film__a { display: grid; gap: 0.8rem; }

.film__frame {
  position: relative;
  display: block;
  height: var(--tile-h);
  border-radius: var(--r-m);
  overflow: hidden;
  background: var(--night-raised);
  box-shadow: 0 0 0 1px var(--night-line);
}

.film__frame :is(img, video) { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* A film is fetched and shown only once the script starts it; until then,
   and without scripting, the poster under it is the picture. */
.js .film__frame video { opacity: 0; transition: opacity 0.3s cubic-bezier(0, 0, 0.2, 1); }
.js .film.is-playing video { opacity: 1; }

/* With scripting off a browser gives every video its own controls, and an
   empty one would cover its poster. */
html:not(.js) .film__frame video { display: none; }

/* The film in the middle is lit; its neighbours wait at a step down. */
.film__frame::after {
  content: '';
  position: absolute; inset: 0;
  background-color: color-mix(in srgb, var(--night) 26%, transparent);
  transition: background-color 0.35s var(--ease-ui);
  pointer-events: none;
}

.film.is-playing .film__frame::after { background-color: transparent; }
.film--all .film__frame::after { content: none; }
@media (hover: hover) { .film__a:hover .film__frame::after { background-color: transparent; } }

.film__meta { display: grid; gap: 0.2rem; font-size: 0.9375rem; line-height: 1.32; }
.film__meta time { font-family: var(--mono); font-size: 0.8125rem; color: var(--on-night-dim); }

.film__meta b {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  font-weight: 400;
  color: var(--on-night);
}

.film--all .film__frame {
  display: grid;
  align-content: end;
  gap: 0.3rem;
  padding: 1.25rem;
  background: var(--night-raised);
  font-size: 0.9375rem;
  color: var(--on-night-dim);
  transition: background-color 0.18s var(--ease-ui);
}

.film--all b { font-size: 1.5rem; font-variation-settings: 'wdth' 100, 'wght' 540; font-weight: 540; letter-spacing: -0.03em; line-height: 1.1; color: var(--on-night); }
@media (hover: hover) { .film--all .film__a:hover .film__frame { background: var(--night-lit); } }

/* --------------------------------------------------------------------------
   Every note, newest first. The one plain list on the page.
   -------------------------------------------------------------------------- */

.notes { padding: clamp(3.5rem, 7vw, 6rem) var(--edge) clamp(5rem, 9vw, 7.5rem); }
.notes__h { margin-bottom: 1.25rem; font-size: 0.9375rem; color: var(--on-night-dim); }

.notes__list { columns: 2; column-gap: clamp(2rem, 5vw, 5rem); border-top: 1px solid var(--night-line); }
.notes__list li { break-inside: avoid; }

.notes__list a {
  display: grid;
  grid-template-columns: 3.75rem minmax(0, 1fr);
  gap: 1rem;
  padding: 0.72rem 0;
  border-bottom: 1px solid var(--night-line);
  font-size: 0.9375rem;
  line-height: 1.38;
  color: var(--on-night-dim);
  transition: color 0.18s var(--ease-ui);
}

.notes__list time { font-size: 0.8125rem; line-height: 1.6; }
.notes__list span { color: var(--on-night); transition: color 0.18s var(--ease-ui); }
@media (hover: hover) { .notes__list a:hover span { color: var(--on-signal); } .notes__list a:hover { color: var(--on-night); } }

/* --------------------------------------------------------------------------
   Pinned: the chapter holds one screen while the rail passes sideways.
   One pixel down is one pixel along. No listener: the scroll position is the
   animation's clock. Without support, the rail scrolls sideways by hand.
   -------------------------------------------------------------------------- */

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) and (min-width: 861px) and (min-height: 640px) {
    .films__track {
      height: calc(100dvh + var(--pan));
      view-timeline: --films block;
      view-timeline-inset: 0;
    }

    .films__pin { position: sticky; top: 0; height: 100dvh; overflow: clip; }

    .rail {
      width: max-content;
      overflow: visible;
      scroll-snap-type: none;
      will-change: transform;
      animation: rail-pan linear both;
      animation-timeline: --films;
      animation-range: contain 0% contain 100%;
    }

    @keyframes rail-pan { to { transform: translateX(calc(-1 * var(--pan))); } }
  }
}

@media (max-width: 860px) {
  .films { --tile-h: 23rem; }
  .films__head { grid-template-columns: minmax(0, 1fr); }
  .notes__list { columns: 1; }
}
