/* =====================================================================
   animations.css: the scroll animations. The script that switches them on is js/animations.js.

   HOW IT WORKS
   animations.js adds the class "anim" to <html> and marks elements with data-anim="...".
   An element marked with data-anim starts hidden/shifted (rules below). When it scrolls into
   view the script adds the class "is-in" and the element moves to its normal place. Without
   JavaScript, or when the visitor asked their device for reduced motion, the class "anim"
   is never added, so nothing below applies and everything is simply visible.

   TO CHANGE THE FEEL: edit the numbers in :root. Which elements get which animation, and WHEN
   (how much of the element must be on screen) is decided in js/animations.js (top of the file).

   Only opacity and transform are animated (cheap for the browser, no re-layout).
   ===================================================================== */

/* Sideways text, history entries and cards on a laptop travel in from the EDGE OF THE SCREEN:
   animations.js measures each element and sets --anim-from (how far it has to move to be off-screen).
   The sideways overhang is hidden by "body { overflow-x: clip }" (pages.css).
   On a phone or tablet this is NOT used: an element parked off the right edge makes the page wider
   than the screen and the phone browser zooms out. There animations.js switches the element to
   data-anim="rise" just before it plays. */
:root {
  --anim-image: 1.4s;        /* pictures fading in */
  --anim-fade: 1s;           /* text and cards fading in */
  --anim-move: 1.1s;         /* how long the sliding takes */
  --anim-small-move: 0.55s;  /* the small fade-up used for long lists of cards */
  --anim-distance: 56px;     /* sideways slide where "from the screen edge" is not used (swipe rows) */
  --anim-rise: 60px;         /* rise from the bottom */
  --anim-small: 10px;        /* the small fade-up */
  --anim-ease: cubic-bezier(0.16, 1, 0.3, 1);   /* fast start, long gentle stop */
}
@media (max-width: 799px) {
  :root { --anim-distance: 32px; --anim-rise: 36px; }
}

/* ---------- the hidden / shifted start positions ---------- */
html.anim [data-anim] { opacity: 0; }
html.anim [data-anim="text-left"]  { transform: translateX(var(--anim-from, calc(var(--anim-distance) * -1))); }
html.anim [data-anim="text-right"] { transform: translateX(var(--anim-from, var(--anim-distance))); }
html.anim [data-anim="from-right"] { transform: translateX(var(--anim-from, var(--anim-distance))); }
html.anim [data-anim="rise"]       { transform: translateY(var(--anim-rise)); }
html.anim [data-anim="fade-up"]    { transform: translateY(var(--anim-small)); }
/* data-anim="media" and "fade" only fade */

/* a browser that cannot hide the sideways overhang (iOS before 16): text rises instead of sliding */
@supports not (overflow-x: clip) {
  html.anim [data-anim="text-left"],
  html.anim [data-anim="text-right"] { transform: translateY(var(--anim-rise)); }
}

/* ---------- the end position and the transition (set on "is-in", so changing back never animates) ---------- */
html.anim [data-anim].is-in {
  opacity: 1;
  transform: none;
  transition: opacity var(--anim-fade) ease-out var(--anim-delay, 0s),
              transform var(--anim-move) var(--anim-ease) var(--anim-delay, 0s);
}
html.anim [data-anim="media"].is-in { transition-duration: var(--anim-image), var(--anim-image); }
html.anim [data-anim="fade-up"].is-in {
  transition-duration: var(--anim-small-move), var(--anim-small-move);
}

/* ---------- pass-rate rings and the line chart: they play when first seen ---------- */
/* the ring and its number start empty; animations.js fills them (--rate and the % text) */
html.anim .donut[data-rate]:not(.is-in) { --rate: 0 !important; }
html.anim .donut[data-rate]:not(.is-in) .donut-value { opacity: 0; }
/* the chart's lines, dots and labels are hidden until the rise starts; the grid and axis stay */
html.anim .line-chart:not(.is-in) .lc-line,
html.anim .line-chart:not(.is-in) .lc-dot,
html.anim .line-chart:not(.is-in) .lc-value,
html.anim .line-chart:not(.is-in) .lc-label { opacity: 0; }
