/* ============================================================
   RESET & BASE
============================================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  min-height: 100%;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  background: #fff;
}

/* ============================================================
   ÉCRAN PRINCIPAL — colonne scrollable
============================================================ */
.screen {
  position: relative;
  width: 100%;
  min-height: 100dvh;                  /* dvh : s'ajuste avec la barre Safari */
  min-height: var(--real-vh, 100dvh);  /* JS-driven : hauteur visible réelle (iPhone 16 Pro) */
  background: #ffffff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* ============================================================
   TITRE
============================================================ */
.titre-zone {
  flex: 0 0 auto;
  padding: clamp(8px, 2dvh, 16px) clamp(12px, 4%, 24px) clamp(4px, 1dvh, 8px);
  text-align: center;
  animation: fadeIn 0.5s ease 0.1s both;
}

.page-title {
  font-size: clamp(0.78rem, 3.2vw, 1.4rem);
  font-weight: 700;
  color: #1a7a7a;
  line-height: 1.4;
  margin-bottom: clamp(3px, 0.8dvh, 8px);
}

.page-subtitle {
  font-size: clamp(0.62rem, 2.3vw, 0.95rem);
  color: #444444;
  line-height: 1.45;
}

/* ============================================================
   GRILLE 8 × 8
============================================================ */
.grille-wrapper {
  flex: 0 0 auto;
  padding: clamp(4px, 1dvh, 10px) clamp(10px, 3%, 20px);
  animation: fadeIn 0.5s ease 0.15s both;
}

.grille {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: clamp(2px, 0.55vw, 4px);
  max-width: 440px;
  margin: 0 auto;
}

/* ── Cellule ── */
.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: clamp(0.60rem, 2.3vw, 1rem);
  font-weight: 700;
  color: #222222;
  background: #ffffff;
  border: 1.5px solid #555555;
  border-radius: 3px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  appearance: none;
  -webkit-appearance: none;
  padding: 0;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.cell:active { transform: scale(0.88); }

/* Sélectionnée (violet) */
.cell.violet {
  background: #9966cc;
  color: #ffffff;
  border-color: #7744aa;
}

/* Mot trouvé (vert) — non re-cliquable */
.cell.green {
  background: #22aa55;
  color: #ffffff;
  border-color: #188840;
  cursor: default;
}
.cell.green:active { transform: none; }

/* ============================================================
   LISTE DES MOTS À TROUVER
============================================================ */
.mots-zone {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(2px, 0.8vw, 8px);
  padding: clamp(5px, 1.4dvh, 12px) clamp(12px, 4%, 24px);
  animation: fadeIn 0.5s ease 0.2s both;
}

.mots-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(3px, 0.7dvh, 7px);
}

.mot-label {
  display: block;
  font-size: clamp(0.63rem, 2.2vw, 0.92rem);
  font-weight: 600;
  color: #222222;
  text-align: center;
  line-height: 1.3;
}

/* Mot trouvé → rouge barré */
.mot-label.trouve {
  color: #cc0000;
  text-decoration: line-through;
}

