/* ==========================================================================
   Sudoku Lovers - World Class Design System & Theme Engine
   ========================================================================== */

:root {
  /* Common System Metrics & Radius */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);

  /* User Defined Danger Rules */
  --color-danger: #ef4444;
  --color-danger-dark: #dc2626;
  --color-danger-glow: rgba(239, 68, 68, 0.25);
  --color-success: #10b981;
}

/* ==========================================================================
   Theme Palettes
   ========================================================================== */

/* 1. Midnight Slate (Default: Deep Dark & Radiant Cyan) */
[data-theme="dark-slate"] {
  --bg-app: #090d16;
  --bg-surface: #111827;
  --bg-surface-elevated: #1f2937;
  --bg-board: #0f172a;
  --bg-cell: #1e293b;
  --bg-cell-highlight: rgba(56, 189, 248, 0.12);
  --bg-cell-same-digit: rgba(56, 189, 248, 0.22);
  --bg-cell-selected: #1d4ed8;
  --bg-cell-conflict: rgba(239, 68, 68, 0.25);

  --border-outer: #334155;
  --border-box: #38bdf8;
  --border-cell: rgba(71, 85, 105, 0.45);
  --border-selected: #38bdf8;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-given: #ffffff;
  --text-user: #38bdf8;
  --text-pencil: #cbd5e1;
  --text-conflict: #fca5a5;
  --text-cell-selected: #ffffff;

  --accent-primary: #38bdf8;
  --accent-primary-hover: #0ea5e9;
  --accent-secondary: #818cf8;
  --accent-glow: 0 0 20px rgba(56, 189, 248, 0.35);

  --ad-bg: #131d31;
  --ad-border: rgba(56, 189, 248, 0.2);
  --shadow-card: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
}

/* 2. Warm Paper (Classic Vintage Newspaper Cream & Royal Blue Ink) */
[data-theme="paper-classic"] {
  --bg-app: #f4efe6;
  --bg-surface: #fcfaf7;
  --bg-surface-elevated: #ede6da;
  --bg-board: #ffffff;
  --bg-cell: #fbf9f5;
  --bg-cell-highlight: #f3ece0;
  --bg-cell-same-digit: #fde68a;
  --bg-cell-selected: #92400e;
  --bg-cell-conflict: #fee2e2;

  --border-outer: #78350f;
  --border-box: #78350f;
  --border-cell: rgba(180, 83, 9, 0.25);
  --border-selected: #ffffff;

  --text-primary: #1c1917;
  --text-secondary: #78716c;
  --text-muted: #a8a29e;
  --text-given: #1c1917;
  --text-user: #1d4ed8;
  --text-pencil: #57534e;
  --text-conflict: #dc2626;
  --text-cell-selected: #ffffff;

  --accent-primary: #b45309;
  --accent-primary-hover: #92400e;
  --accent-secondary: #d97706;
  --accent-glow: 0 0 15px rgba(180, 83, 9, 0.25);

  --ad-bg: #eae3d5;
  --ad-border: #d5c8b5;
  --shadow-card: 0 8px 24px -4px rgba(78, 40, 10, 0.12);
}

/* 3. Zen Matcha (Relaxing Botanical Emerald & Sage) */
[data-theme="zen-matcha"] {
  --bg-app: #0a1712;
  --bg-surface: #11261e;
  --bg-surface-elevated: #1a382d;
  --bg-board: #0e2019;
  --bg-cell: #142e23;
  --bg-cell-highlight: rgba(52, 211, 153, 0.12);
  --bg-cell-same-digit: rgba(52, 211, 153, 0.25);
  --bg-cell-selected: #047857;
  --bg-cell-conflict: rgba(239, 68, 68, 0.3);

  --border-outer: #2d5a47;
  --border-box: #10b981;
  --border-cell: rgba(45, 90, 71, 0.5);
  --border-selected: #34d399;

  --text-primary: #ecfdf5;
  --text-secondary: #a7f3d0;
  --text-muted: #6ee7b7;
  --text-given: #ffffff;
  --text-user: #34d399;
  --text-pencil: #d1fae5;
  --text-conflict: #fca5a5;
  --text-cell-selected: #ffffff;

  --accent-primary: #10b981;
  --accent-primary-hover: #059669;
  --accent-secondary: #6ee7b7;
  --accent-glow: 0 0 20px rgba(16, 185, 129, 0.35);

  --ad-bg: #142e23;
  --ad-border: rgba(16, 185, 129, 0.25);
  --shadow-card: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
}

