/* How the site moves from page to page, and how a page arrives. Every page loads this (after its own styles) and
   js/motion.js, which runs in <head> so it is ready before the new page is first drawn.

   Changing page is a special delivery. The camera pulls back: the page you're on becomes a postcard floating in
   Tracy's painted sky (a white polaroid border with the page's name on it, a strip of the reel's washi tape, and a
   stamp with Cinnamoroll on it, postmarked today). Cinnamoroll (her 2026-01-01 "咻～" drawing, build_motion.py) flies in, grabs it by its top edge
   and carries it off; he comes back from the other side with the next page's card, lets go of it in the middle and
   flies away, and the camera dives into the card. Going back, he flies the other way. Then the page's own heading,
   words and pictures float up one after another (these play on a plain load too).

   It uses cross-document view transitions (Chrome and Edge 126+, Safari 18.2+). Elsewhere pages just swap, as before.
   With "reduce motion" on, pages swap with a short fade and nothing moves or floats in. */

@view-transition { navigation: auto; }

/* The sky and the flyer: js/motion.js puts them in the new page for the transition only. */
.vt-wipe { display: none; }

@media (prefers-reduced-motion: no-preference) {

  /* ---------------------------------------------------------------- special delivery */

  /* The card is the page at --vt-s, --vt-cy below the middle, with the sky above it for him. He is --vt-cin wide on
     screen, which is --vt-w in the card frames below (pages shrunk to cards). --vt-grip is where along the card's
     top edge his paw holds it. --vt-b is the postcard's white border on screen, --vt-foot its deeper bottom, where
     the page's name is written. --dir is 1, or -1 going back. */
  :root {
    --dir: 1;
    --vt-time: 2.2s;
    --vt-s: 0.44;
    --vt-cy: 5vh;
    --vt-cin: calc(min(100vw, 100vh) * 0.42);
    --vt-w: calc(var(--vt-cin) / var(--vt-s));
    --vt-grip: 70%;
    --vt-b: calc(min(100vw, 100vh) * 0.012 + 6px);
    --vt-foot: calc(var(--vt-b) * 3);
  }
  html:active-view-transition-type(back) { --dir: -1; }

  html:active-view-transition .vt-wipe { display: block; position: fixed; inset: 0; overflow: hidden; pointer-events: none; }

  /* bottom to top: the sky, the pages, their postcards and him */
  html:active-view-transition .vt-sky-box { view-transition-name: vt-sky; background: #8fd0f2; }
  html:active-view-transition .vt-carry { view-transition-name: vt-carry; }
  .vt-flip { position: absolute; inset: 0; scale: var(--dir) 1; }   /* inside the layer, so it's in what's drawn */
  ::view-transition-group(vt-sky) { z-index: 0; }
  ::view-transition-group(root) { z-index: 1; }
  ::view-transition-group(vt-carry) { z-index: 2; }
  ::view-transition-new(vt-sky), ::view-transition-new(vt-carry) { animation: none; }   /* live: they move themselves */

  /* the sky: the lower part of Tracy's painting (its heaped clouds, the line at its foot just out of sight), wider
     than the window: the camera pulls back with the card, pans along with him while he carries, and dives back in */
  .vt-sky-zoom { position: absolute; inset: 0; animation: vt-sky var(--vt-time) both; }
  .vt-sky {
    position: absolute; left: 50%; width: max(124vw, 100vh * 1080 / 690); height: auto; max-width: none;
    top: calc(100vh - max(124vw, 100vh * 1080 / 690) * 1290 / 1080); translate: -50% 0;
  }

  /* the pages, as cards */
  ::view-transition-old(root) { animation: vt-card-out var(--vt-time) both; }
  ::view-transition-new(root) { animation: vt-card-in var(--vt-time) both; }

  /* Each card's postcard, in his layer under him: a full-window frame running the card's own keyframes, so it is
     drawn round the page (at 1 / --vt-s, like him). All of it sits outside the page but the tape and the stamp, which
     fade in as the page becomes a card and out as it becomes the page again. */
  .vt-post {
    position: absolute; inset: 0;
    --b: calc(var(--vt-b) / var(--vt-s)); --f: calc(var(--vt-foot) / var(--vt-s)); --px: calc(1px / var(--vt-s));
  }
  .vt-post-out { animation: vt-card-out var(--vt-time) both; }
  .vt-post-in { animation: vt-card-in var(--vt-time) both; }
  .vt-paper {   /* the white border, a little over the page's edge so no sky shows between, and its shadow */
    position: absolute; inset: calc(var(--b) * -1) calc(var(--b) * -1) calc(var(--f) * -1);
    border: solid #fff; border-width: calc(var(--b) + 2px) calc(var(--b) + 2px) calc(var(--f) + 2px);
    border-radius: calc(var(--b) * 0.45);
    box-shadow: 0 calc(var(--px) * 22) calc(var(--px) * 44) rgba(20, 70, 130, 0.28), 0 calc(var(--px) * 3) calc(var(--px) * 6) rgba(20, 70, 130, 0.12);
  }
  .vt-edge { position: absolute; inset: 2px; box-shadow: inset 0 0 0 var(--px) rgba(44, 132, 198, 0.18); }   /* the photo's edge */
  .vt-cap {   /* the page's name, written along the bottom */
    position: absolute; left: calc(var(--b) * 0.15); top: calc(100% + 2px); height: var(--f);
    display: flex; align-items: center; gap: calc(var(--f) * 0.1); white-space: nowrap;
    font: calc(var(--f) * 0.4) / 1 "Huninn", "Huninn UI", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
    color: var(--deep, #2c84c6); letter-spacing: 0.04em;
  }
  .vt-cap svg { width: calc(var(--f) * 0.34); height: auto; fill: var(--pink-deep, #ee7fa8); }
  .vt-deco { position: absolute; inset: 0; }
  .vt-post-out .vt-deco { animation: vt-deco-out var(--vt-time) both; }
  .vt-post-in .vt-deco { animation: vt-deco-in var(--vt-time) both; }
  .vt-tape {   /* the reel's washi tape, across the top corner away from his paw */
    position: absolute; top: 0; left: calc(50% - var(--dir) * 50%); width: calc(var(--f) * 2.5); height: auto; max-width: none;
    translate: -50% -50%; rotate: calc(var(--dir) * -38deg);
  }
  .vt-stamp {   /* bottom right, a little over the page: Tracy's jumping-for-joy drawing on a pale sky */
    position: absolute; right: calc(var(--f) * 0.3); bottom: calc(var(--f) * -0.78);
    width: calc(var(--f) * 1.3); height: calc(var(--f) * 1.6); rotate: 4deg;
    filter: drop-shadow(0 calc(var(--px) * 2) calc(var(--px) * 3) rgba(20, 70, 130, 0.25));
  }
  .vt-stamp-cut {   /* its perforated edge: holes centred on the edge, all round */
    --r: calc(var(--f) * 0.05);
    position: absolute; inset: 0; padding: calc(var(--r) * 2.1); background: #fff;
    mask: radial-gradient(var(--r), #0000 97%, #000) round calc(var(--r) * -1.5) calc(var(--r) * -1.5) / calc(var(--r) * 3) calc(var(--r) * 3),
      linear-gradient(#000 0 0) 50% / calc(100% - var(--r) * 3) calc(100% - var(--r) * 3) no-repeat;
  }
  .vt-stamp-art { position: relative; width: 100%; height: 100%; overflow: hidden; background: linear-gradient(#9fd8f6, #e6f5fe 80%); }
  .vt-stamp-art img { position: absolute; width: 125%; max-width: none; height: auto; left: -14%; top: 6%; }
  .vt-mark {   /* the postmark: its ring on the card, its wavy lines over the stamp */
    position: absolute; right: calc(var(--f) * 0.75); bottom: calc(var(--f) * -0.98); width: calc(var(--f) * 2.3); height: auto;
    color: #2f6fa6; opacity: 0.55; rotate: -6deg; mix-blend-mode: multiply;
    font-family: "Huninn", "Huninn UI", system-ui, sans-serif;
  }

  /* Him: one frame per card, each running the same keyframes as its card while he holds it, so he stays on its
     edge. In it, .vt-me is the point his head is at, and each pose (build_motion.py's fly_*.webp, one scale) is pinned
     there by its own head (--hx, --hy, its height --ar), so the flipbook swaps in place. fly_carry's front paw lands
     on --vt-grip. The reel's speed lines trail him while he's going fast. */
  .vt-hold { position: absolute; inset: 0; }
  .vt-hold-out { animation: vt-hold-out var(--vt-time) both; }
  .vt-hold-in { animation: vt-hold-in var(--vt-time) both; }
  .vt-me {
    position: absolute; width: 0; height: 0;
    left: calc(var(--vt-grip) - var(--vt-w) * 0.2375); top: calc(var(--vt-w) * -0.275);
    transform-origin: calc(var(--vt-w) * 0.2375) calc(var(--vt-w) * 0.275);   /* his paw */
  }
  .vt-hold-out .vt-me { animation: vt-grab var(--vt-time) both; }
  .vt-hold-in .vt-me { animation: vt-hop var(--vt-time) both; }
  .vt-pose {
    position: absolute; max-width: none; height: auto; width: var(--vt-w);
    left: calc(var(--vt-w) * var(--hx) * -1); top: calc(var(--vt-w) * var(--ar) * var(--hy) * -1);
    transform-origin: calc(var(--hx) * 100%) calc(var(--hy) * 100%);
  }
  .vt-p-dash { --hx: 0.625; --hy: 0.3469; --ar: 0.6125; }
  .vt-p-carry { --hx: 0.6625; --hy: 0.3309; --ar: 0.68; }
  .vt-p-yay { --hx: 0.4875; --hy: 0.432; --ar: 0.7812; }
  /* ears beating, and which frame of the flipbook shows when */
  .vt-hold-out .vt-p-dash { animation: vt-flap 0.3s ease-in-out infinite alternate, vt-until-a var(--vt-time) both; }
  .vt-hold-out .vt-p-carry { animation: vt-flap 0.3s ease-in-out infinite alternate, vt-from-a var(--vt-time) both; }
  .vt-hold-in .vt-p-carry { animation: vt-flap 0.3s ease-in-out infinite alternate, vt-until-b var(--vt-time) both; }
  .vt-hold-in .vt-p-yay { animation: vt-flap 0.3s ease-in-out infinite alternate, vt-from-b var(--vt-time) both; }
  .vt-lines { position: absolute; }
  .vt-hold-out .vt-lines { animation: vt-lines-out var(--vt-time) both; }
  .vt-hold-in .vt-lines { animation: vt-lines-in var(--vt-time) both; }
  .vt-line {   /* make_recap SPEED_LINES, behind his ears, flickering */
    position: absolute; height: auto; max-width: none; opacity: 0.9;
    animation: vt-flicker 0.29s ease-in-out infinite alternate;
  }
  .vt-line:nth-child(1) { width: calc(var(--vt-w) * 0.42); top: calc(var(--vt-w) * -0.06); right: calc(var(--vt-w) * 0.72); }
  .vt-line:nth-child(2) { width: calc(var(--vt-w) * 0.62); top: calc(var(--vt-w) * 0.1); right: calc(var(--vt-w) * 0.7); animation-delay: -0.12s; }
  .vt-line:nth-child(3) { width: calc(var(--vt-w) * 0.48); top: calc(var(--vt-w) * 0.26); right: calc(var(--vt-w) * 0.66); animation-delay: -0.2s; }

  /* ---------------------------------------------------------------- a page arriving */

  /* the hero's words one after another, then its picture and the page's main tool. They move with translate / scale /
     rotate, not transform, so they add to whatever turn or hover lift the element already has. */
  .ab-kicker { animation: arrive-pop 0.7s cubic-bezier(0.3, 1.5, 0.5, 1) 0.08s backwards; }
  .ab-h1 { animation: arrive-soft 1s cubic-bezier(0.2, 0.8, 0.2, 1) 0.16s backwards; }
  .ab-lead { animation: arrive-soft 1s cubic-bezier(0.2, 0.8, 0.2, 1) 0.26s backwards; }
  .ab-actions, .pd-get, .hm-continue { animation: arrive-up 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) 0.36s backwards; }
  .ab-hero-art, .gd-hero-art { animation: arrive-art 1.1s cubic-bezier(0.25, 1.2, 0.4, 1) 0.24s backwards; }
  .cd-maker, .wp-grid, .gd-toc { animation: arrive-up 1s cubic-bezier(0.2, 0.8, 0.2, 1) 0.4s backwards; }
  /* the home page: its painted sky settles, its lettering pops up, then its cards, the lead one first (index.html puts
     it first before the page is drawn) */
  .hm-art { animation: arrive-sky 1.4s cubic-bezier(0.2, 0.8, 0.2, 1) backwards; }
  .hm-h1 { animation: arrive-pop 0.8s cubic-bezier(0.3, 1.5, 0.5, 1) 0.12s backwards; }
  .ft-home > .ft { animation: arrive-up 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) calc(0.36s + var(--n, 0) * 0.08s) backwards; }
  .ft-home > .ft:nth-child(2) { --n: 1; }
  .ft-home > .ft:nth-child(3) { --n: 2; }
  .ft-home > .ft:nth-child(4) { --n: 3; }
}

/* The cards' path, over --vt-time:
   0-25%   the camera pulls back to the card
   25-36%  it waits while he dashes in (from 14%)
   36-39%  he grabs it, and it dips under him
   39-50%  he carries it off; it swings back as he speeds up
   52-72%  he brings the next one in; it swings forward as he slows down
   72-81%  he lets go and hops away; it settles with a small wobble, and draws in a breath
   81-100% the camera dives in */
@keyframes vt-card-out {
  0% { translate: 0 0; scale: 1; rotate: 0deg; animation-timing-function: cubic-bezier(0.8, 0, 0.2, 1); }
  25%, 36% { translate: 0 var(--vt-cy); scale: var(--vt-s); rotate: 0deg; animation-timing-function: cubic-bezier(0.3, 0, 0.4, 1); }
  39% { translate: 0 calc(var(--vt-cy) + 1.6vh); scale: var(--vt-s); rotate: calc(var(--dir) * -2deg); animation-timing-function: cubic-bezier(0.55, 0, 0.85, 0.35); }
  45% { translate: calc(var(--dir) * 30vw) -2vh; scale: var(--vt-s); rotate: calc(var(--dir) * 15deg); animation-timing-function: cubic-bezier(0.3, 0.4, 0.6, 1); }
  50%, 100% { translate: calc(var(--dir) * 96vw) -18vh; scale: var(--vt-s); rotate: calc(var(--dir) * 9deg); }
}
@keyframes vt-card-in {
  0%, 52% { translate: calc(var(--dir) * -96vw) -18vh; scale: var(--vt-s); rotate: calc(var(--dir) * 9deg); animation-timing-function: cubic-bezier(0.25, 0.55, 0.45, 1); }
  64% { translate: calc(var(--dir) * -7vw) calc(var(--vt-cy) - 1.5vh); scale: var(--vt-s); rotate: calc(var(--dir) * -6deg); animation-timing-function: cubic-bezier(0.35, 0, 0.35, 1); }
  72% { translate: 0 var(--vt-cy); scale: var(--vt-s); rotate: 0deg; animation-timing-function: cubic-bezier(0.3, 0, 0.5, 1); }
  75% { translate: 0 calc(var(--vt-cy) - 0.9vh); scale: var(--vt-s); rotate: calc(var(--dir) * 2.5deg); animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1); }
  78% { translate: 0 calc(var(--vt-cy) + 0.3vh); scale: var(--vt-s); rotate: calc(var(--dir) * -1deg); animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1); }
  81% { translate: 0 var(--vt-cy); scale: calc(var(--vt-s) * 0.96); rotate: 0deg; animation-timing-function: cubic-bezier(0.6, 0, 0.15, 1); }
  100% { translate: 0 0; scale: 1; rotate: 0deg; }
}
@keyframes vt-deco-out { 0%, 14% { opacity: 0; } 24%, 100% { opacity: 1; } }   /* the tape and stamp, as it becomes a card */
@keyframes vt-deco-in { 0%, 84% { opacity: 1; } 94%, 100% { opacity: 0; } }   /* and as it becomes the page */
/* his frames: the same as the cards while he holds them (no --dir: the layer is turned round instead) */
@keyframes vt-hold-out {
  0%, 14% { translate: -96vw 30vh; scale: var(--vt-s); rotate: -18deg; animation-timing-function: cubic-bezier(0.2, 0.7, 0.3, 1); }
  36% { translate: 0 var(--vt-cy); scale: var(--vt-s); rotate: 0deg; animation-timing-function: cubic-bezier(0.3, 0, 0.4, 1); }
  39% { translate: 0 calc(var(--vt-cy) + 1.6vh); scale: var(--vt-s); rotate: -2deg; animation-timing-function: cubic-bezier(0.55, 0, 0.85, 0.35); }
  45% { translate: 30vw -2vh; scale: var(--vt-s); rotate: 15deg; animation-timing-function: cubic-bezier(0.3, 0.4, 0.6, 1); }
  50%, 100% { translate: 96vw -18vh; scale: var(--vt-s); rotate: 9deg; }
}
@keyframes vt-hold-in {
  0%, 52% { translate: -96vw -18vh; scale: var(--vt-s); rotate: 9deg; animation-timing-function: cubic-bezier(0.25, 0.55, 0.45, 1); }
  64% { translate: -7vw calc(var(--vt-cy) - 1.5vh); scale: var(--vt-s); rotate: -6deg; animation-timing-function: cubic-bezier(0.35, 0, 0.35, 1); }
  72% { translate: 0 var(--vt-cy); scale: var(--vt-s); rotate: 0deg; animation-timing-function: cubic-bezier(0.2, 0.7, 0.3, 1); }
  77% { translate: 3vw calc(var(--vt-cy) - 9vh); scale: var(--vt-s); rotate: -4deg; animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.6); }
  93%, 100% { translate: 62vw -85vh; scale: var(--vt-s); rotate: -20deg; }
}
@keyframes vt-grab {   /* a squash as he takes its weight */
  0%, 35% { scale: 1; }
  37.5% { scale: 1.06 0.9; }
  41%, 100% { scale: 1; }
}
@keyframes vt-hop {   /* crouch, then spring up */
  0%, 71% { scale: 1; }
  73% { scale: 1.08 0.88; }
  76% { scale: 0.94 1.08; }
  79%, 100% { scale: 1; }
}
@keyframes vt-until-a { 0%, 33% { opacity: 1; } 33.01%, 100% { opacity: 0; } }   /* dashing, then reaching */
@keyframes vt-from-a { 0%, 33% { opacity: 0; } 33.01%, 100% { opacity: 1; } }
@keyframes vt-until-b { 0%, 73% { opacity: 1; } 73.01%, 100% { opacity: 0; } }   /* carrying, then jumping for joy */
@keyframes vt-from-b { 0%, 73% { opacity: 0; } 73.01%, 100% { opacity: 1; } }
@keyframes vt-lines-out { 0%, 14% { opacity: 0; } 18%, 31% { opacity: 1; } 35%, 41% { opacity: 0; } 44%, 100% { opacity: 1; } }
@keyframes vt-lines-in { 0%, 61% { opacity: 1; } 67%, 76% { opacity: 0; } 81%, 100% { opacity: 1; } }
@keyframes vt-flap { from { translate: 0 0; rotate: -2deg; } to { translate: 0 -3%; rotate: 2deg; } }
@keyframes vt-flicker { from { translate: calc(var(--vt-w) * -0.04) 0; } to { translate: calc(var(--vt-w) * 0.04) 0; } }
@keyframes vt-sky {
  0% { scale: 1.2; translate: 0 0; animation-timing-function: cubic-bezier(0.8, 0, 0.2, 1); }
  25% { scale: 1; translate: 0 0; animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1); }
  81% { scale: 1; translate: calc(var(--dir) * -9vw) 0; animation-timing-function: cubic-bezier(0.6, 0, 0.15, 1); }
  100% { scale: 1.2; translate: calc(var(--dir) * -9vw) 0; }
}

@keyframes arrive-pop { from { opacity: 0; scale: 0.6; translate: 0 10px; } }
@keyframes arrive-soft { from { opacity: 0; translate: 0 30px; filter: blur(8px); } }
@keyframes arrive-up { from { opacity: 0; translate: 0 44px; } }
@keyframes arrive-art { from { opacity: 0; translate: 0 70px; rotate: -6deg; scale: 0.9; } }
@keyframes arrive-sky { from { opacity: 0; scale: 1.06; } }
