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

:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --secondary: #ec4899;
  --accent: #06b6d4;
  --bg-dark: #0f172a;
  --bg-lighter: #1e293b;
  --border-light: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --success: #10b981;
  --error: #ef4444;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Poppins', sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
}

.background {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.gradient-1, .gradient-2, .gradient-3 {
  position: absolute;
  border-radius: 50%;
  opacity: 0.1;
  blur: 80px;
}

.gradient-1 {
  width: 400px;
  height: 400px;
  background: var(--primary);
  top: -100px;
  right: -100px;
  animation: float 6s ease-in-out infinite;
}

.gradient-2 {
  width: 300px;
  height: 300px;
  background: var(--secondary);
  bottom: -50px;
  left: -50px;
  animation: float 8s ease-in-out infinite reverse;
}

.gradient-3 {
  width: 350px;
  height: 350px;
  background: var(--accent);
  top: 50%;
  left: 50%;
  animation: float 7s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(30px, 30px); }
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.header {
  text-align: center;
}

.title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 20px;
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.stat-item {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(10px);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 4px;
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-light);
}

.controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.difficulty-selector {
  display: flex;
  gap: 8px;
  background: rgba(30, 41, 59, 0.4);
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
}

.diff-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: capitalize;
}

.diff-btn:hover {
  color: var(--primary-light);
  background: rgba(99, 102, 241, 0.1);
}

.diff-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-new-game {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-new-game:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

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

.board-container {
  position: relative;
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 2px;
  background: var(--border-light);
  padding: 3px;
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1;
}

.cell {
  background: var(--bg-lighter);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(1.2rem, 4vw, 1.5rem);
  font-weight: 700;
  color: var(--text-primary);
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}

.cell:hover:not(.immutable) {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
}

.cell.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary-light);
}

.cell.immutable {
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-primary);
  cursor: default;
  font-weight: 700;
}

.cell.error {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--error);
  color: #fca5a5;
}

.cell.hint {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--success);
}

.cell.related {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.3);
}

.cell-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  width: 100%;
  height: 100%;
  padding: 2px;
}

.note {
  font-size: 0.5em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.8);
  border-radius: 12px;
  backdrop-filter: blur(4px);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.toolbar {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  background: rgba(30, 41, 59, 0.5);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tool-btn svg {
  width: 20px;
  height: 20px;
}

.tool-btn:hover {
  border-color: var(--primary);
  color: var(--primary-light);
  background: rgba(99, 102, 241, 0.1);
}

.tool-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

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

.numpad-btn {
  padding: 12px;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'JetBrains Mono', monospace;
}

.numpad-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
  color: var(--primary-light);
  transform: translateY(-2px);
}

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

.numpad-btn.clear {
  grid-column: 1 / -1;
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--error);
  color: #fca5a5;
}

.numpad-btn.clear:hover {
  background: rgba(239, 68, 68, 0.2);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

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

.modal-content {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(30, 41, 59, 0.85));
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 40px 30px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  backdrop-filter: blur(10px);
  animation: slideUp 0.3s ease;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

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

.modal-emoji {
  font-size: 3.5rem;
  margin-bottom: 20px;
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.modal-content h2 {
  font-size: 2rem;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-time,
.modal-moves {
  color: var(--text-secondary);
  font-size: 1rem;
  margin: 8px 0;
  font-family: 'JetBrains Mono', monospace;
}

.modal-content .btn-new-game {
  margin-top: 24px;
  width: 100%;
}

/* Responsive Design */
@media (max-width: 600px) {
  .container {
    padding: 16px;
    gap: 16px;
  }

  .title {
    font-size: 2rem;
  }

  .stats-row {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
  }

  .stat-item {
    padding: 10px;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .controls-bar {
    gap: 8px;
  }

  .difficulty-selector {
    gap: 4px;
  }

  .diff-btn {
    padding: 4px 8px;
    font-size: 0.8rem;
  }

  .btn-new-game {
    padding: 8px 16px;
    font-size: 0.85rem;
  }

  .board {
    gap: 1px;
    padding: 2px;
  }

  .cell {
    font-size: clamp(1rem, 3vw, 1.3rem);
  }

  .cell-notes {
    gap: 1px;
    padding: 1px;
  }

  .note {
    font-size: 0.4em;
  }

  .toolbar {
    gap: 6px;
  }

  .tool-btn {
    width: 40px;
    height: 40px;
  }

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

  .numpad {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }

  .numpad-btn {
    padding: 10px;
    font-size: 1rem;
  }

  .modal-content {
    padding: 30px 20px;
  }

  .modal-emoji {
    font-size: 3rem;
  }

  .modal-content h2 {
    font-size: 1.5rem;
  }
}

@media (max-width: 400px) {
  .container {
    padding: 12px;
    gap: 12px;
  }

  .title {
    font-size: 1.5rem;
    margin-bottom: 12px;
  }

  .stats-row {
    gap: 6px;
  }

  .stat-item {
    padding: 8px;
  }

  .stat-label {
    font-size: 0.65rem;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  .numpad {
    grid-template-columns: repeat(4, 1fr);
  }

  .numpad-btn {
    padding: 8px;
    font-size: 0.9rem;
  }

  .modal-content {
    padding: 24px 16px;
  }

  .modal-emoji {
    font-size: 2.5rem;
  }
}
