/* ==========================================================================
   style.css - Charte graphique commune a toute l'application
   --------------------------------------------------------------------------
   On regroupe ici tout ce qui est partage : couleurs, typographie, boutons,
   en-tete, ecrans, modale. Les styles propres a chaque jeu sont dans jeux.css.

   ASTUCE POUR DEBUTANT : les « variables CSS » (--nom) permettent de definir
   une couleur une seule fois et de la reutiliser partout. Pour changer le
   theme de l'application entiere, il suffit de modifier le bloc :root.
   ========================================================================== */

:root {
  /* --- Palette sombre et sobre ---------------------------------------- */
  --fond:            #10151f;  /* fond general de l'application            */
  --surface:         #182031;  /* cartes, panneaux                         */
  --surface-haute:   #212c42;  /* elements survoles / selectionnes         */
  --bordure:         #2c3852;  /* traits de separation                     */
  --texte:           #e7ecf6;  /* texte principal                          */
  --texte-doux:      #93a1bd;  /* texte secondaire, legendes               */
  --accent:          #5b8cff;  /* couleur d'action principale (bleu)       */
  --accent-clair:    #7ba3ff;
  --succes:          #3ecf8e;  /* validation, mot trouve, victoire         */
  --erreur:          #ff6b6b;  /* erreur, mine, defaite                    */
  --alerte:          #ffc857;  /* indice, drapeau, record                  */

  /* --- Mesures reutilisables ------------------------------------------ */
  --rayon:           12px;     /* arrondi standard des cartes et boutons   */
  --rayon-petit:      8px;
  --espace:          16px;     /* espacement standard                      */
  --largeur-max:    560px;     /* largeur maximale du contenu (lisibilite) */
  --hauteur-entete:  56px;

  color-scheme: dark;
}

/* Reinitialisation legere : la meme base sur tous les navigateurs. */
* {
  box-sizing: border-box;                    /* la largeur inclut bordure et padding */
  -webkit-tap-highlight-color: transparent;  /* pas de flash bleu au tap */
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--fond);
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  /* overscroll-behavior : empeche le « rebond » de la page sur mobile,
     tres genant quand on fait glisser le doigt sur une grille de jeu. */
  overscroll-behavior: none;
}

/* Le contenu des grilles ne doit jamais etre selectionne par erreur */
.grille-sudoku, .grille-mots, .grille-demineur, .grille-memoire, .pave-numerique {
  user-select: none;
  -webkit-user-select: none;
}

h1, h2, h3 { margin: 0; font-weight: 650; line-height: 1.25; }

/* ==========================================================================
   EN-TETE
   ========================================================================== */
.entete {
  position: sticky;            /* reste collee en haut quand on defile */
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  /* La zone « safe-area » evite que le titre passe sous l'encoche des iPhone */
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--hauteur-entete) + env(safe-area-inset-top, 0px));
  background: rgba(16, 21, 31, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--bordure);
}

