/* =========================================
   GAMES MODULE — SUDOKU
   ========================================= */

/* ─── Level Selector Screen ─── */
.games-hub {
  padding: 4px 0 12px;
}

.games-hub-title {
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  margin-bottom: 4px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.games-hub-sub {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

/* Game tiles on hub */
.games-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.game-tile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.game-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(59,130,246,0.06), rgba(139,92,246,0.06));
  opacity: 0;
  transition: opacity 0.2s ease;
}

.game-tile:hover::before {
  opacity: 1;
}

.game-tile:hover {
  border-color: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(59,130,246,0.14);
}

.game-tile:active {
  transform: scale(0.98);
}

.game-tile-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(59,130,246,0.25);
}

.game-tile-info {
  flex: 1;
  min-width: 0;
}

.game-tile-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.game-tile-desc {
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.game-tile-arrow {
  font-size: 18px;
  color: var(--text-secondary);
  opacity: 0.5;
  flex-shrink: 0;
}

/* ─── Sudoku Game Screen ─── */
.sudoku-screen {
  display: none;
  flex-direction: column;
  gap: 0;
  animation: fadeIn 0.18s ease forwards;
}

.sudoku-screen.active {
  display: flex;
}

/* Level Select Screen */
.sudoku-level-screen {
  display: none;
  animation: fadeIn 0.18s ease forwards;
}

.sudoku-level-screen.active {
  display: block;
}

.sudoku-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
  margin-bottom: 12px;
  transition: opacity 0.15s ease;
}

.sudoku-back-btn:hover { opacity: 0.75; }

