/* Interactive photo/video timeline — "The Thread of Years" (#197). Loaded by
   timeline.html at /gallery/<slug>/timeline. Bump ?v= in timeline.html on edit. */
:root {
    --bg: #FAF8F5; --surface: #ffffff; --text: #1c1917; --muted: #78716c;
    --accent: #4a7c59; --accent-dark: #3a6147; --accent-bg: #f0f5f1; --ink: #1a3325;
    --line: #e3ded6;
    --serif: Georgia, "Times New Roman", serif;
    --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  }
  * { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0; background: var(--bg); color: var(--text);
    font-family: var(--sans); line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }
  a { color: var(--accent-dark); }

  /* ── Top bar ── */
  .tl-top {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 16px 22px; border-bottom: 1px solid var(--line); background: var(--bg);
    position: sticky; top: 0; z-index: 10; backdrop-filter: saturate(1.1);
  }
  .tl-top a.back {
    font-size: 0.82rem; color: var(--muted); text-decoration: none;
    display: inline-flex; align-items: center; gap: 6px;
  }
  .tl-top a.back:hover { color: var(--ink); }
  .tl-wordmark { font-family: var(--serif); font-size: 1.05rem; color: var(--ink); letter-spacing: .01em; }

  /* ── Intro ── */
  .tl-intro { text-align: center; padding: 56px 22px 20px; }
  .tl-intro .eyebrow {
    font-size: 0.7rem; letter-spacing: .22em; text-transform: uppercase;
    color: var(--accent); font-weight: 600;
  }
  .tl-intro h1 {
    font-family: var(--serif); font-weight: 400; color: var(--ink);
    font-size: clamp(1.9rem, 5vw, 2.9rem); margin: 12px 0 6px; letter-spacing: -0.01em;
    text-wrap: balance;
  }
  .tl-intro .years { color: var(--muted); font-size: 0.95rem; }
  .tl-intro .lead {
    max-width: 30rem; margin: 16px auto 0; color: var(--muted);
    font-family: var(--serif); font-style: italic; font-size: 1.05rem;
  }

  /* ── Timeline structure ── */
  .tl { position: relative; max-width: 1000px; margin: 30px auto 0; padding: 0 20px 80px; list-style: none; }
  /* the thread + its drawn (scroll-linked) fill */
  .tl-rail, .tl-fill { position: absolute; top: 0; width: 2px; left: 50%; transform: translateX(-50%); }
  .tl-rail { bottom: 0; background: var(--line); }
  .tl-fill { height: 0; background: linear-gradient(var(--accent), var(--accent)); border-radius: 2px; will-change: height; }

  /* Year chapter marker */
  .tl-year {
    position: relative; text-align: center; margin: 66px 0 26px; z-index: 2;
  }
  .tl-year .chip {
    display: inline-block; background: var(--bg); padding: 0 18px;
  }
  .tl-year .num {
    font-family: var(--serif); font-size: clamp(2rem, 6vw, 2.9rem); color: var(--ink);
    line-height: 1; letter-spacing: -0.01em;
  }
  .tl-year .age {
    display: block; margin-top: 6px; font-size: 0.68rem; letter-spacing: .18em;
    text-transform: uppercase; color: var(--muted);
  }
  .tl-year:first-of-type { margin-top: 8px; }

  /* Node */
  .tl-node { position: relative; width: 50%; padding: 14px 44px; z-index: 2; }
  .tl-node.left  { left: 0; text-align: right; }
  .tl-node.right { left: 50%; text-align: left; }
  /* connector dot on the thread */
  .tl-node::after {
    content: ""; position: absolute; top: 26px; width: 11px; height: 11px;
    background: var(--surface); border: 2px solid var(--accent); border-radius: 50%; z-index: 3;
  }
  .tl-node.left::after  { right: -6px; }
  .tl-node.right::after { left: -6px; }

  .tl-fig { margin: 0; display: inline-block; max-width: 420px; width: 100%; vertical-align: top; }
  .tl-media {
    position: relative; overflow: hidden; border-radius: 14px; background: var(--accent-bg);
    box-shadow: 0 10px 30px -18px rgba(26,51,37,.5); line-height: 0;
  }
  .tl-media img, .tl-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
  .tl-fig figcaption { padding: 10px 4px 0; }
  .tl-date { font-size: 0.72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-dark); font-weight: 600; }
  .tl-desc { margin: 4px 0 0; font-family: var(--serif); font-style: italic; color: var(--text); font-size: 1rem; }
  .tl-place {
    display: inline-flex; align-items: center; gap: 5px; margin-top: 7px;
    font-size: 0.76rem; color: var(--muted); text-decoration: none;
  }
  .tl-place:hover { color: var(--accent-dark); }
  .tl-place svg { width: 13px; height: 13px; }

  /* video play affordance */
  .tl-media.video::before {
    content: ""; position: absolute; inset: 0; background: rgba(26,51,37,.16); z-index: 1;
    transition: background .2s;
  }
  .tl-play {
    position: absolute; inset: 0; margin: auto; width: 56px; height: 56px; z-index: 2;
    border: none; border-radius: 50%; background: rgba(255,255,255,.92); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 20px -8px rgba(0,0,0,.5); transition: transform .15s;
  }
  .tl-play:hover { transform: scale(1.06); }
  .tl-play svg { width: 22px; height: 22px; margin-left: 3px; fill: var(--accent-dark); }

  /* ── Rich-year MOSAIC (#197): a square-thumbnail grid — loads the same ~10 KB cached
     thumbnails the galleries already use (NOT the full renditions), so a busy year is
     lightning fast. The busier the year, the tighter it packs. Tap any photo to open it
     full-size (lightbox). ── */
  .tl-cluster-wrap { position: relative; z-index: 2; margin: 4px 0 12px; }
  .tl-cluster { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 880px; margin: 0 auto; padding: 0 20px; }
  .tl-cluster.m-dense  { grid-template-columns: repeat(4, 1fr); gap: 8px; }   /* 13–24 photos */
  .tl-cluster.m-packed { grid-template-columns: repeat(5, 1fr); gap: 7px; }   /* 25+ photos */
  .tl-cfig { margin: 0; display: block; }
  .tl-cluster .tl-media { aspect-ratio: 1; border-radius: 10px; }
  .tl-ccap { font-family: var(--serif); font-style: italic; font-size: .82rem; color: var(--muted); padding: 5px 2px 0; }
  .tl-cluster.m-dense .tl-ccap, .tl-cluster.m-packed .tl-ccap { display: none; }  /* a dense year reads as a clean mosaic — the year is the label */

  /* reveal animation */
  .tl-node, .tl-year, .tl-cluster-wrap { opacity: 0; transform: translateY(16px); transition: opacity .7s ease, transform .7s cubic-bezier(.22,.61,.36,1); }
  .tl-node.in, .tl-year.in, .tl-cluster-wrap.in { opacity: 1; transform: none; }

  /* ── "More memories" tail (undated) ── */
  .tl-more { max-width: 1000px; margin: 30px auto 90px; padding: 0 22px; }
  .tl-more h2 {
    font-family: var(--serif); font-weight: 400; color: var(--ink); text-align: center;
    font-size: 1.5rem; margin: 0 0 22px;
  }
  .tl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .tl-grid .tl-media { border-radius: 12px; aspect-ratio: 1/1; }

  /* states */
  .tl-msg { text-align: center; color: var(--muted); padding: 80px 22px; font-family: var(--serif); font-style: italic; }

  /* ── Year scrubber (jump / scrub through the years — touch-friendly) ── */
  .tl-scrub {
    position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 20; width: min(520px, calc(100vw - 28px));
    background: rgba(255,255,255,.94); backdrop-filter: blur(10px) saturate(1.1);
    border: 1px solid var(--line); border-radius: 20px;
    padding: 9px 18px 12px; box-shadow: 0 12px 34px -12px rgba(26,51,37,.42);
    opacity: 0; transform: translateX(-50%) translateY(10px); pointer-events: none;
    transition: opacity .35s ease, transform .35s ease;
  }
  .tl-scrub.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
  .tl-scrub-now { display: block; text-align: center; font-family: var(--serif); font-size: 1.2rem; color: var(--ink); line-height: 1.25; }
  .tl-scrub-row { display: flex; align-items: center; gap: 12px; margin-top: 2px; }
  .tl-scrub-end { font-size: .72rem; color: var(--muted); flex: 0 0 auto; font-variant-numeric: tabular-nums; }
  input#scrub-range {
    -webkit-appearance: none; appearance: none; flex: 1; height: 4px; border-radius: 999px;
    background: var(--accent-bg); outline: none; cursor: pointer; margin: 8px 0;
  }
  input#scrub-range::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%;
    background: var(--accent); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(26,51,37,.35); cursor: grab;
  }
  input#scrub-range::-webkit-slider-thumb:active { cursor: grabbing; }
  input#scrub-range::-moz-range-thumb {
    width: 22px; height: 22px; border-radius: 50%; background: var(--accent);
    border: 3px solid #fff; box-shadow: 0 2px 8px rgba(26,51,37,.35); cursor: grab;
  }
  input#scrub-range:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; }

  /* ── Lightbox — full-size image on tap (loads the display rendition on demand) ── */
  .tl-lb { position: fixed; inset: 0; z-index: 50; background: rgba(20,18,16,.94); display: none; align-items: center; justify-content: center; padding: 24px; }
  .tl-lb.show { display: flex; }
  .tl-lb-fig { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 100%; }
  .tl-lb-fig img { max-width: 100%; max-height: calc(100vh - 130px); max-height: calc(100dvh - 130px); object-fit: contain; border-radius: 6px; box-shadow: 0 24px 70px -20px rgba(0,0,0,.8); }
  .tl-lb-cap { color: rgba(255,255,255,.86); font-family: var(--serif); font-style: italic; font-size: 1rem; line-height: 1.5; text-align: center; max-width: 42rem; padding: 0 8px; }
  .tl-lb-close {
    position: absolute; top: 14px; right: 16px; width: 44px; height: 44px; border: none; border-radius: 50%;
    background: rgba(255,255,255,.14); color: #fff; font-size: 1.7rem; line-height: 1; cursor: pointer; transition: background .15s;
  }
  .tl-lb-close:hover { background: rgba(255,255,255,.26); }

  /* ── Mobile: single column, thread on the left ── */
  @media (max-width: 720px) {
    .tl { padding: 0 16px 60px; }
    .tl-rail, .tl-fill { left: 18px; }
    .tl-year { text-align: left; margin: 44px 0 20px; padding-left: 6px; }
    .tl-year .chip { padding: 0 10px 0 0; }
    .tl-node { width: 100%; left: 0 !important; text-align: left !important; padding: 12px 0 12px 44px; }
    .tl-node::after { left: 13px !important; right: auto !important; top: 24px; }
    .tl-fig { max-width: 100%; }
    .tl-cluster { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 0 8px 0 44px; }  /* sit to the right of the thread */
    .tl-cluster.m-dense, .tl-cluster.m-packed { grid-template-columns: repeat(3, 1fr); gap: 7px; }
  }

  @media (prefers-reduced-motion: reduce) {
    .tl-node, .tl-year, .tl-cluster-wrap { opacity: 1; transform: none; transition: none; }
    * { scroll-behavior: auto !important; }
  }
