/* =====================================================================
   motion.css  —  ANIMATION (the 10 principles of animation)
   ---------------------------------------------------------------------
   To switch ALL motion off: delete the <link ... motion.css> line and the
   <script ... motion.js> line in index.html. The game still works.

   Everything is inside "prefers-reduced-motion: no-preference", so people
   who turned on "reduce motion" on their phone/PC see no animation.

   Where each principle lives (search for the number):
     01 Squash & stretch      06 Slow in, slow out
     02 Anticipation          07 Moving in arcs
     03 Staging the focus     08 Secondary action
     04 Pose to pose          09 Snappy timing
     05 Follow through        10 Exaggerated feedback
   ===================================================================== */

@media (prefers-reduced-motion: no-preference) {

  :root {
    /* 06 SLOW IN, SLOW OUT: every move eases at both ends, never linear.
       (The only linear thing is the scrolling grid, a constant ticker.) */
    --ease-inout: cubic-bezier(0.65, 0, 0.35, 1);
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    /* overshoots the target then settles back: used for follow through */
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* 09 SNAPPY TIMING: UI feedback is quick, big moments are still < 0.8s */
    --t-snap: 140ms;
    --t-med: 260ms;
  }

  /* ---------------------------------------------------------------
     01 SQUASH & STRETCH — buttons squash when pressed, then spring back
     with a little stretch (the release overshoots).
     --------------------------------------------------------------- */
  .pill-btn, .round-btn, .chip-btn, .option-btn, .icon-btn,
  .footer-links a, .link-btn-dot, .nav-pills a {
    transition: transform var(--t-med) var(--ease-spring),
                background var(--t-snap) var(--ease-inout),
                border-color var(--t-snap) var(--ease-inout),
                color var(--t-snap) var(--ease-inout);
  }
  .pill-btn:hover, .round-btn:hover, .chip-btn:hover:not(:disabled),
  .option-btn:hover:not(:disabled), .icon-btn:hover { transform: translateY(-2px); }
  .pill-btn:active, .round-btn:active, .chip-btn:active:not(:disabled),
  .option-btn:active:not(:disabled), .icon-btn:active {
    transform: scale(1.07, 0.88);               /* squash: wider and flatter */
    transition-duration: 70ms;                  /* the squash itself is instant */
  }

  /* ---------------------------------------------------------------
     02 ANTICIPATION — wind up before the action.
     The Check arrow pulls back, then shoots forward.
     --------------------------------------------------------------- */
  .round-btn svg { transition: transform var(--t-med) var(--ease-spring); }
  .round-btn:active svg { transform: translateX(-5px); }          /* wind-up */
  .round-btn.is-go svg { animation: arrow-go 380ms var(--ease-inout); }
  @keyframes arrow-go {
    0%   { transform: translateX(-6px); }
    45%  { transform: translateX(16px); opacity: 0; }   /* shoots off */
    46%  { transform: translateX(-16px); opacity: 0; }  /* re-enters */
    100% { transform: translateX(0); opacity: 1; }
  }
  /* the whole answer card ducks slightly just before the success pop */
  .rcard-main.is-winding { animation: wind-up 160ms var(--ease-inout) forwards; }
  @keyframes wind-up { to { transform: scale(0.975) translateY(3px); } }

  /* ---------------------------------------------------------------
     03 STAGING THE FOCUS — on a correct answer the rest of the page
     dims so the eye goes to the result.
     --------------------------------------------------------------- */
  .stage-scrim {
    position: fixed; inset: 0;
    z-index: 55;
    pointer-events: none;
    background: radial-gradient(70% 60% at 50% 40%, rgba(5,5,6,0.35), rgba(5,5,6,0.82));
    opacity: 0;
    transition: opacity var(--t-med) var(--ease-inout);
  }
  .stage-scrim.is-on { opacity: 1; }
  html.is-staging .rcard-main,
  html.is-staging #success { position: relative; z-index: 60; }
  /* the card you are answering glows brighter while you type */
  .rcard-main { transition: box-shadow var(--t-med) var(--ease-inout), border-color var(--t-med) var(--ease-inout); }
  .rcard-main:focus-within {
    border-color: rgba(167, 209, 140, 0.55);
    box-shadow: 0 30px 90px -26px rgba(127, 174, 99, 0.6);
  }

  /* ---------------------------------------------------------------
     04 POSE TO POSE — the success card is built from key poses:
     hidden → overshoot → dip → rest.
     --------------------------------------------------------------- */
  .success-card:not([hidden]) { animation: pose-pop 720ms var(--ease-inout) backwards; }
  @keyframes pose-pop {
    0%   { opacity: 0; transform: translateY(44px) scale(0.9) rotate(-1.2deg); }  /* pose 1 */
    55%  { opacity: 1; transform: translateY(-10px) scale(1.035) rotate(0.5deg); } /* pose 2: overshoot */
    78%  { transform: translateY(3px) scale(0.994) rotate(0deg); }                 /* pose 3: dip */
    100% { transform: none; }                                                      /* rest */
  }
  /* the page itself arrives in poses: hero lines, then the three cards */
  .hero .chip-soft, .hero-title, .hero-sub { animation: rise 640ms var(--ease-out) backwards; }
  .hero-title { animation-delay: 80ms; }
  .hero-sub { animation-delay: 170ms; }
  @keyframes rise { from { opacity: 0; transform: translateY(22px); } }
  .rcard-main { animation: card-up 640ms var(--ease-out) 120ms backwards; }
  .rcard-prev { animation: card-left 640ms var(--ease-out) 260ms backwards; }
  .rcard-next { animation: card-right 640ms var(--ease-out) 260ms backwards; }
  @keyframes card-up { from { opacity: 0; transform: translateY(40px) scale(0.96); } }
  @keyframes card-left { from { opacity: 0; transform: translateX(-36px); } }
  @keyframes card-right { from { opacity: 0; transform: translateX(36px); } }

  /* ---------------------------------------------------------------
     05 FOLLOW THROUGH — things keep moving after the main action stops.
     The success card's contents settle one after another, a beat late,
     and overshoot before resting.
     --------------------------------------------------------------- */
  .success-card:not([hidden]) > * { animation: settle 560ms var(--ease-spring) backwards; }
  .success-card:not([hidden]) > :nth-child(1) { animation-delay: 380ms; }
  .success-card:not([hidden]) > :nth-child(2) { animation-delay: 450ms; }
  .success-card:not([hidden]) > :nth-child(3) { animation-delay: 520ms; }
  .success-card:not([hidden]) > :nth-child(4) { animation-delay: 590ms; }
  .success-card:not([hidden]) > :nth-child(5) { animation-delay: 660ms; }
  @keyframes settle { from { opacity: 0; transform: translateY(16px) scale(0.95); } }
  /* leaderboard rows rise in a staggered line when scrolled into view */
  .reveal.is-in .leaderboard-list li { animation: settle 520ms var(--ease-spring) backwards; }
  .reveal.is-in .leaderboard-list li:nth-child(2) { animation-delay: 70ms; }
  .reveal.is-in .leaderboard-list li:nth-child(3) { animation-delay: 140ms; }
  .reveal.is-in .leaderboard-list li:nth-child(4) { animation-delay: 210ms; }
  .reveal.is-in .leaderboard-list li:nth-child(5) { animation-delay: 280ms; }

  /* scroll reveal: sections ease up as they come into view */
  html.reveal-ready .reveal { opacity: 0; transform: translateY(34px); }
  html.reveal-ready .reveal.is-in {
    opacity: 1; transform: none;
    transition: opacity 600ms var(--ease-out), transform 700ms var(--ease-out);
  }

  /* ---------------------------------------------------------------
     07 MOVING IN ARCS — nothing moves in a straight line.
     The emoji swings like a pendulum (an arc), the sparkles drift on
     curved paths, and confetti (motion.js) flies in parabolas.
     --------------------------------------------------------------- */
  .avatar-main {
    transform-origin: 50% 230%;          /* far below = it swings along an arc */
    animation: swing-arc 5s var(--ease-inout) infinite alternate;
  }
  @keyframes swing-arc { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
  .sparkle { animation: twinkle 4s var(--ease-inout) infinite, drift-arc 9s var(--ease-inout) infinite alternate; }
  .s1 { transform-origin: 40px 90px; }
  .s2 { transform-origin: -50px 60px; animation-duration: 4s, 11s; }
  .s3 { transform-origin: 60px -40px; animation-duration: 4s, 8s; }
  .s4 { transform-origin: -30px -70px; animation-duration: 4s, 12s; }
  @keyframes drift-arc { from { rotate: -18deg; } to { rotate: 18deg; } }

  /* ---------------------------------------------------------------
     08 SECONDARY ACTION — small supporting motion that adds life
     without stealing focus: the stopwatch icon ticks, the streak flame
     flickers, tiles jiggle their emoji on hover.
     --------------------------------------------------------------- */
  .timer-icon { display: inline-block; transform-origin: 50% 20%; animation: tick-swing 1s var(--ease-inout) infinite alternate; }
  @keyframes tick-swing { from { transform: rotate(-14deg); } to { transform: rotate(14deg); } }
  .timer.is-done .timer-icon, .timer.is-over .timer-icon { animation: none; }
  .flame { display: inline-block; transform-origin: 50% 90%; animation: flicker 1.3s var(--ease-inout) infinite alternate; }
  @keyframes flicker {
    0%   { transform: scale(1, 1) rotate(-3deg); }
    50%  { transform: scale(0.94, 1.1) rotate(2deg); }
    100% { transform: scale(1.04, 0.96) rotate(-1deg); }
  }
  .tile:not(.tile-post) { transition: transform var(--t-med) var(--ease-spring); }
  .tile:not(.tile-post):hover { transform: translateY(-4px); }
  .tile:not(.tile-post):hover .tile-emoji { animation: jiggle 480ms var(--ease-inout); }
  @keyframes jiggle { 25% { transform: rotate(-14deg) scale(1.15); } 60% { transform: rotate(10deg) scale(1.1); } }
  .hint-text:not([hidden]) { animation: settle 360ms var(--ease-spring) backwards; }
  .feedback:not(:empty) { animation: settle 300ms var(--ease-spring) backwards; }

  /* the "+10" that floats up out of the card (created by motion.js) */
  .fx-points {
    position: fixed; z-index: 70;
    pointer-events: none;
    font-family: var(--font-serif); font-style: italic;
    font-size: 3.4rem; line-height: 1;
    color: var(--success);
    text-shadow: 0 6px 30px rgba(127, 174, 99, 0.7);
  }

  /* ---------------------------------------------------------------
     10 EXAGGERATED FEEDBACK — wrong and right answers are unmistakable.
     --------------------------------------------------------------- */
  /* wrong: a hard shake (replaces the soft one in style.css), a red
     flash, and the whole card jolts */
  .pill-input:has(.shake) { animation: shake-hard 520ms var(--ease-inout) both; }
  @keyframes shake-hard {
    0%   { transform: translateX(7px); }            /* 02: tiny wind-up the other way */
    12%  { transform: translateX(-16px) rotate(-1deg); }
    28%  { transform: translateX(15px) rotate(0.8deg); }
    44%  { transform: translateX(-11px); }
    60%  { transform: translateX(8px); }
    78%  { transform: translateX(-4px); }
    100% { transform: none; }
  }
  .rcard-main.fx-wrong { animation: jolt 420ms var(--ease-inout); }
  @keyframes jolt {
    0%   { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.0); }
    25%  { transform: translateX(-6px) rotate(-0.6deg); box-shadow: 0 0 60px 6px rgba(255, 107, 107, 0.55); border-color: var(--danger); }
    55%  { transform: translateX(5px) rotate(0.5deg); }
    100% { transform: none; box-shadow: 0 0 0 0 rgba(255, 107, 107, 0); }
  }
  .feedback.is-wrong:not(:empty) { animation: pop-wrong 420ms var(--ease-spring) backwards; }
  @keyframes pop-wrong { from { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.18); } }

  /* right: big pops on the score chips, a jumping emoji with squash on
     landing, a flare on the flame */
  .bump { animation: bump 620ms var(--ease-spring); }
  @keyframes bump {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.7) rotate(-4deg); }
    60%  { transform: scale(0.9) rotate(2deg); }
    100% { transform: scale(1); }
  }
  .chip:has(.bump) { border-color: var(--success); }
  .avatar-main.is-jump { animation: swing-arc 5s var(--ease-inout) infinite alternate, jump 900ms var(--ease-inout); }
  @keyframes jump {
    0%   { translate: 0 0;     scale: 1 1; rotate: 0deg; }
    14%  { translate: 0 4px;   scale: 1.18 0.78; }               /* 02 crouch (anticipation) */
    40%  { translate: 0 -46px; scale: 0.86 1.2; rotate: -12deg; } /* 01 stretch in the air */
    68%  { translate: 0 0;     scale: 1.25 0.74; rotate: 9deg; }  /* 01 squash on landing */
    82%  { translate: 0 -8px;  scale: 0.95 1.06; rotate: -4deg; } /* 05 follow-through bounce */
    100% { translate: 0 0;     scale: 1 1; rotate: 0deg; }
  }
  .success-title { transform-origin: 0 50%; }
  .success-card:not([hidden]) .success-title { animation: settle 560ms var(--ease-spring) 380ms backwards, glow-pulse 1.4s var(--ease-inout) 900ms 2; }
  @keyframes glow-pulse { 50% { text-shadow: 0 0 26px rgba(155, 224, 122, 0.8); } }

  /* the clock panics in the last 10 seconds (heartbeat) and flashes when
     time runs out */
  .timer.is-panic { animation: heartbeat 520ms var(--ease-inout) infinite; border-color: var(--danger); color: var(--danger); }
  @keyframes heartbeat {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 107, 107, 0); }
    35%      { transform: scale(1.18); box-shadow: 0 0 22px 2px rgba(255, 107, 107, 0.6); }
    60%      { transform: scale(0.97); }
  }
  .timer.is-over { animation: over-flash 700ms var(--ease-inout); }
  @keyframes over-flash {
    0%, 40% { transform: scale(1.3); background: rgba(255, 107, 107, 0.35); }
    100%    { transform: scale(1); }
  }

  /* gentle press feedback for the signup arrow */
  .link-btn:active .link-btn-dot { transform: scale(0.85); }
}
