// Shared tokens & components for the Those Days website.
// Direction A — Periodical. Bone paper, ink, signal red.
// Modern type via the SF Pro / Inter Tight system stack;
// JetBrains Mono retained only for utility labels (issue numbers,
// captions, accession marks). Nostalgia comes from paper grain,
// hairlines, photo plates, and editorial layout — not the type.

const TD = {
  // PALETTE — bone + ink + signal red
  paper: '#ffffff',
  paperWarm: '#f4f3ef',     // slightly recessed band — for the "Why us" slab
  card: '#ffffff',
  ink: '#1a1a1a',
  mid: 'rgba(26,26,26,0.62)',
  light: 'rgba(26,26,26,0.32)',
  hair: 'rgba(26,26,26,0.16)',
  hairBold: 'rgba(26,26,26,0.32)',
  // Photo placeholder tones (neutral grey)
  slot: '#dcdad3',
  slotDeep: '#c8c5be',
  slotInk: 'rgba(26,26,26,0.55)',
  // Signature accent
  accent: '#b53a26',

  display: '-apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter Tight", "Helvetica Neue", sans-serif',
  body: '-apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter Tight", "Helvetica Neue", sans-serif',
  mono: '"JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace',
};

(function injectSharedStyles() {
  const existing = document.getElementById('td-site-shared');
  if (existing) existing.remove();
  const s = document.createElement('style');
  s.id = 'td-site-shared';
  s.textContent = `
    .td-site {
      font-family: ${TD.body};
      color: ${TD.ink};
      background: ${TD.paper};
      line-height: 1.5;
      -webkit-font-smoothing: antialiased;
      font-feature-settings: "liga","kern";
      position: relative;
    }
    .td-site * { box-sizing: border-box; }
    html { scroll-behavior: smooth; }
    .td-site section[id] { scroll-margin-top: 20px; }

    /* TYPE */
    .td-site .eyebrow { font-family: ${TD.mono}; font-weight: 400; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: ${TD.mid}; }
    .td-site .display { font-family: ${TD.display}; font-weight: 700; letter-spacing: -0.028em; line-height: 0.96; }
    .td-site .display-tight { font-family: ${TD.display}; font-weight: 700; letter-spacing: -0.036em; line-height: 0.92; }
    .td-site .display-xl { font-family: ${TD.display}; font-weight: 700; letter-spacing: -0.046em; line-height: 0.9; }
    .td-site .display-italic { font-family: ${TD.display}; font-weight: 400; font-style: normal; letter-spacing: -0.018em; line-height: 0.96; }
    .td-site .accent-red { color: ${TD.accent}; }

    /* RULES */
    .td-site .rule { height: 1px; background: ${TD.hairBold}; }
    .td-site .rule-thick { height: 1px; background: ${TD.hairBold}; }
    .td-site .rule-hair { height: 1px; background: ${TD.hair}; }

    /* LINKS */
    .td-site a { color: inherit; text-decoration: none; }
    .td-site .link { display: inline-block; position: relative; padding-bottom: 2px; transition: color .25s; }
    .td-site .link::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: currentColor; transform-origin: left center; transition: transform .35s cubic-bezier(.2,.7,.3,1); }
    .td-site .link:hover { color: ${TD.accent}; }
    .td-site .link:hover::after { transform: scaleX(0.55); transform-origin: right center; background: ${TD.accent}; }

    /* NAV */
    .td-site .nav-link { display: inline-block; padding: 4px 0; font-family: ${TD.mono}; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: ${TD.ink}; position: relative; transition: color .25s; }
    .td-site .nav-link::after { content: ''; position: absolute; left: 0; right: 0; bottom: -4px; height: 1px; background: ${TD.accent}; transform: scaleX(0); transform-origin: left center; transition: transform .3s cubic-bezier(.2,.7,.3,1); }
    .td-site .nav-link:hover { color: ${TD.accent}; }
    .td-site .nav-link:hover::after { transform: scaleX(1); }

    /* Founder card mini-links — same eyebrow type, accent on hover */
    .td-site .founder-link { text-decoration: none; transition: color .25s ease; }
    .td-site .founder-link:hover { color: ${TD.accent} !important; }

    /* Team carousel */
    .td-site .team-rail { scrollbar-color: ${TD.hairBold} transparent; cursor: grab; }
    .td-site .team-rail.is-dragging { cursor: grabbing; user-select: none; }
    .td-site .team-rail::-webkit-scrollbar { height: 6px; }
    .td-site .team-rail::-webkit-scrollbar-thumb { background: ${TD.hairBold}; border-radius: 999px; }
    .td-site .team-rail::-webkit-scrollbar-track { background: transparent; }
    .td-site .team-nav-btn {
      width: 36px; height: 36px; border-radius: 999px;
      border: 1px solid ${TD.hair};
      background: ${TD.paper};
      color: ${TD.ink};
      font-size: 18px; line-height: 1;
      cursor: pointer;
      display: inline-flex; align-items: center; justify-content: center;
      transition: background .25s ease, border-color .25s ease, color .25s ease;
    }
    .td-site .team-nav-btn:hover {
      background: ${TD.ink}; color: ${TD.paper}; border-color: ${TD.ink};
    }

    /* REVEAL — content is visible by DEFAULT; the hidden initial state is
       only applied once JS adds .reveals-armed to the root, so the page is
       never blank if the script is slow, blocked, or the observer misfires. */
    .td-site .reveal { transition: opacity 1s cubic-bezier(.2,.7,.3,1), transform 1s cubic-bezier(.2,.7,.3,1); }
    .td-site.reveals-armed .reveal { opacity: 0; transform: translateY(20px); }
    .td-site .reveal.in { opacity: 1; transform: translateY(0); }

    /* PHOTO PLATE — neutral grey placeholder with film grain */
    .td-site .photo {
      position: relative; overflow: hidden;
      background:
        radial-gradient(at 30% 30%, rgba(180,180,178,0.5), transparent 60%),
        radial-gradient(at 70% 70%, rgba(40,40,38,0.55), transparent 55%),
        linear-gradient(180deg, ${TD.slotDeep}, #2e2c28);
      filter: grayscale(0.2) contrast(0.97);
    }
    .td-site .photo::after {
      content: ''; position: absolute; inset: 0;
      background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.95' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.28 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
      mix-blend-mode: overlay; opacity: 0.55; pointer-events: none;
    }
    .td-site .photo-tag {
      position: absolute; bottom: 14px; left: 14px;
      padding: 4px 10px;
      background: rgba(247,244,236,0.94);
      color: ${TD.ink};
      font-family: ${TD.mono}; font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase;
      z-index: 2;
    }
    .td-site .photo-num {
      position: absolute; top: 14px; right: 14px;
      font-family: ${TD.mono}; font-size: 9.5px; letter-spacing: 0.14em; color: rgba(247,244,236,0.85);
      z-index: 2;
    }

    /* DROP CAP for the first column of the intro */
    .td-site .dropcap::first-letter {
      font-family: ${TD.display}; font-weight: 700;
      font-size: 5.6em; line-height: 0.86; float: left;
      padding: 6px 12px 0 0; margin-top: 4px;
      color: ${TD.ink};
    }
    .td-site .col-body { font-size: 15px; line-height: 1.6; }
    .td-site .col-body p { margin: 0 0 14px; }

    /* HOVER LINKS in work / contact rows */
    .td-site .arrow { display: inline-block; transition: transform .3s, color .25s; }
    .td-site a:hover .arrow { transform: translateX(4px); color: ${TD.accent}; }

    /* CURSOR DOT */
    .td-site .cursor-dot { position: fixed; width: 8px; height: 8px; border-radius: 50%; background: ${TD.ink}; pointer-events: none; z-index: 9999; transform: translate(-50%, -50%); mix-blend-mode: difference; transition: width .25s, height .25s, background .25s; }
    .td-site .cursor-dot.hover { width: 38px; height: 38px; background: ${TD.accent}; mix-blend-mode: normal; opacity: 0.85; }

    /* CTA BUTTONS */
    .td-site .btn {
      display: inline-flex; align-items: center; gap: 10px;
      padding: 13px 24px;
      font-family: ${TD.mono}; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
      border-radius: 999px; transition: background .25s, color .25s, border-color .25s;
    }
    .td-site .btn-primary { background: ${TD.ink}; color: ${TD.paper}; border: 1px solid ${TD.ink}; }
    .td-site .btn-primary:hover { background: ${TD.accent}; border-color: ${TD.accent}; }
    .td-site .btn-ghost { background: transparent; color: ${TD.ink}; border: 1px solid ${TD.hairBold}; }
    .td-site .btn-ghost:hover { background: ${TD.ink}; color: ${TD.paper}; border-color: ${TD.ink}; }

    /* CAPTION strip below a photo — museum-label style */
    .td-site .plate { display: block; }
    .td-site .plate .photo { box-shadow: inset 0 0 0 1px rgba(247,244,236,0.18); }
    .td-site .plate-cap {
      display: flex; justify-content: space-between; gap: 16px;
      padding-top: 10px;
      font-family: ${TD.mono}; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
      color: ${TD.mid};
    }
    .td-site .plate-cap .em { font-family: ${TD.body}; font-style: italic; text-transform: none; letter-spacing: -0.005em; font-size: 13px; }

    /* CORNER page mark — small, top-right inside section head */
    .td-site .page-mark { font-family: ${TD.mono}; font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: ${TD.mid}; }

    /* ============================================================ */
    /* IMMERSIVE LAYER — cover page, scroll progress, indicator,    */
    /* photo parallax, headline reveal stagger.                     */
    /* ============================================================ */

    /* COVER PAGE — 100vh entry, with optional background video */
    .td-site .cover-page {
      min-height: 100vh; display: flex; flex-direction: column;
      padding: 32px 56px 40px;
      position: relative;
      overflow: hidden;
    }
    /* Animated placeholder backdrop — replaced by <video> once a file exists */
    .td-site .cover-bg {
      position: absolute; inset: 0; z-index: 0; pointer-events: none;
      background:
        radial-gradient(at 22% 28%, rgba(140,40,30,0.20), transparent 55%),
        radial-gradient(at 78% 72%, rgba(40,30,25,0.45), transparent 50%),
        linear-gradient(135deg, #2c2825 0%, #1a1816 100%);
      animation: cover-bg-pan 28s ease-in-out infinite alternate;
    }
    @keyframes cover-bg-pan {
      0%   { transform: scale(1.04) translate3d(-1.5%, -1%, 0); }
      100% { transform: scale(1.08) translate3d( 1.5%,  1%, 0); }
    }
    /* The video sits in the same layer as .cover-bg and replaces it visually if loaded */
    .td-site .cover-video {
      position: absolute; inset: 0; width: 100%; height: 100%;
      object-fit: cover; z-index: 1; pointer-events: none;
      opacity: 0; transition: opacity .8s ease;
    }
    .td-site .cover-video.is-ready { opacity: 1; }
    /* Dark overlay + blur — between media and content (inverted cover) */
    .td-site .cover-veil {
      position: absolute; inset: 0; z-index: 2; pointer-events: none;
      background:
        linear-gradient(180deg, rgba(12,11,10,0.45) 0%, rgba(12,11,10,0.55) 60%, rgba(12,11,10,0.7) 100%);
      backdrop-filter: blur(5px) saturate(0.9);
      -webkit-backdrop-filter: blur(5px) saturate(0.9);
    }
    /* Bring all cover content above the media layers */
    .td-site .cover-page > .cover-meta-row,
    .td-site .cover-page > .cover-mark { position: relative; z-index: 3; }
    .td-site .cover-meta-row { display: flex; justify-content: space-between; align-items: baseline; gap: 24px; white-space: nowrap; }
    .td-site .cover-mark {
      flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
      text-align: center; padding: 32px 0 24px;
    }
    .td-site .cover-wm {
      display: block;
      width: clamp(280px, 68vw, 880px);
      height: auto;
      max-width: 100%;
      filter: invert(1) brightness(1.05);
    }
    .td-site .cover-tag {
      font-family: ${TD.display}; font-weight: 300; font-style: normal;
      font-size: clamp(17px, 1.35vw, 21px); color: rgba(247,244,236,0.78);
      margin-top: 26px; max-width: 720px; line-height: 1.45;
    }
    /* Glass pill CTA on the dark cover */
    .td-site .cover-cta {
      margin-top: 32px;
      display: inline-flex; align-items: center; gap: 14px;
      white-space: nowrap;
      padding: 14px 26px 14px 28px;
      border-radius: 999px;
      font-family: ${TD.mono}; font-size: 11px; letter-spacing: 0.18em;
      text-transform: uppercase; color: ${TD.paper};
      text-decoration: none;
      background: rgba(247, 244, 236, 0.08);
      border: 1px solid rgba(247, 244, 236, 0.32);
      backdrop-filter: blur(14px) saturate(1.1);
      -webkit-backdrop-filter: blur(14px) saturate(1.1);
      box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.18),
        inset 0 -1px 0 rgba(0,0,0,0.18),
        0 8px 24px rgba(0,0,0,0.18);
      transition: background .3s ease, border-color .3s ease, transform .35s cubic-bezier(.2,.7,.3,1);
    }
    .td-site .cover-cta:hover {
      background: rgba(247, 244, 236, 0.16);
      border-color: rgba(247, 244, 236, 0.55);
      transform: translateY(-1px);
    }
    .td-site .cover-cta-arrow {
      display: inline-block;
      font-family: ${TD.display}; font-size: 14px; letter-spacing: 0;
      transition: transform .35s cubic-bezier(.2,.7,.3,1);
    }
    .td-site .cover-cta:hover .cover-cta-arrow {
      transform: translate(3px, -3px);
    }
    /* All eyebrows / meta inside the cover read on dark */
    .td-site .cover-page .eyebrow { color: rgba(247,244,236,0.7); }
    .td-site .cover-scroll {
      display: flex; flex-direction: column; align-items: center; gap: 12px;
      padding-top: 20px;
    }
    .td-site .cover-scroll-line {
      width: 1px; height: 44px;
      background: linear-gradient(180deg, ${TD.paper}, transparent);
      animation: scroll-pulse 2.6s ease-in-out infinite;
      transform-origin: top center;
    }
    /* Nav adopts paper-on-dark while sticky over the cover */
    .td-site.over-cover nav .nav-link { color: ${TD.paper}; }
    .td-site.over-cover nav .nav-link:hover { color: ${TD.accent}; }
    .td-site.over-cover nav .td-wordmark { filter: invert(1) !important; }
    @keyframes scroll-pulse {
      0%, 100% { transform: scaleY(0.55); opacity: 0.85; }
      50% { transform: scaleY(1.0); opacity: 0.3; }
    }

    /* SCROLL PROGRESS HAIRLINE — top of viewport */
    .td-site .scroll-progress {
      position: fixed; top: 0; left: 0; right: 0; height: 2px;
      background: rgba(26,26,26,0.05); z-index: 100; pointer-events: none;
    }
    .td-site .scroll-progress > i {
      display: block; height: 100%; width: var(--p, 0%);
      background: ${TD.accent};
    }

    /* SECTION INDICATOR — fixed right edge */
    .td-site .section-ind {
      position: fixed; right: 28px; top: 50%; transform: translateY(-50%);
      display: flex; flex-direction: column; gap: 18px; z-index: 60;
      mix-blend-mode: difference;
    }
    .td-site .section-ind a {
      display: inline-flex; align-items: center; gap: 12px;
      font-family: ${TD.mono}; font-size: 9.5px; letter-spacing: 0.2em; text-transform: uppercase;
      color: ${TD.paper}; opacity: 0.55; transition: opacity .3s;
      text-decoration: none;
    }
    .td-site .section-ind a .dot {
      width: 6px; height: 6px; border-radius: 50%; background: ${TD.paper};
      opacity: 0.45; transition: opacity .3s, transform .3s, background .3s;
    }
    .td-site .section-ind a .lbl {
      opacity: 0; transform: translateX(6px);
      transition: opacity .3s, transform .3s;
    }
    .td-site .section-ind a:hover { opacity: 1; }
    .td-site .section-ind a:hover .lbl { opacity: 1; transform: translateX(0); }
    .td-site .section-ind a.active { opacity: 1; }
    .td-site .section-ind a.active .dot { opacity: 1; transform: scale(1.4); }
    .td-site .section-ind a.active .lbl { opacity: 1; transform: translateX(0); }
    @media (max-width: 1100px) { .td-site .section-ind { display: none; } }

    /* PARALLAX PHOTO container */
    .td-site .px-frame { position: relative; overflow: hidden; }
    .td-site .px-frame .px-inner { position: absolute; inset: -8% 0; will-change: transform; }

    /* HEADLINE REVEAL — line-by-line stagger */
    .td-site .hl-stagger > * {
      transition: opacity .9s cubic-bezier(.2,.7,.3,1), transform .9s cubic-bezier(.2,.7,.3,1);
    }
    .td-site.reveals-armed .hl-stagger > * {
      opacity: 0; transform: translateY(28px);
    }
    .td-site .reveal.in .hl-stagger > *,
    .td-site .reveal.in.hl-stagger > * { opacity: 1; transform: translateY(0); }
    .td-site .reveal.in .hl-stagger > *:nth-child(2),
    .td-site .reveal.in.hl-stagger > *:nth-child(2) { transition-delay: 100ms; }
    .td-site .reveal.in .hl-stagger > *:nth-child(3),
    .td-site .reveal.in.hl-stagger > *:nth-child(3) { transition-delay: 200ms; }
    .td-site .reveal.in .hl-stagger > *:nth-child(4),
    .td-site .reveal.in.hl-stagger > *:nth-child(4) { transition-delay: 300ms; }

    /* SECTION HEAD STRIP — reveals from both sides */
    .td-site .sec-head-l, .td-site .sec-head-r { transition: opacity .8s ease, transform .8s ease; }
    .td-site.reveals-armed .sec-head-l, .td-site.reveals-armed .sec-head-r { opacity: 0; }
    .td-site.reveals-armed .sec-head-l { transform: translateX(-12px); }
    .td-site.reveals-armed .sec-head-r { transform: translateX(12px); }
    .td-site .reveal.in .sec-head-l, .td-site .reveal.in .sec-head-r { opacity: 1; transform: translateX(0); }

    /* ============================================================ */
    /* MOBILE — collapse two-col layouts, shrink padding & type     */
    /* ============================================================ */
    @media (max-width: 760px) {
      /* hide custom cursor on touch */
      .td-site .cursor-dot { display: none !important; }

      /* The section-head "hang into the margin" offset (translateX ±12px)
         reads as intentional against the 56px desktop gutter, but on the
         18px mobile gutter it shoves eyebrows to the screen edge and makes
         every section label sit at a different left edge — kill it so labels
         line up cleanly with their headings/body. */
      .td-site .sec-head-l, .td-site .sec-head-r { transform: none !important; }

      /* NAV */
      .td-site > nav {
        padding: 14px 18px !important;
        gap: 14px !important;
      }
      .td-site > nav > a > img { height: 28px !important; }
      .td-site > nav > div {
        gap: 14px !important;
        flex-wrap: wrap;
        justify-content: flex-end;
      }
      .td-site .nav-link { font-size: 10px; letter-spacing: 0.14em; }

      /* COVER */
      .td-site .cover-page {
        padding: 20px 18px 28px !important;
        margin-top: -52px !important;
      }
      .td-site .cover-meta-row {
        flex-wrap: wrap;
        gap: 6px 14px;
        white-space: normal !important;
      }
      .td-site .cover-meta-row .eyebrow { font-size: 10px; }
      .td-site .cover-mark { padding: 32px 0 20px !important; }
      .td-site .cover-wm { width: 80vw !important; }
      .td-site .cover-tag {
        font-size: 14px !important;
        line-height: 1.45 !important;
        max-width: 90vw;
        margin-top: 18px !important;
      }

      /* universal section horizontal padding */
      .td-site section[id] {
        padding-left: 18px !important;
        padding-right: 18px !important;
      }

      /* Section I (cover-story) — stack the two columns */
      .td-site #cover-story {
        grid-template-columns: 1fr !important;
        gap: 40px !important;
        padding-top: 64px !important;
        padding-bottom: 72px !important;
        align-items: start !important;
      }
      .td-site #cover-story h2 {
        font-size: clamp(40px, 11vw, 64px) !important;
        line-height: 0.98 !important;
      }
      .td-site #cover-story p { font-size: 16px !important; max-width: 100% !important; }
      .td-site #cover-story .btn { padding: 11px 18px; font-size: 10px; }

      /* Section II (intro) */
      .td-site #intro { padding-bottom: 56px !important; }
      .td-site #intro > p {
        font-size: clamp(24px, 6.5vw, 32px) !important;
        margin-bottom: 56px !important;
        line-height: 1.2 !important;
        letter-spacing: -0.015em !important;
      }
      .td-site #intro > div p { font-size: 16px !important; }
      .td-site .intro-body-grid {
        grid-template-columns: 1fr !important;
        gap: 48px !important;
      }
      .td-site .bcn-mark { max-width: 220px !important; }

      /* Section III — pods stack, smaller heading */
      .td-site #what-we-do { padding-bottom: 72px !important; }
      .td-site #what-we-do > h3 { font-size: clamp(40px, 11vw, 64px) !important; margin-bottom: 32px !important; }
      .td-site #what-we-do > div:last-of-type {
        grid-template-columns: 1fr !important;
        gap: 48px !important;
      }
      .td-site #what-we-do h4 { font-size: 36px !important; }

      /* Section IV — logos 2-up instead of 4-up */
      .td-site #we-work-with { padding-bottom: 72px !important; }
      .td-site #we-work-with > h3 { font-size: clamp(36px, 10vw, 56px) !important; }
      .td-site #we-work-with > div.reveal:last-of-type {
        grid-template-columns: 1fr 1fr !important;
      }
      /* grid items default to min-width:auto, so the logo images refuse to
         shrink and blow the columns past the viewport — force them to shrink.
         Also: the desktop cells use aspect-ratio 16/9, but tall stacked logos
         (Drumelia, Universal) force their cell taller than the aspect box,
         which breaks row alignment and makes the grid look jagged/glitchy.
         Pin every cell to one fixed height so the grid is perfectly even. */
      .td-site #we-work-with > div.reveal:last-of-type > div {
        min-width: 0 !important;
        aspect-ratio: auto !important;
        height: 92px !important;
        padding: 14px 12px !important;
      }
      .td-site #we-work-with > div.reveal:last-of-type img {
        max-width: 100% !important;
        max-height: 40px !important;
      }

      /* Section V — team: on phones the horizontal drag-rail is awkward, so
         stack the profiles vertically as compact square-photo blocks. */
      .td-site #founders { padding-bottom: 64px !important; }
      .td-site #founders h3 { font-size: clamp(40px, 11vw, 64px) !important; }
      .td-site #founders .team-rule { margin-left: 0 !important; margin-right: 0 !important; }
      .td-site #founders .team-head { padding-left: 0 !important; padding-right: 0 !important; }
      .td-site #founders .team-heading { padding-left: 0 !important; padding-right: 0 !important; }
      .td-site .team-drag-hint { display: none !important; }   /* no drag on a stack */
      .td-site .team-rail {
        flex-direction: column !important;
        overflow: visible !important;
        scroll-snap-type: none !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        scroll-padding-left: 0 !important;
        gap: 16px !important;
      }
      .td-site .team-rail article {
        flex: 0 0 auto !important;
        flex-basis: auto !important;
        width: 100% !important;
        max-width: 100% !important;
      }
      /* portrait: tall 3/4 → square block */
      .td-site .team-rail article > div:first-child {
        aspect-ratio: 1 / 1 !important;
      }
      .td-site .team-rail > div[aria-hidden="true"] { display: none !important; }  /* trailing spacer */

      /* Section VI — contact rows stack */
      .td-site #contact { padding: 72px 18px 56px !important; }
      .td-site #contact > h3 { font-size: clamp(48px, 13vw, 80px) !important; margin-bottom: 40px !important; }
      .td-site #contact > div.reveal > a {
        grid-template-columns: 1fr !important;
        gap: 6px !important;
        padding: 22px 0 !important;
      }
      .td-site #contact > div.reveal > a > span:nth-child(2) {
        font-size: clamp(22px, 5.6vw, 30px) !important;
        word-break: break-word;
        letter-spacing: -0.01em !important;
      }

      /* footer */
      .td-site > footer { padding: 20px 18px 32px !important; }
      .td-site > footer > div { flex-direction: column; align-items: flex-start !important; gap: 8px !important; }
    }
  `;
  document.head.appendChild(s);
})();

