/* ============================================================
   ROMANTIC LOVE LETTER — Custom Styles
   ============================================================ */

/* ── Base & Scrolling ──────────────────────────────────────── */
html {
  scroll-behavior: smooth;
}

body {
  background: linear-gradient(
    180deg,
    #FDF2F8 0%,
    #FFF1F2 30%,
    #FFF8F0 60%,
    #FDF2F8 100%
  );
  background-attachment: fixed;
}

::selection {
  background: rgba(244, 114, 182, 0.3);
  color: #831843;
}

/* ── Paper Container ───────────────────────────────────────── */
.paper {
  background-color: #FFF8F0;
  background-image:
    /* Faint ruled lines */
    repeating-linear-gradient(
      transparent,
      transparent 35px,
      rgba(219, 39, 119, 0.04) 35px,
      rgba(219, 39, 119, 0.04) 36px
    );
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.04),
    0 8px 32px rgba(0, 0, 0, 0.06),
    0 0 80px rgba(219, 39, 119, 0.04),
    /* Paper edge effect */
    inset 0 0 60px rgba(255, 248, 240, 0.5);
  position: relative;
  overflow: hidden;
}

/* Subtle paper grain texture */
.paper::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  pointer-events: none;
  border-radius: inherit;
}

/* Left margin line (like a real notebook) */
.paper::after {
  content: '';
  position: absolute;
  left: 48px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(219, 39, 119, 0.06);
  pointer-events: none;
}

@media (max-width: 768px) {
  .paper::after {
    left: 24px;
  }
}

/* ── Polaroid / Scrapbook Photos ───────────────────────────── */
.polaroid {
  background: white;
  padding: 10px 10px 36px 10px;
  box-shadow:
    2px 4px 12px rgba(0, 0, 0, 0.1),
    0 1px 3px rgba(0, 0, 0, 0.06);
  border-radius: 2px;
  max-width: 280px;
  display: inline-block;
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              box-shadow 0.4s ease;
  /* Hidden by default — GSAP reveals */
  visibility: hidden;
}

.polaroid:hover {
  box-shadow:
    4px 8px 24px rgba(0, 0, 0, 0.15),
    0 2px 6px rgba(0, 0, 0, 0.08);
}

.polaroid img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 1px;
}

.polaroid-caption {
  padding-top: 4px;
  line-height: 1.4;
}

/* Tape effect */
.polaroid.taped::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  width: 60px;
  height: 22px;
  background: rgba(255, 248, 220, 0.7);
  border: 1px solid rgba(200, 180, 120, 0.2);
  border-radius: 2px;
  z-index: 2;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.polaroid {
  position: relative;
}

/* Rotation classes */
.tilt-left {
  --tilt: -3deg;
  transform: rotate(-3deg);
}

.tilt-right {
  --tilt: 3deg;
  transform: rotate(3deg);
}

.tilt-slight {
  --tilt: 1.5deg;
  transform: rotate(1.5deg);
}

/* ── GIF Memory Frame ──────────────────────────────────────── */
.gif-frame {
  max-width: 380px;
  padding: 8px;
  border-radius: 8px;
  background: linear-gradient(135deg, #F6E05E, #CA8A04, #F6E05E, #CA8A04);
  background-size: 300% 300%;
  animation: shimmer-gold 4s ease-in-out infinite;
  box-shadow:
    0 4px 20px rgba(202, 138, 4, 0.2),
    0 0 40px rgba(246, 224, 94, 0.1);
  /* Hidden by default — GSAP reveals */
  visibility: hidden;
}

.gif-frame img {
  display: block;
  border-radius: 4px;
}

@keyframes shimmer-gold {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* ── Letter Paragraphs (hidden for GSAP reveal) ───────────── */
.letter-paragraph {
  visibility: hidden;
}

/* ── Glowing Heart ─────────────────────────────────────────── */
.glowing-heart {
  animation: heartbeat 2s ease-in-out infinite;
  filter: drop-shadow(0 0 8px rgba(219, 39, 119, 0.4));
}

@keyframes heartbeat {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 0 8px rgba(219, 39, 119, 0.4));
  }
  15% {
    transform: scale(1.1);
    filter: drop-shadow(0 0 20px rgba(244, 114, 182, 0.6));
  }
  30% {
    transform: scale(1);
    filter: drop-shadow(0 0 8px rgba(219, 39, 119, 0.4));
  }
  45% {
    transform: scale(1.06);
    filter: drop-shadow(0 0 16px rgba(244, 114, 182, 0.5));
  }
}

/* ── Floating Love Notes ───────────────────────────────────── */
.love-note {
  position: fixed;
  z-index: 30;
  background: linear-gradient(135deg, #FFF1F2, #FDF2F8);
  border: 1px solid rgba(244, 114, 182, 0.2);
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 140px;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.06),
    0 0 20px rgba(244, 114, 182, 0.05);
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  animation: float 4s ease-in-out infinite;
  animation-delay: var(--float-delay, 0s);
}

