:root {
  --bg-start: #ffeef5;
  --bg-end: #fff9f0;

  --envelope-base: #fdfafb;
  --envelope-shadow: rgba(0, 0, 0, 0.15);
  --envelope-line: #f3c5d1;
  --envelope-flap: #f7e6ea;
  --envelope-front-left: #fdfafb;
  --envelope-front-right: #f9f0f2;

  --accent: #ff5c8a;
  --accent-soft: #ffc2d1;

  --text-main: #35263a;
  --text-muted: #7d6b7f;

  --letter-bg: #fffefe;

  --font-heading: 'Outfit', sans-serif;
  --font-handwriting: 'Great Vibes', cursive;
}

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

body {
  font-family: var(--font-heading);
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  overflow-y: auto;
}

.page {
  width: 100%;
  min-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.card-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 10;
}

/* ENVELOPE */
.envelope {
  position: relative;
  width: clamp(280px, 80vw, 500px);
  aspect-ratio: 4 / 3;
  margin-top: 50px;
  perspective: 1000px;
  cursor: pointer;
  transition: transform 0.4s ease;
  z-index: 5;
}

.shadow-pulse {
  animation: pulse-idle 3s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes pulse-idle {
  0% {
    transform: scale(1) translateY(0);
    filter: drop-shadow(0 10px 15px var(--envelope-shadow));
  }

  100% {
    transform: scale(1.02) translateY(-4px);
    filter: drop-shadow(0 20px 25px var(--envelope-shadow));
  }
}

/* Envelope Parts */
.envelope__back {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--envelope-base);
  border-radius: 4px;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.03);
  z-index: 0;
}

.envelope__front {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
  border-radius: 4px;
  overflow: hidden;
}

/* Creating the cross flaps using borders */
.envelope__front::before,
.envelope__front::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  bottom: 0;
}

.envelope__front::before {
  left: 0;
  border-bottom: calc(clamp(280px, 80vw, 500px) * 0.75 / 2 + 10px) solid var(--envelope-front-left);
  border-left: calc(clamp(280px, 80vw, 500px) / 2) solid var(--envelope-front-left);
  border-right: calc(clamp(280px, 80vw, 500px) / 2) solid transparent;
  border-top: calc(clamp(280px, 80vw, 500px) * 0.75 / 2 - 10px) solid transparent;
  filter: drop-shadow(2px -2px 5px rgba(0, 0, 0, 0.05));
  z-index: 4;
}

.envelope__front::after {
  right: 0;
  border-bottom: calc(clamp(280px, 80vw, 500px) * 0.75 / 2 + 10px) solid var(--envelope-front-right);
  border-right: calc(clamp(280px, 80vw, 500px) / 2) solid var(--envelope-front-right);
  border-left: calc(clamp(280px, 80vw, 500px) / 2) solid transparent;
  border-top: calc(clamp(280px, 80vw, 500px) * 0.75 / 2 - 10px) solid transparent;
  filter: drop-shadow(-2px -2px 5px rgba(0, 0, 0, 0.05));
  z-index: 3;
}

/* Bottom flap */
.envelope__front .bottom-flap {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 0;
  border-bottom: calc(clamp(280px, 80vw, 500px) * 0.75 / 2 + 20px) solid var(--envelope-base);
  border-left: calc(clamp(280px, 80vw, 500px) / 2) solid transparent;
  border-right: calc(clamp(280px, 80vw, 500px) / 2) solid transparent;
  z-index: 5;
  filter: drop-shadow(0 -4px 4px rgba(0, 0, 0, 0.04));
}

.envelope__flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 0;
  border-top: calc(clamp(280px, 80vw, 500px) * 0.75 / 2 + 20px) solid var(--envelope-flap);
  border-left: calc(clamp(280px, 80vw, 500px) / 2) solid transparent;
  border-right: calc(clamp(280px, 80vw, 500px) / 2) solid transparent;
  z-index: 6;
  transform-origin: top center;
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1), z-index 0s 0.3s;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.08));
}

