:root {
  --bg: #e8f0fe;
  --board-bg: #ffffff;
  --cell-bg: #f5f8ff;
  --cell-hover: #dbe8ff;
  --cell-selected: #a8ccff;
  --cell-highlight: #e4edfa;
  --cell-same-num: #c2daff;
  --cell-given: #1a2a4a;
  --cell-user: #2b6cb0;
  --cell-error: #e53e3e;
  --cell-correct-flash: #48bb78;
  --text: #1a2a4a;
  --text-dim: #718096;
  --accent: #3b82f6;
  --accent-glow: rgba(59,130,246,0.25);
  --panel-bg: #ffffff;
  --thin-line: #d0d8e8;
  --thick-line: #3b82f6;
  --key-shadow: #a0aec0;
  --key-bg: #e2ecf9;
  --key-hover: #cddcf3;
}

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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Side-by-side layout */
.game-container {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  max-height: 100vh;
  padding: 12px;
}

.board-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.board-container {
  background: var(--board-bg);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 2px 16px rgba(59,130,246,0.1);
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 64px);
  grid-template-rows: repeat(9, 64px);
  border: 2px solid var(--thick-line);
  border-radius: 4px;
  overflow: hidden;
}

.cell {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  font-size: 26px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  border-right: 1px solid var(--thin-line);
  border-bottom: 1px solid var(--thin-line);
  transition: background 0.12s;
}
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }
.cell.thick-right { border-right: 2px solid var(--thick-line); }
.cell.thick-bottom { border-bottom: 2px solid var(--thick-line); }

.cell:hover { background: var(--cell-hover); }
.cell.selected { background: var(--cell-selected); z-index: 1; }
.cell.highlighted { background: var(--cell-highlight); }
.cell.same-number { background: var(--cell-same-num); }
.cell.given { color: var(--cell-given); }
.cell.user-filled { color: var(--cell-user); }
.cell.error { color: var(--cell-error); animation: shake 0.35s ease; }
.cell.error-flash { background: rgba(229,62,62,0.18); }
.cell.win-green { background: var(--cell-correct-flash); color: #fff; transition: background 0.3s; }
.cell.place-shine { animation: shine 0.5s ease; }

@keyframes shine {
  0%   { background: var(--cell-bg); box-shadow: none; }
  35%  { background: #b0d8ff; box-shadow: 0 0 14px rgba(59,130,246,0.45); }
  100% { background: var(--cell-bg); box-shadow: none; }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* Numpad */
.numpad-container {
  background: var(--panel-bg);
  padding: 8px;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.07);
}
.numpad { display: flex; justify-content: center; gap: 4px; }
.num-key {
  background: var(--key-bg);
  color: var(--text);
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  font-size: 18px; font-weight: bold;
  cursor: pointer; user-select: none;
  box-shadow: 0 2px 0 var(--key-shadow);
  transition: all 0.1s;
}
.num-key:hover { background: var(--key-hover); transform: translateY(-1px); }
.num-key:active { transform: translateY(1px); box-shadow: none; }
.num-key.active-num { background: var(--accent); color: #fff; box-shadow: 0 2px 0 #2563a8, 0 0 10px var(--accent-glow); }
.num-key.completed { opacity: 0.25; pointer-events: none; }
.erase-key { width: 50px; }

/* Right panel */
.panel-side {
  background: var(--panel-bg);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 180px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  align-self: stretch;
}

.stat-block {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 18px; font-weight: bold; color: var(--accent); }

.panel-divider { height: 1px; background: var(--thin-line); margin: 2px 0; }

.diff-buttons { display: flex; gap: 4px; }

.panel-btn {
  background: var(--key-bg);
  border: 1.5px solid var(--thin-line);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  text-align: center;
}
.panel-btn:hover { border-color: var(--accent); background: var(--cell-hover); }
.panel-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.panel-btn .hint { font-size: 10px; opacity: 0.6; }

.diff-btn { width: auto; flex: 1; padding: 5px 8px; font-size: 12px; }

/* Overlays */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.overlay-content {
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.overlay-content h2 { color: var(--accent); font-size: 24px; margin-bottom: 8px; }
.overlay-content p { color: var(--text-dim); font-size: 14px; margin-bottom: 16px; }
.overlay-content .panel-btn { width: auto; display: inline-block; padding: 8px 24px; }

.confirm-buttons { display: flex; gap: 10px; justify-content: center; }
.confirm-yes { background: var(--accent); color: #fff; border-color: var(--accent); }
.confirm-no { background: #fff; }

/* Clipart hearts */
.hearts-row { display: flex; gap: 4px; }
.heart {
  width: 22px; height: 20px;
  position: relative;
  display: inline-block;
}
.heart::before, .heart::after {
  content: '';
  position: absolute;
  width: 12px; height: 18px;
  background: #e53e3e;
  border-radius: 12px 12px 0 0;
  top: 0;
}
.heart::before { left: 11px; transform: rotate(-45deg); transform-origin: 0 100%; }
.heart::after { left: 0; transform: rotate(45deg); transform-origin: 100% 100%; }

.heart.lost::before, .heart.lost::after { background: #cbd5e1; }

/* Number count badges */
.num-key { position: relative; }
.num-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Progress bar */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--thin-line);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 4px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}
.stat-sub {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Debug panel */
.debug-btn { background: rgba(229,62,62,0.08); border-color: rgba(229,62,62,0.3); }
.debug-btn:hover { background: rgba(229,62,62,0.15); border-color: var(--cell-error); }

/* Win screen */
.win-content {
  background: linear-gradient(145deg, #ffffff, #e8f0fe);
  border: 3px solid var(--accent);
  border-radius: 24px;
  padding: 40px 50px;
  text-align: center;
  box-shadow: 0 12px 60px rgba(59,130,246,0.3), 0 0 80px rgba(59,130,246,0.1);
  animation: winPop 0.5s cubic-bezier(0.34,1.56,0.64,1);
  position: relative;
  overflow: hidden;
}

@keyframes winPop {
  0% { transform: scale(0.5) rotate(-3deg); opacity: 0; }
  60% { transform: scale(1.05) rotate(1deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.win-trophy {
  font-size: 64px;
  animation: trophyBounce 1s ease infinite;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 12px rgba(255,193,7,0.4));
}

@keyframes trophyBounce {
  0%,100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.05); }
}

.win-heading {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 16px;
  letter-spacing: -0.5px;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 16px;
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(59,130,246,0.08);
  border-radius: 12px;
  padding: 10px 18px;
}

.win-stat-icon { font-size: 22px; }
.win-stat-val { font-size: 16px; font-weight: 700; color: var(--text); }

.win-rating {
  font-size: 32px;
  margin-bottom: 18px;
  letter-spacing: 4px;
}

.win-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 32px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(59,130,246,0.3);
}
.win-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(59,130,246,0.4); }

/* Confetti particles */
.win-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  top: -10px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(350px) rotate(720deg); opacity: 0; }
}
