/* Isilumko AI Library: motion layer (design-handoff MOTION-SPEC.md). Driven by /js/motion.js.
   Loaded LAST on every page (after the page stylesheet), so hover rules here win.

   Rules (MOTION-SPEC s0):
   - Everything that moves sits inside @media (prefers-reduced-motion: no-preference). With reduce,
     nothing here applies: rings fully drawn, seeded highlights visible, no glow, no entrance, no
     hover movement (the hover border-colour change stays).
   - Only transform and opacity animate, plus stroke-dashoffset for the ring draw-in. The theme
     reveal (clip-path) lives in theme.js / base.css; the copy tick + burst in /js/prompt-card.css.
   - Banner rings stay literal white / maroon / slate (banners are dark in both themes); the glow
     rgba values are banner-only decoration (MOTION-SPEC s4). Everything else uses tokens.
   - will-change only on the glow layers.

   Classes set by /js/motion.js:
     html.entered             the once-per-load entrance is over (never replays)
     html.m-hold              page opened in a background tab: entrance waits until visible
     .m-enter / .m-new        card entrance (index in --m-n) / 150 ms fade for genuinely new cards
     .hero|.phead.m-live      banner loop running (after the draw-in); .m-skip = entrance was skipped
     .m-paused                banner off screen (< 10% visible) or tab hidden: loops paused
     .m-breathing             breathing slots running (Home banner, light headers)
     .tile.m-pass             one hover / focus pass of the tile's division personality
   Ring hooks come from /js/rings.js: pathLength="1", --xf, --j, --o, data-kind, data-under. */

/* ------------------------------------------------------------------ keyframes */
@keyframes m-draw{from{stroke-dashoffset:1;opacity:0}30%{opacity:var(--o,1)}to{stroke-dashoffset:0;opacity:var(--o,1)}}
@keyframes m-rise{from{opacity:0;transform:translateY(16px)}to{opacity:1;transform:none}}
@keyframes m-fade{from{opacity:0}to{opacity:1}}
/* s1 breathing slot */
@keyframes m-breathe{0%,100%{opacity:0;transform:scale(.93)}50%{opacity:1;transform:scale(1.06)}}
/* s3a stadium wave (--lift in viewBox units: banner 5, tile 4, stragglers 2) */
@keyframes m-wave{
  0%{transform:translateY(0);opacity:var(--o)}
  5%{transform:translateY(calc(var(--lift,5px) * -1));opacity:1}
  14%,100%{transform:translateY(0);opacity:var(--o)}
}
@keyframes m-wave-hi{
  0%{transform:translateY(0) scale(1)}
  5%{transform:translateY(calc(var(--lift,5px) * -1)) scale(1.08)}
  14%,100%{transform:translateY(0) scale(1)}
}
/* s3b the grid runs */
@keyframes m-rowlight{0%,22%,100%{opacity:var(--o)}7%{opacity:.95}}
/* s3c switch on: transform / opacity only (the resting pattern already has the maroon centre) */
@keyframes m-sw0{0%,10%{transform:scale(1)}16%{transform:scale(1.22)}24%,100%{transform:scale(1)}}
@keyframes m-sw1{0%,18%{opacity:0}27%,82%{opacity:var(--o)}94%,100%{opacity:0}}
@keyframes m-sw2{0%,26%{opacity:0}36%,82%{opacity:var(--o)}94%,100%{opacity:0}}
@keyframes m-sw1-dim{0%,18%{opacity:var(--o)}27%,82%{opacity:0}94%,100%{opacity:var(--o)}}
@keyframes m-sw2-dim{0%,26%{opacity:var(--o)}36%,82%{opacity:0}94%,100%{opacity:var(--o)}}
@keyframes m-ripple{0%,14%{opacity:0;transform:scale(1)}17%{opacity:.7}40%,100%{opacity:0;transform:scale(5.5)}}
/* s4 glow */
@keyframes m-glowA{0%{transform:translate(-22%,-12%)}50%{transform:translate(8%,10%)}100%{transform:translate(26%,-6%)}}
@keyframes m-glowB{0%{transform:translate(28%,14%)}50%{transform:translate(-4%,-12%)}100%{transform:translate(-26%,10%)}}
/* s6 icon bounce */
@keyframes m-bounce{0%,100%{transform:translateY(0)}30%{transform:translateY(-6px) scale(1.06)}55%{transform:translateY(1px) scale(.98)}75%{transform:translateY(-2px)}}

/* -------------------------------------------------------- static (all motion settings) */
.m-glows{display:none}                                 /* s4: reduced motion removes the glow */
svg.rings circle[data-kind="slot"]{opacity:0}          /* breathing slots exist only while motion runs */
.hero svg.rings{--lift:5px}
.tile svg.rings{--lift:4px}
svg.rings circle[data-kind="straggler"]{--lift:2px}

