/* TSP homepage prototype, section 4 "More work": the case-study rail, v3.
   The owner (2026-11-26): "could we make the scroll slide the case studies? I guess we can have the button, but i
   want it to be more dynamic".

   Two layouts. rail.js picks one on load and on every resize, and sets it on the section:
   - .th-rail--pin (a desktop screen of at least 1024 x 640 with a mouse or trackpad, motion allowed, and room for
     the cards): the panel .th-rail__pin is one screen tall and pins below the nav. The section grows by the slide's
     length (::after, --th-rail-run), and rail.js moves the track with translate3d as the page scrolls.
   - no class (JS off, reduced motion, a touch-first or smaller screen): the original row, which scrolls sideways
     with snap.

   Replaces the th-rail rules in home.css (README.md lists them). Every rule is scoped under .th-rail, including
   the shared patterns home.css writes once with :is() (box sizing, wrap, thread anchors, eyebrow, H2, focus ring,
   reveal, reduced motion), so the section ports to Kajabi on its own. Those copies must keep home.css's values:
   this file loads after home.css and would override them (tools/integrate.mjs refuses to integrate if they differ).
   Load it after home.css. */

/* ======================================================================= shared patterns, scoped to the rail */
.th-rail { position: relative; line-height: 1.6; color: var(--text); scroll-margin-top: 0; }   /* the header's height is html's scroll-padding-top (tokens.css) */
/* The grid's left edge with the track running to the window edges: the first card lines up with the page's 1200px
   column (the track's padding, its snap padding, and where the pinned panel's fade ends). Measured on the section's
   own width (100cqw) where container units exist, as the hero does: 100vw includes a visible scrollbar (the page's
   styled one, tokens.css: 12px at 13:53, 14px since 22:42), which put the first card half its width right of the
   heading and the last one as far short of the grid's right edge. */
.th-rail { --th-rail-edge: max(var(--gutter), calc((100vw - var(--wrap)) / 2 + var(--gutter))); }
@supports (width: 1cqw) { .th-rail { container-type: inline-size; --th-rail-edge: max(var(--gutter), calc((100cqw - var(--wrap)) / 2 + var(--gutter))); } }
.th-rail, .th-rail *, .th-rail *::before, .th-rail *::after { box-sizing: border-box; }
.th-rail .th-wrap { position: relative; max-width: var(--wrap); margin: 0 auto; padding-left: var(--gutter); padding-right: var(--gutter); }
/* A thread anchor with no element of its own: it covers the section, and x/y place the point. th-anchor--g runs
   from the middle of the left gutter to the middle of the right one. */
.th-rail .th-anchor { position: absolute; inset: 0; pointer-events: none; }
.th-rail .th-anchor--g { left: calc((100% - min(100%, var(--wrap))) / 4 + var(--gutter) / 2); right: calc((100% - min(100%, var(--wrap))) / 4 + var(--gutter) / 2); }
/* Section label: a few words, sentence case, quiet grey and no accent rule (home.css 22:57, the owner: the cyan label
   with a rule read as AI slop). */
.th-rail .th-eyebrow { display: flex; align-items: center; gap: 12px; margin: 0 0 18px; font: 500 15px/1.4 var(--f-body); letter-spacing: 0; text-transform: none; color: var(--text-3); }
.th-rail .th-h2 { margin: 0; font-family: var(--f-display); font-weight: 600; color: var(--text); text-wrap: balance; }
.th-rail .th-h2--utility { font-size: clamp(2rem, 3.4vw, 3rem); line-height: 1.07; letter-spacing: -0.035em; max-width: 22ch; }
.th-rail :is(a, button):focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
/* One-time reveal (opacity + 12px rise, ~500ms). Hidden only once rail.js has run. */
.th-rail.th-js .th-rv { opacity: 0; transform: translateY(12px); transition: opacity .5s var(--ease-out), transform .5s var(--ease-out); transition-delay: var(--rv-d, 0ms); }
.th-rail.th-js .th-rv.is-in { opacity: 1; transform: none; }
/* Revealed by keyboard focus (a card reached by Tab before it was shown): at once, so the focus ring is never faded. */
.th-rail.th-rail--now .th-rv { transition: none; }

