/* ============================================
   SUDOKU - Dark Theme Styles
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Arial, sans-serif;
  background: #0f0f0f;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e0e0e0;
  overflow: hidden;
}

.game-container {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  justify-content: center;
}

/* ============================================
   START SCREEN
   ============================================ */

.screen {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-title {
  font-size: 3em;
  font-weight: 800;
  background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 50%, #f59e0b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  letter-spacing: -1px;
}

.subtitle {
  color: #888;
  font-size: 1.1em;
  margin-bottom: 32px;
}

.difficulty-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 280px;
}

.btn-difficulty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 16px 24px;
  background: #1a1a2e;
  border: 2px solid #2a2a4a;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #e0e0e0;
  font-family: inherit;
}

.btn-difficulty:hover {
  border-color: #f59e0b;
  background: #1e1e38;
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(245, 158, 11, 0.15);
}

.btn-difficulty:active {
  transform: translateY(0);
}

.diff-label {
  font-size: 1.2em;
  font-weight: 700;
  color: #f59e0b;
}

.diff-desc {
  font-size: 0.8em;
  color: #888;
}

/* ============================================
   TOP BAR
   ============================================ */

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 4px;
  margin-bottom: 12px;
}

.top-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #666;
  font-weight: 600;
}

.stat-value {
  font-size: 1.1em;
  font-weight: 700;
  color: #e0e0e0;
  font-variant-numeric: tabular-nums;
}

#difficulty-badge {
  font-size: 0.75em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(245, 158, 11, 0.25);
}

/* ============================================
   SUDOKU BOARD
   ============================================ */

#board-wrapper {
  width: 100%;
  aspect-ratio: 1;
  max-width: 432px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1;
  background: #2a2a4a;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #3a3a5a;
  gap: 0;
  /* Subgrid lines via box-shadow on cells */
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 4.5vw, 24px);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s ease;
  position: relative;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 0.5px solid #2a2a4a;
}

/* 3x3 box borders - thicker lines */
.cell.border-right {
  border-right: 2px solid #3a3a5a;
}

.cell.border-bottom {
  border-bottom: 2px solid #3a3a5a;
}

/* Given (pre-filled) cells */
.cell.given {
  color: #c0c0d0;
  font-weight: 800;
}

/* User-placed cells */
.cell.user-placed {
  color: #f59e0b;
}

/* Selected cell */
.cell.selected {
  background: rgba(245, 158, 11, 0.25) !important;
  box-shadow: inset 0 0 0 2px #f59e0b;
  z-index: 2;
}

/* Same number highlight */
.cell.same-number {
  background: rgba(245, 158, 11, 0.1);
}

/* Same row/col/box highlight */
.cell.same-group {
  background: rgba(245, 158, 11, 0.06);
}

/* Conflict highlight */
.cell.conflict {
  color: #ef4444 !important;
  animation: shake 0.3s ease;
}

.cell.conflict-bg {
  background: rgba(239, 68, 68, 0.12) !important;
}

/* Notes (pencil marks) */
.cell .notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.cell .notes-grid span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(7px, 1.6vw, 10px);
  font-weight: 600;
  color: #7a8ab0;
  line-height: 1;
}

/* Hint animation */
.cell.hint-reveal {
  animation: hintPulse 0.6s ease;
}

@keyframes hintPulse {
  0% { background: rgba(245, 158, 11, 0.5); transform: scale(1.08); }
  100% { background: rgba(245, 158, 11, 0.25); transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

/* ============================================
   NUMBER PAD
   ============================================ */

#numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  width: 100%;
  margin-top: 14px;
  padding: 0 2px;
}

.numpad-btn {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 4vw, 22px);
  font-weight: 700;
  font-family: inherit;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 2px solid #2a2a4a;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  position: relative;
}

.numpad-btn:hover {
  background: #252545;
  border-color: #f59e0b;
}

.numpad-btn:active {
  transform: scale(0.93);
}

.numpad-btn.active-number {
  background: #f59e0b;
  color: #0f0f0f;
  border-color: #f59e0b;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.3);
}

/* Completed number (all 9 placed) */
.numpad-btn.completed {
  opacity: 0.25;
  pointer-events: none;
}

