/* =========================================================
   CARTA ETERNA – Stylesheet
   ========================================================= */

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

:root {
  --paper-light: #f7edd8;
  --paper-mid: #ede0c4;
  --paper-dark: #d9c9a8;
  --ink: #2c1a0e;
  --ink-faded: #5c3d2e;
  --wax: #8B1A1A;
  --gold: #b8860b;
  --gold-light: #d4a843;
  --shadow: rgba(30, 15, 5, 0.45);
  --vignette: rgba(20, 10, 3, 0.72);
  --font-script: 'Dancing Script', cursive;
  --font-serif: 'IM Fell English', serif;
  --font-elegant: 'Cormorant Garamond', serif;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background-color: #1a0e05;
  background-image:
    /* Warm lamp light center glow */
    radial-gradient(ellipse 80% 60% at 50% 30%, rgba(255, 210, 120, 0.15) 0%, transparent 70%),
    /* Paper-like noise texture via SVG filter reference */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='400' height='400' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
  font-family: var(--font-elegant);
  color: var(--ink);
  overflow-x: hidden;
  position: relative;
}

/* ---------- Vignette ---------- */
.vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 90% 90% at 50% 50%,
      transparent 30%,
      rgba(10, 5, 0, 0.5) 65%,
      rgba(5, 2, 0, 0.85) 100%);
  z-index: 1000;
}

/* ---------- Dust Particles ---------- */
.dust-container {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  overflow: hidden;
}

.dust {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 220, 140, 0.5);
  animation: floatDust linear infinite;
}

@keyframes floatDust {
  0%   { transform: translateY(100vh) translateX(0) scale(1); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 0.6; }
  100% { transform: translateY(-10vh) translateX(var(--drift)) scale(0.4); opacity: 0; }
}

/* ---------- Action Bar ---------- */
.action-bar {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  z-index: 2000;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.6s 0.5s, transform 0.6s 0.5s;
}

.action-bar.visible {
  opacity: 1;
  transform: translateY(0);
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(247, 237, 216, 0.12);
  border: 1px solid rgba(184, 134, 11, 0.35);
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  color: var(--gold-light);
  font-family: var(--font-elegant);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  backdrop-filter: blur(6px);
  transition: background 0.3s, border-color 0.3s, transform 0.2s;
}

.action-btn:hover {
  background: rgba(247, 237, 216, 0.22);
  border-color: rgba(212, 168, 67, 0.6);
  transform: translateY(-2px);
}

.action-btn .icon {
  font-size: 1.1rem;
  line-height: 1;
}

.action-btn.active {
  background: rgba(184, 134, 11, 0.25);
  border-color: var(--gold);
  color: var(--gold);
}

/* ---------- Scenes ---------- */
.scene {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 2rem 1rem;
  transition: opacity 0.8s;
}

.scene.hidden {
  display: none;
}

.scene-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5rem;
}

/* ---------- Pre-title ---------- */
.pre-title {
  font-family: var(--font-script);
  color: rgba(247, 237, 216, 0.5);
  font-size: clamp(0.85rem, 2.5vw, 1.1rem);
  letter-spacing: 0.12em;
  text-align: center;
  animation: fadeSlideDown 1.5s ease 0.3s both;
}

@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Envelope Wrapper ---------- */
.envelope-wrapper {
  position: relative;
  animation: fadeSlideDown 1.5s ease 0.6s both;
}

/* ---------- Wax Seal ---------- */
.wax-seal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70px;
  height: 70px;
  z-index: 30;
  filter: drop-shadow(0 3px 8px rgba(100, 10, 10, 0.7));
  transition: transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s;
  cursor: pointer;
}

.wax-seal.broken {
  transform: translate(-50%, -100%) rotate(-25deg) scale(0.7);
  opacity: 0;
}

/* ---------- Envelope ---------- */
.envelope {
  width: clamp(260px, 70vw, 420px);
  position: relative;
}

/* Envelope flap (top triangle) */
.envelope-flap {
  width: 0;
  height: 0;
  border-left: calc(clamp(260px, 70vw, 420px) / 2) solid transparent;
  border-right: calc(clamp(260px, 70vw, 420px) / 2) solid transparent;
  border-bottom: calc(clamp(260px, 70vw, 420px) * 0.42) solid #c9a96e;
  position: relative;
  z-index: 20;
  transform-origin: top center;
  transition: transform 0.9s cubic-bezier(0.4, 0, 0.2, 1);
  filter: drop-shadow(0 -2px 4px rgba(0,0,0,0.3));
}

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

