/* ==========================================================================
   patches.css: the two drawn accents, the bow (on the photo frame's lace ring) and the sparkle
   (on the order button). Markup (index.html):
     <span class="patch patch-NAME" data-patch="NAME" aria-hidden="true">
       <svg class="patch-svg" viewBox="0 0 120 120" focusable="false"><use href="assets/sprite.svg#patch-NAME"></use></svg>
     </span>
   css/layout.css owns position, offsets, width, z-index and --patch-tilt. This file owns display, aspect ratio,
   the resting rotation, shadow, paint and every animation or state. It never sets position or size.
   Motion:
     - entrance on .patch (individual `scale` property + opacity, so the tilt transform is untouched),
       staggered by data-patch-order (set by js/patches.mjs in DOM order), only after html.page-ready;
     - wobble / squish / spin on .patch-svg, switched by js/patches.mjs with the classes
       patch--wobble, patch--squish, patch--spin on .patch, removed on animationend (always run to the end).
   Colours: tokens only.
   ========================================================================== */

/* Paint of the two drawings, pinned on the <use> itself so they look the same whatever --sp-* values
   the surrounding rules (or :root in css/tokens.css) set. */
use[href$="sprite.svg#patch-bow"],
use[href$="sprite.svg#patch-sparkle"] {
  --sp-fill: var(--c-rose);         /* bow loops and knot */
  --sp-fill-2: var(--c-rose-600);   /* bow tails */
  --sp-hole: var(--c-cocoa);        /* the one outline */
  --sp-shine: var(--c-lace);        /* the bow's one shine */
  --sp-paper: var(--c-cream);       /* sparkle body */
}

.patch {
  display: block;
  aspect-ratio: 1;
  transform: rotate(var(--patch-tilt, 0deg));
  /* one soft shadow so the patch sits on the card */
  filter: drop-shadow(0 2px 2px var(--c-cocoa-a22));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.patch-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;           /* the span is the hit target, never the SVG */
  transform-origin: 50% 50%;
}
/* the bow swings from its knot, not from the middle of its box */
.patch-bow .patch-svg { transform-origin: 50% 44%; }

/* ---------- the bow photo (art slot "bow", css/art.css): once assets/art/bow.webp exists it replaces the
   drawn bow inside the same .patch-svg, so entrance, wobble, squish and pop keep working and the soft
   drop shadow on .patch follows the photo's own outline. css/layout.css may give .patch-bow another box
   under the same selector, using --art-bow-ar. ---------- */
html[data-art~="bow"] .patch-bow .patch-svg {
  background: var(--art-bow) center / contain no-repeat;
}
html[data-art~="bow"] .patch-bow .patch-svg use { display: none; }

/* hosted patch (the sparkle on the order button): never takes a click, reacts to its host */
[data-patch-host] .patch { pointer-events: none; }

/* ---------- before the page is ready: nothing shows, so a patch never flashes before its entrance ---------- */
html:not(.page-ready) .patch { visibility: hidden; }

/* ---------- entrance: a soft pop, one after another ---------- */
@keyframes patch-stick {
  0%   { scale: .6;   opacity: 0; }
  55%  { scale: 1.08; opacity: 1; }
  80%  { scale: .98; }
  100% { scale: 1;    opacity: 1; }
}
html.page-ready .patch {
  animation: patch-stick 460ms var(--ease) both;
}
html.page-ready .patch[data-patch-order="1"] { animation-delay: 160ms; }
html.page-ready .patch[data-patch-order="2"] { animation-delay: 320ms; }
html.page-ready .patch[data-patch-order="3"] { animation-delay: 480ms; }

/* ---------- hover wobble (fine pointers; class set by js/patches.mjs) ---------- */
@keyframes patch-wobble {
  0%   { transform: rotate(0deg) scale(1); }
  20%  { transform: rotate(-8deg) scale(1.05); }
  42%  { transform: rotate(6deg) scale(1.05); }
  62%  { transform: rotate(-3deg) scale(1.02); }
  82%  { transform: rotate(1.5deg) scale(1.01); }
  100% { transform: rotate(0deg) scale(1); }
}
.patch.patch--wobble .patch-svg { animation: patch-wobble 640ms ease-in-out; }

/* ---------- click / tap squish ---------- */
@keyframes patch-squish {
  0%   { transform: scale(1, 1); }
  22%  { transform: scale(1.14, .84); }
  48%  { transform: scale(.93, 1.09); }
  72%  { transform: scale(1.03, .98); }
  100% { transform: scale(1, 1); }
}
.patch.patch--squish .patch-svg { animation: patch-squish 520ms var(--ease-spring); }

/* ---------- hosted twinkle: one quarter turn with a little grow per hover / focus of the host
   (a four-point sparkle looks the same every 90deg, so it ends exactly where it started) ---------- */
@keyframes patch-spin {
  0%   { transform: rotate(0deg) scale(1); }
  55%  { transform: rotate(70deg) scale(1.2); }
  100% { transform: rotate(90deg) scale(1); }
}
.patch.patch--spin .patch-svg { animation: patch-spin 600ms var(--ease); }

/* ---------- reduced motion: patches are simply there ---------- */
@media (prefers-reduced-motion: reduce) {
  html.page-ready .patch,
  .patch .patch-svg,
  .patch.patch--wobble .patch-svg,
  .patch.patch--squish .patch-svg,
  .patch.patch--spin .patch-svg { animation: none; }
  html.page-ready .patch { opacity: 1; scale: none; }
}
