/* The app's small motions, in one place (loaded after every other sheet, so its rules win the ties):
   what she touches answers her touch, what's new arrives instead of appearing, and every wait moves.

   Three rules hold everything here:
   - Fast and small. Presses are instant, arrivals take --dur-slow at most, nothing bounces.
   - Cheap on a phone. Only opacity, scale, translate and rotate move (the GPU does those without
     laying the page out again); never a shadow, a blur or a size.
   - A wait is never still. A greyed-out button or a line of words that doesn't move reads as
     "stuck", so everything she waits on moves, even when she asked for less motion: then it breathes
     (its opacity rises and falls) instead of turning or sliding. Less motion means nothing travels
     across the screen, not that the app looks frozen.

   "Less motion" is either her phone's setting (prefers-reduced-motion, which also sets the --dur
   tokens to 0s in tokens.css) or Settings > Appearance (app.js puts .reduce-motion on <html>). */

/* ============================================================== the shapes every motion uses */

@keyframes mo-arrive { from { opacity: 0; translate: 0 8px; } }
@keyframes mo-fade { from { opacity: 0; } }
@keyframes mo-pop { from { opacity: 0; scale: 0.96; } }
@keyframes wait-spin { to { rotate: 360deg; } }
@keyframes wait-breathe { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
/* a light running along a line, left to right, again and again (the gradient is 40% of the line) */
@keyframes wait-run { from { background-position: -70% 0; } to { background-position: 170% 0; } }

/* ============================================================== a touch answers */

/* A button gives a little under her finger, and comes back when she lets go. The press is instant
   (feedback has to be), the way back eases. :where() keeps this at no weight, so a button with a
   transition of its own keeps it. */
:where(button, .scene-card, [role="button"]) { transition: scale var(--dur-fast) var(--ease); }
:is(button, .scene-card, [role="button"]):not(:disabled, .today-go, #welcome .starters button):active { scale: 0.96; transition-duration: 0s; }
/* (wide things give less, or a long row would look like it's folding; the greeting's starters and
   Today's buttons give already, canvas.css) */
:is(.chat-item .open, .lesson-item .open, .scene-card, .turn-option):not(:disabled):active { scale: 0.985; }

/* The send button wakes up when there's something to send */
#send:not(:disabled) svg { transition: translate var(--dur) var(--ease); }
#send:not(:disabled):hover svg { translate: 0 -1px; }

/* With a mouse, what she can open lifts a pixel toward her */
@media (hover: hover) {
  :where(.scene-card, .starters button) { transition: scale var(--dur-fast) var(--ease), translate var(--dur) var(--ease); }
  :is(.scene-card:not(.building), .starters button):hover { translate: 0 -2px; }
}

/* ============================================================== what's new arrives */

/* A message in the conversation glides up into place as it comes (app.js marks a live one .is-new;
   a saved chat's messages are drawn at once, all of them already there). Hers grows from her side. */
#log .msg.is-new:not(.pending) { animation: mo-arrive var(--dur-slow) var(--ease) both; }
#log .msg.user.is-new { transform-origin: bottom right; animation-name: mo-pop; }
/* ("Thinking…" keeps its own shimmer: it moves already) */

/* A chat's new name, written by the quick model after its first answer, fades in where the old one
   was (in the list and over the chat), the way Claude and ChatGPT show theirs */
:is(.chat-item .title, #chat-title).retitled { animation: mo-fade var(--dur-slow) var(--ease) both; }

/* The greeting: its parts come in one after another, top to bottom, quickly */
#welcome:not([hidden]) .empty > * { animation: mo-arrive var(--dur-slow) var(--ease) both; }
#welcome .empty > :nth-child(2) { animation-delay: 40ms; }
#welcome .empty > :nth-child(3) { animation-delay: 80ms; }
#welcome .empty > :nth-child(n + 4) { animation-delay: 120ms; }
#welcome .starters > button { animation: mo-pop var(--dur-slow) var(--ease) both; }
#welcome .starters > button:nth-child(2) { animation-delay: 180ms; }
#welcome .starters > button:nth-child(3) { animation-delay: 220ms; }
#welcome .starters > button:nth-child(n + 4) { animation-delay: 260ms; }


/* ============================================================== every wait moves */

/* A button waiting on the server (web/waiting.ts sets aria-busy): a small ring turns beside its words */
button[aria-busy="true"] { cursor: progress; }
button[aria-busy="true"]::after {
  content: ""; display: inline-block; flex: none; width: 12px; height: 12px; margin-left: 8px; vertical-align: -2px;
  box-sizing: border-box; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: wait-spin 0.8s linear infinite;
}

/* A chat she tapped in the list, while it comes: a light runs along the bottom of its row */
.chat-item[aria-busy="true"] { cursor: progress; }
.chat-item[aria-busy="true"]::after,
.scene-card.building::after,
.wait-bar::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; border-radius: var(--ui-r-full); pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--ui-active), transparent) 0 0 / 40% 100% no-repeat;
  animation: wait-run 1.1s var(--ease) infinite;
}

