/* ==========================================================================
   Cosmic Sudoku Theme Variables & Reset
   ========================================================================== */

:root {
  /* Common variables */
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  
  --border-radius-sm: 8px;
  --border-radius-md: 16px;
  --border-radius-lg: 24px;
  --border-radius-xl: 32px;

  /* Theme: Dark (Default) */
  --bg-gradient: radial-gradient(circle at 50% 50%, #0d0b21 0%, #05030f 100%);
  --panel-bg: rgba(18, 16, 35, 0.65);
  --panel-border: rgba(124, 58, 237, 0.2);
  --panel-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --panel-glow: 0 0 15px rgba(139, 92, 246, 0.15);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-accent: #a78bfa;
  
  --cell-bg-clue: rgba(30, 27, 75, 0.4);
  --cell-bg-empty: rgba(255, 255, 255, 0.02);
  --cell-border: rgba(139, 92, 246, 0.2);
  --cell-border-thick: rgba(139, 92, 246, 0.5);
  
  --cell-text-clue: #a78bfa;
  --cell-text-user: #e9d5ff;
  
  /* State Highlights */
  --highlight-focus: rgba(139, 92, 246, 0.35);
  --highlight-related: rgba(139, 92, 246, 0.08);
  --highlight-same-val: rgba(34, 211, 238, 0.2);
  --highlight-same-val-border: rgba(34, 211, 238, 0.6);
  --highlight-error-bg: rgba(239, 68, 68, 0.15);
  --highlight-error-text: #ef4444;
  --highlight-note: #9ca3af;
  
  /* Buttons & Keys */
  --btn-secondary-bg: rgba(139, 92, 246, 0.15);
  --btn-secondary-hover: rgba(139, 92, 246, 0.28);
  --btn-secondary-text: #c084fc;
  
  --keypad-bg: rgba(30, 27, 75, 0.3);
  --keypad-btn-bg: rgba(255, 255, 255, 0.04);
  --keypad-btn-hover: rgba(139, 92, 246, 0.2);
  --keypad-btn-text: #f3f4f6;
  
  --difficulty-easy: #10b981;
  --difficulty-medium: #f59e0b;
  --difficulty-hard: #ef4444;
}

[data-theme="light"] {
  /* Theme: Light */
  --bg-gradient: radial-gradient(circle at 50% 50%, #f4f6fc 0%, #e2e8f0 100%);
  --panel-bg: rgba(255, 255, 255, 0.7);
  --panel-border: rgba(99, 102, 241, 0.2);
  --panel-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.08);
  --panel-glow: 0 0 15px rgba(99, 102, 241, 0.06);
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-accent: #6366f1;
  
  --cell-bg-clue: rgba(99, 102, 241, 0.06);
  --cell-bg-empty: rgba(255, 255, 255, 0.4);
  --cell-border: rgba(99, 102, 241, 0.15);
  --cell-border-thick: rgba(99, 102, 241, 0.45);
  
  --cell-text-clue: #4f46e5;
  --cell-text-user: #0f172a;
  
  /* State Highlights */
  --highlight-focus: rgba(99, 102, 241, 0.25);
  --highlight-related: rgba(99, 102, 241, 0.05);
  --highlight-same-val: rgba(6, 182, 212, 0.15);
  --highlight-same-val-border: rgba(6, 182, 212, 0.5);
  --highlight-error-bg: rgba(239, 68, 68, 0.12);
  --highlight-error-text: #dc2626;
  --highlight-note: #64748b;
  
  /* Buttons & Keys */
  --btn-secondary-bg: rgba(99, 102, 241, 0.1);
  --btn-secondary-hover: rgba(99, 102, 241, 0.18);
  --btn-secondary-text: #4f46e5;
  
  --keypad-bg: rgba(226, 232, 240, 0.5);
  --keypad-btn-bg: rgba(255, 255, 255, 0.8);
  --keypad-btn-hover: rgba(99, 102, 241, 0.15);
  --keypad-btn-text: #1e293b;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-drag: none;
}

body {
  font-family: var(--font-main);
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ==========================================================================
   Animated Starfield Background (Only active in Dark Mode)
   ========================================================================== */

.stars-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  transition: opacity var(--transition-slow);
}

[data-theme="light"] .stars-container {
  opacity: 0;
}

/* Star generator via shadows */
.stars, .stars2, .stars3 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent;
}