/* Envelope body */
.envelope-body {
  background: linear-gradient(160deg, #d4aa6a 0%, #c9986a 40%, #b8875a 100%);
  border: 1px solid #a0713a;
  border-top: none;
  min-height: calc(clamp(260px, 70vw, 420px) * 0.65);
  position: relative;
  box-shadow:
    0 8px 30px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,220,140,0.2),
    inset 0 -1px 0 rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* V-lines inside envelope body */
.envelope-lines {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom right, transparent calc(50% - 1px), rgba(0,0,0,0.1) calc(50%), transparent calc(50% + 1px)),
    linear-gradient(to bottom left, transparent calc(50% - 1px), rgba(0,0,0,0.1) calc(50%), transparent calc(50% + 1px));
}

/* Address text */
.envelope-address {
  z-index: 10;
  text-align: center;
}

.address-to {
  font-family: var(--font-script);
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  color: rgba(44, 26, 14, 0.75);
  letter-spacing: 0.05em;
}

.address-heart {
  font-size: 1.2rem;
  color: rgba(139, 26, 26, 0.65);
  margin-top: 0.3rem;
}

/* ---------- Open Button ---------- */
.open-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  background: transparent;
  border: 1.5px solid rgba(184, 134, 11, 0.55);
  border-radius: 40px;
  padding: 0.9rem 2.5rem;
  cursor: pointer;
  color: #d4a843;
  font-family: var(--font-script);
  font-size: clamp(1.1rem, 3vw, 1.45rem);
  letter-spacing: 0.06em;
  transition: all 0.35s;
  animation: fadeSlideDown 1.5s ease 1s both;
  position: relative;
  overflow: hidden;
}

.open-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(212,168,67,0.15) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.4s;
}

.open-btn:hover::before { opacity: 1; }
.open-btn:hover {
  border-color: rgba(212, 168, 67, 0.9);
  color: #f0c060;
  transform: scale(1.03);
  box-shadow: 0 0 25px rgba(184, 134, 11, 0.2);
}

.open-btn-text {
  display: block;
}

.open-btn-sub {
  display: block;
  font-size: 0.7rem;
  font-family: var(--font-elegant);
  letter-spacing: 0.2em;
  color: rgba(212, 168, 67, 0.55);
  font-style: italic;
}

/* ---------- Letter Scene ---------- */
#letterScene {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 3rem;
  padding-bottom: 4rem;
}

/* ---------- Customization Panel ---------- */
.custom-panel {
  width: min(90vw, 520px);
  background: rgba(25, 12, 3, 0.7);
  border: 1px solid rgba(184, 134, 11, 0.25);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  backdrop-filter: blur(8px);
  margin-bottom: 1.5rem;
  animation: fadeIn 0.8s ease both;
}

.custom-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: flex-end;
}

.custom-fields label {
  flex: 1 1 130px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-family: var(--font-elegant);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(212, 168, 67, 0.7);
}

.custom-fields input {
  background: rgba(247, 237, 216, 0.08);
  border: 1px solid rgba(184, 134, 11, 0.3);
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  color: var(--paper-light);
  font-family: var(--font-script);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.3s, background 0.3s;
}

.custom-fields input:focus {
  border-color: var(--gold-light);
  background: rgba(247, 237, 216, 0.13);
}

.apply-btn {
  background: rgba(184, 134, 11, 0.25);
  border: 1px solid rgba(184, 134, 11, 0.5);
  border-radius: 8px;
  padding: 0.5rem 1.2rem;
  color: var(--gold-light);
  font-family: var(--font-script);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  white-space: nowrap;
}

.apply-btn:hover {
  background: rgba(184, 134, 11, 0.4);
  border-color: var(--gold);
  transform: scale(1.02);
}

/* ---------- Letter Container ---------- */
.letter-container {
  width: min(92vw, 580px);
  perspective: 1200px;
  animation: unfoldLetter 1.2s cubic-bezier(0.23, 1, 0.32, 1) both;
}

