* {
  box-sizing: border-box;
}
body {
  margin: 0;
  padding: 0;
  font-family: 'Playfair Display', serif;
  background: url('assets/background.png') no-repeat center center fixed;
  background-size: cover;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  /* Allow scrolling if needed on small screens */
  overflow-x: hidden;
  overflow-y: auto;
  /* Allow vertical scroll on very small screens */
}
.main-container {
  padding: 2rem;
  background: rgba(40, 0, 0, 0.6);
  backdrop-filter: blur(15px);
  border-radius: 20px;
  border: 3px double #fcc201;
  box-shadow: 0 0 50px rgba(255, 215, 0, 0.4);
  text-align: center;
  max-width: 800px;
  width: 90%;
  margin: 20px auto;
  /* Add margin for scrollable scenarios */
}
@media (max-width: 600px) {
  .main-container {
    padding: 1rem;
    width: 95%;
    margin: 10px auto;
    border-width: 2px;
  }
}
.main-container h1.title {
  font-family: 'Dancing Script', cursive;
  font-size: 4rem;
  color: #fcc201;
  text-shadow: 3px 3px 5px rgba(0, 0, 0, 0.8), 0 0 20px #ffea00;
  margin-bottom: 2rem;
  margin-top: 0;
}
@media (max-width: 600px) {
  .main-container h1.title {
    font-size: 2.2rem;
    /* Smaller title */
    margin-bottom: 1rem;
    text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.8);
  }
}
.game-area {
  margin-bottom: 2rem;
  position: relative;
  height: 400px;
  /* Desktop height */
  width: 100%;
}
@media (max-width: 600px) {
  .game-area {
    height: auto;
    /* Auto height to fit grid */
    min-height: 450px;
    /* Minimum height for 3 rows */
    margin-bottom: 1rem;
  }
}
.envelopes-wrapper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 20px;
  justify-items: center;
  align-items: center;
  /* Center vertically */
  position: relative;
  width: 100%;
  height: 100%;
  perspective: 1000px;
}
@media (max-width: 600px) {
  .envelopes-wrapper {
    grid-template-columns: repeat(2, 1fr);
    /* 2 columns */
    grid-gap: 15px;
    /* Smaller gap */
  }
}
.envelope-item {
  width: 100%;
  max-width: 150px;
  height: 180px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* Mobile adjustments for envelopes */
}
@media (max-width: 600px) {
  .envelope-item {
    max-width: 120px;
    /* Smaller width */
    height: 140px;
    /* Smaller height */
  }
}
.envelope-item.flipped {
  transform: rotateY(180deg);
}
.envelope-item.selected {
  z-index: 10;
  transform: rotateY(180deg) scale(1.15);
  box-shadow: 0 0 30px #fcc201;
  border-radius: 12px;
}
.envelope-item.revealed {
  transform: rotateY(0deg) scale(1.15);
  box-shadow: 0 0 40px #fcc201, inset 0 0 20px #fcc201;
}
.envelope-item .face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  border: 2px solid #fcc201;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  /* Crucial: Pass clicks to parent */
}
.envelope-item .front {
  background: linear-gradient(135deg, #fffbec 0%, #ffe082 100%);
  color: #b71c1c;
  font-family: 'Lobster', cursive;
  font-size: 2.5rem;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.5);
  transform: rotateY(0deg);
  z-index: 2;
  border: 4px solid #fcc201;
}
@media (max-width: 600px) {
  .envelope-item .front {
    font-size: 1.8rem;
    /* Smaller font for value */
  }
}
.envelope-item .front::after {
  content: '';
  position: absolute;
  width: 80%;
  height: 80%;
  border: 2px dashed #b71c1c;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0.3;
}
.envelope-item .back {
  background: radial-gradient(circle, #e53935 0%, #b71c1c 100%);
  background-image: radial-gradient(#fcc201 15%, transparent 16%), radial-gradient(#fcc201 15%, transparent 16%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  color: #fcc201;
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 2px solid #fcc201;
}
.envelope-item .back .deco-text {
  font-family: 'Dancing Script', cursive;
  font-size: 2.8rem;
  margin-bottom: 5px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
@media (max-width: 600px) {
  .envelope-item .back .deco-text {
    font-size: 2rem;
    /* Smaller decorative text */
  }
}
.envelope-item .back .icon {
  font-size: 3.5rem;
  filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.3));
}
@media (max-width: 600px) {
  .envelope-item .back .icon {
    font-size: 2.5rem;
  }
}
.shuffling .envelope-item {
  position: absolute;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Button Styles - Completely Redone */
.controls {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 30px;
}
@media (max-width: 600px) {
  .controls {
    margin-top: 15px;
    /* Reduce gap */
  }
}
.controls .btn {
  position: relative;
  padding: 15px 40px;
  font-size: 0.85rem;
  /* Reduced from 1.5rem as requested */
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all 0.2s ease;
  overflow: hidden;
  outline: none;
  /* Inner shine */
}
@media (max-width: 600px) {
  .controls .btn {
    padding: 12px 30px;
    font-size: 0.8rem;
    /* Smaller on mobile */
    width: auto;
  }
}
.controls .btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 50%;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.4), transparent);
  border-radius: 50px 50px 0 0;
  pointer-events: none;
}
.controls .btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}
.controls .btn:active {
  transform: translateY(1px);
  filter: brightness(0.95);
}
.controls .btn.hidden {
  display: none;
}
.controls .btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(100%);
  transform: none !important;
}
.controls .btn-primary {
  background: linear-gradient(to bottom, #fdd835 0%, #fbc02d 50%, #f9a825 100%);
  color: #b71c1c;
  border: 2px solid #fff59d;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3), 0 0 0 4px rgba(251, 192, 45, 0.3), inset 0 0 10px rgba(255, 255, 255, 0.5);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}
.controls .btn-success {
  background: linear-gradient(to bottom, #ef5350 0%, #c62828 50%, #b71c1c 100%);
  color: #fff;
  border: 2px solid #ffcdd2;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3), 0 0 0 4px rgba(198, 40, 40, 0.3), inset 0 0 10px rgba(255, 255, 255, 0.3);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
  backdrop-filter: blur(8px);
}
.overlay.visible {
  opacity: 1;
  pointer-events: all;
}
.overlay .message-box {
  background: linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%);
  padding: 3rem 4rem;
  border-radius: 30px;
  text-align: center;
  color: #333;
  border: 4px solid #fcc201;
  box-shadow: 0 0 60px rgba(255, 215, 0, 0.5);
  animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  min-width: 350px;
  max-width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Secondary Button inside Overlay */
}
@media (max-width: 600px) {
  .overlay .message-box {
    padding: 2rem;
    min-width: 300px;
    width: 90%;
  }
}
.overlay .message-box h2 {
  color: #b71c1c;
  font-size: 3rem;
  margin-bottom: 1rem;
  font-family: 'Dancing Script', cursive;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.8);
}
@media (max-width: 600px) {
  .overlay .message-box h2 {
    font-size: 2rem;
  }
}
.overlay .message-box p {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  font-family: 'Playfair Display', serif;
  color: #5d4037;
}
@media (max-width: 600px) {
  .overlay .message-box p {
    font-size: 1.2rem;
  }
}
.overlay .message-box .result-amount {
  font-size: 5rem;
  color: #d50000;
  font-family: 'Lobster', cursive;
  font-weight: bold;
  margin: 1.5rem 0;
  text-shadow: 3px 3px 0 #fff, 0 0 25px #fcc201;
  transform: rotate(-3deg);
  display: inline-block;
}
@media (max-width: 600px) {
  .overlay .message-box .result-amount {
    font-size: 3.5rem;
  }
}
.overlay .message-box .btn-secondary {
  display: inline-block;
  margin-top: 1.5rem;
  padding: 12px 40px;
  font-size: 1.3rem;
  border-radius: 50px;
  cursor: pointer;
  font-family: 'Playfair Display', serif;
  font-weight: bold;
  text-transform: uppercase;
  border: none;
  background: linear-gradient(to bottom, #ff7043 0%, #f4511e 100%);
  color: #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.2s;
}
.overlay .message-box .btn-secondary:hover {
  transform: scale(1.05);
}
@media (max-width: 600px) {
  .overlay .message-box .btn-secondary {
    padding: 10px 30px;
    font-size: 1.1rem;
  }
}
@keyframes popIn {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
.hidden {
  display: none !important;
}
