/* ==========================================================================
   kit/mechanics.css — how things arrive and how they answer a pointer.
   Layers: entrance, then components. Standing rule 7; patterns/motion-kit.md.

   THE ORDER OF THE TWO LAYERS IS THE POINT. The settled entrance state
   (`.js [data-in="stagger"].is-in > *`, specificity 0,3,0) used to out-weigh
   `.tile:hover` (0,2,0) and silently kill the hover lift; it passed every lint and only a
   browser showed it (AAA, 2026-09-20). Cascade layers make it impossible: `entrance` is
   declared below `components` in the layer order, so a component's :hover wins whatever its
   specificity. If that order line is ever wrong, verify.mjs reports the dead hover.

   Every hidden state is behind `.js`, which the <head> sets on its first line. With the script
   blocked nothing on the page is ever invisible.
   ========================================================================== */

@layer entrance {
  .js [data-in] { opacity: 0; }
  .js [data-in].is-in { opacity: 1; }

  /* rise: a band, or a block of text */
  .js [data-in="rise"] {
    transform: translateY(16px);
    transition: opacity var(--m-in) var(--m-ease), transform var(--m-in) var(--m-ease);
  }
  .js [data-in="rise"].is-in { transform: none; }

  /* stagger: a row of cards, each a step behind the last */
  .js [data-in="stagger"] { opacity: 1; }
  .js [data-in="stagger"] > * {
    opacity: 0; transform: translateY(16px);
    transition: opacity var(--m-in) var(--m-ease), transform var(--m-in) var(--m-ease);
  }
  .js [data-in="stagger"].is-in > * { opacity: 1; transform: none; }
  .js [data-in="stagger"].is-in > :nth-child(2) { transition-delay: calc(var(--m-step) * 1); }
  .js [data-in="stagger"].is-in > :nth-child(3) { transition-delay: calc(var(--m-step) * 2); }
  .js [data-in="stagger"].is-in > :nth-child(4) { transition-delay: calc(var(--m-step) * 3); }
  .js [data-in="stagger"].is-in > :nth-child(5) { transition-delay: calc(var(--m-step) * 4); }
  .js [data-in="stagger"].is-in > :nth-child(6) { transition-delay: calc(var(--m-step) * 5); }
  /* past six they arrive together: a seventh delay is a queue, not a stagger */

  /* unmask: a photograph settling. The FRAME is observed, never the image: an element clipped to
     zero area by its own transform is invisible to an IntersectionObserver (found in v9). */
  .js [data-in="unmask"] { opacity: 1; }
  .js [data-in="unmask"] img { transform: scale(1.06); transition: transform var(--m-unmask) var(--m-ease); }
  .js [data-in="unmask"].is-in img { transform: none; }

  /* draw: a line growing from its left edge */
  .js [data-in="draw"] { opacity: 1; transform: scaleX(0); transform-origin: left center; transition: transform var(--m-draw) var(--m-ease); }
  .js [data-in="draw"].is-in { transform: none; }

  @media (prefers-reduced-motion: reduce) {
    .js [data-in], .js [data-in] > *, .js [data-in] img {
      opacity: 1 !important; transform: none !important; transition: none !important;
    }
  }
}

@layer components {
  /* a photograph in a frame: the photograph zooms, the frame does not */
  .frame { overflow: hidden; border-radius: var(--r-surface); }
  .frame img { width: 100%; transition: transform var(--hover-slow) var(--hover-ease); }
  @media (hover: hover) { .frame:hover img { transform: scale(var(--zoom-img)); } }

  /* a card that IS a link lifts. A card that is not a link does nothing and gets no pointer cursor. */
  .card-link {
    display: block; color: inherit; text-decoration: none; border-radius: var(--r-surface);
    transition: transform var(--hover-move) var(--hover-ease), box-shadow var(--hover-move) var(--hover-ease);
  }
  @media (hover: hover) {
    .card-link:hover { transform: translateY(var(--lift-card)); box-shadow: var(--shadow-emphatic); }
  }

  /* a rail: scrolls by hand always; mechanics.js drifts it, and stops for every reason to stop */
  .rail-wrap { position: relative; }
  .rail {
    display: flex; gap: var(--grid-gap);
    overflow-x: auto; scroll-snap-type: x mandatory; scroll-behavior: smooth;
    padding-block: var(--space-8);
    scrollbar-width: thin;
  }
  .rail > * { flex: 0 0 min(82%, 320px); scroll-snap-align: start; }
  /* A rail in a band starts in line with the heading and runs out to the band's right edge, which is the
     screen's: a card is cut by the screen, not by an invisible line, and the row reads as "there's more"
     (approved on the demo, tasks/2026-09-27-demo-full-width). 100cqw is the band's width without the
     scrollbar (100vw would include it and scroll sideways). A browser without container units drops these
     and keeps the boxed rail. Cards are sized from the column, so about 3⅓ show on a desktop and 2⅓ on a
     tablet whatever the screen: the last one visible is always cut by the edge, and the row always scrolls
     (at the old min(82%, 320px) four cards fitted side by side on a wide screen and the row stopped). */
  .band:has(.rail) { container-type: inline-size; overflow-x: clip; }
  .band .rail {
    --bleed: calc(max(0px, (100cqw - var(--content-max)) / 2) + var(--pad-x));
    margin-right: calc(-1 * var(--bleed));
    padding-right: var(--bleed);
    scroll-padding-inline-end: var(--bleed);
  }
  @media (min-width: 641px) {
    .band .rail > * { flex-basis: calc((min(100cqw, var(--content-max)) - 2 * var(--pad-x) - 2 * var(--grid-gap)) / 2.3); }
  }
  @media (min-width: 1080px) {
    .band .rail > * { flex-basis: calc((min(100cqw, var(--content-max)) - 2 * var(--pad-x) - 2 * var(--grid-gap)) / 3.3); }
  }
  .rail__ctl { display: flex; gap: var(--space-8); margin-top: var(--space-16); }
  /* round arrow buttons: a ghost button that is round, so they lift and answer like every other button */
  .rail__btn {
    display: grid; place-items: center; width: 44px; height: 44px;
    border: 0; border-radius: var(--r-pill);
    background-color: transparent; color: var(--c-link); box-shadow: inset 0 0 0 2px var(--c-link); cursor: pointer;
    transition: background-color var(--hover-fast) var(--hover-ease), color var(--hover-fast) var(--hover-ease), transform var(--hover-fast) var(--hover-ease);
  }
  .rail__btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
  @media (hover: hover) {
    .rail__btn:hover { background-color: var(--c-link); color: var(--c-bg); transform: translateY(var(--lift-btn)); }
  }

  @media (prefers-reduced-motion: reduce) {
    .btn:hover, .card-link:hover, .node:hover, .rail__btn:hover { transform: none; }
    .frame:hover img { transform: none; }
    .rail { scroll-behavior: auto; }
  }
}
