@import url(fonts/clear-sans.css);

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #0d1117 0%, #161b22 50%, #21262d 100%);
  color: #c9d1d9;
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  font-size: 18px;
  overflow-x: hidden;
}

body { margin: 20px 0; }

.heading:after { content: ""; display: block; clear: both; }

h1.title {
  font-size: 48px;
  font-weight: bold;
  margin: 0;
  display: block;
  float: left;
  color: #f7931a;
  text-shadow: 0 0 10px rgba(247, 147, 26, 0.5);
}

.scores-container { float: right; text-align: right; }

.score-container, .best-container {
  position: relative;
  display: inline-block;
  background: #21262d;
  padding: 8px 15px;
  font-size: 18px;
  height: 35px;
  line-height: 35px;
  font-weight: bold;
  border-radius: 6px;
  color: #f7931a;
  margin-top: 4px;
  text-align: center;
  border: 1px solid #f7931a;
}

.score-container:after { content: "SCORE"; display: block; font-size: 10px; color: #8b949e; line-height: 1; }
.best-container:after { content: "BEST"; display: block; font-size: 10px; color: #8b949e; line-height: 1; }

p { margin-top: 0; margin-bottom: 8px; line-height: 1.5; }

a { color: #f7931a; font-weight: bold; text-decoration: underline; cursor: pointer; }

strong.important { text-transform: uppercase; }

hr { border: none; border-bottom: 1px solid #30363d; margin-top: 15px; margin-bottom: 20px; }

.container { width: 100%; max-width: 500px; margin: 0 auto; padding: 0 10px; box-sizing: border-box; }

.game-container {
  margin-top: 20px;
  position: relative;
  padding: 10px;
  background: #161b22;
  border-radius: 6px;
  width: 100%;
  max-width: 500px;
  height: auto;
  aspect-ratio: 1;
  box-sizing: border-box;
  border: 2px solid #30363d;
}

.grid-container { position: absolute; z-index: 1; top: 10px; left: 10px; right: 10px; bottom: 10px; }

.grid-row { margin-bottom: 2%; height: 23.5%; }
.grid-row:last-child { margin-bottom: 0; }
.grid-row:after { content: ""; display: block; clear: both; }

.grid-cell {
  width: 23.5%;
  height: 100%;
  margin-right: 2%;
  float: left;
  border-radius: 4px;
  background: rgba(48, 54, 61, 0.5);
}
.grid-cell:last-child { margin-right: 0; }

.tile-container { position: absolute; z-index: 2; top: 10px; left: 10px; right: 10px; bottom: 10px; }

.tile, .tile .tile-inner {
  width: 106.25px;
  height: 106.25px;
  line-height: 106.25px;
}

.tile { 
  position: absolute; 
  transition: transform 150ms cubic-bezier(0.4, 0.0, 0.2, 1);
  z-index: 10;
  will-change: transform;
}

.tile .tile-inner {
  transition: transform 150ms cubic-bezier(0.4, 0.0, 0.2, 1),
              background-color 150ms ease,
              box-shadow 150ms ease;
}

/* Dramatic color changes for each tile value */
.tile-2 .tile-inner { 
  background: linear-gradient(145deg, #1e3a5f, #2d5a87); 
  color: #fff; 
  box-shadow: 0 0 10px rgba(30, 58, 95, 0.5);
}
.tile-4 .tile-inner { 
  background: linear-gradient(145deg, #2d5a87, #3d7ab8); 
  color: #fff; 
  box-shadow: 0 0 15px rgba(45, 90, 135, 0.6);
}
.tile-8 .tile-inner { 
  background: linear-gradient(145deg, #3d7ab8, #4a9ad4); 
  color: #fff; 
  box-shadow: 0 0 20px rgba(61, 122, 184, 0.7);
}
.tile-16 .tile-inner { 
  background: linear-gradient(145deg, #f59e0b, #f7931a); 
  color: #1a1a1a; 
  box-shadow: 0 0 25px rgba(245, 158, 11, 0.8);
}
.tile-32 .tile-inner { 
  background: linear-gradient(145deg, #f7931a, #ea580c); 
  color: #fff; 
  box-shadow: 0 0 30px rgba(247, 147, 26, 0.9);
}
.tile-64 .tile-inner { 
  background: linear-gradient(145deg, #ea580c, #dc2626); 
  color: #fff; 
  box-shadow: 0 0 35px rgba(234, 88, 12, 1);
}
.tile-128 .tile-inner { 
  background: linear-gradient(145deg, #dc2626, #991b1b); 
  color: #fff; 
  font-size: 45px;
  box-shadow: 0 0 40px rgba(220, 38, 38, 1);
  animation: pulse-red 1.5s ease-in-out infinite;
}
.tile-256 .tile-inner { 
  background: linear-gradient(145deg, #7c3aed, #6d28d9); 
  color: #fff; 
  font-size: 45px;
  box-shadow: 0 0 45px rgba(124, 58, 237, 1);
  animation: pulse-purple 1.2s ease-in-out infinite;
}
.tile-512 .tile-inner { 
  background: linear-gradient(145deg, #ec4899, #db2777); 
  color: #fff; 
  font-size: 45px;
  box-shadow: 0 0 50px rgba(236, 72, 153, 1);
  animation: pulse-pink 1s ease-in-out infinite;
}
.tile-1024 .tile-inner { 
  background: linear-gradient(145deg, #10b981, #059669); 
  color: #fff; 
  font-size: 35px;
  box-shadow: 0 0 60px rgba(16, 185, 129, 1);
  animation: pulse-green 0.8s ease-in-out infinite;
}
.tile-2048 .tile-inner { 
  background: linear-gradient(45deg, #f7931a, #fbbf24, #f7931a, #fbbf24);
  background-size: 400% 400%;
  color: #1a1a1a; 
  font-size: 45px;
  box-shadow: 0 0 80px rgba(247, 147, 26, 1), 0 0 120px rgba(251, 191, 36, 0.8), inset 0 0 30px rgba(255, 255, 255, 0.5);
  animation: gradientShift 1.5s ease infinite, pulse-gold 0.5s ease-in-out infinite, bitcoinGlow 2s ease-in-out infinite;
  font-weight: 900;
  border: 3px solid #fbbf24;
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.8);
}

.tile-2048 .tile-inner::before {
  content: "₿";
  display: block;
  font-size: 20px;
  margin-bottom: -10px;
}

@keyframes bitcoinGlow {
  0%, 100% { box-shadow: 0 0 80px rgba(247, 147, 26, 1), 0 0 120px rgba(251, 191, 36, 0.6); }
  50% { box-shadow: 0 0 100px rgba(247, 147, 26, 1.2), 0 0 150px rgba(251, 191, 36, 0.9), 0 0 200px rgba(251, 191, 36, 0.4); }
}

.tile-super .tile-inner { 
  background: linear-gradient(45deg, #ff0080, #f7931a, #00ff88, #0080ff);
  background-size: 400% 400%;
  color: #fff;
  animation: rainbow 1.5s linear infinite;
}

.tile .tile-inner {
  border-radius: 4px;
  font-weight: bold;
  text-align: center;
  position: absolute;
}

/* Tile appear animation */
.tile-new .tile-inner {
  animation: appear 200ms ease-out;
}

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

/* Tile merge animation */
.tile-merged .tile-inner {
  animation: pop 200ms ease-in-out;
}

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

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 40px rgba(220, 38, 38, 1); transform: scale(1); }
  50% { box-shadow: 0 0 60px rgba(220, 38, 38, 1.2); transform: scale(1.02); }
}

@keyframes pulse-purple {
  0%, 100% { box-shadow: 0 0 45px rgba(124, 58, 237, 1); transform: scale(1); }
  50% { box-shadow: 0 0 65px rgba(124, 58, 237, 1.2); transform: scale(1.02); }
}

@keyframes pulse-pink {
  0%, 100% { box-shadow: 0 0 50px rgba(236, 72, 153, 1); transform: scale(1); }
  50% { box-shadow: 0 0 70px rgba(236, 72, 153, 1.2); transform: scale(1.02); }
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 60px rgba(16, 185, 129, 1); transform: scale(1); }
  50% { box-shadow: 0 0 80px rgba(16, 185, 129, 1.2); transform: scale(1.02); }
}

@keyframes pulse-gold {
  0%, 100% { box-shadow: 0 0 70px rgba(251, 191, 36, 1), 0 0 100px rgba(247, 147, 26, 0.8); transform: scale(1); }
  50% { box-shadow: 0 0 100px rgba(251, 191, 36, 1.3), 0 0 150px rgba(247, 147, 26, 1); transform: scale(1.03); }
}

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

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

/* Tile positions using pixels */
.tile.tile-position-1-1 { transform: translate(0px, 0px); }
.tile.tile-position-1-2 { transform: translate(0px, 121px); }
.tile.tile-position-1-3 { transform: translate(0px, 242px); }
.tile.tile-position-1-4 { transform: translate(0px, 363px); }
.tile.tile-position-2-1 { transform: translate(121px, 0px); }
.tile.tile-position-2-2 { transform: translate(121px, 121px); }
.tile.tile-position-2-3 { transform: translate(121px, 242px); }
.tile.tile-position-2-4 { transform: translate(121px, 363px); }
.tile.tile-position-3-1 { transform: translate(242px, 0px); }
.tile.tile-position-3-2 { transform: translate(242px, 121px); }
.tile.tile-position-3-3 { transform: translate(242px, 242px); }
.tile.tile-position-3-4 { transform: translate(242px, 363px); }
.tile.tile-position-4-1 { transform: translate(363px, 0px); }
.tile.tile-position-4-2 { transform: translate(363px, 121px); }
.tile.tile-position-4-3 { transform: translate(363px, 242px); }
.tile.tile-position-4-4 { transform: translate(363px, 363px); }

.game-message { 
  display: none; 
  position: absolute; 
  top: 0; 
  right: 0; 
  bottom: 0; 
  left: 0; 
  background: rgba(26, 26, 46, 0.98); 
  z-index: 100; 
  text-align: center;
  border-radius: 6px;
  animation: fadeInBlurred 500ms ease-in-out;
}


.game-message p { 
  font-size: 48px; 
  font-weight: bold; 
  height: 60px; 
  line-height: 60px; 
  margin-top: 40%; 
  color: #ffa500;
  animation: pulseTitle 2s ease-in-out infinite;
  text-shadow: 0 0 20px rgba(255, 165, 0, 0.8), 0 0 40px rgba(255, 165, 0, 0.4);
}

@keyframes pulseTitle {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); text-shadow: 0 0 30px rgba(255, 165, 0, 1), 0 0 60px rgba(255, 165, 0, 0.6); }
}

.game-message .lower { margin-top: 40px; }

.game-message a { 
  display: inline-block; 
  background: #f7931a; 
  border-radius: 6px; 
  padding: 0 20px; 
  color: #1a1a1a; 
  height: 40px; 
  line-height: 42px; 
  margin-left: 9px; 
  text-decoration: none; 
  font-weight: bold;
}

.game-message.game-won { 
  background: rgba(251, 191, 36, 0.95);
}

.game-message.game-won p {
  color: #1a1a1a;
}

.game-message.game-won .keep-playing-button { display: inline-block; }

.score-addition {
  position: absolute;
  right: 20px;
  font-size: 16px;
  color: #f7931a;
  animation: scoreUp 600ms ease-in-out forwards;
  font-weight: bold;
}

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

/* Mobile responsive adjustments */
@media screen and (max-width: 520px) {
  body { margin: 10px 0; }
  h1.title { font-size: 36px; }
  .container { padding: 0 8px; }
  .game-container {
    max-width: 350px;
    height: 350px;
    padding: 8px;
  }
  .grid-container { top: 8px; left: 8px; right: 8px; bottom: 8px; }
  .grid-row { margin-bottom: 2.5%; height: 23.125%; }
  .grid-cell {
    width: 23.125%;
    height: 100%;
    margin-right: 2.5%;
  }
  .tile-container { top: 8px; left: 8px; right: 8px; bottom: 8px; }
  .tile, .tile .tile-inner {
    width: 73px;
    height: 73px;
    line-height: 73px;
  }
  .score-container, .best-container { 
    padding: 6px 12px; 
    font-size: 14px; 
    height: 30px;
    line-height: 30px;
  }
  .score-container:after, .best-container:after { font-size: 8px; }
  .tile-128 .tile-inner, .tile-256 .tile-inner, .tile-512 .tile-inner { font-size: 28px; }
  .tile-1024 .tile-inner, .tile-2048 .tile-inner { font-size: 22px; }
  /* Responsive tile positions for 350px container */
  .tile.tile-position-1-1 { transform: translate(0px, 0px); }
  .tile.tile-position-1-2 { transform: translate(0px, 83px); }
  .tile.tile-position-1-3 { transform: translate(0px, 166px); }
  .tile.tile-position-1-4 { transform: translate(0px, 249px); }
  .tile.tile-position-2-1 { transform: translate(83px, 0px); }
  .tile.tile-position-2-2 { transform: translate(83px, 83px); }
  .tile.tile-position-2-3 { transform: translate(83px, 166px); }
  .tile.tile-position-2-4 { transform: translate(83px, 249px); }
  .tile.tile-position-3-1 { transform: translate(166px, 0px); }
  .tile.tile-position-3-2 { transform: translate(166px, 83px); }
  .tile.tile-position-3-3 { transform: translate(166px, 166px); }
  .tile.tile-position-3-4 { transform: translate(166px, 249px); }
  .tile.tile-position-4-1 { transform: translate(249px, 0px); }
  .tile.tile-position-4-2 { transform: translate(249px, 83px); }
  .tile.tile-position-4-3 { transform: translate(249px, 166px); }
  .tile.tile-position-4-4 { transform: translate(249px, 249px); }
}

@media screen and (max-width: 380px) {
  h1.title { font-size: 32px; }
  .game-container {
    max-width: 300px;
    height: 300px;
    padding: 6px;
  }
  .grid-container { top: 6px; left: 6px; right: 6px; bottom: 6px; }
  .grid-row { margin-bottom: 2.7%; height: 22.975%; }
  .grid-cell {
    width: 22.975%;
    height: 100%;
    margin-right: 2.7%;
  }
  .tile-container { top: 6px; left: 6px; right: 6px; bottom: 6px; }
  .tile, .tile .tile-inner {
    width: 62px;
    height: 62px;
    line-height: 62px;
  }
  .tile-128 .tile-inner, .tile-256 .tile-inner, .tile-512 .tile-inner { font-size: 24px; }
  .tile-1024 .tile-inner, .tile-2048 .tile-inner { font-size: 18px; }
  .game-message p { font-size: 36px; }
  /* Responsive tile positions for 300px container */
  .tile.tile-position-1-1 { transform: translate(0px, 0px); }
  .tile.tile-position-1-2 { transform: translate(0px, 71px); }
  .tile.tile-position-1-3 { transform: translate(0px, 142px); }
  .tile.tile-position-1-4 { transform: translate(0px, 213px); }
  .tile.tile-position-2-1 { transform: translate(71px, 0px); }
  .tile.tile-position-2-2 { transform: translate(71px, 71px); }
  .tile.tile-position-2-3 { transform: translate(71px, 142px); }
  .tile.tile-position-2-4 { transform: translate(71px, 213px); }
  .tile.tile-position-3-1 { transform: translate(142px, 0px); }
  .tile.tile-position-3-2 { transform: translate(142px, 71px); }
  .tile.tile-position-3-3 { transform: translate(142px, 142px); }
  .tile.tile-position-3-4 { transform: translate(142px, 213px); }
  .tile.tile-position-4-1 { transform: translate(213px, 0px); }
  .tile.tile-position-4-2 { transform: translate(213px, 71px); }
  .tile.tile-position-4-3 { transform: translate(213px, 142px); }
  .tile.tile-position-4-4 { transform: translate(213px, 213px); }
}

@media screen and (max-width: 320px) {
  h1.title { font-size: 28px; }
  .game-container {
    max-width: 280px;
    height: 280px;
    padding: 5px;
  }
  .grid-container { top: 5px; left: 5px; right: 5px; bottom: 5px; }
  .tile, .tile .tile-inner {
    width: 58px;
    height: 58px;
    line-height: 58px;
  }
  .tile-128 .tile-inner, .tile-256 .tile-inner, .tile-512 .tile-inner { font-size: 22px; }
  .tile-1024 .tile-inner, .tile-2048 .tile-inner { font-size: 16px; }
  .game-message p { font-size: 28px; }
  /* Responsive tile positions for 280px container */
  .tile.tile-position-1-1 { transform: translate(0px, 0px); }
  .tile.tile-position-1-2 { transform: translate(0px, 66px); }
  .tile.tile-position-1-3 { transform: translate(0px, 132px); }
  .tile.tile-position-1-4 { transform: translate(0px, 198px); }
  .tile.tile-position-2-1 { transform: translate(66px, 0px); }
  .tile.tile-position-2-2 { transform: translate(66px, 66px); }
  .tile.tile-position-2-3 { transform: translate(66px, 132px); }
  .tile.tile-position-2-4 { transform: translate(66px, 198px); }
  .tile.tile-position-3-1 { transform: translate(132px, 0px); }
  .tile.tile-position-3-2 { transform: translate(132px, 66px); }
  .tile.tile-position-3-3 { transform: translate(132px, 132px); }
  .tile.tile-position-3-4 { transform: translate(132px, 198px); }
  .tile.tile-position-4-1 { transform: translate(198px, 0px); }
  .tile.tile-position-4-2 { transform: translate(198px, 66px); }
  .tile.tile-position-4-3 { transform: translate(198px, 132px); }
  .tile.tile-position-4-4 { transform: translate(198px, 198px); }
}

/* Particle animation for celebrations */
@keyframes particleFloat {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-100px) scale(0) rotate(360deg);
  }
}

/* Enhanced Game Over Popup */
.game-message { 
  backdrop-filter: blur(5px);
  animation: fadeInGame 500ms ease-out;
}

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

/* Enhanced Game Message Text */
.game-message p { 
  letter-spacing: 2px;
  font-weight: 900;
}

/* Game Over visibility */
.game-message.game-over,
.game-message.game-won { 
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.game-message.game-over {
  background: rgba(220, 38, 38, 0.95);
}

.game-message.game-over p {
  color: #fff;
}

/* Auto-hide Game Over overlay after animation */
.game-message.show-final-active {
  background: transparent !important;
  pointer-events: none !important;
  opacity: 0 !important;
  transition: background 1s ease, opacity 1s ease;
}

.game-message.show-final-active p,
.game-message.show-final-active .lower {
  opacity: 0 !important;
  visibility: hidden !important;
  transition: opacity 1s ease, visibility 1s ease;
}

/* New Game Button - Smaller size (~66%) */
.restart-button {
  display: inline-block;
  background: linear-gradient(145deg, #f7931a, #ea580c);
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  padding: 8px 16px;
  color: #fff;
  font-weight: bold;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(247, 147, 26, 0.5), 0 0 15px rgba(247, 147, 26, 0.3);
  transition: all 200ms ease;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.restart-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(247, 147, 26, 0.6), 0 0 25px rgba(247, 147, 26, 0.4);
}

.restart-button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(247, 147, 26, 0.4);
}

/* Button group layout */
.button-group { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Reset High Score Button */
.reset-score-button {
  display: inline-block;
  background: linear-gradient(145deg, #6b7280, #4b5563);
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  padding: 8px 16px;
  color: #fff;
  font-weight: bold;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(107, 114, 128, 0.4);
  transition: all 200ms ease;
}

.reset-score-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(107, 114, 128, 0.6);
}

/* Theme Toggle Button */
.theme-toggle {
  display: inline-block;
  background: linear-gradient(145deg, #8b5cf6, #7c3aed);
  border: 2px solid #1a1a1a;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  text-align: center;
  line-height: 36px;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.4);
  transition: all 200ms ease;
  user-select: none;
}

.theme-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.6);
}

/* Tutorial Button */
.tutorial-button {
  display: inline-block;
  background: linear-gradient(145deg, #10b981, #059669);
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  padding: 8px 14px;
  color: #fff;
  font-weight: bold;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(16, 185, 129, 0.4), 0 0 15px rgba(16, 185, 129, 0.2);
  transition: all 200ms ease;
}

.tutorial-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(16, 185, 129, 0.5), 0 0 25px rgba(16, 185, 129, 0.3);
}

.tutorial-button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

/* Undo Button */
.undo-button {
  display: inline-block;
  background: linear-gradient(145deg, #3b82f6, #2563eb);
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  padding: 8px 16px;
  color: #fff;
  font-weight: bold;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
  transition: all 200ms ease;
}

.undo-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.6);
}

.undo-button.used {
  background: linear-gradient(145deg, #6b7280, #4b5563);
  opacity: 0.5;
  pointer-events: none;
}

/* Stats Button */
.stats-button {
  display: inline-block;
  background: linear-gradient(145deg, #10b981, #059669);
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  padding: 8px 16px;
  color: #fff;
  font-weight: bold;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
  transition: all 200ms ease;
}

.stats-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.6);
}

/* Statistics Panel */
.stats-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.98), rgba(15, 23, 42, 0.98));
  border: 2px solid #f7931a;
  border-radius: 12px;
  padding: 30px;
  z-index: 3000;
  min-width: 280px;
  box-shadow: 0 0 50px rgba(247, 147, 26, 0.5);
}

.stats-panel h3 {
  margin: 0 0 20px 0;
  color: #f7931a;
  font-size: 24px;
  text-align: center;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(247, 147, 26, 0.2);
  color: #c9d1d9;
}

.stat-row:last-of-type {
  border-bottom: none;
}

.stats-close-x {
  position: absolute;
  top: 10px;
  right: 15px;
  background: transparent;
  border: none;
  color: #f7931a;
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}

.stats-close-x:hover {
  color: #fff;
  transform: scale(1.2);
}

.close-stats {
  display: block;
  margin-top: 20px;
  text-align: center;
  background: #f7931a;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  color: #1a1a1a;
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
}

.close-stats:hover {
  background: #ffb347;
}

/* Confetti animation */
.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  z-index: 4000;
  animation: confettiFall 3s ease-out forwards;
}

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

/* Floating score animation */
.floating-score {
  position: absolute;
  font-weight: bold;
  font-size: 24px;
  color: #ffd700;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
  pointer-events: none;
  animation: floatUp 1s ease-out forwards;
  z-index: 100;
}

@keyframes floatUp {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-50px) scale(1.5); opacity: 0; }
}

/* Merge sparkle effect */
.sparkle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: white;
  border-radius: 50%;
  pointer-events: none;
  animation: sparkle 0.6s ease-out forwards;
}