/* s6 hover life: the border-colour change is the only part that survives reduced motion */
:is(.card.plat,.card.ghost,.mcard,.pcard){
  transition:border-color .25s cubic-bezier(.2,.7,.2,1),box-shadow .25s cubic-bezier(.2,.7,.2,1),transform .25s cubic-bezier(.2,.7,.2,1)}
@media (hover:hover) and (pointer:fine){
  :is(.card.plat,.card.ghost,.mcard,.pcard):hover{border-color:var(--accent-tint-border)}
}
:is(.card.plat,.mcard,.pcard):has(:focus-visible),.card.ghost:focus-visible{border-color:var(--accent-tint-border)}
.pcard.sel:hover,.pcard.sel:has(:focus-visible){border-color:var(--accent)}   /* the selected prompt keeps its accent border */
.ic::after{transition:transform .6s cubic-bezier(.2,.7,.2,1)}
.card .open svg.i,.mcard .open svg.i{transition:transform .25s cubic-bezier(.2,.7,.2,1)}
.tile{transition:transform .2s ease}

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

  /* ---------------------------------------------------------- s5 entrance (once per load) */
  html:not(.entered) :is(.hero,.phead) svg.rings circle:not([data-under]):not([data-kind="ripple"]):not([data-kind="slot"]){
    stroke-dasharray:1;animation:m-draw 1.2s cubic-bezier(.2,.7,.2,1) both;animation-delay:calc(var(--xf,0) * .9s)}
  html:not(.entered) :is(.hero,.phead) > .in{animation:m-rise .6s ease both}
  html:not(.entered) .m-glows{animation:m-fade 1.2s ease both}
  .m-enter{animation:m-rise .6s cubic-bezier(.2,.7,.2,1) both;animation-delay:calc(.35s + var(--m-n,0) * .06s)}
  .m-new{animation:m-fade .15s ease-out both}
  /* !important: the animation shorthands below would otherwise reset play-state to running */
  html.m-hold :is(.hero,.phead) svg.rings circle,html.m-hold :is(.hero,.phead) > .in,
  html.m-hold .m-glows,html.m-hold .m-enter{animation-play-state:paused!important}

  /* ---------------------------------------------------------------------- s4 glow */
  .m-glows{display:block;position:absolute;inset:0;pointer-events:none}
  .m-glow{position:absolute;inset:-50%;pointer-events:none;will-change:transform}
  /* peak alphas as overridable hooks (--m-glow-1 / --m-glow-2 on a banner); defaults = MOTION-SPEC s4 */
  .m-glow.g1{background:radial-gradient(circle at 50% 50%,rgba(255,255,255,var(--m-glow-1,.17)),rgba(255,255,255,0) 32%);animation:m-glowA 16s ease-in-out infinite alternate}
  .m-glow.g2{background:radial-gradient(circle at 50% 50%,rgba(142,24,43,var(--m-glow-2,.45)),rgba(142,24,43,0) 30%);animation:m-glowB 21s ease-in-out infinite alternate}
  /* per-banner strength (MOTION-SPEC s4 check): at the spec's .17 the white glow pulls the 84% white
     text on slate (Staffing) and the grey eyebrow on Home under 4.5:1 at its peak. At .075 every
     banner text stays >= 4.5:1 (re-measured with the QA glow sweep); Industrial / Activate keep .17. */
  body.home .hero,body.staffing .hero{--m-glow-1:.075}

  /* ------------------------------------------------- s0.3 pause off screen / hidden tab */
  .m-paused .m-glow,.m-paused.m-live svg.rings circle{animation-play-state:paused!important}

  /* ------------------------------------------------ s1 breathing (Home + light headers) */
  .m-breathing svg.rings circle[data-kind="hi"]{opacity:0;transition:opacity 1s ease}
  .m-breathing svg.rings circle[data-kind="slot"]{animation:m-breathe 5s ease-in-out infinite both;animation-delay:var(--m-slot,0s)}

  /* ---------------------------------------------------------- s3 banner personalities */
  .m-live svg.rings{--m-start:0s}
  .m-live svg.rings[data-mode="staffing"]{--m-start:.6s}            /* first pass 0.6 s after the draw-in */
  .m-live.m-skip svg.rings[data-mode="staffing"]{--m-start:.3s}     /* ... or 0.3 s when the entrance was skipped */

  /* s3a Staffing: stadium wave */
  .m-live svg.rings[data-mode="staffing"] circle{
    animation:m-wave 5s ease-in-out infinite both;animation-delay:calc(var(--m-start) + var(--xf,0) * 2.1s)}
  .m-live svg.rings[data-mode="staffing"] circle[data-kind="hi"]{animation-name:m-wave-hi}

  /* s3b Industrial: the grid runs (highlights stay lit) */
  .m-live svg.rings[data-mode="industrial"] circle[data-kind="base"]{
    animation:m-rowlight 4s linear infinite both;animation-delay:calc(var(--m-start) + var(--j,0) * .2s)}

  /* s3c Activate: switch on. The loop enters at 80% (the resting brand pattern), so it never pops. */
  .m-live svg.rings[data-mode="activate"] circle:is([data-kind="d0"],[data-kind="d1"],[data-kind="d2"],[data-under],[data-kind="ripple"]){
    animation-duration:5s;animation-timing-function:ease-in-out;animation-iteration-count:infinite;animation-fill-mode:both;
    animation-delay:calc(var(--m-start) - 4s)}
  .m-live svg.rings[data-mode="activate"] circle[data-kind="d0"]{animation-name:m-sw0}
  .m-live svg.rings[data-mode="activate"] circle[data-kind="d1"]{animation-name:m-sw1}
  .m-live svg.rings[data-mode="activate"] circle[data-kind="d2"]{animation-name:m-sw2}
  .m-live svg.rings[data-mode="activate"] circle[data-under="d1"]{animation-name:m-sw1-dim}
  .m-live svg.rings[data-mode="activate"] circle[data-under="d2"]{animation-name:m-sw2-dim}
  .m-live svg.rings[data-mode="activate"] circle[data-kind="ripple"]{animation-name:m-ripple;animation-timing-function:ease-out}

  /* s3d Home tiles: static at rest, ONE pass on hover / keyboard focus (fill backwards: the
     pass ends exactly on the resting pattern, so nothing snaps) */
  .tile.m-pass svg.rings[data-mode="staffing"] circle{
    animation:m-wave 5s ease-in-out backwards;animation-iteration-count:.14;animation-delay:calc(var(--xf,0) * 2.1s)}
  .tile.m-pass svg.rings[data-mode="staffing"] circle[data-kind="hi"]{animation-name:m-wave-hi}
  .tile.m-pass svg.rings[data-mode="industrial"] circle[data-kind="base"]{
    animation:m-rowlight 4s linear backwards;animation-iteration-count:.22;animation-delay:calc(var(--j,0) * .2s)}
  .tile.m-pass svg.rings[data-mode="activate"] circle:is([data-kind="d0"],[data-kind="d1"],[data-kind="d2"],[data-under],[data-kind="ripple"]){
    animation-duration:5s;animation-timing-function:ease-in-out;animation-iteration-count:1.4;animation-fill-mode:backwards;animation-delay:-4s}
  .tile.m-pass svg.rings[data-mode="activate"] circle[data-kind="d0"]{animation-name:m-sw0}
  .tile.m-pass svg.rings[data-mode="activate"] circle[data-kind="d1"]{animation-name:m-sw1}
  .tile.m-pass svg.rings[data-mode="activate"] circle[data-kind="d2"]{animation-name:m-sw2}
  .tile.m-pass svg.rings[data-mode="activate"] circle[data-under="d1"]{animation-name:m-sw1-dim}
  .tile.m-pass svg.rings[data-mode="activate"] circle[data-under="d2"]{animation-name:m-sw2-dim}
  .tile.m-pass svg.rings[data-mode="activate"] circle[data-kind="ripple"]{animation-name:m-ripple;animation-timing-function:ease-out}

  /* ---------------------------------------------------------------- s6 card hover life */
  :is(.card.plat,.mcard,.pcard):has(:focus-visible),.card.ghost:focus-visible{transform:translateY(-4px);box-shadow:var(--shadow-lg)}
  .card.plat:has(:focus-visible) .ic::after{transform:scale(1.28)}
  .pcard:has(:focus-visible) .pc-deco svg{transform:rotate(120deg)}
  .card.plat:has(:focus-visible) .ic svg.i,.mcard:has(:focus-visible) .mav{animation:m-bounce .7s cubic-bezier(.3,.7,.3,1)}
  :is(.card.plat,.mcard):has(:focus-visible) .open svg.i{transform:translateX(3px)}
  .tile:has(:focus-visible){transform:translateY(-2px)}
}

@media (prefers-reduced-motion:no-preference) and (hover:hover) and (pointer:fine){
  :is(.card.plat,.card.ghost,.mcard,.pcard):hover{transform:translateY(-4px);box-shadow:var(--shadow-lg)}
  .card.plat:hover .ic::after{transform:scale(1.28)}                  /* platform cards: corner ring grows */
  .pcard:hover .pc-deco svg{transform:rotate(120deg)}                  /* prompt cards: dashed ring spins */
  .card.plat:hover .ic svg.i,.mcard:hover .mav{animation:m-bounce .7s cubic-bezier(.3,.7,.3,1)}
  :is(.card.plat,.mcard):hover .open svg.i{transform:translateX(3px)}
  .tile:hover{transform:translateY(-2px)}                              /* Home division tiles lift 2 px */
}