.love-note:nth-child(1) { --float-delay: 0s; }
.love-note:nth-child(2) { --float-delay: 0.8s; }
.love-note:nth-child(3) { --float-delay: 1.6s; }
.love-note:nth-child(4) { --float-delay: 2.4s; }
.love-note:nth-child(5) { --float-delay: 3.2s; }

.love-note .note-preview {
  font-family: 'Caveat', cursive;
  font-size: 1.1rem;
  color: #DB2777;
  font-weight: 600;
  text-align: center;
}

.love-note .note-full {
  display: none;
  font-family: 'Quicksand', sans-serif;
  font-size: 0.75rem;
  color: #831843;
  line-height: 1.5;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(244, 114, 182, 0.2);
}

.love-note.expanded {
  max-width: 220px;
  background: linear-gradient(135deg, #FFFFFF, #FDF2F8);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.1),
    0 0 30px rgba(244, 114, 182, 0.1);
  z-index: 35;
  animation-play-state: paused;
}

.love-note.expanded .note-full {
  display: block;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0) rotate(var(--note-rotation, 0deg));
  }
  50% {
    transform: translateY(-12px) rotate(var(--note-rotation, 0deg));
  }
}

/* ── Mobile Inline Love Notes (horizontal scroll) ──────────── */
.love-notes-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 4px 16px 4px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  /* Hide scrollbar but keep scrollable */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.love-notes-scroll::-webkit-scrollbar {
  display: none;
}

.love-note-inline {
  flex: 0 0 auto;
  width: 130px;
  min-height: 60px;
  background: linear-gradient(135deg, #FFF1F2, #FDF2F8);
  border: 1px solid rgba(244, 114, 182, 0.25);
  border-radius: 14px;
  padding: 14px 12px;
  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.05),
    0 0 16px rgba(244, 114, 182, 0.06);
  cursor: pointer;
  scroll-snap-align: center;
  transition: all 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transform: rotate(var(--note-rotation, 0deg));
  -webkit-tap-highlight-color: transparent;
}

.love-note-inline .note-preview {
  font-family: 'Caveat', cursive;
  font-size: 1.1rem;
  color: #DB2777;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}

.love-note-inline .note-full {
  display: none;
  font-family: 'Quicksand', sans-serif;
  font-size: 0.72rem;
  color: #831843;
  line-height: 1.5;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(244, 114, 182, 0.2);
  text-align: center;
}

.love-note-inline.expanded {
  width: 200px;
  background: linear-gradient(135deg, #FFFFFF, #FDF2F8);
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.1),
    0 0 24px rgba(244, 114, 182, 0.1);
  transform: rotate(0deg) scale(1.03);
}

.love-note-inline.expanded .note-full {
  display: block;
}

/* ── Music Button ──────────────────────────────────────────── */
.music-btn {
  border: 2px solid rgba(244, 114, 182, 0.2);
}

.music-btn.playing {
  animation: music-pulse 2s ease-in-out infinite;
  border-color: rgba(219, 39, 119, 0.3);
}

@keyframes music-pulse {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 0 0 0 0 rgba(219, 39, 119, 0);
  }
  50% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 0 0 20px 4px rgba(219, 39, 119, 0.15);
  }
}

/* ── Cursor Trail Hearts ───────────────────────────────────── */
.trail-heart {
  position: fixed;
  pointer-events: none;
  z-index: 45;
  font-size: 14px;
  color: #F472B6;
  user-select: none;
}

/* ── Handwriting Cursor ────────────────────────────────────── */
.writing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #DB2777;
  margin-left: 2px;
  animation: cursor-blink 0.8s ease-in-out infinite;
  vertical-align: text-bottom;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Handwriting characters hidden by default */
.hw-char {
  opacity: 0;
  /* MUST stay inline (not inline-block) so text wraps naturally within the paper */
}

/* Letter paragraphs need to contain their text */
.letter-paragraph {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Paragraph writing cursor — positioned inline at end of text */
.para-cursor {
  display: inline-block;
  width: 2px;
  height: 0.9em;
  vertical-align: text-bottom;
  margin-left: 1px;
}

/* ── Closing Text ──────────────────────────────────────────── */
#closing-text {
  visibility: hidden;
}

/* ── Photo Lightbox Overlay ─────────────────────────────────── */
#photo-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px);
  pointer-events: none;
  transition: background 0.4s ease, backdrop-filter 0.4s ease;
}

#photo-overlay.active {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
  pointer-events: all;
  cursor: pointer;
}

