/* ==========================================================================
   Animations de la mascotte (Tinyflow Motion) — Animations vectorielles de la mascotte Nina
   Ouverture (splash), chargements (loader), célébrations (ajouts/validations),
   toasts animés et mascottes interactives vivantes.
   ========================================================================== */

/* --- Base SVG articulée --- */
.c-billo-anim {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
  user-select: none;
  vertical-align: middle;
}

.c-billo-anim[data-interactive="true"] {
  cursor: pointer;
}

.c-billo-svg {
  display: block;
  overflow: visible;
  width: 100%;
  height: 100%;
}

/* Couleurs pilotées par le fond (billo-motion.js → adaptMascot) :
   traits encre sur fond clair, traits clairs sur fond sombre. Le visage reste encre (posé sur le corps blanc). */
.c-billo-svg {
  --billo-line: #0B0D12;
  --billo-shadow: #0B0D12;
  --billo-shadow-k: 1;
}

.c-billo-anim--on-dark .c-billo-svg {
  --billo-line: #EEF1F6;
  --billo-shadow: #000000;
  --billo-shadow-k: 3.4;
}

.c-billo-svg .c-billo-svg__line {
  stroke: var(--billo-line);
  transition: stroke 0.25s ease;
}

.c-billo-svg__shadow {
  fill: var(--billo-shadow);
  opacity: calc(0.11 * var(--billo-shadow-k));
  transform-box: fill-box;
  transform-origin: center;
}

.c-billo-svg__actor {
  transform-box: fill-box;
  transform-origin: 50% 92%;
}

.c-billo-svg__arm {
  transform-box: fill-box;
  transform-origin: 12% 85%;
}

.c-billo-svg__leg-l,
.c-billo-svg__leg-r {
  transform-box: fill-box;
  transform-origin: 50% 0%;
}

.c-billo-svg__eyes-normal {
  transform-box: fill-box;
  transform-origin: 50% 50%;
}

.c-billo-svg__eyes-happy,
.c-billo-svg__eyes-oops,
.c-billo-svg__mouth-open,
.c-billo-svg__mouth-oops,
.c-billo-svg__sparkles {
  opacity: 0;
}

/* --- Keyframes --- */
@keyframes billoFloat {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  50%      { transform: translateY(-4px) scale(1.01, 0.99); }
}

@keyframes billoShadowFloat {
  0%, 100% { transform: scaleX(1); opacity: calc(0.12 * var(--billo-shadow-k, 1)); }
  50%      { transform: scaleX(0.88); opacity: calc(0.08 * var(--billo-shadow-k, 1)); }
}

@keyframes billoBlink {
  0%, 91%, 96%, 100% { transform: scaleY(1); }
  93.5%              { transform: scaleY(0.12); }
}

@keyframes billoWaveArm {
  0%, 100% { transform: rotate(0deg); }
  20%      { transform: rotate(16deg); }
  40%      { transform: rotate(-10deg); }
  60%      { transform: rotate(14deg); }
  80%      { transform: rotate(-6deg); }
}

@keyframes billoJump {
  0%   { transform: translateY(0) scale(1, 1); }
  14%  { transform: translateY(4px) scale(1.09, 0.90); }
  36%  { transform: translateY(-18px) scale(0.94, 1.08) rotate(-3deg); }
  56%  { transform: translateY(-15px) scale(0.97, 1.04) rotate(3deg); }
  74%  { transform: translateY(3px) scale(1.06, 0.94); }
  88%  { transform: translateY(-4px) scale(0.99, 1.01); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes billoShadowJump {
  0%, 100% { transform: scaleX(1); opacity: calc(0.12 * var(--billo-shadow-k, 1)); }
  14%      { transform: scaleX(1.12); opacity: calc(0.15 * var(--billo-shadow-k, 1)); }
  45%      { transform: scaleX(0.62); opacity: calc(0.05 * var(--billo-shadow-k, 1)); }
  74%      { transform: scaleX(1.08); opacity: calc(0.14 * var(--billo-shadow-k, 1)); }
}

@keyframes billoTrotBody {
  0%, 100% { transform: translateY(0) rotate(-2.5deg); }
  25%      { transform: translateY(-6px) rotate(0deg); }
  50%      { transform: translateY(0) rotate(2.5deg); }
  75%      { transform: translateY(-6px) rotate(0deg); }
}

@keyframes billoLegLeft {
  0%, 100% { transform: rotate(16deg); }
  50%      { transform: rotate(-16deg); }
}

@keyframes billoLegRight {
  0%, 100% { transform: rotate(-16deg); }
  50%      { transform: rotate(16deg); }
}

@keyframes billoOopsShake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  20%      { transform: translateX(-5px) rotate(-5deg); }
  40%      { transform: translateX(5px) rotate(5deg); }
  60%      { transform: translateX(-3px) rotate(-3deg); }
  80%      { transform: translateX(3px) rotate(2deg); }
}

@keyframes billoSparklePop {
  0%   { opacity: 0; transform: scale(0.35) translateY(8px); }
  30%  { opacity: 1; transform: scale(1.12) translateY(-4px); }
  70%  { opacity: 1; transform: scale(1) translateY(-8px); }
  100% { opacity: 0; transform: scale(0.75) translateY(-14px); }
}

@keyframes billoDotPulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40%           { opacity: 1; transform: scale(1.15); }
}

