/*
 * Le rideau du premier chargement (Gemmora Blast) : le renard démarre, court sur place et rassemble les gemmes qui arrivent en
 * sautillant, sous un ciel étoilé ; en dessous, le nom du jeu, une phrase, la barre qui suit le chargement (boot.js la remplit par
 * --p) et son pourcentage.
 * Le rideau n'existe que lorsque boot.js a posé « booting » sur <html> (une fois par visite) ; sans JavaScript, la page s'affiche
 * telle quelle. Chargé avant style.css : le rideau est dessiné dès la première image.
 */
.boot {
  display: none;
}
.booting {
  overflow: hidden;
}
.booting .boot {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow: hidden;
  color: #f6f1ff;
  background:
    radial-gradient(60% 45% at 50% 40%, rgb(124 72 255 / 45%) 0%, transparent 70%),
    radial-gradient(120% 90% at 50% 45%, #2a1680 0%, #1d0d57 45%, #140a3a 85%);
  font-family: 'Fredoka', 'Nunito', system-ui, sans-serif;
  /* Filet de sécurité : si boot.js s'arrêtait en route, le rideau s'efface seul au bout de 12 s. */
  animation: boot-failsafe 0.6s 12s forwards;
}
.boot.is-out {
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.6s ease,
    visibility 0s 0.6s;
}

/* Le ciel : deux couches de petites étoiles qui scintillent à contretemps. */
.boot::before,
.boot::after {
  content: '';
  position: absolute;
  inset: -10%;
  pointer-events: none;
  background-image:
    radial-gradient(circle, #fff 0 1.5px, transparent 2px),
    radial-gradient(circle, #ffe39a 0 1.2px, transparent 1.7px),
    radial-gradient(circle, #c9b8ff 0 1px, transparent 1.5px);
  background-size:
    173px 167px,
    241px 229px,
    97px 113px;
  background-position:
    11px 23px,
    83px 131px,
    41px 7px;
  animation: boot-twinkle 2.6s ease-in-out infinite alternate;
}
.boot::after {
  background-position:
    127px 71px,
    19px 197px,
    67px 59px;
  animation-delay: -1.3s;
}

.boot__inner {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 14px;
  text-align: center;
  animation: boot-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition:
    scale 0.6s ease,
    translate 0.6s ease;
}
.is-out .boot__inner {
  scale: 1.06;
  translate: 0 -12px;
}

/* ---------- La scène : le renard, le sol qui défile, les gemmes ---------- */
.boot__stage {
  position: relative;
  width: min(340px, 92vw);
  height: 190px;
}
/* Une lueur dorée sous le renard. */
.boot__stage::before {
  content: '';
  position: absolute;
  left: 8%;
  bottom: 14px;
  width: 64%;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgb(255 197 51 / 38%), transparent);
  animation: boot-glow 0.24s ease-in-out infinite;
}
/* Le sol : une piste de petits points qui file vers la gauche, fondue sur les bords. */
.boot__stage::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 26px;
  height: 6px;
  background: radial-gradient(circle, rgb(255 255 255 / 40%) 0 2px, transparent 2.5px) 0 50% / 22px 6px repeat-x;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
  animation: boot-ground 0.48s linear infinite;
}

/* Le renard, d'après la planche design/mascotte/running-fox.png découpée par scripts/make-boot-fox.mjs : toutes les images ont le
   même cadre, calées sur l'œil (la tête reste en place, seuls le corps et les pattes bougent).
   - Il est d'abord assis, se ramasse et démarre (0,7 s).
   - Puis il court : quatre foulées en boucle, chacune se fondant dans la suivante (la nouvelle apparaît par-dessus l'ancienne, qui
     reste pleine dessous : il n'est jamais transparent ; la cinquième image est la première, pour boucler sans à-coup). Il rebondit
     à chaque foulée, la lueur sous lui et la poussière suivent.
   - Quand la page est prête (« is-dash », posé par boot.js), il accélère, traînée lumineuse comprise, et file hors de l'écran. */
.boot__fox {
  --run: 0.48s;
  position: absolute;
  z-index: 2;
  left: -64px;
  bottom: 14px;
  width: 290px;
  aspect-ratio: 374 / 197;
  filter: drop-shadow(0 6px 10px rgb(10 4 40 / 45%));
  animation: boot-bob calc(var(--run) / 2) ease-in-out 0.7s infinite;
}
.boot__fox img,
.boot__run,
.boot__dash {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.boot__sit {
  z-index: 1;
  transform-origin: 80% 100%;
  animation: boot-sit 0.7s ease-in-out forwards;
}
.boot__run {
  opacity: 0;
  animation: boot-run-in 0.7s step-end forwards;
}
.boot__run img,
.boot__dash img {
  opacity: 0;
}
.boot__run img {
  animation: var(--run) linear infinite;
}
.boot__run img:nth-child(1) {
  animation-name: boot-f1;
}
.boot__run img:nth-child(2) {
  animation-name: boot-f2;
}
.boot__run img:nth-child(3) {
  animation-name: boot-f3;
}
.boot__run img:nth-child(4) {
  animation-name: boot-f4;
}
.boot__run img:nth-child(5) {
  animation-name: boot-f5;
}

/* La sortie : trois poses de plus en plus rapides, puis il file vers la droite. */
.is-dash .boot__fox {
  animation: boot-zoom 0.62s cubic-bezier(0.55, 0, 0.85, 0.35) forwards;
}
.is-dash .boot__sit,
.is-dash .boot__run {
  display: none;
}
.is-dash .boot__dash img {
  animation: 0.3s linear forwards;
}
.is-dash .boot__dash img:nth-child(1) {
  animation-name: boot-d1;
}
.is-dash .boot__dash img:nth-child(2) {
  animation-name: boot-d2;
}
.is-dash .boot__dash img:nth-child(3) {
  animation-name: boot-d3;
}
.is-dash .boot__gem,
.is-dash .boot__dust {
  visibility: hidden;
}

/* Deux bouffées de poussière derrière les pattes arrière, à chaque atterrissage. */
.boot__dust {
  position: absolute;
  z-index: 1;
  left: 34px;
  bottom: 20px;
  width: 26px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgb(255 255 255 / 85%), rgb(220 205 255 / 40%) 70%, transparent);
  opacity: 0;
  animation: boot-dust 0.48s ease-out 0.7s infinite;
}
.boot__dust:nth-of-type(2) {
  left: 56px;
  width: 18px;
  height: 13px;
  animation-delay: 0.94s;
}

/* Les gemmes arrivent de la droite en sautillant ; le renard les attrape (elles grossissent et s'évanouissent dans un éclat). */
.boot__gem {
  position: absolute;
  z-index: 1;
  left: 196px;
  bottom: 40px;
  width: 40px;
  height: 40px;
  opacity: 0;
  animation: boot-gem 2.04s linear infinite;
  filter: drop-shadow(0 4px 6px rgb(10 4 40 / 50%));
}
.boot__gem:nth-of-type(2) {
  animation-delay: 0.51s;
}
.boot__gem:nth-of-type(3) {
  animation-delay: 1.02s;
}
.boot__gem:nth-of-type(4) {
  animation-delay: 1.53s;
}

/* ---------- Le nom, la phrase, la barre ---------- */
.boot__name {
  margin: 0;
  font-size: clamp(30px, 8.5vw, 42px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.01em;
  color: #ffc533;
  background: linear-gradient(100deg, #ffab1f 0%, #ffe07a 30%, #fff8d6 45%, #ffe07a 60%, #ffab1f 100%) 0 0 / 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 #7a3a06) drop-shadow(0 8px 18px rgb(255 171 31 / 35%));
  animation: boot-shine 2.4s ease-in-out infinite;
}
.boot__line {
  margin: -4px 0 6px;
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: #cfc2f5;
}
.boot__line::after {
  content: '';
  display: inline-block;
  width: 1.2em;
  text-align: start;
  animation: boot-dots 1.2s steps(4, end) infinite;
}
.boot__bar {
  --p: 0;
  position: relative;
  width: min(260px, 70vw);
  height: 12px;
  border-radius: 99px;
  overflow: hidden;
  background: rgb(255 255 255 / 12%);
  box-shadow: inset 0 2px 3px rgb(0 0 0 / 30%);
}
.boot__bar::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform: scaleX(var(--p));
  transform-origin: left center;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 45%) 0 40%, transparent 40%),
    linear-gradient(90deg, #ffab1f, #ffc533 60%, #ffe07a);
}
[data-rtl] .boot__bar::before {
  transform-origin: right center;
}
/* Le pourcentage sous la barre (boot.js l'écrit) : chiffres de même largeur, pour qu'il ne tremble pas en montant. */
.boot__pct {
  margin: -6px 0 0;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: #ffe07a;
}
/* Un reflet qui passe sur la barre. */
.boot__bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgb(255 255 255 / 55%) 50%, transparent 70%) -100% 0 / 60% 100% no-repeat;
  animation: boot-sweep 1.6s ease-in-out infinite;
}