// ImageSlot — neutral photo plate placeholder.
function ImageSlot({ tag, num, ratio = '4/5', style = {}, fill = false }) {
  return (
    <div className="photo" style={{ ...(fill ? {} : { aspectRatio: ratio }), width: '100%', height: fill ? '100%' : undefined, ...style }}>
      {num && <div className="photo-num">{num}</div>}
      {tag && <div className="photo-tag">{tag}</div>}
    </div>
  );
}

function useScrollReveals(containerRef) {
  React.useLayoutEffect(() => {
    const root = containerRef.current;
    if (!root) return;
    const targets = Array.from(root.querySelectorAll('.reveal'));
    if (!targets.length) return;

    // Respect reduced-motion: show everything, no animation, no arming.
    if (window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
      targets.forEach((t) => t.classList.add('in'));
      return;
    }

    // Arm the hidden initial state ONLY now that JS is confirmed running.
    root.classList.add('reveals-armed');

    const pending = new Set(targets);
    let raf = 0;
    let failSafe = 0;

    const cleanup = () => {
      window.removeEventListener('scroll', schedule);
      window.removeEventListener('resize', schedule);
      if (raf) cancelAnimationFrame(raf);
      if (failSafe) clearTimeout(failSafe);
    };

    const check = () => {
      const vh = window.innerHeight || document.documentElement.clientHeight;
      pending.forEach((t) => {
        const r = t.getBoundingClientRect();
        // Reveal once any part enters the lower 92% of the viewport.
        if (r.top < vh * 0.92 && r.bottom > 0) {
          t.classList.add('in');
          pending.delete(t);
        }
      });
      if (!pending.size) cleanup();
    };

    function schedule() {
      if (!raf) raf = requestAnimationFrame(() => { raf = 0; check(); });
    }

    // Reveal whatever is already on screen before first paint (prevents flash).
    check();

    window.addEventListener('scroll', schedule, { passive: true });
    window.addEventListener('resize', schedule);

    // Absolute safety net: nothing stays hidden for more than 2.5s.
    failSafe = setTimeout(() => {
      targets.forEach((t) => t.classList.add('in'));
      pending.clear();
      cleanup();
    }, 2500);

    return cleanup;
  }, [containerRef]);
}

