:root {
  --fond: #f5f6fa;
  --primaire: #2c3e50;
  --secondaire: #3498db;
  --accent: #e67e22;

  --case-fond: #ffffff;
  --case-bord: #bdc3c7;
  --case-selection: #f1c40f;
  --case-neutralisee: #95a5a6;

  --rayon: 0.5rem;
  --transition: 0.15s ease-in-out;
  
  --final-case-size: clamp(32px, 9vw, 64px);
}

/* ------------------------------
   STRUCTURE GÉNÉRALE
------------------------------ */

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background-color: var(--fond);
  color: var(--primaire);

  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1;
  max-width: none;
  width: 100%;
  margin: auto;
  padding: 1rem;
}

.site-header,
.site-footer {
  background-color: var(--primaire);
  color: white;
  text-align: center;
  padding: 1rem;
}

.header-flag {
  width: 48px;
  height: auto;
  margin-top: 0.5rem;
}

.jeu-bloque {
  pointer-events: none;
}

/* ------------------------------
   INTRO
------------------------------ */

.intro-texte {
  margin: 0 0 1rem 0;
}

/* ------------------------------
   LAYOUT LISTE + GRILLE
------------------------------ */

.jeu {
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-areas: "sidebar grille";
  gap: 1rem;
  align-items: start;
}

.sidebar {
  grid-area: sidebar;
  background: white;
  padding: 1rem;
  border-radius: var(--rayon);
}

.grille-zone {
  grid-area: grille;
  background: white;
  padding: 1rem;
  border-radius: var(--rayon);
  position: relative;
}

/* ------------------------------
   MODE ÉCRAN ÉTROIT
------------------------------ */

@media (max-width: 700px) {
  .jeu {
    grid-template-columns: 1fr;
    grid-template-areas:
      "sidebar"
      "grille";
  }

  .sidebar {
    width: 100%;
  }

  /* Colonnes dynamiques */
  .liste-mots {
    column-width: 120px;
    column-gap: 1rem;
  }

  .liste-mots .mot {
    break-inside: avoid;
  }
}

/* ------------------------------
   LISTE DES MOTS
------------------------------ */

.liste-mots {
  list-style: none;
  column-width: 180px;
  padding: 0;
  margin: 0;
}

.mot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
}

.mot.trouve {
  text-decoration: line-through;
  opacity: 0.6;
}

.icone-langue {
  width: 24px;
}

/* ------------------------------
   POPUP DEFINITION
------------------------------ */

.popup {
  position: fixed;
  background: white;
  border-radius: var(--rayon);
  padding: 0.8rem;
  max-width: 350px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 2000;
  border: 1px solid #d0d0d0;
}

.popup-close {
  position: absolute;
  top: 0.2rem;
  right: 0.4rem;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
}

.popup-row {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
}

.popup-help {
  background: white;
  border: 2px solid #f1c40f;
  color: #e67e22;
  border-radius: 50%;
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  cursor: pointer;
}

.popup-text {
  flex: 1;
}

