/* ==========================================================================
   To My Love — Love Letter Experience Stylesheet
   Color Palette: #C9788A, #E29C9C, #E6BEAE, #EEDAC5, #F5F5DC
   Fonts: 'Alex Brush' & 'Caveat'
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Design Tokens & Color Variables
   -------------------------------------------------------------------------- */
:root {
  /* Swatch Colors from ca971759.jpg */
  --c-puce: #C9788A;
  --c-salmon: #E29C9C;
  --c-dogwood: #E6BEAE;
  --c-almond: #EEDAC5;
  --c-beige: #F5F5DC;

  /* Natural Ink & Contrast */
  --ink-primary: #2C1E23;
  --ink-faded: #4A363D;
  --ink-glow: rgba(201, 120, 138, 0.25);

  /* Kraft Envelope Tones */
  --kraft-base: #C9A075;
  --kraft-dark: #B1885D;
  --kraft-light: #DDB78F;
  --kraft-shadow: rgba(60, 36, 20, 0.25);

  /* Typography */
  --font-script: 'Alex Brush', cursive;
  --font-hand: 'Caveat', cursive, sans-serif;
  --font-ui: 'Outfit', sans-serif;

  /* Shadows */
  --shadow-envelope: 0 16px 45px rgba(65, 38, 30, 0.28), 0 4px 14px rgba(0, 0, 0, 0.08);
  --shadow-letter: 0 24px 60px rgba(50, 30, 36, 0.16), 0 6px 18px rgba(0, 0, 0, 0.05);

  /* Transitions */
  --ease-smooth: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* --------------------------------------------------------------------------
   1. Base Reset & Atmospheric Background
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
}

body {
  font-family: var(--font-hand);
  background-color: #FAF7F2;
  background: radial-gradient(circle at 50% 45%, #FFFFFF 0%, var(--c-beige) 48%, #F2E8DC 85%, #EADAC8 100%);
  color: var(--ink-primary);
  display: flex;
  flex-direction: column;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* Canvas for subtle floating dust/heart particles */
.ambient-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* --------------------------------------------------------------------------
   2. Header Minimalist Plain Dots (Tooltips on hover only)
   -------------------------------------------------------------------------- */
.romantic-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px;
  pointer-events: none;
}

.romantic-header button {
  pointer-events: auto;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Minimal Plain Dot Buttons */
.plain-dot-btn {
  position: relative;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  outline: none;
}

/* The actual colored dot */
.plain-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--c-puce);
  opacity: 0.72;
  box-shadow: 0 2px 6px rgba(201, 120, 138, 0.35);
  transition: all 0.25s var(--ease-smooth);
}

.plain-dot-btn:hover .plain-dot {
  transform: scale(1.45);
  opacity: 1;
  background-color: var(--c-puce);
  box-shadow: 0 0 14px rgba(201, 120, 138, 0.75), 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Active glowing state for sound */
.plain-dot-btn.active .plain-dot {
  opacity: 1;
  box-shadow: 0 0 12px var(--c-puce);
  animation: pulseDot 2s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 8px rgba(201, 120, 138, 0.5);
  }
  50% {
    transform: scale(1.3);
    box-shadow: 0 0 18px rgba(201, 120, 138, 0.85);
  }
}

/* Floating Tooltip Pill (Revealed only on mouse hover) */
.dot-tooltip {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: rgba(44, 30, 35, 0.92);
  color: #FFFFFF;
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 9999px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(4px);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
  z-index: 100;
}

.header-right .dot-tooltip {
  left: auto;
  right: 0;
  transform: translateY(4px);
}

.plain-dot-btn:hover .dot-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(8px);
}

.header-right .plain-dot-btn:hover .dot-tooltip {
  transform: translateY(8px);
}

/* --------------------------------------------------------------------------
   3. Main Stage Container
   -------------------------------------------------------------------------- */
.letter-stage {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px 80px;
  position: relative;
  z-index: 10;
  min-height: 100vh;
}

