/* =========================================================
   Sudoku — design minimalista, paleta neutra + acento índigo
   ========================================================= */

/* Tema único — escuro forçado, ignora prefers-color-scheme do sistema. */
:root {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --border-strong: #cbd5e1;
  --accent: #818cf8;
  --accent-soft: #312e81;
  --accent-hover: #a5b4fc;
  --error-bg: #7f1d1d;
  --error-text: #fecaca;
  --fixed-bg: #334155;
  --hint-bg: #064e3b;
  --hint-text: #a7f3d0;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-modal: 0 10px 40px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --radius-sm: 6px;
  --transition: 150ms ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========== Layout ========== */

.app {
  max-width: 540px;
  margin: 0 auto;
  padding: 24px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100%;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.title {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-item {
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 500;
}

#timer {
  font-size: 1rem;
  color: var(--text);
  min-width: 52px;
  text-align: right;
}

.error-counter {
  font-variant-numeric: tabular-nums;
  transition: color var(--transition);
}

.error-counter.warning {
  color: #d97706;        /* âmbar — 1 erro restante */
  font-weight: 600;
}

.error-counter.danger {
  color: var(--error-text);
  font-weight: 600;
}

/* ========== Board ========== */

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  height: 100%;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: var(--shadow);
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: clamp(1rem, 5vw, 1.5rem);
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
  position: relative;
  outline: none;
}

/* Bordas grossas entre blocos 3x3 */
.cell[data-col="2"], .cell[data-col="5"] { border-right: 2px solid var(--border-strong); }
.cell[data-row="2"], .cell[data-row="5"] { border-bottom: 2px solid var(--border-strong); }
.cell[data-col="0"] { border-left: none; }
.cell[data-col="8"] { border-right: none; }
.cell[data-row="0"] { border-top: none; }
.cell[data-row="8"] { border-bottom: none; }

.cell.fixed {
  background: var(--fixed-bg);
  font-weight: 600;
  cursor: default;
}

.cell.selected {
  background: var(--accent-soft);
  z-index: 1;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cell.highlight {
  background: var(--accent-soft);
}

.cell.fixed.highlight {
  background: color-mix(in srgb, var(--accent-soft) 70%, var(--fixed-bg));
}

.cell.same-number {
  color: var(--accent);
  font-weight: 600;
}

.cell.error {
  background: var(--error-bg);
  color: var(--error-text);
}

.cell.hint {
  animation: hintPulse 600ms ease;
}

@keyframes hintPulse {
  0%   { background: var(--hint-bg); }
  100% { background: var(--surface); }
}

.cell:hover:not(.fixed):not(.selected) {
  background: color-mix(in srgb, var(--accent-soft) 50%, var(--surface));
}

/* ========== Overlay de pausa ========== */

.overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  z-index: 5;
}

.overlay[hidden] {
  display: none;
}

.resume-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}

.resume-btn:hover {
  background: var(--accent-hover);
}

/* ========== Controles ========== */

.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.num-pad {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
}

.num-btn {
  aspect-ratio: 1;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.num-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.num-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.num-btn.erase {
  font-size: 1rem;
  color: var(--text-muted);
}

.num-btn.exhausted {
  opacity: 0.35;
  cursor: default;
}

.num-btn.exhausted:hover {
  background: var(--surface);
  border-color: var(--border);
}

.actions {
  display: flex;
  gap: 8px;
}

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary:focus-visible, .btn-secondary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary:disabled:hover {
  border-color: var(--border);
  color: var(--text);
}

.hint-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
}

/* ========== Botão de pausa (icone) ========== */

.icon-btn {
  width: 36px;
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition), background var(--transition);
  font-family: inherit;
  padding: 0;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon-pause {
  display: inline-block;
  width: 12px;
  height: 14px;
  border-left: 3px solid var(--text);
  border-right: 3px solid var(--text);
}

.icon-btn.paused .icon-pause {
  width: 0;
  height: 0;
  border-left: 9px solid var(--text);
  border-right: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

/* ========== Modais ========== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal[hidden] {
  display: none;
}

.modal-card {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-modal);
  text-align: center;
  animation: slideUp 250ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal-card h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.modal-sub {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  flex-direction: column;
}

.diff-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.diff-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: inherit;
  color: var(--text);
}

.diff-btn:hover, .diff-btn:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.diff-name {
  font-weight: 600;
  font-size: 1rem;
}

.diff-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.link-btn {
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

.link-btn:hover {
  color: var(--accent);
}

/* Modal de vitória */

.win-card {
  padding-top: 24px;
}

.win-emoji, .lose-emoji {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 600;
}

.win-emoji {
  background: var(--accent-soft);
  color: var(--accent);
}

.lose-emoji {
  background: var(--error-bg);
  color: var(--error-text);
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 20px 0 24px;
  padding: 16px;
  background: var(--fixed-bg);
  border-radius: var(--radius);
}

.win-stats div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.win-stats dt {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.win-stats dd {
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ========== Loader ========== */

.loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.loader[hidden] {
  display: none;
}

.loader-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== Responsividade ========== */

/* Mobile / tablets pequenos: num-pad em 2 linhas de 5 botões, alvos maiores. */
@media (max-width: 560px) {
  .num-pad {
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
  }
  .num-btn {
    font-size: 1.5rem;
    font-weight: 500;
  }
  .num-btn.erase {
    font-size: 1.3rem;
  }
}

@media (max-width: 420px) {
  .app {
    padding: 16px 12px 24px;
    gap: 16px;
  }
  .title {
    font-size: 1.25rem;
  }
  .actions {
    flex-direction: column;
  }
}

@media (min-width: 720px) {
  .app {
    max-width: 600px;
    padding: 40px 24px;
  }
}

/* Acessibilidade: respeita prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
