/* ==========================================================================
   ABlawg — motion system
   --------------------------------------------------------------------------
   One reusable vocabulary for entrance and hover motion, applied through a
   `data-animate` attribute so templates stay readable and no class lists grow.

   Two rules govern everything here:

   1. NOTHING IS EVER HIDDEN WITHOUT JAVASCRIPT.
      The hidden start state is scoped to `html.js-anim`, a class set by a tiny
      inline script in <head> that runs only when JavaScript is available, the
      IntersectionObserver API exists, AND the visitor has not asked for reduced
      motion. If any of those is false the class is never added, the start state
      never applies, and every element renders at its resting state. A failed or
      slow script cannot leave the page blank.

   2. ONLY `opacity` AND `transform` ARE ANIMATED.
      Both are composited, so a reveal costs no layout and no paint. Nothing
      here animates width, height, top or left, and nothing changes an
      element's box — so revealing cannot shift the page.

   Reduced motion is handled twice over: the class is never added in the first
   place, and app.css's global reduce block already clamps every transition to
   0.01ms as a backstop.
   ========================================================================== */

:root {
  /* Entrance timing. 520ms sits in the brief's 300–700ms band and matches the
     404 band, which is this system's reference. --ease is the design's own. */
  --anim-dur: 520ms;
  --anim-dist: 0.75rem;     /* 12px — the same travel the 404 uses */
  --anim-stagger: 70ms;     /* gap between siblings in a group */
}


/* ── 1. The reveal ────────────────────────────────────────────────────────
   The start state is deliberately written as the ONLY place opacity is set to
   zero. `is-revealed` is added by assets/js/app.js when the element enters the
   viewport; elements already on screen at load get it on the observer's first
   callback, which is what makes this double as a page-load animation.      */

html.js-anim [data-animate] {
  opacity: 0;
  transition:
    opacity var(--anim-dur) var(--ease),
    transform var(--anim-dur) var(--ease);
}

html.js-anim [data-animate='fade-up']    { transform: translate3d(0, var(--anim-dist), 0); }
html.js-anim [data-animate='fade-down']  { transform: translate3d(0, calc(var(--anim-dist) * -1), 0); }
html.js-anim [data-animate='fade-left']  { transform: translate3d(var(--anim-dist), 0, 0); }
html.js-anim [data-animate='fade-right'] { transform: translate3d(calc(var(--anim-dist) * -1), 0, 0); }
html.js-anim [data-animate='zoom']       { transform: scale(0.97); }
/* `fade` on its own moves nothing — for anything where travel would read as a
   jolt, such as a full-bleed band. */

html.js-anim [data-animate].is-revealed {
  opacity: 1;
  transform: none;
}


/* ── 2. Stagger ───────────────────────────────────────────────────────────
   `data-animate-group` on a parent walks its animated children in. Capped at
   eight: past that the last item waits over half a second, which reads as the
   page being slow rather than as polish. Anything beyond the cap shares the
   final delay and arrives together.                                        */

[data-animate-group] > [data-animate]:nth-child(1) { transition-delay: 0ms; }
[data-animate-group] > [data-animate]:nth-child(2) { transition-delay: calc(var(--anim-stagger) * 1); }
[data-animate-group] > [data-animate]:nth-child(3) { transition-delay: calc(var(--anim-stagger) * 2); }
[data-animate-group] > [data-animate]:nth-child(4) { transition-delay: calc(var(--anim-stagger) * 3); }
[data-animate-group] > [data-animate]:nth-child(5) { transition-delay: calc(var(--anim-stagger) * 4); }
[data-animate-group] > [data-animate]:nth-child(6) { transition-delay: calc(var(--anim-stagger) * 5); }
[data-animate-group] > [data-animate]:nth-child(n + 7) { transition-delay: calc(var(--anim-stagger) * 6); }

/* A card appended by "Load more" must not inherit a stagger meant for the
   first screenful — it arrives alone, so it arrives immediately. */