function PageCursor() {
  const dotRef = React.useRef(null);
  React.useEffect(() => {
    const dot = dotRef.current;
    if (!dot) return;
    const onMove = (e) => { dot.style.left = e.clientX + 'px'; dot.style.top = e.clientY + 'px'; };
    const onOver = (e) => { if (e.target.closest('[data-hot]')) dot.classList.add('hover'); };
    const onOut = (e) => { if (e.target.closest('[data-hot]')) dot.classList.remove('hover'); };
    window.addEventListener('mousemove', onMove);
    window.addEventListener('mouseover', onOver);
    window.addEventListener('mouseout', onOut);
    return () => {
      window.removeEventListener('mousemove', onMove);
      window.removeEventListener('mouseover', onOver);
      window.removeEventListener('mouseout', onOut);
    };
  }, []);
  return <div ref={dotRef} className="cursor-dot" />;
}

function Wordmark({ size = 22, color = TD.ink }) {
  const isLight = color === TD.paper || color === '#ffffff' || color === 'white';
  return (
    <img
      src="assets/logo-those-days-brush5.png"
      alt="Those Days"
      className="td-wordmark"
      style={{
        height: size,
        width: 'auto',
        display: 'inline-block',
        verticalAlign: 'middle',
        filter: isLight ? 'invert(1)' : 'none',
      }}
    />
  );
}

