@import url("https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Montserrat", sans-serif;
  background: black;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-left: 20px;
  padding-right: 20px;
  position: relative; /* allow pseudo-elements */
  overflow-x: hidden; /* allow vertical scrolling if needed; prevent horizontal overflow */
}

/* Decorative corner images that blend into black. Use pseudo-elements so they don't interfere with layout. */
body::before,
body::after {
  content: "";
  position: absolute;
  z-index: 0; /* behind content */
  pointer-events: none;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: contain;
}

/* Top-left decorative image */
body::before {
  top: 0;
  left: 0;
  width: min(45vw, 520px);
  height: min(45vw, 520px);
  background-image: url("src/topleft.png");
}

/* Bottom-right decorative image */
body::after {
  bottom: 0;
  right: 0;
  width: min(45vw, 520px);
  height: min(45vw, 520px);
  background-image: url("src/bottomright.png");
}

/* Ensure game content sits above decorative images */
.game-container,
.match-popup,
.winner-popup {
  position: relative;
  z-index: 1;
}

.game-container {
  text-align: center;
}

.banner {
  margin-bottom: 10px;
}

.banner-logo {
  max-width: 500px;
  height: auto;
  filter: drop-shadow(0 4px 8px rgba(255, 255, 255, 0.1));
}

.title-stats-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
  width: 100%;
  max-width: 1600px;
}

h1 {
  color: white;
  margin-bottom: 0;
  font-size: 2.5em;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.bottom-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  width: 100%;
  max-width: 1600px;
}

.stats {
  display: flex;
  gap: 20px;
  color: white;
  font-size: 1.1em;
}

.stat-item {
  padding: 10px 20px;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(8, 158px);
  grid-template-rows: repeat(2, 224px);
  gap: 25px;
  justify-content: center;
  margin: 0 auto;
}

.card {
  aspect-ratio: 1;
  width: 158px;
  height: 224px;
  background: white;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.4s ease;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Only show hover effect on unmatched cards */
.card:not(.matched):not(.flipped):hover {
  transform: scale(1.05);
}

.card.flipped {
  transform: rotateY(180deg);
}

.card.matched {
  opacity: 0.7;
  cursor: default;
  pointer-events: none;
  transform: none;
}

.matched-card-image {
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: 10px;
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 3em;
}

.card-front {
  background: white;
  transform: rotateY(180deg);
}

.card-back {
  background: white;
  font-size: 2em;
  color: white;
}

.card-logo {
  width: 80%;
  height: 80%;
  object-fit: contain;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: 10px;
}

.reset-btn {
  padding: 12px 30px;
  font-size: 1.1em;
  background: white;
  color: black;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.reset-btn:hover {
  transform: scale(1.05);
}

.reset-btn:active {
  transform: scale(0.95);
}

.winner {
  color: #ffd700;
  font-size: 1.5em;
  margin-top: 20px;
  font-weight: bold;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.match-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.match-popup.show {
  opacity: 1;
}

.popup-content {
  background: white;
  padding: 40px;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: left;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  width: 90%;
  overflow: hidden;
  max-width: 1200px;
  min-width: 320px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
  overflow-y: auto;
  max-height: 90vh;
}

.match-popup.show .popup-content {
  transform: scale(1);
}

.popup-emoji {
  font-size: 4em;
  margin-bottom: 20px;
  display: block;
}

/* .popup-image {
  margin-bottom: 20px;
}

.popup-card-image {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: inherit;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
} */

.finish-image {
  width: 380px;
  height: 380px;
  object-fit: cover;
  border-radius: inherit;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  display: block;
  margin: 0 auto;
}
.popup-content h3 {
  color: black;
  font-size: 1.8em;
  margin-bottom: 10px;
  font-weight: bold;
  text-align: center;
}

.popup-content p {
  color: black;
  font-size: 1.1em;
  margin-bottom: 20px;
  text-align: center;
  line-height: 1.6;
  max-height: 300px;
  overflow-y: auto;
  padding: 0 10px;
}

.popup-stats {
  background: black;
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 25px;
  display: flex;
  justify-content: space-around;
  font-weight: bold;
  color: white;
}

.popup-close {
  background: black;
  color: white;
  border: none;
  padding: 12px 30px;
  border-radius: 25px;
  font-size: 1.1em;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
  font-family: "Montserrat", sans-serif;
}

.popup-close:hover {
  background: #1f1f1f;
  transform: scale(1.05);
}

.popup-close:active {
  transform: scale(0.95);
}

@media (max-width: 768px) {
  .game-board {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: auto;
    gap: 10px;
    max-width: 100%;
    padding: 0 10px;
    width: 80%;
  }

  /* Stack stats above the new game button on mobile */
  .bottom-controls {
    flex-direction: column;
    gap: 12px;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
  }

  .stats {
    order: 0; /* keep stats on top */
    display: flex;
    gap: 12px;
    justify-content: center;
    width: 100%;
  }

  .reset-btn {
    order: 1; /* button comes after stats */
    width: auto;
    padding: 12px 28px;
  }

  .card {
    width: 100%;
    aspect-ratio: 1;
    height: auto;
    position: relative;
  }

  .card-face {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
  }

  .card-image,
  .matched-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  body::before {
    display: none;
  }

  /* Bottom-right decorative image */
  body::after {
    display: none;
  }
}

/* Reduce image size on very small screens */
/* @media (max-width: 480px) {
  body::before,
  body::after {
    width: 35vw;
    height: 35vw;
    -webkit-mask-image: linear-gradient(
      135deg,
      rgba(0, 0, 0, 1) 55%,
      rgba(0, 0, 0, 0) 100%
    );
    mask-image: linear-gradient(
      135deg,
      rgba(0, 0, 0, 1) 55%,
      rgba(0, 0, 0, 0) 100%
    );
  }
} */