/* 4. Sunset Dusk (Royal Violet & Radiant Coral Dusk) */
[data-theme="sunset-dusk"] {
  --bg-app: #130a21;
  --bg-surface: #1e1133;
  --bg-surface-elevated: #2f1b4f;
  --bg-board: #190e2b;
  --bg-cell: #261642;
  --bg-cell-highlight: rgba(244, 63, 94, 0.15);
  --bg-cell-same-digit: rgba(244, 63, 94, 0.28);
  --bg-cell-selected: #831843;
  --bg-cell-conflict: rgba(239, 68, 68, 0.35);

  --border-outer: #582a8a;
  --border-box: #f43f5e;
  --border-cell: rgba(99, 47, 155, 0.45);
  --border-selected: #f43f5e;

  --text-primary: #fff1f2;
  --text-secondary: #fda4af;
  --text-muted: #f472b6;
  --text-given: #ffffff;
  --text-user: #fb7185;
  --text-pencil: #fbcfe8;
  --text-conflict: #fecdd3;
  --text-cell-selected: #ffffff;

  --accent-primary: #f43f5e;
  --accent-primary-hover: #e11d48;
  --accent-secondary: #fb923c;
  --accent-glow: 0 0 22px rgba(244, 63, 94, 0.4);

  --ad-bg: #22143b;
  --ad-border: rgba(244, 63, 94, 0.25);
  --shadow-card: 0 10px 30px -5px rgba(0, 0, 0, 0.65);
}

/* 5. Cyberpunk Synth (OLED Black, Hot Fuchsia & Electric Cyan) */
[data-theme="cyberpunk-synth"] {
  --bg-app: #050505;
  --bg-surface: #101014;
  --bg-surface-elevated: #1a1a22;
  --bg-board: #0a0a0e;
  --bg-cell: #14141c;
  --bg-cell-highlight: rgba(236, 72, 153, 0.15);
  --bg-cell-same-digit: rgba(6, 182, 212, 0.22);
  --bg-cell-selected: #4f46e5;
  --bg-cell-conflict: rgba(239, 68, 68, 0.4);

  --border-outer: #06b6d4;
  --border-box: #ec4899;
  --border-cell: rgba(236, 72, 153, 0.25);
  --border-selected: #06b6d4;

  --text-primary: #fdf4ff;
  --text-secondary: #a5f3fc;
  --text-muted: #f472b6;
  --text-given: #06b6d4;
  --text-user: #ec4899;
  --text-pencil: #67e8f9;
  --text-conflict: #ef4444;
  --text-cell-selected: #ffffff;

  --accent-primary: #ec4899;
  --accent-primary-hover: #db2777;
  --accent-secondary: #06b6d4;
  --accent-glow: 0 0 24px rgba(236, 72, 153, 0.5);

  --ad-bg: #12121a;
  --ad-border: rgba(6, 182, 212, 0.3);
  --shadow-card: 0 10px 35px -5px rgba(0, 0, 0, 0.85);
}

