/* =========================================================================
   Cabinhub News — motion layer (additive)

   Owner: motion-design lane. Loaded AFTER styles.css so it can layer on top
   without editing the identity lane's file. Every rule here is scoped under
   html[data-motion="on"], which frontend/motion.js sets only after it has
   initialised. If motion.js fails to load, this whole file is inert and the
   existing CSS motion in styles.css stays in charge.

   Contract and token rationale: frontend/MOTION.md.
   Only transform and opacity animate here. Nothing else.
   ========================================================================= */

/* ---------------------------------------------------------------- tokens --
   One source of truth: motion.js reads these at boot for the WAAPI runs, and
   CSS transitions below use the same custom properties. Change a value here
   and both the CSS and the script follow. */
:root {
  --m-dur-1: 90ms;    /* press acknowledgement */
  --m-dur-2: 160ms;   /* one-element state change, crossfade */
  --m-dur-3: 240ms;   /* block entrance, list move, detail enter */
  --m-dur-4: 420ms;   /* the whole page-load run, budget only */

  --m-stagger: 30ms;  /* between consecutive items */
  --m-cap: 6;         /* last stagger slot; items after it move together */

  --m-dist-1: 2px;    /* press nudge */
  --m-dist-2: 8px;    /* entrance rise */
  --m-dist-3: 14px;

  --m-ease-out: cubic-bezier(0.16, 1, 0.3, 1);     /* entrances, settles */
  --m-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1); /* FLIP moves that travel */
  --m-ease-in: cubic-bezier(0.4, 0, 1, 1);         /* exits only */
}

/* Disable the styles.css entrance animations the script has taken over.
   styles.css still owns them for the no-JS / motion.js-failed case. */
html[data-motion="on"] .feed.is-revealed .card,
html[data-motion="on"] .feed.is-revealed .article,
html[data-motion="on"] .detail,
html[data-motion="on"] .state {
  animation: none;
}

/* ------------------------------------------------------- press feedback --
   A control acknowledges the press before the network answers. Small
   controls take a 1px nudge and a 1% compression; large surfaces only take
   the nudge, because scaling a lead card reads as a page wobble. */
html[data-motion="on"] .chip,
html[data-motion="on"] .locale-switch__btn,
html[data-motion="on"] .detail__back,
html[data-motion="on"] .button,
html[data-motion="on"] .skip-link,
html[data-motion="on"] .colophon__link,
html[data-motion="on"] .masthead__link,
html[data-motion="on"] .ops-head__nav .button {
  transition-property: transform, color, background-color, border-color;
  transition-duration: var(--m-dur-1), 140ms, 140ms, 140ms;
  transition-timing-function: var(--m-ease-out), var(--ease), var(--ease), var(--ease);
  transition-delay: 0s;
  transform-origin: 50% 60%;
}

html[data-motion="on"] .chip:active,
html[data-motion="on"] .locale-switch__btn:active,
html[data-motion="on"] .detail__back:active,
html[data-motion="on"] .button:active,
html[data-motion="on"] .skip-link:active,
html[data-motion="on"] .colophon__link:active {
  transform: translateY(var(--m-dist-1)) scale(0.985);
}

html[data-motion="on"] .masthead__link:active,
html[data-motion="on"] .card:active,
html[data-motion="on"] .article:active {
  transform: translateY(var(--m-dist-1));
}

/* The card and article keep their colour transition and gain the press
   transform. Declared separately so the identity lane's 160ms colour curve
   is preserved rather than replaced. */
html[data-motion="on"] .card,
html[data-motion="on"] .article {
  transition-property: background-color, transform;
  transition-duration: 160ms, var(--m-dur-1);
  transition-timing-function: var(--ease), var(--m-ease-out);
}

/* -------------------------------------------------------- hover motion --
   Only where a real pointer can hover. A hairline grows under a chip that is
   not already selected; the selected state itself belongs to the identity
   lane's accent border, so motion never draws a second line under it. */
@media (hover: hover) and (pointer: fine) {
  html[data-motion="on"] .chip:not([aria-pressed="true"]) {
    position: relative;
  }
  html[data-motion="on"] .chip:not([aria-pressed="true"])::after {
    content: "";
    position: absolute;
    left: 0.66rem;
    right: 0.66rem;
    bottom: 0;
    height: 1px;
    /* Warm hairline (@--rule-strong), not the cool --on-dark-faint: the chip
       text and every other rule in the chrome are warm ink, and the chip strip
       is on the light paper bar in both themes, so a blue-grey underline was
       the only cool mark on the row. */
    background: var(--rule-strong);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform var(--m-dur-2) var(--m-ease-out);
    pointer-events: none;
  }
  html[data-motion="on"] .chip:not([aria-pressed="true"]):hover::after {
    transform: scaleX(1);
  }

  /* A locale button that is not selected grows the same hairline inside the
     pressed marker's slot, so the switch reads as one object. */
  html[data-motion="on"] .locale-switch__btn { position: relative; }
  html[data-motion="on"] .locale-switch__btn::before {
    content: "";
    position: absolute;
    left: 30%;
    right: 30%;
    bottom: 9px;
    height: 1px;
    /* Warm hairline, matching the chip underline above and the chip row itself
       (see that rule). */
    background: var(--rule-strong);
    transform: scaleX(0);
    transition: transform var(--m-dur-2) var(--m-ease-out);
    pointer-events: none;
  }
  html[data-motion="on"] .locale-switch__btn:not([aria-pressed="true"]):hover::before {
    transform: scaleX(1);
  }
}

/* Pressing a feed row should not leave a stuck transform if the route change
   is cancelled or the node is reused. The browser clears :active on its own;
   this only guards against a scroll interrupting mid-press. */

