/* Fromagle — style général. Fond noir, texte blanc, couleurs vives et lisibles. */

:root {
  --fond: #000;
  --surface: #111;
  --ligne: #2a2a2a;
  --texte: #f2f2f2;
  --discret: #8f8f8f;
  --accent: #f5c542;           /* jaune fromage, pour les éléments actifs */

  /* Couleurs des cases (texte foncé sur fond vif = bon contraste) */
  --vert: #3fbf5f;      --vert-texte: #04170a;
  --orange: #f0a020;    --orange-texte: #1c1100;
  --rouge: #e5484d;     --rouge-texte: #ffffff;
  --gris: #3a3a3a;      --gris-texte: #d0d0d0;

  --rayon: 10px;
  --largeur: 760px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.visuellement-cache {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------------------------------------------------------------- Mise en page */
/* Téléphone et petit écran : titre, puis la carte (avec la recherche posée dessus), puis le jeu.
   Grand écran : le globe à gauche (fixe, recherche dessus), le titre et le jeu à droite. */

.zone-carte {
  position: relative;
  height: 46vh;
  min-height: 260px;
  background: #000;
}
/* Le globe apparaît en fondu une fois prêt (classe « prete » ajoutée par carte.js) */
.carte { position: absolute; inset: 0; opacity: 0; transition: opacity .8s ease; }
.carte.prete { opacity: 1; }

/* Sans carte (appareil sans 3D, ou réglage « Pas de carte ») : la recherche reprend sa place normale */
.zone-carte.indisponible, .zone-carte.sans-carte { height: auto; min-height: 0; padding: 8px 16px 0; }
.zone-carte.indisponible .carte, .zone-carte.sans-carte .carte { display: none; }

/* Mini-carte repliable : petite carte, puis le bouton pour la replier, puis la recherche */
.bouton-replier { display: none; }
.zone-carte.mini { height: auto; min-height: 0; padding: 0 0 0; display: flex; flex-direction: column; }
.zone-carte.mini .carte {
  position: relative; inset: auto;
  height: 30vh; min-height: 170px;
  transition: height .35s ease, min-height .35s ease, opacity .8s ease;
}
.zone-carte.mini.repliee .carte { height: 0; min-height: 0; }
.zone-carte.mini .bouton-replier {
  display: block; align-self: center;
  margin: 6px 0 0; padding: 4px 14px;
  border: 1px solid var(--ligne); border-radius: 999px;
  background: var(--surface); color: var(--discret);
  font: inherit; font-size: 13px; cursor: pointer;
}
.zone-carte.mini .bouton-replier::before { content: "▲ "; font-size: 10px; }
.zone-carte.mini.repliee .bouton-replier::before { content: "▼ "; }
.zone-carte.mini .recherche { margin: 8px 16px 0; }

@media (min-width: 1000px) {
  .mise-en-page {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(460px, 600px);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "carte entete" "carte jeu" "carte pied";
    min-height: 100vh;
  }
  .zone-carte { grid-area: carte; align-self: start; position: sticky; top: 0; height: 100vh; }
  .entete { grid-area: entete; width: 100%; }
  .jeu { grid-area: jeu; width: 100%; }
  .pied { grid-area: pied; width: 100%; }
  .entete, .jeu, .pied { border-left: 1px solid #141414; }
  .zone-carte.indisponible { grid-area: carte; height: auto; }
}

/* ---------------------------------------------------------------- Globe et épingles */

.maplibregl-ctrl-attrib { background: rgba(0, 0, 0, .7) !important; color: #c8c8c8; font-size: 11px; }
.maplibregl-ctrl-attrib a { color: #e0e0e0; }
.maplibregl-ctrl-attrib-button { filter: invert(1); }

/* Pas de « position » ici : MapLibre place lui-même l'épingle (position absolute + transform).
   La redéfinir décalait les épingles les unes sous les autres. */
.epingle { width: 22px; height: 22px; cursor: default; }
.epingle-point {
  display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  font-size: 11px; font-weight: 800;
  border: 2px solid #000;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .7);
}
.epingle-vert   .epingle-point { background: var(--vert);   color: var(--vert-texte); }
.epingle-orange .epingle-point { background: var(--orange); color: var(--orange-texte); }
.epingle-rouge  .epingle-point { background: var(--rouge);  color: var(--rouge-texte); }
.epingle-solution .epingle-point {
  width: 28px; height: 28px; margin: -3px;
  background: var(--accent); color: #000; font-size: 15px;
  box-shadow: 0 0 0 2px #fff, 0 0 18px 4px rgba(245, 197, 66, .55);
}

.epingle-etiquette {
  position: absolute; left: 50%; bottom: calc(100% + 6px);
  transform: translateX(-50%);
  padding: 2px 8px; border-radius: 6px;
  background: rgba(0, 0, 0, .8); color: #fff;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease;
}
.epingle-dernier .epingle-etiquette,
.epingle-solution .epingle-etiquette,
.epingle:hover .epingle-etiquette { opacity: 1; }
.epingle:hover { z-index: 2; }

/* L'épingle se pose : elle tombe légèrement et rebondit (0,3 s) */
.epingle-nouvelle .epingle-point { animation: poser .3s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes poser {
  from { transform: translateY(-14px) scale(.4); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ---------------------------------------------------------------- En-tête */

.entete {
  position: relative;
  max-width: var(--largeur);
  margin: 0 auto;
  padding: 20px 16px 8px;
  text-align: center;
}

/* Boutons ronds de l'en-tête : statistiques (à gauche) et réglages (à droite) */
.bouton-rond {
  position: absolute; top: 14px;
  display: grid; place-items: center;
  width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--ligne); border-radius: 50%;
  background: var(--surface); color: var(--discret); cursor: pointer;
  transition: color .2s ease, border-color .2s ease;
}
.bouton-rond:hover, .bouton-rond[aria-expanded="true"] { color: var(--texte); border-color: #555; }
.bouton-stats { left: 12px; }
.bouton-reglages { right: 12px; }
.bouton-aide { right: 58px; font-size: 18px; font-weight: 800; }

.reglages {
  position: absolute; z-index: 20; top: 60px; right: 12px;
  width: min(320px, calc(100% - 24px));
  padding: 12px 14px; text-align: left;
  background: #161616; border: 1px solid var(--ligne); border-radius: var(--rayon);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .6);
  animation: apparaitre .2s ease both;
}
.reglages-titre { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--discret); }
.reglage { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.reglage input { margin: 3px 0 0; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.reglage small { display: block; color: var(--discret); font-size: 13px; }

/* Choix de la carte : seulement sur petit écran (sur ordinateur, toujours le globe) */
.reglage-carte { margin: 14px 0 0; padding: 12px 0 0; border: 0; border-top: 1px solid var(--ligne); }
.reglage-carte legend { padding: 0; margin-bottom: 8px; font-weight: 700; }
.reglage-carte .reglage + .reglage { margin-top: 8px; }
@media (min-width: 1000px) { .reglage-carte { display: none; } }

.titre { margin: 0; line-height: 0; }

/* Le logo : 240 px de large au plus ; sur téléphone, il laisse la place aux boutons ronds
   de l'en-tête (≈ 100 px de chaque côté), d'où le « 100vw - 210px ». */
.logo {
  display: block;
  margin: 4px auto 0;
  width: clamp(120px, calc(100vw - 210px), 240px);
  height: auto;
}

.sous-titre { margin: 2px 0 14px; color: var(--discret); font-size: 14px; }

.onglets { display: inline-flex; gap: 6px; padding: 4px; background: var(--surface); border-radius: 999px; }

.onglet {
  border: 0; border-radius: 999px; padding: 8px 18px;
  background: transparent; color: var(--discret);
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background-color .25s ease, color .25s ease;
}
.onglet:hover { color: var(--texte); }
.onglet[aria-selected="true"] { background: var(--texte); color: #000; }
.onglet-etat { margin-left: 6px; }
.onglet:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------------------------------------------------------------- Recherche */

.jeu { max-width: var(--largeur); margin: 0 auto; padding: 16px 16px 48px; }

/* La barre de recherche flotte en haut du globe */
.recherche {
  position: absolute; z-index: 5;
  top: 14px; left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100% - 24px));
}
.zone-carte.indisponible .recherche,
.zone-carte.sans-carte .recherche { position: relative; top: auto; left: auto; transform: none; margin: 0 auto; }
.zone-carte.mini .recherche { position: relative; top: auto; left: auto; transform: none; width: auto; }

#champ-recherche {
  width: 100%;
  padding: 14px 16px;
  font: inherit; font-size: 17px;           /* ≥ 16 px : pas de zoom automatique sur iPhone */
  color: var(--texte);
  background: rgba(14, 14, 14, .82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: var(--rayon);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
  transition: border-color .2s ease, opacity .2s ease;
}
#champ-recherche::placeholder { color: #9a9a9a; }
#champ-recherche:focus { outline: none; border-color: var(--texte); }
#champ-recherche:disabled { opacity: .5; }

.suggestions {
  position: absolute; z-index: 10; left: 0; right: 0; top: 54px;
  margin: 0; padding: 4px; list-style: none;
  max-height: 320px; overflow-y: auto;
  background: #161616; border: 1px solid var(--ligne); border-radius: var(--rayon);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .6);
}
.suggestions li { padding: 10px 12px; border-radius: 6px; cursor: pointer; }
.suggestions li[aria-selected="true"] { background: #2b2b2b; }
.suggestions li.aucun { color: var(--discret); cursor: default; }
.suggestion-alias { display: block; font-size: 13px; color: var(--discret); }

/* Rappel des cases vertes, en tête de la liste quand elle s'ouvre */
.suggestions li.suggestions-note {
  padding: 6px 12px 8px; cursor: default;
  font-size: 12.5px; color: var(--discret); line-height: 1.9;
  border-bottom: 1px solid var(--ligne); border-radius: 0; margin-bottom: 4px;
}
.indice {
  display: inline-block; margin: 0 2px; padding: 0 8px; border-radius: 999px;
  background: var(--vert); color: var(--vert-texte); font-weight: 600; white-space: nowrap;
}

/* ---------------------------------------------------------------- Grille */

.grille { display: grid; gap: 14px; }

.grille-entete, .cases {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.grille-entete span {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--discret); text-align: center;
}

.essai-nom {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px; font-weight: 700;
}
.essai-numero { color: var(--discret); font-weight: 400; font-size: 13px; }

.case {
  min-height: 60px;
  padding: 6px 4px;
  border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-align: center;
  font-size: 13px; line-height: 1.2; font-weight: 600;
  overflow-wrap: break-word; hyphens: auto;   /* coupe les mots longs avec un tiret, en français */
}
.case.vert   { background: var(--vert);   color: var(--vert-texte); }
.case.orange { background: var(--orange); color: var(--orange-texte); }
.case.rouge  { background: var(--rouge);  color: var(--rouge-texte); }
.case.gris   { background: var(--gris);   color: var(--gris-texte); }

/* Mode daltonien : le vert devient bleu (bien distinct de l'orange et du rouge),
   et chaque case porte un symbole : ✓ juste, ≈ proche, ✗ faux. */
.daltonien { --vert: #2f74e0; --vert-texte: #ffffff; }
.daltonien .case::before { font-size: 13px; font-weight: 800; line-height: 1; }
.daltonien .case.vert::before   { content: "✓"; }
.daltonien .case.orange::before { content: "≈"; }
.daltonien .case.rouge::before  { content: "✗"; }

.fleche { font-size: 18px; line-height: 1; font-weight: 800; display: inline-block; }
.fleche-direction { transition: transform .4s ease; }

/* Les cases se retournent une par une à l'arrivée d'un essai, une fois l'épingle posée
   (--attente, réglé par app.js) */
.essai.nouveau .case {
  animation: retourner .45s ease both;
  animation-delay: calc(var(--attente, 0ms) + var(--rang) * .2s);
}
@keyframes retourner {
  from { transform: perspective(400px) rotateX(-90deg); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.essai.nouveau .essai-nom { animation: apparaitre .3s ease both; }
@keyframes apparaitre { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- Fin de partie */

.fin {
  margin: 0 0 20px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--ligne);
  border-radius: 14px;
  animation: apparaitre .5s ease both;
}
.fin h2 { margin: 0 0 4px; font-size: 22px; }
.fin .resultat { margin: 0 0 14px; color: var(--discret); }
.fin .solution { font-size: 24px; font-weight: 800; margin: 0; }
.fin .details { margin: 2px 0 12px; color: var(--discret); font-size: 14px; }
.fin .anecdote { margin: 0 0 12px; }
.fin .anecdote strong { color: var(--accent); }
.fin a { color: var(--texte); }
.fin .prochain { margin: 16px 0 0; font-size: 14px; color: var(--discret); }
.fin .prochain strong { color: var(--texte); font-variant-numeric: tabular-nums; }

.bouton {
  display: inline-block; margin-top: 14px; margin-right: 8px;
  padding: 10px 18px; border: 0; border-radius: 999px;
  background: var(--texte); color: #000;
  font: inherit; font-weight: 700; cursor: pointer;
}
.bouton.secondaire { background: transparent; color: var(--texte); border: 1px solid var(--ligne); }

.partage-message { margin: 10px 0 0; font-size: 14px; color: var(--accent); white-space: pre-line; }
.partage-message:empty { display: none; }

/* ---------------------------------------------------------------- Statistiques */

.stats-titre-fin { margin: 22px 0 10px; padding-top: 16px; border-top: 1px solid var(--ligne); font-size: 15px; }

.stats-chiffres { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stats-chiffres strong { display: block; font-size: 24px; font-weight: 800; line-height: 1.1; }
.stats-chiffres span { display: block; font-size: 12px; color: var(--discret); line-height: 1.2; }

.stats-sous-titre { margin: 16px 0 6px; font-size: 13px; color: var(--discret); }
.stats-barres { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.stats-barres li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.stats-essai { width: 1em; text-align: right; color: var(--discret); font-variant-numeric: tabular-nums; }
.stats-barre {
  min-width: 22px; padding: 1px 6px; border-radius: 4px;
  background: var(--gris); color: var(--texte); text-align: right; font-weight: 700;
}
.stats-barres li.actuelle .stats-barre { background: var(--vert); color: var(--vert-texte); }

/* Fenêtre des statistiques */
.fenetre {
  width: min(420px, calc(100% - 24px)); max-height: calc(100% - 40px);
  margin: auto; padding: 0;
  background: #121212; color: var(--texte);
  border: 1px solid var(--ligne); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .7);
}
.fenetre::backdrop { background: rgba(0, 0, 0, .6); }
.fenetre[open] { animation: apparaitre .25s ease both; }
.fenetre-contenu { padding: 16px 18px 18px; }
.fenetre-entete { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.fenetre-entete h2 { margin: 0; font-size: 20px; }
.fenetre-fermer {
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: transparent; color: var(--discret); font-size: 24px; line-height: 1; cursor: pointer;
}
.fenetre-fermer:hover { color: var(--texte); background: #222; }
.fenetre section h3 { margin: 16px 0 10px; font-size: 15px; }
.fenetre section + section { margin-top: 8px; padding-top: 4px; border-top: 1px solid var(--ligne); }
.fenetre-note { margin: 16px 0 0; font-size: 12px; color: var(--discret); }

/* Fenêtre « Comment jouer » */
.aide { font-size: 15px; }
.aide p { margin: 10px 0; }
.aide ul { margin: 8px 0; padding-left: 20px; }
.aide li { margin: 4px 0; }
.aide h3 { margin: 18px 0 8px; font-size: 15px; }
.aide-exemples { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.aide-exemples .case { min-height: 44px; font-size: 13px; }
.aide-cases { margin: 0; }
.aide-cases dt { font-weight: 700; margin-top: 10px; }
.aide-cases dd { margin: 2px 0 0; color: #cfcfcf; font-size: 14px; }
.aide .bouton { margin-top: 8px; }

/* ---------------------------------------------------------------- Pied de page */

.pied {
  max-width: var(--largeur); margin: 0 auto;
  padding: 8px 16px 32px;
  text-align: center; font-size: 13px; color: var(--discret);
}
.pied-liens { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; margin-bottom: 10px; }
.pied a, .lien { color: var(--discret); text-decoration: underline; text-underline-offset: 2px; }
.pied a:hover, .lien:hover { color: var(--texte); }
.lien { padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }
.credits { margin: 0; font-size: 12px; line-height: 1.6; }

/* ---------------------------------------------------------------- Pages de texte (mentions, confidentialité) */

.texte { max-width: 720px; margin: 0 auto; padding: 24px 18px 60px; line-height: 1.6; }
.texte h1 { font-size: 28px; margin: 18px 0 6px; }
.texte h2 { font-size: 19px; margin: 30px 0 8px; }
.texte a { color: var(--texte); }
.texte .retour { color: var(--discret); text-decoration: none; }
.texte .retour:hover { color: var(--texte); }
.texte .maj { color: var(--discret); font-size: 14px; margin: 0 0 20px; }
.texte ul { padding-left: 22px; }
.texte code { background: #1a1a1a; padding: 1px 5px; border-radius: 4px; font-size: .92em; }

.erreur { max-width: var(--largeur); margin: 24px auto; padding: 0 16px; color: var(--rouge); text-align: center; }

/* ---------------------------------------------------------------- Écrans étroits */

@media (max-width: 480px) {
  .entete { padding: 12px 12px 10px; }
  .sous-titre { margin-bottom: 10px; }
  .jeu { padding: 12px 10px 40px; }
  .grille-entete, .cases { gap: 4px; }
  .case { min-height: 54px; font-size: 10.5px; padding: 5px 2px; letter-spacing: -0.01em; }
  .grille-entete span { font-size: 10px; letter-spacing: .02em; }
}

/* ---------------------------------------------------------------- Réduire les animations */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}
