/**
 * PlayAwale — L'Elo gagné, à la fin d'une partie
 * -----------------------------------------------------------------------------
 * Le dessin de assets/js/game/elo-gain.js : le nombre qui monte, la pastille
 * « +18 » qui jaillit, la gerbe d'étincelles, la barre vers le prochain cap, le
 * bandeau du record. Voir la section 69.48 de la documentation.
 *
 * LES COULEURS DU SITE : le brun de la marque, l'ambre des badges, le vert des
 * victoires. Rien de criard : la fête tient au MOUVEMENT, pas aux couleurs.
 *
 * @package   PlayAwale
 * @version   2.0
 * @author    Nicolas Lion — Développeur web — https://nlion.fr
 * @copyright 2026 Nicolas Lion
 */

.elo-gain {
  position: relative;
  margin: var(--space-sm) auto var(--space-md);
  padding: var(--space-sm) var(--space-md) var(--space-sm);
  max-width: 19rem;

  text-align: center;

  background: linear-gradient(180deg, rgba(255, 219, 153, 0.35), rgba(240, 225, 209, 0.5));
  border-radius: var(--radius-md);
  box-shadow: inset 0 0 0 1px rgba(216, 164, 78, 0.35);

  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(.2, .9, .3, 1.2);
}

.elo-gain.is-in,
.elo-gain.is-done {
  opacity: 1;
  transform: none;
}

/* Une perte : le même bloc, sans or. */
.elo-gain--down {
  background: rgba(240, 225, 209, 0.5);
  box-shadow: inset 0 0 0 1px rgba(60, 39, 35, 0.1);
}

.elo-gain__label {
  margin: 0;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* LE NOMBRE, ET SA PASTILLE */
.elo-gain__main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  margin: 0.1em 0 0.35em;
}

.elo-gain__value {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 9vw, 2.9rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

/* Le halo qui pulse pendant que le nombre monte. */
.elo-gain--up .elo-gain__value::after {
  content: "";
  position: absolute;
  inset: -0.25em -0.4em;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 201, 102, 0.75), rgba(255, 201, 102, 0));
  opacity: 0;
}

.elo-gain--up .elo-gain__value.is-counting::after {
  animation: elo-halo 0.7s ease-in-out infinite alternate;
}

.elo-gain--up .elo-gain__value.is-landed {
  animation: elo-land 0.45s cubic-bezier(.3, 1.6, .5, 1);
}

@keyframes elo-halo {
  from { opacity: 0.25; transform: scale(0.9); }
  to   { opacity: 0.9;  transform: scale(1.1); }
}

@keyframes elo-land {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.elo-gain__delta {
  display: inline-flex;
  align-items: center;
  padding: 0.18em 0.6em;

  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #fff;

  background: linear-gradient(180deg, #5fb764, var(--color-online));
  border-radius: var(--radius-full);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12), 0 0 0 3px rgba(255, 255, 255, 0.6);

  transform: scale(0);
}

.elo-gain__delta.is-pop {
  animation: elo-pop 0.6s cubic-bezier(.2, 1.8, .4, 1) forwards;
}

.elo-gain--down .elo-gain__delta {
  color: var(--color-danger);
  background: var(--color-danger-surface);
  box-shadow: none;
}

.elo-gain--flat .elo-gain__delta {
  color: var(--color-text-muted);
  background: var(--color-sand-200);
  box-shadow: none;
}

.elo-gain--down .elo-gain__delta.is-pop,
.elo-gain--flat .elo-gain__delta.is-pop {
  animation: elo-appear 0.35s ease forwards;
}

@keyframes elo-pop {
  0%   { transform: scale(0) rotate(-12deg); }
  60%  { transform: scale(1.25) rotate(4deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes elo-appear {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* LA BARRE, VERS LE PROCHAIN CAP */
.elo-gain__bar {
  position: relative;
  height: 8px;
  margin: 0.2em auto 0.35em;
  overflow: hidden;

  background: rgba(60, 39, 35, 0.1);
  border-radius: var(--radius-full);
}

.elo-gain__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--color-brand-amber-deep), var(--color-brand-amber));
}

/* Le reflet qui file sur la barre, pendant qu'elle avance. */
.elo-gain--up .elo-gain__fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.8) 50%, transparent 80%);
  background-size: 200% 100%;
  animation: elo-shine 1.1s linear 2;
}

.elo-gain--down .elo-gain__fill {
  background: var(--color-sand-400);
}

.elo-gain__bar.is-flash {
  animation: elo-flash 0.5s ease;
}