.stars {
  width: 1px;
  height: 1px;
  box-shadow: 
    10vw 20vh #fff, 20vw 80vh #fff, 35vw 45vh #fff, 50vw 10vh #fff, 65vw 70vh #fff, 85vw 30vh #fff, 95vw 85vh #fff,
    15vw 60vh rgba(255,255,255,0.5), 45vw 90vh rgba(255,255,255,0.7), 75vw 15vh rgba(255,255,255,0.6), 88vw 66vh rgba(255,255,255,0.8),
    5vw 40vh #fff, 30vw 15vh #fff, 60vw 35vh #fff, 70vw 90vh #fff, 90vw 50vh #fff;
  animation: starScroll 150s linear infinite;
}

.stars2 {
  width: 2px;
  height: 2px;
  box-shadow: 
    15vw 10vh #a78bfa, 25vw 70vh #8b5cf6, 40vw 30vh #c084fc, 55vw 85vh #a78bfa, 70vw 20vh #8b5cf6, 80vw 60vh #c084fc,
    5vw 80vh rgba(139,92,246,0.5), 35vw 95vh rgba(139,92,246,0.7), 65vw 50vh rgba(139,92,246,0.6), 92vw 15vh rgba(139,92,246,0.8);
  animation: starScroll 100s linear infinite;
}

.stars3 {
  width: 3px;
  height: 3px;
  box-shadow: 
    8vw 50vh #22d3ee, 28vw 20vh #06b6d4, 48vw 75vh #22d3ee, 68vw 40vh #06b6d4, 88vw 80vh #22d3ee,
    18vw 90vh rgba(34,211,238,0.5), 78vw 10vh rgba(34,211,238,0.7);
  animation: starScroll 70s linear infinite;
}

@keyframes starScroll {
  from { transform: translateY(0px); }
  to { transform: translateY(-1000px); }
}

/* ==========================================================================
   App Container & Header
   ========================================================================== */

.app-container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
  justify-content: center;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--border-radius-md);
  box-shadow: var(--panel-shadow);
  box-shadow: var(--panel-shadow), var(--panel-glow);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  color: var(--text-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.4));
}

.logo-area h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-main) 30%, var(--text-accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-controls {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  padding: 10px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--btn-secondary-bg);
  border-color: var(--text-accent);
  color: var(--text-accent);
  transform: translateY(-2px);
}

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

/* ==========================================================================
   Game Layout Panels
   ========================================================================== */

.game-layout {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 24px;
  align-items: start;
}

.glass-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--panel-shadow), var(--panel-glow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: border-color var(--transition-normal);
}

/* Stats Bar */
.stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.15);
  padding: 12px 18px;
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-val {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
}

#game-difficulty.difficulty-easy { color: var(--difficulty-easy); }
#game-difficulty.difficulty-medium { color: var(--difficulty-medium); }
#game-difficulty.difficulty-hard { color: var(--difficulty-hard); }

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

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

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

/* ==========================================================================
   The Sudoku Board Layout
   ========================================================================== */

.board-outer-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.board-wrapper {
  position: relative;
  width: 100%;
  max-width: 440px;
  aspect-ratio: 1 / 1;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--border-radius-md);
  overflow: hidden;
  border: 3px solid var(--cell-border-thick);
}

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  height: 100%;
}

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

