/* Gebeta visual motion library — STEP 2, connected to existing menu buttons and small dialogs.
   Opt-in classes plus explicit existing presentation selectors. No IDs, rules, timers, event handlers or server changes.
   Apply transforms to a dedicated visual wrapper if its host already uses one.
   CSS curves approximate spring motion; they are not a physics simulation.
   Compositor-friendly properties improve smoothness, but cannot guarantee FPS. */
:root {
  --royal-press-time: 110ms;
  --royal-spring-time: 360ms;
  --royal-popup-time: 300ms;
  --royal-seed-time: 400ms; /* Existing sowing contract; never infer game timing from CSS. */
  --royal-ease-out: cubic-bezier(.16, 1, .3, 1);
  --royal-ease-spring: cubic-bezier(.2, .8, .25, 1.18);
}

/* Buttons: attach only to menu/action buttons, not board pits or memory tiles.
   Native disabled state and all existing input/focus semantics remain intact.
   Existing focus outlines must remain visible; this library never removes them. */
:is(.royal-button, button.primary):not(.memory-grid button):not([data-sheba]) {
  transform-origin: center;
  transition: transform var(--royal-spring-time) var(--royal-ease-spring);
}
@media (hover: hover) and (pointer: fine) {
  :is(.royal-button, button.primary):not(.memory-grid button):not([data-sheba]):not(:disabled):not([aria-disabled="true"]):hover {
    transform: translate3d(0, -1px, 0) scale(1.015);
  }
}
:is(.royal-button, button.primary):not(.memory-grid button):not([data-sheba]):not(:disabled):not([aria-disabled="true"]):active {
  transform: translate3d(0, 1px, 0) scale(.96);
  transition-duration: var(--royal-press-time);
  transition-timing-function: ease-out;
}
/* Optional one-shot visual wrapper; add only when a visual event is wired later. */
.royal-bounce {
  animation: royal-spring-bounce var(--royal-spring-time) linear both;
}
@keyframes royal-spring-bounce {
  0%   { transform: translate3d(0, 0, 0) scale(.96); }
  45%  { transform: translate3d(0, -2px, 0) scale(1.035); }
  72%  { transform: translate3d(0, 1px, 0) scale(.99); }
  100% { transform: translate3d(0, 0, 0) scale(1); }
}

/* Use on a modal's inner visual panel, or a host with no positioning transform.
   Opening/closing, focus trapping and completion promises remain app-owned.
   No exit delay is introduced by this library. */
