/* ==========================================================================
   Design Tokens & Color Palette
   Theme: Classy Noir Romance (Deep Dark Red, Obsidian, Champagne Gold, Velvet)
   Vibe: "Black Cat Energy" — Sophisticated, Magnetic, Moody, Luxurious
   ========================================================================== */
:root {
  --bg-dark-1: #0A0305;
  --bg-dark-2: #16060A;
  --bg-dark-3: #22080F;
  
  --card-bg: rgba(22, 7, 11, 0.82);
  --card-border: rgba(212, 175, 55, 0.25);
  --card-shadow: 0 24px 64px -12px rgba(0, 0, 0, 0.85),
                 0 0 45px rgba(139, 21, 40, 0.16);

  --accent-gold: #D4AF37;
  --accent-gold-light: #FCE8B3;
  --accent-gold-dark: #A68423;
  
  --accent-red-rich: #8B1528;
  --accent-red-deep: #5A0C19;
  --accent-red-dark: #38050E;
  --accent-glow: rgba(186, 28, 52, 0.4);

  --text-primary: #F8F1ED;
  --text-secondary: #CBB9BE;
  --text-muted: #8C757B;

  --input-bg: rgba(14, 4, 7, 0.85);
  --input-border: rgba(212, 175, 55, 0.3);
  --input-border-focus: #D4AF37;

  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-script: 'Great Vibes', cursive;
  --font-handwriting: 'Caveat', cursive;
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;

  --radius-card: 26px;
  --radius-btn: 50px;
  --radius-input: 16px;

  --transition-smooth: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   Reset & Mobile Foundation
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  min-height: 100dvh;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: radial-gradient(circle at 50% 15%, #2B0811 0%, #170509 45%, #0A0204 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

#ambient-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.page-container {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 12px;
}

/* ==========================================================================
   Card Component (Classy Noir Luxury)
   ========================================================================== */
.card {
  width: 100%;
  max-width: 440px;
  background: var(--card-bg);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--card-shadow);
  padding: 36px 24px;
  text-align: center;
  position: relative;
  transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1), 
              transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.letter-card {
  max-width: 460px;
  padding: 30px 18px;
}

@media (max-width: 380px) {
  .card {
    padding: 28px 16px;
    border-radius: 20px;
  }
}

.card.hidden {
  display: none !important;
  opacity: 0;
  transform: scale(0.95) translateY(14px);
  pointer-events: none;
}

.card.active {
  display: block !important;
  opacity: 1;
  transform: scale(1) translateY(0);
  animation: cardFadeIn 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(16px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ==========================================================================
   Screen 1: Password Gate (Mysterious & Classy)
   ========================================================================== */
.emblem-wrapper {
  position: relative;
  width: 68px;
  height: 68px;
  margin: 0 auto 16px auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emblem-icon {
  font-size: 34px;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 4px 12px rgba(212, 175, 55, 0.45));
  animation: gentleFloat 4s ease-in-out infinite;
}

.emblem-glow {
  position: absolute;
  width: 58px;
  height: 58px;
  background: radial-gradient(circle, rgba(212, 175, 55, 0.3) 0%, transparent 70%);
  border-radius: 50%;
  z-index: 1;
  animation: pulseGlow 3s ease-in-out infinite alternate;
}

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

@keyframes pulseGlow {
  0% { transform: scale(0.85); opacity: 0.5; }
  100% { transform: scale(1.2); opacity: 0.85; }
}

.tagline {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 2.8px;
  color: var(--accent-gold);
  margin-bottom: 8px;
}

.gate-title, .screen-title {
  font-family: var(--font-serif);
  font-size: clamp(27px, 6.5vw, 33px);
  font-weight: 600;
  line-height: 1.22;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.gate-title.yellow-text {
  color: #F7D050;
  text-shadow: 0 0 20px rgba(247, 208, 80, 0.35);
  margin-bottom: 24px;
}

.gate-subtitle, .screen-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 22px;
  max-width: 340px;
  margin-left: auto;
  margin-right: auto;
}

.input-group {
  position: relative;
  margin-bottom: 12px;
}

#password-input {
  width: 100%;
  height: 52px;
  padding: 0 50px 0 18px;
  font-family: var(--font-sans);
  font-size: 16px;
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-input);
  outline: none;
  transition: var(--transition-smooth);
}