/* ---------- Les mouvements ---------- */
/* Pose k pleine au début de son quart de tour ; elle apparaît pendant les 14 % qui précèdent, par-dessus la précédente. */
@keyframes boot-f1 {
  0%,
  25% {
    opacity: 1;
  }
  25.01%,
  100% {
    opacity: 0;
  }
}
@keyframes boot-f2 {
  0%,
  11% {
    opacity: 0;
  }
  25%,
  50% {
    opacity: 1;
  }
  50.01%,
  100% {
    opacity: 0;
  }
}
@keyframes boot-f3 {
  0%,
  36% {
    opacity: 0;
  }
  50%,
  75% {
    opacity: 1;
  }
  75.01%,
  100% {
    opacity: 0;
  }
}
@keyframes boot-f4 {
  0%,
  61% {
    opacity: 0;
  }
  75%,
  100% {
    opacity: 1;
  }
}
@keyframes boot-f5 {
  0%,
  86% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
/* Le départ : assis, il se ramasse un instant, puis la course prend sa place (elle apparaît pleine sous lui, il s'efface). */
@keyframes boot-sit {
  0%,
  35% {
    opacity: 1;
    scale: 1 1;
  }
  55% {
    opacity: 1;
    scale: 1.05 0.93;
  }
  80%,
  100% {
    opacity: 0;
    scale: 1 1.02;
  }
}
@keyframes boot-run-in {
  0% {
    opacity: 0;
  }
  55%,
  100% {
    opacity: 1;
  }
}
/* La sortie : chaque pose pleine au début de son tiers, apparue par-dessus la précédente. */
@keyframes boot-d1 {
  0%,
  45% {
    opacity: 1;
  }
  45.01%,
  100% {
    opacity: 0;
  }
}
@keyframes boot-d2 {
  0%,
  25% {
    opacity: 0;
  }
  45%,
  78% {
    opacity: 1;
  }
  78.01%,
  100% {
    opacity: 0;
  }
}
@keyframes boot-d3 {
  0%,
  58% {
    opacity: 0;
  }
  78%,
  100% {
    opacity: 1;
  }
}
@keyframes boot-zoom {
  0% {
    translate: 0 -4px;
  }
  30% {
    translate: -14px 0;
  }
  100% {
    translate: 110vw -12px;
  }
}
/* En l'air pendant les poses aux pattes tendues (1 et 3), au sol pendant les poses ramassées (2 et 4). */
@keyframes boot-bob {
  0%,
  100% {
    translate: 0 -6px;
  }
  50% {
    translate: 0 0;
  }
}
@keyframes boot-dust {
  0% {
    opacity: 0.9;
    translate: 0 0;
    scale: 0.4;
  }
  100% {
    opacity: 0;
    translate: -46px -10px;
    scale: 1.4;
  }
}
@keyframes boot-glow {
  0%,
  100% {
    opacity: 0.7;
    scale: 0.88 0.9;
  }
  50% {
    opacity: 1;
    scale: 1.04 1;
  }
}
@keyframes boot-ground {
  to {
    background-position: -44px 50%;
  }
}
@keyframes boot-gem {
  0% {
    opacity: 0;
    translate: 180px 0;
    scale: 0.7;
    rotate: 0deg;
  }
  8% {
    opacity: 1;
    scale: 1;
  }
  22% {
    translate: 140px -26px;
  }
  38% {
    translate: 100px 0;
  }
  54% {
    translate: 60px -22px;
  }
  70% {
    translate: 24px 0;
    scale: 1;
    opacity: 1;
  }
  80% {
    translate: 0 -10px;
    scale: 1.6;
    opacity: 0;
    rotate: -30deg;
  }
  100% {
    opacity: 0;
    translate: 0 -10px;
  }
}
@keyframes boot-twinkle {
  from {
    opacity: 0.25;
  }
  to {
    opacity: 0.9;
  }
}
@keyframes boot-rise {
  from {
    opacity: 0;
    translate: 0 14px;
  }
}
@keyframes boot-shine {
  0% {
    background-position: 100% 0;
  }
  60%,
  100% {
    background-position: 0% 0;
  }
}
@keyframes boot-dots {
  0% {
    content: '';
  }
  25% {
    content: '.';
  }
  50% {
    content: '..';
  }
  75%,
  100% {
    content: '...';
  }
}
@keyframes boot-sweep {
  to {
    background-position: 250% 0;
  }
}
@keyframes boot-failsafe {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* Moins d'animations demandées : le renard reste posé, sans gemmes, poussière ni scintillement ; la barre reste. */
@media (prefers-reduced-motion: reduce) {
  .boot *,
  .boot *::before,
  .boot *::after,
  .boot::before,
  .boot::after {
    animation: none !important;
  }
  .boot__sit {
    display: none;
  }
  .boot__run,
  .boot__run img:nth-child(1) {
    opacity: 1;
  }
  .boot__gem,
  .boot__dust,
  .boot__line::after {
    display: none;
  }
}
