/* =====================================================================
   RANKING.CSS — Vue Classement (grimoire ouvert, dans une clairière)

   Structure HTML (dans index.html) :
     <section id="ranking-view" class="game-view ranking-view">
       .rank-bg / .rank-glow / .rank-shade / .rank-particles  -> décor
       .rank-tabs                                             -> catégorie + période (bandeau du haut)
       .rank-podium   (page de gauche)  -> top 3
       .rank-list     (page de droite)  -> classement 4+ (défile)
       .rank-me       (ruban en bas, accroché à la reliure) -> position du joueur
     </section>
   Le contenu est généré par js/ranking.js.

   Partis pris de ce redesign (v2, suite au retour "pas fan") :
   - Les noms et scores passent en Montserrat (pas Cinzel) : Cinzel n'a pas de
     bas-de-casse, donc tout texte dans cette police s'affichait en MAJUSCULES
     forcées dès qu'il y avait plus de 2-3 mots → illisible et "cheap" sur une
     longue liste. Cinzel reste réservé aux titres courts (onglets, chiffres
     romains du podium, libellé "TA POSITION").
   - Les lignes de la liste sont des <button> : sans "background" explicite,
     le navigateur leur applique un fond blanc par défaut (c'était le bug des
     rangées "plates" signalé). Ici le fond est explicitement transparent,
     avec juste un filet et une légère teinte, façon registre manuscrit.
   - Le podium troque sa plaque ivoire plate contre une plaquette de laiton
     (avec rivets) et son socle affiche un chiffre romain gravé plutôt qu'un
     badge rond, pour coller à l'esprit "ferrures dorées" du grimoire.
   ===================================================================== */

.ranking-view { overflow: hidden; }