/* 6. Nordic Frost (Minimalist Arctic Light Theme) */
[data-theme="nordic-frost"] {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-board: #ffffff;
  --bg-cell: #f8fafc;
  --bg-cell-highlight: #e0f2fe;
  --bg-cell-same-digit: #bae6fd;
  --bg-cell-selected: #0369a1;
  --bg-cell-conflict: #fee2e2;

  --border-outer: #334155;
  --border-box: #0284c7;
  --border-cell: #cbd5e1;
  --border-selected: #ffffff;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-given: #0f172a;
  --text-user: #2563eb;
  --text-pencil: #475569;
  --text-conflict: #dc2626;
  --text-cell-selected: #ffffff;

  --accent-primary: #0284c7;
  --accent-primary-hover: #0369a1;
  --accent-secondary: #38bdf8;
  --accent-glow: 0 0 18px rgba(2, 132, 199, 0.25);

  --ad-bg: #f1f5f9;
  --ad-border: #e2e8f0;
  --shadow-card: 0 8px 24px -4px rgba(15, 23, 42, 0.08);
}

/* ==========================================================================
   Base & Resets
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  min-height: 100%;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow-x: hidden;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Victory Confetti Canvas */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

/* ==========================================================================
   Layout Wrapper: Desktop Sidebar Ads + Centered Mobile App Container
   ========================================================================== */

.app-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  width: 100%;
  padding: 0;
  position: relative;
}

/* Mobile-First Main Column */
.game-container {
  width: 100%;
  max-width: 520px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 10px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  z-index: 10;
}

/* Desktop Sidebar Ad Columns (Hidden on phones and tablets) */
.desktop-ad-column {
  display: none;
  width: 190px;
  position: sticky;
  top: 24px;
  padding: 16px 8px;
}

@media (min-width: 980px) {
  .desktop-ad-column {
    display: block;
  }
  .ad-column-left {
    margin-right: 16px;
  }
  .ad-column-right {
    margin-left: 16px;
  }
}

/* ==========================================================================
   Advertisement Slots Design
   ========================================================================== */

.ad-unit {
  background: var(--ad-bg);
  border: 1px solid var(--ad-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.ad-unit:hover {
  border-color: var(--accent-primary);
}

.ad-label {
  font-size: 9px;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.ad-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--accent-primary);
  color: #ffffff;
  letter-spacing: 0.05em;
}

/* Horizontal Banner (Header & Footer) */
.ad-wrapper-top {
  width: 100%;
}

.ad-wrapper-bottom {
  width: 100%;
  margin-top: 4px;
}

.ad-content-box-horizontal {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.ad-headline {
  flex: 1;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ad-cta-btn-sm {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-cell);
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 700;
  border-radius: var(--radius-xs);
  cursor: pointer;
  white-space: nowrap;
}

.ad-cta-btn-sm:hover {
  background: var(--accent-primary);
  color: #fff;
}

/* Skyscraper Ads (Desktop) */
.ad-skyscraper {
  min-height: 520px;
  display: flex;
  flex-direction: column;
}

.ad-skyscraper .ad-content-box {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding-top: 12px;
}

.ad-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.ad-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.ad-cta-btn {
  width: 100%;
  margin-top: auto;
  background: var(--accent-primary);
  color: #ffffff;
  border: none;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  border-radius: var(--radius-xs);
  cursor: pointer;
}

/* ==========================================================================
   Header & Brand
   ========================================================================== */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon-wrap {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-cell);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.app-logo {
  width: 28px;
  height: 28px;
}

.app-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.1;
}

.app-subtitle {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-cell);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px);
}

.icon-svg {
  width: 18px;
  height: 18px;
}

.primary-btn {
  background: var(--accent-primary);
  color: #ffffff;
  border: none;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 13px;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: var(--accent-glow);
  transition: all var(--transition-fast);
}

.primary-btn:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-1px);
}

.primary-btn:active {
  transform: translateY(1px);
}

.secondary-btn {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-cell);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 13px;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.secondary-btn:hover {
  border-color: var(--accent-primary);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 16px;
}

/* ==========================================================================
   Navigation Tabs: Play vs Solution
   ========================================================================== */

.view-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-surface);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 4px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--transition-fast);
  position: relative;
}

.tab-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.tab-btn:not(.active):hover {
  color: var(--text-primary);
  background: var(--bg-surface-elevated);
}