/* The seal heart in the middle of the flap */
.envelope__seal {
  position: absolute;
  top: calc(clamp(280px, 80vw, 500px) * 0.75 / 2 + 5px);
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 7;
  transition: opacity 0.3s ease 0.1s;
  pointer-events: none;
}

.seal-heart {
  width: 40px;
  height: 40px;
  background-color: var(--accent);
  position: relative;
  transform: rotate(45deg);
  border-radius: 4px;
  box-shadow: 0 4px 10px rgba(255, 92, 138, 0.4);
}

.seal-heart::before,
.seal-heart::after {
  content: '';
  width: 40px;
  height: 40px;
  background-color: var(--accent);
  border-radius: 50%;
  position: absolute;
}

.seal-heart::before {
  top: -20px;
  left: 0;
}

.seal-heart::after {
  top: 0;
  left: -20px;
}


/* LETTER */
.envelope__letter {
  position: absolute;
  bottom: 5%;
  left: 5%;
  width: 90%;
  height: 90%;
  background: var(--letter-bg);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1;
  /* Below FRONT, Above BACK */
  transform: translateY(0);
  transition: transform 0.9s cubic-bezier(0.175, 0.885, 0.32, 1.275), height 0.9s ease, bottom 0.9s ease, left 0.9s ease, width 0.9s ease;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}

.envelope__letter::-webkit-scrollbar {
  display: none;
}

.letter__inner {
  padding: 24px;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  opacity: 0.5;
  transition: opacity 0.6s ease 0.4s;
}

.letter__photo-wrapper {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 80px;
  height: 90px;
  background: white;
  padding: 4px 4px 16px 4px;
  box-shadow: 1px 3px 8px rgba(0, 0, 0, 0.15);
  transform: rotate(6deg);
  z-index: 2;
  transition: transform 0.3s ease;
}

.letter__photo-wrapper:hover {
  transform: rotate(0deg) scale(1.1);
}

.letter__photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-pin {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  background: radial-gradient(circle at 30% 30%, #ff8fa3, var(--accent));
  border-radius: 50%;
  box-shadow: 1px 2px 4px rgba(0, 0, 0, 0.3), inset -1px -1px 3px rgba(0, 0, 0, 0.2);
}

.letter__eyebrow {
  font-size: 0.85rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.letter__title {
  font-family: var(--font-handwriting);
  font-size: 2.8rem;
  color: var(--text-main);
  margin-bottom: 16px;
  line-height: 1.1;
  max-width: 90%;
}

.letter__body {
  font-size: 1.15rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.letter__signature {
  font-family: var(--font-handwriting);
  font-size: 2rem;
  text-align: right;
  margin-top: auto;
  color: var(--accent);
}

/* OPEN ANIMATIONS */
.is-open .shadow-pulse {
  animation: none;
  transform: scale(0.9) translateY(40px);
  /* Move down and scale slightly */
}

.is-open .envelope__flap {
  transform: rotateX(180deg);
  z-index: 0;
  /* Fall behind letter once open */
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1), z-index 0s 0.6s;
}

.is-open .envelope__seal {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.is-open .envelope__letter {
  transform: translateY(15px);
  /* Move downwards slightly to perfectly center */
  height: 140%;
  /* More compact height */
  width: 104%;
  /* Slightly wider than envelope */
  left: -2%;
  /* Center horizontally */
  bottom: 0%;
  /* Center relative to envelope fold */
  z-index: 10;
  /* Bring in front of all envelope layers */
  box-shadow: 0 -10px 20px rgba(0, 0, 0, 0.1);
}

.is-open .letter__inner {
  opacity: 1;
}

/* HEARTS LAYER */
.hearts-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9000;
}

.floating-heart {
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--accent);
  transform: rotate(45deg);
  opacity: 0;
  animation: float-up 3s ease-in-out forwards;
}

.floating-heart::before,
.floating-heart::after {
  content: '';
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
  position: absolute;
}

.floating-heart::before {
  top: -10px;
  left: 0;
}

.floating-heart::after {
  top: 0;
  left: -10px;
}

@keyframes float-up {
  0% {
    transform: translateY(0) rotate(45deg) scale(0.5);
    opacity: 0;
  }

  20% {
    opacity: 0.8;
  }

  100% {
    transform: translateY(-300px) rotate(45deg) scale(1.2);
    opacity: 0;
  }
}

/* CONTROLS */
.controls {
  position: absolute;
  bottom: -90px;
  text-align: center;
  width: 100%;
  transition: opacity 0.3s;
  z-index: 50;
  /* Ensure it stays above the envelope */
}

.hint {
  font-size: 0.9rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.6);
  padding: 8px 16px;
  border-radius: 20px;
  backdrop-filter: blur(4px);
  display: inline-block;
  animation: fade-in 1s ease 1s both;
}

