/* ──────────────────────────────────────────────────────────────
   motion.css — the whole motion vocabulary.

   Motion here explains, it never decorates. An entrance orients
   the eye down the screen; a state transition keeps a panel from
   appearing out of nowhere; a press confirms a finger landed.
   Nothing loops, nothing bounces, nothing moves on its own after
   the screen has settled.

   Four things, applied by adding one class:

     .enter          one element rises in
     .enter-1…6      the step it rises on
     .stagger        a container whose children cascade in
     .pressable      the iOS depress under a finger

   plus one state transition, .disclosure-panel, for a section
   that folds away.

   Durations, curves and the stagger step are tokens — see the
   Motion block in app/assets/tailwind/application.css. Only
   opacity and transform are animated, with the single documented
   exception of the disclosure panel, which has to change height.
   ────────────────────────────────────────────────────────────── */

/* ── Entrance ─────────────────────────────────────────────────
   Opacity plus a small lift. Never a scale from zero, never a
   slide in from off-screen: the element was always there, the
   screen is just arriving. `both` holds the start state through
   the delay, so nothing flashes before its turn.                */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(var(--rise-from, 12px));
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Transform only. For rows inside something that is already
   fading in, where a second opacity ramp would wash them out. */
@keyframes settle {
  from {
    transform: translateY(var(--rise-from, 8px));
  }
  to {
    transform: none;
  }
}

.enter,
.stagger > * {
  animation: rise var(--duration-entrance) var(--ease-settle) both;
  animation-delay: var(--stagger-base, 0ms);
}

/* Hand-placed steps, for a handful of elements that are not
   siblings in one container (the home hero). */
.enter-1 {
  animation-delay: calc(var(--stagger-step) * 0);
}
.enter-2 {
  animation-delay: calc(var(--stagger-step) * 1);
}
.enter-3 {
  animation-delay: calc(var(--stagger-step) * 2);
}
.enter-4 {
  animation-delay: calc(var(--stagger-step) * 3);
}
.enter-5 {
  animation-delay: calc(var(--stagger-step) * 4);
}
.enter-6 {
  animation-delay: calc(var(--stagger-step) * 5);
}

/* ── Stagger ──────────────────────────────────────────────────
   One class on the container; the children cascade themselves.
   The cascade stops at the eighth child and everything after it
   arrives together — a list of forty people should not take two
   seconds to finish appearing.

   Children start one step after a .enter heading above them, so
   a page head and the cards under it read as one sequence.      */

/* Hidden form plumbing — the CSRF token, a _method field, a wrapper
   marked hidden — is not something a person can watch arrive, so it
   does not take a place in the queue. Still one class on the
   container: nothing has to be added to the children.
   `:nth-child(… of S)` is Safari 9+, Chrome 111+, Firefox 113+; where
   it is not understood these rules are dropped and the children
   simply arrive together, which is a fine floor. */
.stagger > *:nth-child(1 of :not([hidden]):not([type="hidden"])) {
  animation-delay: calc(var(--stagger-base, 0ms) + var(--stagger-step) * 1);
}
.stagger > *:nth-child(2 of :not([hidden]):not([type="hidden"])) {
  animation-delay: calc(var(--stagger-base, 0ms) + var(--stagger-step) * 2);
}
.stagger > *:nth-child(3 of :not([hidden]):not([type="hidden"])) {
  animation-delay: calc(var(--stagger-base, 0ms) + var(--stagger-step) * 3);
}
.stagger > *:nth-child(4 of :not([hidden]):not([type="hidden"])) {
  animation-delay: calc(var(--stagger-base, 0ms) + var(--stagger-step) * 4);
}
.stagger > *:nth-child(5 of :not([hidden]):not([type="hidden"])) {
  animation-delay: calc(var(--stagger-base, 0ms) + var(--stagger-step) * 5);
}
.stagger > *:nth-child(6 of :not([hidden]):not([type="hidden"])) {
  animation-delay: calc(var(--stagger-base, 0ms) + var(--stagger-step) * 6);
}
.stagger > *:nth-child(7 of :not([hidden]):not([type="hidden"])) {
  animation-delay: calc(var(--stagger-base, 0ms) + var(--stagger-step) * 7);
}
.stagger > *:nth-child(n + 8 of :not([hidden]):not([type="hidden"])) {
  animation-delay: calc(var(--stagger-base, 0ms) + var(--stagger-step) * 8);
}

