* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  padding: 20px 0;
  display: flex;
  background: #363439;
}

.game {
  width: min(800px, calc(100vw - 32px));
  margin: auto;
}

.memory-game {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  display: flex;
  flex-wrap: wrap;
  perspective: 1000px;
}

.game-status {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
  color: #FFF;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 36px;
  line-height: 1;
}

.stat {
  min-width: 1.5ch;
  color: inherit;
  font: inherit;
  text-align: center;
}

.new-game {
  padding: 8px 2px;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.new-game:hover {
  opacity: .75;
}

.new-game:focus-visible {
  outline: 2px solid #FFF;
  outline-offset: 4px;
}

.memory-card {
  width: calc(25% - 10px);
  height: auto;
  aspect-ratio: 1;
  margin: 5px;
  position: relative;
  transform: scale(1);
  transform-style: preserve-3d;
  transition: transform .5s;
  box-shadow: 1px 1px 1px rgba(0,0,0,.3);
}

.memory-card:not(.flip) {
  cursor: pointer;
}

.memory-card:active {
  transform: scale(0.97);
  transition: transform .2s;
}

.memory-card.flip {
  transform: rotateY(180deg);
}

.memory-card.shuffle {
  animation: shuffle-card .42s ease-in-out;
}

.memory-card.celebrate {
  animation: celebrate-card .42s ease-in-out;
}

@keyframes shuffle-card {
  40% {
    transform: translate(var(--shuffle-x), var(--shuffle-y)) rotate(var(--shuffle-rotation));
  }
}

@keyframes celebrate-card {
  40% {
    transform: rotateY(180deg) translate(var(--shuffle-x), var(--shuffle-y)) rotateZ(var(--shuffle-rotation));
  }
}

@media (prefers-reduced-motion: reduce) {
  .memory-card.shuffle,
  .memory-card.celebrate {
    animation: none;
  }
}

.front-face,
.back-face {
  inset: 0;
  width: 100%;
  height: 100%;
  padding: clamp(8px, 2.5vw, 20px);
  position: absolute;
  border-radius: 5px;
  background: #FFF;
  object-fit: contain;
  backface-visibility: hidden;
}

.front-face {
  transform: rotateY(180deg);
}
