/* ==========================================================================
   AJ's Birthday Envelope - Style System
   Soft Light Blue & Azure Celebration Palette | Mobile-First Design
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design Tokens & Root Variables (Light Blue Celebration Theme)
   -------------------------------------------------------------------------- */
:root {
  /* Soft Light Blue & Azure Palette */
  --bg-primary: #f0f7ff;
  --bg-secondary: #dbeafe;
  --bg-accent-glow: rgba(255, 215, 0, 0.3);
  
  --envelope-body: #1e3a8a;
  --envelope-body-dark: #0f172a;
  --envelope-border: rgba(212, 175, 55, 0.65);
  --envelope-inner: #0b132b;

  --gold-primary: #d4af37;
  --gold-light: #fdf2bb;
  --gold-dark: #8c6508;
  --gold-gradient: linear-gradient(135deg, #bf953f 0%, #fcf6ba 25%, #b38728 50%, #fbf5b7 75%, #aa771c 100%);
  --gold-glow: 0 0 20px rgba(212, 175, 55, 0.5);

  --card-bg: linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);
  --card-text: #0f172a;
  --card-text-muted: #334155;

  /* Responsive Dimensions - Mobile Base (< 480px) */
  --envelope-width: min(310px, 88vw);
  --envelope-height: 200px;
  --card-open-lift: -140px;
  --card-open-scale: 1.08;

  /* Typography */
  --font-heading: 'Cinzel Decorative', Georgia, serif;
  --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-accent: 'Playfair Display', Georgia, serif;
}

/* --------------------------------------------------------------------------
   2. Media Query Overrides for Larger Viewports
   -------------------------------------------------------------------------- */
@media (min-width: 480px) {
  :root {
    --envelope-width: 360px;
    --envelope-height: 230px;
    --card-open-lift: -160px;
    --card-open-scale: 1.14;
  }
}

@media (min-width: 768px) {
  :root {
    --envelope-width: 420px;
    --envelope-height: 270px;
    --card-open-lift: -190px;
    --card-open-scale: 1.20;
  }
}

/* --------------------------------------------------------------------------
   3. Reset & General Layout
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: #0f172a;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* --------------------------------------------------------------------------
   4. Scene & Ambient Atmosphere (Light Sky/Azure Blue)
   -------------------------------------------------------------------------- */