/* ── Expanded photos ── */
.expanded-photo-clone {
  /* Position set by JS after measuring — do NOT set left/top/transform here */
  position: absolute;
  background: white;
  padding: 10px 10px 40px 10px;
  border-radius: 3px;
  box-shadow: 0 0 30px rgba(219,39,119,0.12), 0 12px 40px rgba(0,0,0,0.25);
  visibility: visible !important;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* Single photo — larger */
.expanded-photo-clone:not(.scattered) {
  max-width: 85vw;
  padding: 12px 12px 44px 12px;
}

/* Scattered (multi-photo) — smaller so they fit side by side */
.expanded-photo-clone.scattered {
  max-width: 40vw;
}

.expanded-photo-clone img {
  max-width: 100%;
  max-height: 65vh;
  width: auto;
  height: auto;
  display: block;
  border-radius: 2px;
  pointer-events: none; /* so drag works on the image too */
}

.expanded-photo-clone.scattered img {
  max-height: 50vh;
}

.expanded-photo-clone .polaroid-caption {
  text-align: center;
  padding-top: 6px;
  font-size: 0.85rem;
  color: #7C6F64;
  font-family: 'Quicksand', sans-serif;
  pointer-events: none;
}

/* Lift effect when dragging */
.expanded-photo-clone:active {
  box-shadow: 0 0 40px rgba(219,39,119,0.2), 0 24px 60px rgba(0,0,0,0.35) !important;
}

@media (max-width: 768px) {
  .expanded-photo-clone.scattered {
    max-width: 52vw;
    padding: 6px 6px 28px 6px;
  }
  .expanded-photo-clone.scattered img {
    max-height: 35vh;
  }
  .expanded-photo-clone:not(.scattered) {
    max-width: 90vw;
    padding: 8px 8px 36px 8px;
  }
  .expanded-photo-clone:not(.scattered) img {
    max-height: 60vh;
  }
}

.overlay-close-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Quicksand', sans-serif;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.1em;
  opacity: 0;
  transition: opacity 0.5s ease 0.5s;
  pointer-events: auto;
  z-index: 1;
}

#photo-overlay.active .overlay-close-hint {
  opacity: 1;
}

/* Prevent scroll when photo is expanded */
body.photo-expanded {
  overflow: hidden;
}

/* Make photos look clickable on hover */
.polaroid:hover, .gif-frame:hover {
  transform: scale(1.03);
  transition: transform 0.2s ease;
}

/* ── Replay Button Extra ───────────────────────────────────── */
#replay-btn::before {
  content: '↑ ';
}

/* ── Reduced Motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .letter-paragraph,
  .polaroid,
  .gif-frame,
  #closing-text,
  .hw-char,
  .close-char {
    visibility: visible !important;
    opacity: 1 !important;
  }

  .love-note {
    animation: none;
  }

  .glowing-heart {
    animation: none;
    filter: drop-shadow(0 0 8px rgba(219, 39, 119, 0.4));
  }

  html {
    scroll-behavior: auto;
  }
}

/* (music-active indicator removed — now using lightbox click model) */

/* ── Responsive Tweaks ─────────────────────────────────────── */

/* Tablet */
@media (max-width: 768px) {
  .paper {
    margin-left: 8px !important;
    margin-right: 8px !important;
    padding: 2.5rem 1.5rem !important;
  }

  /* Remove margin line on small screens */
  .paper::after {
    display: none;
  }

  .polaroid {
    max-width: 55vw;
    padding: 6px 6px 24px 6px;
  }

  .polaroid.taped::before {
    width: 45px;
    height: 18px;
  }

  .photo-pair {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }

  .photo-pair .polaroid {
    margin-right: 0 !important;
    margin-left: 0 !important;
    margin-top: 0 !important;
    max-width: 65vw;
  }

  .gif-frame {
    max-width: 85vw;
  }

  .photo-cluster {
    gap: 8px;
  }

  .photo-cluster .polaroid {
    max-width: 100%;
  }

  /* Music button bigger on mobile for easy tapping */
  #music-toggle {
    width: 48px;
    height: 48px;
    bottom: 12px;
    right: 12px;
  }

  /* Desktop love notes already hidden via Tailwind hidden lg:block */

  .letter-paragraph {
    font-size: 1.15rem !important;
    line-height: 1.75;
  }
}

/* Phone */
@media (max-width: 480px) {
  body {
    /* Prevent any horizontal overflow */
    overflow-x: hidden;
  }

  .paper {
    margin: 4px !important;
    padding: 1.5rem 1rem !important;
    border-radius: 0;
    box-shadow:
      0 2px 8px rgba(0, 0, 0, 0.04),
      0 4px 16px rgba(0, 0, 0, 0.04);
  }

  #handwriting-title {
    font-size: 1.8rem;
  }

  .letter-paragraph {
    font-size: 1.05rem !important;
    line-height: 1.7;
    margin-bottom: 2rem !important;
  }

  .polaroid {
    max-width: 70vw;
    padding: 4px 4px 20px 4px;
  }

  .polaroid-caption {
    font-size: 0.7rem !important;
  }

  .photo-pair .polaroid {
    max-width: 75vw;
  }

  .gif-frame {
    max-width: 90vw;
    padding: 5px;
  }

  .photo-cluster {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .photo-cluster .polaroid {
    max-width: 75vw;
    margin: 0 auto;
  }

  .photo-cluster .polaroid.tilt-slight {
    max-width: 80vw !important;
  }

  #closing-text {
    font-size: 1.5rem !important;
  }

  .glowing-heart {
    width: 56px !important;
    height: 56px !important;
  }

  #replay-btn {
    padding: 12px 24px;
    font-size: 0.75rem;
  }

}
