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

:root {
  --paper: #fdf6e3;
  --paper-dark: #f5e6c8;
  --ink: #2c1810;
  --ink-light: #5a3a2a;
  --red: #8b2252;
  --red-light: #c45a7d;
  --accent: #d4a574;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'EB Garamond', serif;
  background: #1a0a0a;
  color: var(--ink);
  overflow-x: hidden;
}

/* --- Envelope Opening Screen --- */
#envelope-screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #2a0a0f 0%, #0d0305 100%);
  cursor: pointer;
  transition: opacity 0.8s ease, visibility 0.8s ease;
}

#envelope-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.envelope-container {
  position: relative;
  width: 320px;
  height: 220px;
  perspective: 800px;
}

.envelope {
  position: relative;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--paper-dark), var(--paper));
  border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.envelope::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  background: linear-gradient(135deg, #e8d5b7, #f0e0c8);
  clip-path: polygon(0 0, 50% 80%, 100% 0);
  z-index: 2;
  transform-origin: top center;
  transition: transform 0.6s ease;
}

.envelope-container:hover .envelope::before {
  transform: rotateX(160deg);
}

.envelope-heart {
  position: absolute;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.5rem;
  z-index: 1;
  color: var(--red);
  animation: heartbeat 1.5s ease-in-out infinite;
}

.envelope-text {
  position: absolute;
  bottom: -50px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--paper-dark);
  font-family: 'EB Garamond', serif;
  font-size: 1.4rem;
  white-space: nowrap;
  opacity: 0.8;
  animation: gentle-pulse 2s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  15% { transform: translate(-50%, -50%) scale(1.15); }
  30% { transform: translate(-50%, -50%) scale(1); }
  45% { transform: translate(-50%, -50%) scale(1.1); }
}