// ─────────────────────────────────────────────────────────────
// IMMERSIVE LAYER
// ─────────────────────────────────────────────────────────────

// Top-of-viewport reading progress hairline.
function ScrollProgress() {
  const ref = React.useRef(null);
  React.useEffect(() => {
    let raf = 0;
    const update = () => {
      const sh = document.documentElement.scrollHeight - window.innerHeight;
      const p = sh > 0 ? Math.min(100, Math.max(0, (window.scrollY / sh) * 100)) : 0;
      if (ref.current) ref.current.style.setProperty('--p', p + '%');
      raf = 0;
    };
    const schedule = () => { if (!raf) raf = requestAnimationFrame(update); };
    schedule();
    window.addEventListener('scroll', schedule, { passive: true });
    window.addEventListener('resize', schedule);
    return () => {
      window.removeEventListener('scroll', schedule);
      window.removeEventListener('resize', schedule);
      cancelAnimationFrame(raf);
    };
  }, []);
  return <div ref={ref} className="scroll-progress"><i /></div>;
}

// Right-edge section indicator with active highlighting.
function SectionIndicator({ items }) {
  const [active, setActive] = React.useState(items[0]?.id);
  React.useEffect(() => {
    const obs = new IntersectionObserver(
      (entries) => {
        entries.forEach((e) => {
          if (e.isIntersecting) setActive(e.target.id);
        });
      },
      { rootMargin: '-45% 0px -50% 0px' }
    );
    items.forEach(({ id }) => {
      const el = document.getElementById(id);
      if (el) obs.observe(el);
    });
    return () => obs.disconnect();
  }, [items]);
  return (
    <nav className="section-ind" aria-label="Section navigation">
      {items.map((it) => (
        <a key={it.id} href={`#${it.id}`} className={active === it.id ? 'active' : ''} data-hot>
          <span className="lbl">{it.label}</span>
          <span className="dot" />
        </a>
      ))}
    </nav>
  );
}

