* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  background: #0b1220;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: -webkit-fill-available;
  min-height: 100vh;
  font-family: 'Inter', 'Arial', sans-serif;
  padding: clamp(15px, 4vw, 30px);
  gap: 20px;
}

h1 {
  color: #c69214;
  font-size: clamp(1.3rem, 5vw, 1.8rem);
  margin: 0 0 10px 0;
  text-align: center;
}

.instructions {
  color: #94a3b8;
  font-size: clamp(0.85rem, 3vw, 1rem);
  text-align: center;
  max-width: 400px;
  line-height: 1.5;
}

#level-display {
  color: #cbd5e1;
  font-size: clamp(1rem, 4vw, 1.2rem);
  font-weight: bold;
}

#grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(6px, 2vw, 10px);
  width: min(90vw, 330px);
  touch-action: manipulation;
}

.cell {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #334155;
  border-radius: clamp(6px, 2vw, 10px);
  transition: background 0.15s, box-shadow 0.15s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cell.active {
  background: #3b82f6;
  box-shadow: 0 0 25px rgba(59, 130, 246, 0.6);
}

.cell.correct {
  background: #22c55e;
  box-shadow: 0 0 25px rgba(34, 197, 94, 0.6);
}

.cell.wrong {
  background: #ef4444;
  box-shadow: 0 0 25px rgba(239, 68, 68, 0.6);
}

#controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  width: 100%;
  max-width: 300px;
}

button {
  padding: clamp(12px, 4vw, 18px) clamp(25px, 8vw, 40px);
  font-size: clamp(1rem, 4vw, 1.3rem);
  background: #22c55e;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: white;
  font-weight: bold;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, background 0.15s;
  width: 100%;
  max-width: 250px;
}

button:active {
  transform: scale(0.97);
  background: #16a34a;
}

#matchBtn {
  width: 100%;
  max-width: 250px;
  min-height: clamp(60px, 15vw, 80px);
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  background: #c69214;
  color: #062a4d;
}

#matchBtn:active {
  background: #a57b0f;
}

#matchBtn[style*="none"] {
  display: none !important;
}

#score {
  color: #22c55e;
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  font-weight: bold;
}

#message {
  color: #fbbf24;
  font-size: clamp(0.9rem, 3.5vw, 1.1rem);
  text-align: center;
  min-height: 24px;
}

/* Mobile */
@media (max-width: 400px) {
  body { padding: 15px; gap: 15px; }
  #grid { gap: 5px; width: 85vw; }
  .cell { border-radius: 6px; }
  button { padding: 12px 20px; }
  #matchBtn { min-height: 55px; }
}

@media (max-width: 320px) {
  #grid { width: 280px; }
  .cell { border-radius: 5px; }
}

/* Landscape */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    padding: 10px;
  }
  h1 { width: 100%; margin-bottom: 5px; font-size: 1.2rem; }
  .instructions { display: none; }
  #grid {
    width: min(45vh, 250px);
    gap: 5px;
  }
  #controls {
    gap: 10px;
    width: auto;
  }
  button { padding: 10px 20px; font-size: 1rem; }
  #matchBtn { min-height: 50px; font-size: 1.2rem; }
}