/* 3x3 block borders */
.cell:nth-child(3n) {
  border-right: 2px solid var(--cell-border-thick);
}
.cell:nth-child(9n) {
  border-right: none; /* remove rightmost outer boundary border */
}

/* row thick borders */
.cell-row-2, .cell-row-5 {
  border-bottom: 2px solid var(--cell-border-thick);
}
.cell-row-8 {
  border-bottom: none; /* remove bottom outer boundary border */
}

/* Numbers text */
.cell-value {
  font-size: 1.6rem;
  font-weight: 500;
  font-family: var(--font-main);
  pointer-events: none;
  animation: numberPopIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.cell.clue .cell-value {
  color: var(--cell-text-clue);
  font-weight: 700;
}

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

/* Cell highlight states */
.cell.highlighted {
  background: var(--highlight-related);
}

.cell.same-value {
  background: var(--highlight-same-val);
  box-shadow: inset 0 0 0 1.5px var(--highlight-same-val-border);
}

.cell.focused {
  background: var(--highlight-focus);
  box-shadow: inset 0 0 0 2px var(--text-accent);
  z-index: 2;
}

.cell.error {
  background: var(--highlight-error-bg) !important;
}
.cell.error .cell-value {
  color: var(--highlight-error-text) !important;
  animation: shake 0.3s;
}

/* Pencil marks/Notes */
.notes-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 3px;
  pointer-events: none;
}

.note-slot {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--highlight-note);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.note-slot.active {
  opacity: 1;
}

@keyframes numberPopIn {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

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

/* Pause Overlay */
.board-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 3, 15, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

.overlay-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-main);
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.overlay-content h3 {
  font-size: 1.5rem;
  font-weight: 700;
}

.pulse-animation {
  color: var(--text-accent);
  animation: iconPulse 2s infinite ease-in-out;
}

@keyframes iconPulse {
  0%, 100% { transform: scale(1); opacity: 0.8; filter: drop-shadow(0 0 2px rgba(139, 92, 246, 0)); }
  50% { transform: scale(1.1); opacity: 1; filter: drop-shadow(0 0 10px rgba(139, 92, 246, 0.6)); }
}

/* ==========================================================================
   Game Toolbar & Control keys
   ========================================================================== */

.game-toolbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.tool-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-radius: var(--border-radius-md);
  padding: 10px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.tool-btn:hover:not(:disabled) {
  background: var(--btn-secondary-bg);
  border-color: var(--panel-border);
  color: var(--text-accent);
}

.tool-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.notes-icon-wrapper {
  position: relative;
}

.notes-badge {
  position: absolute;
  top: -8px;
  right: -12px;
  font-size: 0.55rem;
  font-weight: 700;
  background: var(--text-muted);
  color: #000;
  padding: 1px 4px;
  border-radius: 4px;
  line-height: 1;
}

.tool-btn.active-tool {
  background: var(--text-accent) !important;
  border-color: var(--text-accent) !important;
  color: #1e1b4b !important;
}

.tool-btn.active-tool .notes-badge {
  background: #1e1b4b !important;
  color: var(--text-main) !important;
}

/* On-Screen Keypad */
.keypad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  background: var(--keypad-bg);
  padding: 8px;
  border-radius: var(--border-radius-md);
}

.keypad-btn {
  background: var(--keypad-btn-bg);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--keypad-btn-text);
  aspect-ratio: 1;
  border-radius: 8px;
  font-family: var(--font-main);
  font-size: 1.3rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.keypad-btn:hover {
  background: var(--keypad-btn-hover);
  border-color: var(--panel-border);
  transform: scale(1.05);
}

.keypad-btn:active {
  transform: scale(0.95);
}

/* New Game controls */
.new-game-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 6px;
}

.difficulty-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  padding: 12px;
  border-radius: var(--border-radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.9rem;
}