.tab-icon {
  width: 16px;
  height: 16px;
}

.badge-solution {
  font-size: 9px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.22);
  padding: 2px 5px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ==========================================================================
   Controls Bar: Difficulty Selection & Guided vs Manual Toggle
   ========================================================================== */

.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

/* Difficulty Selector Pills */
.difficulty-group {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.diff-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.diff-btn.active {
  background: var(--bg-surface-elevated);
  color: var(--accent-primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* Assistance Mode Switcher (Guided vs Manual) */
.assist-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.assist-label-text {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.segmented-control {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all var(--transition-fast);
}

.seg-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background-color var(--transition-fast);
}

.seg-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
}

.seg-btn.active .seg-dot {
  background: #ffffff;
}

/* ==========================================================================
   Game Status Bar: Level, Timer, Mistakes
   ========================================================================== */

.game-status-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-surface);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-md);
  padding: 8px 12px;
}

.status-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.status-item:not(:last-child) {
  border-right: 1px solid var(--border-cell);
}

.status-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.status-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.font-mono {
  font-family: var(--font-mono);
}

.level-num-clickable {
  color: var(--accent-primary);
  cursor: pointer;
  text-decoration: underline dotted;
  transition: opacity var(--transition-fast);
}

.level-num-clickable:hover {
  opacity: 0.8;
}

.timer-display-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.timer-pause-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  transition: color var(--transition-fast);
}

.timer-pause-btn:hover {
  color: var(--accent-primary);
}

.icon-mini {
  width: 14px;
  height: 14px;
}

/* ==========================================================================
   9x9 Sudoku Board & Cells (Ultra Responsive Mobile First)
   ========================================================================== */

.board-outer-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 480px;
  margin: 0 auto;
}

.sudoku-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--bg-board);
  border: 3px solid var(--border-box);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  position: relative;
}

/* Individual Cell */
.sudoku-cell {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-cell);
  border-right: 1px solid var(--border-cell);
  border-bottom: 1px solid var(--border-cell);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

/* 3x3 Block Thicker Boundaries */
.sudoku-cell[data-col="2"],
.sudoku-cell[data-col="5"] {
  border-right: 2.5px solid var(--border-box);
}

.sudoku-cell[data-row="2"],
.sudoku-cell[data-row="5"] {
  border-bottom: 2.5px solid var(--border-box);
}

.sudoku-cell[data-col="8"] {
  border-right: none;
}

.sudoku-cell[data-row="8"] {
  border-bottom: none;
}

/* Cell States & Guided Highlights */
.sudoku-cell.cell-highlighted {
  background-color: var(--bg-cell-highlight);
}

.sudoku-cell.cell-same-digit {
  background-color: var(--bg-cell-same-digit);
}

.sudoku-cell.cell-selected {
  background-color: var(--bg-cell-selected) !important;
  box-shadow: inset 0 0 0 2px var(--border-selected, #ffffff), var(--accent-glow);
  z-index: 2;
}

/* High-contrast overrides for any number or candidate inside selected cell */
.sudoku-cell.cell-selected .cell-digit,
.sudoku-cell.cell-selected.cell-given .cell-digit,
.sudoku-cell.cell-selected.cell-user .cell-digit {
  color: var(--text-cell-selected, #ffffff) !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.sudoku-cell.cell-selected .note-item {
  color: var(--text-cell-selected, #ffffff) !important;
  font-weight: 700;
}

.sudoku-cell.cell-conflict {
  background-color: var(--bg-cell-conflict) !important;
  animation: shake 0.3s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.sudoku-cell.cell-conflict .cell-digit,
.sudoku-cell.cell-selected.cell-conflict .cell-digit {
  color: var(--color-danger) !important;
  text-shadow: none;
}

/* Number Styles */
.cell-digit {
  font-family: var(--font-mono);
  font-size: clamp(18px, 5.2vw, 32px);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.cell-given .cell-digit {
  color: var(--text-given);
  font-weight: 800;
}

.cell-user .cell-digit {
  color: var(--text-user);
  font-weight: 700;
}

/* Pencil Marks / Candidates 3x3 Grid inside empty cell */
.notes-grid {
  position: absolute;
  top: 1px;
  left: 1px;
  right: 1px;
  bottom: 1px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}

.note-item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: clamp(7px, 1.8vw, 11px);
  font-weight: 600;
  color: var(--text-pencil);
  line-height: 1;
}

/* Pause Board Overlay */
.board-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 13, 22, 0.88);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.pause-card {
  text-align: center;
  padding: 24px;
}

.pause-icon {
  font-size: 42px;
  margin-bottom: 10px;
}

.pause-card h3 {
  font-size: 20px;
  margin-bottom: 6px;
}

.pause-card p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 16px;
}

/* Solution View Panel */
.solution-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  z-index: 15;
  display: flex;
  flex-direction: column;
}

.solution-header-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-cell);
}

