@import url("https://fonts.googleapis.com/css2?family=Luckiest+Guy&family=Nunito:wght@400;500;600;700&display=swap");

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

html {
  font-size: 16px;
}

body {
  min-height: 100vh;
  display: flex;
  background: radial-gradient(circle, #fff5e8 0%, #fcf0d8 100%);
  color: #4a4a4a;
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
    "Segoe UI Symbol";
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 15px;
}

.game-header {
  margin-bottom: 20px;
  text-align: center;
}
.game-header h1 {
  font-family: "Luckiest Guy", cursive;
  font-size: 2.5rem;
  color: #089da1;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
  font-weight: 600;
  letter-spacing: 1px;
}

.memory-game {
  width: 90vw;
  height: 90vw;
  max-width: 600px;
  max-height: 600px;
  margin: 20px auto;
  display: grid;
  grid-template-columns: repeat(var(--game-columns, 4), 1fr);
  grid-template-rows: repeat(var(--game-rows, 2), 1fr);
  gap: clamp(5px, 1.5vw, 10px);
  perspective: 1000px;
  background-color: #089da1;
  background-image: linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.04) 25%,
      transparent 25%,
      transparent 75%,
      rgba(255, 255, 255, 0.04) 75%,
      rgba(255, 255, 255, 0.04)
    ),
    linear-gradient(
      -45deg,
      rgba(255, 255, 255, 0.04) 25%,
      transparent 25%,
      transparent 75%,
      rgba(255, 255, 255, 0.04) 75%,
      rgba(255, 255, 255, 0.04)
    );
  background-size: 24px 24px;
  border-radius: 15px;
  padding: clamp(10px, 2.5vw, 20px);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05), 0 8px 25px rgba(0, 0, 0, 0.12);
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.memory-card {
  position: relative;
  transform: scale(1);
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  cursor: pointer;
  background-color: transparent;
}

.memory-card:not(.flip):not(.matched):hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
}

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

.memory-game.visible {
  opacity: 1;
  transform: scale(1);
}

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

@keyframes cardMatched {
  0% {
    transform: scale(1) rotateY(180deg);
    opacity: 1;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
  }
  100% {
    transform: scale(1) rotateY(180deg);
    opacity: 0.6;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.07);
  }
}

.memory-card.matched {
  cursor: default;
}

.face-container {
  width: 100%;
  height: 100%;
  padding: 10px;
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 8px;
  backface-visibility: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.face-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.back-face {
  background: #f5e6cb;
}

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

.button {
  width: auto;
  min-width: 180px;
  padding: 12px 25px;
  height: auto;
  background: linear-gradient(to bottom, #0caab0 0%, #089da1 100%);
  color: #fcf0d8;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-family: "Nunito", sans-serif;
  font-weight: 600;
  text-align: center;
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.15),
    inset 0 1px 0px rgba(255, 255, 255, 0.15);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2);
}

.button:hover {
  background: linear-gradient(to bottom, #0ddedf 0%, #0abcc2 100%);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 1px rgba(255, 255, 255, 0.25);
}

.button:active {
  background: linear-gradient(to bottom, #078c8f 0%, #06797c 100%);
  transform: translateY(1px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), inset 0 1px 0px rgba(0, 0, 0, 0.1);
}

.button:focus-visible {
  outline: 2px solid #056a6c;
  outline-offset: 2px;
}

.game-info {
  margin-top: 25px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  width: 90vw;
  max-width: 400px;
  padding: 20px;
  background-color: #fffaf0;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
  pointer-events: none;
}

.game-info.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#game-active-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.game-stats {
  display: flex;
  justify-content: space-around;
  width: 100%;
  font-size: 1.1em;
  color: #555;
}

.win-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
  margin-top: 15px;
}

.win-message {
  font-family: "Luckiest Guy", cursive;
  letter-spacing: 1px;
  font-size: 2.8em;
  color: #06797c;
  font-weight: bold;
  text-align: center;
  text-shadow: 2px 2px 0px #f1c40f, 4px 4px 0px rgba(0, 0, 0, 0.1);
  animation: winMessagePulse 1.5s infinite alternate ease-in-out;
  margin-bottom: 10px;
}

@keyframes winMessagePulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.05);
  }
}

.best-score {
  font-size: 1em;
  color: #333;
}

.star-rating {
  font-size: 1.8em;
  color: #f1c40f;
  height: 1.5em;
}

.star-rating span {
  display: inline-block;
  opacity: 0;
  transform: scale(0.3) rotate(-15deg);
  animation: starAppear 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.star-rating span:nth-child(1) {
  animation-delay: 0.1s;
}
.star-rating span:nth-child(2) {
  animation-delay: 0.25s;
}
.star-rating span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes starAppear {
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

.difficulty-selection {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  padding: 25px;
  background-color: #fffaf0;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
  width: 90vw;
  max-width: 350px;
  text-align: center;
}

.difficulty-selection h2 {
  font-family: "Luckiest Guy", cursive;
  letter-spacing: 1px;
  margin-bottom: 15px;
  color: #333;
  font-size: 1.6em;
}

.difficulty-selection .button {
  width: 100%;
  margin-bottom: 8px;
}
.difficulty-selection .button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2),
    inset 0 1px 1px rgba(255, 255, 255, 0.25);
}

.difficulty-selection .button:active {
  transform: translateY(0px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2), inset 0 1px 0px rgba(0, 0, 0, 0.1);
}
.difficulty-selection .button:last-child {
  margin-bottom: 0;
}

@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  .game-header h1 {
    font-size: 2rem;
  }

  .memory-game {
    padding: clamp(8px, 2vw, 15px);
    gap: clamp(4px, 1.2vw, 8px);
  }

  .face-container {
    padding: 6px;
    border-radius: 6px;
  }
  .memory-card {
    border-radius: 6px;
  }

  .win-message {
    font-size: 1.6em;
  }

  .game-stats {
    font-size: 1em;
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }

  .button {
    padding: 10px 20px;
    font-size: 0.95rem;
  }

  .win-section {
    margin-top: 10px;
  }

  .difficulty-selection h2 {
    font-size: 1.4em;
  }
}