:is(.royal-popup-enter, dialog:where(#help, #handover, #result, #restart, #social-panel, #chat-panel, #profile-panel, #settings-panel, #crystal-panel, #recovery-panel, #password-reset, #progress-panel)[open]) {
  transform-origin: center;
  animation: royal-popup-enter var(--royal-popup-time) linear both;
}
@keyframes royal-popup-enter {
  0%   { opacity: 0; transform: translate3d(0, 14px, 0) scale(.94); }
  60%  { opacity: 1; transform: translate3d(0, -2px, 0) scale(1.015); }
  82%  { opacity: 1; transform: translate3d(0, 1px, 0) scale(.997); }
  100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

/* Flight is an opt-in alternative, NOT an override for .flying-seed.
   The current flySeed() owns geometry, timing, WAAPI playback and cleanup.
   Do not add this class to the same node while its WAAPI transform is running.
   A later adapter must supply start positioning + --royal-dx / --royal-dy in px
   and --royal-seed-time from the existing frame duration. --royal-arc is a
   nonnegative lift chosen for available viewport space, not a gameplay value.
   Element is decorative; its owner must set aria-hidden and remove it afterward.
   Linear time + sampled y(t)=dy*t - 4*arc*t*(1-t) approximates a parabola,
   including diagonal, downward and reverse-direction flights. */
.royal-seed-flight {
  --royal-dx: 0px;
  --royal-dy: 0px;
  --royal-arc: 32px;
  pointer-events: none;
  transform-origin: center;
  animation: royal-seed-arc var(--royal-seed-time) linear both;
  /* Only transient flight nodes are promoted; never the entire board. */
  will-change: transform;
}
@keyframes royal-seed-arc {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  12.5% {
    transform: translate3d(calc(var(--royal-dx) * .125), calc(var(--royal-dy) * .125 - var(--royal-arc) * .4375), 0) scale(1.025);
  }
  25% {
    transform: translate3d(calc(var(--royal-dx) * .25), calc(var(--royal-dy) * .25 - var(--royal-arc) * .75), 0) scale(1.05);
  }
  37.5% {
    transform: translate3d(calc(var(--royal-dx) * .375), calc(var(--royal-dy) * .375 - var(--royal-arc) * .9375), 0) scale(1.075);
  }
  50% {
    transform: translate3d(calc(var(--royal-dx) * .5), calc(var(--royal-dy) * .5 - var(--royal-arc)), 0) scale(1.08);
  }
  62.5% {
    transform: translate3d(calc(var(--royal-dx) * .625), calc(var(--royal-dy) * .625 - var(--royal-arc) * .9375), 0) scale(1.075);
  }
  75% {
    transform: translate3d(calc(var(--royal-dx) * .75), calc(var(--royal-dy) * .75 - var(--royal-arc) * .75), 0) scale(1.05);
  }
  87.5% {
    transform: translate3d(calc(var(--royal-dx) * .875), calc(var(--royal-dy) * .875 - var(--royal-arc) * .4375), 0) scale(1.025);
  }
  100% { transform: translate3d(var(--royal-dx), var(--royal-dy), 0) scale(1); }
}
@keyframes royal-seed-straight {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(var(--royal-dx), var(--royal-dy), 0); }
}

/* Keep essential seed travel at the same duration; omit arc and scaling.
   Decorative springs/pop-ups stop completely, with no global timing overrides. */
@media (prefers-reduced-motion: reduce) {
  :is(.royal-button, button.primary):not(.memory-grid button):not([data-sheba]) { transition: none; }
  :is(.royal-button, button.primary):not(.memory-grid button):not([data-sheba]):not(:disabled):not([aria-disabled="true"]):hover,
  :is(.royal-button, button.primary):not(.memory-grid button):not([data-sheba]):not(:disabled):not([aria-disabled="true"]):active { transform: none; }
  .royal-bounce,
  :is(.royal-popup-enter, dialog:where(#help, #handover, #result, #restart, #social-panel, #chat-panel, #profile-panel, #settings-panel, #crystal-panel, #recovery-panel, #password-reset, #progress-panel)[open]) { animation: none; }
  .royal-seed-flight { animation-name: royal-seed-straight; }
}

/* STEP 4: decorative landing flecks and capture sparks, outside pit/count DOM. */
.royal-pit-burst{position:fixed;z-index:29;width:0;height:0;pointer-events:none}
.royal-pit-spark{position:absolute;left:0;top:0;width:var(--spark-size,4px);height:var(--spark-size,4px);border-radius:50%;background:#ffe1a0;pointer-events:none;animation:royal-pit-spark 480ms ease-out both}
@keyframes royal-pit-spark{0%{opacity:0;transform:translate3d(0,0,0) scale(.4)}18%{opacity:.85}100%{opacity:0;transform:translate3d(var(--spark-x),var(--spark-y),0) scale(.15)}}
@media(prefers-reduced-motion:reduce){.royal-pit-burst{display:none}.royal-pit-spark{animation:none}}

/* Outcome reactions reuse the original cutout. Text/outcome remains authoritative. */
.queen-guide[data-queen-reaction="celebrate"]>img{animation:royal-queen-celebrate 850ms ease-out both,queen-idle 5s 850ms ease-in-out infinite}
.queen-guide[data-queen-reaction="encourage"]>img{animation:royal-queen-encourage 650ms ease-out both,queen-idle 5s 650ms ease-in-out infinite}
.queen-guide[data-queen-reaction="ready"]>img{animation:royal-queen-ready 700ms ease-out both,queen-idle 5s 700ms ease-in-out infinite}
#result[data-queen-reaction]::before{content:'';display:block;width:78px;height:110px;margin:0 auto 8px;background:url('/queen-sheba-v1.png') center/contain no-repeat;pointer-events:none;transform-origin:50% 100%}
.queen-result-portrait{display:block;object-fit:contain;margin:0 auto 8px;max-height:125px;transform-origin:50% 100%}
#result[data-queen-reaction="celebrate"]::before,[data-queen-reaction="celebrate"]>.queen-result-portrait{animation:royal-queen-celebrate 850ms ease-out both}
#result[data-queen-reaction="encourage"]::before{animation:royal-queen-encourage 650ms ease-out both}
#result[data-queen-reaction="ready"]::before{animation:royal-queen-ready 700ms ease-out both}
@keyframes royal-queen-celebrate{0%{transform:translate3d(0,6px,0) scale(.98)}35%{transform:translate3d(0,-5px,0) scale(1.025)}65%{transform:translate3d(0,1px,0) scale(.995)}100%{transform:translate3d(0,0,0) scale(1)}}
@keyframes royal-queen-encourage{0%{transform:translate3d(0,3px,0) rotate(-1deg)}55%{transform:translate3d(0,-1px,0) rotate(.6deg)}100%{transform:translate3d(0,0,0) rotate(0)}}
@keyframes royal-queen-ready{0%{opacity:.7;transform:translate3d(0,5px,0)}100%{opacity:1;transform:translate3d(0,0,0)}}
@media(max-height:500px){#result[data-queen-reaction]::before{width:48px;height:64px}.queen-result-portrait{max-height:80px}}
@media(prefers-reduced-motion:reduce){.queen-guide[data-queen-reaction]>img,#result[data-queen-reaction]::before,.queen-result-portrait{animation:none}}
