/* ================================================================
   How the portal moves. One file, one set of numbers.

   WHY THIS EXISTS
   ---------------
   Each room got its entrance animation written separately, and they
   drifted — measured in a browser rather than read off the page:

     Training Rooms   nothing at all
     Vocabulary       nothing at all
     AWA              300ms
     Quant            620ms
     Verbal           910ms
     Mocks hub        1930ms
     Question Index   1950ms,  on 6,034 elements

   Five different easing curves, and the slowest room took six times
   longer to settle than the quickest. A student moving from Quant to
   the mocks hub feels that as the mocks page being slow, not as the
   mocks page being graceful.

   So the numbers live here now, once. The room files keep their own
   keyframes — those are the choreography, and each room's is its own
   — but the DURATION, the DELAY and the CURVE come from here.

   WHY AS AN OVERRIDE RATHER THAN AN EDIT
   --------------------------------------
   The mocks hub and the Question Index are generated by the mock
   pipeline. Editing their timings in place would work until the next
   time either is regenerated, and then it would silently be gone.
   Re-timing them from a file the build step injects means a freshly
   generated page arrives already in step, with nobody having to
   remember anything.

   This file is linked at the TOP of each room's head, before the
   room's own <style>, so on a tie the room wins. The :root prefix
   below buys one notch of specificity, which is enough against a bare
   `.card` but not against a room's `.mod-grid .mod` — and measuring
   showed exactly that happening, with two rooms keeping their own
   curve. So the three timing properties are marked !important as
   well. That is not a shortcut here: being the last word on duration,
   delay and easing is the entire job of this file. Nothing else in it
   is !important, and no colour, size or position is touched.
   ================================================================ */

:root {
  /* The one curve. A plain decelerate: quick off the mark, settling
     rather than stopping. Close to what Quant and Verbal already had,
     so those two barely change. */
  --ga-ease: cubic-bezier(.2, .8, .3, 1);

  /* Softer, for something leaving rather than arriving. */
  --ga-ease-out: cubic-bezier(.4, 0, .6, 1);

  /* How long one thing takes to arrive. */
  --ga-dur: 420ms;
  --ga-dur-lg: 560ms;     /* a hero image or a whole panel */
  --ga-dur-sm: 260ms;     /* something small, or something leaving */

  /* The gap between one item and the next in a staggered row. Six of
     these still lands inside the settle budget. */
  --ga-step: 60ms;

  /* How far something travels on its way in. Far enough to read as
     movement, near enough not to look like it fell. */
  --ga-rise: 14px;

  /* The whole first screen should be finished by about here. If you
     want the portal slower or quicker everywhere, change --ga-dur and
     --ga-step and nothing else: every room follows. */
}

/* ---------------- the two shapes everything uses ---------------- */

@keyframes ga-rise { from { opacity: 0; transform: translateY(var(--ga-rise)); }
                     to   { opacity: 1; transform: none; } }
@keyframes ga-fade { from { opacity: 0; } to { opacity: 1; } }

/* Every entrance below fills BACKWARDS, never `both`, and that one
   word matters more than it looks.

   A filled-forwards animation keeps its last frame applied for the
   life of the page, and a filled value beats an ordinary declaration —
   so `transform: none` from the final frame quietly outranked every
   :hover and :active transform on the element. The room cards on the
   hub had stopped lifting under the cursor entirely; the rule was
   there, the animation was simply louder.

   `backwards` holds the FROM state through the delay, which is all
   that was ever wanted — the card must not flash before its turn —
   and then lets go. Both shapes end exactly where the element sits
   naturally (opacity 1, no transform), so nothing moves at the
   handover and the page looks identical. */

/* Put `ga-in` on something and it arrives. Give it --i to put it in a
   queue: the third card in a row is style="--i:3". */
@media (prefers-reduced-motion: no-preference) {
  .ga-in      { animation: ga-rise var(--ga-dur) var(--ga-ease) backwards;
                animation-delay: calc(var(--i, 0) * var(--ga-step)); }
  .ga-in-fade { animation: ga-fade var(--ga-dur) var(--ga-ease) backwards;
                animation-delay: calc(var(--i, 0) * var(--ga-step)); }
}

/* ================================================================
   The portal's own pages — the Training Rooms hub, the runbooks, the
   Roster, Progress, Profile, the Notebook, Devices, Results, sign-in.

   They all share one shape: a `.wrap` holding a title, the batch chip,
   the diamond rule, and then that page's own blocks. So the entrance
   is stated once here, against that shape, and every page gets it
   without a line of markup changing — which is also why a new page
   added later arrives already matching.

   `body.pg` is the scope. The rooms are somebody else's HTML and some
   of them have a `.wrap` and an `h1` of their own; without a marker
   that only the portal's pages carry, the rules below would reach in
   and re-time parts of the Question Index by accident. Once was
   enough of that.
   ================================================================ */