.hint[hidden] {
  display: none !important;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 30px;
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(255, 92, 138, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  margin: 0 4px;
}

.btn-action {
  background: white;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(255, 92, 138, 0.4);
}

.btn[hidden] {
  display: none !important;
}

.photo-instruction {
  margin-top: 12px;
  color: #a494a6;
}

/* Modifiers */
.is-open .hint {
  display: none;
}

@media (max-width: 400px) {
  .envelope {
    margin-top: 100px;
  }
}

/* SCATTERING FRAMES */
.frames-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 2;
  /* Between envelope back and front */
}

.scatter-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  width: clamp(120px, 20vw, 250px);
  aspect-ratio: 1;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.1);
  transition: transform 1.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.8s ease;
  border: 8px solid white;
  box-shadow: 2px 4px 15px rgba(0, 0, 0, 0.15);
  border-bottom-width: 25px;
  /* Polaroid like look */
  background-color: white;
  /* In case the frame image is transparent */
}

.scatter-photo {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: #f0f0f0;
}

.scatter-frame.is-scattered {
  opacity: 1;
}

/* CURSOR LOVE PARTICLES */
.cursor-love {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  color: var(--accent);
  font-size: 20px;
  animation: fall-and-fade 1s linear forwards;
  will-change: transform, opacity;
}

@keyframes fall-and-fade {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }

  100% {
    transform: translateY(100px) scale(0.5);
    opacity: 0;
  }
}

/* BG DOODLES */
.doodles-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  /* Right above background */
  opacity: 0.15;
  /* Subtle opacity so it doesn't distract */
}

.doodle {
  position: absolute;
  color: var(--accent);
  font-family: var(--font-handwriting);
}

/* ========================================= */
/* 1. INTRO OVERLAY */
/* ========================================= */
#envelope-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: var(--bg-start);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 5000;
  transition: opacity 0.8s ease, visibility 0.8s;
  cursor: pointer;
}

#envelope-overlay:not(.is-visible) {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.intro-envelope {
  width: 150px;
  height: 100px;
  background: var(--envelope-base);
  position: relative;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  margin-bottom: 2rem;
  animation: float-intro 3s ease-in-out infinite;
}

.intro-envelope::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 75px solid transparent;
  border-right: 75px solid transparent;
  border-top: 55px solid var(--envelope-flap);
  z-index: 2;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.1));
}

.intro-envelope::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 75px solid var(--envelope-front-left);
  border-right: 75px solid var(--envelope-front-right);
  border-bottom: 55px solid #faf5f6;
  z-index: 1;
}

.intro-envelope-seal {
  width: 24px;
  height: 24px;
  background: var(--accent);
  position: absolute;
  top: 55px;
  left: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  z-index: 3;
  border-radius: 2px;
  box-shadow: 0 2px 5px rgba(255, 92, 138, 0.4);
}

.intro-text {
  font-size: 1.2rem;
  color: var(--text-muted);
  animation: pulse-text 2s infinite;
}

@keyframes float-intro {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-10px);
  }
}

@keyframes pulse-text {

  0%,
  100% {
    opacity: 0.6;
  }

  50% {
    opacity: 1;
  }
}


/* ========================================= */
/* 3. MUSIC TOGGLE */
/* ========================================= */
.music-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--envelope-line);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 20px;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  cursor: pointer;
  z-index: 4000;
  backdrop-filter: blur(4px);
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.music-toggle:hover {
  background: white;
  transform: scale(1.05);
}


/* ========================================= */
/* 4. EASTER EGG */
/* ========================================= */
.letter__photo-wrapper {
  cursor: pointer;
}

