/* ============================================================================
   Define — timeline case study
   Used by the "timeline" project format (admin → Timelines). Scoped to .tl*
   so it can never touch the classic project template.

   Palette comes from the CMS via three custom properties written into the
   page by admin/lib/generate.php:
     --tl-accent  spine fill, active year, ticks, rules that need to sing
     --tl-ink     the project's text colour
     --tl-plate   the project's page background (used to break the spine)
   ========================================================================== */

.tl,
.tl-intro,
.tl-closing {
  --tl-accent: currentColor;
  --tl-ink: currentColor;
  --tl-plate: var(--royal-blue, #000);
  --tl-rule: color-mix(in srgb, var(--tl-ink) 22%, transparent);
  --tl-rule-soft: color-mix(in srgb, var(--tl-ink) 12%, transparent);
  --tl-muted: color-mix(in srgb, var(--tl-ink) 60%, transparent);
  --tl-top: 6.75rem;
  --tl-rail: 9.5rem;
  --tl-gap: clamp(1.5rem, 3.2vw, 3.25rem);
  /* screen video — override these to redress it on another timeline page */
  --tl-screen-radius: 8px;
  --tl-screen-stroke: color-mix(in srgb, #6D5B86 55%, transparent);
  --tl-screen-shadow: 0 18px 40px color-mix(in srgb, #0E0619 78%, transparent);
}

/* ------------------------------------------------------------- tracking ---- */

/* the site's base sheet sets negative letter-spacing on body, p and h1–h4.
   Nothing in the timeline sections inherits it — positive tracking on the
   small-caps labels is set on those rules directly and is unaffected. */
.tl-intro,
.tl,
.tl-closing,
.tl-intro p,
.tl-intro h1, .tl-intro h2, .tl-intro h3, .tl-intro h4,
.tl p,
.tl h1, .tl h2, .tl h3, .tl h4,
.tl li,
.tl-closing p,
.tl-closing h1, .tl-closing h2, .tl-closing h3, .tl-closing h4 {
  letter-spacing: 0;
}

/* ---------------------------------------------------------------- intro ---- */

/* label + deck on the left, the prose on the right; everything ranged left */
.tl-intro {
  position: relative;
  padding-top: clamp(4rem, 9vw, 8rem);
  padding-bottom: clamp(4rem, 9vw, 8rem);
}

.tl-intro-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--tl-gap);
  align-items: start;
}

.tl-intro-label {
  display: inline-flex;
  margin-bottom: 1.9rem;
}

/* type styling is shared with .tl-heading — see the narrative section below */
.tl-intro-deck {
  margin: 0;
  /* holds the deck to a readable measure instead of letting it run the
     column's full width on a wide screen */
  max-width: 13em;
}

/* same treatment as the narrative in the years below */
.tl-intro-body p {
  font-size: 1.0625em;
  line-height: 155%;
  letter-spacing: 0;
  max-width: 34em;
}

.tl-intro-body p + p {
  margin-top: 1em;
}

/* ------------------------------------------------------------- timeline ---- */

.tl {
  position: relative;
  padding-bottom: clamp(4rem, 9vw, 8rem);
}

/* year index -------------------------------------------------------------- */

.tl-yearnav {
  position: relative;
  z-index: 3;
  width: 90%;
  max-width: 80em;
  margin: 0 auto clamp(6rem, 8vw, 9rem);
  overflow-x: auto;
  scrollbar-width: none;
}

.tl-yearnav::-webkit-scrollbar { display: none; }

/* width:max-content + auto margins centres the strip when it fits and still
   lets it scroll from the left when it doesn't. The padding keeps the chips'
   borders and focus rings clear of the scroll container's edge. */
.tl-yearnav-inner {
  display: flex;
  gap: .5rem;
  width: max-content;
  padding: 2px;
  margin-inline: auto;
}

/* pill tabs in the site's secondary-button idiom: every chip carries the
   same stroke, nothing rules across the page */
.tl-yearnav-chip {
  flex: none;
  padding: .75em 1.2em;
  font-size: .75rem;
  font-weight: 400;
  letter-spacing: .1rem;
  line-height: 100%;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  color: var(--tl-muted);
  border: 1px solid var(--tl-rule);
  border-radius: 100vw;
  transition: color .3s ease, background-color .3s ease, border-color .3s ease;
}

.tl-yearnav-chip:hover {
  color: var(--tl-ink);
  border-color: var(--tl-ink);
}

/* the browser default outline is near-invisible on a dark project palette */
.tl-yearnav-chip:focus-visible {
  color: var(--tl-ink);
  outline: 2px solid var(--tl-accent);
  outline-offset: 2px;
}

.tl-yearnav-chip.is-current {
  color: var(--tl-plate);
  background-color: var(--tl-accent);
  border-color: var(--tl-accent);
}

/* the spine --------------------------------------------------------------- */

.tl-track { position: relative; }

.tl-spine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background-color: var(--tl-rule);
  pointer-events: none;
}

