/* =====================================================================
   KBFX transitions.css  -  smooth page-to-page moves + gallery "grow"
   ---------------------------------------------------------------------
   Pairs with transitions.js (optional for page moves, needed for grow).

   ENABLE (in the <head> of EVERY page that should take part, old and new):
     <link rel="stylesheet" href="/assets/js/fx/transitions.css">
     <script src="/assets/js/fx/transitions.js"></script>   (classic, in head)
     <link rel="expect" href="#hero" blocking="render">     (id of the hero box:
       the new page waits to paint until the hero is parsed, so it can morph)

   MARK ELEMENTS (each name at most ONCE per page, or the browser skips
   the whole transition):
     data-fx-vt="header"  site header / top bar      -> stays still, on top
     data-fx-vt="title"   the page <h1>              -> slides to new place
     data-fx-vt="hero"    the hero photo             -> photo morphs
                          Put it on the <img> when nothing is drawn over the
                          photo. If the theme darkens the photo with an
                          overlay, put it on a wrapper that holds only the
                          photo and that overlay (else the overlay pops in at
                          the end). Never on <picture> alone, never on a
                          section that also holds text or cards.
     data-fx-vt="main"    optional: main content box -> own fade + slide
   Everything not marked fades and slides a little (the "root").

   TUNE (in a theme stylesheet, on :root, or via data-fx-* on <html>,
   which transitions.js copies here):
     --kbfx-vt-duration  page move time          (default 380ms)
     --kbfx-vt-shift     content slide distance  (default 18px)
     --kbfx-vt-ease      easing curve
     --kbfx-vt-hero      hero morph time         (default 520ms)
     --kbfx-vt-grow      gallery grow time       (default 440ms)

   Unsupported browsers: these rules are ignored, links work as usual.
   Reduced motion: everything below is switched off.
   ===================================================================== */

:root {
  --kbfx-vt-duration: 380ms;
  --kbfx-vt-shift: 18px;
  --kbfx-vt-ease: cubic-bezier(.22, .72, .18, 1);
  --kbfx-vt-hero: 520ms;
  --kbfx-vt-grow: 440ms;
}

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
    types: kb-page;
  }

  [data-fx-vt="header"] { view-transition-name: kb-header; }
  [data-fx-vt="title"]  { view-transition-name: kb-title; }
  [data-fx-vt="hero"]   { view-transition-name: kb-hero; }
  [data-fx-vt="main"]   { view-transition-name: kb-main; }
  /* During the gallery grow the page parts stay under the viewer's shade. */
  html[data-fx-vt-busy] [data-fx-vt] { view-transition-name: none; }

  /* ---- Page moves (cross-document only, typed kb-page) ---- */
  html:active-view-transition-type(kb-page)::view-transition-old(root),
  html:active-view-transition-type(kb-page)::view-transition-old(kb-main) {
    animation: var(--kbfx-vt-duration) var(--kbfx-vt-ease) both kbfx-vt-out;
  }
  html:active-view-transition-type(kb-page)::view-transition-new(root),
  html:active-view-transition-type(kb-page)::view-transition-new(kb-main) {
    animation: var(--kbfx-vt-duration) var(--kbfx-vt-ease) both kbfx-vt-in;
  }
  /* Going back: slide the other way. */
  html:active-view-transition-type(kb-back)::view-transition-old(root),
  html:active-view-transition-type(kb-back)::view-transition-old(kb-main) {
    animation-name: kbfx-vt-out-back;
  }
  html:active-view-transition-type(kb-back)::view-transition-new(root),
  html:active-view-transition-type(kb-back)::view-transition-new(kb-main) {
    animation-name: kbfx-vt-in-back;
  }

  /* Header: sits above everything and stays still. */
  ::view-transition-group(kb-header) { z-index: 3; animation-duration: 0s; }
  ::view-transition-old(kb-header) { display: none; }
  ::view-transition-new(kb-header) { animation: none; }

  /* Title: box glides, text is never stretched, quick cross-fade. */
  ::view-transition-group(kb-title) {
    z-index: 2;
    animation-duration: var(--kbfx-vt-duration);
    animation-timing-function: var(--kbfx-vt-ease);
  }
  ::view-transition-old(kb-title),
  ::view-transition-new(kb-title) {
    width: 100%; height: 100%;
    object-fit: none; object-position: left center;
    animation-duration: calc(var(--kbfx-vt-duration) * .7);
  }

  /* Hero photo: one picture turns into the other, crops stay clean. */
  ::view-transition-group(kb-hero),
  ::view-transition-group(kb-grow) {
    animation-duration: var(--kbfx-vt-hero);
    animation-timing-function: var(--kbfx-vt-ease);
    overflow: clip;
  }
  ::view-transition-old(kb-hero), ::view-transition-new(kb-hero),
  ::view-transition-old(kb-grow), ::view-transition-new(kb-grow) {
    width: 100%; height: 100%;
    object-fit: cover;
    animation-duration: var(--kbfx-vt-hero);
  }

  /* ---- Gallery grow (same-document, typed kb-grow) ---- */
  html:active-view-transition-type(kb-grow)::view-transition-group(kb-grow) {
    z-index: 5;
    animation-duration: var(--kbfx-vt-grow);
  }
  html:active-view-transition-type(kb-grow)::view-transition-old(kb-grow),
  html:active-view-transition-type(kb-grow)::view-transition-new(kb-grow) {
    animation-duration: calc(var(--kbfx-vt-grow) * .6);
  }
  html:active-view-transition-type(kb-grow)::view-transition-old(root),
  html:active-view-transition-type(kb-grow)::view-transition-new(root) {
    animation-duration: var(--kbfx-vt-grow);
    animation-timing-function: var(--kbfx-vt-ease);
  }
}

@keyframes kbfx-vt-out { to { opacity: 0; transform: translateY(calc(var(--kbfx-vt-shift) * -.6)); } }
@keyframes kbfx-vt-in  { from { opacity: 0; transform: translateY(var(--kbfx-vt-shift)); } }
@keyframes kbfx-vt-out-back { to { opacity: 0; transform: translateY(calc(var(--kbfx-vt-shift) * .6)); } }
@keyframes kbfx-vt-in-back  { from { opacity: 0; transform: translateY(calc(var(--kbfx-vt-shift) * -1)); } }
