/* Motion: transitions and entrances across the app (2026-09-16).

   Loaded LAST on every page that links it (shell.html, persona-chat.html,
   login.html), so these win over a component's own rule only for the
   motion properties they set - nothing here changes layout or colour.

   One vocabulary, so the app moves like one thing:
     --dur-fast  hovers, presses, things closing          (quick, gets out of the way)
     --dur       menus, tabs, fades                        (noticeable, not slow)
     --dur-slow  pages, panels sliding, modals, messages   (the big moves)
   Entrances use --ease-out (fast start, soft landing); exits are fast
   and plain, because nobody wants to wait for something to leave.

   Reduced motion: every duration token collapses to ~0, so the same
   rules still run but finish instantly - one switch instead of a
   `prefers-reduced-motion` block per component. The three pre-existing
   looping animations (mic pulse, typing dots, spinner) keep their own
   handling in shell.css/styles.css. */

:root {
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --dur-fast: 140ms;
  --dur: 220ms;
  --dur-slow: 340ms;
}
@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 1ms; --dur: 1ms; --dur-slow: 1ms; }
}

@keyframes sr-fade-in   { from { opacity: 0; } }
@keyframes sr-fade-out  { to   { opacity: 0; } }
@keyframes sr-rise-in   { from { opacity: 0; transform: translateY(10px); } }
@keyframes sr-route-out { to   { opacity: 0; transform: translateY(-6px); } }
@keyframes sr-drop-down { from { opacity: 0; transform: translateY(-6px) scale(.97); } }
@keyframes sr-drop-up   { from { opacity: 0; transform: translateY(6px) scale(.97); } }
@keyframes sr-pop-in    { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes sr-pop-out   { to   { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes sr-from-left  { from { opacity: 0; transform: translateX(-14px); } }
@keyframes sr-from-right { from { opacity: 0; transform: translateX(14px); } }
@keyframes sr-from-origin {
  from {
    opacity: 0;
    transform: translate3d(var(--msg-enter-x, 0), var(--msg-enter-y, 0), 0) scale(.82);
  }
}

/* --- Controls: hover and press ------------------------------------------ */

button,
.primary-btn,
.ghost-btn,
.filter-btn,
.nav-link,
.chat-row,
.menu-item,
.menu-cta,
.style-card,
.text-input,
select,
input,
textarea {
  transition:
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease,
    color var(--dur-fast) ease,
    box-shadow var(--dur-fast) ease,
    opacity var(--dur-fast) ease,
    transform var(--dur-fast) var(--ease-out);
}
/* A small press, so a click feels like it landed. Not on things that are
   dragged or already carry their own transform. */
button:active:not(:disabled),
.primary-btn:active,
.ghost-btn:active,
.filter-btn:active,
.style-card:active { transform: scale(.97); }
.nav-link:active,
.chat-row:active { transform: scale(.985); }
/* Tiles already lift on hover; pressing keeps the lift and adds the press
   rather than dropping them back down. */
.tile:active { transform: translateY(-2px) scale(.98); }

/* --- Pages ---------------------------------------------------------------- */

/* Every page's content rises in as it lands. Children of the outlet, not
   the outlet itself: the outlet is the scroll container, and a transform
   on it would also re-anchor anything position:fixed inside a page. As
   routes build their content asynchronously, whatever is appended to the
   page later rises in on its own too. */
.route-outlet > * { animation: sr-rise-in var(--dur-slow) var(--ease-out) backwards; }
.route-page > * { animation: sr-rise-in var(--dur-slow) var(--ease-out) backwards; }
.route-page > :nth-child(2) { animation-delay: 40ms; }
.route-page > :nth-child(3) { animation-delay: 80ms; }
.route-page > :nth-child(n+4) { animation-delay: 110ms; }

/* The outgoing page, for the moment before it's cleared (shell.js render). */
.route-outlet.route-leaving > * {
  animation: sr-route-out var(--dur-fast) ease-in forwards;
  pointer-events: none;
}

/* Moving between two chats keeps the chat list still - it's the same list,
   and having it blink on every click reads as a reload. Only the
   conversation and the profile beside it change. */
.route-outlet > .chat-layout { animation: sr-fade-in var(--dur) ease backwards; }
.route-outlet > .chat-layout.chat-switch { animation: none; }
.chat-layout.chat-switch > .chat-main { animation: sr-fade-in var(--dur) ease backwards; }
.chat-layout.chat-switch > .character-panel { animation: sr-fade-in var(--dur-slow) ease backwards; }

/* Card grids stagger in, a beat apart, capped so a long grid doesn't make
   the last card wait. */
.card-grid > * { animation: sr-rise-in var(--dur-slow) var(--ease-out) backwards; }
.card-grid > :nth-child(2)  { animation-delay: 25ms; }
.card-grid > :nth-child(3)  { animation-delay: 50ms; }
.card-grid > :nth-child(4)  { animation-delay: 75ms; }
.card-grid > :nth-child(5)  { animation-delay: 100ms; }
.card-grid > :nth-child(6)  { animation-delay: 125ms; }
.card-grid > :nth-child(7)  { animation-delay: 150ms; }
.card-grid > :nth-child(8)  { animation-delay: 175ms; }
.card-grid > :nth-child(n+9) { animation-delay: 200ms; }
.collection-section { animation: sr-fade-in var(--dur) ease backwards; }

.promo-slide { animation: sr-from-right var(--dur-slow) var(--ease-out) backwards; }
.promo-slide:nth-child(2) { animation-delay: 60ms; }
.promo-slide:nth-child(n+3) { animation-delay: 120ms; }

.auth-card { animation: sr-pop-in var(--dur-slow) var(--ease-out) backwards; }

/* --- Sliding panels ------------------------------------------------------ */

/* Sidebar, chat list and character panel all collapse by changing a grid
   column's width with the column COUNT unchanged, which is what lets the
   browser animate it. Switched off while a resize handle is being dragged
   (.is-resizing), so the column tracks the pointer instead of easing
   after it. */
.app-body { transition: grid-template-columns var(--dur-slow) var(--ease-out); }
.chat-layout,
.shell { transition: grid-template-columns var(--dur-slow) var(--ease-out); }
.is-resizing .app-body,
.is-resizing .chat-layout { transition: none; }

/* Whatever comes back into view after a collapse fades in rather than
   popping. */
.character-panel:not(.is-collapsed) > .panel-tabs,
.character-panel:not(.is-collapsed) > .panel-pane:not([hidden]) {
  animation: sr-fade-in var(--dur-slow) ease backwards;
}
.panel-pane:not([hidden]) { animation: sr-fade-in var(--dur) ease backwards; }

/* The sidebar's "More" group opens and closes as a slide (0fr <-> 1fr). */
.nav-secondary-links {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows var(--dur) var(--ease-out), opacity var(--dur) ease;
}
.nav-secondary-links.is-closed { grid-template-rows: 0fr; opacity: 0; }
.nav-secondary-inner { min-height: 0; overflow: hidden; }

/* --- Menus and popovers ------------------------------------------------- */

.menu-panel:not([hidden]) {
  transform-origin: top right;
  animation: sr-drop-down var(--dur) var(--ease-out);
}
.chat-new-panel:not([hidden]),
.chat-menu-panel:not([hidden]) {
  transform-origin: top left;
  animation: sr-drop-down var(--dur) var(--ease-out);
}
.chat-row-menu,
.media-trigger-menu:not([hidden]) {
  transform-origin: bottom left;
  animation: sr-drop-up var(--dur) var(--ease-out);
}
.style-filter:not([hidden]) { animation: sr-fade-in var(--dur) ease; }
.chat-row-actions { animation: sr-fade-in var(--dur-fast) ease; }

/* --- Modals ---------------------------------------------------------------- */

.chat-menu-modal-backdrop { animation: sr-fade-in var(--dur) ease; }
.chat-menu-modal { animation: sr-pop-in var(--dur-slow) var(--ease-out); }
/* Closing: chat-menu.js adds .is-closing and removes the node once this
   has had time to play. */
.chat-menu-modal-backdrop.is-closing { animation: sr-fade-out var(--dur-fast) ease forwards; }
.chat-menu-modal-backdrop.is-closing .chat-menu-modal {
  animation: sr-pop-out var(--dur-fast) ease forwards;
}

/* --- Conversation ------------------------------------------------------------ */

/* Only NEW messages - persona-chat.js marks them .msg-enter; a history
   redraw re-renders everything without it. Theirs slide in from the left,
   yours from the right, the side each sits on. */
.msg.msg-enter { animation: sr-from-left var(--dur-slow) var(--ease-out) backwards; }
.msg.user.msg-enter { animation-name: sr-from-right; }
.msg.msg-enter-from-origin { animation: sr-from-origin var(--dur-slow) var(--ease-out) backwards; }
.media-triggers { animation: sr-fade-in var(--dur-slow) ease backwards; }
