/* La Quête du Cavalier — dialogues : choix du niveau, victoire et règles. */

/* ---------- Dialogues ---------- */

dialog {
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(12, 16, 25, 0.58);
}

.dialog-card {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

dialog[open] .dialog-card { animation: rise 0.28s var(--ease); }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 12px 8px 20px;
}

.dialog-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
}

.dialog-body {
  padding: 6px 20px 20px;
  overflow: auto;
  overscroll-behavior: contain;
}

.sheet {
  width: min(100vw - 20px, 780px);
  max-height: min(100vh - 20px, 920px);
  max-height: min(100dvh - 20px, 920px);
}

.levels-intro {
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.level-chapters {
  display: grid;
  gap: 18px;
}

.level-chapter__title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.level-card {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: 70px auto 1fr; /* rangée d'aperçu fixe : les noms s'alignent */
  gap: 6px 10px;
  width: 100%;
  height: 100%;
  min-height: 132px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.2s, border-color 0.2s;
}

.level-card:active:not(:disabled) { transform: scale(0.98); }

.level-card[aria-current="true"] {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-soft);
}

.level-card:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.level-card__num {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 600;
  line-height: 1;
}

.level-card__name {
  grid-column: 1 / -1;
  font-weight: 650;
}

.level-card__meta {
  grid-column: 1 / -1;
  align-self: end;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 0.76rem;
}

.level-card__meta .icon {
  width: 15px;
  height: 15px;
}

.level-card.is-done .level-card__status { color: var(--success); }
.level-card__status { display: inline-flex; align-items: center; gap: 4px; }

.preview {
  display: grid;
  grid-template-columns: repeat(var(--cols), 6px);
  grid-auto-rows: 6px;
  gap: 1.5px;
  align-self: start;
}

.preview__cell {
  border-radius: 1.5px;
  background: var(--tile-dark);
}

.preview__cell.is-void { visibility: hidden; }
.preview__cell.is-rock { background: var(--rock); border-radius: 50%; }
.preview__cell.is-start { background: var(--gold); }
.preview__cell.is-milestone { background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--gold); border-radius: 50%; }

.levels-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.victory {
  width: min(100vw - 32px, 430px);
  /* Repli pour les navigateurs sans unité dvh (voir .sheet) : une valeur non reconnue est
     ignorée à l'analyse, donc la ligne vh reste appliquée tant que la ligne dvh ne l'est
     pas encore. */
  max-height: min(100vh - 32px, 640px);
  max-height: min(100dvh - 32px, 640px);
}

.victory .dialog-card {
  /* La carte de victoire n'a pas de zone de défilement dédiée (`.dialog-body`) : sur un
     écran bas (téléphone à l'horizontale…), le contenu peut dépasser `max-height` ci-dessus.
     Rendre la carte elle-même défilante garantit que « Rejouer » et « Choix du niveau »
     restent toujours atteignables, plutôt que coupés sous `overflow: hidden` (règle de
     base de .dialog-card). */
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 22px 20px;
  text-align: center;
  background: radial-gradient(120% 70% at 50% 0%, var(--gold-soft), transparent 62%), var(--surface);
}

.victory__crown {
  /* flex-shrink: 0 — sans cela, un `.dialog-card` en colonne flexible réduit ce cercle à
     la taille de l'icône qu'il contient dès que le contenu dépasse la hauteur disponible. */
  flex-shrink: 0;
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--on-gold);
  box-shadow: 0 10px 26px -10px var(--gold);
  animation: pop 0.55s var(--ease-bounce) both;
}

.victory__crown .icon {
  width: 32px;
  height: 32px;
}

.victory__title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 600;
}

.victory__subtitle {
  margin: 0 0 16px;
  color: var(--ink-soft);
}

.victory__stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.victory__stats li {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Étoiles ---------- */

/* Étoile pleine (gagnée) ou simple contour (à gagner) : la forme distingue les deux,
   pas seulement la couleur. */
.stars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.star {
  display: inline-grid;
  place-items: center;
}

.star .star-art {
  width: 16px;
  height: 16px;
  fill: transparent;
  stroke: var(--star-empty);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.star.is-earned .star-art {
  fill: var(--star);
  stroke: var(--star-edge);
}

.victory__stars {
  /* `.dialog-card` est une colonne flexible dont les enfants s'étirent par défaut : la
     rangée prend toute la largeur, et `justify-content` recentre les étoiles — le
     `text-align: center` hérité de `.dialog-card` n'a aucun effet sur un flex item. */
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0 0 14px;
}

.victory__stars .star-art {
  width: 40px;
  height: 40px;
  stroke-width: 1.2;
  filter: drop-shadow(0 4px 8px var(--gold-soft));
}

/* Chaque étoile apparaît à son tour ; js/ui/sound.js fait tinter les étoiles gagnées
   au même rythme (STAR_DELAY_S = 0.3 s, STAR_STEP_S = 0.18 s). */
.victory__stars .star {
  animation: pop 0.5s var(--ease-bounce) both;
  animation-delay: calc(0.3s + var(--i, 0) * 0.18s);
}

/* base.css réduit la durée des animations, pas leur délai : sans cette règle, les étoiles
   resteraient invisibles (première image de « pop ») pendant le délai avant d'apparaître. */
@media (prefers-reduced-motion: reduce) {
  .victory__stars .star { animation-delay: 0s; }
}

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

/* Chapitre parallèle débloqué : une nouveauté, mise en avant. */
.victory__unlock {
  margin: -6px 0 16px;
  padding: 8px 12px;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: var(--gold-soft);
  font-weight: 650;
}

.swatch--milestone .cell__milestone {
  width: 30px;
  font-size: 0.85rem;
}

.star-rules {
  display: grid;
  gap: 8px;
  margin: 10px 0;
  padding: 0;
  list-style: none;
}

.star-rules li {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 12px;
  align-items: center;
}

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

.rules {
  width: min(100vw - 24px, 560px);
  max-height: min(100vh - 24px, 820px); /* repli sans dvh, voir .sheet */
  max-height: min(100dvh - 24px, 820px);
}

.rules p,
.rules li { line-height: 1.5; }

.rules h3 {
  margin: 18px 0 8px;
  font-family: var(--font-display);
  font-size: 1.15rem;
}

.legend {
  display: grid;
  gap: 10px;
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

.legend li {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  align-items: center;
}

.swatch {
  position: relative;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--tile-light);
  box-shadow: inset 0 -2px 0 var(--tile-edge);
  color: var(--visited-ink);
  font-weight: 700;
}

.swatch--visited,
.swatch--knight { background: linear-gradient(155deg, var(--visited), var(--visited-deep)); }
.swatch--knight { box-shadow: inset 0 0 0 3px var(--gold); }
.swatch--knight .knight-art { width: 30px; height: 30px; }
.swatch--rock { background: var(--rock-bed); }
.swatch--rock .rock-art { width: 30px; height: 30px; }
.swatch--void { border: 2px dashed var(--line-strong); background: transparent; box-shadow: none; }

.swatch--available::after {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.swatch--hint { background: var(--hint-soft); box-shadow: inset 0 0 0 3px var(--hint); }
.swatch--hint .star-art { width: 20px; height: 20px; fill: var(--hint); }

kbd {
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-2);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.82em;
}

/* Les raccourcis clavier n'ont pas de sens sur un écran uniquement tactile. */
@media (hover: none) and (pointer: coarse) {
  .rules__keyboard { display: none; }
}