/* --- États de la mascotte --- */
.c-billo-anim--idle .c-billo-svg__actor {
  animation: billoFloat 3.4s ease-in-out infinite;
}
.c-billo-anim--idle .c-billo-svg__shadow {
  animation: billoShadowFloat 3.4s ease-in-out infinite;
}
.c-billo-anim--idle .c-billo-svg__eyes-normal {
  animation: billoBlink 5.2s ease-in-out infinite;
}
.c-billo-anim--idle:hover .c-billo-svg__arm {
  animation: billoWaveArm 0.75s ease-in-out;
}
.c-billo-anim--idle:hover .c-billo-svg__actor {
  animation: billoJump 0.72s cubic-bezier(0.22, 1, 0.36, 1);
}

.c-billo-anim--wave .c-billo-svg__actor {
  animation: billoJump 0.9s cubic-bezier(0.22, 1, 0.36, 1) 1, billoFloat 3s ease-in-out 0.9s infinite;
}
.c-billo-anim--wave .c-billo-svg__shadow {
  animation: billoShadowJump 0.9s cubic-bezier(0.22, 1, 0.36, 1) 1, billoShadowFloat 3s ease-in-out 0.9s infinite;
}
.c-billo-anim--wave .c-billo-svg__arm {
  animation: billoWaveArm 0.85s ease-in-out infinite;
}
.c-billo-anim--wave .c-billo-svg__eyes-normal {
  animation: billoBlink 4.2s ease-in-out infinite;
}

.c-billo-anim--loading .c-billo-svg__actor {
  animation: billoTrotBody 0.56s ease-in-out infinite;
}
.c-billo-anim--loading .c-billo-svg__leg-l {
  animation: billoLegLeft 0.56s ease-in-out infinite;
}
.c-billo-anim--loading .c-billo-svg__leg-r {
  animation: billoLegRight 0.56s ease-in-out infinite;
}
.c-billo-anim--loading .c-billo-svg__arm {
  animation: billoWaveArm 0.7s ease-in-out infinite;
}
.c-billo-anim--loading .c-billo-svg__shadow {
  animation: billoShadowFloat 0.56s ease-in-out infinite;
}