.popup-mot-zone {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.popup-flag {
  width: 22px;
}

.popup-mot {
  font-weight: bold;
  color: var(--secondaire);
  font-size: 1.1rem;
}

.popup-def {
  margin: 0.2rem 0 0.6rem 0;
}

.popup-separator {
  border: none;
  border-top: 1px solid #ddd;
  margin: 0.4rem 0;
}

.popup-flag-fr {
  width: 22px;
}

.popup-mot-fr {
  font-weight: bold;
  color: var(--secondaire);
  margin: 0.2rem 0;
}

.popup-def-fr {
  margin: 0;
}

.hidden {
  display: none !important;
}

/* ------------------------------
   GRILLE
------------------------------ */

.grille-wrapper {
  display: block;
  width: 100%;
}

.grille-zone {
  min-width: 0;
}

.grille {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
  width: 100%;
  margin-inline: auto;
  touch-action: none;
}


.case {
  aspect-ratio: 1 / 1;
  font-size: clamp(1.2rem, 4vw, 2rem);
  font-weight: bold;
  background-color: var(--case-fond);
  border: 2px solid var(--case-bord);
  border-radius: var(--rayon);
  cursor: pointer
  max-width: 150px;
  max-height: 150px;
}

.case.selectionnee {
  background-color: var(--case-selection);
  border-color: var(--accent);
}

.case.neutralisee {
  background-color: var(--case-neutralisee);
  color: white;
  cursor: not-allowed;
}

/* ------------------------------
   BOUTONS
------------------------------ */

.selection-et-boutons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.boutons-grille button {
  font: inherit;
  padding: 0.3rem 0.7rem;
  border-radius: var(--rayon);
  border: none;
  background-color: var(--secondaire);
  color: white;
  cursor: pointer;
}

.boutons-grille button:hover {
  background-color: #2980b9;
}

/* ------------------------------
   PHASE 2
------------------------------ */

.final-zone {
  background: white;
  padding: 1rem;
  border-radius: var(--rayon);
  margin-top: 1rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.final-def-row {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.final-help {
  background: white;
  border: 2px solid #f1c40f;
  color: #e67e22;
  border-radius: 50%;
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  cursor: pointer;
}

.final-def-text p {
  margin: 0 0 0.4rem 0;
}

/* ------------------------------
   LETTRES RESTANTES
------------------------------ */

.final-letters-block {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 1rem;
}

.letters-pool,
.letters-slots {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--final-case-size);
  gap: 0.4rem;
  justify-content: start;
}


.letter-tile,
.slot-tile {
  width: var(--final-case-size);
  height: var(--final-case-size);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: bold;
  border-radius: var(--rayon);
}


.letter,
.letter-slot {
  aspect-ratio: 1 / 1;
  width: var(--final-case-size);
  height: var(--final-case-size);
  
  box-sizing: border-box;

  display: flex;
  align-items: center;
  justify-content: center;

  font-size: clamp(1.1rem, 3.5vw, 1.6rem);
  font-weight: bold;
  border-radius: var(--rayon);
}


.letter {
  background-color: var(--case-fond);
  border: 2px solid var(--case-bord);
  cursor: pointer;
}

.letter-slot {
  background-color: #f0f0f0;
  border: 2px dashed var(--case-bord);
}

.letter-tile {
  background-color: var(--case-fond);
  cursor: pointer;
}

.letter-tile.used {
  opacity: 0.3;
  cursor: default;
}

.slot-tile {
  background-color: #ecf0f1;
}

/* ------------------------------
   PHASE 3
------------------------------ */

.final-image-zone {
  margin-top: 1rem;
  text-align: center;
}

.final-image-wrapper {
  max-width: 500px;
  margin: 0 auto;
  overflow: hidden;
  border-radius: var(--rayon);
}

.final-image-wrapper img {
  width: 100%;
  display: block;
}

.final-caption {
  margin-top: 0.5rem;
  font-weight: bold;
}

/* ------------------------------
   BOÎTE DE DIALOGUE
------------------------------ */

.dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
}

.dialog-box {
  background: white;
  padding: 1.5rem;
  border-radius: 0.6rem;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.dialog-buttons {
  display: flex;
  justify-content: space-around;
  margin-top: 1rem;
}

.dialog-buttons button {
  padding: 0.4rem 1rem;
  border: none;
  border-radius: 0.4rem;
  background: var(--secondaire);
  color: white;
  cursor: pointer;
}

.dialog-buttons button:hover {
  background: #2980b9;
}

/* ------------------------------
   ANIMATIONS
------------------------------ */

.fade-out {
  animation: fadeOut 0.5s forwards;
}

.fade-in {
  animation: fadeIn 0.5s forwards;
}

@keyframes fadeOut {
  to { opacity: 0; transform: scale(0.98); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(1.02); }
  to { opacity: 1; transform: scale(1); }
}
