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

body {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
}

.app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.container {
  width: 100%;
  max-width: 500px;
  animation: fadeInScale 0.5s ease-out;
}

/* ── Header ── */
.header {
  text-align: center;
  margin-bottom: 24px;
}

.title {
  font-size: 2.25rem;
  font-weight: 800;
  color: white;
  letter-spacing: -0.025em;
  animation: slideDown 0.5s ease-out;
}

.subtitle {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* ── Top bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 4px;
}

.timer {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  padding: 6px 12px;
  color: white;
  font-family: "Courier New", monospace;
  font-size: 1.125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: transform 0.2s;
}
.timer:hover {
  transform: scale(1.05);
}

.timer-icon {
  width: 16px;
  height: 16px;
  opacity: 0.7;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  animation: popIn 0.3s ease-out;
}
.badge.easy { background: #10b981; }
.badge.medium { background: #f59e0b; }
.badge.hard { background: #f97316; }
.badge.expert { background: #f43f5e; }

.btn {
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}
.btn:active { transform: scale(0.95); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  color: white;
  font-size: 0.875rem;
  padding: 6px 12px;
  border-radius: 8px;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.2); }

.btn-primary {
  background: #2563eb;
  color: white;
  padding: 8px 24px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
}
.btn-primary:hover { background: #1d4ed8; }

/* ── Menu ── */
.menu-dropdown {
  overflow: hidden;
  margin-bottom: 12px;
  animation: slideDown 0.2s ease-out;
}
.menu-dropdown.hidden { display: none; }

.menu-content {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 12px;
}

.menu-label {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

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

.btn-diff {
  font-family: inherit;
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-diff:hover { transform: scale(1.05); }
.btn-diff:active { transform: scale(0.95); }
.btn-diff.active { box-shadow: 0 0 0 2px white; }

.btn-diff[data-diff="easy"] { background: #10b981; }
.btn-diff[data-diff="easy"]:not(.active) { background: rgba(255,255,255,0.1); }
.btn-diff[data-diff="medium"] { background: #f59e0b; }
.btn-diff[data-diff="medium"]:not(.active) { background: rgba(255,255,255,0.1); }
.btn-diff[data-diff="hard"] { background: #f97316; }
.btn-diff[data-diff="hard"]:not(.active) { background: rgba(255,255,255,0.1); }
.btn-diff[data-diff="expert"] { background: #f43f5e; }
.btn-diff[data-diff="expert"]:not(.active) { background: rgba(255,255,255,0.1); }

/* ── Board ── */
.board-wrapper {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  background: white;
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  outline: none;
  transition: background-color 0.075s;
  border: 1px solid #d0d7de;
  border-radius: 0;
  font-size: clamp(1rem, 4vw, 1.5rem);
  -webkit-tap-highlight-color: transparent;
}

.cell:focus-visible {
  box-shadow: inset 0 0 0 2px #3b82f6;
}

/* 3x3 box borders */
.cell:nth-child(9n+3),
.cell:nth-child(9n+6) { border-right-width: 2px; border-right-color: #37474f; }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54),
.cell:nth-child(n+73):nth-child(-n+81) { border-bottom-width: 2px; border-bottom-color: #37474f; }

.cell:nth-child(9n-8) { border-left: none; }
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(-n+9) { border-top: none; }
.cell:nth-child(n+73) { border-bottom: none; }

.cell.selected { background: #bbdefb !important; z-index: 1; }
.cell.related { background: #e3f2fd; }
.cell.same-value { background: #c5d9f0; }
.cell.conflict { background: #ffcdd2; }
.cell.hint { background: #fff9c4; }
.cell.hover:not(.selected):not(.conflict) { background: #f8f9fa; }

.cell.given { color: #1a237e; font-weight: 700; }
.cell.filled { color: #0d47a1; font-weight: 600; }
.cell.user-value { color: #0d47a1; font-weight: 600; }
.cell.conflict .cell-value { color: #dc2626; }

.cell-value {
  animation: popIn 0.2s ease-out;
}

/* Pencil marks grid */
.pencil-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 1px;
}

.pencil-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.3rem, 1.2vw, 0.55rem);
  color: #94a3b8;
  font-weight: 500;
  animation: popIn 0.15s ease-out;
}

/* ── Completion overlay ── */
.completion-overlay {
  position: absolute;
  inset: 0;
  background: white;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
  animation: fadeInScale 0.4s ease-out;
}
.completion-overlay.hidden { display: none; }

.completion-content {
  text-align: center;
  animation: slideUp 0.5s ease-out;
}

.completion-emoji {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: wiggle 0.6s ease-in-out;
}

.completion-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 4px;
}

.completion-time {
  color: #64748b;
  margin-bottom: 16px;
}

/* ── Action buttons ── */
.actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  color: white;
}
.action-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
.action-btn:active:not(:disabled) { transform: scale(0.95); }
.action-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.action-btn.active {
  background: #2563eb;
  box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
}

.action-icon { font-size: 1.125rem; }
.action-label { font-size: 0.625rem; font-weight: 600; }

/* ── Number pad ── */
.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  margin-top: 16px;
  animation: slideUp 0.3s ease-out;
}

.numpad-btn {
  aspect-ratio: 1;
  border-radius: 12px;
  font-size: 1.25rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  color: white;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.numpad-btn:hover:not(:disabled) {
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.3);
}
.numpad-btn:active:not(:disabled) { transform: scale(0.9); }
.numpad-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}
.numpad-btn.used {
  opacity: 0.35;
  cursor: default;
}

.keyboard-hint {
  text-align: center;
  color: rgba(255, 255, 255, 0.3);
  font-size: 0.75rem;
  margin-top: 16px;
}

.sudoku-home-fab {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1rem 0.65rem 0.85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: #4c1d95;
  font-size: 0.875rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.sudoku-home-fab:hover {
  color: #5b21b6;
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
}

.sudoku-home-fab i {
  font-size: 1rem;
}

/* ── Animations ── */
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes popIn {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-10deg); }
  50% { transform: rotate(10deg); }
  75% { transform: rotate(-10deg); }
}