@keyframes unfoldLetter {
  from {
    opacity: 0;
    transform: rotateX(-30deg) translateY(40px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: rotateX(0) translateY(0) scale(1);
  }
}

/* ---------- Letter Paper ---------- */
.letter-paper {
  background:
    /* Subtle aged spots */
    radial-gradient(ellipse 40% 30% at 15% 20%, rgba(180, 140, 80, 0.12) 0%, transparent 100%),
    radial-gradient(ellipse 30% 20% at 80% 70%, rgba(160, 120, 60, 0.1) 0%, transparent 100%),
    radial-gradient(ellipse 20% 15% at 60% 15%, rgba(180, 150, 90, 0.08) 0%, transparent 100%),
    /* Base paper gradient */
    linear-gradient(175deg, #f4e8ca 0%, #ecdcb5 30%, #e8d5aa 60%, #e0cc9e 100%);

  border: 1px solid rgba(160, 113, 58, 0.4);
  border-radius: 2px;
  padding: clamp(2rem, 6vw, 3.5rem) clamp(1.8rem, 6vw, 3.5rem);
  position: relative;
  box-shadow:
    0 4px 8px rgba(0,0,0,0.12),
    0 12px 35px rgba(0,0,0,0.35),
    0 30px 80px rgba(0,0,0,0.25),
    inset 0 0 60px rgba(180, 140, 60, 0.08),
    inset 0 0 0 1px rgba(255, 230, 160, 0.25);

  /* Torn/worn edges illusion */
  filter: url(#paperFilter);
}

/* Aged paper corners */
.letter-paper::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 2px;
  background:
    radial-gradient(ellipse 25% 15% at 0% 0%, rgba(140, 100, 40, 0.25) 0%, transparent 100%),
    radial-gradient(ellipse 20% 12% at 100% 0%, rgba(130, 90, 35, 0.2) 0%, transparent 100%),
    radial-gradient(ellipse 25% 15% at 0% 100%, rgba(120, 85, 30, 0.22) 0%, transparent 100%),
    radial-gradient(ellipse 20% 12% at 100% 100%, rgba(130, 90, 35, 0.2) 0%, transparent 100%);
  pointer-events: none;
}

/* Horizontal ruled lines (subtle) */
.letter-paper::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 31px,
    rgba(160, 120, 60, 0.1) 31px,
    rgba(160, 120, 60, 0.1) 32px
  );
  border-radius: 2px;
  pointer-events: none;
}

/* ---------- Letter Typography ---------- */
.letter-flourish {
  text-align: center;
  color: rgba(130, 90, 40, 0.5);
  font-size: 1.5rem;
  line-height: 1;
  user-select: none;
}

.top-flourish { margin-bottom: 1.2rem; }
.bottom-flourish { margin-top: 1.5rem; }

.letter-date {
  font-family: var(--font-script);
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  color: var(--ink-faded);
  text-align: right;
  margin-bottom: 1.8rem;
  opacity: 0;
  transition: opacity 0.8s;
  font-style: italic;
}

.letter-salutation {
  font-family: var(--font-script);
  font-size: clamp(1.4rem, 4vw, 1.8rem);
  color: var(--ink);
  margin-bottom: 1.2rem;
  opacity: 0;
  transition: opacity 0.8s 0.3s;
}

.letter-body {
  font-family: var(--font-serif);
  font-size: clamp(0.92rem, 2.4vw, 1.05rem);
  line-height: 1.95;
  color: var(--ink);
  text-align: justify;
  hyphens: auto;
  min-height: 4rem;
  white-space: pre-wrap;
}

.letter-body .cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--ink-faded);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: blink 0.85s step-end infinite;
}

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

/* Paragraph spacing inside letter-body */
.letter-para {
  margin-bottom: 1.1em;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.7s, transform 0.7s;
}

.letter-para.revealed {
  opacity: 1;
  transform: translateY(0);
}

.letter-closing {
  margin-top: 2rem;
  font-family: var(--font-serif);
  font-size: clamp(0.9rem, 2.3vw, 1rem);
  color: var(--ink-faded);
  font-style: italic;
  line-height: 1.8;
  opacity: 0;
  transition: opacity 0.9s;
}

.closing-phrase {
  font-family: var(--font-script);
  font-size: clamp(1.2rem, 3.5vw, 1.5rem);
  color: var(--wax);
  margin-top: 0.6rem;
  font-style: normal;
}

.letter-signature {
  margin-top: 1.2rem;
  font-family: var(--font-script);
  font-size: clamp(1.3rem, 4vw, 1.7rem);
  color: var(--ink);
  text-align: right;
  opacity: 0;
  transition: opacity 0.9s;
}

/* ---------- Scroll Hint ---------- */
.scroll-hint {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-elegant);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: rgba(212, 168, 67, 0.45);
  animation: pulseHint 2.5s ease-in-out infinite;
  z-index: 900;
  pointer-events: none;
  transition: opacity 0.6s;
}

.scroll-hint.hidden { opacity: 0; }

@keyframes pulseHint {
  0%, 100% { opacity: 0.45; transform: translateX(-50%) translateY(0); }
  50%       { opacity: 0.8;  transform: translateX(-50%) translateY(4px); }
}

/* ---------- Shared ---------- */
.visible-element { opacity: 1 !important; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .action-btn .label { display: none; }
  .action-btn { padding: 0.4rem 0.5rem; }
  .custom-panel { padding: 0.8rem 1rem; }
  .letter-paper { padding: 1.5rem 1.2rem; }
}

/* ---------- Print / PDF layer (hidden) ---------- */
.pdf-layer {
  display: none;
}

/* ---------- SVG filter for paper texture ---------- */
svg.paper-svg { position: absolute; width: 0; height: 0; }