.titre-appli {
  flex: 1;                     /* occupe l'espace restant : le titre est centre */
  text-align: center;
  font-size: 1.05rem;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Bouton rond de l'en-tete (retour, installer) */
.bouton-icone {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;              /* taille fixe, ne retrecit pas */
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  color: var(--texte);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.bouton-icone:hover  { background: var(--surface-haute); }
.bouton-icone:active { transform: scale(0.92); }
/* Masque : on garde la place occupee pour que le titre reste bien centre */
.bouton-icone[hidden] { display: block; visibility: hidden; }

/* ==========================================================================
   ECRANS
   ========================================================================== */
.contenu {
  max-width: var(--largeur-max);
  margin: 0 auto;
  padding: var(--espace);
  padding-bottom: calc(var(--espace) + env(safe-area-inset-bottom, 0px));
}

.ecran { animation: apparition 0.18s ease-out; }
.ecran[hidden] { display: none; }

@keyframes apparition {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* Respecte le reglage « reduire les animations » du systeme */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.intro         { margin: 0 0 var(--espace); color: var(--texte-doux); text-align: center; }
/* Bandeau « nouvelle version prete » (accueil). :not([hidden]) : sinon
   display: flex annulerait le masquage par l'attribut hidden. */
.bandeau-mise-a-jour:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  margin: 0 0 var(--espace);
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  text-align: center;
}
.bandeau-mise-a-jour p { margin: 0; flex: 1 1 220px; }

.pied-page     { margin-top: 28px; font-size: 0.8rem; color: var(--texte-doux); text-align: center; }

/* Section « A propos », sous le pied de page de l'accueil : discrete, comme lui. */
.a-propos       { margin-top: 20px; font-size: 0.85rem; color: var(--texte-doux); text-align: center; }
.a-propos p     { margin: 0 0 6px; }
.a-propos-titre { font-size: 0.95rem; margin: 0 0 6px; color: var(--texte); }
.a-propos-lien  { font-size: 0.8rem; }
/* Le lien garde la couleur du texte autour (juste souligne) ; une adresse trop
   longue pour un petit ecran passe a la ligne au lieu de deborder. */
.a-propos-lien a { color: inherit; text-underline-offset: 3px; overflow-wrap: anywhere; }
.titre-section { font-size: 1.3rem; margin-bottom: 4px; }

/* ==========================================================================
   ACCUEIL : cartes des jeux
   ========================================================================== */
.grille-jeux {
  display: grid;
  /* auto-fit + minmax : 1 colonne sur petit ecran, 2 des qu'il y a la place */
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.carte-jeu {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px;
  font: inherit;
  text-align: left;
  color: var(--texte);
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.carte-jeu:hover  { background: var(--surface-haute); border-color: var(--accent); }
.carte-jeu:active { transform: scale(0.985); }

.carte-jeu .icone-jeu {
  font-size: 1.8rem;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: grid;
  place-items: center;
  background: var(--fond);
  border-radius: var(--rayon-petit);
}
/* display:block est indispensable : un <span> est un element « en ligne »,
   le nom et la description se retrouveraient sinon colles sur la meme ligne. */
.carte-jeu .nom-jeu  { display: block; font-weight: 650; font-size: 1.05rem; }
.carte-jeu .desc-jeu { display: block; font-size: 0.85rem; color: var(--texte-doux); line-height: 1.35; }

/* ==========================================================================
   BOUTONS
   ========================================================================== */
.bouton {
  font: inherit;
  font-weight: 600;
  color: var(--texte);
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon-petit);
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  /* 44px : taille minimale recommandee pour viser confortablement au doigt */
  min-height: 44px;
}
.bouton:hover    { background: var(--surface-haute); }
.bouton:active   { transform: scale(0.96); }
.bouton:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.bouton-principal {
  background: var(--accent);
  border-color: var(--accent);
  color: #071021;
}
.bouton-principal:hover { background: var(--accent-clair); }

.bouton-large { width: 100%; margin-bottom: 8px; }

/* Bouton actif dans un groupe de choix (theme selectionne, mode notes...) */
.bouton.actif {
  background: var(--accent);
  border-color: var(--accent);
  color: #071021;
}

/* Accessibilite : contour bien visible pour la navigation au clavier */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ==========================================================================
   ECRAN DES NIVEAUX
   ========================================================================== */
.bloc-options { margin-top: 20px; }
.titre-option {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--texte-doux);
  margin-bottom: 8px;
}

.liste-choix   { display: flex; flex-wrap: wrap; gap: 8px; }
.liste-niveaux { display: grid; gap: 10px; }

.carte-niveau {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  font: inherit;
  text-align: left;
  color: var(--texte);
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  cursor: pointer;
}
.carte-niveau:hover  { background: var(--surface-haute); border-color: var(--accent); }
.carte-niveau:active { transform: scale(0.99); }
.carte-niveau .nom-niveau    { display: block; font-weight: 650; }
.carte-niveau .detail-niveau { display: block; font-size: 0.82rem; color: var(--texte-doux); }
.carte-niveau .record        { font-size: 0.82rem; color: var(--alerte); white-space: nowrap; text-align: right; }

/* ==========================================================================
   BANDEAU DE JEU (chronometre, compteurs) + BARRE D'ACTIONS
   ========================================================================== */
.bandeau-jeu {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
}

.info-jeu { text-align: center; flex: 1; }
.info-jeu .etiquette {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--texte-doux);
}
.info-jeu .valeur {
  font-size: 1.15rem;
  font-weight: 700;
  /* chiffres a largeur fixe : le chronometre ne « saute » plus */
  font-variant-numeric: tabular-nums;
}

.barre-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}
.barre-actions .bouton { flex: 1 1 auto; min-width: 88px; }

/* ==========================================================================
   MODALE (victoire, defaite, confirmation)
   ========================================================================== */
.fond-modale {
  position: fixed;
  inset: 0;                    /* raccourci pour top/right/bottom/left: 0 */
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6, 9, 16, 0.75);
  backdrop-filter: blur(3px);
  animation: apparition 0.15s ease-out;
}
.fond-modale[hidden] { display: none; }

.modale {
  width: 100%;
  max-width: 360px;
  padding: 22px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}
.titre-modale { font-size: 1.35rem; margin-bottom: 10px; }
.corps-modale { color: var(--texte-doux); margin-bottom: 18px; }
.corps-modale strong { color: var(--texte); }
.actions-modale { display: flex; flex-direction: column; gap: 8px; }

/* ==========================================================================
   BULLE D'INFORMATION TEMPORAIRE
   ========================================================================== */
.bulle-info {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 200;
  max-width: 90vw;
  padding: 10px 18px;
  font-weight: 600;
  text-align: center;
  background: var(--surface-haute);
  border: 1px solid var(--accent);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: apparition 0.2s ease-out;
}
.bulle-info[hidden] { display: none; }

/* Note d'installation (section À propos) : inutile une fois l'application
   installée, puisqu'elle s'ouvre alors dans sa propre fenêtre (mode
   d'affichage autre que « browser », celui d'un onglet de navigateur). */
@media not all and (display-mode: browser) {
  .note-installation { display: none; }
}