/* ======================================================================= the section (tight) */
.th-rail { padding: clamp(104px, 11vw, 152px) 0 clamp(88px, 9vw, 128px); }
.th-rail .th-rail__head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 24px 48px; margin-bottom: clamp(36px, 4vw, 56px); }
.th-rail .th-rail__ctrl { display: flex; align-items: center; gap: 8px; }
/* The arrows. Without JS they stay hidden (the hidden attribute); rail.js shows them once they work. */
.th-rail .th-railbtn { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: 8px; border: 1px solid var(--line-2); background: transparent; color: var(--text); font: 500 17px/1 var(--f-display); cursor: pointer; transition: border-color .2s, opacity .2s; }
.th-rail .th-railbtn[hidden] { display: none; }
.th-rail .th-railbtn:hover { border-color: var(--text-3); }
.th-rail .th-railbtn[aria-disabled="true"] { opacity: .3; cursor: default; border-color: var(--line); }
.th-rail .th-rail__all { padding: 12px 2px; font: 600 15px var(--f-display); color: var(--text); text-decoration: none; white-space: nowrap; transition: color .2s; }
.th-rail .th-railbtn:not([hidden]) ~ .th-rail__all { margin-left: 14px; }
.th-rail .th-rail__all:hover { color: var(--cyan); }
/* The row. --edge lines the first card up with the page's 1200px grid while the row runs to the window edges.
   The 10px above and below leave room for a card's focus ring inside the scroller (the margins keep the row
   where it was). overflow-y: hidden (home.css 22:40): with auto, the row's spare height could take a vertical
   wheel or swipe meant for the page. */
.th-rail .th-rail__track { --edge: var(--th-rail-edge); position: relative; list-style: none; margin: -6px 0 -2px; padding: 10px var(--edge) 10px; display: grid; grid-auto-flow: column; grid-auto-columns: clamp(248px, 21vw, 304px); gap: 28px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scroll-padding-inline: var(--edge); scrollbar-width: none; }
.th-rail .th-rail__track::-webkit-scrollbar { display: none; }
.th-rail .th-rail__item { scroll-snap-align: start; display: flex; }
/* Editorial cards: the cover art, then the caption under it. No box, no number, no glow. The square media box is
   sized before the image arrives, so a lazy cover never shifts the layout. */
