@import url("https://fonts.googleapis.com/css2?family=Sarabun:wght@400;600;700&display=swap");
:root {
  --primary: #2e7d32;
  --primary-light: #e8f5e9;
  --active-cell: #fff9c4;
  --highlight-word: #e1f5fe;
  --border-color: #424242;
  --bg-color: #f8f9fa;
}

body {
  font-family: "Sarabun", "Poppins", sans-serif;
  background-color: var(--bg-color);
  color: #333;
  margin: 0;
  padding: 20px;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  background: white;
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

h1 {
  color: var(--primary);
  text-align: center;
  margin-top: 0;
  font-size: 24px;
}

.subtitle {
  text-align: center;
  color: #666;
  margin-bottom: 25px;
  font-size: 14px;
}

/* Alignement du conteneur du jeu et des définitions côte à côte */
.crossword-layout {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2rem;
    align-items: flex-start;
}

.grid-container {
  overflow-x: auto;
  padding: 5px;
}

.grid-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* Défilement fluide sur iOS */
  max-width: 100%;
}

.grid {
  display: grid;
  /* On laisse JavaScript gérer le nombre exact de colonnes et lignes */
  gap: 1px;
  background-color: var(--border-color);
  border: 2px solid var(--border-color);
  border-radius: 4px;
  width: fit-content; /* Ajuste la largeur pile au contenu */
  height: fit-content; /* Ajuste la hauteur pile au contenu */
}

/* ICI AJOUT */

/* Conteneur principal de la grille */
#crossword-grid {
    display: grid;
    gap: 2px;
    background-color: #333; /* Couleur du quadrillage/cases noires */
    padding: 2px;
    border: 2px solid #333;
    width: fit-content;
    margin: 0 auto 20px auto;
}

/* Format strict des cases carrées */
.grid-cell {
    width: 40px;
    height: 40px;
    position: relative;
    background-color: #000; /* Cases noires par défaut */
}

/* Case active (blanche) */
.grid-cell.active {
    background-color: #fff;
}

/* Saisie du texte dans la case */
.grid-cell input {
    width: 100%;
    height: 100%;
    border: none;
    text-align: center;
    font-size: 1.1rem;
    font-family: 'Sarabun', sans-serif;
    font-weight: 600;
    background: transparent;
    outline: none;
    text-transform: uppercase;
}

/* Numéro de la définition */
.cell-number {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 0.65rem;
    color: #555;
    pointer-events: none;
}

/* FIN AJOUT */

.cell {
  width: 34px;
  height: 34px;
  background-color: #fff;
  position: relative;
  box-sizing: border-box;
}

.cell.empty {
  background-color: #7a6868;
  border: none;
}

/* Ajustement pour que le texte thaï soit bien lisible dans les cases et la liste */
.cell input {
  font-family: "Sarabun", sans-serif;
  /* ... reste de votre code .cell input ... */
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  outline: none;
  background: transparent;
  padding: 0;
  caret-color: transparent;
  cursor: pointer;
}

.cell.highlight {
  background-color: var(--highlight-word);
}

.cell.active {
  background-color: var(--active-cell) !important;
}

.cell .number {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 9px;
  font-weight: 600;
  color: #555;
  pointer-events: none;
  user-select: none;
}

.clues-container {
  flex: 1;
  min-width: 280px;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.clues-section {
  background: #fafafa;
  padding: 15px;
  border-radius: 8px;
  border-left: 4px solid var(--primary);
}

.clues-section h2 {
  font-size: 16px;
  margin-top: 0;
  margin-bottom: 10px;
  color: var(--primary);
}

.clues-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.clues-list li {
  font-family: "Sarabun", sans-serif;
  /* ... reste de votre code .clues-list li ... */

  padding: 6px 8px;
  margin-bottom: 4px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.2s;
}

.clues-list li:hover {
  background-color: var(--primary-light);
}

.clues-list li.active-clue {
  background-color: var(--highlight-word);
  font-weight: 600;
}

/* Boutons centrés en bas */
.controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
    width: 100%;
}

button {
  background-color: var(--primary);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

button:hover {
  background-color: #1b5e20;
}

button.secondary {
  background-color: #312424;
}
button.secondary:hover {
  background-color: #616161;
}

.status-msg {
  text-align: center;
  margin-top: 15px;
  font-weight: 600;
}
.status-msg.success {
  color: #2e7d32;
}
.status-msg.error {
  color: #c62828;
}

/* ==========================================
   ADAPTATION RESPONSIVE (MOBILES & TABLETTES)
   ========================================== */

/* Écrans de taille moyenne (Tablettes, < 768px) */
@media (max-width: 768px) {
    /* Basculer les définitions sous la grille */
    .crossword-layout {
        flex-direction: column;
        align-items: center;
    }

    .clues-container {
       width: 100%;
        max-width: 500px;
        margin: 1.1rem auto 0 auto; /* 'auto' à gauche et à droite centre le bloc */
        text-align: center;         /* Centre le texte à l'intérieur */
    }

    /* Centrer les titres des colonnes (Horizontale / Verticale) */
    .clues-column h3 {
        text-align: center;
    }

    /* Enlever les puces de la liste et centrer les éléments */
    .clues-list {
        list-style: none; /* Supprime la puce pour un alignement propre */
        padding-left: 0;
    }

    .clues-list li {
        text-align: center;
        margin-bottom: 0.4rem;
    }

    /* Réduction de la taille des cases */
    .grid-cell {
        width: 32px;
        height: 32px;
    }

    .grid-cell input {
        font-size: 0.95rem;
    }

    .cell-number {
        font-size: 0.55rem;
        top: 0px;
        left: 1px;
    }
}

/* Petits écrans (Smartphones, < 480px) */
@media (max-width: 480px) {
    #crossword-grid {
        gap: 1px; /* Réduction du quadrillage pour gagner de l'espace */
        padding: 1px;
    }

    /* Taille optimale pour faire tenir 12 cases sur 360px de large */
    .grid-cell {
        width: 26px;
        height: 26px;
    }

    .grid-cell input {
        font-size: 0.8rem;
    }

    .cell-number {
        font-size: 0.5rem;
        line-height: 1;
    }

    /* Ajustement des boutons */
    .controls {
        flex-direction: column;
        width: 100%;
        padding: 0 1rem;
    }

    .controls .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}