.tl-spine-fill {
  position: absolute;
  inset: 0 0 auto 0;
  display: block;
  height: 0;
  background-color: var(--tl-accent);
}

/* entries ----------------------------------------------------------------- */

.tl-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tl-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--tl-rail) minmax(0, 1fr);
  column-gap: var(--tl-gap);
  align-items: stretch;
  min-height: 70vh;
  padding-bottom: clamp(4.5rem, 9vw, 9rem);
  scroll-margin-top: var(--tl-top);
}

.tl-entry:last-child { padding-bottom: 0; }

.tl-col { min-width: 0; }
.tl-col-media { grid-column: 1; grid-row: 1; }

/* the year and the narrative are one sticky block spanning the rail and the
   text track, so they pin — and release — together */
.tl-col-text { grid-column: 2 / 4; grid-row: 1; }

/* What pins is the year and the heading — short enough to stay put for the
   whole of a year no matter how long the prose runs. The prose, the ledger
   and that year's images all scroll past underneath it. */
.tl-sticky {
  position: sticky;
  /* pinned against the very top, with the offset carried as padding so the
     header's plate can mask the prose passing beneath it; the negative margin
     cancels that padding while the header is still in flow */
  top: 0;
  padding-top: var(--tl-top);
  margin-top: calc(var(--tl-top) * -1);
  z-index: 2;
  display: flex;
  gap: var(--tl-gap);
  /* the year and the heading share a baseline — including when the heading
     runs to two lines, where it's the first line that lines up */
  align-items: baseline;
  pointer-events: none;
}

.tl-sticky > * { pointer-events: auto; }

.tl-headline {
  position: relative;
  flex: 1;
  min-width: 0;
  /* baseline alignment drops the heading below the sticky's padding; the
     padding carries the plate back up over the gap, the negative margin keeps
     the text itself where the baseline put it. Kept tight: this plus the
     ::before below is how far the plate reaches above the heading, and any
     further and it covers the year index sitting above the first entry. */
  padding-top: 2rem;
  margin-top: -2rem;
  padding-bottom: .6rem;
  background-color: var(--tl-plate);
}

/* fills the sticky element's top padding, so copy scrolling up disappears
   cleanly instead of showing above the heading */
.tl-headline::before {
  content: "";
  position: absolute;
  inset: auto 0 100% 0;
  height: var(--tl-top);
  background-color: var(--tl-plate);
}

.tl-headline::after {
  content: "";
  position: absolute;
  inset: 100% 0 auto 0;
  height: 1rem;
  pointer-events: none;
  background-image: linear-gradient(
    to bottom,
    var(--tl-plate),
    color-mix(in srgb, var(--tl-plate) 0%, transparent)
  );
}

/* the marker stays clear of the plate so the spine and its fill keep
   running behind the year rather than being masked at the top of the screen */
.tl-marker {
  flex: none;
  width: var(--tl-rail);
  text-align: center;
  padding-top: .2rem;
}

.tl-copy {
  margin-left: calc(var(--tl-rail) + var(--tl-gap));
  /* clears the headline's fade, so the first line is never under it */
  padding-top: 1rem;
}

/* the year's plate is painted after the node, so the node needs its own
   stacking context — otherwise the plate clips the active node's halo */
.tl-node {
  position: relative;
  z-index: 1;
  display: block;
  width: 9px;
  height: 9px;
  margin: 0 auto;
  border: 1px solid var(--tl-rule);
  border-radius: 50%;
  background-color: var(--tl-plate);
  transition: background-color .4s ease, border-color .4s ease, box-shadow .4s ease;
}

.tl-entry.is-active .tl-node {
  background-color: var(--tl-accent);
  border-color: var(--tl-accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--tl-accent) 16%, transparent);
}