.stage-inner {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* --------------------------------------------------------------------------
   4. Sealed Kraft Envelope Scene
   -------------------------------------------------------------------------- */
.envelope-scene {
  perspective: 1200px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  transition: opacity 0.6s var(--ease-smooth), transform 0.6s var(--ease-smooth);
}

.envelope-scene.fade-out {
  opacity: 0;
  transform: scale(0.92);
  pointer-events: none;
}

.envelope-wrapper {
  position: relative;
  width: 480px;
  max-width: 90vw;
  height: 310px;
  cursor: pointer;
  outline: none;
  animation: floatEnvelope 5s ease-in-out infinite;
}

@keyframes floatEnvelope {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

.envelope {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--kraft-base);
  background-image: url('assets/envelope-texture.svg'), linear-gradient(135deg, var(--kraft-light), var(--kraft-dark));
  background-size: cover;
  background-position: center;
  border-radius: 8px;
  box-shadow: var(--shadow-envelope);
  transform-style: preserve-3d;
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.envelope-wrapper:hover .envelope {
  box-shadow: 0 24px 55px rgba(65, 38, 30, 0.35), 0 0 30px rgba(226, 156, 156, 0.3);
  transform: scale(1.02);
}

.envelope-back {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #A67E55;
  border-radius: 8px;
  z-index: 1;
}

.envelope-paper-preview {
  position: absolute;
  top: 15px;
  left: 20px;
  right: 20px;
  height: 275px;
  background-color: var(--c-beige);
  background-image: url('assets/paper-texture.svg');
  background-size: cover;
  border-radius: 6px;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.12);
  z-index: 2;
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.envelope-flap {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
}

.flap-left {
  z-index: 3;
  clip-path: polygon(0% 0%, 50% 50%, 0% 100%);
  background: #C49B71;
  border-radius: 8px 0 0 8px;
  box-shadow: inset -2px 0 8px rgba(70, 40, 20, 0.12);
}

.flap-right {
  z-index: 3;
  clip-path: polygon(100% 0%, 50% 50%, 100% 100%);
  background: #C49B71;
  border-radius: 0 8px 8px 0;
  box-shadow: inset 2px 0 8px rgba(70, 40, 20, 0.12);
}

.flap-bottom {
  z-index: 4;
  clip-path: polygon(0% 100%, 50% 48%, 100% 100%);
  background: #CFA579;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 -4px 12px rgba(70, 40, 20, 0.15);
}

.flap-top {
  z-index: 5;
  clip-path: polygon(0% 0%, 50% 55%, 100% 0%);
  background: #D4AB7E;
  border-radius: 8px 8px 0 0;
  transform-origin: top center;
  transition: transform 0.75s cubic-bezier(0.4, 0, 0.2, 1), z-index 0.2s 0.35s;
  box-shadow: 0 6px 14px rgba(70, 40, 20, 0.2);
}

.envelope.is-opening .flap-top {
  transform: rotateX(180deg);
  z-index: 1;
}

.envelope.is-opening .envelope-paper-preview {
  transform: translateY(-10px);
  opacity: 0.85;
}

/* Floating "click to open" Cursive Script */
.envelope-seal-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.envelope-seal-text span {
  font-family: var(--font-script);
  font-size: 2.85rem;
  color: var(--ink-primary);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6), 0 2px 10px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  display: inline-block;
  animation: floatClickToOpen 3.2s ease-in-out infinite;
}

@keyframes floatClickToOpen {
  0%, 100% {
    transform: translateY(0) rotate(-0.8deg);
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.12), 0 0 14px rgba(226, 156, 156, 0.4);
  }
  50% {
    transform: translateY(-9px) rotate(1deg);
    text-shadow: 0 8px 18px rgba(0, 0, 0, 0.2), 0 0 24px rgba(201, 120, 138, 0.7);
  }
}

.envelope-wrapper:hover .envelope-seal-text span {
  color: #1F1518;
}

.envelope.is-opening .envelope-seal-text {
  opacity: 0;
  transform: translate(-50%, -60%) scale(0.9);
}

.wax-seal {
  display: none;
}

/* --------------------------------------------------------------------------
   5. The Unfolded Crumpled Letter Sheet (Pre-sized, Text Never Cut)
   -------------------------------------------------------------------------- */
.letter-sheet-container {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  opacity: 0;
  transform: translateY(30px) scale(0.96);
  transition: opacity 0.8s var(--ease-smooth), transform 0.8s var(--ease-smooth);
}

.letter-sheet-container.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.letter-sheet {
  position: relative;
  width: 100%;
  min-height: 540px;
  height: auto;
  background-color: #FAF6EF;
  background-image: url('assets/paper-texture.svg');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 4px;
  padding: 50px 60px 55px;
  box-shadow: var(--shadow-letter);
  border: 1px solid rgba(230, 190, 174, 0.4);
  transform: rotate(-0.35deg);
  box-sizing: border-box;
  transition: transform 0.3s ease;
}

.sheet-texture-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.35) 0%, rgba(238, 218, 197, 0.15) 100%);
  pointer-events: none;
}

.letter-content {
  position: relative;
  z-index: 2;
}

/* Handwritten Text Body (Caveat) - Generously spaced, never cut */
.handwritten-body {
  font-family: var(--font-hand);
  font-size: 1.55rem;
  font-weight: 500;
  line-height: 1.82;
  color: var(--ink-primary);
  text-align: left;
  letter-spacing: 0.2px;
  word-spacing: 2px;
  text-shadow: 0 0 1px rgba(44, 30, 35, 0.2);
}

/* --------------------------------------------------------------------------
   6. Bottom-Right Sign-off ("to my love" fixed in bottom right corner)
   -------------------------------------------------------------------------- */
.romantic-footer {
  position: fixed;
  bottom: 24px;
  right: 32px;
  z-index: 50;
  pointer-events: none;
}

.signature-text {
  font-family: var(--font-script);
  font-size: 3.2rem;
  color: var(--ink-primary);
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.9), 0 1px 4px rgba(201, 120, 138, 0.2);
  letter-spacing: -0.5px;
  user-select: none;
  display: inline-block;
  padding-right: 20px; /* guarantees cursive swash on 'e' is never clipped */
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   7. Responsive Design (Mobile & Tablet)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .romantic-header {
    padding: 16px 20px;
  }

  .envelope-wrapper {
    height: 250px;
  }

  .envelope-seal-text span {
    font-size: 2.3rem;
  }

  .letter-stage {
    padding: 60px 16px 80px;
  }

  .letter-sheet {
    padding: 36px 24px 44px;
    min-height: 520px;
    transform: rotate(0deg);
  }

  .handwritten-body {
    font-size: 1.35rem;
    line-height: 1.75;
  }

  .romantic-footer {
    bottom: 16px;
    right: 20px;
  }

  .signature-text {
    font-size: 2.5rem;
    padding-right: 14px;
  }
}

@media (max-width: 480px) {
  .envelope-wrapper {
    height: 220px;
  }

  .envelope-seal-text span {
    font-size: 2rem;
  }

  .letter-sheet {
    padding: 28px 18px 36px;
    min-height: 500px;
  }

  .handwritten-body {
    font-size: 1.25rem;
    line-height: 1.7;
  }

  .romantic-footer {
    bottom: 12px;
    right: 16px;
  }

  .signature-text {
    font-size: 2.2rem;
    padding-right: 10px;
  }
}