/* Rows inside a card that is itself arriving. Shorter, tighter,
   and transform only so the two fades never multiply.
   Declared after .stagger > * — equal specificity, order wins.  */
.stagger--rows {
  --stagger-step: 40ms;
  --stagger-base: 60ms;
  --rise-from: 8px;
}

.stagger--rows > * {
  animation: settle var(--duration-state) var(--ease-settle) both;
}

/* ── Press ────────────────────────────────────────────────────
   The iOS tap: the control gives a little under the finger and
   comes straight back. Transform only, so it costs nothing.     */

.pressable {
  transition: transform var(--duration-press) var(--ease-std);
}

.pressable:active {
  transform: scale(0.97);
}

/* A whole card is a big thing to shrink; 1.5% reads as a press
   where 3% reads as a glitch. */
.pressable--card:active {
  transform: scale(0.985);
}

/* ── State: a section that folds away ────────────────────────
   grid-template-rows 0fr → 1fr rather than interpolate-size with
   height:auto. interpolate-size is Chromium-only today, and this
   is an Apple-first app — the grid technique has worked in Safari
   since 16. Where it is not supported the panel simply snaps
   open, which is where this started.

   Height is a layout property, so this one transition is not on
   the compositor. It is the only one, and it is bounded to a
   panel a few hundred pixels tall.                              */

.disclosure-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--duration-state) var(--ease-settle);
}

.disclosure-panel > * {
  /* min-height:0 lets the row actually collapse; the inset pair
     gives focus rings 2px to breathe in without moving anything.
     No vertical padding here on purpose — padding is part of this
     box, not its contents, so overflow would not clip it and a shut
     panel would still stand 12px tall. */
  min-height: 0;
  overflow: hidden;
  padding-inline: 2px;
  margin-inline: -2px;
  opacity: 0;
  /* visibility, not display: it takes the shut panel's fields out of the tab
     order without costing the transition. It is stepped, not interpolated —
     visible the instant the panel opens, so the field can take focus, and
     hidden only once it has finished closing. */
  visibility: hidden;
  transition: opacity var(--duration-state) var(--ease-std),
    visibility 0s linear var(--duration-state);
}

/* The gap between the trigger and the panel, placed inside the clip
   so it collapses with everything else. The component owns this, so
   a view never has to remember it. */
.disclosure-panel > * > :first-child {
  margin-top: 0.875rem;
}

.disclosure-panel[data-open] {
  grid-template-rows: 1fr;
}

.disclosure-panel[data-open] > * {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--duration-state) var(--ease-std),
    visibility 0s linear 0s;
}

/* ── Already seen ─────────────────────────────────────────────
   entrance_controller.js stamps the screen when Turbo is about to
   render one that just played — a cached preview and the real body
   that replaces it. The second one arrives already settled.      */
[data-entrance="settled"] .enter,
[data-entrance="settled"] .stagger > * {
  animation: none;
  opacity: 1;
  transform: none;
}

/* Tab panels fade only; the tabs_controller sets these inline. */
[data-tabs-target="panel"] {
  will-change: opacity;
}

/* ── Reduced motion ───────────────────────────────────────────
   Everything above collapses to its finished state, instantly.
   Not "faster" — still. This is not negotiable.                 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }

  .enter,
  .stagger > * {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .pressable:active,
  .pressable--card:active,
  .glass-button:active,
  .glass-card--link:hover,
  .glass-card--link:active,
  .home-cross:hover {
    transform: none;
  }
}
