@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700;800&display=swap');

:root {
  --gap: 12px;
  --bg-color: #fef5e7;
  --board-bg: linear-gradient(135deg, #fff8e1 0%, #ffe0b2 100%);
  --tile-bg: #ffe0b2;
  --font-color: #3e2723;
  --font-family: 'Poppins', 'Segoe UI', sans-serif;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);
  --shadow-xl: 0 12px 40px rgba(0,0,0,0.25);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html {
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: fixed;
  touch-action: none;
  -webkit-overflow-scrolling: touch;
}

body {
  background: linear-gradient(135deg, #fef5e7 0%, #ffe0b2 50%, #ffcc80 100%);
  background-attachment: fixed;
  font-family: var(--font-family);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  min-height: 100vh;
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 50%, rgba(255, 193, 7, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(255, 152, 0, 0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1rem;
}

.header {
  text-align: center;
  width: 100%;
  animation: fadeInDown 0.6s ease;
}

h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  color: #5d4037;
  text-shadow: 2px 2px 4px rgba(255,255,255,0.8), 0 0 20px rgba(255,193,7,0.3);
  margin-bottom: 0.5rem;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #6d4c41 0%, #8d6e63 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stats-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 500px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  padding: 1rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: fadeInUp 0.6s ease;
  border: 2px solid rgba(255, 193, 7, 0.2);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-label {
  font-size: 0.75rem;
  color: #8d6e63;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #5d4037;
}

.challenge-card {
  background: linear-gradient(135deg, rgba(255, 193, 7, 0.2) 0%, rgba(255, 152, 0, 0.2) 100%);
  backdrop-filter: blur(10px);
  padding: 1rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
  width: 100%;
  text-align: center;
  border: 2px solid rgba(255, 193, 7, 0.3);
  animation: fadeInUp 0.8s ease;
}

.challenge-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #5d4037;
  margin-bottom: 0.5rem;
}

.progress-bar-container {
  width: 100%;
  height: 12px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 0.5rem;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #ffc107 0%, #ff9800 100%);
  border-radius: 10px;
  transition: width 0.5s ease;
  box-shadow: 0 2px 4px rgba(255, 152, 0, 0.4);
  position: relative;
  overflow: hidden;
}

.progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 2s infinite;
}

.game-container {
  max-width: 450px;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--board-bg);
  padding: var(--gap);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  grid-gap: var(--gap);
  border-radius: 1.5rem;
  box-shadow: var(--shadow-xl), inset 0 2px 4px rgba(255,255,255,0.5);
  position: relative;
  animation: fadeInUp 1s ease;
  border: 4px solid rgba(255, 193, 7, 0.3);
}

/* Dynamic grid sizes will be set via JavaScript */

.tile {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(0.5rem, 2vw, 0.85rem);
  font-weight: 700;
  color: var(--font-color);
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.4), 0 2px 4px rgba(0,0,0,0.1);
  overflow: hidden;
  text-align: center;
  padding: 0.3rem;
  box-sizing: border-box;
  word-wrap: break-word;
  line-height: 1.2;
  position: relative;
  border: 2px solid rgba(255,255,255,0.3);
}

.tile:not(.empty):hover {
  transform: scale(1.05);
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.5), 0 4px 8px rgba(0,0,0,0.15);
}

.tile.empty {
  background: rgba(255, 255, 255, 0.15);
  border: 2px dashed rgba(255, 193, 7, 0.2);
  box-shadow: none;
}

.tile.new {
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tile.merged {
  animation: mergePulse 0.4s ease;
}

.fact-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 1rem 1.5rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
  width: 100%;
  text-align: center;
  font-size: 0.9rem;
  color: #5d4037;
  line-height: 1.6;
  border: 2px solid rgba(255, 193, 7, 0.2);
  animation: fadeInUp 1.2s ease;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.leaderboard-card {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  padding: 1.5rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
  width: 100%;
  border: 2px solid rgba(255, 193, 7, 0.2);
  animation: fadeInUp 1.4s ease;
}

.leaderboard-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #5d4037;
  margin-bottom: 1rem;
  text-align: center;
}

#leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

#leaderboard-list li {
  padding: 0.75rem;
  margin: 0.5rem 0;
  background: linear-gradient(135deg, rgba(255, 193, 7, 0.1) 0%, rgba(255, 152, 0, 0.1) 100%);
  border-radius: 0.75rem;
  font-weight: 600;
  color: #5d4037;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s;
}