// Photo plate with gentle scroll-driven parallax on the image only.
function ParallaxPlate({ ratio = '4/5', range = 70, children }) {
  const frameRef = React.useRef(null);
  const innerRef = React.useRef(null);
  React.useEffect(() => {
    const frame = frameRef.current;
    const inner = innerRef.current;
    if (!frame || !inner) return;
    let raf = 0;
    const update = () => {
      const r = frame.getBoundingClientRect();
      const vh = window.innerHeight;
      const center = r.top + r.height / 2;
      const t = (vh / 2 - center) / vh; // -0.5..+0.5 as the plate crosses the viewport
      const ty = t * range;
      inner.style.transform = `translateY(${ty.toFixed(2)}px)`;
      raf = 0;
    };
    const schedule = () => { if (!raf) raf = requestAnimationFrame(update); };
    schedule();
    window.addEventListener('scroll', schedule, { passive: true });
    window.addEventListener('resize', schedule);
    return () => {
      window.removeEventListener('scroll', schedule);
      window.removeEventListener('resize', schedule);
      cancelAnimationFrame(raf);
    };
  }, []);
  return (
    <div ref={frameRef} className="px-frame" style={{ aspectRatio: ratio }}>
      <div ref={innerRef} className="px-inner">{children}</div>
    </div>
  );
}

Object.assign(window, { TD, ImageSlot, PageCursor, useScrollReveals, Wordmark, ScrollProgress, SectionIndicator, ParallaxPlate });
