/* ═══════════════════════════════════════════════════════════════════════
   MOTION — the platform's micro-interactions, in one place.

   John, 8 Oct 2026, choosing option 2 of the micro-interactions board
   ("feedback and a few moments") and then "the speeds look right ... Make it
   slower for score arrives though". Every effect answers a question the
   person has just asked (did it take? did it save? where did it go? is it
   still working?). Nothing here decorates.

   THREE SPEEDS, for three jobs:
     instant    100-150 ms  feedback on your own click (a press, a chosen
                            answer). Under a tenth of a second it reads as the
                            screen simply doing it; slower feels like lag.
     seen       250-480 ms  something to notice changing: a tick drawn, a
                            score arriving. A stroke needs ~400 ms to read as
                            drawn rather than blinked.
     lingering  2 s +       a highlight showing where something went.

   THE EXAM ROOM gets instant feedback only, never over 300 ms and never on
   the path that saves an answer or runs the clock (player.css and
   question-render.css hold its two effects; tests/test_micro_interactions.py
   measures them).

   STILL FOR ANYONE WHO ASKS: every effect here has a reduced-motion version
   at the foot of this file, and the suite fails if one is added without it.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --motion-instant: 100ms;
  --motion-seen: 450ms;
  --motion-ease: cubic-bezier(.2, .7, .3, 1);
  --motion-line: var(--flag-gold);   /* a working line on any button */
}

/* ── A press you can feel ──────────────────────────────────────────────
   `scale`, not `transform`: it composes with any transform a button already
   has, so nothing positioned by a transform jumps when pressed. A browser
   too old for the property simply does not dip. */
button, a.btn, [role="button"] { transition: scale var(--motion-instant) var(--motion-ease); }
button:not(:disabled):active, a.btn:active, [role="button"]:active { scale: .97; }

/* ── A drawn tick ──────────────────────────────────────────────────────
   <svg class="tick-draw" viewBox="0 0 16 16"><path d="M3 8.5l3.2 3L13 4.5"/></svg>
   The same pen as the tutor list's "handed in" tick. */
.tick-draw { width: 1em; height: 1em; vertical-align: -0.12em; margin-right: 0.3em; flex: none; }
.tick-draw path {
  fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 20; stroke-dashoffset: 20;
  animation: motion-tick var(--motion-seen) var(--motion-ease) forwards;
}
@keyframes motion-tick { to { stroke-dashoffset: 0; } }

/* ── Still working: a line sweeps along the button ─────────────────────
   Only while something really is being made (a PDF, a backup). */
.is-working { position: relative; overflow: hidden; }
.is-working::after {
  content: ""; position: absolute; left: -40%; bottom: 0; width: 40%; height: 3px;
  background: var(--motion-line); border-radius: 2px; pointer-events: none;
  animation: motion-sweep 1200ms ease-in-out infinite;
}
@keyframes motion-sweep { to { left: 100%; } }

/* ── Handing in: a line runs while the paper is sent ───────────────────
   It grows to nine tenths over 700 ms and waits there for the server; the
   button turns to a tick only when the paper has really been taken. */
.is-sending { position: relative; overflow: hidden; }
.is-sending::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: 0;
  background: var(--motion-line); pointer-events: none;
  animation: motion-send 700ms var(--motion-ease) forwards;
}
.is-sending.is-sent::after { width: 100%; animation: none; }
@keyframes motion-send { to { width: 90%; } }

/* ── Arrivals ──────────────────────────────────────────────────────────
   The score rises into place, at the slower speed John asked for (480 ms);
   content rises in where its loading lines were (250 ms). */
.score-arrive { animation: motion-rise 480ms var(--motion-ease) both; }
.content-arrive { animation: motion-rise 250ms var(--motion-ease) both; }
@keyframes motion-rise { from { opacity: 0; transform: translateY(6px); } }

/* ── A result, revealed in order (row 363; John, 14 Oct 2026) ──────────
   The first time a family sees a result: the score first (its own 480 ms
   rise, above), then what it means, then the questions to look at, a beat
   apart. Group 2 starts at 250 ms and group 3 at 500 ms, each rising over
   300 ms, so the last line is still by 800 ms: under a second in all.
   Opacity and a 6px lift only: everything is in the page from the start,
   read by a screen reader and reachable by Tab while it rises, and nothing
   moves the layout. The class comes off once played (player.js
   startResultReveal), so a redraw never replays it; a revisit never gets it. */
.reveal-in-order [data-reveal] { animation: motion-rise 300ms var(--motion-ease) both; }
.reveal-in-order [data-reveal="2"] { animation-delay: 250ms; }
.reveal-in-order [data-reveal="3"] { animation-delay: 500ms; }

/* ── Confirmed in place (shared/confirm.js) ────────────────────────────
   "Copied ✓": the word, then the drawn tick after it, where the person
   clicked. The live region is read aloud and never seen. */
.tick-draw.tick-after { margin-right: 0; margin-left: 0.2em; }
/* ALREADY DRAWN: the same tick on a visit after the hand-in (the finished
   screen's stamp, teacher's-week rehearsal, 22 Oct 2026). The draw is for the
   moment it happens, once. */
.tick-draw.is-still path { animation: none; stroke-dashoffset: 0; }
.is-confirmed { white-space: nowrap; }
.confirm-live {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── Where it went: a sage wash that fades over 2.4 s ──────────────────
   A task just set, on the row it went to. */
.just-set { animation: motion-wash 2400ms var(--motion-ease); }
@keyframes motion-wash {
  0%   { background-color: var(--correct-bg); }
  58%  { background-color: var(--correct-bg); }
  100% { background-color: transparent; }
}

/* ── Asked in the page (shared/ask.js, row 473) ────────────────────────
   The dim fades in and the card rises a little and settles (180 ms); both
   fade out together when it closes. A row removed or cancelled folds away
   (220 ms) before the list is redrawn. */
.ask-back { animation: motion-fade 180ms var(--motion-ease) both; }
.ask-card { animation: motion-ask 180ms var(--motion-ease) both; }
.ask-back.is-leaving { animation: motion-fade-out 150ms var(--motion-ease) forwards; }
@keyframes motion-fade { from { opacity: 0; } }
@keyframes motion-fade-out { to { opacity: 0; } }
@keyframes motion-ask { from { opacity: 0; transform: translateY(10px) scale(.97); } }
.row-leaving {
  transition: max-height 220ms var(--motion-ease), opacity 180ms var(--motion-ease),
              padding 220ms var(--motion-ease), margin 220ms var(--motion-ease);
  max-height: 0 !important; opacity: 0; padding-top: 0; padding-bottom: 0;
  margin-top: 0; margin-bottom: 0;
}

/* ── Still, for anyone who asked for still ─────────────────────────────
   Everything lands in its end state at once. The working line stays, still,
   because "it is working" is information, not decoration. */
@media (prefers-reduced-motion: reduce) {
  button:not(:disabled):active, a.btn:active, [role="button"]:active { scale: none; }
  .tick-draw path { animation: none; stroke-dashoffset: 0; }
  .is-working::after { animation: none; left: 0; width: 100%; opacity: .55; }
  .is-sending::after { animation: none; width: 90%; }
  .score-arrive, .content-arrive, .just-set { animation: none; }
  .reveal-in-order [data-reveal] { animation: none; }
  .ask-back, .ask-card, .ask-back.is-leaving { animation: none; }
  .row-leaving { transition: none; }
}