@keyframes sparkle {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(3); opacity: 0; }
}

/* Light theme */
body.light-theme {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 50%, #d1d5db 100%);
  color: #1f2937;
}

body.light-theme .game-container {
  background: #ffffff;
  border-color: #d1d5db;
}

body.light-theme .grid-cell {
  background: rgba(209, 213, 219, 0.5);
}

body.light-theme .score-container,
body.light-theme .best-container {
  background: #ffffff;
  border-color: #f7931a;
  color: #f7931a;
}

/* ===========================
   HIGH SCORE MODAL
   =========================== */
.high-score-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 5000;
  opacity: 0;
  animation: modalFadeIn 0.3s ease forwards;
}

@keyframes modalFadeIn {
  to { opacity: 1; }
}

.high-score-modal {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  border: 2px solid #f7931a;
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 0 40px rgba(247, 147, 26, 0.5);
  animation: modalSlideIn 0.4s ease forwards;
}

@keyframes modalSlideIn {
  from { transform: translateY(-50px) scale(0.9); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.high-score-modal h2 {
  color: #f7931a;
  font-size: 28px;
  margin-bottom: 10px;
  text-shadow: 0 0 10px rgba(247, 147, 26, 0.5);
}

.high-score-modal .score-display {
  color: #ffd700;
  font-size: 48px;
  font-weight: bold;
  margin: 20px 0;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
}

.high-score-modal p {
  color: #8b949e;
  margin-bottom: 20px;
}

.high-score-modal input {
  width: 100%;
  padding: 12px;
  font-size: 18px;
  border: 2px solid #30363d;
  border-radius: 8px;
  background: #0d1117;
  color: #f7931a;
  margin-bottom: 20px;
  text-align: center;
  box-sizing: border-box;
}

.high-score-modal input:focus {
  outline: none;
  border-color: #f7931a;
  box-shadow: 0 0 10px rgba(247, 147, 26, 0.3);
}

.high-score-modal button {
  background: linear-gradient(135deg, #f7931a 0%, #ffd700 100%);
  color: #0d1117;
  border: none;
  padding: 15px 40px;
  font-size: 18px;
  font-weight: bold;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}

.high-score-modal button:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(247, 147, 26, 0.5);
}

.high-score-modal button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: scale(1);
}

/* Leaderboard Button */
.leaderboard-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  filter: drop-shadow(0 0 6px rgba(247,147,26,0.4));
  transition: transform 0.15s;
}