@keyframes gentle-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* --- Falling petals --- */
.petal {
  position: fixed;
  width: 12px;
  height: 12px;
  background: var(--red-light);
  border-radius: 50% 0 50% 50%;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

/* --- Main Letter Container --- */
.letter-wrapper {
  max-width: 750px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

/* --- Paper Section --- */
.paper {
  background: linear-gradient(180deg, var(--paper) 0%, #faf0d8 100%);
  padding: 50px 45px;
  margin-bottom: 40px;
  position: relative;
  box-shadow:
    0 1px 1px rgba(0,0,0,0.05),
    0 4px 12px rgba(0,0,0,0.1),
    0 20px 40px rgba(0,0,0,0.15);
  border-radius: 2px;
  opacity: 0;
  transform: translateY(40px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.paper.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Lined paper effect */
.paper.lined {
  background-image:
    linear-gradient(180deg, var(--paper) 0%, #faf0d8 100%),
    repeating-linear-gradient(
      transparent,
      transparent 31px,
      #e8d8c4 31px,
      #e8d8c4 32px
    );
  background-size: 100% 100%, 100% 100%;
  background-blend-mode: normal;
}

.paper.lined::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 70px;
  width: 1px;
  background: rgba(200, 120, 120, 0.25);
}

/* Paper edge effect */
.paper::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.03) 0%, transparent 3%, transparent 97%, rgba(0,0,0,0.03) 100%),
    linear-gradient(180deg, rgba(0,0,0,0.02) 0%, transparent 2%, transparent 98%, rgba(0,0,0,0.03) 100%);
  pointer-events: none;
  border-radius: 2px;
}

/* Tape effect on some papers */
.paper.taped::after {
  content: '';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  width: 100px;
  height: 28px;
  background: rgba(255, 255, 240, 0.5);
  border: 1px solid rgba(200, 200, 180, 0.3);
  border-radius: 2px;
}

/* --- Typography --- */
.date {
  text-align: right;
  font-size: 1.3rem;
  color: var(--ink-light);
  margin-bottom: 30px;
  font-style: italic;
}

.greeting {
  font-family: 'EB Garamond', serif;
  font-style: italic;
  font-size: 2.4rem;
  color: var(--red);
  margin-bottom: 25px;
  font-weight: 600;
}

.letter-body {
  font-size: 1.55rem;
  line-height: 2;
  color: var(--ink);
  text-align: left;
}

.letter-body p {
  margin-bottom: 20px;
  text-indent: 2em;
}

.letter-body p:first-child {
  text-indent: 0;
}

.emphasis {
  color: var(--red);
  font-weight: 600;
  font-size: 1.65rem;
}

.signature {
  text-align: right;
  font-family: 'EB Garamond', serif;
  font-style: italic;
  font-size: 2rem;
  color: var(--red);
  margin-top: 30px;
}

/* --- Section Titles --- */
.section-divider {
  text-align: center;
  padding: 30px 0;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.section-divider.visible {
  opacity: 1;
  transform: translateY(0);
}

.section-divider .ornament {
  color: var(--red-light);
  font-size: 1.8rem;
  letter-spacing: 8px;
}

/* --- Photo Sections --- */
.photo-section {
  display: flex;
  gap: 25px;
  align-items: center;
  margin-bottom: 40px;
  opacity: 0;
  transform: translateY(40px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.photo-section.visible {
  opacity: 1;
  transform: translateY(0);
}

.photo-section.reverse {
  flex-direction: row-reverse;
}

.photo-frame {
  flex: 0 0 260px;
  height: 260px;
  background: var(--paper);
  padding: 10px;
  box-shadow:
    0 3px 15px rgba(0,0,0,0.2),
    inset 0 0 20px rgba(0,0,0,0.05);
  transform: rotate(-2deg);
  position: relative;
}

.photo-section.reverse .photo-frame {
  transform: rotate(2deg);
}

.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #e8ddd0 0%, #ddd0c0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--ink-light);
  font-size: 1.1rem;
}

.photo-placeholder .icon {
  font-size: 2.5rem;
  opacity: 0.4;
}

.photo-placeholder .text {
  font-family: 'EB Garamond', serif;
  opacity: 0.6;
  font-size: 1rem;
}

.photo-caption {
  flex: 1;
  background: linear-gradient(180deg, var(--paper) 0%, #faf0d8 100%);
  padding: 30px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  border-radius: 2px;
}

.photo-caption p {
  font-size: 1.45rem;
  line-height: 1.9;
  color: var(--ink);
}

.photo-caption .caption-title {
  font-family: 'EB Garamond', serif;
  font-style: italic;
  font-size: 1.6rem;
  color: var(--red);
  margin-bottom: 10px;
}

/* --- Promise List --- */
.promises {
  list-style: none;
  padding: 0;
}

.promises li {
  font-size: 1.45rem;
  line-height: 1.8;
  padding: 12px 0 12px 35px;
  position: relative;
  border-bottom: 1px dashed rgba(44, 24, 16, 0.1);
  opacity: 0;
  transform: translateX(-20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.promises li.visible {
  opacity: 1;
  transform: translateX(0);
}

.promises li::before {
  content: '\2665';
  position: absolute;
  left: 5px;
  color: var(--red);
  font-size: 1.2rem;
}

/* --- Final Section --- */
.final-message {
  text-align: center;
  padding: 60px 40px;
  background: linear-gradient(180deg, var(--paper) 0%, #faf0d8 100%);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  border-radius: 2px;
  opacity: 0;
  transform: translateY(40px) scale(0.98);
  transition: opacity 1s ease, transform 1s ease;
}

.final-message.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.final-message .big-heart {
  font-size: 4rem;
  color: var(--red);
  animation: heartbeat 1.5s ease-in-out infinite;
  display: inline-block;
  margin-bottom: 20px;
}

.final-message .final-text {
  font-family: 'EB Garamond', serif;
  font-style: italic;
  font-size: 2.5rem;
  color: var(--red);
  line-height: 1.6;
}

.final-message .sub-text {
  font-size: 1.5rem;
  color: var(--ink-light);
  margin-top: 20px;
  line-height: 1.8;
}

/* --- Background decoration --- */
.bg-hearts {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.bg-heart {
  position: absolute;
  color: rgba(139, 34, 82, 0.06);
  font-size: 2rem;
  animation: float-up linear infinite;
}

@keyframes float-up {
  0% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0;
  }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% {
    transform: translateY(-100px) rotate(360deg);
    opacity: 0;
  }
}

/* --- Music toggle --- */
.music-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  background: var(--paper);
  border: 2px solid var(--red-light);
  color: var(--red);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  font-family: sans-serif;
}

.music-toggle:hover {
  transform: scale(1.1);
}

/* --- Scroll progress --- */
.scroll-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--red), var(--red-light), var(--accent));
  z-index: 999;
  transition: width 0.1s linear;
}

/* --- Responsive --- */
@media (max-width: 700px) {
  .letter-wrapper {
    padding: 20px 10px 60px;
  }

  .paper {
    padding: 30px 25px;
  }

  .paper.lined::after {
    left: 40px;
  }

  .greeting {
    font-size: 2rem;
  }

  .letter-body {
    font-size: 1.35rem;
  }

  .photo-section {
    flex-direction: column !important;
  }

  .photo-frame {
    flex: none;
    width: 100%;
    height: 250px;
    transform: rotate(-1deg) !important;
  }

  .photo-caption {
    width: 100%;
  }

  .final-message .final-text {
    font-size: 2rem;
  }

  .envelope-container {
    width: 260px;
    height: 180px;
  }
}