.th-rail .th-card { flex: 1; display: flex; flex-direction: column; color: var(--text); text-decoration: none; }
.th-rail .th-card__media { position: relative; display: block; aspect-ratio: 1; margin-bottom: 18px; overflow: hidden; border-radius: 8px; background: #0b1020; }
/* The covers are AI illustrations. Until 2026-11-29 each carried an "Illustration" chip (.th-card__art, top left of the
   media box); the owner asked for the chips to go ("where it says ILLUSTRATION - that's going to go away in the live
   version right?"), so the markup and its rules are gone. */
/* One treatment for all eleven covers, so the neon renders read as one calm editorial set (home.css, 12:04). */
.th-rail .th-card__media img { display: block; width: 100%; height: 100%; object-fit: cover; filter: saturate(.6) brightness(.92); transition: transform .7s var(--ease-out), filter .4s ease; }
.th-rail .th-card__body { display: grid; gap: 8px; }
.th-rail .th-card__k { font: 500 13.5px/1.4 var(--f-body); color: var(--text-3); }
.th-rail .th-card__o { font: 600 clamp(18px, 1.4vw, 20px)/1.28 var(--f-display); letter-spacing: -0.015em; color: var(--text); text-wrap: pretty; text-decoration: underline; text-decoration-color: transparent; text-decoration-thickness: 1px; text-underline-offset: 5px; transition: text-decoration-color .25s; }
.th-rail .th-card__t { font-size: 14px; line-height: 1.45; color: var(--text-3); }
.th-rail .th-card:hover .th-card__media img { transform: scale(1.03); filter: saturate(.8) brightness(1); }
.th-rail .th-card:hover .th-card__o { text-decoration-color: currentColor; }
.th-rail .th-card:focus-visible { outline-offset: 6px; border-radius: 8px; }
/* The progress line: how much of the row you have seen. rail.js sets its transform; --p is the no-JS value. */
.th-rail .th-rail__foot { display: flex; align-items: center; gap: 24px; margin-top: 36px; }
.th-rail .th-rail__bar { position: relative; flex: 1; height: 1px; overflow: hidden; background: var(--line); }
.th-rail .th-rail__fill { position: absolute; inset: 0; background: var(--text-3); transform-origin: 0 50%; transform: scaleX(var(--p, .25)); transition: transform .2s linear; }

/* ======================================================================= pinned: the page scroll slides the cards */
/* --th-rail-pt is the space above the panel; the panel centres its content in the rest of the screen. It pins under the
   header and the homepage's chapter bar (--sticky-top, 2026-11-27; the header alone where there is no bar). */
.th-rail.th-rail--pin { --th-rail-pt: clamp(40px, 5vw, 72px); --th-rail-panel: calc(100vh - var(--sticky-top, var(--nav-h))); padding: var(--th-rail-pt) 0 clamp(24px, 4vw, 56px); }
@supports (height: 100svh) { .th-rail.th-rail--pin { --th-rail-panel: calc(100svh - var(--sticky-top, var(--nav-h))); } }
/* overflow: clip, not hidden: a clipped box can't be scrolled, so focusing an off-screen card can't shift it. */
.th-rail.th-rail--pin .th-rail__pin { position: sticky; top: var(--sticky-top, var(--nav-h)); height: var(--th-rail-panel); display: flex; flex-direction: column; justify-content: center; overflow: hidden; overflow: clip; }
/* The thread runs down the left gutter while the panel is pinned (rail-gutter and rail-out sit at x = 0 of
   th-anchor--g: the middle of the space left of the grid), and the cards slide out under it. The panel, which
   doesn't move, fades them out before they reach it: clear up to 6px past the line, opaque from 10px before the
   grid edge, so a card at a stop with its focus ring, the heading and the progress line are untouched. Where the
   gutter is too narrow for a ramp the two stops meet in a hard edge, still clear of the line. The mask is
   composited: the track's translate3d doesn't repaint it. */
.th-rail.th-rail--pin .th-rail__pin { --th-rail-fade: linear-gradient(90deg, transparent calc((100% - min(100%, var(--wrap))) / 4 + var(--gutter) / 2 + 6px), #000 calc(var(--th-rail-edge) - 10px)); -webkit-mask-image: var(--th-rail-fade); mask-image: var(--th-rail-fade); }
.th-rail.th-rail--pin .th-rail__pin > .th-wrap { width: 100%; }
/* The slide's length: the track's overflow plus a short hold at each end (rail.js measures it on resize). */
.th-rail.th-rail--pin::after { content: ""; display: block; height: var(--th-rail-run, 0px); }
/* rail.js moves the track with translate3d. --th-rail-card is set only when a short screen needs smaller cards. */
.th-rail.th-rail--pin .th-rail__track { overflow: visible; scroll-snap-type: none; will-change: transform; grid-auto-columns: var(--th-rail-card, clamp(248px, 21vw, 304px)); }
.th-rail.th-rail--pin .th-rail__fill { transition: none; }
/* Depth (rail.js DEPTH = .04): while pinned each cover drifts against the slide by up to 4% of the card's width.
   It sits 8% larger in its frame (scale 1 + 2 x DEPTH), so the drift never shows more than the original crop
   (The Capital's cover keeps its painted date out of view). translate and scale compose with the hover zoom. */
.th-rail.th-rail--depth .th-card__media img { scale: 1.08; will-change: transform; }
/* Thread: the three points that bring the line into the section measure against the first screen of it, not
   against the whole, taller section, so the line still turns into the left gutter above the heading. */
.th-rail.th-rail--pin .th-anchor.th-rail__a-top { bottom: auto; height: calc(var(--th-rail-pt) + var(--th-rail-panel)); }
/* A laptop-height screen: tighter spacing, and the heading may take one line beside the arrows (same type sizes),
   so the cards keep their width. rail.js narrows the cards only if this still doesn't fit. */
@media (max-height: 860px) {
  .th-rail.th-rail--pin .th-eyebrow { margin-bottom: 8px; }
  .th-rail.th-rail--pin .th-rail__head { margin-bottom: 24px; }
  .th-rail.th-rail--pin .th-rail__head > div:first-child { flex: 1 1 0; min-width: 0; }
  .th-rail.th-rail--pin .th-h2--utility { max-width: none; }
  .th-rail.th-rail--pin .th-card__media { margin-bottom: 14px; }
  .th-rail.th-rail--pin .th-card__body { gap: 6px; }
  .th-rail.th-rail--pin .th-rail__foot { margin-top: 20px; }
}

/* ======================================================================= tablet and phone (2026-11-27 mobile pass, v3/mobile-audit/PLAN.md) */
@media (max-width: 960px) {
  .th-rail { padding: clamp(72px, 11vw, 104px) 0 clamp(56px, 9vw, 88px); }
  .th-rail :is(.th-card__t, .th-card__o) { text-wrap: balance; }
}
@media (max-width: 640px) {
  .th-rail .th-rail__head { align-items: flex-start; }
  .th-rail .th-rail__all { padding: 12px 0; line-height: 20px; }   /* 44px */
  .th-rail .th-railbtn:not([hidden]) ~ .th-rail__all { margin-left: 10px; }
  /* R1: cqw leaves a scrollbar out; the end padding lets the last card snap, the one before it just off screen */
  .th-rail .th-rail__track { grid-auto-columns: 74cqw; gap: var(--edge); padding-right: calc(26cqw - var(--edge)); }
  .th-rail .th-rail__foot { flex-direction: column; align-items: stretch; gap: 14px; margin-top: 20px; }
  .th-rail .th-rail__bar { flex: none; width: 100%; height: 2px; }
  .th-rail .th-rail__fill { background: var(--text-2); }
}

/* ======================================================================= reduced motion: no pin (rail.js), nothing moves */
@media (prefers-reduced-motion: reduce) {
  .th-rail *, .th-rail *::before, .th-rail *::after { animation: none !important; transition: none !important; }
  .th-rail.th-js .th-rv { opacity: 1; transform: none; }
  .th-rail .th-card:hover .th-card__media img { transform: none; }
}