#password-input::placeholder {
  color: var(--text-muted);
}

#password-input:focus {
  border-color: var(--accent-gold);
  background: rgba(24, 7, 12, 0.95);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.2);
}

#toggle-pw-visibility {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 10px;
  font-size: 16px;
  opacity: 0.65;
  touch-action: manipulation;
}

.error-msg {
  min-height: 22px;
  font-size: 13px;
  color: #FF5A73;
  margin-bottom: 14px;
  opacity: 0;
  transition: opacity 0.3s ease;
  font-weight: 600;
}

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

.shake {
  animation: shakeAnimation 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shakeAnimation {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-5px, 0, 0); }
  40%, 60% { transform: translate3d(5px, 0, 0); }
}

/* Primary Button: Deep Velvet Crimson */
.primary-btn {
  width: 100%;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, #8B1528 0%, #6E1020 50%, #4D0914 100%);
  color: #FFF7F0;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: var(--radius-btn);
  cursor: pointer;
  box-shadow: 0 10px 26px -6px rgba(110, 16, 32, 0.6);
  transition: var(--transition-smooth);
}

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

.primary-btn:hover {
  background: linear-gradient(135deg, #9C192E 0%, #7E1325 50%, #590B18 100%);
  box-shadow: 0 12px 30px -6px rgba(139, 21, 40, 0.7);
}

/* Badge Pill */
.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(139, 21, 40, 0.28);
  color: var(--accent-gold);
  border: 1px solid rgba(212, 175, 55, 0.35);
  padding: 5px 16px;
  border-radius: 50px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 2px;
  margin-bottom: 14px;
}

/* ==========================================================================
   Screen 2: Digital Art Dark Red Velvet Cake & Calming Flame Physics
   ========================================================================== */
.cake-stage {
  position: relative;
  width: 100%;
  max-width: 320px;
  margin: 0 auto 12px auto;
  cursor: pointer;
  display: flex;
  justify-content: center;
}

#cake-svg {
  width: 100%;
  max-height: 290px;
  display: block;
  user-select: none;
}

/* Organic Slow Wiggle SVG Flames */
.interactive-flame {
  transform-box: view-box;
  will-change: transform, opacity;
  transition: filter 0.2s ease;
}

#flame-1 {
  transform-origin: 131px 70px;
}

#flame-2 {
  transform-origin: 170px 60px;
}

#flame-3 {
  transform-origin: 209px 70px;
}

.flame-halo {
  animation: haloPulse 3.5s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes haloPulse {
  0% { opacity: 0.5; }
  100% { opacity: 0.7; }
}

/* Smoke Wisps */
.candle-smoke {
  transform-box: view-box;
  transition: opacity 0.6s ease;
}

#smoke-1 {
  transform-origin: 131px 70px;
}

#smoke-2 {
  transform-origin: 170px 60px;
}

#smoke-3 {
  transform-origin: 209px 70px;
}

.candle-smoke.smoking {
  animation: smokeWisp 2s ease-out forwards;
}

@keyframes smokeWisp {
  0% {
    opacity: 0.75;
    transform: translateY(0) scale(0.8);
  }
  50% {
    opacity: 0.4;
    transform: translateY(-26px) scale(1.8) rotate(8deg);
  }
  100% {
    opacity: 0;
    transform: translateY(-50px) scale(2.8) rotate(-12deg);
  }
}

/* Mic Controls & Wind Meter */
.mic-controls {
  margin-top: 4px;
}

.mic-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 26px;
  background: linear-gradient(135deg, #7A1424 0%, #540D18 100%);
  color: #FFF6EE;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: var(--radius-btn);
  cursor: pointer;
  box-shadow: 0 8px 22px -4px rgba(90, 12, 25, 0.5);
  transition: var(--transition-smooth);
}

