/* Badges de progression de « Ma mémoire » (public/memory-badges.js). Mêmes classes partout :
   badge compact à côté d'un nom, popover, carte détaillée du profil. */

/* Badge compact agrandi ; les lignes avec avatar reprennent son diamètre. */
.memory-badge--compact {
  --memory-badge-size: 32px;
  position: relative;
  /* Un <button> n'hérite pas de la police : sans cela, 1.1em suivrait la taille du navigateur et
     non celle du nom. */
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: var(--memory-badge-size);
  height: var(--memory-badge-size);
  /* Marges verticales négatives : la boîte de mise en page reste haute de 1em même quand le visuel
     dépasse (minimum 18 px dans une ligne de 13 px) — l'interligne du texte n'est jamais agrandi. */
  margin: calc((1em - var(--memory-badge-size)) / 2) 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  vertical-align: middle;
  line-height: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
/* Zone tactile élargie sans effet sur la mise en page (cible confortable au doigt). */
.memory-badge--compact::before {
  content: "";
  position: absolute;
  inset: -9px;
  border-radius: 50%;
}
.memory-badge--compact:focus { outline: none; }
.memory-badge--compact:focus-visible {
  outline: 2px solid #2f7fa3;
  outline-offset: 2px;
}
/* Visuel du rang affiché tel quel, entier, dans le carré du badge (aucun recadrage). */
.memory-badge-visual {
  display: block;
}
.memory-badge-visual-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}
.memory-badge-image {
  width: 100%;
  height: 100%;
}

