/* =========================================================
   THE MUSIC BLUEPRINT — MOTION
   blog.brmarketgroup.io, and the Blueprint pages on the main site

   Loaded after masthead.css (which defines the easing tokens) and after each
   page's own inline styles, so it can set the finish without a rewrite of
   every template. Rules here are additive: what a control already does on
   hover stays as it was.

   The brief (BRAND-MUSIC-BLUEPRINT.md §7): quiet, reading is the product.
   What that means in practice:
     - Press is instant and small. A control that does not answer the thumb
       feels broken, and 3% is enough to answer it.
     - Hover only for pointers that can hover.
     - Things that enter use expo-out; things that leave are faster than they
       arrived.
     - Only transform and opacity ever move.
     - Nothing animates when the reader asked it not to.
   ========================================================= */

/* ── Touch ───────────────────────────────────────────────────
   Removes the grey flash iOS paints over a tapped link (we draw our own press
   state) and the double-tap-to-zoom delay on anything tappable. */
:where(a, button, summary, label, input, select, textarea, [role='button']) {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ── Press ────────────────────────────────────────────────────
   One shared transition so the scale has an ease and the colour/opacity
   changes each control already had keep working. */
:root
  :is(
    .cta,
    .article-cta-link,
    .bookmark-btn,
    .share-btn,
    .comment-submit,
    .br-article-cta-btn,
    .br-hero-bar-btn,
    .br-sidebar-btn,
    .br-sticky-btn,
    .br-sub-btn,
    .saved-clear,
    .saved-remove,
    .filter-chip,
    .filter-sort,
    .tmb-art-submit,
    .tmb-art-tag
  ) {
  transition:
    transform 160ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)),
    opacity 0.2s ease,
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
}
:root
  :is(
    .cta,
    .article-cta-link,
    .bookmark-btn,
    .share-btn,
    .comment-submit,
    .br-article-cta-btn,
    .br-hero-bar-btn,
    .br-sidebar-btn,
    .br-sticky-btn,
    .br-sub-btn,
    .saved-clear,
    .saved-remove,
    .filter-chip,
    .filter-sort,
    .tmb-art-submit,
    .tmb-art-tag
  ):active {
  transform: scale(0.97);
}
/* Whole rows and cards are links too. They are bigger, so the same 3% would be
   a visible lurch; they dim and settle a hair instead. */
:root :is(.article-card, .article-list-item, .saved-row, .search-suggestion-row):active {
  opacity: 0.7;
  transition: opacity 80ms linear;
}

/* ── Scroll reveal ────────────────────────────────────────────
   motion.js marks list items and cards [data-rv] before they paint and adds
   .is-in as they cross into view, a few at a time, 45ms apart. Never applied
   to above-the-fold headlines: hiding the largest paint until script runs
   would cost more in LCP than the entrance is worth. */
[data-rv] {
  opacity: 0;
  transform: translate3d(0, 14px, 0);
}
[data-rv].is-in {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  transition:
    opacity 560ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)),
    transform 720ms var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
}

/* A printed page has no scroll to reveal on. */
@media print {
  [data-rv] {
    opacity: 1;
    transform: none;
  }
}

/* ── Sheets (modals on a phone) ───────────────────────────────
   On a desktop a modal is a card in the middle of the page. On a phone that is
   the one thing apps do not do: a card floats in the way of the thumb. They
   rise from the bottom edge instead, on the same curve as the menu, with a
   grabber, and can be flicked away (motion.js). Radius stays 0: this is a
   printed publication, not a widget. */
@media (max-width: 720px) {
  :root .br-sub-overlay,
  :root .tmb-art-overlay {
    align-items: flex-end;
    padding: 0;
  }
  :root .br-sub-modal,
  :root .tmb-art-modal {
    max-width: none;
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-width: 1px 0 0;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
    transform: translate3d(0, 100%, 0);
    transition: transform 260ms var(--ease-drawer, cubic-bezier(0.32, 0.72, 0, 1));
  }
  :root .br-sub-overlay.is-open .br-sub-modal,
  :root .tmb-art-overlay.is-open .tmb-art-modal {
    transform: translate3d(0, 0, 0);
    transition: transform 460ms var(--ease-drawer, cubic-bezier(0.32, 0.72, 0, 1));
  }
  :root .br-sub-modal.is-dragging,
  :root .tmb-art-modal.is-dragging {
    transition: none;
  }
  :root .br-sub-modal::before,
  :root .tmb-art-modal::before {
    content: '';
    display: block;
    width: 32px;
    height: 3px;
    margin: -1rem auto 1.25rem;
    border-radius: 2px;
    background: var(--ink-faint, rgba(18, 18, 18, 0.16));
  }
}

/* ── Sticky subscribe bar ─────────────────────────────────────
   Clears the home indicator, and arrives on the sheet curve. */
:root .br-sticky-bar {
  padding-bottom: calc(0.875rem + env(safe-area-inset-bottom, 0px));
  transition: transform 460ms var(--ease-drawer, cubic-bezier(0.32, 0.72, 0, 1));
}

/* ── Page transitions ─────────────────────────────────────────
   Cross-document view transitions: moving between blog pages is a short
   crossfade with the masthead held in place, instead of a white flash and a
   page rebuilding. Browsers without support just navigate as they always did.
   The masthead is named so it is carried across rather than faded, which is
   most of why it reads as one app rather than many pages. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
  .mh {
    view-transition-name: tmb-masthead;
  }
  ::view-transition-group(tmb-masthead) {
    animation-duration: 0s;
  }
  ::view-transition-old(root) {
    animation: tmb-vt-out 140ms var(--ease-out-expo, ease-out) both;
  }
  ::view-transition-new(root) {
    animation: tmb-vt-in 360ms var(--ease-out-expo, ease-out) both;
  }
}
@keyframes tmb-vt-out {
  to {
    opacity: 0;
  }
}
@keyframes tmb-vt-in {
  from {
    opacity: 0;
    transform: translate3d(0, 6px, 0);
  }
}

/* ── Reduced motion ───────────────────────────────────────────
   Fewer and gentler, not none: fades that aid comprehension stay, travel goes. */
@media (prefers-reduced-motion: reduce) {
  :root :is(.cta, .article-cta-link, .br-sub-btn, .br-sticky-btn, .tmb-art-submit):active {
    transform: none;
  }
  :root .br-sub-modal,
  :root .tmb-art-modal,
  :root .br-sub-overlay.is-open .br-sub-modal,
  :root .tmb-art-overlay.is-open .tmb-art-modal {
    transform: none;
    transition: none;
  }
  :root .br-sticky-bar {
    transition: opacity 160ms linear;
  }
}