.easy-btn:hover {
  background: rgba(16, 185, 129, 0.15);
  border-color: var(--difficulty-easy);
  color: var(--difficulty-easy);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.medium-btn:hover {
  background: rgba(245, 158, 11, 0.15);
  border-color: var(--difficulty-medium);
  color: var(--difficulty-medium);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.2);
}

.hard-btn:hover {
  background: rgba(239, 68, 110, 0.15);
  border-color: var(--difficulty-hard);
  color: var(--difficulty-hard);
  box-shadow: 0 0 10px rgba(239, 68, 110, 0.2);
}

/* ==========================================================================
   Mascot & Speech Bubble Elements
   ========================================================================== */

.mascot-section {
  align-self: stretch;
}

.mascot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  min-height: 480px;
}

.mascot-header {
  text-align: center;
  margin-bottom: 12px;
  width: 100%;
}

.mascot-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.mascot-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.mascot-avatar-container {
  width: 170px;
  height: 170px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0;
}

/* Mascot SVG Animation Classes */
.zen-mascot {
  transform-origin: bottom center;
  animation: bodyFloat 4s ease-in-out infinite;
}

.cat-tail {
  transform-origin: 125px 135px;
  animation: tailWag 3s ease-in-out infinite;
}

.paw-left {
  transform-origin: 82px 148px;
}

.paw-right {
  transform-origin: 118px 148px;
}

.backpack-light {
  animation: blinkLight 1.5s infinite step-end;
}

.cheek-blush {
  animation: blushPulse 4s infinite ease-in-out;
}

/* Mascot Expressions based on classes toggled by JS */

/* Happy mood */
.zen-mascot.mood-happy .eye-normal,
.zen-mascot.mood-happy .eye-pupil,
.zen-mascot.mood-happy .eye-pupil-sub,
.zen-mascot.mood-happy .mouth-sad,
.zen-mascot.mood-happy .mouth-shocked {
  display: none !important;
}

.zen-mascot.mood-happy .eye-happy,
.zen-mascot.mood-happy .mouth-happy {
  display: block !important;
}

.zen-mascot.mood-happy .paw-left {
  animation: wavePawLeft 1s ease-in-out infinite;
}

/* Shocked mood */
.zen-mascot.mood-shocked .eye-normal,
.zen-mascot.mood-shocked .eye-pupil,
.zen-mascot.mood-shocked .eye-pupil-sub,
.zen-mascot.mood-shocked .mouth-happy,
.zen-mascot.mood-shocked .mouth-sad {
  display: none !important;
}

.zen-mascot.mood-shocked .eye-shocked,
.zen-mascot.mood-shocked .eye-shocked-pupil,
.zen-mascot.mood-shocked .mouth-shocked {
  display: block !important;
}

.zen-mascot.mood-shocked .sweat-drop {
  animation: sweatFall 1s ease-out forwards;
}

.zen-mascot.mood-shocked {
  animation: shiver 0.15s infinite linear;
}

/* Thinking mood */
.zen-mascot.mood-thinking .eye-pupil {
  transform: translate(2px, -3px); /* looking up/aside */
}

.zen-mascot.mood-thinking .mouth-happy,
.zen-mascot.mood-thinking .mouth-shocked {
  display: none;
}

.zen-mascot.mood-thinking .mouth-sad {
  display: block !important;
}

.zen-mascot.mood-thinking .cat-head-group {
  animation: tiltHead 4s ease-in-out infinite;
}

/* Sleeping mood */
.zen-mascot.mood-sleeping .eye-normal,
.zen-mascot.mood-sleeping .eye-pupil,
.zen-mascot.mood-sleeping .eye-pupil-sub,
.zen-mascot.mood-sleeping .mouth-happy,
.zen-mascot.mood-sleeping .mouth-shocked {
  display: none !important;
}

.zen-mascot.mood-sleeping .eye-sleeping,
.zen-mascot.mood-sleeping .mouth-sad {
  display: block !important;
}

.zen-mascot.mood-sleeping .sleep-zzz {
  animation: floatZzz 3s infinite ease-out;
}