.c-billo-anim--celebrate .c-billo-svg__actor {
  animation: billoJump 0.92s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.c-billo-anim--celebrate .c-billo-svg__shadow {
  animation: billoShadowJump 0.92s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.c-billo-anim--celebrate .c-billo-svg__arm {
  animation: billoWaveArm 0.75s ease-in-out 2;
}
.c-billo-anim--celebrate .c-billo-svg__eyes-normal,
.c-billo-anim--celebrate .c-billo-svg__mouth-smile {
  opacity: 0;
}
.c-billo-anim--celebrate .c-billo-svg__eyes-happy,
.c-billo-anim--celebrate .c-billo-svg__mouth-open {
  opacity: 1;
}
.c-billo-anim--celebrate .c-billo-svg__sparkles {
  transform-box: fill-box;
  transform-origin: center;
  animation: billoSparklePop 1.05s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.c-billo-anim--oops .c-billo-svg__actor {
  animation: billoOopsShake 0.55s ease-in-out both;
}
.c-billo-anim--oops .c-billo-svg__eyes-normal,
.c-billo-anim--oops .c-billo-svg__mouth-smile {
  opacity: 0;
}
.c-billo-anim--oops .c-billo-svg__eyes-oops,
.c-billo-anim--oops .c-billo-svg__mouth-oops {
  opacity: 1;
}

/* --- 1. Splash d’ouverture léger (site & app) --- */
.c-billo-splash {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: var(--bg-canvas, #F6F7F9);
  color: var(--ink-high, #0B0D12);
  opacity: 1;
  transition: opacity 0.32s cubic-bezier(0.22, 1, 0.36, 1), transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.c-billo-splash.is-leaving {
  opacity: 0;
  transform: scale(1.03);
  pointer-events: none;
}

.c-billo-splash__badge {
  width: 112px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.c-billo-splash__title {
  margin: 0;
  font-family: var(--font-display, 'Schibsted Grotesk', system-ui, sans-serif);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink-high, #0B0D12);
}

.c-billo-splash__sub {
  margin: 0;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-muted, #68707E);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.c-billo-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.c-billo-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-accent, #0075EB);
  display: inline-block;
  animation: billoDotPulse 1.1s infinite ease-in-out;
}
.c-billo-dots i:nth-child(2) { animation-delay: 0.16s; background: #FFA8CD; }
.c-billo-dots i:nth-child(3) { animation-delay: 0.32s; background: #10B981; }

/* --- 2. Pilule flottante de chargement (requêtes API / actualisation) --- */
.c-billo-loader {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  z-index: 240;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.90);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle, rgba(11, 13, 18, 0.08));
  box-shadow: 0 12px 30px rgba(11, 13, 18, 0.12);
  color: var(--ink-high, #0B0D12);
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -14px) scale(0.95);
  transition: opacity 0.2s ease, transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] .c-billo-loader {
  background: rgba(22, 26, 35, 0.92);
  border-color: rgba(255, 255, 255, 0.10);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

.c-billo-loader.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

/* --- 3. Mini-scène de célébration (ajouts & grandes validations) --- */
.c-billo-burst {
  position: fixed;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px));
  z-index: 250;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  width: max-content;
  min-width: min(280px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  padding: 12px 20px 12px 14px;
  border-radius: 22px;
  background: rgba(11, 13, 18, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 46px rgba(11, 13, 18, 0.28);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 22px) scale(0.92);
  transition: opacity 0.24s ease, transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] .c-billo-burst {
  background: rgba(28, 33, 45, 0.96);
  border-color: rgba(255, 168, 205, 0.26);
}

.c-billo-burst.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.c-billo-burst__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.c-billo-burst__title {
  font-family: var(--font-display, 'Schibsted Grotesk', system-ui, sans-serif);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  color: #FFFFFF;
}

.c-billo-burst__sub {
  font-size: 12.5px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.74);
  line-height: 1.3;
}

/* --- 4. Mascotte Nina dans les toasts --- */
.c-toast__mascot {
  width: 30px;
  height: 27px;
  flex-shrink: 0;
  margin-left: -4px;
}

.c-toast__msg {
  line-height: 1.35;
}

.c-toast {
  animation: billoToastIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes billoToastIn {
  0%   { opacity: 0; transform: translateY(10px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- 5. Bloc de chargement inline (ex. pot.html) --- */
.c-billo-inline-load {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-muted, #68707E);
  font-size: 14px;
  font-weight: 500;
}

@media (max-width: 960px) {
  .c-billo-burst {
    bottom: calc(var(--bottom-nav-h, 74px) + 18px);
  }
}

/* --- Accessibilité : respect strict de prefers-reduced-motion --- */
@media (prefers-reduced-motion: reduce) {
  .c-billo-anim *,
  .c-billo-dots i,
  .c-toast {
    animation: none !important;
  }
  .c-billo-splash,
  .c-billo-loader,
  .c-billo-burst {
    transition-duration: 0.01ms !important;
  }
}

/* Avant l’animation JS (ou sans JS) : variante statique à traits clairs en thème sombre */
[data-theme="dark"] img[src*="billo-mascot.svg"] {
  content: url("../icons/billo-mascot-dark.svg?v=41");
}
