h1 {
  margin: 40px auto 30px;
  font-weight: 700;
  font-size: 22px;
  color: #fff;
  text-align: center;
}

.container {
  background: #394555;
  padding: 25px;
  margin: 40px auto;
  border-radius: 10px;
  width: calc(100% - 30px);
  max-width: 480px;
  box-shadow: 0 0 15px rgba(0,0,0,.3);
  border: 1px solid #3a3a5e;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 15px;
}

.controls select {
  flex: 1;
  min-width: 120px;
}

select {
  padding: 10px;
  font-size: 16px;
  border: none;
  border-radius: 5px;
}

button {
  width: 100%;
  padding: 12px;
  font-size: 17px;
  border: none;
  border-radius: 5px;
  background-color: #4caf50;
  color: #fff;
  cursor: pointer;
  margin-top: 10px;
}

button:hover {
  background-color: #45a049;
}

.controls button {
  flex: 1;
  width: auto;
  min-width: 120px;
  margin-top: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 15px;
}

.stat-item {
  background: #2d3a4a;
  padding: 10px 6px;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
}

#message {
  min-height: 30px;
  margin-bottom: 15px;
  font-weight: 700;
  color: #2ecc71;
  text-align: center;
}

#gameBoard {
  display: grid;
  gap: 10px;
}

#gameBoard.board-cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

#gameBoard.board-cols-6 {
  grid-template-columns: repeat(6, 1fr);
}

.card {
  position: relative;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform .5s ease;
}

.card.flipped,
.card.matched {
  transform: rotateY(180deg);
}

.card-back,
.card-front {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: clamp(1.6rem, 8vw, 2.6rem);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  user-select: none;
}

.card-back {
  background: #2d3a4a;
  border: 2px solid #4a5a70;
  transition: background .2s ease;
}

.card:hover .card-back {
  background: #364659;
}

.card-front {
  background: #f5f1eb;
  transform: rotateY(180deg);
}

.card.matched .card-front {
  background: #a5d6a7;
}

@media (max-width: 400px) {
  .container {
    padding: 15px;
  }

  #gameBoard {
    gap: 6px;
  }
}
