/* CSS Variables & Styling Reset */
:root {
  --bg-primary: #fff1f2;
  --bg-gradient: linear-gradient(135deg, #ffe4e6 0%, #fecdd3 100%);
  --romantic-pink: #f43f5e;
  --romantic-pink-hover: #e11d48;
  --romantic-gold: #eab308;
  --text-dark: #4c0519;
  --text-muted: #881337;
  --glass-bg: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(244, 63, 94, 0.15);
  --font-modern: 'Outfit', sans-serif;
  --font-handwritten: 'Nanum Pen Script', 'Gamja Flower', cursive;
  --card-shadow: 0 10px 30px rgba(244, 63, 94, 0.08), 0 1px 8px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  background-color: var(--bg-primary);
  background-image: var(--bg-gradient);
  color: var(--text-dark);
  font-family: var(--font-modern);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
}

/* Background Canvas */
#heartCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* Main Wrapper */
.app-container {
  position: relative;
  width: 90%;
  max-width: 520px;
  z-index: 2;
  perspective: 1000px;
}

/* Screen Panels (Transition States) */
.screen-panel {
  display: none;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 32px;
  padding: 40px 30px;
  box-shadow: var(--card-shadow);
  text-align: center;
  transform-style: preserve-3d;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.screen-panel.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Start Screen specific styling */
.heart-pulse-icon {
  font-size: 80px;
  margin-bottom: 20px;
  animation: pulseHeart 1.2s infinite ease-in-out;
  filter: drop-shadow(0 8px 16px rgba(244, 63, 94, 0.3));
}

.main-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--romantic-pink);
  margin-bottom: 15px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.intro-text {
  font-size: 17px;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 35px;
  font-weight: 500;
}

/* Buttons */
.btn {
  font-family: var(--font-modern);
  font-weight: 800;
  font-size: 16px;
  padding: 14px 36px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  outline: none;
}

.btn-primary {
  background: linear-gradient(135deg, #ff758f, #ff7e5f);
  color: white;
  box-shadow: 0 8px 20px rgba(244, 63, 94, 0.3);
}

.btn-primary:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 12px 25px rgba(244, 63, 94, 0.45);
}

.btn-primary:active {
  transform: translateY(1px) scale(0.97);
}

.btn-secondary {
  background: white;
  color: var(--romantic-pink);
  border: 2px solid var(--romantic-pink);
  margin-top: 25px;
}

.btn-secondary:hover {
  background: var(--romantic-pink);
  color: white;
  transform: scale(1.05);
  box-shadow: 0 5px 15px rgba(244, 63, 94, 0.2);
}

/* Game Play Screen styling */
.progress-container {
  display: flex;
  align-items: center;
  gap: 15px;
  width: 100%;
  margin-bottom: 30px;
}

.progress-bar-wrapper {
  flex-grow: 1;
  height: 12px;
  background: rgba(244, 63, 94, 0.1);
  border-radius: 6px;
  position: relative;
  overflow: visible;
}

.progress-bar-fill {
  height: 100%;
  width: 20%;
  background: linear-gradient(90deg, #ff7e5f, #ff758f);
  border-radius: 6px;
  transition: width 0.4s ease;
}

.progress-heart-icon {
  position: absolute;
  top: 50%;
  left: 20%; /* Tied to the fill percentage in game.js */
  transform: translate(-50%, -50%);
  font-size: 20px;
  transition: left 0.4s ease;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.progress-text {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-muted);
  min-width: 45px;
}

/* Quiz Card transition engine */
.quiz-card-container {
  width: 100%;
  min-height: 280px;
  position: relative;
}

.quiz-card {
  display: none;
  width: 100%;
  flex-direction: column;
  animation: cardFadeIn 0.5s ease forwards;
}

.quiz-card.active {
  display: flex;
}

.question-text {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.5;
  margin-bottom: 24px;
  color: var(--text-dark);
}

.question-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -15px;
  margin-bottom: 20px;
  opacity: 0.8;
  font-weight: 600;
}

/* Options Grid for Multiple Choice */
.options-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.option-btn {
  background: white;
  border: 2px solid rgba(244, 63, 94, 0.08);
  padding: 16px 20px;
  border-radius: 18px;
  font-family: var(--font-modern);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dark);
  text-align: left;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 6px rgba(244, 63, 94, 0.02);
}

.option-btn:hover {
  border-color: var(--romantic-pink);
  background: #fff5f5;
  transform: translateY(-2px);
}

.option-btn:active {
  transform: scale(0.98);
}

.option-btn.correct {
  background: #f0fdf4 !important;
  border-color: #22c55e !important;
  color: #15803d !important;
}

.option-btn.wrong {
  background: #fef2f2 !important;
  border-color: #ef4444 !important;
  color: #b91c1c !important;
}

/* Input Area for Short Answers */
.input-area {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-bottom: 15px;
}

.text-input {
  flex-grow: 1;
  padding: 14px 20px;
  border-radius: 18px;
  border: 2px solid rgba(244, 63, 94, 0.15);
  font-family: var(--font-modern);
  font-size: 15px;
  outline: none;
  transition: all 0.3s ease;
}

.text-input:focus {
  border-color: var(--romantic-pink);
  box-shadow: 0 0 10px rgba(244, 63, 94, 0.1);
  background: white;
}

.btn-submit {
  background: var(--romantic-pink);
  color: white;
  padding: 14px 25px;
  box-shadow: 0 4px 10px rgba(244, 63, 94, 0.2);
}

