.game-popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
  
}

.game-popup-overlay.is-active {
  opacity: 1;
  visibility: visible;
}

.game-popup-content {
  position: absolute;
  top: 110px;
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  
  width: 90%;
  max-width: 900px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;

  padding: 20px 30px;
  background: #1a1a1a;
  border-radius: 20px;
  border: 1px solid #444;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  transition: transform 0.4s ease;
}

.game-popup-overlay.is-active .game-popup-content {
    transform: translateX(-50%) scale(1);
}

.game-popup-close {
  position: absolute;
  top: 15px;
  right: 20px;
  background: none;
  border: none;
  color: #888;
  font-size: 2.5rem;
  font-weight: 300;
  cursor: pointer;
  transition: color 0.3s, transform 0.3s;
  line-height: 1;
  z-index: 10; 
}

.game-popup-close:hover {
  color: white;
  transform: rotate(90deg);
}

#gameContainer {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  text-align: center;
}

#instructions {
  line-height: 1.6;
  font-size: 1.2rem;
  font-family: 'Anonymous Pro', monospace;
  border: 1.5px solid #bda063;
  border-radius: 16px;
  padding: 15px 25px;
  background: rgba(0,0,0,0.2);
  min-height: 110px;
  color: #fff;
}
#instructions strong { font-weight: 700; }
.blinking-cursor {
  display: inline-block;
  background-color: white;
  width: 10px;
  height: 1.2rem;
  animation: blink 1s step-end infinite;
  margin-left: 2px;
  position: relative;
  top: 3px;
}
@keyframes blink {
  from, to { background-color: transparent; }
  50% { background-color: white; }
}

.cards-area {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
  min-height: 360px;
  margin: 20px auto 20px;
  perspective: 1000px;
}
.card {
  width: 240px;
  height: 360px;
  position: relative;
  transform-style: preserve-3d;
  cursor: pointer;
}
.card .card-inner {
  transition: transform 0.6s, box-shadow 0.3s;
}
.card:not(.flipped):hover .card-inner {
  transform: translateY(-15px) scale(1.05);
  box-shadow: 0 15px 30px rgba(155, 89, 182, 0.4);
}
.card.flipped:hover .card-inner {
  transform: rotateY(180deg) translateY(-15px) scale(1.05);
  box-shadow: 0 15px 30px rgba(155, 89, 182, 0.4);
}
.card-inner {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  position: relative;
  border-radius: 16px;
}
.card.flipped .card-inner {
  transform: rotateY(180deg);
}
.card-front, .card-back {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  backface-visibility: hidden;
  border-radius: 16px;
  border: 2px solid #000;
  overflow: hidden;
}
.card-front img, .card-back img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 14px;
}
.card-back {
  transform: rotateY(180deg);
}

#startGame, #playAgain, #proceedToGameBtn {
  padding: 12px 28px;
  font-size: 1rem;
  background: linear-gradient(135deg, #9B59B6, #00D1B2);
  color: #fff;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.3s, transform 0.3s;
  margin: 10px;
  font-family: 'Montserrat', sans-serif;
  font-weight: 500;
}
#startGame:hover, #playAgain:hover, #proceedToGameBtn:hover {
  background: linear-gradient(135deg, #00D1B2, #9B59B6);
  transform: translateY(-2px);
}
#proceedToGameBtn {
    margin-top: 25px;
}

.modal {
  display: none; 
  position: fixed; 
  top: 0; 
  left: 0;
  width: 100%; 
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  z-index: 3000;
  align-items: center; 
  justify-content: center;
}
.modal.is-active { 
  display: flex; 
}
.modal-content {
  background: #fff; 
  color: #333;
  padding: 25px 30px;
  border-radius: 8px; 
  text-align: center;
  width: 90%; 
  max-width: 340px; 
  position: relative;
  font-family: 'Montserrat', sans-serif;
}
.modal-content button {
  padding: 10px 20px; 
  margin-top: 15px;
  background: linear-gradient(135deg, #9B59B6, #00D1B2);
  color: #fff; 
  border: none; 
  border-radius: 24px;
  cursor: pointer; 
  transition: background 0.3s, transform 0.3s;
  font-family: 'Montserrat', sans-serif;
  font-weight: 500;
}
.modal-content button:hover {
  background: linear-gradient(135deg, #00D1B2, #9B59B6);
  transform: translateY(-2px);
}
.close-modal {
  position: absolute; 
  top: 8px; 
  right: 12px;
  cursor: pointer; 
  font-size: 1.5rem;
  color: #888;
}
.close-modal:hover {
    color: #333;
}

@media (max-width: 820px) {
  .cards-area { gap: 20px; min-height: 300px; }
  .card { width: 200px; height: 300px; }
  .game-popup-content { width: 95%; top: 100px; max-height: calc(100vh - 120px); }
}
@media (max-width: 680px) {
  .cards-area { min-height: 270px; }
  .card { width: 180px; height: 270px; }
}
@media (max-width: 620px) {
  .cards-area { 
    flex-wrap: wrap; 
    min-height: auto; 
    gap: 15px;
  }
  .card { width: 120px; height: 180px; }
  #instructions { font-size: 1rem; }
  .game-popup-content { padding: 15px; top: 80px; max-height: calc(100vh - 100px); }
}

#playGameButton:disabled {
  opacity: 1;
  cursor: not-allowed;
  pointer-events: none;
  background: #333 !important;
  color: #fff !important;
  font-weight: 600;
  font-size: 1.05rem;
  transition: none;
}