.solution-tag {
  font-size: 10px;
  font-weight: 800;
  background: var(--accent-primary);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
}

.solution-status-text p {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.solution-actions-row {
  display: flex;
  gap: 6px;
}

.solution-mode-grid {
  flex: 1;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  border-top: none;
}

.solution-cell-diff {
  background-color: rgba(56, 189, 248, 0.15);
}

/* ==========================================================================
   Action Toolbar (Undo, Erase, Notes, Hint)
   ========================================================================== */

.action-toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 2px;
}

.tool-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tool-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

.tool-btn:active {
  transform: translateY(1px);
}

.tool-icon-wrap {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.tool-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Notes Active Indicator */
.pencil-badge-wrap {
  position: relative;
}

.pencil-state-indicator {
  position: absolute;
  top: -6px;
  right: -10px;
  font-size: 8px;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--text-muted);
  color: #ffffff;
  letter-spacing: 0.02em;
}

.tool-btn.pencil-active {
  border-color: var(--accent-primary);
  background: var(--bg-surface-elevated);
  color: var(--accent-primary);
}

.tool-btn.pencil-active .pencil-state-indicator {
  background: var(--accent-primary);
}

.highlight-tool {
  color: var(--accent-secondary);
}

/* ==========================================================================
   Keypad (Numbers 1 to 9 with Badges)
   ========================================================================== */

.keypad-container {
  width: 100%;
  margin-top: 2px;
}

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

.num-key {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-sm);
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
  font-family: var(--font-mono);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: all var(--transition-fast);
}

.num-key:hover {
  border-color: var(--accent-primary);
  background: var(--bg-surface-elevated);
  transform: translateY(-1px);
}

.num-key:active {
  transform: translateY(1px);
}

.key-digit {
  font-size: clamp(16px, 4.5vw, 22px);
  font-weight: 800;
  line-height: 1;
}

.key-count {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1;
  margin-top: 3px;
}

/* Key completed state: when 9 numbers have been placed */
.num-key.completed {
  opacity: 0.35;
  pointer-events: none;
}

/* ==========================================================================
   Modals & Dialogs
   ========================================================================== */

.modal-dialog {
  border: none;
  background: transparent;
  padding: 0;
  max-width: 440px;
  width: 90%;
  margin: auto;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  z-index: 1000;
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-lg);
  padding: 20px;
  color: var(--text-primary);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 18px;
  font-weight: 800;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 8px;
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-bottom: 16px;
}

/* Form inputs */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-with-button {
  display: flex;
  gap: 8px;
}

.form-input {
  flex: 1;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-cell);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  outline: none;
}

.form-input:focus {
  border-color: var(--accent-primary);
}

.divider-text {
  text-align: center;
  margin: 16px 0;
  position: relative;
}

.divider-text::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border-cell);
}

