/* Icon micro-motion, decided by the icon. RWTIcon and Kit.icon stamp data-fx="<name>" on an icon from its glyph (the FX table in rwt-icon.js), and the rules
 * below play it inside any interactive parent: a link, button, tab, menu item or summary. No control opts in, so every button gets it, new ones included.
 *
 *   hover / keyboard focus   nudge (arrows, chevrons: 4px the way they point), plus (turns 90deg), send (up-right), spin (quarter turn back), tilt (trash)
 *   press, touch included    every icon in a pressed control scales to .9
 *   open                     turn (chevron-down) rotates 180deg while aria-expanded or details[open]
 *   a state RWTIconMotion sets on the control   data-ico-state="success" (check draws, send flies, pop) "new" (ring swings) "loading" (spin turns)
 *
 * Transform and opacity only, plus the stroke-dash draw of the check glyph. Every animation and transition sits in a no-preference block: reduced motion gets
 * the final, static icon. Timings are the shared tokens (--s1-dur-*). */
:root { --s1-fx-spring: cubic-bezier(.34, 1.56, .64, 1); }
@keyframes s1-fx-draw { from { stroke-dasharray: 24; stroke-dashoffset: 24; } to { stroke-dasharray: 24; stroke-dashoffset: 0; } }
@keyframes s1-fx-ring { 0%, 100% { transform: rotate(0); } 18% { transform: rotate(14deg); } 38% { transform: rotate(-11deg); } 58% { transform: rotate(7deg); } 78% { transform: rotate(-3deg); } }
@keyframes s1-fx-spin { to { transform: rotate(360deg); } }
@keyframes s1-fx-pop { 0% { transform: scale(1); } 40% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes s1-fx-fly { 0% { transform: none; opacity: 1; } 45% { transform: translate(9px, -9px); opacity: 0; } 46% { transform: translate(-9px, 9px); opacity: 0; } 100% { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: no-preference) {
  .s1-icon, .k-icon, .s1n-ico { transition: transform var(--s1-dur-2) var(--s1-ease); transform-origin: 50% 50%; }

  /* press: every icon in a pressed control */
  :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):active > :is(.s1-icon, .k-icon, .s1n-ico) { transform: scale(.9); transition-duration: var(--s1-dur-1); }

  /* hover (devices that hover) and keyboard focus */
  @media (hover: hover) {
    :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):hover [data-fx="nudge"] { transform: translateX(4px); }
    :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):hover [data-fx="nudge-back"] { transform: translateX(-4px); }
    :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):hover [data-fx="nudge-up"] { transform: translateY(-4px); }
    :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):hover [data-fx="nudge-ne"] { transform: translate(3px, -3px); }
    :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):hover [data-fx="send"] { transform: translate(3px, -3px); }
    :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):hover [data-fx="plus"] { transform: rotate(90deg); }
    :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):hover [data-fx="tilt"] { transform: rotate(-12deg); transform-origin: 70% 90%; }
    :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):hover:not([data-ico-state="loading"]) [data-fx="spin"] { transform: rotate(-90deg); }
  }
  :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):focus-visible [data-fx="nudge"] { transform: translateX(4px); }
  :is(a, button, [role="button"], [role="tab"], [role="menuitem"], summary):not(:disabled):focus-visible [data-fx="plus"] { transform: rotate(90deg); }

  /* open: a chevron that says "this is open" */
  [aria-expanded="true"] [data-fx="turn"], details[open] > summary [data-fx="turn"] { transform: rotate(180deg); }

  /* states set by RWTIconMotion on the control */
  [data-ico-state="success"] [data-fx="check"] { animation: s1-fx-draw var(--s1-dur-3) var(--s1-ease) both; }
  [data-ico-state="success"] [data-fx="send"] { animation: s1-fx-fly var(--s1-dur-5) var(--s1-ease) 1; }
  [data-ico-state="success"] [data-fx="pop"] { animation: s1-fx-pop var(--s1-dur-3) var(--s1-fx-spring) 1; }
  [data-ico-state="new"] [data-fx="ring"] { animation: s1-fx-ring var(--s1-dur-5) var(--s1-ease) 1; transform-origin: 50% 12%; }
  [data-ico-state="loading"] [data-fx="spin"] { animation: s1-fx-spin 900ms linear infinite; }

  /* Moments the portal already marks (no call needed): a toast's check, the "Saved" live line and a resolved For-you item draw their check. */
  .k-toast [data-fx="check"], [data-s1-motion="live-enter"].s1-live--ok .s1-icon, [data-s1-motion="resolved"] .s1-resolved-check .s1-icon { animation: s1-fx-draw var(--s1-dur-3) var(--s1-ease) 120ms both; }
}