#leaderboard-list li:hover {
  transform: translateX(5px);
}

#leaderboard-list li::before {
  content: '🏆';
  font-size: 1.2rem;
}

#leaderboard-list li:first-child::before {
  content: '🥇';
}

#leaderboard-list li:nth-child(2)::before {
  content: '🥈';
}

#leaderboard-list li:nth-child(3)::before {
  content: '🥉';
}

#game-over {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 248, 225, 0.98);
  backdrop-filter: blur(10px);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  color: #5d4037;
  border-radius: 1.5rem;
  z-index: 10;
  padding: 2rem;
  text-align: center;
  box-shadow: inset 0 0 50px rgba(0,0,0,0.1);
  animation: fadeIn 0.5s ease;
}

#game-over.show {
  display: flex;
  animation: fadeInScale 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#game-over-message {
  margin-bottom: 1.5rem;
  font-weight: 700;
  line-height: 1.4;
}

#restart-btn {
  margin-top: 1rem;
  padding: 1rem 2rem;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 1rem;
  background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
  color: #3e2723;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
  font-family: var(--font-family);
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
}

#restart-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

#restart-btn:hover::before {
  width: 300px;
  height: 300px;
}

#restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

#restart-btn:active {
  transform: translateY(0);
}

#restart-btn span {
  position: relative;
  z-index: 1;
}

.controls-hint {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: #8d6e63;
  text-align: center;
  font-style: italic;
}

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

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes popIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes mergePulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@keyframes scorePop {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
}

.score-pop {
  animation: scorePop 0.3s ease;
}

@media (max-width: 480px) {
  body {
    padding: 0.25rem;
  }

  .container {
    gap: 0.5rem;
  }

  .header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
  }

  .stats-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .stat-card {
    padding: 0.75rem;
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .challenge-card {
    padding: 0.75rem;
  }

  .challenge-title {
    font-size: 0.8rem;
  }

  .game-container {
    max-width: 100%;
    padding: 8px;
    grid-gap: 8px;
    border-radius: 1rem;
  }
  
  .tile {
    font-size: clamp(0.4rem, 2.5vw, 0.65rem);
    padding: 0.15rem;
    border-radius: 0.75rem;
  }

  .fact-card {
    padding: 0.75rem;
    font-size: 0.8rem;
    min-height: 50px;
  }

  .leaderboard-card {
    padding: 1rem;
  }

  .leaderboard-title {
    font-size: 1rem;
  }

  .controls-hint {
    font-size: 0.75rem;
    margin-top: 0.5rem;
  }
}

@media (max-height: 700px) {
  .container {
    gap: 0.5rem;
  }

  .header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
  }

  .stats-container {
    gap: 0.5rem;
  }

  .stat-card {
    padding: 0.5rem;
  }

  .challenge-card {
    padding: 0.5rem;
  }

  .fact-card {
    padding: 0.5rem;
    font-size: 0.75rem;
    min-height: 40px;
  }

  .leaderboard-card {
    padding: 0.75rem;
  }
}

.achievement-badge {
  position: fixed;
  top: 20px;
  right: 20px;
  background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
  color: #3e2723;
  padding: 1rem 1.5rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-lg);
  font-weight: 700;
  z-index: 1000;
  animation: slideInRight 0.5s ease, slideOutRight 0.5s ease 2.5s forwards;
  display: none;
}

.achievement-badge.show {
  display: block;
}

.bonus-indicator {
  position: fixed;
  top: 120px;
  left: 50%;
  transform: translateX(-50%);
  background: none;
  color: #ff6b35;
  padding: 0.5rem 1rem;
  font-weight: 900;
  font-size: 1.3rem;
  z-index: 2000;
  display: none;
  text-align: center;
  pointer-events: none;
  text-shadow: 
    2px 2px 4px rgba(0, 0, 0, 0.8),
    0 0 10px rgba(255, 107, 53, 0.8),
    0 0 20px rgba(255, 107, 53, 0.6),
    0 0 30px rgba(255, 107, 53, 0.4);
}

.bonus-indicator.show {
  display: block;
  animation: bonusPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), bonusFadeOut 0.3s ease 1.2s forwards;
}

@keyframes bonusPop {
  0% {
    transform: translateX(-50%) translateY(-20px) scale(0.8);
    opacity: 0;
  }
  50% {
    transform: translateX(-50%) translateY(-10px) scale(1.1);
  }
  100% {
    transform: translateX(-50%) translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes bonusFadeOut {
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px) scale(0.95);
  }
}