.secret-photo {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
  /* Let clicks pass through if hidden */
}

.secret-photo.revealed {
  opacity: 1;
  z-index: 10;
  pointer-events: auto;
}


/* ========================================= */
/* 7. QUIZ POLAROIDS */
/* ========================================= */
.quiz-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  /* make sure it's on top of letter and frames */
  pointer-events: none;
  /* Let clicks pass through if hidden */
}

.quiz-polaroid {
  position: absolute;
  pointer-events: auto; /* IMPORTANT: Only polaroids themselves are clickable */
  background: white;
  padding: 12px 12px 30px 12px;
  border-radius: 2px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  width: clamp(260px, 80vw, 320px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform-origin: center;
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Stagger positions specifically */
#quiz-1 {
  top: 15%;
  left: 10%;
  transform: rotate(-5deg);
}

#quiz-2 {
  bottom: 20%;
  right: 10%;
  transform: rotate(7deg);
  z-index: 2;
}

.quiz-polaroid.solved {
  transform: translateY(-20px) scale(0.9) rotate(0deg);
  opacity: 1;
  /* Keep fully visible when solved! */
  pointer-events: none;
}

.quiz-polaroid.solved .btn-minimize {
  pointer-events: auto; /* Allow closing even when solved */
}

.quiz-polaroid.minimized {
  transform: scale(0) rotate(0deg);
  opacity: 0;
  pointer-events: none !important;
}

.btn-minimize {
  position: absolute;
  top: 15px;
  right: 15px;
  width: 35px;
  height: 35px;
  background: white;
  border: none;
  border-radius: 50%;
  font-size: 1.5rem; /* Larger 'X' */
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 50; /* Above all other polaroid children */
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2); /* Enhance depth */
  transition: all 0.2s;
  pointer-events: auto; /* Guarantee touch interaction */
}

.btn-minimize:hover {
  background: var(--accent);
  color: white;
}

.quiz-photo {
  width: 100%;
  aspect-ratio: 4/3;
  background-color: var(--text-main);
  /* Black placeholder */
  background-size: cover;
  background-position: center;
  transition: background-image 0.5s;
}

/* Initially hidden, will be overridden by JS on solve */
.quiz-photo.quiz-photo-hidden {
  background-image: none !important;
}

#quiz-1 .quiz-photo {
  background-image: url('../img/6156929352642269387.jpg');
}

#quiz-2 .quiz-photo {
  background-image: url('../img/6156929352642269389.jpg');
}

.quiz-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.quiz-question {
  font-family: var(--font-handwriting);
  font-size: 1.6rem;
  color: var(--text-main);
  text-align: center;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn-option {
  padding: 8px;
  background: var(--bg-start);
  border: 1px solid var(--envelope-line);
  border-radius: 4px;
  font-family: var(--font-heading);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-option:hover {
  background: var(--accent-soft);
  color: var(--text-main);
}

.btn-option.selected-wrong {
  background: #ffcdd2;
  border-color: #ef5350;
}

.quiz-feedback {
  font-size: 0.8rem;
  text-align: center;
  min-height: 16px;
  color: var(--accent);
}


/* ========================================= */
/* 2. GRATITUDE FORM */
/* ========================================= */
.gratitude-form {
  position: fixed;
  bottom: 0px;
  left: 50%;
  transform: translateX(-50%);
  width: clamp(300px, 90vw, 500px);
  background: white;
  padding: 24px;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
  z-index: 3500;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gratitude-form[hidden] {
  display: flex !important;
  /* Override native hidden */
  transform: translate(-50%, 120%);
}

.gratitude-form h3 {
  font-family: var(--font-handwriting);
  font-size: 2rem;
  color: var(--accent);
  text-align: center;
}

.gratitude-form textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--envelope-line);
  border-radius: 8px;
  font-family: var(--font-heading);
  font-size: 1rem;
  resize: vertical;
  background: var(--bg-start);
  outline: none;
}

.gratitude-form textarea:focus {
  border-color: var(--accent);
}

.btn-send {
  width: 100%;
  margin: 0;
}