:root {
  /* Light Theme */
  --bg-color: #f7f9fc;
  --surface: #ffffff;
  --text-main: #2b2d42;
  --text-muted: #8d99ae;
  --primary: #4361ee;
  --primary-hover: #3a0ca3;
  --border: #e2eafc;
  --grid-border: #2b2d42;
  --cell-bg: #ffffff;
  --cell-selected: #e2eafc;
  --cell-highlight: #f8f9fa;
  --cell-error: #ef233c;
  --cell-error-bg: #ffe5e5;
  --cell-given: #2b2d42;
  --cell-input: #4361ee;
  --cell-conflict: #ffa6a6;
  --badge-bg: #ef233c;
  --badge-color: white;
}

[data-theme="dark"] {
  --bg-color: #0f172a;
  --surface: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --border: #334155;
  --grid-border: #64748b;
  --cell-bg: #1e293b;
  --cell-selected: #3b82f640;
  --cell-highlight: #334155;
  --cell-error: #f43f5e;
  --cell-error-bg: #f43f5e40;
  --cell-given: #f8fafc;
  --cell-input: #60a5fa;
  --cell-conflict: #f43f5e80;
  --badge-bg: #f43f5e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.3s, color 0.3s;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.theme-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
}

#themeBtn {
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
}

.container {
  max-width: 500px;
  width: 100%;
}

header {
  text-align: center;
  margin-bottom: 24px;
}

h1 {
  font-family: 'Playfair Display', serif;
  font-size: 2.5rem;
  margin-bottom: 16px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.stats-bar {
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-muted);
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  aspect-ratio: 1;
  width: 100%;
  background-color: var(--grid-border);
  gap: 1px;
  border: 2px solid var(--grid-border);
}

/* 3x3 block separation */
.sudoku-grid .cell:nth-child(3n) { margin-right: 2px; }
.sudoku-grid .cell:nth-child(n+19):nth-child(-n+27),
.sudoku-grid .cell:nth-child(n+46):nth-child(-n+54) { margin-bottom: 2px; }
/* remove right/bottom margins from actual edges */
.sudoku-grid .cell:nth-child(9n) { margin-right: 0 !important; }
.sudoku-grid .cell:nth-child(n+73) { margin-bottom: 0 !important; }


.cell {
  background-color: var(--cell-bg);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(20px, 6vw, 28px);
  cursor: pointer;
  user-select: none;
  font-family: 'Playfair Display', serif;
  font-weight: 600;
  position: relative;
}

.cell.given {
  color: var(--cell-given);
  cursor: default;
}

.cell.input {
  color: var(--cell-input);
}

.cell.selected {
  background-color: var(--cell-selected) !important;
}

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

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

.cell.conflict {
  background-color: var(--cell-conflict) !important;
  color: white !important;
}

.cell .candidates {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(8px, 2.5vw, 12px);
  font-family: 'Inter', sans-serif;
  color: var(--text-muted);
  font-weight: 400;
  pointer-events: none;
}

.cell .candidates .cand {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Controls */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.actions-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.action-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 12px 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
}

.action-btn:hover {
  background: var(--cell-highlight);
}

.action-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.badge {
  background-color: var(--badge-bg);
  color: var(--badge-color);
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 10px;
  position: absolute;
  top: -6px;
  right: -6px;
  font-weight: bold;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 8px;
}

.num-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--primary);
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 700;
  padding: 12px 0;
  border-radius: 8px;
  cursor: pointer;
}

.num-btn:hover {
  background: var(--primary);
  color: white;
}

.game-controls {
  display: flex;
  gap: 12px;
}

.primary-btn, .secondary-btn {
  flex: 1;
  padding: 14px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

.primary-btn {
  background: var(--primary);
  color: white;
}

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

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

.secondary-btn:hover {
  background: var(--cell-highlight);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--surface);
  padding: 32px;
  border-radius: 16px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-content h2 {
  font-family: 'Playfair Display', serif;
  margin-bottom: 24px;
}

.difficulty-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
}

.diff-btn {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
  padding: 12px;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
}

.diff-btn:hover {
  background: var(--primary);
  color: white;
}

.diff-btn.challenge {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border: none;
}

.close-btn {
  margin-top: 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  text-decoration: underline;
}

/* Fireworks Celebration */
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); color: var(--primary); }
  100% { transform: scale(1); }
}

.celebrate {
  animation: pop 0.5s ease;
}
