body {
  min-height: 100vh;
  min-width: 100%;
  background: linear-gradient(135deg, #e0e7ff, #f0f4f8);
  color: #1e293b;
  margin: 0px;
  overflow-x: hidden;
}

h1 {
  text-align: center;
  font-weight: 700;
  font-size: 50px;
  padding: 20px;

}

p {
  text-align: center;
  font-size: 30px;
  font-weight: bold;
}

.hud {
  text-align: center;
  font-size: 30px;
  font-weight: bold;
  padding: 20px;
}

.actions {
  display: flex;
  justify-content: center;
}

.actions button {
  padding: 8px 16px;
  font-size: 20px;
  border-radius: 10px;
  background-color: #4f46e5;
  color: white;
}

.grid-container {
  display: grid;
  justify-content: center;
  align-items: center;
  grid-gap: 16px;
  grid-template-columns: repeat(6, 140px);
  grid-template-rows: repeat(2, calc(140px / 2 * 3));
}

.card {
  height: calc(140px / 2 * 3);
  width: 140px;
  border-radius: 10px;
  background-color: white;
  position: relative;
  transform-style: preserve-3d;
  transition: all 0.5s ease-in-out;
}

.front-image {
  width: 60px;
  height: 60px;
}

.card.flipped {
  transform: rotateY(180deg);
}

.front,
.back {
  backface-visibility: hidden;
  position: absolute;
  border-radius: 10px;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
}

.card .front {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #c5c2ff;
}

.card .back {
  background: #4f46e5;
  background-position: center center;
  background-size: cover;
  backface-visibility: hidden;
}

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

.game-over-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  /* dimmed background */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.game-over-popup.hidden {
  display: none;
}

.win-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

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

.popup-content {
  background: #fff;
  padding: 2rem;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  max-width: 300px;
  width: 90%;
}

.popup-content h2 {
  margin: 0 0 1rem;
  font-size: 1.8rem;
  color: #d32f2f;
}

.popup-content p {
  margin: 0 0 1.5rem;
  font-size: 1.2rem;
}

.popup-content button {
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  background: #4f46e5;
  color: white;
  cursor: pointer;
  transition: background 0.3s ease;
}

.popup-content button:hover {
  background: #4f46e5;
}

/* Instruction tab at bottom */
.instruction-tab {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20%;
  /* ✅ one-fifth the original length */
  background: #4f46e5;
  color: white;
  text-align: center;
  padding: 10px;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  z-index: 1100;
  transition: background 0.3s;
}

.instruction-tab:hover {
  background: #242247;
}

/* Hidden instruction box */
.instruction-content {
  position: fixed;
  bottom: 60px;
  /* sits above the tab */
  left: 50%;
  transform: translateX(-50%);
  background: white;
  color: #333;
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 350px;
  text-align: center;
  z-index: 1099;
  display: none;
  /* hidden by default */
}

.instruction-content.show {
  display: block;
}

.instruction-content h3 {
  margin-top: 0;
  font-size: 18px;
  color: #4f46e5;
}

.instruction-content p {
  margin: 6px 0;
  font-size: 14px;
}

/* Close button */
.close-btn {
  position: absolute;
  top: 8px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 20px;
  font-weight: bold;
  color: #333;
  cursor: pointer;
}

.confetti {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url("../images/confetti.gif") center center / cover no-repeat;
  /* 🎉 Use a confetti GIF */
  pointer-events: none;
  /* so it doesn’t block clicks */
  z-index: 1001;
  /* above dimmed background but under popup content */
}

/* 404 error page */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.frem {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  text-align: center;
  padding: 1rem;
}

.frem .gif {
  max-width: 320px;
  /* desktop/tablet default size */
  width: 100%;
  /* responsive scaling */
  height: auto;
  margin-bottom: 1rem;
}

.frem p {
  font-size: 7rem;
  color: #00000063;
  margin-bottom: 1rem;
}

.frem h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.frem h5 {
  color: #9c9c9c;
  font-size: 1rem;
  margin-bottom: 2rem;
}

.frem a {
  background: #4f46e5;
  padding: 12px 24px;
  color: white;
  text-decoration: none;
  font-size: 1.2rem;
  border-radius: 13px;
  transition: background 0.3s ease;
}

.frem a:hover {
  background: #3730a3;
}

/* --- Tablet (all devices up to ~1080px wide) --- */
@media (max-width: 1080px) {
  .grid-container {
    display: grid;
    /* justify-content: center; */
    /* align-items: center; */
    justify-content: space-around;

    grid-template-columns: repeat(6, 1fr);
    /* 6 per row, auto-resize */
    grid-gap: 19px;
    width: 100%;
    padding: 0 12px;
    box-sizing: border-box;
  }

  .card {
    width: 100%;
    aspect-ratio: 2 / 3;
    /* keep 2:3 proportion */
    height: auto;
  }

  .front-image {
    width: 55%;
    height: auto;
  }

  h1 {
    font-size: 40px;
  }

  .hud {
    font-size: 24px;
  }

  .actions button {
    font-size: 22px;
    padding: 6px 12px;
  }
}

/*  Mobile (up to 430px wide) */
@media (max-width: 430px) {
  .grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 per row */
    grid-template-rows: repeat(4, 1fr); /* 4 equal rows */
    gap: 4px; /* reduced even spacing */
    width: 95vw; /* shrink container slightly */
    height: 70vh; /* shrink grid height */
    margin: auto; /* center the grid */
    box-sizing: border-box;
    justify-items: center;
    align-items: center;
    transform: scale(0.8); /* Shrinks to 80% of original size */
    transform-origin: top center; /* Keeps layout centered, anchored at the top */
  }

  .card {
    width: 65%;
    height: 65%;
    aspect-ratio: 2 / 3;
    border-radius: 8px;
    place-self: center;
  }

  .front-image {
    width: 55%;
    height: auto;
  }

  h1 {
    font-size: 22px;
    margin: 4px 0;
  }

  p,
  .hud {
    font-size: 18px;
    margin: 2px 0;
  }

  .actions button {
    font-size: 15px;
    padding: 5px 8px;
  }

  .instruction-tab {
  width: 30%;
  padding: 5px;
  font-size: 17px;
  font-weight: lighter;
}

.instruction-content {
  width: 70%;
}
}

/* Extra small devices: 375x667px */
@media (max-width: 375px) and (max-height: 667px) {
  body {
    height: 100vh;          /* lock body to viewport height */
    overflow-y: hidden;     /* avoid vertical scrolling */
    overflow-x: hidden;     /* avoid horizontal scrollbars */
  }

  .grid-container {
    transform: scale(0.7);       /* shrink grid down */
    transform-origin: top center; /* anchor from top center */
    margin: 0 auto;               /* center horizontally */
  }

  .hud, 
  .actions {
    transform: scale(0.7);       /* shrink HUD + restart button */
    transform-origin: top center;
  }

  h1 {
    font-size: 18px;   /* shrink title */
    margin: 4px 0;
  }

 .instruction-tab {
  width: 30%;
  padding: 5px;
  font-size: 12px;
  font-weight: lighter;
}
}