* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

body {
  font-family: 'Press Start 2P', cursive;
  background: #8b956d;
  background-image: 
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.05) 2px, rgba(0,0,0,0.05) 4px),
    repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0,0,0,0.05) 2px, rgba(0,0,0,0.05) 4px);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.game-container {
  background: #f4e8c1;
  border: 8px solid #5a4a3a;
  border-radius: 0;
  padding: 24px;
  box-shadow: 
    8px 8px 0 rgba(0, 0, 0, 0.3),
    inset 4px 4px 0 rgba(255, 255, 255, 0.3),
    inset -4px -4px 0 rgba(0, 0, 0, 0.2);
  max-width: 600px;
  width: 100%;
  position: relative;
}

.game-container::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 4px solid #3a2a1a;
  pointer-events: none;
}

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

h1 {
  color: #3a2a1a;
  font-size: 1.2em;
  margin-bottom: 20px;
  text-shadow: 
    3px 3px 0 #8b7355,
    -1px -1px 0 #fff;
  letter-spacing: 2px;
  line-height: 1.6;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 0.6em;
}

.stat-box {
  background: #6b8e23;
  border: 4px solid #4a5f1a;
  padding: 12px 16px;
  box-shadow: 
    4px 4px 0 rgba(0, 0, 0, 0.3),
    inset 2px 2px 0 rgba(255, 255, 255, 0.2),
    inset -2px -2px 0 rgba(0, 0, 0, 0.2);
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-box .label {
  color: #fff;
  text-transform: uppercase;
  font-weight: normal;
}

.stat-box .value {
  color: #ffeb3b;
  font-size: 1.4em;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  background: #3a2a1a;
  padding: 8px;
  border: 6px solid #5a4a3a;
  box-shadow: 
    inset 4px 4px 0 rgba(0, 0, 0, 0.5),
    inset -2px -2px 0 rgba(255, 255, 255, 0.1);
  margin-bottom: 20px;
}

.cell {
  aspect-ratio: 1;
  background: #8b7355;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: none;
  border: 3px solid #6b5a45;
  box-shadow: 
    inset 2px 2px 0 rgba(255, 255, 255, 0.3),
    inset -2px -2px 0 rgba(0, 0, 0, 0.3);
  user-select: none;
  padding: 6px;
  position: relative;
  overflow: visible;
}

.cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.cell:hover {
  background: #9b8365;
  border-color: #7b6a55;
}

.cell:active {
  box-shadow: 
    inset 3px 3px 0 rgba(0, 0, 0, 0.5),
    inset -1px -1px 0 rgba(255, 255, 255, 0.2);
}

.cell.selected {
  background: #ffeb3b;
  border-color: #fbc02d;
  box-shadow: 
    0 0 0 3px #fff,
    0 0 0 6px #fbc02d,
    inset 2px 2px 0 rgba(255, 255, 255, 0.5);
  animation: pixelPulse 0.5s infinite;
}

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

.cell.matching {
  animation: pixelMatch 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  z-index: 10;
}

@keyframes pixelMatch {
  0% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
    filter: brightness(1);
  }
  15% {
    transform: scale(1.4) rotate(0deg);
    opacity: 1;
    filter: brightness(1.5) saturate(1.5);
  }
  30% {
    transform: scale(1.5) rotate(10deg);
    opacity: 1;
    filter: brightness(1.8) saturate(2);
  }
  45% {
    transform: scale(1.6) rotate(-10deg);
    opacity: 0.9;
    filter: brightness(2) saturate(2.5);
  }
  60% {
    transform: scale(1.3) rotate(5deg);
    opacity: 0.7;
    filter: brightness(1.5) saturate(2);
  }
  75% {
    transform: scale(0.8) rotate(-5deg);
    opacity: 0.4;
    filter: brightness(1) saturate(1);
  }
  90% {
    transform: scale(0.3) rotate(0deg);
    opacity: 0.2;
    filter: brightness(0.5);
  }
  100% {
    transform: scale(0) rotate(0deg);
    opacity: 0;
    filter: brightness(0);
  }
}