/* ============================================================
   ZONE RÉPONSE
   – instruction toujours visible
   – .lettres-bleues masquées jusqu'à tous mots trouvés
   – .lettres-orange toujours visible (slots vides)
============================================================ */
.reponse-zone {
  flex: 0 0 auto;
  padding: clamp(6px, 1.5dvh, 14px) clamp(12px, 4%, 24px) clamp(4px, 1dvh, 10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(5px, 1.2dvh, 12px);
  animation: fadeIn 0.5s ease 0.25s both;
}

.reponse-instruction {
  font-size: clamp(0.62rem, 2.2vw, 0.88rem);
  color: #333333;
  text-align: center;
  line-height: 1.4;
}

/* Conteneur principal : ? à gauche, deux rangées à droite */
.lettres-container {
  display: flex;
  flex-direction: row;
  align-items: center;       /* ? centré verticalement sur les deux rangées */
  gap: clamp(8px, 2vw, 16px);
}

/* Bouton ? */
.explication-img {
  height: clamp(28px, 7vw, 46px);
  width: auto;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  flex-shrink: 0;
  align-self: center;        /* centrage vertical garanti */
}
.explication-img:active { transform: scale(0.88); }

/* Colonne droite : rangée bleue au-dessus, orange en-dessous */
.lettres-colonnes {
  display: flex;
  flex-direction: column;
  gap: clamp(5px, 1.2dvh, 10px);
}

/* Rangée bleue — toujours visible */
.lettres-bleues {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: clamp(3px, 1vw, 8px);
}

/* Slots orange */
.lettres-orange {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: clamp(3px, 1vw, 8px);
}

/* ── Tuile commune (bleue & orange) ── */
.btn-lettre {
  width: clamp(30px, 8.5vw, 50px);
  height: clamp(30px, 8.5vw, 50px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: clamp(0.62rem, 2.5vw, 0.98rem);
  font-weight: 700;
  border-radius: 5px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  appearance: none;
  -webkit-appearance: none;
  padding: 0;
  line-height: 1;
  transition: background 0.12s ease, transform 0.1s ease, border-color 0.12s ease;
}
.btn-lettre:active { transform: scale(0.86); }

/* Tuile bleue — état normal (lettre masquée) */
.btn-lettre.bleu {
  background: #3388dd;
  color: transparent;          /* lettre invisible jusqu'à révélation */
  border: 2px solid #1a66bb;
}

/* Lettres révélées quand tous les mots sont trouvés */
.lettres-bleues.revelee .btn-lettre.bleu {
  color: #ffffff;
}

/* Tuile bleue — sélectionnée (en attente de placement) */
.btn-lettre.bleu.selectionne {
  background: #cc2222;
  color: #ffffff;
  border-color: #991111;
  box-shadow: 0 0 0 2px #ff6666;
}

/* Tuile bleue — déjà placée dans un slot */
.btn-lettre.bleu.utilisee {
  background: #aaaaaa;
  color: #dddddd;
  border-color: #888888;
  cursor: default;
}
.btn-lettre.bleu.utilisee:active { transform: none; }

/* Slot orange — rempli */
.btn-lettre.orange {
  background: #ff9933;
  color: #111111;
  border: 2px solid #cc6600;
}

/* Slot orange — vide (tiret pointillé) */
.btn-lettre.orange:not(.rempli) {
  background: #ffe0b0;
  border: 2px dashed #cc8800;
  color: transparent;
}

/* ============================================================
   BAS DE PAGE — grille 3 colonnes
============================================================ */
.bas-zone {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: clamp(6px, 1.5dvh, 14px) clamp(12px, 4%, 24px) clamp(10px, 2.5dvh, 20px);
  margin-top: auto;           /* pousse le bas-zone vers le bas si espace libre */
  animation: fadeIn 0.5s ease 0.3s both;
}

/* Flèche retour — colonne 1 */
.retour-img {
  grid-column: 1;
  justify-self: start;
  height: clamp(36px, 8dvh, 60px);
  width: auto;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  filter: drop-shadow(1px 1px 3px rgba(0,0,0,0.28));
}
.retour-img:active { transform: scale(0.90); }

/* Lézard — colonne 2 */
.lezard-img {
  grid-column: 2;
  height: clamp(55px, 13dvh, 110px);
  width: auto;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  border-radius: clamp(4px, 1vw, 8px);
  filter: drop-shadow(1px 2px 5px rgba(0,0,0,0.35));
}
.lezard-img:active { transform: scale(0.93); }

/* Score : coffre + rectangle rouge — colonne 3 */
.score-zone {
  grid-column: 3;
  justify-self: end;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: clamp(4px, 1.2vw, 10px);
}

.coffre-img {
  height: clamp(30px, 6dvh, 56px);
  width: auto;
  display: block;
}

.points-box {
  background: #cc0000;
  color: #ffffff;
  font-weight: 700;
  font-size: clamp(0.82rem, 2.8vw, 1.15rem);
  min-width: clamp(34px, 9vw, 62px);
  padding: clamp(3px, 0.7dvh, 7px) clamp(5px, 1.2vw, 10px);
  border-radius: 5px;
  text-align: center;
  line-height: 1.2;
}

/* ============================================================
   PANNEAUX (Bravo / Erreur)
============================================================ */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.60);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease both;
}

.panel-box {
  background: #ffffff;
  border-radius: clamp(10px, 2.5vw, 22px);
  padding: clamp(20px, 5dvh, 40px) clamp(24px, 6vw, 48px);
  max-width: 85vw;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}

/* Image pouce dans le panneau Bravo */
.panel-bravo-img {
  display: block;
  margin: 0 auto clamp(10px, 2dvh, 18px);
  height: clamp(60px, 15dvh, 110px);
  width: auto;
}

/* Image émoticône dans le panneau Erreur */
.panel-erreur-img {
  display: block;
  margin: 0 auto clamp(10px, 2dvh, 18px);
  height: clamp(55px, 13dvh, 100px);
  width: auto;
}

/* Sous-texte "Vous ne marquez pas de point." */
.panel-sous-texte {
  font-size: clamp(0.70rem, 2.4vw, 0.95rem);
  color: #555555;
  margin-top: clamp(6px, 1.2dvh, 12px);
  margin-bottom: clamp(12px, 2.5dvh, 22px);
}