html.js-anim [data-animate][data-animate-appended] { transition-delay: 0ms; }


/* ── 3. Hover ─────────────────────────────────────────────────────────────
   The design already defines hover states for buttons, nav items, topic
   tiles, arrow links and every text link, all on --dur/--ease. Nothing below
   duplicates those; this adds only what the design left flat.             */

/* 3a. Cards.
   The design draws a card as a flat bordered panel with no hover at all. A
   border that picks up the brand and a 2px lift is the smallest change that
   makes a whole card read as clickable, and matches what .topic already does. */
/* The lift uses `translate`, not `transform`, on purpose. A card is usually
   also a [data-animate] element, and the reveal above owns `transform` with a
   520ms duration — a hover sharing that property would inherit the reveal's
   timing and lose its own border-colour transition to the same shorthand.
   `translate` is a separate animatable property, so the two never collide.
   The design already animates this property on the off-canvas panel. */
.card,
.related__item {
  transition:
    border-color var(--dur) var(--ease),
    translate var(--dur) var(--ease);
}

/* A card is usually a reveal target too, and `html.js-anim [data-animate]`
   above is (0,2,0) — it would replace the shorthand declared on `.card` and
   silently drop the hover's two properties. Rather than fight that with
   !important, the combined case is declared once, at (0,3,0), listing all four
   properties with the duration each one wants: the slow entrance pair, and the
   quick interaction pair. */
html.js-anim .card[data-animate],
html.js-anim .related__item[data-animate] {
  transition:
    opacity var(--anim-dur) var(--ease),
    transform var(--anim-dur) var(--ease),
    border-color var(--dur) var(--ease),
    translate var(--dur) var(--ease);
}
/* `.card--article` is excluded from both states below. It is the article body
   on a single post and a static page — the page's own content, not a link to
   somewhere else. Lifting it and reddening its border advertises a click that
   does not exist, which is the same reason the single post's featured image is
   left out of the image zoom above. Its `:focus-within` is worse than the
   hover: the article body is full of links, so tabbing through the prose would
   hold the whole card red the entire way down. */
@media (hover: hover) {
  .card:not(.card--article):hover,
  .related__item:hover {
    border-color: var(--clr-red);
    translate: 0 -2px;
  }
}

/* A keyboard user gets the same affordance, via the focused link inside. */
.card:not(.card--article):focus-within,
.related__item:focus-within { border-color: var(--clr-red); }

/* 3b. Images.
   A slow crop inside the frame the image already occupies. `overflow: hidden`
   on the wrapper is what keeps the scale from changing any layout box.

   Only the related-post thumbnails: those sit inside a link, so the zoom is
   feedback for something the visitor can actually click. A single post's own
   featured image is not a link, and zooming it on hover would promise an
   interaction that does not exist. */
.related__media { overflow: hidden; }
.related__media img { transition: transform 600ms var(--ease); }

@media (hover: hover) {
  .related__item:hover .related__media img { transform: scale(1.04); }
}

/* 3c. Popular posts and feed items — text-only rows the design leaves static. */
.popular__item,
.feed-post { transition: translate var(--dur) var(--ease); }
@media (hover: hover) {
  .popular__item:hover,
  .feed-post:hover { translate: 3px 0; }
}

/* 3d. Footer and sidebar links get the nudge the main nav already has. */
.footer-links a,
.sidebar .widget li a { transition: color var(--dur) var(--ease); }


/* ── 4. Accessibility and print ───────────────────────────────────────────
   The js-anim class is never added under a reduced-motion preference, so the
   block below is a backstop for a preference that changes AFTER load — the
   media query re-evaluates live, the class does not.                      */

@media (prefers-reduced-motion: reduce) {
  html.js-anim [data-animate] {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .card:hover,
  .related__item:hover,
  .popular__item:hover,
  .feed-post:hover { translate: none; }
  .related__item:hover .related__media img { transform: none; }
}

@media print {
  html.js-anim [data-animate] { opacity: 1 !important; transform: none !important; }
}
