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

:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-light: #a5b4fc;
  --zone-0: #d4e6b5;
  --zone-1: #b8d4f0;
  --zone-2: #f5d0a9;
  --zone-3: #e8b4c8;
  --zone-4: #c5b8e8;
  --zone-5: #f0e6a0;
  --zone-6: #a8e0d0;
  --zone-7: #f0b8b8;
  --border-zone: #555;
  --border-cell: #ccc;
  --cell-selected: rgba(99, 102, 241, 0.25);
  --cell-highlight: rgba(99, 102, 241, 0.10);
  --error: #ef4444;
  --success: #22c55e;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  width: 100%;
  max-width: 520px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

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

header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* Screens */
.screen { display: none; width: 100%; }
.screen.active { display: block; }

/* Menu */
.difficulty-picker {
  background: var(--card);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 20px;
}

.difficulty-picker h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: center;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 16px 20px;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  margin-bottom: 10px;
  color: white;
}

.btn:last-child { margin-bottom: 0; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.btn:active { transform: scale(0.98); }

.btn span {
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.85;
}

.btn-easy { background: linear-gradient(135deg, #22c55e, #16a34a); }
.btn-medium { background: linear-gradient(135deg, #f59e0b, #d97706); }
.btn-hard { background: linear-gradient(135deg, #ef4444, #dc2626); }

.how-to-play {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.how-to-play h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.how-to-play ul {
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.7;
}

/* Game Header */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 12px;
}

.btn-back {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  padding: 6px 0;
}

.timer {
  font-size: 1.1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

/* Grid */
#grid-container {
  display: inline-grid;
  gap: 0;
  background: var(--border-zone);
  border: 3px solid var(--border-zone);
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
  max-width: 480px;
  min-height: 100px;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.1s;
  border: 0.5px solid var(--border-cell);
  aspect-ratio: 1;
}

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

.cell.user-value {
  color: var(--accent);
}

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

.cell.selected {
  box-shadow: inset 0 0 0 2.5px var(--accent);
  z-index: 2;
}

.cell.highlight {
  filter: brightness(0.93);
}

.cell.same-number {
  filter: brightness(0.88);
}

/* Zone borders */
.cell.border-top { border-top: 2.5px solid var(--border-zone); }
.cell.border-bottom { border-bottom: 2.5px solid var(--border-zone); }
.cell.border-left { border-left: 2.5px solid var(--border-zone); }
.cell.border-right { border-right: 2.5px solid var(--border-zone); }

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

.cell .notes span {
  font-size: 0.55rem;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Controls */
.controls {
  width: 100%;
  max-width: 480px;
  margin-top: 14px;
}

.number-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}

.num-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 12px;
  background: var(--card);
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: transform 0.1s, background 0.1s;
}

.num-btn:hover { background: #e8e8f0; }
.num-btn:active { transform: scale(0.93); }
.num-btn.active-stamp {
  background: var(--accent);
  color: white;
}

.action-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 18px;
  border: none;
  border-radius: 12px;
  background: var(--card);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: background 0.15s;
}

.action-btn:hover { background: #e8e8f0; }
.action-btn.active {
  background: var(--accent);
  color: white;
}

/* Overlay */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  justify-content: center;
  align-items: center;
}

.overlay.active {
  display: flex;
}

.win-card {
  background: var(--card);
  border-radius: 20px;
  padding: 36px 32px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  animation: pop 0.3s ease;
}

.win-card h2 {
  font-size: 1.8rem;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.win-card p {
  color: var(--text-muted);
  margin-bottom: 20px;
}

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

.loading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 40px;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Responsive */
@media (max-width: 400px) {
  .cell { font-size: 1.2rem; }
  .num-btn { width: 40px; height: 40px; font-size: 1rem; }
  .action-btn { padding: 8px 12px; }
  .cell .notes span { font-size: 0.45rem; }
}