.sudoku-level-title {
  font-size: 20px;
  font-weight: 900;
  text-align: center;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.sudoku-level-sub {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* Level Cards */
.sudoku-levels-grid {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.sudoku-level-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.sudoku-level-card:hover {
  transform: translateX(4px);
  border-color: var(--accent-light);
}

.sudoku-level-card:active {
  transform: scale(0.98);
}

.level-emoji {
  font-size: 22px;
  width: 40px;
  text-align: center;
  flex-shrink: 0;
}

.level-info {
  flex: 1;
}

.level-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 1px;
}

.level-detail {
  font-size: 11px;
  color: var(--text-secondary);
}

.level-badge {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.level-badge.badge-easy   { background: rgba(16,185,129,0.15); color: #10b981; }
.level-badge.badge-medium { background: rgba(245,158,11,0.15); color: #f59e0b; }
.level-badge.badge-hard   { background: rgba(239,68,68,0.15);  color: #ef4444; }
.level-badge.badge-expert { background: rgba(139,92,246,0.15); color: #8b5cf6; }
.level-badge.badge-master { background: rgba(236,72,153,0.15); color: #ec4899; }

/* ─── Sudoku Play Screen ─── */
.sudoku-play-screen {
  display: none;
  flex-direction: column;
  animation: fadeIn 0.18s ease forwards;
}

.sudoku-play-screen.active {
  display: flex;
}

/* Top row: back + level name */
.sudoku-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sudoku-level-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Stats row: timer, mistakes, best */
.sudoku-stats-row {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 6px;
  margin-bottom: 12px;
}

.sudoku-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.sudoku-stat-label {
  font-size: 9.5px;
  color: var(--text-secondary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sudoku-stat-value {
  font-size: 17px;
  font-weight: 900;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.sudoku-stat-value.timer-running {
  color: var(--accent);
}

.sudoku-stat-value.mistakes-warn {
  color: var(--warning);
}

.sudoku-stat-value.mistakes-danger {
  color: var(--danger);
  animation: shake 0.3s ease;
}

/* ─── Sudoku Grid ─── */
.sudoku-grid-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 12px;
}

.sudoku-grid {
  display: grid;
  border: 2.5px solid var(--text-secondary);
  border-radius: 10px;
  overflow: hidden;
  touch-action: manipulation;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  max-width: min(360px, calc(100vw - 32px));
  width: min(360px, calc(100vw - 32px));
  aspect-ratio: 1;
}

/* Grid size variants */
.sudoku-grid.size-2 { grid-template-columns: repeat(2, 1fr); }
.sudoku-grid.size-3 { grid-template-columns: repeat(3, 1fr); }
.sudoku-grid.size-4 { grid-template-columns: repeat(4, 1fr); }
.sudoku-grid.size-6 { grid-template-columns: repeat(6, 1fr); }
.sudoku-grid.size-9 { grid-template-columns: repeat(9, 1fr); }

.sudoku-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  font-weight: 800;
  color: var(--text-primary);
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

/* Font sizes by grid size */
.sudoku-grid.size-2 .sudoku-cell { font-size: 36px; }
.sudoku-grid.size-3 .sudoku-cell { font-size: 28px; }
.sudoku-grid.size-4 .sudoku-cell { font-size: 22px; }
.sudoku-grid.size-6 .sudoku-cell { font-size: 16px; }
.sudoku-grid.size-9 .sudoku-cell { font-size: 14px; }

/* Given (prefilled) cells */
.sudoku-cell.given {
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: default;
}

[data-theme="dark"] .sudoku-cell.given {
  background: rgba(255,255,255,0.04);
}

/* Selected cell */
.sudoku-cell.selected {
  background: rgba(59,130,246,0.18) !important;
  border-color: var(--accent) !important;
  z-index: 2;
}

/* Highlighted (same row/col/box) */
.sudoku-cell.highlighted {
  background: rgba(59,130,246,0.07);
}

/* Same number highlight */
.sudoku-cell.same-num {
  background: rgba(59,130,246,0.12);
}

/* Error cell */
.sudoku-cell.error {
  background: rgba(239,68,68,0.15) !important;
  color: var(--danger) !important;
  animation: errorPulse 0.35s ease;
}

/* Hint reveal */
.sudoku-cell.hint-reveal {
  background: rgba(16,185,129,0.18) !important;
  color: var(--success) !important;
  animation: hintPop 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

/* User-filled cells */
.sudoku-cell.user-filled {
  color: var(--accent);
}

/* Box border separators for 4×4 */
.sudoku-grid.size-4 .sudoku-cell.box-right  { border-right-width: 2.5px; border-right-color: var(--text-secondary); }
.sudoku-grid.size-4 .sudoku-cell.box-bottom { border-bottom-width: 2.5px; border-bottom-color: var(--text-secondary); }

/* Box border separators for 6×6 */
.sudoku-grid.size-6 .sudoku-cell.box-right  { border-right-width: 2px; border-right-color: var(--text-secondary); }
.sudoku-grid.size-6 .sudoku-cell.box-bottom { border-bottom-width: 2px; border-bottom-color: var(--text-secondary); }

/* Box border separators for 9×9 */
.sudoku-grid.size-9 .sudoku-cell.box-right  { border-right-width: 2px; border-right-color: var(--text-secondary); }
.sudoku-grid.size-9 .sudoku-cell.box-bottom { border-bottom-width: 2px; border-bottom-color: var(--text-secondary); }

/* Notes mode (small numbers in corners) */
.sudoku-cell .cell-notes {
  position: absolute;
  inset: 1px;
  display: grid;
  pointer-events: none;
}

.sudoku-grid.size-4 .cell-notes { grid-template-columns: repeat(2, 1fr); font-size: 7px; }
.sudoku-grid.size-6 .cell-notes { grid-template-columns: repeat(3, 1fr); font-size: 5.5px; }
.sudoku-grid.size-9 .cell-notes { grid-template-columns: repeat(3, 1fr); font-size: 5px; }

.cell-note-num {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: inherit;
  font-weight: 700;
  line-height: 1;
}

/* ─── Number Pad ─── */
.sudoku-numpad {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

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

.numpad-btn {
  flex: 1;
  max-width: 52px;
  height: 50px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s ease;
  touch-action: manipulation;
}

.numpad-btn:hover {
  background: rgba(59,130,246,0.1);
  border-color: var(--accent-light);
}

.numpad-btn:active {
  transform: scale(0.92);
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.numpad-btn.erase-btn {
  font-size: 18px;
  background: rgba(239,68,68,0.08);
  border-color: rgba(239,68,68,0.3);
  color: var(--danger);
}

.numpad-btn.erase-btn:active {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.numpad-btn.notes-btn {
  font-size: 15px;
  background: rgba(139,92,246,0.08);
  border-color: rgba(139,92,246,0.3);
  color: #8b5cf6;
}

.numpad-btn.notes-btn.active {
  background: #8b5cf6;
  color: #fff;
  border-color: #8b5cf6;
}

/* ─── Action Buttons Row ─── */
.sudoku-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.sudoku-action-btn {
  flex: 1;
  padding: 9px 8px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.sudoku-action-btn:hover {
  border-color: var(--accent-light);
  background: rgba(59,130,246,0.08);
}

.sudoku-action-btn:active {
  transform: scale(0.96);
}

.sudoku-action-btn.hint-btn {
  color: #f59e0b;
  border-color: rgba(245,158,11,0.35);
  background: rgba(245,158,11,0.07);
}

.sudoku-action-btn.new-game-btn {
  color: var(--success);
  border-color: rgba(16,185,129,0.35);
  background: rgba(16,185,129,0.07);
}

.sudoku-action-btn.validate-btn {
  color: var(--accent);
  border-color: rgba(59,130,246,0.35);
  background: rgba(59,130,246,0.07);
}

/* ─── Win Overlay ─── */
.sudoku-win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.sudoku-win-overlay.show {
  display: flex;
  animation: winFadeIn 0.35s ease;
}

.sudoku-win-card {
  background: var(--bg-card);
  border-radius: 24px;
  padding: 32px 24px;
  text-align: center;
  width: 100%;
  max-width: 340px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
  animation: winCardPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.win-emoji {
  font-size: 64px;
  margin-bottom: 8px;
  display: block;
  animation: winningSpin 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}

.win-title {
  font-size: 26px;
  font-weight: 900;
  background: linear-gradient(135deg, #f59e0b, #ec4899, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.win-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.win-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.win-stat-item {
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 10px 6px;
  border: 1px solid var(--border);
}

.win-stat-num {
  font-size: 18px;
  font-weight: 900;
  color: var(--text-primary);
  display: block;
}

.win-stat-lbl {
  font-size: 9.5px;
  color: var(--text-secondary);
  font-weight: 700;
  text-transform: uppercase;
}

.win-best-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(245,158,11,0.15), rgba(236,72,153,0.15));
  border: 1px solid rgba(245,158,11,0.4);
  color: #f59e0b;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 20px;
  display: none;
}

.win-best-badge.visible {
  display: inline-flex;
}

.win-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.win-play-again-btn {
  padding: 13px;
  border-radius: 13px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 4px 16px rgba(59,130,246,0.35);
}

.win-play-again-btn:active {
  transform: scale(0.97);
}

.win-change-level-btn {
  padding: 11px;
  border-radius: 13px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: all 0.15s ease;
}

.win-change-level-btn:hover {
  border-color: var(--accent-light);
  color: var(--accent);
}

/* ─── Confetti ─── */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 299;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}

/* ─── Animations ─── */
@keyframes errorPulse {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.12); }
  60%  { transform: scale(0.96); }
  100% { transform: scale(1); }
}

@keyframes hintPop {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-4px); }
  40%,80% { transform: translateX(4px); }
}

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

@keyframes winCardPop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

@keyframes winningSpin {
  from { transform: rotate(-20deg) scale(0.5); opacity: 0; }
  to   { transform: rotate(0deg)  scale(1);   opacity: 1; }
}

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

/* ─── Progress bar for clue fill ─── */
.sudoku-progress-wrap {
  background: var(--border);
  border-radius: 6px;
  height: 5px;
  overflow: hidden;
  margin-bottom: 10px;
}

.sudoku-progress-bar {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  transition: width 0.3s ease;
}

/* ─── Responsive tweaks ─── */
@media (max-height: 680px) {
  .sudoku-stats-row { padding: 5px 6px; margin-bottom: 8px; }
  .sudoku-stat-value { font-size: 14px; }
  .numpad-btn { height: 42px; font-size: 17px; }
  .sudoku-grid-wrapper { margin-bottom: 8px; }
  .sudoku-action-btn { padding: 7px 6px; font-size: 11px; }
}

@media (max-height: 580px) {
  .sudoku-numpad { gap: 5px; }
  .numpad-btn { height: 36px; font-size: 15px; }
}
