/* How the app moves (b2453). Linked by every whole page of the hub's: the owner's pages (admin/templates/base.html,
   chats.html), the front door and the legal pages, a desk page's own frame and a question's page, the operator's
   pages. Four things, all of them transform and opacity only, none of them needing script to be right:

   1. A move from one page to another is a view transition, not a cut: the two pages cross-fade (180 ms). On a
      phone a move down into a page (a row on Home, a job in Activity, a chat) pushes it in from the right and the
      bar's way back pops it off to the right, as the iPhone apps this frame is measured off do; the bar holds still
      and only its title changes. Which way a move goes is said by motion.js (the tap that starts it, or the
      browser's own back and forward); a move it says nothing about (the way anywhere's sheet, a form saved, the
      side list on a desktop) cross-fades. A browser without view transitions between pages cuts, as before.
   2. Something that comes onto a page (a row that opens, a sheet, a message) eases in from where it comes from,
      and what a page puts away fades; each rule is beside the thing it moves, in that thing's own stylesheet.
   3. Reduce Motion keeps the cross-fade, which moves nothing, and drops every slide. */

@view-transition { navigation: auto; }

/* the page under a move stays the page: a tap during the 240-300 ms lands on what is there now */
::view-transition { pointer-events: none; }
/* the page before is held 60 ms before the fade starts: the new page's first frame takes about that long to draw, and
   a fade started without it was three quarters over in the first frame anyone saw (recorded, b2453) */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.18s; animation-delay: 0.06s; animation-fill-mode: both; }
::view-transition-group(*) { animation-duration: 0.2s; animation-timing-function: cubic-bezier(0.2, 0.9, 0.25, 1); }

/* a desktop's side list is the same list on every page: it holds still while the page beside it changes */
@media (min-width: 761px) { aside.side { view-transition-name: side; } }

@media (max-width: 760px) and (prefers-reduced-motion: no-preference) {
  /* the bar stays where it is, over the pages moving under it */
  .appbar { view-transition-name: bar; }
  ::view-transition-group(bar) { z-index: 2; }
  html:active-view-transition-type(forward)::view-transition-old(root),
  html:active-view-transition-type(forward)::view-transition-new(root),
  html:active-view-transition-type(back)::view-transition-old(root),
  html:active-view-transition-type(back)::view-transition-new(root) {
    mix-blend-mode: normal; animation-duration: 0.3s; animation-timing-function: cubic-bezier(0.2, 0.9, 0.25, 1);
    animation-delay: 0s; animation-fill-mode: both;
  }
  /* down into a page: it comes in from the right over the one before, which gives way a little */
  html:active-view-transition-type(forward)::view-transition-old(root) { animation-name: move-under-left; }
  html:active-view-transition-type(forward)::view-transition-new(root) { animation-name: move-in-right; }
  /* back out of it: it leaves to the right, and the page before comes back from where it gave way to */
  html:active-view-transition-type(back)::view-transition-old(root) { animation-name: move-out-right; z-index: 1; }
  html:active-view-transition-type(back)::view-transition-new(root) { animation-name: move-up-left; }
}
/* Into the first chat from setup's last screen (admin/static/finish.js, b2672), a move of the kind "arrive": the
   agent's face, which that screen brought to its middle, settles into the chat's bar, where the chat has it, while
   the chat fades in under it. The chat's bar picture takes the face's name only for this move, so on every other
   move it is part of the bar as before. Under Reduce Motion the screen before never names its face (admin.css),
   and the move is the plain cross-fade. */
@media (prefers-reduced-motion: no-preference) {
  html:active-view-transition-type(arrive) .appbar .bar-contact .bar-avatar { view-transition-name: stage-face; }
  html:active-view-transition-type(arrive)::view-transition-group(stage-face) { z-index: 3; animation-duration: 0.4s; animation-timing-function: cubic-bezier(0.2, 0, 0, 1); }
  html:active-view-transition-type(arrive)::view-transition-old(root),
  html:active-view-transition-type(arrive)::view-transition-new(root) { animation-duration: 0.3s; animation-delay: 0s; }
}
@keyframes move-in-right { from { transform: translateX(100%); } }

/* 4. A page shows once, laid out (core/static/hold.js, b2690): until its script says so the page is laid out and not
   painted, and it comes in whole, with no fade. A move here from another page holds that page on the screen for as
   long, then goes: the two pages of a move are both finished ones. The 4 s animation lets go by itself if the script
   never runs to its end. Not under the app's launch screen (admin/static/launch.js): that covers the page whole, and
   a page with nothing painted gets no frame at all in Safari's engine, so there the page is painted under it. */
html.held:not(.launch) body { opacity: 0; animation: held-most 0s linear 4s forwards; }
@keyframes held-most { to { opacity: 1; } }
html.held::view-transition-old(root), html.held::view-transition-new(root), html.held::view-transition-group(*) { animation-play-state: paused; }
@keyframes move-out-right { to { transform: translateX(100%); } }
@keyframes move-under-left { to { transform: translateX(-25%); opacity: 0.4; } }
@keyframes move-up-left { from { transform: translateX(-25%); opacity: 0.4; } }