/* ------------------------------------------------ optimistic locale cue --
   The locale switch updates its own pressed state synchronously in app.js, so
   the *state* is already optimistic. What is not is the content: it stays in
   the old language until the fetch answers. Dim it and lay a hairline across
   the filter bar so the switch is visibly in flight; settle when the new
   edition renders. Opacity only. */
html[data-motion="on"][data-motion-pending="locale"] [data-root] > * {
  opacity: 0.45;
  transition: opacity var(--m-dur-2) var(--m-ease-out);
}

html[data-motion="on"] .filters__inner { position: relative; }

html[data-motion="on"][data-motion-pending="locale"] .filters__inner::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 1px;
  width: 100%;
  /* `--accent-on-dark` was referenced here and DEFINED NOWHERE IN THE PRODUCT
     (git grep, 2026-11-16: zero declarations for it, `--ink-text` or
     `--rule-dark`). An undefined custom property makes the declaration invalid
     at computed-value time, so `background` fell back to its initial value,
     `transparent`: the script ran the wipe, the element existed with the right
     geometry, and it painted nothing. Measured live: the ::after computed
     backgroundColor was rgba(0,0,0,0). The wipe sits on the filter bar, whose
     ground is `--paper`, so the accent that belongs here is `--accent`. */
  background: var(--accent);
  opacity: 0.7;
  transform: scaleX(0);
  transform-origin: left center;
  animation: m-pending-wipe var(--m-dur-4) var(--m-ease-out) both;
}

/* Transform only: one property for the whole wipe. */
@keyframes m-pending-wipe {
  0%   { transform: scaleX(0); }
  70%  { transform: scaleX(1); }
  100% { transform: scaleX(1); }
}

/* ------------------------------------------------------------ the ghost --
   The outgoing skeleton is moved into this layer and faded, so content
   replaces it instead of cutting over it. Fixed, non-interactive, and
   removed as soon as its fade finishes. */
.m-ghost-layer {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  contain: strict;
}

.m-ghost-layer > .skeleton {
  position: fixed;
  margin: 0;
  pointer-events: none;
}

/* ----------------------------------------------------- detail dissolve ---
   The clicked card's headline is re-seated where the reader last saw it and
   dissolves in place while the detail headline arrives underneath. Scale is
   deliberately not used: morphing a 27px card headline into a 57px detail
   title distorts the letterforms. One transform, one fade. */
.m-flight {
  position: fixed;
  z-index: 6;
  pointer-events: none;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.06;
  letter-spacing: -0.02em;
  /* Same dead token: `--ink-text` is defined nowhere. It fell back to inherited
     colour, which happened to be the page ink on a feed card — but the flight
     headline sits over a surface it does not inherit from, so this read as the
     reader's default black. `--ink` is the token the detail title itself uses. */
  color: var(--ink);
  background: transparent;
  transform-origin: left top;
  overflow: hidden;
}

/* -------------------------------------------------------- MOTION_DEBUG ---
   Only present with ?MOTION_DEBUG=1. It draws; it does not animate, so it is
   safe under reduced motion too. */
.m-debug {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 90;
  width: min(320px, calc(100vw - 24px));
  max-height: 46vh;
  overflow: auto;
  padding: 10px 12px;
  background: rgba(8, 14, 22, 0.94);
  /* `--accent-on-dark` and `--rule-dark` were undefined (see the wipe note
     above), so this border and this rule resolved to `none`/`transparent`:
     the debug panel drew as an unruled block. It sits on a DARK ground at every
     theme, so the on-dark family is the correct source. */
  border: 1px solid var(--on-dark-dim);
  color: var(--on-dark);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  pointer-events: auto;
}

.m-debug__title {
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--on-dark-muted);
  margin-bottom: 6px;
}

.m-debug__row { display: flex; justify-content: space-between; gap: 8px; }
.m-debug__row--muted { color: var(--on-dark-faint); }
.m-debug__log { margin-top: 6px; border-top: 1px solid var(--on-dark-dim); padding-top: 6px; }
.m-debug__log div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.m-debug__tag {
  position: fixed;
  z-index: 91;
  padding: 1px 4px;
  background: rgba(8, 14, 22, 0.9);
  border: 1px solid var(--on-dark-dim);
  color: var(--on-dark-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  pointer-events: none;
  white-space: nowrap;
}

/* ------------------------------------------------------------- reduced --
   One branch. The script reads the same query and skips every animation, so
   these rules are a second belt on the same trousers, not a second policy. */
@media (prefers-reduced-motion: reduce) {
  html[data-motion="on"] [data-root] > *,
  html[data-motion="on"] .m-ghost-layer,
  html[data-motion="on"] .m-flight,
  html[data-motion="on"][data-motion-pending="locale"] [data-root] > * {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
    transition: none !important;
  }
  html[data-motion="on"] .filters__inner::after { display: none !important; }
  html[data-motion="on"] .chip::after,
  html[data-motion="on"] .locale-switch__btn::before { display: none !important; }

  /* The press. MOTION.md §5 promises "no press scale" here, and the block above
     only reaches `[data-root] > *`, which is the feed — the controls these rules
     target live in the chrome, outside it. responsive.css does collapse the
     transition under reduce, but that makes the change instant rather than
     absent: a reduced-motion reader still got the 2px nudge and the 1.5%
     squeeze, just without the glide. Killing the transform is the promise. */
  html[data-motion="on"] .chip:active,
  html[data-motion="on"] .locale-switch__btn:active,
  html[data-motion="on"] .detail__back:active,
  html[data-motion="on"] .button:active,
  html[data-motion="on"] .skip-link:active,
  html[data-motion="on"] .colophon__link:active,
  html[data-motion="on"] .masthead__link:active,
  html[data-motion="on"] .card:active,
  html[data-motion="on"] .article:active { transform: none !important; }
}