.mic-btn:hover {
  background: linear-gradient(135deg, #8E192B 0%, #63101E 100%);
}

.mic-btn.active-listening {
  background: linear-gradient(135deg, #2E7D32 0%, #1B5E20 100%);
  border-color: #66BB6A;
  box-shadow: 0 8px 20px -4px rgba(46, 125, 50, 0.5);
}

.mic-status {
  margin-top: 12px;
}

.wind-meter-bar {
  width: 100%;
  max-width: 220px;
  height: 8px;
  background: rgba(139, 21, 40, 0.3);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: 20px;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
}

.wind-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #A51C30, #D4AF37, #FDF0CD);
  border-radius: 20px;
  transition: width 0.1s linear;
}

.listening-text {
  font-size: 13px;
  color: var(--accent-gold);
  font-weight: 500;
  margin-top: 6px;
}

.tap-blow-link {
  display: block;
  margin: 8px auto 0 auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 6px;
}

/* ==========================================================================
   Screen 3: Full-Size Mobile Classy Burgundy Stationery Envelope & Letter
   ========================================================================== */
.letter-screen-title {
  font-family: var(--font-serif);
  font-size: clamp(26px, 6.5vw, 30px);
  color: var(--text-primary);
  margin-bottom: 16px;
}

.letter-screen-subtitle {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

/* Header transition when letter is opened */
#letter-prompt-header {
  transition: opacity 0.4s ease, max-height 0.4s ease, margin 0.4s ease;
  max-height: 120px;
  overflow: hidden;
}

.reading-mode #letter-prompt-header {
  opacity: 0;
  max-height: 0;
  margin-bottom: 0;
  pointer-events: none;
}