/* The lesson being written (app.js showDrawing: 30 seconds or more): its card, the dots in its tile
   (canvas.css) and a light along its foot, so a long wait reads as work going on */
.scene-card.building { position: relative; overflow: hidden; }
.scene-card.building::after { left: 24px; right: 24px; } /* (clear of its round corners) */
.scene-card.building .scene-text b { animation: wait-breathe 2.4s var(--ease) infinite; }

/* Words that say something is on its way ("Loading the paper…"): they shimmer, like "Thinking…" */
.wait-text {
  background: linear-gradient(90deg, var(--ui-ink-3) 0%, var(--ui-ink) 50%, var(--ui-ink-3) 100%) 0 0 / 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.6s linear infinite; /* (style.css's keyframes) */
}

/* ============================================================== less motion: still alive */

/* Nothing arrives or lifts: it's there. But every wait above, and the ones the other sheets turn
   off for less motion ("Thinking…"'s word, the lesson card's dots, a picture being drawn), breathes. */
@media (prefers-reduced-motion: reduce) {
  #log .msg.is-new, #welcome:not([hidden]) .empty > *, #welcome .starters > button { animation: none; }
  :is(.scene-card:not(.building), .starters button):hover { translate: none; }
  button[aria-busy="true"]::after { animation: wait-breathe 1.2s ease-in-out infinite; border-right-color: currentColor; }
  .chat-item[aria-busy="true"]::after, .scene-card.building::after, .wait-bar::after { background-size: 100% 100%; animation: wait-breathe 1.6s ease-in-out infinite; }
  .msg.pending:not(.drawing, .musing), .msg.pending.musing .muse, .wait-text { animation: wait-breathe 1.8s ease-in-out infinite; }
  .scene-card.building .scene-dots i { animation: scene-build 1.2s ease-in-out infinite; } /* (opacity only already) */
  #flat-board .fb-tool-picture .t-art.is-waiting, #flat-board .fb-tool-image .t-photo.is-waiting, #flat-board .fb-tool-picture .t-drawing { animation: wait-breathe 1.8s ease-in-out infinite; }
}
html.reduce-motion :is(#log .msg.is-new, #welcome:not([hidden]) .empty > *, #welcome .starters > button) { animation: none; }
html.reduce-motion :is(.scene-card:not(.building), .starters button):hover { translate: none; }
html.reduce-motion button[aria-busy="true"]::after { animation: wait-breathe 1.2s ease-in-out infinite; border-right-color: currentColor; }
html.reduce-motion :is(.chat-item[aria-busy="true"], .scene-card.building, .wait-bar)::after { background-size: 100% 100%; animation: wait-breathe 1.6s ease-in-out infinite; }
html.reduce-motion :is(.msg.pending:not(.drawing, .musing), .wait-text) { animation: wait-breathe 1.8s ease-in-out infinite; }
html.reduce-motion .msg.pending.musing .muse { animation: wait-breathe 1.8s ease-in-out infinite; }
html.reduce-motion .scene-card.building .scene-dots i { animation: scene-build 1.2s ease-in-out infinite; }
html.reduce-motion #flat-board .fb-tool-picture :is(.t-art.is-waiting, .t-drawing) { animation: wait-breathe 1.8s ease-in-out infinite; }
html.reduce-motion #flat-board .fb-tool-image .t-photo.is-waiting { animation: wait-breathe 1.8s ease-in-out infinite; }