@media (prefers-reduced-motion: no-preference) {

  /* The page's own furniture, in reading order. Naming the blocks
     rather than saying `> *` keeps this away from two things that
     must not animate: a slide-over sheet, which has a transition of
     its own, and the message strip, which appears in response to
     something the reader just did and should not float in. */
  body.pg .wrap > h1,
  body.pg .wrap > .seg,
  body.pg .wrap > .diamond,
  body.pg .wrap > .mark,
  body.pg .wrap > .hero,
  body.pg .wrap > .panel,
  body.pg .wrap > .toolbar,
  body.pg .wrap > .filters,
  body.pg .wrap > .stat,
  body.pg .wrap > .updates,
  body.pg .wrap > .rbpick,
  body.pg .wrap > .grid,
  body.pg .wrap > .rgroups,
  body.pg .wrap > #body,
  body.pg .wrap > #reader,
  body.pg .wrap > #mine,
  body.pg .wrap > #arc,
  body.pg .wrap > #runbook,
  body.pg .wrap > #tasks,
  body.pg .wrap > .hint {
    animation: ga-rise var(--ga-dur) var(--ga-ease) backwards;
    animation-delay: calc(var(--i, 0) * var(--ga-step));
  }

  /* Its place in the queue, taken from where it sits on the page, so
     nothing has to be numbered by hand. Capped at the seventh: past
     that a reader is waiting rather than watching. */
  body.pg .wrap > *:nth-child(1) { --i: 0 }
  body.pg .wrap > *:nth-child(2) { --i: 1 }
  body.pg .wrap > *:nth-child(3) { --i: 2 }
  body.pg .wrap > *:nth-child(4) { --i: 3 }
  body.pg .wrap > *:nth-child(5) { --i: 4 }
  body.pg .wrap > *:nth-child(6) { --i: 5 }
  body.pg .wrap > *:nth-child(7) { --i: 6 }
  body.pg .wrap > *:nth-child(n+8) { --i: 7 }

  /* Two grids are drawn once and never redrawn, so their tiles can
     arrive one after another: the five room cards on the hub, and the
     figures across the top of the Roster and the Results page.

     Nothing else is staggered per item on purpose. A roster of 115
     students, a notebook of saved questions and the Results table all
     redraw on every keystroke in their filter box; an entrance
     animation on those rows would flash the whole list each time a
     letter is typed. Lists get their container's entrance and nothing
     more. */
  /* The hub's rooms sit in one grid per course (GRE, IBA) since Oct
     2026; each grid's cards arrive in the same queue. */
  body.pg .wrap > .grid > *,
  body.pg .wrap > .rgroups .grid > *,
  body.pg .wrap > .hero > * {
    animation: ga-rise var(--ga-dur) var(--ga-ease) backwards;
  }
  body.pg .wrap > .grid > *:nth-child(1),
  body.pg .wrap > .rgroups .grid > *:nth-child(1),
  body.pg .wrap > .hero > *:nth-child(1) { animation-delay: 180ms }
  body.pg .wrap > .grid > *:nth-child(2),
  body.pg .wrap > .rgroups .grid > *:nth-child(2),
  body.pg .wrap > .hero > *:nth-child(2) { animation-delay: 240ms }
  body.pg .wrap > .grid > *:nth-child(3),
  body.pg .wrap > .rgroups .grid > *:nth-child(3),
  body.pg .wrap > .hero > *:nth-child(3) { animation-delay: 300ms }
  body.pg .wrap > .grid > *:nth-child(4),
  body.pg .wrap > .rgroups .grid > *:nth-child(4),
  body.pg .wrap > .hero > *:nth-child(4) { animation-delay: 360ms }
  body.pg .wrap > .grid > *:nth-child(n+5),
  body.pg .wrap > .rgroups .grid > *:nth-child(n+5),
  body.pg .wrap > .hero > *:nth-child(n+5) { animation-delay: 420ms }

  /* The top bar is the one piece that is on every page and in the
     same place on every page. It fades rather than rises: a bar that
     slides on each navigation reads as the page being rebuilt. */
  body.pg > .bar { animation: ga-fade var(--ga-dur-sm) var(--ga-ease) backwards }
}

