/* Global Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: Arial, Helvetica, sans-serif;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-direction: column;
  min-height: 100vh;
  color: #ffffff;
  background: darkgreen;
  overflow-x: hidden;
  text-align: center;
}

/* Page Wrapper */
.page-wrapper {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  padding: 40px 60px;
  border-radius: 12px;
  z-index: 2;
  background: url("../projectimages/background.webp") no-repeat center center;
  background-size: cover;
  box-shadow: 0 0 15px rgba(0,0,0,0.3);
  position: relative;
  content-visibility: auto;
}

/* Background Overlay */
.page-wrapper::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  z-index: 0;
}

.page-wrapper > * {
  position: relative;
  z-index: 1;
}

.page-header {
  margin-top: 10px;
  margin-bottom: 30px;
  font-size: 1.4rem;
  color: #ffffff;
  text-align: center;
  max-width: 1200px;
}

.stats {
  font-size: 1.2rem;
  margin: 10px 0 15px 0;
  color: white;
}

#starRating {
  color: gold;
  font-size: 1.2rem;
}

.page-footer {
  background-color: darkolivegreen;
  color: white;
  text-align: center;
  padding: 15px 10px;
  font-size: 0.9rem;
  margin-top: 30px;
  width: 100%;
  max-width: 1200px;
}

.page-footer a {
  color: #ffffff;
  text-decoration: none;
  margin: 0 5px;
  transition: color 0.3s ease;
}

.page-footer a:hover {
  color: #ffffff;
}

h1 {
  font-size: 2em;
  color: #ffffff;
  letter-spacing: 0.1em;
  text-align: center;
}

.reset,
#instructionsBtn,
#playGameBtn,
#mute-btn {
  padding: 15px 30px;
  color: darkolivegreen;
  background: white;
  border: none;
  font-size: 1.5em;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s, color 0.3s;
  margin-top: 10px;
  border-radius: 6px;
}

.reset:hover,
#instructionsBtn:hover,
#playGameBtn:hover,
#mute-btn:hover {
  color: white;
  background: darkolivegreen;
}

/* Game Grid */
.game {
  display: grid;
  gap: clamp(6px, 2vw, 12px);
  perspective: 1000px;
  justify-content: center;
  width: 100%;
  margin: 0 auto;
  max-width: 440px;
  grid-template-columns: repeat(4, 1fr);
}

.item {
  width: 100%;
  aspect-ratio: 1 / 1;
  perspective: 1000px;
  cursor: pointer;
}

.item.hidden {
  visibility: hidden;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s;
  border-radius: 6px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.item.boxOpen .card,
.item.boxMatch .card {
  transform: rotateY(180deg);
  cursor: default;
}

.front,
.back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5em;
  border-radius: 6px;
  user-select: none;
}

.front {
  background: green;
  box-shadow: inset 0 0 10px #004d00;
}

.back {
  background: white;
  transform: rotateY(180deg);
}

/* Instructions */
.instructions-wrapper {
  position: relative;
  margin-bottom: 20px;
  z-index: 10;
}

.instructions-popup {
  display: none;
  position: absolute;
  top: 120%;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  color: darkolivegreen;
  padding: 20px;
  border-radius: 10px;
  width: 280px;
  z-index: 1000;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  text-align: left;
}

.instructions-popup.hidden {
  display: none;
}

.instructions-popup:not(.hidden) {
  display: block;
}

/* Stats */
.stats {
  display: flex;
  gap: 23px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin: 20px 0;
}

.stats span {
  font-weight: bold;
}

.stat-item {
  background: rgba(255, 255, 255, 0.8);
  color: #222;
  padding: 14px 24px;
  border-radius: 20px;
  font-size: 1.6rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Falling Leaves */
.falling-leaves {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  overflow: visible;
  z-index: 10;
  transform: translateZ(0);
}

.leaf {
  position: absolute;
  top: -60px;
  width: 30px;
  height: 30px;
  background: url("leafs2.webp") no-repeat center/contain;
  opacity: 0.8;
  animation: fall 8s linear infinite;
  pointer-events: none;
  will-change: transform, opacity;
}

/* left leaves */
.leaf.left1 { left: 5vw; animation-delay: 0s; }
.leaf.left2 { left: 12vw; animation-delay: 2.5s; }
.leaf.left3 { left: 18vw; animation-delay: 5s; }

/* right leaves */
.leaf.right1 { right: 5vw; animation-delay: 0s; }
.leaf.right2 { right: 12vw; animation-delay: 2s; }
.leaf.right3 { right: 18vw; animation-delay: 4.5s; }

@keyframes fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0.8;
  }
  100% {
    transform: translateY(110vh) rotate(360deg);
    opacity: 0;
  }
}

/* Mobile: 2 cards per row */
@media (max-width: 480px) {
  .page-wrapper {
    padding: 20px;
    gap: 20px;
    max-width: 100%;
    overflow-x: hidden;
  }
  .page-header {
    margin-bottom: 40px;
  }
  h1 {
    font-size: 2em;
  }
  .item { height: 60px; }
  .front, .back { font-size: 1.8em; }
  .reset, #mute-btn, #instructionsBtn, #playGameBtn {
    font-size: 1em;
    padding: 10px 20px;
  }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 1024px) {
  .page-wrapper { padding: 30px; gap: 30px; }
  h1 { font-size: 2.5em; }
  .game { grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); max-width: 400px; }
  .front, .back { font-size: 2.2em; }
  .reset, #mute-btn, #instructionsBtn, #playGameBtn {
    font-size: 1.2em;
    padding: 12px 25px;
  }
}

/* Desktop */
@media (min-width: 1025px) {
  .page-wrapper { padding: 40px 60px; }
  h1 { font-size: 3em; }
  .game { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); max-width: 440px; }
  .front, .back { font-size: 3em; }
  .reset, #mute-btn, #instructionsBtn, #playGameBtn {
    font-size: 1.5em;
    padding: 15px 30px;
  }
}