/* La Quête du Cavalier — classement en ligne : formulaire d'inscription ou de reprise d'un
   profil, profil dans les paramètres, bloc « Classement » de la fenêtre de victoire. */

/* ---------- Formulaire d'inscription ou de reprise d'un profil ---------- */

.join {
  display: grid;
  gap: 8px;
  text-align: left;
}

.join__intro {
  margin: 0 0 2px;
  line-height: 1.45;
}

.join__label {
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 650;
}

/* 16 px au moins : en dessous, Safari sur iPhone zoome sur le champ en le touchant. */
.join__input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

.join__input[aria-invalid="true"] { border-color: var(--danger); }
.join__input[readonly] { opacity: 0.7; }

.join__input--code,
.profile__code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.06em;
}

.join__input--code { text-transform: uppercase; }

.join__hint {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
  line-height: 1.4;
}

.join__error {
  margin: 0;
  color: var(--danger);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.4;
}

.join__error:empty { display: none; }

.join__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.join__actions .btn--gold { flex: 1 1 auto; }
.join[aria-busy] .btn--gold { cursor: progress; }

/* Passer de l'inscription à la reprise d'un profil, et inversement : un lien discret. */
.join__switch {
  justify-self: start;
  min-height: 40px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Inscription ou reprise réussie, à la victoire : bienvenue et rappel du code. */
.join__done {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--gold-soft);
  font-weight: 600;
  line-height: 1.45;
  text-align: left;
}

/* ---------- Bloc « Classement » de la fenêtre de victoire ---------- */

.victory__ranking {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  text-align: left;
}

.victory__ranking-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
}

.victory__ranking-title .icon {
  width: 20px;
  height: 20px;
  color: var(--star-edge);
}

/* ---------- Profil, dans les paramètres ---------- */

.profile {
  display: grid;
  gap: 8px;
}

.profile__notice {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--gold-soft);
  font-weight: 600;
  line-height: 1.45;
}

.profile__notice:empty { display: none; }

.profile__pseudo {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 0;
}

.profile__label {
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 650;
}

.profile__name {
  font-size: 1.1rem;
  overflow-wrap: anywhere;
}

.profile__code-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.profile__code {
  flex: 1 1 13em;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1rem;
}

.btn--small {
  padding: 0 12px;
  font-size: 0.85rem;
}

.profile__help {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.45;
}

.profile__status {
  margin: 0;
  color: var(--success);
  font-size: 0.86rem;
  font-weight: 600;
}

.profile__status:empty { display: none; }

.profile__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* « Voir le classement », depuis la fenêtre de victoire : un lien discret, comme celui du
   formulaire. Depuis le choix du niveau : un bouton, sous la présentation. */
.victory__see-ranking {
  justify-self: start;
  min-height: 40px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.levels-ranking { margin: 0 0 16px; }
.levels-ranking .icon { color: var(--star-edge); }

/* ---------- Classement d'un niveau : à la victoire et dans l'écran Classement ---------- */

.level-board {
  --chart-h: 56px;
  display: grid;
  gap: 8px;
  /* Place réservée pendant l'attente : rien ne bouge quand les données arrivent. */
  min-height: 132px;
  align-content: start;
}

.level-board__record {
  margin: 0;
  font-weight: 650;
  line-height: 1.4;
}

.level-board__note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.level-board__you {
  position: relative;
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.45;
}

/* Record battu, détenu ou égalé : une pastille dorée, comme le record de sauts de l'appareil. */
.level-board__you.is-new-record,
.level-board__you.is-hold,
.level-board__you.is-tie {
  justify-self: start;
  padding: 5px 12px;
  border-radius: 12px;
  background: var(--gold-soft);
  color: var(--ink);
  font-weight: 700;
}

.level-board__you.is-celebrating { animation: pop 0.55s var(--ease-bounce) both; }

/* Histogramme : une colonne par nombre de sauts, les étiquettes du record et du plus long
   parcours sous leur barre. Barres et étiquettes partagent la même grille (--bins colonnes). */
.level-board__chart {
  display: grid;
  gap: 4px;
  margin: 0;
}

.level-board__bars,
.level-board__axis {
  display: grid;
  grid-template-columns: repeat(var(--bins, 8), minmax(4px, 26px));
  justify-content: center;
  column-gap: 3px;
}

.level-board__bars {
  grid-template-rows: var(--chart-h);
  align-items: end;
  border-bottom: 2px solid var(--line-strong);
}

.level-board__bar {
  height: calc(var(--h) * var(--chart-h));
  min-height: 4px;
  border-radius: 5px 5px 0 0;
  background: color-mix(in srgb, var(--ink-soft) 38%, transparent);
}

.level-board__bar.is-empty { min-height: 0; }
.level-board__bar.is-record { background: color-mix(in srgb, var(--star-edge) 55%, transparent); }

.level-board__bar.is-you {
  background: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-soft);
}

