/* ==========================================================================
   ltm.onl — motion
   The named motions built for hikomi's site and app, cut down to the six that
   have a home here. motion.js has the rules and says which part of which page
   uses which motion; this file is how each one looks.

   <html> carries m-<name> only while a motion is on (the script in each page's
   head sets it before the first paint), and every rule below sits behind that
   class. With ?motion=off, or under reduced motion, the site is exactly as it
   was. Nothing here loops.
   ========================================================================== */

/* --spring is a real damped spring (damping ratio 0.78) sampled into CSS's
   linear(): a quick start, about 2% of overshoot, settled by the end of
   --spring-dur. --spring-soft is the same spring critically damped, with no
   overshoot, for fades and blurs, which shouldn't go past where they stop.
   A browser without linear() (Safari before 17.2, Firefox before 112) gets
   the nearest plain curve to each, set just under this block. It has to be
   told: a curve it cannot read does not fall back to an ease, it switches
   off every transition that names it, and things would jump into place.
   --leave: something going away is quicker than something arriving, and
   speeds up as it goes. */
:root {
  --spring: linear(0, 0.0266, 0.0934, 0.1842, 0.2869, 0.3925, 0.4949, 0.5899, 0.6751, 0.7494,
                   0.8125, 0.8649, 0.9074, 0.9409, 0.9668, 0.986, 0.9998, 1.0092, 1.0152, 1.0185,
                   1.0198, 1.0197, 1.0187, 1.017, 1.0151, 1.013, 1.0109, 1.0089, 1.0071, 1.0056,
                   1.0042, 1.0031, 1.0022, 1.0014, 1.0009, 1.0004, 1);
  --spring-soft: linear(0, 0.055, 0.1734, 0.3101, 0.4422, 0.5591, 0.6575, 0.7374, 0.8009, 0.8503,
                        0.8883, 0.9172, 0.9389, 0.9551, 0.9672, 0.9761, 0.9826, 0.9874, 0.9909,
                        0.9935, 0.9953, 0.9966, 0.9976, 0.9983, 1);
  --spring-dur: 480ms;
  --leave: cubic-bezier(.4, 0, 1, 1);
  --leave-dur: 150ms;
}
/* The nearest cubic-bezier to each spring (tools/extra/bezfit.py: never more
   than 0.044 and 0.028 away, with the same 2% past the end for --spring and
   none for --spring-soft). Browsers that know linear() skip this. */
@supports not (transition-timing-function: linear(0, 1)) {
  :root {
    --spring: cubic-bezier(.38, .89, .08, 1.09);
    --spring-soft: cubic-bezier(.3, .56, .08, 1);
  }
}

/* ---- page: one page gives way to the next ---------------------------------
   A cross-document view transition (each page's head asks for it, and only
   when reduced motion is not set). The page being left drifts up as the new
   one comes up under the header. The header stays where it is, and so do the
   stars and the glow, which sit in the same place on every page.
   The two pages fade across each other at one even rate, blended
   plus-lighter, so the screen's brightness goes straight from the old page's
   to the new one's: no dip to the bare ground between them and no flash.
   With the phone menu open, the header and the stars are left in the page's
   own picture, so the menu and its shade stay over them as they go.
   ?motion=off skips it (the page being left decides, in motion.js). */
.m-page body:not(.drawer-open) .site-header { view-transition-name: site-header; }
.m-page body:not(.drawer-open) .site-bg { view-transition-name: site-bg; }
html.m-page::view-transition-old(root) {
  animation: page-fade-out 220ms linear both, page-out 220ms var(--leave) both;
  mix-blend-mode: plus-lighter;
}
html.m-page::view-transition-new(root) {
  animation: page-fade-in 220ms linear both, page-in 420ms var(--spring-soft, ease-out) both;
  mix-blend-mode: plus-lighter;
}
@keyframes page-fade-out { to { opacity: 0; } }
@keyframes page-fade-in { from { opacity: 0; } }
@keyframes page-out { to { translate: 0 -8px; } }
@keyframes page-in { from { translate: 0 12px; } }

/* ---- rise: things come in as you reach them -------------------------------
   motion.js hides only what is still below the screen ([data-rise]), then
   lets it go as it comes into view. !important because these two classes are
   only ever on for the move, and must win over whatever the thing's own rules
   say meanwhile. What waits is hidden only behind html.m-rise and only on a
   screen: with rise switched off it is simply there, and a printed page has
   all of it. It cannot be clicked while it cannot be seen. */
@media screen {
  .m-rise .rise-wait { opacity: 0 !important; translate: 0 18px !important; pointer-events: none !important; }
  .m-rise .rise-word.rise-wait { translate: 0 .45em !important; filter: blur(5px) !important; }
}
.rise-word { display: inline-block; }
.rise-go {
  transition: opacity 360ms var(--spring-soft) var(--rise-d, 0ms),
              translate var(--spring-dur) var(--spring) var(--rise-d, 0ms),
              filter 380ms var(--spring-soft) var(--rise-d, 0ms) !important;
}