/* Count badge */
.numpad-btn .count-badge {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 8px;
  font-weight: 600;
  color: #666;
  line-height: 1;
}

/* ============================================
   ACTION BAR
   ============================================ */

.action-bar {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 14px;
  width: 100%;
}

.btn-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: #888;
  cursor: pointer;
  transition: all 0.15s ease;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.7em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex: 1;
  max-width: 80px;
}

.btn-action:hover {
  color: #e0e0e0;
  background: rgba(255, 255, 255, 0.05);
}

.btn-action:active {
  transform: scale(0.93);
}

.btn-action.active {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
}

.btn-action svg {
  width: 22px;
  height: 22px;
}

/* ============================================
   NEW GAME BUTTON
   ============================================ */

.btn-new-game {
  margin-top: 14px;
  padding: 12px 32px;
  background: transparent;
  border: 1.5px solid #3a3a5a;
  color: #888;
  font-size: 0.85em;
  font-weight: 600;
  font-family: inherit;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.5px;
}

.btn-new-game:hover {
  border-color: #f59e0b;
  color: #f59e0b;
}

/* ============================================
   OVERLAYS
   ============================================ */

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.35s ease;
}

.overlay-content {
  background: linear-gradient(145deg, #1a1a2e, #16162a);
  border-radius: 24px;
  padding: 40px 36px;
  text-align: center;
  border: 2px solid #2a2a4a;
  max-width: 90%;
  width: 360px;
  animation: slideUp 0.4s ease;
}

.overlay-content.gameover {
  border-color: rgba(239, 68, 68, 0.3);
}

.win-icon {
  font-size: 64px;
  color: #f59e0b;
  margin-bottom: 16px;
  animation: bounce 0.6s ease;
  display: inline-block;
}

.gameover-icon {
  color: #ef4444;
  font-size: 56px;
}

.overlay-title {
  font-size: 1.8em;
  font-weight: 800;
  color: #f59e0b;
  margin-bottom: 24px;
}

.gameover-title {
  color: #ef4444;
}

.overlay-subtitle {
  color: #888;
  margin-bottom: 24px;
  font-size: 0.95em;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 28px;
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.win-stat-label {
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #666;
  font-weight: 600;
}

.win-stat-value {
  font-size: 1.4em;
  font-weight: 800;
  color: #e0e0e0;
}

.btn-play-again {
  padding: 14px 40px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0f0f0f;
  border: none;
  border-radius: 12px;
  font-size: 1.05em;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 20px rgba(245, 158, 11, 0.3);
}

.btn-play-again:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(245, 158, 11, 0.4);
}

.btn-play-again:active {
  transform: translateY(0);
}

/* ============================================
   ANIMATIONS
   ============================================ */

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

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

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* Win confetti particles (generated via JS) */
.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  z-index: 200;
  pointer-events: none;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateY(100vh) rotate(720deg);
  }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 380px) {
  .game-container {
    padding: 8px;
  }

  .action-bar {
    gap: 2px;
  }

  .btn-action {
    padding: 8px 10px;
    font-size: 0.6em;
  }

  .btn-action svg {
    width: 18px;
    height: 18px;
  }

  #numpad {
    gap: 4px;
  }
}

/* Tall phones: add some extra spacing */
@media (min-height: 800px) and (max-width: 460px) {
  .top-bar {
    margin-bottom: 16px;
  }

  #numpad {
    margin-top: 18px;
  }

  .action-bar {
    margin-top: 16px;
  }
}

/* Short screens: squeeze layout */
@media (max-height: 680px) {
  .game-container {
    padding: 6px;
    justify-content: flex-start;
    padding-top: 4px;
  }

  .top-bar {
    margin-bottom: 6px;
  }

  #numpad {
    margin-top: 8px;
  }

  .action-bar {
    margin-top: 8px;
  }

  .btn-new-game {
    margin-top: 8px;
    padding: 8px 24px;
  }

  .btn-action {
    padding: 6px 10px;
  }
}

/* Desktop: cap the width and center nicely */
@media (min-width: 768px) {
  body {
    background: radial-gradient(ellipse at center, #1a1a2e 0%, #0f0f0f 70%);
  }

  .game-container {
    min-height: auto;
    padding: 24px;
  }
}