.scene {
  width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  perspective: 1200px;
  background: linear-gradient(135deg, #f7faff 0%, #e3f2ff 50%, #d0e7ff 100%);
  padding: 20px 10px;
}

/* Ambient Radial Warm Gold & Azure Glow Behind Envelope */
.glow-bg {
  position: absolute;
  width: min(550px, 92vw);
  height: min(550px, 92vw);
  background: radial-gradient(circle, rgba(255, 215, 0, 0.32) 0%, rgba(56, 189, 248, 0.22) 45%, rgba(147, 197, 253, 0.25) 75%, transparent 100%);
  border-radius: 50%;
  pointer-events: none;
  filter: blur(45px);
  z-index: 0;
}

/* Sparkling Golden & Azure Dust Atmosphere */
.ambient-stars {
  position: absolute;
  inset: 0;
  background-image: 
    radial-gradient(2px 2px at 30px 40px, rgba(212, 175, 55, 0.8), rgba(0,0,0,0)),
    radial-gradient(3px 3px at 160px 190px, rgba(56, 189, 248, 0.7), rgba(0,0,0,0)),
    radial-gradient(2px 2px at 290px 90px, rgba(212, 175, 55, 0.75), rgba(0,0,0,0)),
    radial-gradient(3px 3px at 90% 75%, rgba(147, 197, 253, 0.75), rgba(0,0,0,0)),
    radial-gradient(2px 2px at 85% 25%, rgba(212, 175, 55, 0.8), rgba(0,0,0,0));
  background-repeat: repeat;
  background-size: 380px 380px;
  opacity: 0.8;
  pointer-events: none;
  z-index: 0;
}

/* --------------------------------------------------------------------------
   5. Envelope Container & 3D Layers
   -------------------------------------------------------------------------- */
.envelope {
  position: relative;
  width: var(--envelope-width);
  height: var(--envelope-height);
  cursor: pointer;
  transform-style: preserve-3d;
  z-index: 10;
  transition: transform 0.4s ease;
  filter: drop-shadow(0 22px 35px rgba(30, 58, 138, 0.22));
  margin-top: 40px;
}

.envelope:hover {
  transform: translateY(-4px) scale(1.015);
}

/* 5.1 Envelope Back Layer */
.envelope-back {
  position: absolute;
  inset: 0;
  background: var(--envelope-inner);
  border-radius: 12px;
  border: 1px solid rgba(212, 175, 55, 0.45);
  z-index: 1;
  overflow: hidden;
  box-shadow: inset 0 0 25px rgba(0, 0, 0, 0.65);
}

.envelope-back::before {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 8px;
  background-image: repeating-linear-gradient(45deg, rgba(212, 175, 55, 0.08) 0, rgba(212, 175, 55, 0.08) 10px, transparent 10px, transparent 20px);
}

/* 5.2 Dynamic Birthday Card */
.card {
  position: absolute;
  top: 10px;
  left: 4%;
  width: 92%;
  min-height: calc(var(--envelope-height) - 20px);
  max-height: calc(var(--envelope-height) - 20px);
  background: var(--card-bg);
  border-radius: 12px;
  z-index: 2;
  box-shadow: 0 10px 25px rgba(30, 58, 138, 0.15);
  border: 2px solid var(--gold-primary);
  overflow: hidden;
  transform: translateY(0);
  transition: transform 0.85s cubic-bezier(0.34, 1.35, 0.64, 1), 
              max-height 0.85s ease, 
              z-index 0s 0.4s, 
              box-shadow 0.6s ease;
  display: flex;
  flex-direction: column;
}

.card-inner {
  flex: 1;
  padding: clamp(12px, 3.5vw, 24px) clamp(10px, 3vw, 20px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--card-text);
  border: 1px solid rgba(212, 175, 55, 0.4);
  margin: 5px;
  border-radius: 8px;
  background: radial-gradient(circle at center, #ffffff 0%, #f8fafc 100%);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-primary) transparent;
}

.card-inner::-webkit-scrollbar {
  width: 4px;
}
.card-inner::-webkit-scrollbar-thumb {
  background: var(--gold-primary);
  border-radius: 4px;
}

.card-badge {
  font-size: clamp(0.68rem, 2.5vw, 0.78rem);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--gold-dark);
  font-weight: 700;
  margin-bottom: 6px;
}

.card-title {
  font-family: var(--font-heading);
  font-size: clamp(1.15rem, 4.5vw, 1.6rem);
  color: #0f172a;
  margin-bottom: 6px;
  background: var(--gold-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  word-break: break-word;
  max-width: 100%;
}

.card-divider {
  width: 45px;
  height: 2px;
  background: var(--gold-gradient);
  margin: 6px 0 10px 0;
  border-radius: 2px;
  flex-shrink: 0;
}

.card-message {
  font-size: clamp(0.82rem, 3.2vw, 0.98rem);
  line-height: 1.55;
  color: var(--card-text-muted);
  font-family: var(--font-accent);
  font-style: italic;
  width: 100%;
  max-width: 100%;
  word-break: break-word;
}

.card-footer {
  margin-top: 10px;
  flex-shrink: 0;
}

.card-toast {
  font-size: clamp(0.78rem, 2.8vw, 0.88rem);
  font-weight: 600;
  color: var(--gold-dark);
}

/* 5.3 Envelope Front Pocket Layer */
.envelope-front {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(165deg, var(--envelope-body) 0%, var(--envelope-body-dark) 100%);
  border-radius: 12px;
  clip-path: polygon(0 0, 50% 50%, 100% 0, 100% 100%, 0 100%);
  border-bottom: 2px solid var(--envelope-border);
}

.envelope-front::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(212, 175, 55, 0.2), transparent 40%);
  pointer-events: none;
}

/* 5.4 Envelope Top Flap */
.envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  transform-origin: top center;
  transform-style: preserve-3d;
  background: linear-gradient(195deg, #1e40af 0%, var(--envelope-body-dark) 100%);
  border-radius: 12px 12px 0 0;
  clip-path: polygon(0 0, 100% 0, 50% 55%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: transform 0.75s cubic-bezier(0.4, 0, 0.2, 1), z-index 0s 0.35s;
}

.envelope-flap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--gold-gradient);
  clip-path: polygon(0 0, 100% 0, 50% 55%);
  opacity: 0.4;
  pointer-events: none;
}

