/* Grille de Sudoku et tout ce qui l'entoure pendant une partie : pavé, commandes,
   indice, écran de fin. Chargé par le solo, le défi, le multijoueur et les pages
   annexes, APRÈS le socle fichiers-partages-des-jeux/css/jeu.css (fond, carte, boutons,
   overlay, barre du haut) : ne rien redéfinir ici de ce qu'il fournit déjà.

   La taille d'une case est une seule variable, --case, calculée sur la largeur de
   l'écran : la grille occupe toute la largeur d'un téléphone et s'arrête à 54 px par
   case sur un grand écran. Tout le reste (chiffres, notes, pavé) en découle. */

/* L'attribut hidden doit l'emporter sur le display des boutons et des blocs du socle */
[hidden] { display: none !important; }

.su-jeu {
  --n: 9;
  --bw: 3;
  --marge: 28px;
  --case-max: 54px;
  --case: min(calc((100vw - var(--marge)) / var(--n)), var(--case-max));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 12px;
  margin: 0 auto 14px;
}

.su-taille-6 { --n: 6; --case-max: 64px; }
.su-taille-4 { --n: 4; --bw: 2; --case-max: 76px; }

/* --- La grille ------------------------------------------------------------ */
.su-grille {
  display: grid;
  grid-template-columns: repeat(var(--n), var(--case));
  grid-auto-rows: var(--case);
  border: 2px solid var(--color-mid);
  border-radius: 6px;
  background: var(--surface-0);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.su-case {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--case);
  height: var(--case);
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface-1);
  color: var(--color-light);
  font-family: 'Inter', sans-serif;
  font-size: calc(var(--case) * 0.52);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.su-case:nth-child(9n) { border-right: 0; }
.su-taille-6 .su-case:nth-child(6n) { border-right: 0; }
.su-taille-4 .su-case:nth-child(4n) { border-right: 0; }
.su-taille-9 .su-case:nth-child(n + 73),
.su-taille-6 .su-case:nth-child(n + 31),
.su-taille-4 .su-case:nth-child(n + 13) { border-bottom: 0; }

