/* Shared timing for controls, content changes, a change of view, and deliberate map moves: unhurried, and easing
   out smoothly rather than stopping short. The ease spreads a move over its time (half done at 28% of it, nine
   tenths at 68%), so a menu or a card is seen to come rather than blink in. */
:root {
  --motion-ui: 280ms;
  --motion-reader: 380ms;
  --motion-view: 420ms;
  --motion-camera: 750ms;
  --motion-ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --motion-ease-in-out: cubic-bezier(0.45, 0, 0.2, 1);
}

@keyframes page-in { from { opacity: 0.75; } }

@media (prefers-reduced-motion: no-preference) {
  main { animation: page-in var(--motion-ui) var(--motion-ease); }
  :is(button, a, summary, select, input) {
    transition: color var(--motion-ui) var(--motion-ease),
      background-color var(--motion-ui) var(--motion-ease),
      border-color var(--motion-ui) var(--motion-ease),
      opacity var(--motion-ui) var(--motion-ease);
  }

  /* A change of view (app.js: changeView) moves the panel and the player as sheets from where they were to where they
     are now, their contents crossfading; the page's own old picture is not shown, so the chart goes on drawing live
     beneath them. The top bar changes with the panel, not before it. */
  .side { view-transition-name: panel; }
  .time { view-transition-name: player; }
  .app-header { view-transition-name: header; }
  ::view-transition-old(root) { animation: none; opacity: 0; }
  ::view-transition-new(root) { animation: none; }
  ::view-transition-group(panel), ::view-transition-group(player), ::view-transition-group(header) { animation-duration: var(--motion-view); animation-timing-function: var(--motion-ease-in-out); }
  /* (pseudo-elements in lists of their own: :is() cannot hold them, and drops a rule that tries) */
  ::view-transition-old(panel), ::view-transition-new(panel), ::view-transition-old(player), ::view-transition-new(player),
  ::view-transition-old(header), ::view-transition-new(header) {
    animation-duration: var(--motion-view); animation-timing-function: var(--motion-ease-in-out);
  }
  /* The top bar crossfades on its paper (its brand and links the same either side, a voyage's line in or out); the
     panel, where it turns into itself (app.js: changeView), fades through its paper: the old out, then the new in, so
     their words never show through each other, and the chart never through the panel. */
  ::view-transition-group(header), :root[data-panel-turns]::view-transition-group(panel) { background: var(--paper); }
  /* a voyage's line goes with the bar, not over the chart; the clip would take the bar's neatline too, so the group
     draws it (style.css: .app-header) */
  ::view-transition-group(header) { overflow: clip; box-shadow: var(--neatline-bottom); }
  :root[data-panel-turns]::view-transition-old(panel) { animation: view-out calc(var(--motion-view) * 0.4) var(--motion-ease) both; }
  :root[data-panel-turns]::view-transition-new(panel) {
    animation: view-in calc(var(--motion-view) * 0.65) var(--motion-ease) calc(var(--motion-view) * 0.35) both;
  }

  /* On a desktop the list's panel lies over the chart's right side (style.css): it slides in over the chart from that
     edge, and back out to it (to its tab, app.js: setMode), as a voyage's card or the welcome fades in or out in its
     place, rather than turning into them. */
  @media (min-width: 1001px) and (orientation: landscape) and (hover: hover) and (pointer: fine) {
    body[data-mode="voyage"] .side { view-transition-name: card; }
    body.home .side { view-transition-name: welcome; }
    ::view-transition-new(panel):only-child { animation: panel-in var(--motion-view) var(--motion-ease) both; }
    ::view-transition-old(panel):only-child { animation: panel-out var(--motion-view) var(--motion-ease-in-out) both; }
    ::view-transition-group(card), ::view-transition-group(welcome) { animation-duration: var(--motion-view); animation-timing-function: var(--motion-ease-in-out); }
    /* the welcome and a voyage's card, which stand in different places, turn as the panel does: the old out, then the
       new in, so their words never show through each other */
    ::view-transition-old(card), ::view-transition-old(welcome) { animation: view-out calc(var(--motion-view) * 0.4) var(--motion-ease) both; }
    ::view-transition-new(card), ::view-transition-new(welcome) {
      animation: view-in calc(var(--motion-view) * 0.65) var(--motion-ease) calc(var(--motion-view) * 0.35) both;
    }
    /* the zoom buttons and the key move aside with it, and the key over the player and back */
    :is(.maplibregl-ctrl-top-right, .corner) { transition: right var(--motion-view) var(--motion-ease), bottom var(--motion-view) var(--motion-ease); }
  }
}
@keyframes panel-in { from { translate: calc(100% + 8px) 0; } }   /* its neatline too */
@keyframes panel-out { to { translate: calc(100% + 8px) 0; } }
@keyframes view-out { to { opacity: 0; } }
@keyframes view-in { from { opacity: 0; } }
