:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --bg-color: #f8fafc;
  --grid-bg: #fff;
  --border-color: #cbd5e1;
  --border-strong: #475569;
  --text-color: #1e293b;
  --fixed-color: #0f172a;
  --user-color: #3b82f6;
  --error-color: #ef4444;
  --selected-bg: #dbeafe;
  --highlight-bg: #eff6ff;
  --same-num-bg: #bfdbfe;
  --note-color: #64748b;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  height: 100vh;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.app-container {
  width: 100%;
  max-width: 500px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
  text-align: center;
  color: var(--primary-dark);
}

.stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 500;
}

.difficulty-select select {
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  border: 1px solid var(--border-color);
  background: white;
  color: var(--text-color);
  font-family: inherit;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.mistakes {
  color: var(--error-color);
}

main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 1rem;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1;
  background: var(--grid-bg);
  border: 2px solid var(--border-strong);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.cell {
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: background-color 0.1s ease;
}

/* Thicker borders for 3x3 grids */
.cell.border-right {
  border-right: 2px solid var(--border-strong);
}

.cell.border-bottom {
  border-bottom: 2px solid var(--border-strong);
}

/* Specific border adjustments to avoid double borders or misalignment */
/* Actually grid gap might be easier but border logic is standard for Sudoku */
/* Just ensure the last column/row doesn't have extra thick border if it's the grid edge */
.cell:nth-child(9n) {
  border-right: none;
}
.cell:nth-child(n+73) {
  border-bottom: none;
}


/* Cell States */
.cell.fixed {
  color: var(--fixed-color);
  font-weight: 700;
  background-color: #f1f5f9;
}

.cell:not(.fixed) {
  color: var(--user-color);
}

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

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

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

.cell.error {
  color: var(--error-color) !important;
  background-color: #fee2e2 !important;
}

/* Notes Grid inside cell */
.cell .notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
  font-size: 0.6rem;
  line-height: 1;
  color: var(--note-color);
  pointer-events: none;
  align-content: center; /* Center content vertically if flex/grid allows */
  text-align: center;
  word-break: break-all; /* Fallback */
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 1px;
}

/* Controls */
.controls-area {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.tools {
  display: flex;
  justify-content: space-around;
}

.tools button {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-color);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.5rem;
  transition: background-color 0.2s;
}

.tools button:hover {
  background-color: #e2e8f0;
}

.tools button.active {
  color: var(--primary);
  background-color: var(--selected-bg);
}

.tools button svg {
  width: 20px;
  height: 20px;
}

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

.num-btn {
  aspect-ratio: 1; /* For perfectly square buttons if space allows, or roughly square */
  padding: 0;
  height: 3rem; /* Fixed height for better touch */
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  transition: all 0.1s;
}

.num-btn:active {
  transform: translateY(1px);
  background-color: #f1f5f9;
  box-shadow: none;
}

.secondary-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

#btn-new-game, #btn-daily {
  padding: 0.5rem 1.5rem;
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.5);
  transition: transform 0.1s, box-shadow 0.1s;
}

#btn-daily {
  background-color: #8b5cf6; /* Purple for daily */
  box-shadow: 0 4px 6px -1px rgba(139, 92, 246, 0.5);
}

#btn-new-game:active, #btn-daily:active {
  transform: translateY(1px);
  box-shadow: 0 2px 4px -1px rgba(59, 130, 246, 0.5);
}

/* Animations */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.shake {
  animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes pop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.cell:not(.fixed) {
  animation: pop 0.2s ease-out;
}

/* Paused state */
.game-board.paused .cell {
  color: transparent !important;
  background: #e2e8f0 !important;
}

.game-board.paused .cell.border-right,
.game-board.paused .cell.border-bottom {
  border-color: #cbd5e1;
}


/* Responsive adjustments */
@media (min-width: 600px) {
  .app-container {
    padding: 2rem;
  }

  .game-board {
    border-width: 4px;
  }

  .cell {
    font-size: 2rem;
  }

  .numpad {
    gap: 0.5rem;
  }
}