.bonus-amount {
  font-size: 2rem;
  margin-top: 0.3rem;
  text-shadow: 
    2px 2px 6px rgba(0, 0, 0, 0.9),
    0 0 15px rgba(255, 107, 53, 1),
    0 0 25px rgba(255, 107, 53, 0.8),
    0 0 35px rgba(255, 107, 53, 0.6);
  font-weight: 900;
  letter-spacing: 2px;
  color: #ff6b35;
}

@media (max-width: 480px) {
  .bonus-indicator {
    top: 100px;
    padding: 0.5rem;
    font-size: 1.1rem;
  }
  
  .bonus-amount {
    font-size: 1.6rem;
  }
}

/* Settings Panel */
.settings-panel {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 2000;
}

.settings-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid rgba(255, 193, 7, 0.3);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-btn:hover {
  transform: rotate(90deg) scale(1.1);
  box-shadow: var(--shadow-lg);
}

.settings-menu {
  position: absolute;
  top: 60px;
  left: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 1rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  border: 2px solid rgba(255, 193, 7, 0.3);
  animation: fadeInDown 0.3s ease;
}

.settings-section {
  margin-bottom: 1rem;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-title {
  font-size: 0.75rem;
  color: #8d6e63;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.theme-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.theme-btn {
  padding: 0.5rem;
  border: 2px solid rgba(255, 193, 7, 0.3);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.8);
  color: #5d4037;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-family);
}

.theme-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.theme-btn.active {
  background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
  color: #3e2723;
  border-color: #ff9800;
}

.audio-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.audio-btn {
  padding: 0.5rem 1rem;
  border: 2px solid rgba(255, 193, 7, 0.3);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.8);
  color: #5d4037;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-family);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.audio-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.audio-btn.muted {
  opacity: 0.5;
}

/* Particle Canvas */
#particle-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1500;
}

/* Tile sliding animations */
.tile {
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

.tile.sliding {
  z-index: 10;
}

/* Dark Mode */
body.dark-mode {
  background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 50%, #1a1a1a 100%);
  color: #e0e0e0;
}

body.dark-mode .stat-card,
body.dark-mode .challenge-card,
body.dark-mode .fact-card,
body.dark-mode .leaderboard-card,
body.dark-mode .mode-selector,
body.dark-mode .size-selector,
body.dark-mode .powerups-container,
body.dark-mode .target-card,
body.dark-mode .settings-menu {
  background: rgba(30, 30, 30, 0.95);
  border-color: rgba(255, 193, 7, 0.3);
  color: #e0e0e0;
}

body.dark-mode .stat-value,
body.dark-mode .challenge-title,
body.dark-mode h1 {
  color: #fff;
}

body.dark-mode .game-container {
  background: linear-gradient(135deg, #2d2d2d 0%, #1a1a1a 100%);
  border-color: rgba(255, 193, 7, 0.2);
}

body.dark-mode .tile.empty {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 193, 7, 0.1);
}

body.dark-mode #game-over {
  background: rgba(30, 30, 30, 0.98);
  color: #e0e0e0;
}