/* Wax Seal Badge */
.wax-seal {
  position: absolute;
  top: 47%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--gold-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35), inset 0 0 4px rgba(255, 255, 255, 0.7);
  border: 2px solid #8e6515;
  z-index: 5;
  cursor: pointer;
  transition: transform 0.5s ease, opacity 0.5s ease;
}

.seal-initials {
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 700;
  color: #3d2706;
  letter-spacing: 1px;
}

/* --------------------------------------------------------------------------
   6. OPEN State Rules
   -------------------------------------------------------------------------- */

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

.envelope.open .wax-seal {
  opacity: 0.2;
  transform: translate(-50%, -50%) scale(0.55);
}

.envelope.open .card {
  max-height: min(72vh, 480px);
  height: auto;
  transform: translateY(var(--card-open-lift)) scale(var(--card-open-scale));
  z-index: 15;
  box-shadow: 0 25px 50px rgba(30, 58, 138, 0.25), 0 0 35px rgba(212, 175, 55, 0.45);
}

.envelope.open:hover {
  transform: translateY(0) scale(1);
}

/* --------------------------------------------------------------------------
   7. Dynamic Particle Containers & Animations
   -------------------------------------------------------------------------- */
.confetti-container,
.balloon-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 20;
}

.confetti-piece {
  position: absolute;
  top: -25px;
  pointer-events: none;
  will-change: transform, opacity;
  animation: confettiFall var(--fall-duration, 3.5s) cubic-bezier(0.25, 0.46, 0.45, 0.94) var(--fall-delay, 0s) forwards;
}

.confetti-piece.rectangle { width: 10px; height: 18px; border-radius: 2px; }
.confetti-piece.square { width: 10px; height: 10px; border-radius: 2px; }
.confetti-piece.ribbon { width: 6px; height: 26px; border-radius: 10px; }

.confetti-piece.gold-glitter {
  background: var(--gold-gradient) !important;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.8);
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    opacity: 1;
  }
  80% { opacity: 0.9; }
  100% {
    transform: translateY(108vh) rotateX(720deg) rotateY(540deg) rotateZ(360deg);
    opacity: 0;
  }
}

.balloon {
  position: absolute;
  bottom: -90px;
  width: 44px;
  height: 56px;
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  pointer-events: none;
  box-shadow: inset -5px -5px 12px rgba(0, 0, 0, 0.18), 0 10px 20px rgba(30, 58, 138, 0.15);
  will-change: transform, opacity;
  animation: balloonRise var(--rise-duration, 6s) ease-in-out var(--rise-delay, 0s) forwards;
}

.balloon::before {
  content: '';
  position: absolute;
  top: 14%;
  left: 18%;
  width: 9px;
  height: 13px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
}

.balloon::after {
  content: '';
  position: absolute;
  bottom: -22px;
  left: 50%;
  width: 2px;
  height: 24px;
  background: rgba(255, 255, 255, 0.55);
  transform: translateX(-50%);
}

@keyframes balloonRise {
  0% { transform: translateY(0) translateX(0) rotate(0deg); opacity: 0.95; }
  50% { transform: translateY(-55vh) translateX(var(--drift-x, 35px)) rotate(7deg); }
  100% { transform: translateY(-118vh) translateX(calc(var(--drift-x, 35px) * -0.5)) rotate(-8deg); opacity: 0.9; }
}

/* --------------------------------------------------------------------------
   8. Interactive Hint Banner (Frosted Light Blue Glass Pill)
   -------------------------------------------------------------------------- */
.interaction-hint {
  margin-top: 35px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 22px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 30px;
  backdrop-filter: blur(8px);
  color: #1e3a8a;
  font-size: clamp(0.82rem, 3vw, 0.92rem);
  font-weight: 600;
  letter-spacing: 0.5px;
  box-shadow: 0 10px 25px rgba(37, 99, 235, 0.12);
  z-index: 10;
  transition: all 0.4s ease;
}

.hint-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #d4af37;
  box-shadow: 0 0 10px #d4af37;
  animation: pulseGlow 1.8s infinite ease-in-out;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.5; }
}

.envelope.open ~ .interaction-hint {
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(212, 175, 55, 0.7);
  box-shadow: 0 0 25px rgba(212, 175, 55, 0.4);
}