.zen-mascot.mood-sleeping {
  animation: breathe 3s ease-in-out infinite;
}

/* Keyframes for Mascot */
@keyframes bodyFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes tailWag {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(15deg); }
}

@keyframes blinkLight {
  0%, 100% { fill: #10b981; } /* Green */
  50% { fill: #3b82f6; } /* Blue */
}

@keyframes blushPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

@keyframes wavePawLeft {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-6px) rotate(-10deg); }
}

@keyframes tiltHead {
  0%, 100% { transform: rotate(0deg); transform-origin: 100px 85px; }
  50% { transform: rotate(-5deg); transform-origin: 100px 85px; }
}

@keyframes shiver {
  0% { transform: translate(1px, 1px) rotate(0deg); }
  10% { transform: translate(-1px, -1px) rotate(-0.5deg); }
  20% { transform: translate(-2px, 0px) rotate(0.5deg); }
  30% { transform: translate(0px, 2px) rotate(0deg); }
  40% { transform: translate(1px, -1px) rotate(0.5deg); }
  50% { transform: translate(-1px, 1px) rotate(-0.5deg); }
  60% { transform: translate(-2px, 1px) rotate(0deg); }
  70% { transform: translate(2px, 1px) rotate(-0.5deg); }
  80% { transform: translate(-1px, -1px) rotate(0.5deg); }
  90% { transform: translate(1px, 2px) rotate(0deg); }
  100% { transform: translate(1px, -1px) rotate(-0.5deg); }
}

@keyframes floatZzz {
  0% { transform: translate(-10px, 10px); opacity: 0; }
  20% { opacity: 0.8; }
  100% { transform: translate(15px, -30px); opacity: 0; }
}

@keyframes sweatFall {
  0% { opacity: 0; transform: translateY(0); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateY(20px); }
}

@keyframes breathe {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(0.97) translateY(2px); }
}

/* Mascot Speech Bubble */
.speech-bubble-wrapper {
  position: relative;
  width: 100%;
}

.speech-bubble {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--panel-border);
  padding: 16px 20px;
  border-radius: var(--border-radius-md);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
  text-align: left;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: all var(--transition-normal);
}

.fact-category {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-accent);
  letter-spacing: 1.5px;
  margin-bottom: 6px;
  display: inline-block;
}

.speech-bubble p {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-main);
}

.speech-tail {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 10px solid var(--panel-border);
}

.speech-tail::after {
  content: '';
  position: absolute;
  top: 1px;
  left: -9px;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 9px solid rgba(0, 0, 0, 0.25);
}

.buddy-controls {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 6px;
}

/* ==========================================================================
   Modals & Popups (Overlay layout)
   ========================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 3, 15, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-content {
  width: 90%;
  max-width: 460px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 32px !important;
}

.modal-medium {
  max-width: 500px;
}

.modal-header-accent {
  display: flex;
  justify-content: center;
  align-items: center;
}

.trophy-pulse {
  filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.4));
  animation: trophyFloating 3s ease-in-out infinite;
}

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

.modal-content h2 {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--text-main) 40%, var(--text-accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-subtext {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: -8px;
}

/* Results Grid inside Win Modal */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.result-card {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--border-radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.result-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.result-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.text-easy { color: var(--difficulty-easy); }
.text-medium { color: var(--difficulty-medium); }
.text-hard { color: var(--difficulty-hard); }

.modal-buddy-praise, .gameover-buddy-consolation {
  background: rgba(139, 92, 246, 0.06);
  border: 1px dashed var(--panel-border);
  border-radius: var(--border-radius-md);
  padding: 14px 18px;
  width: 100%;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-main);
  text-align: left;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1.2fr 2fr;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
}

/* Tab Headers and Statistics layout */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 12px;
}

.modal-header h2 {
  font-size: 1.4rem;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
}

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