/* Everything below applies only when the reader has not asked for
   less movement. It has to be said here rather than left to the block
   at the foot of the file: these rules are !important and more
   specific than a `*` selector, so without this wrapper they would
   quietly win against the very thing meant to switch them off. */
@media (prefers-reduced-motion: no-preference) {

/* ================================================================
   Bringing the rooms into step.

   Only the timing is touched. Every keyframe below was written in the
   room itself and still does exactly what it did — it just takes the
   same length of time as everything else in the portal now.
   ================================================================ */

/* ---- the mocks hub: the biggest change ----
   It was written to arrive unhurried, with the hero assembling over
   the best part of two seconds. Read once that is lovely; read every
   day on the way to a mock it is a wait. The sequence is kept — logo,
   then title, then strapline, then rule, then the cards — at the
   portal's tempo instead of its own. */
:root .hero-logo  { animation-duration: var(--ga-dur-lg) !important; animation-delay: 40ms !important}
:root .hero-title { animation-duration: var(--ga-dur) !important;    animation-delay: 120ms !important}
:root .hero-seg   { animation-duration: var(--ga-dur) !important;    animation-delay: 180ms !important}
:root .rule       { animation-duration: var(--ga-dur-lg) !important; animation-delay: 240ms !important}
:root .hero-stats > div { animation-duration: var(--ga-dur) !important}
/* these two were hand-delayed to .64s and .76s in the room; they are
   part of the same queue as everything above and follow it */
:root .hero-stats > div:nth-child(1) { animation-delay: 260ms !important}
:root .hero-stats > div:nth-child(2) { animation-delay: 320ms !important}
:root .hero-stats > div:nth-child(3) { animation-delay: 380ms !important}
:root .toolbar    { animation-duration: var(--ga-dur) !important;    animation-delay: 300ms !important}
:root .prog       { animation-duration: var(--ga-dur) !important;    animation-delay: 360ms !important}
:root .card.in    { animation-duration: var(--ga-dur) !important}
:root .card.out   { animation-duration: var(--ga-dur-sm) !important}
:root .card.bloom::after { animation-duration: var(--ga-dur-lg) !important}
:root .empty.show { animation-duration: var(--ga-dur) !important}
:root .rip        { animation-duration: var(--ga-dur-lg) !important}
:root .tick.pop   { animation-duration: var(--ga-dur-sm) !important}

/* ---- the Question Index: same hero, plus one real problem ----
   The page carries 3,510 questions, and `.rows > .row` put an
   animation on every one of them — 6,034 animated elements, 128,000
   in the document, 2.4 seconds to load on a throttled phone. Rows
   nobody has scrolled to yet do not need to arrive; only the first
   handful in a section is ever seen arriving. */
:root .hlogo   { animation-duration: var(--ga-dur-lg) !important; animation-delay: 60ms !important}
:root .topbar  { animation-duration: var(--ga-dur) !important;    animation-delay: 0ms !important}
/* The Index's own title and strapline are a bare h1 and .seg. Naming
   them here is safe: a duration only does anything to an element that
   is already animating, and nothing else in the portal animates
   either of them. */
:root h1, :root .seg { animation-duration: var(--ga-dur) !important}
:root h1   { animation-delay: 120ms !important}
:root .seg { animation-delay: 180ms !important}

:root .hstats > div { animation-duration: var(--ga-dur) !important}
:root .hstats > div:nth-child(1) { animation-delay: 260ms !important}
:root .hstats > div:nth-child(2) { animation-delay: 320ms !important}
:root .hstats > div:nth-child(3) { animation-delay: 380ms !important}
:root .ovcard:nth-of-type(1)     { animation-delay: 300ms !important}
:root .ovcard:nth-of-type(2)     { animation-delay: 360ms !important}
:root .ovcard:nth-of-type(n+3)   { animation-delay: 420ms !important}
:root .ovcard  { animation-duration: var(--ga-dur) !important}
:root .tb      { animation-duration: var(--ga-dur) !important;    animation-delay: 300ms !important}
:root .pane    { animation-duration: var(--ga-dur) !important}
:root .chipwrap{ animation-duration: var(--ga-dur) !important}
:root .ansrow  { animation-duration: var(--ga-dur-sm) !important}
:root .sec.closing .rows { animation-duration: var(--ga-dur-sm) !important}

:root .rows > .row { animation-duration: var(--ga-dur) !important}
/* past the first dozen in a section, the row simply is there */
:root .rows > .row:nth-child(n + 13) { animation: none !important }

/* The 3,010 answer rows are the real weight on this page. Every one
   of them sits inside a question that is collapsed until somebody
   opens it, and every one of them was carrying an animation from the
   moment the page loaded. They arrive when their question is opened
   and not before — which is the only time anyone sees them anyway. */
:root .ansrow { animation: none !important }
:root .open .ansrow,
:root .row.open .ansrow {
  animation: ansIn var(--ga-dur-sm) var(--ga-ease) backwards;
}

/* ---- Verbal ---- */
:root #page.anim > *:not(.exam),
:root #page.anim .hub,
:root #page.anim .passage,
:root #page.anim .block { animation-duration: var(--ga-dur) !important}
:root #page.anim .hcard { animation-duration: var(--ga-dur-lg) !important}
:root #page.anim .q     { animation-duration: var(--ga-dur) !important}
:root .q .result, :root .q .expl { animation-duration: var(--ga-dur) !important}
:root body.tcsemode #tcseFrame,
:root body.mocksmode #mocksFrame { animation-duration: var(--ga-dur) !important}

/* ---- AWA ---- */
:root .panel.on        { animation-duration: var(--ga-dur) !important}
:root .card.done .markbtn { animation-duration: var(--ga-dur-sm) !important}

/* ---- Quant ----
   Found by asking the browser which elements were actually animating,
   not by reading the stylesheet: the screen itself carries `scIn`, the
   module tiles carry `riseIn`, and a modal carries `modalIn`. */
:root .screen.on { animation-duration: var(--ga-dur) !important}
:root .mod       { animation-duration: var(--ga-dur) !important}
:root .modal     { animation-duration: var(--ga-dur-sm) !important}

/* One curve for every room, whatever each of them asked for. The
   blink on a running timer is deliberately excluded: it is a warning,
   not decoration, and it is supposed to be abrupt. */
:root [class] { }
:root .hero-logo, :root .hero-title, :root .hero-seg, :root .rule,
:root .hero-stats > div, :root .toolbar, :root .prog, :root .card.in,
:root .card.out, :root .empty.show, :root .rip, :root .tick.pop,
:root .hlogo, :root .topbar, :root .hstats > div, :root .ovcard,
:root .tb, :root .pane, :root .chipwrap, :root .ansrow,
:root .rows > .row, :root .sec.closing .rows,
:root #page.anim > *:not(.exam), :root #page.anim .hub,
:root #page.anim .hcard, :root #page.anim .q,
:root #page.anim .passage, :root #page.anim .block,
:root .q .result, :root .q .expl,
:root .panel.on, :root .card.done .markbtn,
:root .screen.on, :root .mod, :root .modal,
:root h1, :root .seg,
:root #fb > * { animation-timing-function: var(--ga-ease) !important}

/* ---- Vocabulary had no entrance at all ----
   Its own `fbin` only fires on a quiz answer, so the room simply
   appeared. The header and whatever view is on screen now arrive the
   way every other room's does. The word list itself is left alone —
   it can run to thousands of rows, and the Question Index above is
   the cautionary tale. */
:root .hdr        { animation: ga-fade var(--ga-dur) var(--ga-ease) backwards }
:root .backlink   { animation: ga-rise var(--ga-dur) var(--ga-ease) backwards;
                    animation-delay: 60ms !important}
:root main > .wrap > .section:nth-of-type(-n + 6),
:root .wrap > .setgrid,
:root .wrap > .cardbox { animation: ga-rise var(--ga-dur) var(--ga-ease) backwards;
                         animation-delay: 120ms !important}
:root #fb > *     { animation-duration: var(--ga-dur-sm) !important}

}

/* ================================================================
   Reduce motion.

   Four rooms each had their own idea of what this meant, including
   one that shortened animations to .001ms rather than removing them.
   Quant's own source carries the warning about that: an animation
   with a `backwards` fill and a near-zero duration can leave the
   from-state on screen, and a student who asked for less movement
   gets a blank page instead.

   So: off. Not shortened — off, with the finished state showing. This
   file is injected into every room, so this block is the one that has
   the last word wherever a room's own is weaker.
   ================================================================ */
@media (prefers-reduced-motion: reduce) {
  :root *, :root *::before, :root *::after {
    animation-duration: 0s !important!important;
    animation-delay: 0s !important!important;
    animation-iteration-count: 1 !important;
    transition-duration: 0s !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  /* A `both`/`backwards` fill with a zero duration still holds the
     to-state, which is the readable one — but a couple of rooms hide
     with opacity rather than animating it, so say it outright. */
  :root .ga-in, :root .ga-in-fade { opacity: 1; transform: none }
}

@media print {
  :root *, :root *::before, :root *::after {
    animation: none !important; transition: none !important;
  }
}