.tl-year {
  display: block;
  padding: .55rem 0 .45rem;
  background-color: var(--tl-plate);
  font-family: Clashdisplay, sans-serif;
  font-weight: 600;
  font-size: clamp(1.375rem, 2.2vw, 2.125rem);
  line-height: 95%;
  letter-spacing: 0;
  white-space: nowrap;
  color: color-mix(in srgb, var(--tl-ink) 42%, transparent);
  transition: color .4s ease;
}

.tl-entry.is-active .tl-year { color: var(--tl-accent); }

/* the year also exists in the text column: the readable one for assistive
   tech on desktop, and the sticky chip on mobile */
.tl-year-head {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* narrative --------------------------------------------------------------- */

/* one type treatment for the year headings and the intro deck */
.tl-heading,
.tl-intro-deck {
  font-family: Clashdisplay, sans-serif;
  font-weight: 600;
  /* the site's base h3 is uppercase; these read as sentences */
  text-transform: none;
  font-size: clamp(1.375rem, 2.1vw, 2.125rem);
  line-height: 115%;
  letter-spacing: 0;
  /* Clash's word space is unusually tight at display sizes */
  word-spacing: .1em;
}

.tl-heading {
  margin: 0;
  max-width: 18em;
}

.tl-body p {
  font-size: 1.0625em;
  line-height: 155%;
  letter-spacing: 0;
  max-width: 34em;
}

.tl-body p + p { margin-top: 1em; }

/* the "meanwhile" ledger -------------------------------------------------- */

.tl-meanwhile {
  margin-top: 2.5rem;
  max-width: 34em;
  border: 1px solid var(--tl-rule);
  border-radius: 1.25rem;
  padding: 1.5rem;
}

/* the pill sits inside the card, heading the list rather than straddling
   the top edge */
.tl-meanwhile-label {
  display: inline-flex;
  align-items: center;
  margin-bottom: 1rem;
  padding: .5em 1em;
  border: 1px solid var(--tl-rule);
  border-radius: 100vw;
  background-color: var(--tl-plate);
  font-size: .6875rem;
  font-weight: 400;
  letter-spacing: .05rem;
  text-transform: uppercase;
  color: var(--tl-muted);
}

.tl-meanwhile-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tl-meanwhile-list li {
  position: relative;
  padding-left: 1.15em;
  font-size: .9375rem;
  line-height: 155%;
  letter-spacing: 0;
}

.tl-meanwhile-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: .62em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: color-mix(in srgb, var(--tl-ink) 45%, transparent);
}

/* no rules between the facts — the spacing does the separating */
.tl-meanwhile-list li + li { margin-top: .7rem; }

/* media column ------------------------------------------------------------ */

.tl-media {
  display: flex;
  flex-direction: column;
  gap: clamp(1.25rem, 2.6vw, 2.75rem);
}

/* every frame runs the full width of the media column; the file's own
   aspect ratio sets the height */
.tl-figure {
  margin: 0;
  width: 100%;
}

.tl-image {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: contain;
}

/* screen video ------------------------------------------------------------ */

/* a video dressed as a device screen. Width is per-frame, written into the
   figure by the CMS as --tl-screen-w; it centres in the column at anything
   under 100%. */
/* room for the shadow to fall into. Without it the next frame's box starts
   inside the shadow's reach and paints over it, ending it in a hard line —
   and lifting the figure instead would put it in front of the spine */
.tl-figure-screen {
  margin-block: 64px;
}

.tl-screen {
  width: var(--tl-screen-w, 100%);
  margin-inline: auto;
  border: 1px solid var(--tl-screen-stroke);
  border-radius: var(--tl-screen-radius);
  /* clips the video's corners to the stroke's inner edge */
  overflow: hidden;
  /* drop-shadow rather than box-shadow so it follows the rounded shape even
     if the video itself carries transparency */
  filter: drop-shadow(var(--tl-screen-shadow));
}

.tl-screen video,
.tl-screen img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: calc(var(--tl-screen-radius) - 1px);
}

/* the caption belongs to the screen, not the column */
.tl-figure-screen .tl-caption { text-align: center; }

/* embeds ------------------------------------------------------------------ */

/* whatever the embed's host hands over, held to the column's width. An iframe
   with no height of its own gets 16:9 — set one in the markup to override. */
