body {
  font-family: Arial, sans-serif;
  text-align: center;
  background-color: #fff8f5;
  color: #333;
  padding: 10px;
  margin: 0;
}

h1 {
  margin-top: 15px;
  font-size: clamp(20px, 4vw, 32px);
}

.scoreboard {
  margin: 15px auto;
  font-size: clamp(16px, 3vw, 22px);
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

#game-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  justify-content: center;
  margin: 20px auto;
  max-width: 460px;
  width: 100%; /* Ensures board takes full available width up to 460px */
}

#game-board.locked {
  pointer-events: none;
}

.card {
  width: 100%;
  aspect-ratio: 1 / 1;
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: clamp(24px, 6vw, 40px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s, background-color 0.3s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.card.flipped,
.card.matched {
  transform: rotateY(180deg);
  background-color: #ffefdb;
}

.card.matched {
  opacity: 0.6;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.25);
  text-align: left;
}

.modal h2 {
  margin: 0 0 6px;
  font-size: clamp(18px, 4vw, 24px);
}

.modal p {
  margin: 6px 0;
}

.leaderboard-form {
  margin-top: 12px;
}

.leaderboard-form.hidden {
  display: none;
}

.leaderboard-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

.leaderboard-form-row {
  display: flex;
  gap: 8px;
}

.leaderboard-form-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.18);
  font-size: 16px;
}

.leaderboard-form-row button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #ffefdb;
  cursor: pointer;
  font-weight: 600;
}

.hint {
  font-size: 13px;
  color: rgba(0,0,0,0.65);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 14px;
}

.modal-actions button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}

.modal-actions button.secondary {
  opacity: 0.85;
}

/* Mobile-specific adjustments */
@media (max-width: 500px) {
  #game-board {
    max-width: 390px; /* explicitly limit width for mobile */
    gap: 8px;
  }

  .scoreboard {
    flex-direction: column;
    gap: 8px;
  }
}