@keyframes elo-shine {
  from { background-position: 150% 0; }
  to   { background-position: -50% 0; }
}

@keyframes elo-flash {
  0%, 100% { box-shadow: none; }
  40%      { box-shadow: 0 0 0 3px rgba(255, 201, 102, 0.9), 0 0 18px rgba(255, 201, 102, 0.9); }
}

.elo-gain__next {
  margin: 0;
  min-height: 1.3em;
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.elo-gain__next.is-cap {
  font-weight: 700;
  color: var(--color-text);
}

/* LE RECORD PERSONNEL */
.elo-gain__record {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin: 0.5em 0 0;
  padding: 0.3em 0.85em;
  overflow: hidden;
  position: relative;

  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--color-text);

  background: linear-gradient(180deg, var(--color-brand-amber-light), var(--color-brand-amber));
  border-radius: var(--radius-full);
  box-shadow: 0 2px 0 var(--color-brand-amber-deep);

  opacity: 0;
  transform: translateY(6px) scale(0.9);
  transition: opacity 0.3s ease, transform 0.45s cubic-bezier(.2, 1.6, .4, 1);
}

.elo-gain__record.is-in {
  opacity: 1;
  transform: none;
}

.elo-gain__record svg {
  width: 1.1em;
  height: 1.1em;
}

.elo-gain__record::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.75) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: elo-shine 1.6s ease-in-out 0.3s 2;
}

/* LES ÉTINCELLES — posées par le script, chacune avec sa direction. */
.elo-gain__spark {
  position: absolute;
  z-index: 2;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: var(--color-brand-amber);
  box-shadow: 0 0 6px rgba(255, 201, 102, 0.9);
  pointer-events: none;
  animation: elo-spark 0.9s cubic-bezier(.15, .7, .3, 1) var(--delai, 0ms) forwards;
}

.elo-gain__spark--star {
  width: 9px;
  height: 9px;
  border-radius: 1px;
  background: #fff3c4;
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
}

@keyframes elo-spark {
  0%   { transform: translate(0, 0) scale(0.4); opacity: 1; }
  70%  { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {

  .elo-gain,
  .elo-gain__record {
    transition: none;
  }

  .elo-gain *,
  .elo-gain *::after {
    animation: none !important;
  }

  .elo-gain__delta {
    transform: none;
  }
}

/* LA VICTOIRE, UN PEU PLUS FÊTÉE — « l'animation de fin quand on gagne peut
   être légèrement augmentée » (69.48). À son arrivée, la fenêtre du bilan se
   pose avec un léger rebond, cerclée d'un halo doré qui pulse deux fois. Rien
   pour une égalité ni pour une défaite. */
.modal__panel.is-victory {
  animation:
    elo-victory-in 0.5s cubic-bezier(.2, 1.4, .4, 1),
    elo-victory-glow 1.6s ease-out 0.2s 2;
}

/* Le halo seul, sans l'entrée : en jeu, la fenêtre est déjà ouverte quand
   l'Elo arrive (solo.js). */
.modal__panel.is-victory-glow {
  animation: elo-victory-glow 1.6s ease-out 2;
}

@keyframes elo-victory-in {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

@keyframes elo-victory-glow {
  0%   { box-shadow: var(--shadow-glow), var(--shadow-raised), 0 0 0 0 rgba(255, 201, 102, 0.75); }
  60%  { box-shadow: var(--shadow-glow), var(--shadow-raised), 0 0 0 14px rgba(255, 201, 102, 0); }
  100% { box-shadow: var(--shadow-glow), var(--shadow-raised), 0 0 0 0 rgba(255, 201, 102, 0); }
}

@media (prefers-reduced-motion: reduce) {

  .modal__panel.is-victory,
  .modal__panel.is-victory-glow {
    animation: none;
  }
}

/* RESPONSIVE — « attention que ça reste responsive » (69.48). La fenêtre de fin
   gagne un bloc : sur un écran bas, il se resserre ; et si la fenêtre dépasse
   malgré tout — un petit téléphone —, elle DÉFILE au lieu d'être coupée en haut.
   Seulement la fenêtre qui porte l'Elo : les autres restent comme avant. */
.modal:has(.elo-gain) {
  overflow-y: auto;
  align-items: safe center;
}

@media (max-height: 700px) {

  .elo-gain {
    margin: var(--space-2xs) auto var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
  }

  .elo-gain__value {
    font-size: clamp(1.8rem, 7vw, 2.3rem);
  }

  .elo-gain__record {
    margin-top: 0.3em;
    font-size: 0.85rem;
  }
}