/* Colorful Theme */
body.colorful-theme {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #00f2fe 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

body.colorful-theme .stat-card,
body.colorful-theme .challenge-card,
body.colorful-theme .fact-card,
body.colorful-theme .leaderboard-card {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(255, 255, 255, 0.5);
}

/* Classic Theme */
body.classic-theme {
  background: linear-gradient(135deg, #f5f5dc 0%, #deb887 100%);
}

body.classic-theme .stat-card,
body.classic-theme .challenge-card,
body.classic-theme .fact-card,
body.classic-theme .leaderboard-card {
  background: rgba(255, 248, 220, 0.95);
  border-color: rgba(139, 69, 19, 0.3);
}

/* Confetti Container */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3000;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #ffc107;
  animation: confettiFall linear forwards;
}

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

@media (max-width: 480px) {
  .settings-panel {
    top: 10px;
    left: 10px;
  }
  
  .settings-btn {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }
  
  .settings-menu {
    top: 50px;
    min-width: 180px;
    padding: 0.75rem;
  }
  
  .theme-buttons {
    grid-template-columns: 1fr;
  }
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-content {
  text-align: center;
  color: white;
}

.loading-logo {
  font-size: 5rem;
  animation: bounce 1s infinite;
  margin-bottom: 1rem;
}

.loading-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 2rem;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.loading-text-fill {
  position: relative;
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 2rem;
  display: inline-block;
  color: rgba(255,255,255,0.3);
  text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.loading-text-fill-inner {
  position: relative;
  display: inline-block;
  background: linear-gradient(90deg, 
    rgba(255,255,255,0.3) 0%, 
    rgba(255,255,255,0.3) 40%,
    white 50%,
    white 60%,
    rgba(255,255,255,0.3) 100%);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: textFill 2.5s ease-in-out infinite;
  background-position: -100% 0%;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

@keyframes textFill {
  0% {
    background-position: -100% 0%;
  }
  50% {
    background-position: 0% 0%;
  }
  100% {
    background-position: 100% 0%;
  }
}

/* Alternative text fill animation - wave effect */
@keyframes textFillWave {
  0% {
    background-position: 0% 0%;
  }
  100% {
    background-position: 200% 0%;
  }
}

/* Error Toast */
.error-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #f44336;
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 0.75rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 1rem;
  z-index: 5000;
  transform: translateX(400px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  max-width: 400px;
}

.error-toast.show {
  transform: translateX(0);
  opacity: 1;
}

.error-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.error-message {
  flex: 1;
  font-weight: 500;
}

.error-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
}

.error-close:hover {
  background: rgba(255,255,255,0.2);
}

/* Onboarding */
.onboarding-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(5px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.onboarding-content {
  background: white;
  border-radius: 1.5rem;
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  position: relative;
  animation: slideUp 0.4s ease;
}

.onboarding-slide {
  display: none;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

.onboarding-slide.active {
  display: block;
}

.onboarding-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: bounce 1s infinite;
}

.onboarding-slide h2 {
  color: #5d4037;
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

.onboarding-slide p {
  color: #6d4c41;
  line-height: 1.6;
  margin-bottom: 2rem;
  text-align: left;
}

.onboarding-slide ul {
  text-align: left;
  color: #6d4c41;
  line-height: 1.8;
  margin-bottom: 2rem;
}

.onboarding-slide ul li {
  margin-bottom: 0.5rem;
}

.onboarding-dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.onboarding-dots .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 193, 7, 0.3);
  transition: all 0.3s ease;
}

.onboarding-dots .dot.active {
  background: #ffc107;
  transform: scale(1.2);
}

.onboarding-btn {
  padding: 0.75rem 2rem;
  background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
  color: #3e2723;
  border: none;
  border-radius: 0.75rem;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-md);
}

.onboarding-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* Help Modal */
.help-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
  z-index: 8000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.help-content {
  background: white;
  border-radius: 1.5rem;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.4s ease;
}

.help-header {
  padding: 1.5rem;
  border-bottom: 2px solid rgba(255, 193, 7, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
}

.help-header h2 {
  color: #5d4037;
  margin: 0;
  font-size: 1.5rem;
}

.help-close {
  background: transparent;
  border: none;
  font-size: 2rem;
  color: #8d6e63;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.help-close:hover {
  background: rgba(255, 193, 7, 0.2);
  color: #5d4037;
}

.help-body {
  padding: 1.5rem;
}

.help-section {
  margin-bottom: 2rem;
}

.help-section:last-child {
  margin-bottom: 0;
}

.help-section h3 {
  color: #5d4037;
  margin-bottom: 0.75rem;
  font-size: 1.2rem;
}

.help-section p {
  color: #6d4c41;
  line-height: 1.6;
  margin-bottom: 0.5rem;
}

.help-section ul {
  color: #6d4c41;
  line-height: 1.8;
  padding-left: 1.5rem;
}

.help-section ul li {
  margin-bottom: 0.5rem;
}

.help-btn {
  width: 100%;
  padding: 0.75rem;
  background: rgba(255, 193, 7, 0.2);
  border: 2px solid rgba(255, 193, 7, 0.3);
  border-radius: 0.5rem;
  color: #5d4037;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-family);
}

.help-btn:hover {
  background: rgba(255, 193, 7, 0.3);
  transform: translateY(-2px);
}

/* Smooth Transitions */
.container {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.container.fade-in {
  animation: fadeInUp 0.5s ease;
}

.stat-card,
.challenge-card,
.fact-card,
.leaderboard-card,
.mode-selector,
.size-selector,
.powerups-container {
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.stat-card:hover,
.challenge-card:hover {
  transform: translateY(-2px);
}

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

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Dark mode adjustments */
body.dark-mode .onboarding-content,
body.dark-mode .help-content {
  background: rgba(30, 30, 30, 0.95);
  color: #e0e0e0;
}

body.dark-mode .onboarding-slide h2,
body.dark-mode .help-header h2,
body.dark-mode .help-section h3 {
  color: #fff;
}

body.dark-mode .onboarding-slide p,
body.dark-mode .onboarding-slide ul,
body.dark-mode .help-section p,
body.dark-mode .help-section ul {
  color: #e0e0e0;
}

@media (max-width: 480px) {
  .error-toast {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
    transform: translateY(-100px);
  }
  
  .error-toast.show {
    transform: translateY(0);
  }
  
  .onboarding-content,
  .help-content {
    padding: 1.5rem;
    max-height: 95vh;
  }
  
  .onboarding-icon {
    font-size: 3rem;
  }
  
  .onboarding-slide h2 {
    font-size: 1.25rem;
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(200%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  to {
    transform: translateX(200%);
    opacity: 0;
  }
}

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

@keyframes tilePop {
  0% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Mode Selector */
.mode-selector, .size-selector {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  padding: 0.75rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
  width: 100%;
  margin-bottom: 0.5rem;
  border: 2px solid rgba(255, 193, 7, 0.2);
}

.mode-title, .size-title {
  font-size: 0.75rem;
  color: #8d6e63;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
  text-align: center;
}

.mode-buttons, .size-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.mode-btn, .size-btn {
  padding: 0.5rem 1rem;
  border: 2px solid rgba(255, 193, 7, 0.3);
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.8);
  color: #5d4037;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-family);
}

.mode-btn:hover, .size-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  background: rgba(255, 193, 7, 0.2);
}

.mode-btn.active, .size-btn.active {
  background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
  color: #3e2723;
  border-color: #ff9800;
  box-shadow: var(--shadow-md);
}

/* Action Buttons */
.action-buttons {
  display: flex;
  gap: 0.75rem;
  width: 100%;
  margin-bottom: 0.5rem;
}

.action-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid rgba(255, 193, 7, 0.3);
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.9);
  color: #5d4037;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-family);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.action-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  background: rgba(255, 193, 7, 0.2);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Power-ups */
.powerups-container {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  padding: 0.75rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
  width: 100%;
  margin-bottom: 0.5rem;
  border: 2px solid rgba(255, 193, 7, 0.2);
}

.powerups-title {
  font-size: 0.75rem;
  color: #8d6e63;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
  text-align: center;
}

.powerups-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.powerup-btn {
  padding: 0.75rem;
  border: 2px solid rgba(255, 193, 7, 0.3);
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.8);
  color: #5d4037;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-family);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.powerup-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  background: rgba(255, 193, 7, 0.2);
}

.powerup-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.powerup-btn.active {
  background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
  color: white;
  border-color: #44a08d;
}

/* Target Card */
.target-card {
  background: linear-gradient(135deg, rgba(76, 175, 80, 0.2) 0%, rgba(56, 142, 60, 0.2) 100%);
  backdrop-filter: blur(10px);
  padding: 1rem;
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
  width: 100%;
  text-align: center;
  border: 2px solid rgba(76, 175, 80, 0.3);
  animation: fadeInUp 0.8s ease;
  margin-bottom: 0.5rem;
}

/* Hint Indicator */
.hint-indicator {
  position: absolute;
  width: 100%;
  height: 100%;
  border: 3px solid #4caf50;
  border-radius: 1rem;
  pointer-events: none;
  animation: hintPulse 1s infinite;
  z-index: 5;
}

@keyframes hintPulse {
  0%, 100% {
    opacity: 0.6;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.02);
  }
}

/* Tile Selection for Remove */
.tile.selectable {
  cursor: pointer;
  border: 3px solid #ff6b35;
  animation: selectPulse 1s infinite;
}

@keyframes selectPulse {
  0%, 100% {
    border-color: #ff6b35;
  }
  50% {
    border-color: #ff8c42;
  }
}

@media (max-width: 480px) {
  .mode-buttons, .size-buttons {
    gap: 0.25rem;
  }
  
  .mode-btn, .size-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
  }
  
  .action-buttons {
    gap: 0.5rem;
  }
  
  .action-btn {
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
  }
  
  .powerups-grid {
    gap: 0.25rem;
  }
  
  .powerup-btn {
    padding: 0.6rem;
    font-size: 0.75rem;
  }
}