.level-board__axis {
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.level-board__axis span {
  grid-row: 1;
  text-align: center;
  white-space: nowrap;
}

/* Une étiquette plus large que sa colonne déborde vers l'intérieur du graphique. */
.level-board__axis span:first-child { grid-column: 1; }
.level-board__axis span:first-child:not(:only-child) { justify-self: start; }
.level-board__axis span:last-child:not(:first-child) { grid-column: -2; justify-self: end; }

.level-board__finders {
  display: grid;
  gap: 4px;
}

.level-board__finders-title {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 650;
}

.level-board__finders-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding-left: 1.6em;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* Attente : la forme du bloc, qui respire doucement. */
.level-board__skeleton {
  display: grid;
  gap: 10px;
}

.level-board__ghost-line {
  width: 80%;
  height: 14px;
  border-radius: 7px;
  background: var(--line);
  animation: ghost 1.1s ease-in-out infinite alternate;
}

.level-board__ghost-line.is-short { width: 55%; }

.level-board__ghost-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  height: var(--chart-h);
}

.level-board__ghost-bar {
  width: 22px;
  height: calc(var(--h) * var(--chart-h));
  border-radius: 5px 5px 0 0;
  background: var(--line);
  animation: ghost 1.1s ease-in-out infinite alternate;
}

@keyframes ghost {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

/* Nouveau record : des éclats d'or jaillissent de la pastille. */
.level-board__burst {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}

.level-board__spark {
  position: absolute;
  width: 7px;
  height: 7px;
  margin: -3.5px;
  border-radius: 2px;
  background: var(--c);
  animation: spark 0.9s var(--ease) var(--delay) both;
}

@keyframes spark {
  from { opacity: 1; transform: translate(0, 0) scale(0.4) rotate(0deg); }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1) rotate(220deg); }
}

/* ---------- Écran Classement ---------- */

.ranking-screen {
  width: min(100vw - 20px, 560px);
  max-height: min(100vh - 20px, 860px); /* repli sans dvh, voir .sheet */
  max-height: min(100dvh - 20px, 860px);
}

.ranking-screen__title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ranking-screen__title .icon {
  width: 26px;
  height: 26px;
  color: var(--star-edge);
}

.ranking-screen .dialog-body {
  display: grid;
  gap: 18px;
}

/* Deux onglets, « Général » et « Niveau » : l'onglet choisi est cerclé d'or. */
.ranking-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.ranking-tab {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-soft);
  font-weight: 700;
  cursor: pointer;
}

.ranking-tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--gold);
}

.ranking-screen__panel {
  display: grid;
  gap: 8px;
}

.ranking-screen__rule {
  margin: 0 0 6px;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.45;
}

.ranking-screen__label {
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 650;
}

.ranking-screen__select {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

.ranking-screen .level-board {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.ranking-screen__profile {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

/* ---------- Classement général ---------- */

.general-board {
  display: grid;
  gap: 10px;
  min-height: 160px;
  align-content: start;
}

.general-board__note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.45;
}

.general-board__table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

/* Largeurs, rembourrage compris : à 360 px, il reste au pseudo une douzaine de caractères. */
.general-board__table th,
.general-board__table td {
  box-sizing: border-box;
  padding: 9px 6px;
}

.general-board__table th {
  padding: 4px;
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.general-board__table td { border-top: 1px solid var(--line); }

/* En rem : la ligne d'en-tête, plus petite, fixe la largeur des colonnes (table-layout: fixed). */
.general-board__rank { width: 2.6rem; }
.general-board__gap { width: 3.4rem; text-align: right !important; }
.general-board__levels { width: 6rem; overflow: hidden; text-align: right !important; white-space: nowrap; }
td.general-board__levels { font-size: 0.86em; }
td.general-board__rank { font-weight: 700; }
.general-board__rank[data-medal="1"] { color: var(--star-edge); }
.general-board__rank[data-medal="2"] { color: color-mix(in srgb, var(--ink-soft) 85%, var(--surface)); }
.general-board__rank[data-medal="3"] { color: color-mix(in srgb, #a0612d 80%, var(--ink)); }

/* Pseudo et badge « vous » : le pseudo se coupe d'une ellipse, le badge reste. */
.general-board__name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.general-board__pseudo {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sa propre ligne : le pseudo entier, quitte à passer à la ligne, le badge à la suite. */
.general-board__table tr.is-me .general-board__name { flex-wrap: wrap; }

.general-board__table tr.is-me .general-board__pseudo {
  overflow: visible;
  white-space: normal;
  overflow-wrap: anywhere;
}

.general-board__you {
  flex: none;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--on-gold);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* La ligne du joueur, en évidence : un bandeau doré. */
.general-board__table tr.is-me td {
  border-top-color: transparent;
  background: var(--gold-soft);
  font-weight: 700;
}

.general-board__table tr.is-me td:first-child { border-radius: 10px 0 0 10px; }
.general-board__table tr.is-me td:last-child { border-radius: 0 10px 10px 0; }
.general-board__table tr.is-me + tr td { border-top-color: transparent; }

.general-board__separator td {
  padding-block: 0;
  border-top: 0 !important;
  color: var(--ink-soft);
  text-align: center;
}

.general-board__skeleton {
  display: grid;
  gap: 8px;
}

.general-board__ghost-row {
  height: 34px;
  border-radius: 10px;
  background: var(--line);
  animation: ghost 1.1s ease-in-out infinite alternate;
}