.tl-embed {
  position: relative;
  width: 100%;
}

.tl-embed iframe,
.tl-embed video,
.tl-embed img,
.tl-embed svg,
.tl-embed canvas {
  display: block;
  max-width: 100%;
}

.tl-embed iframe {
  width: 100%;
  border: 0;
}

.tl-embed > iframe:only-child:not([height]):not([style*="height"]):not([style*="aspect-ratio"]) {
  aspect-ratio: 16 / 9;
  height: auto;
}

/* before / after ---------------------------------------------------------- */

/* the "after" image is the frame; the "before" is laid over it and clipped to
   the handle. A transparent range input covers the whole frame, so it drags
   with a pointer and steps with the arrow keys without any of that in JS. */
.tl-compare {
  --tl-compare-pos: 50%;
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
}

.tl-compare-img {
  display: block;
  width: 100%;
  height: auto;
}

.tl-compare-clip {
  position: absolute;
  inset: 0;
  clip-path: inset(0 calc(100% - var(--tl-compare-pos)) 0 0);
}

.tl-compare-clip .tl-compare-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tl-compare-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--tl-compare-pos);
  width: 1px;
  margin-left: -1px;
  background-color: var(--tl-screen-stroke);
  pointer-events: none;
}

.tl-compare-grip {
  position: absolute;
  top: 50%;
  left: var(--tl-compare-pos);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  width: 2.75rem;
  height: 2.75rem;
  transform: translate(-50%, -50%);
  border: 1px solid var(--tl-screen-stroke);
  border-radius: 50%;
  background-color: color-mix(in srgb, var(--tl-plate) 55%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

/* the two nudge arrows */
.tl-compare-grip::before,
.tl-compare-grip::after {
  content: "";
  width: 0;
  height: 0;
  border-top: .3rem solid transparent;
  border-bottom: .3rem solid transparent;
}

.tl-compare-grip::before { border-right: .34rem solid var(--tl-ink); }
.tl-compare-grip::after { border-left: .34rem solid var(--tl-ink); }

.tl-compare-range {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: ew-resize;
  -webkit-appearance: none;
  appearance: none;
  background-color: transparent;
}

/* a hairline thumb so the value maps to the full width of the frame */
.tl-compare-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 1px;
  height: 100%;
}

.tl-compare-range::-moz-range-thumb {
  width: 1px;
  height: 100%;
  border: 0;
  border-radius: 0;
}

.tl-compare-range:focus-visible ~ .tl-compare-grip {
  outline: 2px solid var(--tl-accent);
  outline-offset: 3px;
}

@media screen and (max-width: 479px) {
  .tl-compare-grip { width: 2.25rem; height: 2.25rem; }
}

.tl-caption {
  margin-top: .7rem;
  font-size: .6875rem;
  letter-spacing: .05rem;
  text-transform: uppercase;
  color: var(--tl-muted);
}

/* closing ----------------------------------------------------------------- */

.tl-closing {
  position: relative;
  padding-top: clamp(4rem, 9vw, 8rem);
  padding-bottom: clamp(4rem, 9vw, 7rem);
  border-top: 1px solid var(--tl-rule);
}

.tl-closing-grid {
  display: grid;
  grid-template-columns: minmax(0, 20rem) minmax(0, 1fr);
  gap: var(--tl-gap);
  align-items: start;
}

.tl-closing-heading {
  font-family: Clashdisplay, sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  font-size: clamp(1.75rem, 3vw, 2.75rem);
  line-height: 95%;
  letter-spacing: 0;
  word-spacing: .16em;
  margin: 0;
}

.tl-closing-body p {
  font-size: 1.25em;
  line-height: 150%;
  letter-spacing: 0;
  max-width: 36em;
}

.tl-closing-body p + p { margin-top: 1.1em; }

.tl-closing-media {
  width: 90%;
  max-width: 80em;
  margin: clamp(3rem, 6vw, 5rem) auto 0;
}

.tl-closing-media img {
  display: block;
  width: 100%;
  height: auto;
}

/* ---------------------------------------------------------------- motion --- */

/* the reveal only exists once the script has run, so a no-JS page is
   fully visible from the start */
.tl-js .tl-figure,
.tl-js .tl-meanwhile {
  opacity: 0;
  transform: translateY(1.25rem);
  transition: opacity .7s cubic-bezier(.22, .61, .36, 1),
              transform .7s cubic-bezier(.22, .61, .36, 1);
}

.tl-js .tl-figure.is-in,
.tl-js .tl-meanwhile.is-in {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .tl-js .tl-figure,
  .tl-js .tl-meanwhile {
    opacity: 1;
    transform: none;
    transition: none;
  }
  .tl-node,
  .tl-year,
  .tl-yearnav-chip { transition: none; }
}

/* narrow desktops: give the rail back to the two content columns */
@media screen and (min-width: 992px) and (max-width: 1200px) {
  .tl,
  .tl-intro,
  .tl-closing {
    --tl-rail: 6.5rem;
    --tl-gap: 1.75rem;
  }
}

/* ======================================================================== */
/* Tablet and below: one column, spine to the left, year pinned as a chip.   */
/* ======================================================================== */

@media screen and (max-width: 991px) {
  .tl,
  .tl-intro,
  .tl-closing {
    --tl-top: 4.5rem;
  }

  .tl-intro-grid,
  .tl-closing-grid {
    grid-template-columns: 1fr;
    gap: 1.75rem;
  }

  .tl-spine { left: 5px; transform: none; }

  /* one column: the narrative first, that year's images after it, and the
     year pinned across both because the entry itself is the sticky container */
  .tl-entry {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-left: 2.25rem;
    padding-bottom: 5.5rem;
  }

  .tl-year-head { order: 0; }
  .tl-col-text { order: 1; }
  .tl-col-media { order: 2; }

  .tl-sticky {
    position: static;
    display: block;
    padding-top: 0;
    margin-top: 0;
  }

  .tl-headline {
    padding-top: 0;
    margin-top: 0;
    padding-bottom: 0;
    background-color: transparent;
  }

  .tl-headline::before,
  .tl-headline::after { display: none; }

  .tl-year-head::after {
    content: "";
    position: absolute;
    inset: 100% 0 auto 0;
    height: 1.25rem;
    pointer-events: none;
    background-image: linear-gradient(
      to bottom,
      var(--tl-plate),
      color-mix(in srgb, var(--tl-plate) 0%, transparent)
    );
  }

  .tl-marker { display: none; }
  .tl-headline { margin-bottom: 1.5rem; }
  .tl-copy { margin-left: 0; padding-top: 0; }

  /* a real sticky header rather than a floating chip, so copy scrolling
     underneath is masked cleanly instead of being cut in half */
  .tl-year-head {
    position: sticky;
    top: 0;
    z-index: 4;
    width: calc(100% + 1.5rem);
    height: auto;
    margin: calc(var(--tl-top) * -1) 0 1.75rem -1.5rem;
    padding: var(--tl-top) 0 .7rem 1.5rem;
    overflow: visible;
    clip: auto;
    clip-path: none;
    border: 0;
    border-bottom: 1px solid var(--tl-rule);
    background-color: var(--tl-plate);
    font-family: Clashdisplay, sans-serif;
    font-weight: 600;
    font-size: 1.5rem;
    line-height: 1.2;
    letter-spacing: 0;
    color: var(--tl-accent);
  }

  .tl-year-head::before {
    content: "";
    display: inline-block;
    vertical-align: .32em;
    width: .6rem;
    height: 1px;
    margin-right: .55rem;
    background-color: var(--tl-accent);
  }

  .tl-media { margin-top: 2rem; }

  .tl-figure-screen { margin-block: 32px; }

  .tl-meanwhile { margin-top: 2rem; }

  .tl-heading { max-width: none; }
}

@media screen and (max-width: 767px) {
  .tl-intro-body p { max-width: none; }
  .tl-closing-body p { font-size: 1.0625em; }
  .tl-yearnav { margin-bottom: 6rem; }
  .tl-yearnav-chip { padding: .7em 1em; }
}

@media screen and (max-width: 479px) {
  .tl-entry { padding-left: 1.75rem; }
  .tl-year-head {
    font-size: 1.25rem;
    width: calc(100% + 1.25rem);
    margin-left: -1.25rem;
    padding-left: 1.25rem;
  }
  .tl-entry { padding-bottom: 4.5rem; }
  .tl-meanwhile { padding: 1.1rem; border-radius: 1rem; }
  .tl-body p,
  .tl-intro-body p { font-size: 1em; }
}