/* Les blocs : un filet épais, et un bloc sur deux un ton plus clair */
.su-case.su-bord-droit { border-right: 2px solid color-mix(in srgb, var(--color-light) 60%, var(--surface-0)); }
.su-case.su-bord-bas { border-bottom: 2px solid color-mix(in srgb, var(--color-light) 60%, var(--surface-0)); }
.su-case.su-bloc-alt { background: color-mix(in srgb, #fff 5%, var(--surface-1)); }

.su-case.su-donnee {
  color: #f0f3f6;
  font-weight: 800;
}

.su-case.su-voisine { background: color-mix(in srgb, var(--color-light) 9%, var(--surface-1)); }
.su-case.su-meme { background: color-mix(in srgb, var(--color-light) 26%, var(--surface-1)); }
.su-case.su-selection {
  background: color-mix(in srgb, var(--color-mid) 48%, var(--surface-1));
  box-shadow: inset 0 0 0 2px var(--color-light);
}

.su-case:focus-visible {
  outline: 2px solid #f0f3f6;
  outline-offset: -3px;
  z-index: 1;
}

.su-case.su-fausse,
.su-case.su-conflit {
  color: #f08a8a;
  background: color-mix(in srgb, #d04848 26%, var(--surface-1));
}

.su-case.su-attente { color: var(--texte-faible); }
.su-case.su-autre { color: #7fc6a0; }
.su-case.su-revelee { color: #d2973a; }

.su-case.su-indice-case { box-shadow: inset 0 0 0 2px #d2973a; }
.su-case.su-indice-cible { background: color-mix(in srgb, #d2973a 22%, var(--surface-1)); }

@keyframes su-secousse {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.su-case.su-secousse { animation: su-secousse 0.25s 1; }

/* Killer : contour en pointillé de chaque cage, et sa somme dans le coin de sa première case */
.su-case.su-cage-h::after,
.su-case.su-cage-b::after,
.su-case.su-cage-g::after,
.su-case.su-cage-d::after {
  content: '';
  position: absolute;
  inset: 3px;
  border: 0 dashed color-mix(in srgb, #d2973a 75%, transparent);
  pointer-events: none;
}

.su-case.su-cage-h::after { border-top-width: 1.5px; }
.su-case.su-cage-b::after { border-bottom-width: 1.5px; }
.su-case.su-cage-g::after { border-left-width: 1.5px; }
.su-case.su-cage-d::after { border-right-width: 1.5px; }

/* Les quatre classes se cumulent sur une même case : un seul pseudo-élément porte tous les côtés */
.su-case.su-cage-h.su-cage-b::after { border-top-width: 1.5px; border-bottom-width: 1.5px; }
.su-case.su-cage-g.su-cage-d::after { border-left-width: 1.5px; border-right-width: 1.5px; }

.su-case[data-somme]::before {
  content: attr(data-somme);
  position: absolute;
  top: 3px;
  left: 4px;
  padding: 0 2px;
  background: inherit;
  font-size: max(9px, calc(var(--case) * 0.22));
  font-weight: 700;
  line-height: 1;
  color: #e3b877;
  z-index: 1;
}
/* Notes : un chiffre par emplacement, comme au crayon dans la case */
.su-notes {
  position: absolute;
  inset: 1px;
  display: grid;
  grid-template-columns: repeat(var(--bw), 1fr);
  align-items: center;
  justify-items: center;
  pointer-events: none;
}

.su-note {
  font-size: max(9px, calc(var(--case) * 0.27));
  font-weight: 600;
  line-height: 1;
  color: var(--texte-doux);
}

.su-note.su-note-meme {
  color: #fff;
  font-weight: 800;
}

/* Pause : la grille reste en place mais illisible */
.su-masquee .su-grille { filter: blur(14px); pointer-events: none; }

/* --- Pavé et commandes ---------------------------------------------------- */
.su-panneau {
  width: 100%;
  max-width: calc(var(--case) * var(--n) + 4px);
  display: grid;
  gap: 10px;
}

.su-pave {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: 4px;
}

.su-touche {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 50px;
  padding: 4px 0;
  border: 1px solid var(--line-forte);
  border-radius: 6px;
  background: var(--surface-2);
  color: #f0f3f6;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}

.su-touche-chiffre {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}

.su-touche-reste {
  min-height: 0.7rem;
  font-size: 0.62rem;
  line-height: 1;
  color: var(--texte-faible);
}

.su-touche:hover { border-color: var(--color-light); }
.su-touche.su-touche-armee {
  background: var(--color-btn1);
  border-color: var(--color-light);
}

.su-touche.su-touche-armee .su-touche-reste { color: #f0f3f6; }
.su-touche.su-touche-finie { opacity: 0.35; }

.su-commandes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
  gap: 4px;
}

.su-cmd {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 5px 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--texte);
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}

.su-cmd-icone {
  font-size: 1.15rem;
  line-height: 1;
}

.su-cmd-libelle {
  font-size: 0.64rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--texte-doux);
  text-align: center;
}

.su-cmd:hover:not(:disabled) { border-color: var(--color-light); background: var(--surface-2); }
.su-cmd:disabled { opacity: 0.4; cursor: not-allowed; }

.su-cmd.su-cmd-actif {
  background: color-mix(in srgb, var(--color-mid) 34%, var(--surface-2));
  border-color: var(--color-light);
}

.su-cmd.su-cmd-actif .su-cmd-libelle { color: #f0f3f6; }

.su-touche:focus-visible,
.su-cmd:focus-visible {
  outline: 2px solid #f0f3f6;
  outline-offset: 2px;
}

.su-message {
  margin: 0;
  font-size: 0.8rem;
  color: #d2973a;
  text-align: center;
}

.su-fige .su-touche,
.su-fige .su-cmd { pointer-events: none; opacity: 0.45; }

/* --- Indice ---------------------------------------------------------------- */
.su-indice {
  width: 100%;
  max-width: 560px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid #d2973a;
  border-radius: 4px;
  background: var(--surface-2);
  text-align: left;
}

.su-indice-nom {
  display: block;
  margin-bottom: 4px;
  font-size: 0.86rem;
  color: #f0f3f6;
}

.su-indice-texte {
  margin: 0 0 10px;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--texte-doux);
}

.su-indice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* --- Écran large : le pavé passe à droite de la grille --------------------- */
@media (min-width: 860px) {

  .su-jeu.su-taille-9 {
    grid-template-columns: auto 232px;
    align-items: start;
    justify-content: center;
    column-gap: 20px;
  }

  .su-taille-9 .su-pave {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .su-taille-9 .su-touche { min-height: 62px; }
  .su-taille-9 .su-touche-chiffre { font-size: 1.5rem; }
  .su-taille-9 .su-commandes { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .su-taille-9 .su-indice { grid-column: 1 / -1; justify-self: center; }
}

/* --- Téléphone couché : grille à gauche, pavé à droite, tout tient à l'écran - */
@media (orientation: landscape) and (max-height: 520px) {

  .su-jeu.su-taille-9 {
    --case: min(calc((100vh - 24px) / 9), 44px);
    grid-template-columns: auto minmax(180px, 250px);
    align-items: start;
    justify-content: center;
    column-gap: 14px;
  }

  .su-taille-9 .su-pave { grid-template-columns: repeat(3, 1fr); }
  .su-taille-9 .su-touche { min-height: 44px; }
  .su-taille-9 .su-commandes { grid-template-columns: repeat(3, 1fr); }
  .su-taille-9 .su-cmd { min-height: 40px; }
  .su-taille-9 .su-indice { grid-column: 1 / -1; }
}

/* --- Page de jeu ------------------------------------------------------------ */

/* Sur téléphone la carte colle presque aux bords : chaque pixel va à la grille */
@media (max-width: 600px) {

  body.page-grille {
    padding-left: 5px;
    padding-right: 5px;
  }

  body.page-grille #app {
    padding-left: 6px;
    padding-right: 6px;
  }

  /* La bannière déborde de la carte par des marges négatives calées sur son retrait
     habituel : avec un retrait de 6 px, elles doivent suivre, sinon la page défile de côté */
  body.page-grille .jeu-banner {
    margin-left: -6px;
    margin-right: -6px;
  }
}

.top-bar-outils {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  min-width: 60px;
}

.su-outil {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--texte);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
}

.su-outil:hover { border-color: var(--color-light); }
.su-outil[aria-pressed="false"] { opacity: 0.5; }

/* Choix du niveau, sur la page de jeu elle-même */
.su-niveaux {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 0 0 12px;
}

.su-niveau {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--texte-doux);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
}

.su-niveau:hover {
  border-color: var(--color-mid);
  color: var(--texte);
}

.su-niveau.actif {
  background: color-mix(in srgb, var(--color-light) 14%, var(--surface-2));
  border-color: var(--color-light);
  color: #f0f3f6;
}

.info-bar .erreurs { color: #e08a8a; }
.info-bar .info-malus {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--texte-faible);
}

.su-sous-plateau {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 16px;
}

.su-sous-plateau .btn {
  font-size: 0.82rem;
  padding: 10px 16px;
  min-height: 42px;
}

.su-reglages {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  margin: 0 0 14px;
  font-size: 0.8rem;
  color: var(--texte-doux);
}

.su-reglages label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  cursor: pointer;
}

.su-reglages input { accent-color: var(--color-mid); width: 16px; height: 16px; }

.su-reglages-note {
  flex-basis: 100%;
  text-align: center;
  font-size: 0.74rem;
  color: var(--texte-faible);
}

.su-chargement {
  padding: 30px 0;
  font-size: 0.9rem;
  color: var(--texte-doux);
}

.su-pause-voile {
  margin: 0 0 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 0.88rem;
  color: var(--texte-doux);
}

/* Texte sous le jeu (pages de niveau, annexes) */
.su-texte {
  margin: 8px 0 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  text-align: left;
}

.su-texte h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: #f0f3f6;
  margin: 18px 0 8px;
}

.su-texte h2:first-child { margin-top: 0; }

.su-texte h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f0f3f6;
  margin: 14px 0 6px;
}

.su-texte p,
.su-texte li {
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--texte-doux);
}

.su-texte p { margin-bottom: 10px; }
.su-texte ul, .su-texte ol { margin: 0 0 12px 20px; }
.su-texte a { color: var(--color-light); }
.su-texte strong { color: var(--texte); }

.su-tableau {
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0 14px;
  font-size: 0.84rem;
}

.su-tableau th,
.su-tableau td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: left;
  color: var(--texte-doux);
  vertical-align: top;
}

.su-tableau th {
  background: var(--surface-2);
  color: #f0f3f6;
  font-weight: 700;
}

.su-tableau-defile { overflow-x: auto; }

.su-intro {
  margin: 0 0 14px;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--texte-doux);
}

/* --- Écran de fin ------------------------------------------------------------ */
.overlay-box {
  position: relative;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.overlay-fermer {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-forte);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--texte);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.overlay-fermer:hover { border-color: var(--color-light); }

.overlay-box .win { color: #64ab7c; }
.overlay-box .lose { color: #d07070; }

.overlay-box p {
  color: var(--texte-doux);
  font-size: 0.9rem;
  margin-bottom: 14px;
}

.overlay-box .fin-rang {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: #f0f3f6;
}

.fin-detail {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  margin: 0 0 14px;
  font-size: 0.84rem;
  color: var(--texte-doux);
}

.fin-detail strong { color: #f0f3f6; font-variant-numeric: tabular-nums; }

#cta-inscription {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--color-mid);
  border-radius: 4px;
  padding: 14px;
  margin: 14px 0;
  text-align: left;
}

.cta-rang {
  font-family: var(--font-display);
  font-size: 1.05rem !important;
  font-weight: 700;
  color: #f0f3f6 !important;
  margin-bottom: 6px !important;
}

.cta-score-msg {
  font-size: 0.85rem !important;
  margin-bottom: 12px !important;
}

.cta-auth-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.cta-auth-btns .btn {
  font-size: 0.85rem;
  padding: 9px 18px;
}

.overlay-btns .btn { min-height: 44px; }

.su-confetti {
  position: fixed;
  top: -12px;
  z-index: 1100;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  pointer-events: none;
  animation: su-chute 3s ease-in forwards;
}

@keyframes su-chute {
  to {
    transform: translateY(110vh) rotate(540deg);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .su-case.su-secousse { animation: none; }
}