.cell.matching::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 120%;
  height: 120%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255, 235, 59, 0.6) 0%, rgba(255, 193, 7, 0.4) 30%, transparent 70%);
  animation: sparkle 0.8s ease-out;
  pointer-events: none;
  z-index: -1;
}

@keyframes sparkle {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(2);
    opacity: 0;
  }
}

.cell.matching::after {
  content: '★';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2em;
  color: #ffeb3b;
  text-shadow: 
    0 0 10px rgba(255, 235, 59, 0.8),
    0 0 20px rgba(255, 193, 7, 0.6);
  animation: starBurst 0.8s ease-out;
  pointer-events: none;
}

@keyframes starBurst {
  0% {
    transform: translate(-50%, -50%) scale(0) rotate(0deg);
    opacity: 0;
  }
  40% {
    transform: translate(-50%, -50%) scale(1.5) rotate(180deg);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(0.5) rotate(360deg);
    opacity: 0;
  }
}

.cell.falling {
  animation: pixelFall 0.4s ease;
}

@keyframes pixelFall {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.controls {
  text-align: center;
}

.btn {
  background: #6b8e23;
  color: #fff;
  border: 4px solid #4a5f1a;
  padding: 14px 32px;
  font-size: 0.7em;
  font-family: 'Press Start 2P', cursive;
  cursor: pointer;
  transition: none;
  box-shadow: 
    4px 4px 0 rgba(0, 0, 0, 0.3),
    inset 2px 2px 0 rgba(255, 255, 255, 0.2),
    inset -2px -2px 0 rgba(0, 0, 0, 0.2);
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
}

.btn:hover {
  background: #7ba428;
  border-color: #5a6f2a;
}

.btn:active {
  box-shadow: 
    2px 2px 0 rgba(0, 0, 0, 0.3),
    inset 3px 3px 0 rgba(0, 0, 0, 0.3);
  transform: translate(2px, 2px);
}

.game-over {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  background-image: 
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.03) 2px, rgba(255,255,255,0.03) 4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.game-over.hidden {
  display: none;
}

.game-over-content {
  background: #f4e8c1;
  border: 8px solid #5a4a3a;
  padding: 32px;
  text-align: center;
  box-shadow: 
    8px 8px 0 rgba(0, 0, 0, 0.5),
    inset 4px 4px 0 rgba(255, 255, 255, 0.3),
    inset -4px -4px 0 rgba(0, 0, 0, 0.2);
  animation: pixelSlideIn 0.4s steps(8);
  position: relative;
  max-width: 400px;
}

.game-over-content::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 4px solid #3a2a1a;
  pointer-events: none;
}

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

.game-over-content h2 {
  color: #3a2a1a;
  font-size: 1.4em;
  margin-bottom: 24px;
  text-shadow: 
    3px 3px 0 #8b7355,
    -1px -1px 0 #fff;
  line-height: 1.6;
}

.game-over-content .final-label {
  font-size: 0.7em;
  color: #5a4a3a;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.game-over-content .final-score-value {
  font-size: 2em;
  color: #6b8e23;
  margin-bottom: 28px;
  text-shadow: 
    3px 3px 0 rgba(0, 0, 0, 0.3),
    -1px -1px 0 rgba(255, 255, 255, 0.5);
}

@media (max-width: 600px) {
  .game-container {
    padding: 16px;
    border-width: 6px;
  }
  
  h1 {
    font-size: 0.9em;
    line-height: 1.8;
  }
  
  .stats {
    gap: 12px;
    font-size: 0.5em;
  }
  
  .stat-box {
    min-width: 110px;
    padding: 10px 12px;
  }
  
  .cell {
    padding: 4px;
    border-width: 2px;
  }
  
  .btn {
    font-size: 0.6em;
    padding: 12px 24px;
  }
  
  .game-over-content h2 {
    font-size: 1.1em;
  }
  
  .game-over-content .final-score-value {
    font-size: 1.6em;
  }
}

@media (max-width: 400px) {
  h1 {
    font-size: 0.7em;
  }
  
  .stats {
    font-size: 0.45em;
  }
  
  .stat-box {
    min-width: 90px;
  }
}
