/* ==========================================================================
   084 — Scaredy Button
   Bouton peureux : il esquive le curseur qui s'approche (fuite spring
   paniquée + micro-tremblement, pilotée en JS et bornée à sa zone).
   Après 3 esquives il se rend — affaissement, tooltip « Bon, d'accord… » —
   et se laisse cliquer : mini confettis + « Bravo ! ». Au clavier (focus)
   il se rend immédiatement ; en reduced-motion il n'esquive jamais.
   ========================================================================== */

.scaredy-btn-zone {
  position: relative;
  display: grid;
  place-items: center;
  width: 300px;
  max-width: 100%;
  height: 200px;
  border: 1px dashed color-mix(in srgb, var(--ml-muted, #8b91a3) 35%, transparent);
  border-radius: 14px;
}

.scaredy-btn-zone__hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--ml-muted, #8b91a3);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* --- Bouton (le transform est piloté par le JS) --------------------------- */

.scaredy-btn {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
}

.scaredy-btn:focus-visible {
  outline: 2px solid var(--ml-accent, #7c8cff);
  outline-offset: 5px;
  border-radius: 12px;
}

/* La « peau » du bouton : les états (fuite, reddition, victoire) vivent ici
   pour ne jamais entrer en conflit avec le translate3d posé par le JS. */
.scaredy-btn__face {
  display: inline-block;
  padding: 12px 26px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ml-fg, #e8eaf2);
  background: linear-gradient(
    135deg,
    var(--ml-accent, #7c8cff),
    color-mix(in srgb, var(--ml-accent, #7c8cff) 55%, var(--ml-accent-2, #2dd4bf))
  );
  box-shadow: 0 8px 22px color-mix(in srgb, var(--ml-accent, #7c8cff) 35%, transparent);
  transition:
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.3s ease,
    filter 0.3s ease;
}

/* Hook JS : le texte remplacé par « Bravo ! » au clic */
.scaredy-btn__label {
  display: inline-block;
}

/* Pendant la fuite : léger étirement, ombre écrasée (il court, quoi) */
.scaredy-btn--fleeing .scaredy-btn__face {
  transform: scale(1.04, 0.94);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--ml-accent, #7c8cff) 25%, transparent);
}

/* Reddition : affaissement — il se tasse, penche, se délave un peu */
.scaredy-btn--surrendered .scaredy-btn__face {
  transform: translateY(3px) scale(0.96) rotate(-1.5deg);
  filter: saturate(0.75) brightness(0.92);
  box-shadow: 0 3px 10px color-mix(in srgb, var(--ml-accent, #7c8cff) 20%, transparent);
}

/* Victoire : re-pop et bascule sur la teinte secondaire */
.scaredy-btn--done .scaredy-btn__face {
  background: linear-gradient(
    135deg,
    var(--ml-accent-2, #2dd4bf),
    var(--ml-accent, #7c8cff)
  );
  box-shadow: 0 8px 22px color-mix(in srgb, var(--ml-accent-2, #2dd4bf) 35%, transparent);
  animation: scaredy-btn-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scaredy-btn-pop {
  0%   { transform: scale(0.88); }
  55%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* --- Tooltip « Bon, d'accord… » ------------------------------------------- */

.scaredy-btn__tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translate(-50%, 6px);
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--ml-surface, #151a24);
  border: 1px solid color-mix(in srgb, var(--ml-muted, #8b91a3) 30%, transparent);
  color: var(--ml-fg, #e8eaf2);
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.scaredy-btn__tip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 8px;
  height: 8px;
  transform: translate(-50%, -5px) rotate(45deg);
  background: inherit;
  border-right: inherit;
  border-bottom: inherit;
}

.scaredy-btn--surrendered .scaredy-btn__tip {
  opacity: 1;
  transform: translate(-50%, 0);
}

.scaredy-btn--done .scaredy-btn__tip {
  opacity: 0;
  transform: translate(-50%, -4px);
}

/* --- Confettis (spans injectés par le JS dans __burst) --------------------- */

.scaredy-btn__burst {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}

.scaredy-btn__bit {
  position: absolute;
  left: -3px;
  top: -5px;
  width: 6px;
  height: 10px;
  border-radius: 2px;
  animation: scaredy-btn-confetti 0.85s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes scaredy-btn-confetti {
  0% {
    transform: translate(0, 0) rotate(0) scale(1);
    opacity: 1;
  }
  65% {
    opacity: 1;
  }
  100% {
    /* trajectoire par pièce via --sc-x / --sc-y / --sc-r (inline),
       + 26px de chute « gravité » en fin de course */
    transform: translate(var(--sc-x, 0px), calc(var(--sc-y, 0px) + 26px))
      rotate(var(--sc-r, 180deg)) scale(0.55);
    opacity: 0;
  }
}

/* --- Reduced motion --------------------------------------------------------
   Le JS n'esquive pas et ne lance pas de confettis ; côté CSS on coupe le
   reste des flourishes pour une bascule d'état sobre. */
@media (prefers-reduced-motion: reduce) {
  .scaredy-btn__face,
  .scaredy-btn__tip {
    transition: none;
    animation: none;
  }
  .scaredy-btn--done .scaredy-btn__face {
    animation: none;
  }
  .scaredy-btn__bit {
    animation: none;
    opacity: 0;
  }
}