/* The first screen is in view before any script runs, so it comes in by CSS
   alone: its parts one after another on the spring, in place of the block's
   single fade (styles.css, "gentle fade-in on load"). The sections under it
   keep that fade. With motion on, none of these is left holding its end.
   A page that arrived by the page motion is already moving as a whole, so it
   plays neither (.vt, set in the head). */
@media screen and (prefers-reduced-motion: no-preference) {
  .m.js main > * { animation-fill-mode: backwards; }
  .m-rise.js main > :first-child { animation: none; }
  .m-rise.js main > :first-child > * {
    animation: rise-fade 360ms var(--spring-soft) backwards, rise-up var(--spring-dur) var(--spring) backwards;
    animation-delay: calc(var(--rise-i, 0) * 55ms);
  }
  .m-rise.js main > :first-child > :nth-child(2) { --rise-i: 1; }
  .m-rise.js main > :first-child > :nth-child(3) { --rise-i: 2; }
  .m-rise.js main > :first-child > :nth-child(4) { --rise-i: 3; }
  .m-rise.js main > :first-child > :nth-child(5) { --rise-i: 4; }
  .m-rise.js main > :first-child > :nth-child(n+6) { --rise-i: 5; }
  .vt.js main > *, .vt.js main > :first-child > * { animation: none; }
}
@keyframes rise-fade { from { opacity: 0; } }
@keyframes rise-up { from { translate: 0 18px; } }

/* ---- glide: one marker follows you along the menu -------------------------
   The liquid marker (motion.js liquid()) is placed by its own springs, so it
   has no transition of its own, only its fade. It sits behind the row's
   words: while glide is on the row is a layer of its own, and it is placed
   (.glide-box) so the marker can be put inside it.
   The marker wears the menu's own hover tint and takes over both of that
   tint's jobs: the link under the pointer, and the page you are on, where it
   rests. With glide off, the links' own tints do those jobs as before. */
.liquid {
  position: absolute; left: 0; top: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms var(--spring-soft);
}
.liquid.on { opacity: 1; }
.m-glide [data-glide] { isolation: isolate; }
.m-glide .glide-box { position: relative !important; }
.glide-mark { z-index: -1; }
html:not(.m-glide) .glide-mark { opacity: 0; }
.nav-mark { border-radius: 8px; background: var(--accent-soft); }
.m-glide .nav-links.nav-glided a:not(.btn):hover,
.m-glide .nav-links.nav-glided a[aria-current="page"] { background: none; }

/* ---- tilt: a card that is a link leans towards the pointer ---------------
   Mouse only. motion.js sets --tilt-x and --tilt-y, -1 to 1, only while
   .tilting is on the card. The card's own lift on hover moves to `translate`,
   on the spring, so the lean and the lift do not fight over one property.
   A card with no destination stays still, as before. */
@media (hover: hover) and (pointer: fine) {
  .m-tilt .card-link { transition: border-color 150ms linear, translate var(--spring-dur) var(--spring); }
  .m-tilt .card-link:hover { transform: none; translate: 0 -2px; }
  .m-tilt .card-link.tilting {
    transform: perspective(900px) rotateX(calc(var(--tilt-y, 0) * -3.2deg)) rotateY(calc(var(--tilt-x, 0) * 3.2deg));
  }
}

/* ---- nudge: an arrow moves the way its link goes, and springs back --------
   [data-nudge="right|left|out|turn"] on the arrow inside a link or a button
   (motion.js gives each arrow a span of its own). */
.m-nudge [data-nudge] {
  display: inline-block;
  transition: translate var(--spring-dur) var(--spring), rotate var(--spring-dur) var(--spring);
}
@media (hover: hover) {
  .m-nudge :is(a, button):hover [data-nudge="right"] { translate: 3px 0; }
  .m-nudge :is(a, button):hover [data-nudge="left"] { translate: -3px 0; }
  .m-nudge :is(a, button):hover [data-nudge="out"] { translate: 2px -2px; }
  .m-nudge :is(a, button):hover [data-nudge="turn"] { rotate: 90deg; }
}
.m-nudge :is(a, button):focus-visible [data-nudge="right"] { translate: 3px 0; }
.m-nudge :is(a, button):focus-visible [data-nudge="left"] { translate: -3px 0; }
.m-nudge :is(a, button):focus-visible [data-nudge="out"] { translate: 2px -2px; }
.m-nudge :is(a, button):focus-visible [data-nudge="turn"] { rotate: 90deg; }

/* ---- focus: the keyboard's ring closes in on what it lands on -------------
   Whatever ring the thing has: this only says where it starts. :where()
   keeps it from outweighing an animation something has of its own. A card
   that is a link draws its ring round the whole card (styles.css). */
:where(.m-focus) :focus-visible { animation: focus-in 220ms var(--spring-soft); }
.m-focus .card-link h3 a:focus-visible::after { animation: focus-in 220ms var(--spring-soft); }
@keyframes focus-in { from { outline-offset: 8px; outline-color: transparent; } }