/* ---------- 1. DÉCOR ---------- */
.rank-bg {
  position: absolute; inset: 0;
  background: url('../assets/images/bg-ranking.webp') center 46% / cover no-repeat;
}
/* Lumière qui baigne les pages du livre, respire doucement */
.rank-glow {
  position: absolute; left: 300px; top: 150px; width: 940px; height: 420px; pointer-events: none;
  background: radial-gradient(ellipse 60% 55% at 50% 35%, rgba(255,236,190,.22), transparent 70%);
  mix-blend-mode: screen; animation: rank-breathe 7s ease-in-out infinite;
}
@keyframes rank-breathe { 0%, 100% { opacity: .7; } 50% { opacity: 1; } }
.rank-shade {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(0deg, rgba(4,3,10,.68) 0%, transparent 22%),
    linear-gradient(180deg, rgba(4,3,10,.5) 0%, transparent 18%);
}
.rank-particles { z-index: 1; }
.ranking-view .ol, .rank-modal .ol { stroke: var(--void, #090811); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }

/* Texte "encré" commun aux pages du livre : sépia chaud (plutôt qu'un gris-violet froid, plus "vieux papier") */
.rank-ink { color: #4a3420; text-shadow: 0 1px 0 rgba(255,255,255,.4); }

/* ---------- 2. BANDEAU DU HAUT : catégorie + période ---------- */
.rank-tabs { position: absolute; left: 250px; right: 350px; top: 136px; z-index: 6; display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.rank-cats { display: flex; gap: 10px; }
.rank-cat {
  display: flex; align-items: center; gap: 7px; height: 42px; padding: 0 14px;
  font: 700 12px "Cinzel", serif; color: var(--cream);
  background: rgba(10,7,22,.86); border: 1px solid rgba(216,168,62,.45);
  clip-path: polygon(9px 0, calc(100% - 9px) 0, 100% 9px, 100% 100%, 0 100%, 0 9px);
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.rank-cat svg { width: 18px; height: 18px; }
@media (hover: hover) {
  /* Souris uniquement : au doigt il n'y a pas de survol, l'effet resterait "collé" après un appui */
  .rank-cat:hover { transform: translateY(-2px); border-color: var(--gold-light); }
}
.rank-cat.is-active { color: var(--gold-light); border-color: var(--gold-light); background: linear-gradient(180deg, rgba(88,48,150,.95), rgba(28,16,52,.95)); box-shadow: 0 0 14px rgba(216,168,62,.4), inset 0 0 10px rgba(156,90,197,.35); }

.rank-periods { display: flex; background: rgba(10,7,22,.86); border: 1px solid rgba(216,168,62,.45); clip-path: polygon(9px 0, calc(100% - 9px) 0, 100% 9px, 100% 100%, 0 100%, 0 9px); }
.rank-period { height: 42px; padding: 0 20px; font: 700 12px "Montserrat"; letter-spacing: .5px; color: var(--muted); border-right: 1px solid rgba(216,168,62,.25); transition: color .15s, background .15s; }
.rank-period:last-child { border-right: none; }
.rank-period.is-active { color: var(--gold-light); background: rgba(216,168,62,.18); }
@media (hover: hover) {
  /* Souris uniquement : au doigt il n'y a pas de survol, l'effet resterait "collé" après un appui */
  .rank-period:hover:not(.is-active) { color: var(--cream); }
}

/* ---------- 3. PAGE DE GAUCHE : PODIUM (top 3) ---------- */
.rank-podium {
  position: absolute; left: 280px; top: 222px; width: 390px; height: 300px; z-index: 5;
  display: flex; align-items: flex-end; justify-content: center; gap: 42px; padding: 0 4px 16px;
}
.rank-step { position: relative; display: flex; flex-direction: column; align-items: center; gap: 7px; width: 112px; }
.rank-step[data-place="1"] { order: 2; padding-bottom: 20px; }
.rank-step[data-place="2"] { order: 1; padding-bottom: 6px; }
.rank-step[data-place="3"] { order: 3; padding-bottom: 6px; }

.rank-crown { width: 22px; height: 22px; margin-bottom: -4px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.5)); animation: rank-crown-bob 2.6s ease-in-out infinite; position: relative; z-index: 2; }
@keyframes rank-crown-bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-4px) rotate(3deg); } }
.rank-avatar {
  --tier: #b9c4dd; --tier-glow: rgba(185,196,221,.55);
  position: relative; width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  font: 800 20px "Cinzel", serif; color: #1c1330;
  background: linear-gradient(160deg, var(--tier), color-mix(in srgb, var(--tier) 55%, #241436));
  box-shadow: 0 0 0 2px var(--tier), 0 0 0 4px rgba(9,8,17,.92), 0 0 16px 3px var(--tier-glow);
  animation: rank-pop .5s cubic-bezier(.2,.9,.3,1.25) both;
}
.rank-step[data-place="1"] .rank-avatar { width: 72px; height: 72px; font-size: 24px; }
/* Cadre à deux liserés façon médaillon gravé (un halo qui pulse + un fin cercle fixe) */
.rank-avatar::after { content: ""; position: absolute; inset: -7px; border-radius: 50%; border: 2px solid var(--tier); opacity: 0; animation: rank-halo 2.4s ease-out infinite; }
.rank-avatar::before { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 1px solid rgba(255,225,138,.55); pointer-events: none; }
.rank-step[data-place="1"] .rank-avatar[data-me="1"], .rank-avatar[data-me="1"] { box-shadow: 0 0 0 3px var(--gold-light), 0 0 0 6px rgba(9,8,17,.92), 0 0 24px 5px rgba(255,225,138,.7); }
@keyframes rank-pop  { from { opacity: 0; transform: scale(.5); } to { opacity: 1; transform: scale(1); } }
@keyframes rank-halo { 0% { opacity: .65; transform: scale(.9); } 100% { opacity: 0; transform: scale(1.25); } }

.rank-step[data-place="1"] .rank-avatar { --tier: #ffd76a; --tier-glow: rgba(255,215,106,.65); }
.rank-step[data-place="2"] .rank-avatar { --tier: #cfd8ea; --tier-glow: rgba(207,216,234,.55); }
.rank-step[data-place="3"] .rank-avatar { --tier: #e3a869; --tier-glow: rgba(227,168,105,.55); }

/* Plaquette de laiton gravée sous l'avatar (rivets aux 4 coins), comme une plaque de socle de trophée */
.rank-plaque {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 10px; max-width: 116px;
  background:
    radial-gradient(circle at 5px 5px, rgba(58,34,8,.55) 1.2px, transparent 1.6px),
    radial-gradient(circle at calc(100% - 5px) 5px, rgba(58,34,8,.55) 1.2px, transparent 1.6px),
    radial-gradient(circle at 5px calc(100% - 5px), rgba(58,34,8,.55) 1.2px, transparent 1.6px),
    radial-gradient(circle at calc(100% - 5px) calc(100% - 5px), rgba(58,34,8,.55) 1.2px, transparent 1.6px),
    linear-gradient(180deg, #f3dc9c, #cc9e46 55%, #9c7430);
  border: 1px solid #6b4e1e; border-radius: 2px;
  box-shadow: 0 2px 6px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.4);
}
.rank-step-name { font: 700 12px "Montserrat"; color: #3a2208; max-width: 100px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 0 rgba(255,255,255,.35); }
.rank-step-score { display: flex; align-items: center; gap: 3px; font: 800 12px "Montserrat"; color: #4a2e08; }
.rank-step-score svg { width: 12px; height: 12px; }

/* Socle du podium : chiffre romain gravé directement dans la pierre (pas de badge rapporté) */
.rank-plinth {
  width: 108%; border-radius: 4px 4px 0 0; display: flex; align-items: flex-start; justify-content: center; padding-top: 13px;
  background: linear-gradient(180deg, rgba(60,40,24,.6), rgba(38,24,14,.78));
  border: 1px solid rgba(216,168,62,.55); border-bottom: none;
  box-shadow: inset 0 2px 10px rgba(0,0,0,.4), inset 0 -3px 8px rgba(0,0,0,.3);
}
.rank-plinth span {
  font: 800 19px "Cinzel", serif; letter-spacing: 1px; color: rgba(255,228,160,.92);
  text-shadow: 0 1px 0 rgba(0,0,0,.65), 0 -1px 0 rgba(255,255,255,.12);
}
.rank-step[data-place="1"] .rank-plinth { height: 50px; }
.rank-step[data-place="2"] .rank-plinth { height: 48px; }
.rank-step[data-place="3"] .rank-plinth { height: 48px; }

/* ---------- 4. PAGE DE DROITE : LISTE (4e place et suivantes) ---------- */
.rank-list-wrap { position: absolute; left: 890px; top: 222px; width: 412px; height: 450px; z-index: 5; display: flex; flex-direction: column; }
.rank-list-head {
  display: grid; grid-template-columns: 30px 1fr 86px; gap: 6px; padding: 0 8px 7px; margin-bottom: 4px;
  border-bottom: 1px solid rgba(74,52,32,.45); font: 700 12px "Montserrat"; letter-spacing: 1.2px; opacity: .7;
}
.rank-list-head span:last-child { text-align: right; }
.rank-list { flex: 1; min-height: 0; overflow-y: auto; padding: 2px 6px 6px 2px; scrollbar-width: thin; scrollbar-color: rgba(90,66,40,.5) transparent; }

/* Lignes "registre" : pas de carte pleine, juste un filet + une teinte à peine perceptible */
.rank-row {
  /* width: 100% est nécessaire ici : un <button> ne s'étire pas sur toute la largeur de son parent
     par défaut, même avec display:grid (contrairement à une <div> comme .rank-list-head) — sans ça,
     la ligne ne fait que la largeur de son contenu et la colonne Score ne tombe plus sous l'en-tête. */
  width: 100%; box-sizing: border-box;
  display: grid; grid-template-columns: 30px 1fr 86px; align-items: center; gap: 6px;
  height: 38px; padding: 0 8px; margin: 0; border-radius: 0;
  background: transparent;                              /* <button> sans ceci = fond blanc du navigateur par défaut */
  border-bottom: 1px solid rgba(74,52,32,.22);
  animation: rank-row-in .38s ease both; animation-delay: calc(var(--i) * 45ms);
  transition: background .15s ease, box-shadow .15s ease;
}
.rank-row:nth-child(even) { background: rgba(120,86,40,.055); }
@media (hover: hover) {
  /* Souris uniquement : au doigt il n'y a pas de survol, l'effet resterait "collé" après un appui */
  .rank-row:hover { background: rgba(120,86,40,.14); }
}
.rank-row.is-me {
  background: linear-gradient(90deg, rgba(216,168,62,.24), rgba(216,168,62,.06));
  border-bottom-color: rgba(216,168,62,.55);
  box-shadow: inset 3px 0 0 var(--gold-light);           /* liseré doré, comme un marque-page glissé dans la ligne */
}
@keyframes rank-row-in { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }

.rank-num { font: 700 13px "Montserrat"; text-align: center; opacity: .7; }
.rank-who { display: flex; align-items: center; gap: 6px; min-width: 0; }
.rank-mini {
  --tier: #8a7ba8; flex: none; width: 25px; height: 25px; border-radius: 50%; display: grid; place-items: center;
  font: 800 12px "Cinzel", serif; color: #1c1330; background: var(--tier); box-shadow: 0 0 0 2px rgba(58,46,85,.35);
}
.rank-who b { font: 700 12px "Montserrat"; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-trend { flex: none; width: 10px; height: 10px; justify-self: center; }
.rank-trend.is-up   { color: #2f8f52; }
.rank-trend.is-down { color: #b0394a; transform: rotate(180deg); }
.rank-trend.is-flat { color: #8a7ba8; }
/* Grille à 2 colonnes fixes : la flèche de tendance toujours au même endroit, puis la valeur
   (banane + nombre) alignée sur son propre bord droit. Avant, tendance + valeur formaient un seul
   bloc "justify-content: flex-end" : la largeur du bloc variait selon la flèche et le nombre de
   chiffres, donc rien ne tombait sous "Score" dans l'en-tête ; avec 2 colonnes séparées, chaque
   partie garde sa position d'une ligne à l'autre, comme une vraie colonne de tableau. */
.rank-score { display: grid; grid-template-columns: 14px 1fr; align-items: center; gap: 4px; font: 800 12px "Montserrat"; }
.rank-score-val { display: flex; align-items: center; justify-content: flex-end; gap: 3px; font-variant-numeric: tabular-nums; }
.rank-score svg { width: 12px; height: 12px; }

.rank-empty { margin: auto; text-align: center; font-size: 13px; opacity: .75; padding: 20px; }

/* ---------- 5. RUBAN "TA POSITION" (accroché à la reliure, en bas) ---------- */
.rank-me {
  /* décalé à droite (pas centré) pour ne pas passer sous le médaillon Lobby de la barre du bas */
  position: absolute; right: 911px; bottom: 196px; z-index: 15;
  display: flex; align-items: center; gap: 26px; padding: 10px 22px 10px 14px; min-width: 340px;
  background: linear-gradient(90deg, #2c1a52, #1c1140 60%, #140c30);
  border: 1px solid rgba(216,168,62,.6);
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  box-shadow: 0 10px 24px rgba(0,0,0,.5), 0 0 16px rgba(156,90,197,.3);
}
.rank-me::before { /* petite pointe de ruban sous le bandeau, comme un marque-page */
  content: ""; position: absolute; right: 36px; bottom: -10px;
  border-left: 14px solid transparent; border-right: 14px solid transparent; border-top: 10px solid #140c30;
}
.rank-me-label { font: 700 12px "Montserrat"; letter-spacing: 2px; color: var(--gold-light); }
.rank-me-rank { font: 800 22px "Cinzel", serif; color: var(--cream); }
.rank-me .rank-mini { width: 40px; height: 40px; font-size: 15px; }
.rank-me-info { flex: 1; min-width: 0; }
.rank-me-info b { display: block; font: 700 15px "Montserrat"; color: var(--cream); }
.rank-me-score { display: flex; align-items: center; gap: 5px; font: 800 14px "Montserrat"; color: var(--gold-light); }
.rank-me-score svg { width: 16px; height: 16px; }
.rank-me-trend { display: flex; align-items: center; gap: 4px; font: 700 12px "Montserrat"; color: var(--muted); }
.rank-me-trend svg { width: 12px; height: 12px; }

/* ---------- 6. FENÊTRE DE DÉTAIL (clic sur une ligne) ---------- */
.rank-detail-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 4px; }
.rank-detail-stats div { padding: 10px 6px; text-align: center; background: rgba(0,0,0,.35); border: 1px solid rgba(216,168,62,.25); }
.rank-detail-stats small { display: block; font: 700 12px "Montserrat"; letter-spacing: 1.2px; color: var(--muted); }
.rank-detail-stats b { display: block; margin-top: 4px; font: 700 15px "Cinzel", serif; color: var(--cream); }

/* ---------- 7. ANIMATIONS D'ENTRÉE (pendant la transition) ---------- */
.ranking-view.is-entering .rank-bg { animation: shop-bg-in 1.1s cubic-bezier(.22,.61,.36,1) both; }
.ranking-view.is-entering .rank-tabs { animation: inv-drop .5s cubic-bezier(.22,.61,.36,1) 200ms both; }
.ranking-view.is-entering .rank-step { animation: rank-step-in .55s cubic-bezier(.2,.9,.3,1.15) both; }
.ranking-view.is-entering .rank-step[data-place="2"] { animation-delay: 320ms; }
.ranking-view.is-entering .rank-step[data-place="1"] { animation-delay: 420ms; }
.ranking-view.is-entering .rank-step[data-place="3"] { animation-delay: 520ms; }
.ranking-view.is-entering .rank-row { animation-delay: calc(var(--i) * 45ms + 600ms); }
.ranking-view.is-entering .rank-me { animation: shop-rise .5s ease 850ms both; }
@keyframes rank-step-in { from { opacity: 0; transform: translateY(40px) scale(.9); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .ranking-view *, .rank-modal * { animation: none !important; transition: none !important; }
}
