body {
  font-family: 'Segoe UI', sans-serif;
  background: linear-gradient(to bottom, #fefcea, #f1da36);
  text-align: center;
  padding: 1rem;
  margin: 0;
}

h1 {
  color: #333;
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

/* GRID BASE */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  padding: 1rem;
  max-width: 600px;
  margin: auto;
}

.card {
  perspective: 1000px;
}

.card-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 3/2;
  transform-style: preserve-3d;
  transition: transform 0.8s;
  cursor: pointer;
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-front, .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  backface-visibility: hidden;
  box-shadow: 0 6px 12px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1rem;
}

.card-front {
  background: #bbb;
  color: #333;
}

.card-back {
  background-size: cover;
  background-position: center;
  transform: rotateY(180deg);
  color: #fff;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}

/* 📱 OPTIMIZACIÓN PARA MÓVIL */
@media (max-width: 480px) {

  h1 {
    font-size: 1.2rem;
    padding: 0 0.5rem;
  }

  .grid {
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 0.8rem;
  }

  .card-inner {
    aspect-ratio: 4/3; /* Más alto para móvil */
  }

  .card-front,
  .card-back {
    font-size: 0.9rem;
    border-radius: 10px;
  }
}

/* 📱 MÓVIL MUY PEQUEÑO (iPhone SE, Android mini) */
@media (max-width: 360px) {

  h1 {
    font-size: 1rem;
  }

  .grid {
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 0.6rem;
  }

  .card-inner {
    aspect-ratio: 1/1; /* Cuadradas si la pantalla es muy pequeña */
  }

  .card-front,
  .card-back {
    font-size: 0.8rem;
  }
}