* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #244680, #0c173c 70%);
  color: #f8fbff;
  font-family: Nunito, system-ui, sans-serif;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #ffda69;
  outline-offset: 3px;
}

.intro {
  min-height: 100svh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1rem;
  padding: 1.25rem;
  text-align: center;
}

.intro h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 4.5rem);
  font-weight: 900;
  line-height: 1.05;
}

.game-header p {
  margin: 0;
  color: #d4e1f8;
}

.action-button {
  border: 0;
  border-radius: 0.75rem;
  background: #ffda69;
  color: #172447;
  cursor: pointer;
  font-weight: 900;
  padding: 0.75rem 1.5rem;
}

.action-button:hover {
  background: #ffe69b;
}

.menu-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.menu-link {
  border: 0;
  padding: 0 0.25rem;
  background: transparent;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.game {
  max-width: 68rem;
  margin: 0 auto;
  padding: 1rem 0.75rem 2rem;
}

.game-header {
  text-align: center;
  margin-bottom: 1rem;
}

.game-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.5rem, 5vw, 2.75rem);
  line-height: 1.1;
}

.game-info {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  margin-top: 0.75rem;
}

.game-info strong {
  color: #ffda69;
}

.game-container {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: clamp(0.35rem, 1.2vw, 0.75rem);
}

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 6;
  padding: 0;
  border: 0;
  border-radius: 0.65rem;
  background: transparent;
  cursor: pointer;
  perspective: 500px;
}

.card.matched {
  cursor: default;
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid #8eb2e6;
  overflow: hidden;
  backface-visibility: hidden;
  transition: transform 300ms ease-in-out;
}

.card-back {
  display: grid;
  place-items: center;
  background: #16295b;
}

.card-back img {
  width: 52%;
  height: auto;
}

.card:not(.visible):hover .card-back {
  background: #21417b;
}

.card-front {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  align-items: center;
  padding: 0.28rem 0.15rem;
  background: #e8f3ff;
  color: #122653;
  transform: rotateY(180deg);
}

.card.visible .card-back {
  transform: rotateY(-180deg);
}

.card.visible .card-front {
  transform: rotateY(0);
}

.card.matched .card-front {
  background: #e0f8e9;
  border-color: #56b882;
}

.card.selected .card-front {
  background: #fff0b8;
  box-shadow: inset 0 0 0 3px #a77008;
}

.card.incorrect .card-front {
  background: #ffe0df;
  box-shadow: inset 0 0 0 3px #b74242;
}

.card-letter {
  font-size: clamp(1.35rem, 4vw, 2.15rem);
  font-weight: 900;
  line-height: 1;
}

.card-value {
  display: block;
  width: 100%;
  max-width: 5rem;
  max-height: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.card-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(0.56rem, 1.7vw, 0.85rem);
  font-weight: 700;
  line-height: 1;
}

.victory {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: #080e26d9;
}

.victory-panel {
  border: 1px solid #8eb2e6;
  border-radius: 1rem;
  background: #16295b;
  padding: 2rem;
  text-align: center;
}

.victory-panel h2 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.5rem, 5vw, 2.5rem);
}

.victory-panel .menu-actions {
  margin-top: 1.25rem;
}

@media (max-width: 850px) {
  .game-container {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .game-container {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (orientation: landscape) and (min-width: 720px) and (max-width: 1400px) {
  .game {
    max-width: 82rem;
    padding: 0.5rem 0.75rem;
  }

  .game-header {
    margin-bottom: 0.65rem;
  }

  .game-header h1 {
    font-size: clamp(1.25rem, 3vw, 2rem);
  }

  .game-info {
    margin-top: 0.35rem;
  }

  .game-container {
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: clamp(0.25rem, 0.65vw, 0.55rem);
  }

  .card {
    aspect-ratio: 10 / 11;
  }

  .card-letter {
    font-size: clamp(1.3rem, 2.5vw, 2.2rem);
  }

  .card-name {
    font-size: clamp(0.57rem, 1.05vw, 0.87rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-face {
    transition: none;
  }
}