/* Popover légère, fixe dans la fenêtre, positionnée par le script près du badge. */
.memory-badge-popover {
  position: fixed;
  z-index: 300200;
  box-sizing: border-box;
  max-width: min(260px, calc(100vw - 24px));
  padding: 10px 13px 11px;
  border: 1px solid #e1e6e8;
  border-radius: 12px;
  background: #fff;
  color: #3c4a52;
  box-shadow: 0 10px 28px rgba(28, 38, 44, 0.18);
  font-family: var(--font-ui, system-ui, -apple-system, sans-serif);
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.memory-badge-popover-name {
  color: #1c262c;
  font-size: 15px;
  font-weight: 700;
}
.memory-badge-popover-threshold { font-weight: 600; }
.memory-badge-popover-description { color: #6b7a82; }

/* Carte détaillée du profil : visuel plus grand, rang, nombre réel, signification. */
.memory-badge-card {
  display: flex;
  align-items: center;
  gap: 14px;
  box-sizing: border-box;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 18px;
  padding: 10px 16px 10px 10px;
  border: 1px solid #e1e6e8;
  border-radius: 14px;
  background: #fff;
  text-align: left;
}
.memory-badge-card { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.memory-badge-card:focus-visible { outline: 2px solid #1c262c; outline-offset: 2px; }
.memory-badge-card-image {
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
}
.memory-badge-card-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}
.memory-badge-card-name {
  color: #1c262c;
  font-size: 1.12em;
  font-weight: 700;
}
.memory-badge-card-count {
  color: #3c4a52;
  font-size: 0.92em;
  font-weight: 600;
}
.memory-badge-card-description {
  color: #6b7a82;
  font-size: 0.88em;
}
@media (max-width: 480px) {
  .memory-badge-card { gap: 11px; padding: 8px 13px 8px 8px; }
  .memory-badge-card-image { width: 60px; height: 60px; }
}

/* Même diamètre que l'avatar de la ligne, sans marge cumulée avec le gap du nom. */
.mon-fil-card-author-topline .memory-badge--compact { --memory-badge-size: 48px; margin-left: 5px; }
.mon-fil-profile-identity-row .memory-badge--compact { --memory-badge-size: 42px; margin-left: 8px; }
.mon-fil-conversation-message .memory-badge--compact { --memory-badge-size: 22px; }
.contribution-social-author .memory-badge--compact { --memory-badge-size: 20px; }

/* Compensation optique du bord transparent du visuel par rapport à l'avatar plein. */
.memory-badge--compact .memory-badge-image {
  transform: scale(1.12);
  transform-origin: center;
}

/* Profil : laisser respirer le nom malgré l'agrandissement optique du badge. */
.profil-page #profil-name-memory-badge .memory-badge--compact {
  margin-left: 10px;
}

/* Fenêtre de récompense ouverte au clic, au-dessus de la page courante. */
dialog.memory-badge-popover {
  inset: 0;
  margin: auto;
  width: min(340px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: 24px;
  align-items: center;
  gap: 10px;
  text-align: center;
  border-radius: 20px;
}
dialog.memory-badge-popover:not([open]) { display: none; }
dialog.memory-badge-popover::backdrop { background: rgba(15, 23, 30, .52); }
.memory-badge-modal-image { width: 180px; height: 180px; flex: 0 0 auto; }
.memory-badge-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #f0f3f5;
  color: #243038;
  font: 26px/1 system-ui, sans-serif;
  cursor: pointer;
}
dialog.memory-badge-popover .memory-badge-popover-name { font-size: 24px; }
.memory-badge-modal-message { margin: 0; color: #52636d; line-height: 1.5; }

/* Déblocage d'un palier : même fenêtre que ci-dessus, entrée animée et bouton « J'ai compris ». */
dialog.memory-badge-unlock[open] {
  display: flex;
  flex-direction: column;
  overflow: visible;
  animation: memory-badge-unlock-pop 520ms cubic-bezier(.2, 1.4, .4, 1) both;
}
dialog.memory-badge-unlock::backdrop {
  animation: memory-badge-unlock-fade 360ms ease-out both;
}
.memory-badge-unlock-kicker {
  color: #a8742a;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.memory-badge-unlock .memory-badge-modal-image {
  position: relative;
  animation: memory-badge-unlock-reveal 900ms cubic-bezier(.2, 1.25, .35, 1) 140ms both;
}
/* Halo doré qui pulse derrière le visuel. */
.memory-badge-unlock .memory-badge-modal-image::before {
  content: "";
  position: absolute;
  inset: -14px;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 214, 128, .75) 0%, rgba(255, 214, 128, 0) 68%);
  animation: memory-badge-unlock-halo 2.4s ease-in-out 700ms infinite both;
}
/* Éclats qui jaillissent du badge à son arrivée. */
.memory-badge-unlock-spark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px;
  border-radius: 50%;
  background: #f5c45e;
  box-shadow: 0 0 8px rgba(245, 196, 94, .9);
  opacity: 0;
  transform: rotate(var(--spark-angle)) translateY(0) scale(.4);
  animation: memory-badge-unlock-spark 900ms ease-out 620ms both;
}
.memory-badge-unlock .memory-badge-popover-name,
.memory-badge-unlock .memory-badge-modal-message,
.memory-badge-unlock .memory-badge-popover-threshold,
.memory-badge-unlock .memory-badge-popover-description,
.memory-badge-unlock-ok {
  animation: memory-badge-unlock-rise 420ms ease-out both;
}
.memory-badge-unlock .memory-badge-popover-name { animation-delay: 700ms; }
.memory-badge-unlock .memory-badge-modal-message { animation-delay: 820ms; }
.memory-badge-unlock .memory-badge-popover-threshold,
.memory-badge-unlock .memory-badge-popover-description { animation-delay: 920ms; }
.memory-badge-unlock-ok {
  margin-top: 8px;
  padding: 11px 26px;
  border: 0;
  border-radius: 999px;
  background: #1c262c;
  color: #fff;
  font: 600 15px/1.2 var(--font-ui, system-ui, -apple-system, sans-serif);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  animation-delay: 1050ms;
}
.memory-badge-unlock-ok:focus { outline: none; }
.memory-badge-unlock-ok:focus-visible { outline: 2px solid #2f7fa3; outline-offset: 2px; }

@keyframes memory-badge-unlock-pop {
  from { opacity: 0; transform: scale(.72) translateY(18px); }
  to { opacity: 1; transform: none; }
}
@keyframes memory-badge-unlock-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes memory-badge-unlock-reveal {
  0% { opacity: 0; transform: scale(.2) rotate(-200deg); }
  70% { opacity: 1; transform: scale(1.12) rotate(8deg); }
  100% { opacity: 1; transform: none; }
}
@keyframes memory-badge-unlock-halo {
  0%, 100% { opacity: .55; transform: scale(.94); }
  50% { opacity: 1; transform: scale(1.06); }
}
@keyframes memory-badge-unlock-spark {
  0% { opacity: 0; transform: rotate(var(--spark-angle)) translateY(0) scale(.4); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: rotate(var(--spark-angle)) translateY(-118px) scale(1); }
}
@keyframes memory-badge-unlock-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  dialog.memory-badge-unlock[open],
  dialog.memory-badge-unlock::backdrop,
  .memory-badge-unlock .memory-badge-modal-image,
  .memory-badge-unlock .memory-badge-modal-image::before,
  .memory-badge-unlock .memory-badge-popover-name,
  .memory-badge-unlock .memory-badge-modal-message,
  .memory-badge-unlock .memory-badge-popover-threshold,
  .memory-badge-unlock .memory-badge-popover-description,
  .memory-badge-unlock-ok { animation: none; }
  .memory-badge-unlock-spark { display: none; }
}