.envelope-scene {
  perspective: 1200px;
  width: 100%;
  margin: 0 auto 12px auto;
  min-height: 250px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* Rich Burgundy Leather/Paper Envelope */
.envelope {
  position: relative;
  width: 100%;
  max-width: 380px;
  height: 236px;
  background: #3B0912;
  border-radius: 14px;
  box-shadow: 0 22px 50px -10px rgba(0, 0, 0, 0.75),
              0 0 25px rgba(120, 18, 35, 0.25);
  border: 1px solid rgba(212, 175, 55, 0.3);
  cursor: pointer;
  transition: all 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (max-width: 400px) {
  .envelope {
    height: 216px;
  }
}

.envelope-back {
  position: absolute;
  inset: 0;
  background: #2D060D;
  border-radius: 14px;
  z-index: 1;
}

/* Front Pocket in Dark Red Velvet */
.envelope-pocket {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 72%;
  background: linear-gradient(180deg, #4A0D17 0%, #35070F 100%);
  border-radius: 0 0 14px 14px;
  clip-path: polygon(0% 100%, 100% 100%, 100% 25%, 50% 64%, 0% 25%);
  box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.4);
  z-index: 4;
  pointer-events: none;
}

.pocket-gold-line {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  clip-path: polygon(0% 25%, 50% 64%, 100% 25%, 100% 26.5%, 50% 65.5%, 0% 26.5%);
  background: linear-gradient(90deg, #D4AF37, #FFF2A8, #D4AF37);
  opacity: 0.9;
}

/* Top Flap */
.envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 60%;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(180deg, #420A13 0%, #30060E 100%);
  transform-origin: top center;
  transition: transform 0.7s cubic-bezier(0.16, 1, 0.3, 1), z-index 0.3s ease;
  z-index: 5;
  border-radius: 14px 14px 0 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.flap-gold-line {
  position: absolute;
  inset: 0;
  clip-path: polygon(0 0, 50% 100%, 100% 0, 98% 0, 50% 97%, 2% 0);
  background: linear-gradient(90deg, #D4AF37, #FFF2A8, #D4AF37);
  opacity: 0.9;
}

/* 3D Royal Gold Wax Seal */
.wax-seal {
  position: absolute;
  top: 48%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 82px;
  height: 82px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.4s ease, opacity 0.4s ease, filter 0.3s ease;
}

.wax-seal:hover {
  transform: translate(-50%, -50%) scale(1.08);
  filter: brightness(1.08);
}

.wax-seal-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.65));
  user-select: none;
}

/* ==========================================================================
   Full-Size Mobile Handwritten Letter (Realistic Deckled Paper & Texture)
   ========================================================================== */
.paper-letter {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: 8px;
  padding: 24px 20px;
  z-index: 2;
  transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.6s ease,
              filter 0.8s ease,
              width 0.8s ease,
              height 0.8s ease;
  text-align: left;
  opacity: 0;
  pointer-events: none;
}

/* Organic Deckled Torn-Paper Background */
.paper-deckle-bg {
  position: absolute;
  inset: 0;
  background-color: #FAF5EA;
  background-image: 
    linear-gradient(180deg, 
      rgba(255, 255, 255, 0.7) 0%, 
      rgba(250, 243, 228, 0.55) 32%, 
      rgba(215, 195, 170, 0.3) 33%, 
      rgba(250, 243, 228, 0.4) 34%, 
      rgba(255, 255, 255, 0.7) 65%, 
      rgba(215, 195, 170, 0.3) 66%, 
      rgba(250, 243, 228, 0.4) 67%, 
      rgba(255, 255, 255, 0.7) 100%
    );
  border: 1px solid #D8C7B4;
  border-radius: 2px 3px 2px 3px;
  box-shadow: inset 0 0 25px rgba(185, 145, 105, 0.22),
              inset 0 0 4px rgba(150, 110, 70, 0.14);
  filter: url(#deckled-edge);
  pointer-events: none;
  z-index: 1;
}

.letter-texture {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 80% 20%, rgba(212, 175, 55, 0.06) 0%, transparent 65%);
  pointer-events: none;
  z-index: 2;
}

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

.letter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  border-bottom: 1px dashed rgba(139, 21, 40, 0.25);
  padding-bottom: 8px;
}

.letter-date {
  font-family: var(--font-handwriting);
  font-size: 20px;
  color: #7A5B64;
}

.letter-salutation {
  font-family: var(--font-handwriting);
  font-size: 27px;
  font-weight: 600;
  color: #7A1424;
  margin-bottom: 14px;
}

.letter-body p {
  font-family: var(--font-handwriting);
  font-size: 21.5px;
  line-height: 1.55;
  color: #260A10; /* Deep velvet ink */
  margin-bottom: 16px;
}

.letter-footer {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  border-top: 1px dashed rgba(139, 21, 40, 0.25);
  padding-top: 12px;
}

.letter-signoff-wrap {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.avatar-wrap {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 1.5px;
  background: linear-gradient(135deg, #D4AF37, #8B1528);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

.signoff-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 20%;
  display: block;
}

.signoff-text {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.letter-closing {
  font-family: var(--font-handwriting);
  font-size: 19px;
  color: #6E4F57;
  line-height: 1.1;
}

.letter-signature {
  font-family: var(--font-script);
  font-size: 30px;
  color: #7A1424;
  margin-top: -2px;
  line-height: 1.1;
}

/* ==========================================================================
   Envelope Open State (Large Mobile Experience)
   ========================================================================== */
.envelope.is-open {
  cursor: default;
  height: auto;
  min-height: 320px;
  background: transparent;
  box-shadow: none;
  border: none;
}

.envelope.is-open .envelope-back,
.envelope.is-open .envelope-pocket {
  opacity: 0;
  pointer-events: none;
  transform: translateY(40px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.envelope.is-open .wax-seal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.35);
  pointer-events: none;
}

.envelope.is-open .envelope-flap {
  opacity: 0;
  transform: rotateX(180deg);
  pointer-events: none;
}

.envelope.is-open .paper-letter {
  opacity: 1;
  pointer-events: auto;
  position: relative;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  min-height: 290px;
  filter: drop-shadow(0 20px 45px rgba(0, 0, 0, 0.7));
  animation: letterBloom 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes letterBloom {
  0% {
    opacity: 0;
    transform: translateY(30px) scale(0.92);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Action Controls */
.action-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.ghost-btn {
  background: transparent;
  border: 1px solid rgba(212, 175, 55, 0.3);
  color: var(--text-secondary);
  font-size: 12.5px;
  padding: 8px 18px;
  border-radius: 30px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.ghost-btn:hover, .ghost-btn:active {
  background: rgba(139, 21, 40, 0.3);
  color: #FFFFFF;
  border-color: var(--accent-gold);
}