.btn-submit:hover {
  background: var(--romantic-pink-hover);
  transform: translateY(-2px);
}

.feedback-msg {
  font-size: 14px;
  font-weight: 800;
  height: 20px;
  margin-top: 10px;
}

.feedback-msg.correct {
  color: #22c55e;
}

.feedback-msg.wrong {
  color: #ef4444;
}

/* Envelope Screen & CSS Animated Envelope */
.envelope-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--romantic-pink);
  margin-bottom: 8px;
}

.envelope-sub {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 40px;
  font-weight: 500;
}

.envelope-wrapper {
  position: relative;
  width: 280px;
  height: 180px;
  margin-bottom: 20px;
  cursor: pointer;
}

.envelope {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #f43f5e;
  border-radius: 0 0 15px 15px;
  box-shadow: 0 15px 30px rgba(0,0,0,0.15);
}

/* Flap at top of envelope */
.envelope .flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 140px solid transparent;
  border-right: 140px solid transparent;
  border-top: 100px solid #f43f5e;
  border-bottom: 0px solid transparent;
  z-index: 5;
  transform-origin: top;
  transition: transform 0.4s ease 0.4s; /* delays rotation till letter slides a bit */
}

/* Diagonal pockets forming envelope */
.envelope .pocket {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #fda4af;
  border-radius: 0 0 15px 15px;
  z-index: 4;
  clip-path: polygon(0 40px, 140px 100px, 280px 40px, 280px 180px, 0 180px);
  border: 1px solid rgba(255,255,255,0.1);
}

/* The letter document hidden inside the envelope */
.envelope .letter {
  position: absolute;
  bottom: 0;
  left: 10px;
  width: 260px;
  height: 150px;
  background: white;
  border-radius: 10px;
  z-index: 2;
  transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.2) 0.6s;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.envelope .letter .heart {
  font-size: 40px;
  animation: pulseHeart 1.5s infinite;
}

/* Open envelope animations */
.envelope-wrapper.open .envelope .flap {
  transform: rotateX(180deg);
  z-index: 1; /* move flap behind */
  border-top-color: #fb7185;
}

.envelope-wrapper.open .envelope .letter {
  transform: translateY(-110px);
  z-index: 3;
}

/* Final Letter Screen Styling */
#letter-screen {
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding: 0;
  max-width: 600px;
}

.letter-paper {
  background: #fdfaf2;
  border-radius: 20px;
  padding: 45px 35px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15), 0 0 10px rgba(244, 63, 94, 0.1);
  border: 1px solid #f2e9d9;
  text-align: left;
  position: relative;
  background-image: linear-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px);
  background-size: 100% 32px; /* Line spacing */
  line-height: 32px;
  overflow: hidden;
  animation: letterOpenUp 0.8s cubic-bezier(0.25, 1, 0.5, 1);
}

/* A cute stamp on the corner of the letter */
.letter-paper::before {
  content: '🌸';
  position: absolute;
  top: 30px;
  right: 30px;
  font-size: 32px;
  opacity: 0.8;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.letter-header {
  font-family: var(--font-handwritten);
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 24px;
  color: var(--text-dark);
  border-bottom: 2px solid rgba(244, 63, 94, 0.15);
  padding-bottom: 6px;
}

.letter-body {
  font-family: var(--font-handwritten);
  font-size: 24px;
  color: #3b0712;
  font-weight: bold;
}

.letter-body p {
  margin-bottom: 12px;
  text-indent: 12px;
}

.letter-footer {
  margin-top: 35px;
  text-align: right;
  font-family: var(--font-handwritten);
  font-size: 25px;
  font-weight: bold;
  color: var(--text-muted);
  border-top: 1px dashed rgba(244, 63, 94, 0.15);
  padding-top: 12px;
}

/* Polaroid Photo Frame */
.photo-container {
  background: white;
  padding: 12px 12px 20px 12px;
  box-shadow: 0 8px 20px rgba(76, 5, 25, 0.08);
  border: 1px solid #f3e8e8;
  transform: rotate(-2.5deg); /* Slightly tilted polaroid style */
  margin: 20px auto 20px auto;
  max-width: 250px;
  text-align: center;
  transition: transform 0.3s ease;
  line-height: normal; /* Override lined paper line-height */
}

.photo-container:hover {
  transform: rotate(0deg) scale(1.05);
}

.polaroid-photo {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border: 1px solid #f1f5f9;
  border-radius: 2px;
}

.photo-caption {
  font-family: var(--font-handwritten);
  font-size: 22px;
  color: var(--text-muted);
  margin-top: 8px;
  font-weight: bold;
}

/* Keyframes Animations */
@keyframes pulseHeart {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

@keyframes cardFadeIn {
  from { opacity: 0; transform: scale(0.96) translateY(5px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes letterOpenUp {
  from { opacity: 0; transform: scale(0.8) translateY(100px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Responsive Scaling */
@media (max-width: 520px) {
  .screen-panel {
    padding: 30px 20px;
    border-radius: 24px;
  }
  .main-title {
    font-size: 26px;
  }
  .question-text {
    font-size: 18px;
  }
  .option-btn {
    font-size: 14px;
    padding: 12px 16px;
  }
  .letter-paper {
    padding: 30px 20px;
    line-height: 28px;
    background-size: 100% 28px;
  }
  .letter-header {
    font-size: 22px;
  }
  .letter-body {
    font-size: 20px;
  }
  .letter-footer {
    font-size: 21px;
  }
}
