/* ============================================================
   letter.css — Section 7: Gravity Falls letter reveal
   ============================================================ */

#section-letter {
  background: var(--color-baby-pink);
  padding: 6rem 2rem;
  text-align: center;
  overflow: hidden;
}

#section-letter .section-header {
  margin-bottom: 1rem;
}

.letter-hint {
  font-family: var(--font-handwritten);
  font-size: 1.1rem;
  color: var(--color-text-light);
  margin-bottom: 3rem;
}

/* ============================================================
   FENCE SCENE
   ============================================================ */
#fence-scene {
  perspective: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  min-height: 340px;
}

/* ---- Fence Gate ---- */
#fence-gate {
  width: clamp(260px, 50vw, 380px);
  position: relative;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  cursor: none;
}

#fence-gate.open {
  transform: rotateY(-115deg);
}

/* The wooden fence panel */
.fence-panel {
  background:
    repeating-linear-gradient(
      90deg,
      var(--color-wood-dark) 0px,
      var(--color-wood-dark) 2px,
      var(--color-wood) 2px,
      var(--color-wood) 40px
    );
  border-radius: var(--radius-sm);
  padding: 1.2rem;
  box-shadow: 4px 6px 20px rgba(100,60,20,0.35);
  position: relative;
  border: 3px solid var(--color-wood-dark);
}

/* Horizontal rails */
.fence-panel::before,
.fence-panel::after {
  content: '';
  position: absolute;
  left: -3px; right: -3px;
  height: 14px;
  background: var(--color-wood-dark);
  border-radius: 4px;
}
.fence-panel::before { top: 22%; }
.fence-panel::after  { top: 62%; }

/* Fence top pickets */
.fence-pickets {
  display: flex;
  gap: 6px;
  margin-bottom: 1rem;
  justify-content: center;
}

.fence-picket {
  width: 28px;
  height: 60px;
  background: var(--color-wood);
  border-radius: 2px 2px 0 0;
  position: relative;
  box-shadow: inset -2px 0 6px rgba(0,0,0,0.15);
}

.fence-picket::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-bottom: 14px solid var(--color-wood);
}

/* ---- Sign ---- */
.fence-sign-wrap {
  background: #f5e6c0;
  border: 2px solid #c8a04a;
  border-radius: 4px;
  padding: 0.8rem 1.4rem;
  display: inline-block;
  box-shadow: 2px 3px 10px rgba(0,0,0,0.2);
  animation: signWiggle 3s ease-in-out infinite;
  position: relative;
  z-index: 2;
}

.fence-sign-main {
  font-family: var(--font-handwritten);
  font-size: 1.6rem;
  color: #5a3a10;
  display: block;
  font-weight: 700;
}

.fence-sign-sub {
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: #8a6a30;
  display: block;
  margin-top: 0.2rem;
}

/* Rope/string from gate to sign */
.fence-sign-rope {
  width: 2px;
  height: 20px;
  background: #8a6a30;
  margin: 0 auto;
}

/* ============================================================
   WADDLES + ENVELOPE (Phase 2)
   ============================================================ */
#waddles-letter {
  display: flex;
  align-items: flex-end;
  gap: 2rem;
  justify-content: center;
  flex-wrap: wrap;
  animation: bounceIn 0.7s var(--transition-bounce) both;
}

.waddles-letter-img {
  width: clamp(100px, 22vw, 160px);
  animation: bob 2.4s ease-in-out infinite;
  filter: drop-shadow(0 6px 18px rgba(233,30,140,0.2));
}

.letter-text-bubble {
  font-family: var(--font-handwritten);
  font-size: 1.2rem;
  color: var(--color-text);
  background: var(--color-white);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 0;
  box-shadow: var(--shadow-card);
  margin-bottom: 1.5rem;
  align-self: flex-start;
  white-space: nowrap;
}

/* ============================================================
   ENVELOPE (CSS drawn)
   ============================================================ */