.tabs-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.tab-headers {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--border-radius-sm);
  padding: 4px;
}

.tab-header {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab-header.active {
  background: var(--text-accent);
  color: #1e1b4b;
}

.tab-content {
  display: none;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}

.tab-content.active {
  display: flex;
}

/* Stats Overview */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-box {
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--border-radius-md);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(255, 255, 255, 0.02);
}

.stat-number {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-accent);
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  text-align: left;
  margin-bottom: -6px;
  color: var(--text-muted);
}

.pb-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.15);
  padding: 12px;
  border-radius: var(--border-radius-md);
}

.pb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.pb-row:last-child {
  border-bottom: none;
}

.pb-difficulty {
  font-weight: 600;
}

.pb-time {
  font-family: var(--font-mono);
  font-weight: 700;
}

.danger-text-btn {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  align-self: center;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background var(--transition-fast);
}

.danger-text-btn:hover {
  background: rgba(239, 68, 68, 0.08);
}

/* Settings List */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  text-align: left;
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 80%;
}

.settings-info label {
  font-weight: 600;
  cursor: pointer;
}

.settings-info span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Toggle Switch Control */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: var(--transition-fast);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: var(--transition-fast);
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--text-accent);
}

input:checked + .slider:before {
  transform: translateX(20px);
  background-color: #1e1b4b;
}

/* Button Classes */
.primary-btn, .secondary-btn {
  border-radius: var(--border-radius-md);
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.primary-btn {
  background: var(--text-accent);
  border: 1px solid var(--text-accent);
  color: #1e1b4b;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.3);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
  background: #b59dfb;
}

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

.secondary-btn {
  background: var(--btn-secondary-bg);
  border: 1px solid var(--panel-border);
  color: var(--btn-secondary-text);
}

.secondary-btn:hover {
  background: var(--btn-secondary-hover);
  border-color: var(--text-accent);
  transform: translateY(-2px);
}

.secondary-btn:active {
  transform: translateY(0);
}

/* Animations */
.pop-in-animation {
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.bounce-in-animation {
  animation: bounceIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes bounceIn {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.05); opacity: 0.8; }
  70% { transform: scale(0.9); opacity: 0.9; }
  100% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   Responsive Viewports (Mobile & Tablet tweaks)
   ========================================================================== */

@media (max-width: 900px) {
  body {
    padding: 10px;
    align-items: flex-start;
  }
  
  .app-container {
    padding: 8px;
    gap: 16px;
    min-height: auto;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .glass-panel {
    padding: 16px;
    gap: 16px;
  }

  .mascot-card {
    min-height: auto;
    gap: 14px;
  }
  
  .mascot-avatar-container {
    width: 140px;
    height: 140px;
  }
  
  .speech-bubble {
    min-height: auto;
    padding: 12px 16px;
  }
  
  .speech-bubble p {
    font-size: 0.9rem;
  }
  
  .cell-value {
    font-size: 1.3rem;
  }

  .keypad-btn {
    font-size: 1.15rem;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 10px 16px;
  }
  
  .logo-area h1 {
    font-size: 1.15rem;
  }
  
  .stats-bar {
    padding: 10px 12px;
  }
  
  .stat-val {
    font-size: 1rem;
  }
  
  .board-wrapper {
    border-width: 2px;
  }

  .game-toolbar {
    gap: 4px;
  }
  
  .tool-btn {
    padding: 8px 2px;
    font-size: 0.65rem;
  }
  
  .tool-btn svg {
    width: 16px;
    height: 16px;
  }
  
  .keypad {
    padding: 6px;
    gap: 4px;
  }
  
  .keypad-btn {
    font-size: 1.1rem;
    border-radius: 6px;
  }

  .difficulty-btn {
    padding: 10px;
    font-size: 0.8rem;
  }
  
  .modal-content {
    padding: 24px 16px !important;
  }
  
  .modal-actions {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}
