/* ==========================================================================
   Royal Gilded Folio Mobile Wedding Envelope
   Haute-Couture Stationery Architecture: Zero Emojis, Pure Classical Typography,
   Gilded Belly-Band, 3D Flap Physics & Arched Cathedral Invitation Card
   ========================================================================== */

/* Only visible on mobile/tablet viewports */
@media (min-width: 769px) {
  #mobile-invitation-section {
    display: none !important;
  }
}

@media (max-width: 768px) {
  /* Container Section */
  .mobile-invitation-section {
    position: relative;
    width: 100%;
    max-width: 100%;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 5.6rem 1rem 3rem;
    background: radial-gradient(circle at 50% 20%, #FFFDF9 0%, #F5ECE0 60%, #EBDDC8 100%);
    overflow: hidden;
    z-index: 10;
    box-sizing: border-box;
  }

  /* Ambient Gold Shimmer Watermark */
  .mobile-invitation-section::before {
    content: '';
    position: absolute;
    top: -10%;
    left: 50%;
    transform: translateX(-50%);
    width: 480px;
    height: 480px;
    background: radial-gradient(circle, rgba(212, 175, 55, 0.12) 0%, rgba(212, 175, 55, 0) 70%);
    pointer-events: none;
    z-index: 0;
  }

  /* Header Typography (Zero Emojis) */
  .mobile-env-header {
    text-align: center;
    margin-bottom: 1.25rem;
    position: relative;
    z-index: 2;
  }

  .mobile-env-badge {
    display: inline-block;
    font-size: 0.7rem;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: #8C6A28;
    padding: 0.38rem 1.3rem;
    border: 1px solid rgba(197, 160, 89, 0.45);
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    margin-bottom: 0.55rem;
    font-weight: 600;
    box-shadow: 0 3px 12px rgba(140, 106, 40, 0.08);
  }

  .mobile-env-title {
    font-family: var(--font-serif);
    font-size: clamp(1.4rem, 5.2vw, 1.8rem);
    font-weight: 500;
    color: var(--text-main);
    line-height: 1.2;
    margin-bottom: 0.25rem;
    padding: 0 0.5rem;
    text-wrap: balance;
  }

  .mobile-env-subtitle {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 0.92rem;
    color: var(--text-muted);
    letter-spacing: 0.03em;
  }

  /* 3D Envelope Container Stage */
  .mobile-env-stage {
    position: relative;
    width: 100%;
    max-width: 335px;
    height: 320px;
    perspective: 1200px;
    margin: 0 auto;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    z-index: 2;
    transition: margin-top 0.85s cubic-bezier(0.22, 1, 0.36, 1), height 0.85s cubic-bezier(0.22, 1, 0.36, 1);
  }

  /* Ambient Gold Light Dust Layer */
  .env-sparkles-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 20;
    overflow: visible;
  }

  .env-gold-speck {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, #FFF2B2 0%, #FFD700 60%, #D4AF37 100%);
    box-shadow: 0 0 6px rgba(255, 215, 0, 0.8);
    pointer-events: none;
    animation: goldDustFloat 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  }

  @keyframes goldDustFloat {
    0% {
      transform: translate(0, 0) scale(0.3) rotate(0deg);
      opacity: 1;
    }
    100% {
      transform: translate(var(--tx, 0px), var(--ty, -60px)) scale(1.2) rotate(var(--rot, 90deg));
      opacity: 0;
    }
  }

  /* The Envelope Box (Portrait Sizing) */
  .envelope-box {
    position: relative;
    width: calc(100% - 16px);
    max-width: 325px;
    height: 315px;
    margin: 0 auto;
    transform-style: preserve-3d;
  }

  /* 1. Soft Ambient Drop Shadow Underneath */
  .envelope-shadow {
    position: absolute;
    bottom: -18px;
    left: 8%;
    width: 84%;
    height: 28px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(64, 46, 32, 0.35) 0%, rgba(64, 46, 32, 0) 72%);
    filter: blur(8px);
    transition: transform 0.9s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.9s ease;
    z-index: 0;
  }

  /* 2. Envelope Back Shell & Imperial Damask Interior */
  .envelope-back {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #F9F4EB 0%, #EFE5D4 100%);
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(50, 36, 25, 0.18), inset 0 0 0 1px rgba(197, 160, 89, 0.35);
    overflow: hidden;
    z-index: 1;
  }

  .envelope-interior-lining {
    position: absolute;
    inset: 6px;
    border-radius: 12px;
    background-color: #1E241E; /* Deep Royal Forest Obsidian */
    background-image: 
      radial-gradient(circle at 50% 50%, rgba(212, 175, 55, 0.28) 1.5px, transparent 1.5px),
      linear-gradient(45deg, transparent 48%, rgba(212, 175, 55, 0.2) 50%, transparent 52%),
      linear-gradient(-45deg, transparent 48%, rgba(212, 175, 55, 0.2) 50%, transparent 52%);
    background-size: 20px 20px, 20px 20px, 20px 20px;
    border: 1px solid rgba(212, 175, 55, 0.35);
    opacity: 0.95;
  }

  /* 3. Gilded Silk Belly Band Across Middle */
  .envelope-gilded-band {
    position: absolute;
    top: 145px;
    left: 0;
    width: 100%;
    height: 42px;
    background: linear-gradient(180deg, #D4AF37 0%, #F5DE8B 50%, #B89146 100%);
    box-shadow: 0 4px 12px rgba(45, 32, 22, 0.15), inset 0 1px 2px rgba(255, 255, 255, 0.6);
    border-top: 1px solid rgba(255, 240, 180, 0.8);
    border-bottom: 1px solid rgba(130, 95, 30, 0.5);
    z-index: 5;
    pointer-events: none;
    overflow: hidden;
  }

  .band-filigree {
    position: absolute;
    inset: 2px 0;
    background-image: repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 8px,
      rgba(255, 255, 255, 0.2) 8px,
      rgba(255, 255, 255, 0.2) 10px
    );
    opacity: 0.65;
  }

  /* 4. Top Triangular Flap with 3D Flip Physics */
  .envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 155px;
    transform-origin: top center;
    transform-style: preserve-3d;
    transition: transform 0.85s cubic-bezier(0.34, 1.35, 0.64, 1), z-index 0.35s ease, filter 0.85s ease;
    will-change: transform;
    -webkit-clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
    clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
    background: linear-gradient(180deg, #FBF8F0 0%, #EFE4CF 90%, #E2D1B5 100%);
    filter: drop-shadow(0 8px 16px rgba(45, 32, 22, 0.2));
    z-index: 6;
    pointer-events: none;
  }

  .flap-gold-rim {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 55px;
    height: 2px;
    background: linear-gradient(90deg, transparent, #C5A059, transparent);
    z-index: 2;
  }

  .flap-interior-motif {
    position: absolute;
    inset: 0;
    background-color: #1E241E;
    background-image: 
      radial-gradient(circle at 50% 50%, rgba(212, 175, 55, 0.28) 1.5px, transparent 1.5px),
      linear-gradient(45deg, transparent 48%, rgba(212, 175, 55, 0.2) 50%, transparent 52%),
      linear-gradient(-45deg, transparent 48%, rgba(212, 175, 55, 0.2) 50%, transparent 52%);
    background-size: 20px 20px, 20px 20px, 20px 20px;
    opacity: 0;
    transition: opacity 0.4s ease 0.2s;
    z-index: 1;
  }

  .flap-heraldic-crest {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    height: 80px;
    pointer-events: none;
    z-index: 3;
    opacity: 0.85;
  }

  /* 5. Royal Invitation Card (Arched Cathedral Frame, Zero Emojis) */
  .envelope-card {
    position: absolute;
    top: 10px;
    left: 12px;
    right: 12px;
    width: auto;
    height: 335px;
    background: #FFFDF9;
    border-radius: 24px 24px 16px 16px; /* Arched cathedral top */
    box-shadow: 0 14px 35px rgba(35, 26, 18, 0.16);
    z-index: 2;
    padding: 0.8rem 0.75rem;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    opacity: 0;
    transform: translateY(15px) scale(0.96);
    pointer-events: none;
    transition: transform 0.95s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s ease, box-shadow 0.9s ease;
    will-change: transform, opacity;
  }

  .envelope-card.has-multi-events {
    height: 365px;
  }

  .mobile-env-stage.unfolded .envelope-card.has-multi-events {
    transform: translateY(-115px) scale(1.02);
  }

  /* Card Inner Frame & Debossed Ornamental Border */
  .card-inner-border {
    border: 1.5px solid rgba(197, 160, 89, 0.6);
    outline: 1px solid rgba(197, 160, 89, 0.3);
    outline-offset: -4px;
    padding: 0.85rem 0.75rem 0.65rem;
    border-radius: 20px 20px 12px 12px;
    background: radial-gradient(circle at center, #FFFFFF 0%, #FAF7F2 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    box-sizing: border-box;
  }

  .crest-wreath-svg {
    width: 50px;
    height: 24px;
    margin-bottom: 0.2rem;
  }

  .card-top-tag {
    font-family: var(--font-display);
    font-size: 0.65rem;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: #8C6A28;
    font-weight: 600;
    margin-bottom: 0.35rem;
  }

  .card-couple-names {
    font-family: var(--font-serif);
    font-size: 1.72rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.15;
    margin-bottom: 0.3rem;
  }

  .card-couple-names .amp {
    font-family: var(--font-script);
    color: #C5A059;
    font-size: 2.1rem;
    font-weight: normal;
    margin: 0 0.15rem;
    vertical-align: -2px;
  }

  .card-ornament-line {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 80%;
    margin-bottom: 0.5rem;
  }

  .card-ornament-line .line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(197, 160, 89, 0.4), transparent);
  }

  .card-ornament-line .diamond {
    font-size: 0.55rem;
    color: #C5A059;
  }

  .card-date-venue {
    font-family: var(--font-display);
    font-size: 0.76rem;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.6rem;
    line-height: 1.4;
  }

  .card-invite-msg {
    font-family: var(--font-serif);
    font-size: 0.78rem;
    color: #5C554F;
    font-style: italic;
    line-height: 1.45;
    border-top: 1px dashed rgba(197, 160, 89, 0.3);
    padding-top: 0.55rem;
    margin-bottom: 0.3rem;
    max-width: 92%;
  }

  .card-footer-flourish {
    font-family: var(--font-serif);
    font-size: 0.68rem;
    color: #B59350;
    letter-spacing: 0.16em;
    text-transform: uppercase;
  }

  /* 6. Lower Envelope Pocket */
  .envelope-pocket {
    position: absolute;
    inset: 0;
    z-index: 4;
    border-radius: 16px;
    overflow: hidden;
    pointer-events: none;
  }

  .pocket-flap {
    position: absolute;
    inset: 0;
  }

  .pocket-left {
    -webkit-clip-path: polygon(0% 0%, 0% 100%, 54% 52%);
    clip-path: polygon(0% 0%, 0% 100%, 54% 52%);
    background: linear-gradient(90deg, #FAF4E8 0%, #ECE0CB 100%);
    filter: drop-shadow(3px 0 6px rgba(45, 32, 22, 0.08));
  }

  .pocket-right {
    -webkit-clip-path: polygon(100% 0%, 100% 100%, 46% 52%);
    clip-path: polygon(100% 0%, 100% 100%, 46% 52%);
    background: linear-gradient(270deg, #FAF4E8 0%, #ECE0CB 100%);
    filter: drop-shadow(-3px 0 6px rgba(45, 32, 22, 0.08));
  }

  .pocket-bottom {
    -webkit-clip-path: polygon(0% 100%, 100% 100%, 50% 46%);
    clip-path: polygon(0% 100%, 100% 100%, 50% 46%);
    background: linear-gradient(180deg, #F9F2E4 0%, #E8DAC2 100%);
    filter: drop-shadow(0 -3px 8px rgba(45, 32, 22, 0.1));
  }

  /* 7. Royal Monogrammed Antique Gold Wax Seal */
  .wax-seal {
    position: absolute;
    top: 165px;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 72px;
    height: 72px;
    border-radius: 50%;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
    will-change: transform, opacity;
  }

  .wax-seal-body {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 48% 52% 49% 51% / 51% 49% 52% 48%; /* Organic molten edge */
    background: radial-gradient(circle at 35% 32%, #FFF0BA 0%, #D4AF37 36%, #9E782F 75%, #664B13 100%);
    box-shadow: 
      0 10px 26px rgba(78, 55, 12, 0.5),
      0 0 15px rgba(255, 215, 0, 0.4),
      0 2px 6px rgba(0, 0, 0, 0.28),
      inset 0 2px 4px rgba(255, 255, 255, 0.75),
      inset 0 -3px 5px rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .wax-seal-groove {
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    border: 1.5px dashed rgba(255, 255, 255, 0.5);
    pointer-events: none;
  }

  .wax-seal-center {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .wax-seal-monogram {
    font-family: var(--font-script);
    font-size: 1.85rem;
    color: #FFFFFF;
    text-shadow: 
      1px 1px 3px rgba(255, 255, 255, 0.8),
      -1px -1px 2px rgba(70, 48, 12, 0.7);
    line-height: 1;
    transform: translateY(0);
    position: relative;
    z-index: 3;
  }

  .wax-seal-year {
    font-family: var(--font-display);
    font-size: 0.45rem;
    letter-spacing: 0.18em;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }

  /* Radiant Breathing Halo on Wax Seal */
  .seal-glow-pulse {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    border: 2px solid rgba(255, 215, 0, 0.85);
    box-shadow: 0 0 14px rgba(255, 215, 0, 0.6);
    animation: sealRadiance 2.6s infinite ease-out;
    pointer-events: none;
  }

  @keyframes sealRadiance {
    0% {
      transform: scale(0.9);
      opacity: 0.95;
    }
    100% {
      transform: scale(1.48);
      opacity: 0;
    }
  }

  /* Mini Prompt Pill Under Wax Seal (No Emojis) */
  .seal-tap-badge {
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(36, 30, 26, 0.92);
    color: #F8E8CD;
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    padding: 2px 10px;
    border-radius: 12px;
    white-space: nowrap;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(212, 175, 55, 0.45);
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  /* ==========================================================================
     OPEN / UNFOLDED STATE (Triggered via tap or scroll)
     ========================================================================== */

  /* 1. Flap swings open 180deg */
  .mobile-env-stage.unfolded .envelope-flap {
    transform: rotateX(180deg);
    z-index: 2;
    filter: drop-shadow(0 -4px 10px rgba(45, 32, 22, 0.14));
  }

  .mobile-env-stage.unfolded .flap-interior-motif {
    opacity: 1;
  }

  .mobile-env-stage.unfolded .flap-heraldic-crest {
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .mobile-env-stage.unfolded {
    margin-top: 110px;
  }

  /* 2. Wax seal breaks & pops open */
  .mobile-env-stage.unfolded .wax-seal {
    transform: translate(-50%, -50%) scale(1.35) rotate(22deg);
    opacity: 0;
    pointer-events: none;
  }

  /* 3. Royal Invitation Card glides upwards and STAYS OPEN INDEFINITELY */
  .mobile-env-stage.unfolded .envelope-card {
    opacity: 1;
    transform: translateY(-95px) scale(1.02);
    box-shadow: 
      0 26px 60px rgba(40, 28, 18, 0.24),
      0 4px 15px rgba(197, 160, 89, 0.25);
    z-index: 8;
    pointer-events: auto;
    transition-delay: 0.22s;
  }

  /* 4. Ambient ground shadow softens */
  .mobile-env-stage.unfolded .envelope-shadow {
    transform: scale(1.08);
    opacity: 0.75;
  }

  /* ==========================================================================
     Action Bar & Unfold Button Controls (Zero Emojis)
     ========================================================================== */
  .env-action-bar {
    margin-top: 1.5rem;
    width: calc(100% - 32px);
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    position: relative;
    z-index: 15;
  }

  .env-tap-btn {
    position: relative;
    background: linear-gradient(135deg, #C5A059 0%, #E8D5A8 50%, #B89146 100%);
    color: #241E1A;
    border: none;
    padding: 0.8rem 1.9rem;
    border-radius: var(--radius-full);
    font-family: var(--font-sans);
    font-size: 0.84rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    box-shadow: 0 8px 24px rgba(184, 145, 70, 0.35);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.3s ease, color 0.3s ease;
    width: 100%;
    box-sizing: border-box;
  }

  /* Shimmer sweep line */
  .env-tap-btn::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -60%;
    width: 40%;
    height: 200%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
    transform: rotate(25deg);
    animation: btnShimmer 3.2s infinite ease-in-out;
  }

  @keyframes btnShimmer {
    0% { left: -60%; }
    30%, 100% { left: 140%; }
  }

  .env-tap-btn:active {
    transform: scale(0.97);
  }

  .mobile-env-stage.unfolded ~ .env-action-bar .env-tap-btn {
    background: linear-gradient(135deg, #241E1A 0%, #3B332C 100%);
    color: #FFFFFF;
    box-shadow: 0 8px 25px rgba(36, 30, 26, 0.3);
    border: 1px solid rgba(212, 175, 55, 0.5);
  }

  .env-scroll-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    animation: gentleBounce 2.2s infinite ease-in-out;
  }

  .hint-arrow {
    color: var(--gold-primary);
    font-weight: bold;
  }

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