.divider-text span {
  position: relative;
  background: var(--bg-surface);
  padding: 0 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.quick-levels-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.quick-level-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.quick-level-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.card-badge {
  font-size: 9px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 6px;
}

.card-badge.easy { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.card-badge.medium { background: rgba(56, 189, 248, 0.2); color: #38bdf8; }
.card-badge.hard { background: rgba(244, 63, 94, 0.2); color: #fb7185; }

.quick-level-card h4 {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 2px;
}

.quick-level-card p {
  font-size: 9px;
  color: var(--text-muted);
  line-height: 1.25;
}

/* Theme Chooser Grid */
.theme-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.theme-option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
}

.theme-option-btn:hover {
  border-color: var(--accent-primary);
}

.theme-option-btn.active {
  border-color: var(--accent-primary);
  box-shadow: inset 0 0 0 1px var(--accent-primary);
}

.theme-swatch {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.swatch-dark-slate { background: #0f172a; color: #38bdf8; border: 1.5px solid #1d4ed8; }
.swatch-paper-classic { background: #fcfaf7; color: #1d4ed8; border: 1.5px solid #92400e; }
.swatch-zen-matcha { background: #11261e; color: #34d399; border: 1.5px solid #047857; }
.swatch-sunset-dusk { background: #1e1133; color: #fb7185; border: 1.5px solid #831843; }
.swatch-cyberpunk { background: #050505; color: #ec4899; border: 1.5px solid #4f46e5; }
.swatch-nordic-frost { background: #ffffff; color: #2563eb; border: 1.5px solid #0369a1; }

.theme-text strong {
  display: block;
  font-size: 13px;
  color: var(--text-primary);
}

.theme-text small {
  font-size: 11px;
  color: var(--text-muted);
}

/* Statistics Overview */
.stats-overview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
  text-align: center;
}

.stat-number {
  font-size: 18px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent-primary);
}

.stat-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

.section-subheading {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.difficulty-records {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
}

.record-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}

.record-row:not(:last-child) {
  border-bottom: 1px solid var(--border-cell);
}

.record-row strong {
  font-family: var(--font-mono);
  color: var(--accent-primary);
}

/* Hint Toast Explainer */
.hint-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1.5px solid var(--accent-secondary);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 100;
  animation: slideUp 0.25s ease-out;
}

.hint-toast-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.hint-icon {
  font-size: 18px;
}

.toast-close {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

#hint-toast-body {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 10px;
}

.hint-apply-btn {
  background: var(--accent-secondary);
  color: #fff;
  border: none;
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer;
}

/* Victory Dialog */
.victory-trophy {
  font-size: 52px;
  margin-bottom: 8px;
  animation: bounce 1s infinite alternate;
}

.victory-title {
  font-size: 22px;
  color: var(--accent-primary);
}

.victory-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.victory-stats-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-cell);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 18px;
}

.v-stat {
  display: flex;
  flex-direction: column;
}

.v-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.v-stat strong {
  font-family: var(--font-mono);
  font-size: 15px;
  margin-top: 2px;
}

.modal-actions-stacked {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.text-center {
  text-align: center;
}

.gameover-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

/* Utility / Helpers */
.hidden {
  display: none !important;
}

/* Animations */
@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
  40%, 60% { transform: translate3d(3px, 0, 0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 15px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

/* ==========================================================================
   Print Stylesheet for Sudoku Lovers
   ========================================================================== */

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .ad-wrapper-top,
  .ad-wrapper-bottom,
  .desktop-ad-column,
  .header-actions,
  .view-tabs,
  .action-toolbar,
  .keypad-container,
  .modal-dialog,
  .hint-toast {
    display: none !important;
  }

  .game-container {
    max-width: 100%;
    padding: 0;
  }

  .app-header {
    border-bottom: 2px solid #000;
    margin-bottom: 20px;
  }

  .sudoku-grid {
    border: 3px solid #000 !important;
    box-shadow: none !important;
    background: #fff !important;
  }

  .sudoku-cell {
    border-color: #999 !important;
    background: #fff !important;
  }

  .cell-digit {
    color: #000 !important;
  }
}
