/* Reset et base */
:root {
  --cell-size: 40px;
  --grid-cols: 9;
  --board-width: calc(var(--grid-cols) * var(--cell-size) + 4px);
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(135deg, #f0f4f8 0%, #e2e8f0 100%);
}

#root {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

h1 {
  margin: 0 0 24px;
  font-size: 1.75rem;
  font-weight: 600;
  color: #1e293b;
  width: 100%;
}

/* Bloc jeu (grille + boutons alignés) */
.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: var(--board-width);
}

/* Grille Sudoku */
.board {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), var(--cell-size));
  grid-template-rows: repeat(var(--grid-cols), var(--cell-size));
  width: var(--board-width);
  background: #fff;
  padding: 2px;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.cell {
  border: 1px solid #cbd5e1;
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  font-weight: 500;
}

/* Chiffres initiaux (donnés au départ) */
.cell.fixed {
  background-color: #f1f5f9;
  color: #1e293b;
  font-weight: 600;
}

/* Chiffres ajoutés par le joueur */
.cell.editable {
  color: #3b82f6;
}

.cell.invalid {
  background-color: #fecaca;
}

/* En cellule avec options : fond focus semi-transparent pour voir les petits chiffres */
.cell-with-options input:focus {
  background-color: rgba(239, 246, 255, 0.5);
}

/* Cellule avec grille d’options (chiffres en petit) */
.cell-with-options {
  position: relative;
}

.cell-options {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  align-items: center;
  justify-items: center;
  pointer-events: none;
  padding: 2px;
}

.cell-options .option-digit {
  font-size: 8px;
  line-height: 1;
  color: #64748b;
  visibility: hidden;
}

.cell-options .option-digit.visible {
  visibility: visible;
}

.cell-with-options input {
  position: relative;
  z-index: 1;
}

.buttons button.active {
  background: #e0f2fe;
  border-color: #0ea5e9;
  color: #0369a1;
}

/* Bordures des blocs 3x3 */
.bold-border-left {
  border-left: 2px solid #64748b;
}

.bold-border-top {
  border-top: 2px solid #64748b;
}

.bold-border-right {
  border-right: 2px solid #64748b;
}

.bold-border-bottom {
  border-bottom: 2px solid #64748b;
}

/* Boutons - même largeur que la grille, alignés */
.buttons {
  margin-top: 24px;
  width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
}

.buttons button {
  flex: 1;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  color: #334155;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.buttons button:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.buttons button:active {
  background: #f1f5f9;
}

.buttons button.active {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
}

/* Clavier numérique mobile - caché par défaut */
.number-pad-wrapper {
  display: none;
  width: 100%;
  margin-top: 12px;
}

.number-pad-wrapper.visible {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.number-pad-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: var(--board-width);
}

.number-pad-row {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
  width: 100%;
}

.num-btn {
  aspect-ratio: 1;
  min-height: 28px;
  padding: 0;
  font-size: 14px;
  font-weight: 600;
  color: #334155;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.num-btn:active {
  transform: scale(0.95);
  background: #f1f5f9;
  border-color: #94a3b8;
}

.number-pad-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: stretch;
  gap: 6px;
  width: 100%;
}

.action-btn {
  flex: 1;
  min-width: 0;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 500;
  color: #334155;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  white-space: normal;
  line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.action-btn.active {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
}

/* Notes (chiffres candidats) dans les cellules */
.cell-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  font-size: 8px;
  color: #64748b;
  place-items: center;
}

.cell-notes span {
  min-width: 0.8em;
  text-align: center;
}

/* Modal succès */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-message {
  margin: 0 0 20px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #1e293b;
  text-align: center;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-btn {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.modal-btn.primary {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

.modal-btn:hover {
  background: #f8fafc;
}

.modal-btn.primary:hover {
  background: #2563eb;
}

/* Cellules éditables (clic + clavier/pavé numérique) */
.cell.editable {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cell.editable.selected {
  background-color: #bfdbfe;
  box-shadow: inset 0 0 0 2px #3b82f6;
}

.cell.editable:active {
  background-color: #eff6ff;
}

/* Mobile : empêcher le zoom/scroll du clavier, layout adapté */
@media (max-width: 768px) {
  :root {
    --cell-size: min(13vw, 41px);
  }

  body {
    padding: 12px;
    min-height: 100vh;
    min-height: 100dvh;
  }

  h1 {
    font-size: 1.4rem;
    margin-bottom: 16px;
  }

  .game-wrapper {
    width: 100%;
    max-width: var(--board-width);
  }

  .desktop-only {
    display: none !important;
  }
}