.envelope-wrap {
  perspective: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.envelope {
  width: clamp(160px, 36vw, 240px);
  height: clamp(110px, 25vw, 170px);
  position: relative;
  cursor: none;
  transform-style: preserve-3d;
  transition: transform 0.3s ease;
}

.envelope:hover {
  transform: scale(1.04) translateY(-4px);
}

/* Envelope body */
.envelope-body {
  position: absolute;
  inset: 0;
  background: var(--color-blush);
  border-radius: 4px;
  box-shadow: var(--shadow-polaroid);
  overflow: hidden;
}

/* V-fold bottom effect */
.envelope-body::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  height: 55%;
  background: linear-gradient(to top, rgba(255,255,255,0.15), transparent);
}

/* Flap — triangle via clip-path */
.envelope-flap {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 55%;
  background: var(--color-blush-dark);
  clip-path: polygon(0 0, 100% 0, 50% 80%);
  transform-origin: top center;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2;
}

.envelope.open .envelope-flap {
  transform: rotateX(-180deg);
}

/* V-lines on body sides */
.envelope-body::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 49.5%, rgba(255,255,255,0.25) 49.5%, rgba(255,255,255,0.25) 50.5%, transparent 50.5%),
    linear-gradient(225deg, transparent 49.5%, rgba(255,255,255,0.25) 49.5%, rgba(255,255,255,0.25) 50.5%, transparent 50.5%);
}

/* Heart seal */
.heart-seal {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
  z-index: 3;
  transition: opacity 0.3s ease, transform 0.3s ease;
  line-height: 1;
  pointer-events: none;
}

.envelope.open .heart-seal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.3);
}

.envelope-cta {
  font-family: var(--font-handwritten);
  font-size: 0.9rem;
  color: var(--color-text-light);
  margin-top: 0.6rem;
  animation: fadeIn 0.5s 0.3s ease both;
}

/* ============================================================
   LETTER (Phase 3)
   ============================================================ */
#letter-content {
  perspective: 900px;
  width: 100%;
  max-width: 640px;
  margin: 2rem auto 0;
}

.letter-wrapper {
  transform-style: preserve-3d;
}

.letter-paper {
  background: #fffdf9;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 40px rgba(180, 100, 120, 0.2);
  padding: 3rem 3rem 2.5rem;
  border: 1px solid rgba(249,192,203,0.4);
  position: relative;
  overflow: hidden;
}

/* Ruled lines */
.letter-paper::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 29px,
    rgba(249,192,203,0.25) 29px,
    rgba(249,192,203,0.25) 30px
  );
  pointer-events: none;
}

.letter-salutation {
  font-family: var(--font-handwritten);
  font-size: 1.4rem;
  color: var(--color-text);
  margin-bottom: 1.2rem;
  display: block;
}

.letter-paragraph {
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--color-text);
  margin-bottom: 1.1rem;
  /* animation applied inline when paragraph is appended to DOM */
  animation: letterTextIn 0.5s ease both;
  position: relative;
  z-index: 1;
}

.letter-closing {
  font-family: var(--font-handwritten);
  font-size: 1.2rem;
  color: var(--color-text);
  display: block;
  margin-top: 1.5rem;
  opacity: 0;
  animation: letterTextIn 0.5s ease both;
}

.letter-signature {
  font-family: var(--font-handwritten);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-rose);
  display: block;
  margin-top: 0.3rem;
  opacity: 0;
  animation: letterTextIn 0.5s ease both;
}

/* Pink wax stamp decoration */
.letter-stamp {
  position: absolute;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 48px;
  height: 48px;
  background: var(--color-rose);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 2px 10px rgba(233,30,140,0.35);
  opacity: 0.8;
}

@media (max-width: 600px) {
  .letter-paper {
    padding: 2rem 1.5rem;
  }

  #waddles-letter {
    gap: 1rem;
  }
}