.leaderboard-btn:hover {
  transform: scale(1.2);
  filter: drop-shadow(0 0 12px rgba(247,147,26,0.7));
}

/* Leaderboard Dropdown */
.leaderboard-dropdown {
  position: relative;
  display: inline-block;
}

.leaderboard-dropdown-content {
  display: none;
  position: absolute;
  background: #1a1a2e;
  min-width: 300px;
  border: 2px solid #f7931a;
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  z-index: 1000;
  padding: 15px;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 10px;
}

.leaderboard-dropdown-content.show {
  display: block;
  animation: dropdownSlide 0.3s ease;
}

@keyframes dropdownSlide {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.leaderboard-dropdown-content h3 {
  color: #f7931a;
  margin: 0 0 15px 0;
  text-align: center;
  font-size: 20px;
}

.leaderboard-entry {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  border-bottom: 1px solid #30363d;
  color: #c9d1d9;
}

.leaderboard-entry:last-child {
  border-bottom: none;
}

.leaderboard-entry.rank-1 {
  background: linear-gradient(90deg, rgba(255,215,0,0.2) 0%, transparent 100%);
  color: #ffd700;
}

.leaderboard-entry.rank-2 {
  background: linear-gradient(90deg, rgba(192,192,192,0.2) 0%, transparent 100%);
  color: #c0c0c0;
}

.leaderboard-entry.rank-3 {
  background: linear-gradient(90deg, rgba(205,127,50,0.2) 0%, transparent 100%);
  color: #cd7f32;
}

.leaderboard-entry .rank {
  font-weight: bold;
  min-width: 30px;
}

.leaderboard-entry .name {
  flex: 1;
  text-align: left;
  padding-left: 10px;
}

.leaderboard-entry .score {
  font-weight: bold;
  color: #f7931a;
}

.leaderboard-loading {
  text-align: center;
  color: #8b949e;
  padding: 20px;
}

.leaderboard-empty {
  text-align: center;
  color: #8b949e;
  padding: 20px;
}
