/* ========================================
   Sudoku - game4.fun UI System
   Dark glassmorphism, neon accents
======================================== */

:root {
  --bg-dark: #0a0a0f;
  --bg-card: rgba(20, 20, 30, 0.75);
  --primary-neon: #6366f1;
  --secondary-neon: #ec4899;
  --accent-cyan: #06b6d4;
  --text-main: #f1f5f9;
  --text-dim: rgba(148, 163, 184, 0.7);
  --border-glass: rgba(255, 255, 255, 0.1);
  --radius-xl: 24px;
  --radius-lg: 16px;

  --cell-size: 44px;
  --cell-gap: 1px;
  --cell-radius: 4px;
  --cell-bg: rgba(30, 30, 45, 0.8);
  --cell-bg-hover: rgba(50, 50, 70, 0.9);
  --cell-selected: rgba(99, 102, 241, 0.35);
  --cell-highlight: rgba(99, 102, 241, 0.12);
  --cell-same-num: rgba(99, 102, 241, 0.22);
  --cell-given: rgba(241, 245, 249, 0.95);
  --cell-user: #6366f1;
  --cell-error: #ef4444;
  --cell-notes: rgba(148, 163, 184, 0.75);
  --box-border: rgba(255, 255, 255, 0.25);
}

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

body {
  min-height: 100vh;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ========== Game Container ========== */
.game-container {
  width: 100%;
  max-width: 520px;
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-header {
  text-align: center;
  margin-bottom: 12px;
}

.game-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-neon), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

/* ========== Difficulty Bar ========== */
.difficulty-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.diff-btn {
  padding: 8px 20px;
  border: 1px solid var(--border-glass);
  background: var(--bg-card);
  color: var(--text-dim);
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  backdrop-filter: blur(8px);
}

.diff-btn:hover {
  border-color: var(--primary-neon);
  color: var(--text-main);
}

.diff-btn.active {
  background: linear-gradient(135deg, var(--primary-neon), var(--accent-cyan));
  color: white;
  border-color: transparent;
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.3);
}

/* ========== Game Panel ========== */
.game-panel {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 16px;
  backdrop-filter: blur(16px);
}

/* ========== HUD ========== */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hud-icon {
  font-size: 1rem;
}

.hud-value {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
}

.new-game-btn {
  padding: 6px 16px;
  border: 1px solid var(--border-glass);
  background: var(--bg-card);
  color: var(--text-main);
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.new-game-btn:hover {
  border-color: var(--primary-neon);
  background: rgba(99, 102, 241, 0.15);
}

/* ========== Board ========== */
.board-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, var(--cell-size));
  grid-template-rows: repeat(9, var(--cell-size));
  gap: var(--cell-gap);
  background: var(--box-border);
  border: 2px solid var(--box-border);
  border-radius: 8px;
  overflow: hidden;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 600;
  transition: background 0.15s;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

.cell:hover {
  background: var(--cell-bg-hover);
}

/* 3x3 box borders */
.cell.box-right {
  border-right: 2px solid var(--box-border);
}

.cell.box-bottom {
  border-bottom: 2px solid var(--box-border);
}

/* Cell states */
.cell.given {
  color: var(--cell-given);
  font-weight: 700;
}

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

.cell.selected {
  background: var(--cell-selected);
  box-shadow: inset 0 0 0 2px var(--primary-neon);
}

.cell.highlighted {
  background: var(--cell-highlight);
}

.cell.same-number {
  background: var(--cell-same-num);
}

.cell.error {
  color: var(--cell-error);
  animation: shake 0.3s ease;
}

.cell.error-bg {
  background: rgba(239, 68, 68, 0.15);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

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

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

/* ========== Number Pad ========== */
.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}

.num-btn {
  height: 44px;
  border: 1px solid var(--border-glass);
  background: var(--cell-bg);
  color: var(--text-main);
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.15rem;
  font-weight: 600;
  transition: all 0.15s;
}

.num-btn:hover {
  background: var(--cell-bg-hover);
  border-color: var(--primary-neon);
}

.num-btn:active {
  transform: scale(0.93);
}

.num-btn.completed {
  opacity: 0.3;
  pointer-events: none;
}

.num-btn.active-num {
  background: rgba(99, 102, 241, 0.3);
  border-color: var(--primary-neon);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

/* ========== Action Bar ========== */
.action-bar {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border: 1px solid var(--border-glass);
  background: var(--bg-card);
  color: var(--text-dim);
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.action-btn:hover {
  border-color: var(--primary-neon);
  color: var(--text-main);
}

.action-btn.active {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--primary-neon);
  color: var(--primary-neon);
}

.action-icon {
  font-size: 1rem;
}

.auto-check-label {
  cursor: pointer;
}

.auto-check-label input[type="checkbox"] {
  display: none;
}

.auto-check-label.active {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--primary-neon);
  color: var(--primary-neon);
}

/* ========== Best Time ========== */
.best-time-display {
  margin-top: 12px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  backdrop-filter: blur(6px);
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 36px 32px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  backdrop-filter: blur(20px);
  transform: scale(0.9);
  transition: transform 0.3s;
}

.modal-overlay.show .modal {
  transform: scale(1);
}

.modal-emoji {
  font-size: 3rem;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary-neon), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.modal-message {
  color: var(--text-dim);
  margin-bottom: 8px;
}

.modal-record {
  color: var(--secondary-neon);
  font-weight: 600;
  margin-bottom: 16px;
  min-height: 1.2em;
}

.modal-btn {
  padding: 12px 32px;
  background: linear-gradient(135deg, var(--primary-neon), var(--accent-cyan));
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.modal-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

/* ========== Celebration ========== */
@keyframes celebratePop {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

.confetti-piece {
  position: fixed;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 200;
  animation: confettiFall linear forwards;
}

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

/* ========== Responsive ========== */
@media (max-width: 480px) {
  :root {
    --cell-size: min(10vw, 40px);
  }

  .game-container {
    padding: 10px 8px;
  }

  .game-title {
    font-size: 1.5rem;
  }

  .diff-btn {
    padding: 6px 14px;
    font-size: 0.8rem;
  }

  .game-panel {
    padding: 10px;
    border-radius: var(--radius-lg);
  }

  .num-btn {
    height: 40px;
    font-size: 1rem;
  }

  .action-btn {
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  .cell .notes-grid span {
    font-size: 0.45rem;
  }
}

@media (max-width: 360px) {
  :root {
    --cell-size: min(9.5vw, 36px);
  }
}
