/* ============================================
   Faqat sen uchun — Cinematic Love Letter
   Premium romantic experience
   ============================================ */

:root {
  --burgundy: #2A101B;
  --near-black: #100B12;
  --ivory: #F4E7D1;
  --muted-rose: #D989A6;
  --wax-red: #9F233B;
  --warm-gold: #D5B27A;
  --soft-pink: #E8A0B8;
  --paper-shadow: rgba(42, 16, 27, 0.35);
  --glow: rgba(217, 137, 166, 0.45);

  --font-serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-script: "Great Vibes", cursive;
  --font-sans: "Inter", system-ui, -apple-system, sans-serif;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100%;
  overflow: hidden;
  background: var(--near-black);
  color: var(--ivory);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

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

.app {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #2A101B 0%, #100B12 55%, #0A070C 100%);
}

/* ---------- Ambient ---------- */
.vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(10, 7, 12, 0.75) 100%);
  z-index: 50;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.04;
  z-index: 51;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px;
}

.particles {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 2;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 3px;
  height: 3px;
  background: var(--warm-gold);
  border-radius: 50%;
  opacity: 0;
  animation: floatDust 12s linear infinite;
}

.particle.petal {
  width: 8px;
  height: 10px;
  background: linear-gradient(135deg, var(--muted-rose), var(--wax-red));
  border-radius: 50% 0 50% 50%;
  opacity: 0;
  animation: floatPetal 18s linear infinite;
}

@keyframes floatDust {
  0% { transform: translateY(100vh) translateX(0) scale(0.4); opacity: 0; }
  10% { opacity: 0.35; }
  90% { opacity: 0.2; }
  100% { transform: translateY(-10vh) translateX(30px) scale(1); opacity: 0; }
}

@keyframes floatPetal {
  0% { transform: translateY(110vh) rotate(0deg) translateX(0); opacity: 0; }
  15% { opacity: 0.5; }
  85% { opacity: 0.3; }
  100% { transform: translateY(-15vh) rotate(360deg) translateX(40px); opacity: 0; }
}

/* ---------- Sound controls ---------- */
.sound-controls {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 100;
}

.sound-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(213, 178, 122, 0.35);
  background: rgba(16, 11, 18, 0.65);
  backdrop-filter: blur(8px);
  color: var(--warm-gold);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.3s, background 0.3s;
}

.sound-btn:hover,
.sound-btn:focus-visible {
  border-color: var(--warm-gold);
  background: rgba(42, 16, 27, 0.8);
  outline: none;
}

/* ---------- Scenes ---------- */
.scene {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 1.1s var(--ease-soft), visibility 1.1s;
  z-index: 10;
}

.scene.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ---------- Scene 1: Intro ---------- */
.scene-intro {
  flex-direction: column;
}

.table-surface {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 38%;
  background: linear-gradient(to top, #1a0c14 0%, #2A101B 40%, transparent 100%);
  opacity: 0.85;
  z-index: 0;
}

.candle-glow {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  width: min(70vw, 420px);
  height: min(50vh, 380px);
  background: radial-gradient(ellipse at center, rgba(213, 178, 122, 0.18) 0%, rgba(159, 35, 59, 0.08) 45%, transparent 70%);
  filter: blur(20px);
  z-index: 1;
  animation: candlePulse 4s ease-in-out infinite;
}

@keyframes candlePulse {
  0%, 100% { opacity: 0.7; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.05); }
}

.intro-content {
  position: relative;
  z-index: 5;
  text-align: center;
  padding: 1.5rem;
  max-width: 90vw;
}

.intro-line {
  font-family: var(--font-serif);
  font-size: clamp(1.35rem, 4.5vw, 2.1rem);
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--ivory);
  margin-bottom: 2.2rem;
  opacity: 0;
  transform: translateY(18px);
  animation: fadeUp 1.4s var(--ease-out) 0.8s forwards;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}

@keyframes fadeUp {
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.85rem 1.9rem;
  transition: transform 0.35s var(--ease-out), box-shadow 0.35s, background 0.35s, opacity 0.3s;
  -webkit-tap-highlight-color: transparent;
}

.btn:focus-visible {
  outline: 2px solid var(--warm-gold);
  outline-offset: 3px;
}

