/* ==========================================================================
   1. RESET E LAYOUT DE TELA CHEIA (ANTI-ROLAGEM VERTICAL)
   ========================================================================== */
* {
  box-sizing: border-box !important;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: #f4f7f6;
  color: #333;
  padding: 8px !important;
  display: flex;
  justify-content: center;
  align-items: center; 
  min-height: 100vh;
  overflow: hidden; /* Elimina barra de rolagem */
}

/* Container Principal compactado */
.wrap {
  width: 100% !important;
  max-width: 400px !important; 
  margin: 0 auto !important;
  display: flex;
  flex-direction: column;
}

/* Ajustes de espaçamento do Topo */
.lang-selector {
  text-align: right;
  font-size: 0.75rem;
  margin-bottom: 4px;
  color: #666;
}
.lang-selector span {
  cursor: pointer;
  margin-left: 8px;
  padding: 1px 4px;
  border-radius: 4px;
}
.lang-selector span.active {
  background-color: #4040ff;
  color: #fff;
  font-weight: bold;
}

#sudoku-timer {
  text-align: center;
  font-size: 1rem !important;
  font-weight: bold;
  margin-bottom: 2px !important;
  color: #333;
}

/* Painel de mensagens com cor de erro configurada */
#sudoku-message {
  text-align: center;
  font-weight: bold;
  min-height: 18px !important;
  margin-bottom: 6px !important;
  font-size: 0.85rem !important;
  color: #d93025; /* Força o vermelho do aviso de erro */
}

/* ==========================================================================
   2. O TABULEIRO SUDOKU (CALCULADO COM MARGEM DE SEGURANÇA EXTRA)
   ========================================================================== */
.sudoku-board {
  width: 100% !important;
  /* Calcula a altura total da tela e subtrai o espaço dos botões e textos */
  max-width: clamp(230px, calc(100vh - 210px), 400px) !important;
  aspect-ratio: 1 / 1 !important; 
  margin: 0 auto 12px auto !important;
  display: block !important;
  clear: both !important;
  height: auto !important;
}

/* Célula base da biblioteca */
.sudoku-board-cell {
  display: inline-block !important;
  float: left !important;
  position: relative !important;
  background: #ffffff !important;
  border: 1px solid #e2e2e2 !important;
  width: 11.11111% !important;
  height: 11.11111% !important;
  box-sizing: border-box !important;
}

/* ==========================================================================
   3. BORDAS INTERNAS 3X3 (MANTIDO DO SCRIPT ORIGINAL)
   ========================================================================== */
.sudoku-board .sudoku-board-cell:nth-of-type(9n+1) {
  border-left: 2.5px solid #222222 !important;
}
.sudoku-board .sudoku-board-cell:nth-of-type(n):nth-of-type(-n+9) {
  border-top: 2px solid #222222 !important;
}
.sudoku-board .sudoku-board-cell:nth-of-type(3n) {
  border-right: 2.5px solid #222222 !important;
}
.sudoku-board .sudoku-board-cell:nth-of-type(n+19):nth-of-type(-n+27), 
.sudoku-board .sudoku-board-cell:nth-of-type(n+46):nth-of-type(-n+54), 
.sudoku-board .sudoku-board-cell:nth-of-type(n+73):nth-of-type(-n+81) {
  border-bottom: 2.5px solid #222222 !important;
}

/* ==========================================================================
   4. INPUTS INTERNOS (NÚMEROS DIGITADOS)
   ========================================================================== */
.sudoku-board-cell input {
  background: transparent !important;
  text-align: center !important;
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 2 !important;
  outline: none !important;
  font-weight: bold !important;
  color: #2c3e50 !important;
  font-size: clamp(13px, 4.5vw, 20px) !important;
}

.sudoku-board-cell input::-webkit-outer-spin-button,
.sudoku-board-cell input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.sudoku-board-cell input[type=number] {
  -moz-appearance: textfield;
}

.sudoku-board-cell .highlight-val {
  color: #1a73e8 !important;
}
.sudoku-board-cell .board-cell--error {
  background-color: #fce8e6 !important;
  color: #d93025 !important;
}

/* ==========================================================================
   5. PISTAS E CANDIDATOS (MICRO-GRID ULTRA-LEGÍVEL ATUALIZADO)
   ========================================================================== */
.sudoku-board-cell .candidates {
  display: none;
  position: absolute !important;
  top: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  z-index: 1 !important;
  padding: 2px !important;
  box-sizing: border-box !important;
}

/* Revela os candidatos usando CSS Grid quando ativado */
.showCandidates .sudoku-board-cell .candidates {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  grid-template-rows: repeat(3, 1fr) !important;
  align-items: center !important;
  justify-items: center !important;
}

/* Estilização de cada numerozinho de pista */
.sudoku-board .candidates div {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  height: 100% !important;
  color: #666 !important;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  /* Fonte inteligente: garante tamanho mínimo de 9px para leitura humana */
  font-size: clamp(9px, 1.5vw, 11px) !important; 
}

.candidate--highlight { 
  background-color: #fff59d !important; 
  border-radius: 2px;
}
.candidate--to-remove { 
  background-color: #ef9a9a !important; 
  color: #b71c1c !important; 
  border-radius: 2px;
}

/* ==========================================================================
   6. BOTÕES DA INTERFACE (MANTÉM EM LINHA SEM QUEBRAR)
   ========================================================================== */
button, 
.sudokubutton1, .sudokubutton2, .sudokubutton3, .sudokubutton4,
.sudokubutton5, .sudokubutton6, .sudokubutton7 {
  flex: 1 !important;
  color: white !important;
  padding: 6px 2px !important; 
  font-weight: bold !important;
  border: none !important;
  border-radius: 4px !important;
  cursor: pointer !important;
  transition: background-color 0.2s, transform 0.1s !important;
  font-size: clamp(9px, 2.5vw, 12px) !important;
}

.sudokubutton1 { background-color: #2ecc71 !important; }
.sudokubutton2 { background-color: #f39c12 !important; }
.sudokubutton3 { background-color: #e74c3c !important; }
.sudokubutton4 { background-color: #2c3e50 !important; }
.sudokubutton5, .sudokubutton6 { background-color: #3498db !important; }
.sudokubutton7 { background-color: #95a5a6 !important; }

.sudokubutton1:hover, .sudokubutton2:hover, .sudokubutton3:hover, .sudokubutton4:hover,
.sudokubutton5:hover, .sudokubutton6:hover, .sudokubutton7:hover {
  background-color: #e2e2e2 !important;
  color: #333 !important;
}

button:active {
  transform: scale(0.96) !important;
}