/* Bouton fermer en bas du panneau Erreur */
.panel-fermer-btn {
  display: block;
  margin: 0 auto;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.panel-fermer-btn:active { transform: scale(0.90); }

.panel-fermer-img {
  display: block;
  height: clamp(36px, 8dvh, 58px);
  width: auto;
}

.panel-title {
  font-size: clamp(1.2rem, 5vw, 2rem);
  font-weight: 700;
  margin-bottom: clamp(8px, 2dvh, 16px);
}
.panel-bravo  .panel-title { color: #22aa55; }
.panel-erreur .panel-title { color: #cc0000; }

.panel-text {
  font-size: clamp(0.76rem, 2.7vw, 1.05rem);
  color: #222222;
  line-height: 1.5;
  margin-bottom: clamp(14px, 3dvh, 24px);
}

.panel-btn {
  appearance: none;
  -webkit-appearance: none;
  background: #1a7a7a;
  color: #ffffff;
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(0.82rem, 2.8vw, 1.1rem);
  padding: clamp(8px, 1.5dvh, 14px) clamp(20px, 5vw, 36px);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.panel-btn:active { transform: scale(0.95); }

/* ============================================================
   OVERLAY DE TRANSITION
============================================================ */
.transition-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  opacity: 1;
  pointer-events: all;
  transition: opacity 0.4s ease;
}

/* ============================================================
   ANIMATIONS
============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ============================================================
   RESPONSIVE — SMARTPHONE (≤ 500px)
============================================================ */
@media (max-width: 500px) {
  .page-title        { font-size: clamp(0.70rem, 3.0vw, 0.92rem); }
  .page-subtitle     { font-size: clamp(0.58rem, 2.2vw, 0.76rem); }
  .mot-label         { font-size: clamp(0.58rem, 2.1vw, 0.78rem); }
  .cell              { font-size: clamp(0.56rem, 2.2vw, 0.84rem); }
  .reponse-instruction { font-size: clamp(0.58rem, 2.1vw, 0.76rem); }
}

/* ============================================================
   RESPONSIVE — PORTRAIT ÉTROIT (≤ 360px)
============================================================ */
@media (max-width: 360px) {
  .page-title        { font-size: 0.66rem; }
  .page-subtitle     { font-size: 0.54rem; }
  .mot-label         { font-size: 0.54rem; }
  .cell              { font-size: 0.52rem; }
  .btn-lettre        { width: 26px; height: 26px; font-size: 0.58rem; }
  .reponse-instruction { font-size: 0.54rem; }
}

/* ============================================================
   RESPONSIVE — TABLETTE (≥ 600px)
============================================================ */
@media (min-width: 600px) {
  .grille            { max-width: 480px; gap: 4px; }
  .cell              { font-size: clamp(0.82rem, 1.7vw, 1.05rem); }
  .mot-label         { font-size: clamp(0.72rem, 1.7vw, 0.96rem); }
  .btn-lettre        { width: clamp(36px, 5.5vw, 52px); height: clamp(36px, 5.5vw, 52px); }
  .lezard-img        { height: clamp(68px, 12dvh, 120px); }
  .coffre-img        { height: clamp(36px, 7dvh, 62px); }
  .points-box        { font-size: clamp(0.88rem, 2.5vw, 1.2rem); }
}

/* ============================================================
   RESPONSIVE — TABLETTE HAUTE (≥ 600px, ≥ 1100px haut)
============================================================ */
@media (min-width: 600px) and (min-height: 1100px) {
  .grille            { max-width: 520px; gap: 5px; }
  .btn-lettre        { width: clamp(40px, 6vw, 58px); height: clamp(40px, 6vw, 58px); }
}

/* ============================================================
   RESPONSIVE — PAYSAGE MOBILE (hauteur ≤ 450px)
============================================================ */
@media (max-height: 450px) and (orientation: landscape) {
  .titre-zone        { padding: 3px 12px 2px; }
  .page-title        { font-size: 0.60rem; margin-bottom: 1px; }
  .page-subtitle     { font-size: 0.52rem; }
  .grille-wrapper    { padding: 2px 10px; }
  .grille            { gap: 2px; }
  .cell              { font-size: 0.52rem; }
  .mots-zone         { padding: 3px 10px; gap: 2px; }
  .mot-label         { font-size: 0.52rem; }
  .reponse-zone      { padding: 3px 10px; gap: 3px; }
  .reponse-instruction { font-size: 0.52rem; }
  .btn-lettre        { width: 24px; height: 24px; font-size: 0.54rem; }
  .explication-img   { height: 24px; }
  .bas-zone          { padding: 3px 10px 5px; }
  .lezard-img        { height: 42px; }
  .retour-img        { height: 28px; }
  .coffre-img        { height: 24px; }
  .points-box        { font-size: 0.66rem; padding: 2px 4px; min-width: 28px; }
}
