/* ============================================================
   Sudoku 9×9 — Feuille de styles responsive
   Organisation :
     1. RESET & BASE
     2. HEADER
     3. LAYOUT (desktop : grille+pavé | panneau)
     4. GRID (canvas)
     5. NUMPAD (pavé numérique adaptatif)
     6. PANEL (contrôles)
     7. MODE SWITCH (3 boutons toggle)
     8. DIFFICULTY SWITCH (3 boutons)
     9. STATUS
    10. BUTTONS
    11. MODAL
    12. RESPONSIVE (tablette < 768px, mobile < 480px)
   ============================================================ */

/* ──────────────────────────────────────────────
   1. RESET & BASE
   ────────────────────────────────────────────── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 16px;
  user-select: none;
  -webkit-tap-highlight-color: transparent; /* Mobile : pas de flash bleu */
}

/* ──────────────────────────────────────────────
   2. HEADER
   ────────────────────────────────────────────── */
h1 {
  font-size: 1.6rem;
  margin-bottom: 2px;
  background: linear-gradient(90deg, #58a6ff, #bc8cff, #f778ba);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.8rem;
  color: #8b949e;
  margin-bottom: 16px;
  text-align: center;
}

/* ──────────────────────────────────────────────
   3. LAYOUT — Desktop : 2 colonnes
   ────────────────────────────────────────────── */
.layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 900px;
  width: 100%;
}

/* Colonne gauche : grille + pavé */
.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* ──────────────────────────────────────────────
   4. GRID — Canvas de jeu
   ────────────────────────────────────────────── */
.grid-container {
  position: relative;
}

canvas {
  border: 2px solid #30363d;
  border-radius: 8px;
  cursor: pointer;
  display: block;
  touch-action: manipulation; /* Mobile : pas de zoom double-tap */
}

/* ──────────────────────────────────────────────
   5. NUMPAD — Pavé numérique adaptatif
   ────────────────────────────────────────────── */
.numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 520px;
}

/* Bouton du pavé */
.num-btn {
  aspect-ratio: 1;
  max-height: 64px;
  border: 1px solid #30363d;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.3rem;
  font-weight: bold;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* Mode Chiffres : fond clair, texte noir */
.num-btn.number-mode {
  background: #f0f0f0;
  color: #111;
}
.num-btn.number-mode:hover {
  background: #e0e0e0;
}
.num-btn.number-mode:active {
  background: #58a6ff;
  color: #fff;
  transform: scale(0.95);
}

/* Bouton effacer (⌫) */
.num-btn.erase {
  background: #21262d;
  color: #f85149;
  font-size: 1.1rem;
}
.num-btn.erase:hover {
  background: #30363d;
}
.num-btn.erase:active {
  background: #f85149;
  color: #fff;
  transform: scale(0.95);
}

/* Mode Couleurs : le fond est défini en inline style par JS */
.num-btn.color-mode {
  color: transparent;
  border-width: 2px;
}
.num-btn.color-mode:hover {
  transform: scale(1.08);
  box-shadow: 0 0 12px currentColor;
}
.num-btn.color-mode:active {
  transform: scale(0.95);
}

/* Mode Fréquences : mini-canvas dans le bouton */
.num-btn.freq-mode {
  background: #161b22;
  padding: 4px;
}
.num-btn.freq-mode:hover {
  background: #1c2128;
  border-color: #58a6ff;
}
.num-btn.freq-mode:active {
  transform: scale(0.95);
  border-color: #f0883e;
}

/* ──────────────────────────────────────────────
   6. PANEL — Panneau de contrôle
   ────────────────────────────────────────────── */
.panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 16px;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel h2 {
  font-size: 0.85rem;
  color: #8b949e;
  margin-bottom: 0;
  letter-spacing: 0.5px;
}

/* ──────────────────────────────────────────────
   7. MODE SWITCH — 3 boutons toggle
   ────────────────────────────────────────────── */
.mode-switch {
  display: flex;
  gap: 4px;
}

.mode-btn {
  flex: 1;
  padding: 8px 4px;
  font-size: 1.1rem;
  border: 1px solid #30363d;
  background: #21262d;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.mode-btn.active {
  background: #1f6feb;
  border-color: #58a6ff;
}
.mode-btn:hover:not(.active) {
  background: #30363d;
}

/* ──────────────────────────────────────────────
   8. DIFFICULTY SWITCH — 3 boutons
   ────────────────────────────────────────────── */
.diff-switch {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.diff-btn {
  padding: 8px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid #30363d;
  background: #21262d;
  color: #c9d1d9;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.diff-btn.active {
  border-color: #3fb950;
  background: #1a2e1a;
  color: #3fb950;
}
.diff-btn:hover:not(.active) {
  background: #30363d;
}

/* ──────────────────────────────────────────────
   9. STATUS DISPLAY
   ────────────────────────────────────────────── */
#statusDisplay {
  font-size: 0.8rem;
  color: #8b949e;
  min-height: 1.2em;
}

#duplicateCount {
  font-size: 0.75rem;
  color: #f85149;
  min-height: 1.2em;
}

/* ──────────────────────────────────────────────
   10. BUTTONS
   ────────────────────────────────────────────── */
.btn {
  background: #21262d;
  border: 1px solid #30363d;
  color: #c9d1d9;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  transition: all 0.2s;
  width: 100%;
}
.btn:hover {
  background: #30363d;
}
.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: #238636;
  border-color: #2ea043;
  color: #fff;
}
.btn.primary:hover {
  background: #2ea043;
}

/* ──────────────────────────────────────────────
   11. MODAL
   ────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
  justify-content: center;
  align-items: center;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  margin: 16px;
}

.modal h2 {
  color: #58a6ff;
  margin-bottom: 12px;
  font-size: 1.1rem;
}

.modal h3 {
  color: #bc8cff;
  margin: 14px 0 6px;
  font-size: 0.9rem;
}

.modal p,
.modal li {
  font-size: 0.8rem;
  line-height: 1.5;
  color: #8b949e;
}

.modal table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.75rem;
}

.modal th {
  text-align: left;
  color: #c9d1d9;
  padding: 4px 8px;
  border-bottom: 1px solid #30363d;
}

.modal td {
  padding: 4px 8px;
  border-bottom: 1px solid #21262d;
  color: #8b949e;
}

.modal-close {
  float: right;
  background: none;
  border: none;
  color: #8b949e;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover {
  color: #f85149;
}

/* ──────────────────────────────────────────────
   12. RESPONSIVE
   ────────────────────────────────────────────── */

/* Tablette (< 768px) : layout vertical */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
    align-items: center;
  }

  .panel {
    width: 100%;
    max-width: 520px;
  }

  .numpad {
    max-width: 520px;
  }
}

/* Mobile (< 480px) : grille et boutons plus compacts */
@media (max-width: 480px) {
  body {
    padding: 8px;
  }

  h1 {
    font-size: 1.3rem;
  }

  .subtitle {
    font-size: 0.7rem;
    margin-bottom: 10px;
  }

  .num-btn {
    font-size: 1rem;
  }

  .panel {
    padding: 12px;
    gap: 8px;
  }

  .panel h2 {
    font-size: 0.75rem;
  }

  .diff-btn {
    font-size: 0.7rem;
    padding: 6px 10px;
  }
}