.btn-primary {
  background: linear-gradient(145deg, var(--wax-red), #7a1a2e);
  color: var(--ivory);
  box-shadow: 0 8px 28px rgba(159, 35, 59, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  opacity: 0;
  transform: translateY(12px);
  animation: fadeUp 1s var(--ease-out) 1.6s forwards;
}

.btn-primary:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 36px rgba(159, 35, 59, 0.55);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-continue {
  margin-top: 1.8rem;
  background: transparent;
  color: var(--burgundy);
  border: 1px solid rgba(42, 16, 27, 0.35);
  font-size: 0.9rem;
  padding: 0.65rem 1.4rem;
}

.btn-continue:hover {
  background: rgba(42, 16, 27, 0.08);
}

.btn-continue.hidden {
  display: none;
}

.skip-btn {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: max(16px, env(safe-area-inset-right));
  z-index: 30;
  background: rgba(16, 11, 18, 0.55);
  border: 1px solid rgba(213, 178, 122, 0.25);
  color: rgba(244, 231, 209, 0.7);
  font-size: 0.8rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: opacity 0.3s, color 0.3s;
}

.skip-btn:hover {
  color: var(--ivory);
}

.skip-btn.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ---------- Scene 2: Envelope ---------- */
.scene-envelope {
  perspective: 1200px;
}

.envelope-stage {
  position: relative;
  width: min(88vw, 340px);
  height: min(58vw, 230px);
  transform-style: preserve-3d;
  transition: transform 1.2s var(--ease-out);
}

.envelope-stage.zoomed {
  transform: scale(1.08);
}

.envelope {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

/* Envelope back */
.envelope-back {
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, #3d1a28 0%, #2A101B 50%, #1f0d16 100%);
  border-radius: 4px 4px 6px 6px;
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.55),
    0 4px 12px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  z-index: 1;
}

/* Front pocket */
.envelope-front {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.envelope-pocket {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 58%;
  background: linear-gradient(180deg, #3a1826 0%, #2A101B 40%, #1c0c14 100%);
  border-radius: 0 0 6px 6px;
  box-shadow: inset 0 12px 18px rgba(0, 0, 0, 0.25);
  clip-path: polygon(0 18%, 50% 0, 100% 18%, 100% 100%, 0 100%);
}

/* Top flap */
.envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 52%;
  z-index: 5;
  transform-origin: top center;
  transform-style: preserve-3d;
  transition: transform 1.6s var(--ease-out);
}

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

.flap-inner {
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #4a2032 0%, #351421 60%, #2A101B 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  backface-visibility: hidden;
}

/* Wax seal */
.wax-seal {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  width: 52px;
  height: 52px;
  transition: transform 0.4s var(--ease-out), opacity 0.5s;
}

.wax-seal.cracking {
  animation: sealImpact 0.45s var(--ease-out);
}

.wax-seal.broken {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.6);
  pointer-events: none;
}

@keyframes sealImpact {
  0% { transform: translate(-50%, -50%) scale(1); }
  30% { transform: translate(-50%, -50%) scale(1.15); }
  60% { transform: translate(-50%, -50%) scale(0.95) rotate(-4deg); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

.seal-body {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c43a55, var(--wax-red) 55%, #6e1528);
  box-shadow:
    0 4px 14px rgba(159, 35, 59, 0.55),
    inset 0 2px 4px rgba(255, 255, 255, 0.2),
    inset 0 -3px 6px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.seal-body::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.seal-heart {
  color: rgba(244, 231, 209, 0.9);
  font-size: 1.15rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  line-height: 1;
}

.seal-crack {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: transparent;
  opacity: 0;
  pointer-events: none;
}

.wax-seal.cracking .seal-crack {
  opacity: 1;
  background:
    linear-gradient(125deg, transparent 42%, rgba(244, 231, 209, 0.35) 48%, transparent 54%),
    linear-gradient(55deg, transparent 40%, rgba(0, 0, 0, 0.25) 50%, transparent 60%);
}

/* Letter paper */
.letter-paper {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 12%;
  height: 85%;
  background: var(--ivory);
  border-radius: 2px;
  z-index: 3;
  transform-origin: center bottom;
  transform: translateY(8%) rotateX(4deg) scale(0.92);
  box-shadow:
    0 8px 24px var(--paper-shadow),
    0 2px 6px rgba(0, 0, 0, 0.12);
  transition:
    transform 1.8s var(--ease-out),
    top 1.8s var(--ease-out),
    height 1.8s var(--ease-out),
    left 1.8s var(--ease-out),
    right 1.8s var(--ease-out),
    border-radius 1s,
    box-shadow 1.5s;
  overflow: hidden;
}

/* Paper texture */
.letter-paper::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 27px,
      rgba(42, 16, 27, 0.035) 27px,
      rgba(42, 16, 27, 0.035) 28px
    );
  opacity: 0.7;
  pointer-events: none;
}

.letter-paper.emerging {
  transform: translateY(-28%) rotateX(2deg) rotateZ(-1.5deg) scale(0.96);
  z-index: 7;
}

.letter-paper.unfolded {
  top: 50%;
  left: 50%;
  right: auto;
  width: min(92vw, 420px);
  height: min(78vh, 560px);
  transform: translate(-50%, -50%) rotateX(0) rotateZ(0) scale(1);
  border-radius: 3px;
  box-shadow:
    0 25px 60px rgba(0, 0, 0, 0.45),
    0 8px 20px var(--paper-shadow);
  z-index: 20;
}

.letter-content {
  position: relative;
  height: 100%;
  padding: 1.8rem 1.6rem 1.4rem;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.letter-text {
  font-family: var(--font-serif);
  font-size: clamp(0.95rem, 2.8vw, 1.15rem);
  line-height: 1.75;
  color: #2A101B;
  white-space: pre-wrap;
  flex: 1;
}

.letter-text .para {
  opacity: 0;
  transform: translateY(6px);
  margin-bottom: 0.95em;
  transition: opacity 0.7s var(--ease-soft), transform 0.7s var(--ease-soft);
}

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

.letter-text .para:last-child {
  margin-bottom: 0.4em;
}

.recipient-label {
  position: absolute;
  bottom: -2.4rem;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-script);
  font-size: 1.5rem;
  color: var(--warm-gold);
  opacity: 0;
  transition: opacity 0.8s;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

.recipient-label.visible {
  opacity: 1;
}

/* When letter is full screen, hide envelope chrome */
.envelope.letter-mode .envelope-back,
.envelope.letter-mode .envelope-front,
.envelope.letter-mode .envelope-flap,
.envelope.letter-mode .wax-seal {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s;
}

.envelope.letter-mode .letter-paper {
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.5),
    0 10px 25px var(--paper-shadow);
}

/* ---------- Scene 4: Question ---------- */
.scene-question {
  background: radial-gradient(ellipse at 50% 40%, #2A101B 0%, #100B12 60%, #0A070C 100%);
}

.question-content {
  text-align: center;
  padding: 1.5rem;
  max-width: 94vw;
  position: relative;
  z-index: 5;
}

.glowing-heart {
  font-size: clamp(2.5rem, 8vw, 3.8rem);
  color: var(--muted-rose);
  text-shadow: 0 0 30px var(--glow), 0 0 60px rgba(159, 35, 59, 0.4);
  margin-bottom: 1.2rem;
  animation: heartPulse 2.4s ease-in-out infinite;
  opacity: 0;
  transform: scale(0.6);
}

.scene-question.active .glowing-heart {
  animation: heartIn 0.9s var(--ease-out) forwards, heartPulse 2.4s ease-in-out 0.9s infinite;
}

@keyframes heartIn {
  to { opacity: 1; transform: scale(1); }
}

@keyframes heartPulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.08); filter: brightness(1.15); }
}

.question-text {
  font-family: var(--font-serif);
  font-size: clamp(1.8rem, 6.5vw, 2.8rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ivory);
  margin-bottom: 2.4rem;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(16px);
}

.scene-question.active .question-text {
  animation: fadeUp 1s var(--ease-out) 0.35s forwards;
}

.buttons-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  justify-content: center;
  align-items: center;
  min-height: 70px;
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

.btn-yes,
.btn-no {
  font-size: 1.05rem;
  padding: 0.9rem 1.8rem;
  min-width: 110px;
  position: relative;
  z-index: 2;
  opacity: 0;
  transform: translateY(12px);
}

.scene-question.active .btn-yes,
.scene-question.active .btn-no {
  animation: fadeUp 0.8s var(--ease-out) 0.7s forwards;
}

.btn-yes {
  background: linear-gradient(145deg, var(--muted-rose), var(--wax-red));
  color: #fff;
  box-shadow: 0 6px 24px rgba(159, 35, 59, 0.4);
  transition: transform 0.4s var(--ease-out), box-shadow 0.4s, font-size 0.4s, padding 0.4s;
}

.btn-yes:hover {
  box-shadow: 0 10px 32px rgba(159, 35, 59, 0.55), 0 0 20px var(--glow);
}

.btn-yes.grown {
  box-shadow: 0 10px 36px rgba(159, 35, 59, 0.55), 0 0 28px var(--glow);
}

.btn-no {
  background: rgba(244, 231, 209, 0.08);
  color: var(--ivory);
  border: 1px solid rgba(244, 231, 209, 0.25);
  transition: transform 0.35s var(--ease-out), opacity 0.3s, font-size 0.3s, padding 0.3s;
}

.btn-no:hover {
  background: rgba(244, 231, 209, 0.12);
}

.playful-msg {
  margin-top: 1.6rem;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  color: var(--muted-rose);
  min-height: 1.5em;
  opacity: 0;
  transition: opacity 0.4s;
}

.playful-msg.visible {
  opacity: 1;
}

/* ---------- Scene 6: Finale ---------- */
.scene-finale {
  background: radial-gradient(ellipse at 50% 35%, #3a1524 0%, #1a0c14 50%, #100B12 100%);
}

.finale-content {
  text-align: center;
  padding: 2rem 1.5rem;
  max-width: 90vw;
  position: relative;
  z-index: 5;
}

.heart-burst {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}

.burst-heart {
  position: absolute;
  color: var(--muted-rose);
  font-size: 1rem;
  opacity: 0;
  animation: burstOut 1.8s var(--ease-out) forwards;
}

@keyframes burstOut {
  0% { transform: translate(0, 0) scale(0.3); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(1); opacity: 0; }
}

.finale-line {
  font-family: var(--font-serif);
  font-size: clamp(1.25rem, 4.2vw, 1.75rem);
  line-height: 1.55;
  color: var(--ivory);
  margin-bottom: 1rem;
  opacity: 0;
  transform: translateY(14px);
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.4);
}

.finale-line.visible {
  animation: fadeUp 1s var(--ease-out) forwards;
}

.finale-signature {
  font-family: var(--font-script);
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  color: var(--warm-gold);
  margin-top: 1.8rem;
  margin-bottom: 2.5rem;
  opacity: 0;
  transform: translateY(10px);
}

.finale-signature.visible {
  animation: fadeUp 1s var(--ease-out) forwards;
}

.btn-replay {
  background: transparent;
  color: rgba(244, 231, 209, 0.7);
  border: 1px solid rgba(213, 178, 122, 0.3);
  font-size: 0.85rem;
  padding: 0.65rem 1.4rem;
  opacity: 0;
}

.btn-replay.visible {
  animation: fadeUp 0.8s var(--ease-out) forwards;
}

.btn-replay:hover {
  color: var(--ivory);
  border-color: var(--warm-gold);
}

/* Floating hearts in finale */
.float-heart {
  position: fixed;
  pointer-events: none;
  color: var(--muted-rose);
  font-size: 0.9rem;
  opacity: 0;
  z-index: 15;
  animation: floatHeart 5s linear forwards;
}

@keyframes floatHeart {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  15% { opacity: 0.7; }
  100% { transform: translateY(-80vh) scale(1.1); opacity: 0; }
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .envelope-stage {
    width: min(90vw, 300px);
    height: min(62vw, 200px);
  }

  .letter-paper.unfolded {
    width: min(94vw, 100%);
    height: min(82vh, 520px);
    padding: 0;
  }

  .letter-content {
    padding: 1.4rem 1.2rem 1.2rem;
  }

  .buttons-wrap {
    gap: 0.9rem;
  }

  .btn-yes,
  .btn-no {
    font-size: 0.98rem;
    padding: 0.8rem 1.5rem;
    min-width: 100px;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .letter-paper.unfolded {
    height: min(88vh, 400px);
  }

  .letter-content {
    padding: 1rem 1.3rem;
  }

  .intro-line {
    margin-bottom: 1.2rem;
  }
}

/* Focus styles for keyboard */
.btn:focus-visible,
.sound-btn:focus-visible,
.skip-btn:focus-visible {
  outline: 2px solid var(--warm-gold);
  outline-offset: 3px;
}
