// ==================== THREE COVER VARIANTS ====================
// All share: marsala/gold/ivory · couple-3 photo · "Save the date — we're getting married"
// · balanced ornaments · lush intro animation
//
// IMPORTANT: every responsive size is derived from container width (via
// useContainerWidth), NOT from `vw`. The variants render inside arbitrary-sized
// design-canvas artboards, so vw would be wildly wrong.

const COVER_DATE = 'Saturday, 9 May 2026 · 9:35 A.M';
const COVER_VENUE = 'Anvitha Gardens · Karimnagar';
const COVER_TAGLINE = "Save the date — we're getting married";

function useContainerWidth() {
  const ref = React.useRef(null);
  const [w, setW] = React.useState(1280);
  React.useLayoutEffect(() => {
    if (!ref.current) return;
    // initial sync measurement so first paint uses real width, not the 1280 default
    setW(ref.current.getBoundingClientRect().width);
    const ro = new ResizeObserver(entries => {
      for (const e of entries) setW(e.contentRect.width);
    });
    ro.observe(ref.current);
    return () => ro.disconnect();
  }, []);
  return [ref, w];
}

// scale a value range linearly between two container widths
function scale(w, [minW, maxW], [minV, maxV]) {
  const t = Math.max(0, Math.min(1, (w - minW) / (maxW - minW)));
  return minV + (maxV - minV) * t;
}

function useIntro() {
  const [phase, setPhase] = React.useState(0);
  React.useEffect(() => {
    const ts = [
      setTimeout(() => setPhase(1), 150),
      setTimeout(() => setPhase(2), 900),
      setTimeout(() => setPhase(3), 1700),
      setTimeout(() => setPhase(4), 2500),
    ];
    return () => ts.forEach(clearTimeout);
  }, []);
  return phase;
}

// ============================================================
// VARIANT A: CINEMATIC FULL-BLEED
// ============================================================
function CoverCinematic({ onEnter, embedded = false }) {
  const phase = useIntro();
  const [ref, w] = useContainerWidth();
  const narrow = w < 560;

  const nameSize = scale(w, [320, 1280], [54, 138]);
  const ampSize  = scale(w, [320, 1280], [56, 130]);
  const taglineSize = scale(w, [320, 1280], [16, 24]);

  return (
    <section ref={ref} style={{
      position:'relative',
      width:'100%', height: embedded ? '100%' : '100vh',
      minHeight: embedded ? 700 : undefined,
      overflow:'hidden',
      background:'#1a0a10',
    }}>
      {/* PHOTO */}
      <div style={{
        position:'absolute', inset:0,
        backgroundImage:'url(../../assets/photos/couple-3.jpeg)',
        backgroundSize:'cover',
        // On narrow viewports the landscape photo gets aggressively cropped;
        // shift the visible window toward the right so both faces stay in view.
        backgroundPosition: narrow ? '62% 32%' : 'center 30%',
        transform: phase >= 1 ? 'scale(1.0)' : 'scale(1.15)',
        transition:'transform 4s cubic-bezier(.2,.7,.2,1)',
        filter:'saturate(1.05) contrast(1.02)',
      }}/>
      {/* MARSALA VIGNETTE — heavier bottom scrim on narrow so names read clearly */}
      <div style={{
        position:'absolute', inset:0,
        background: narrow
          ? `radial-gradient(ellipse at 50% 30%, transparent 0%, rgba(122,31,43,.18) 40%, rgba(74,17,25,.7) 100%),
             linear-gradient(180deg, rgba(58,26,28,.55) 0%, rgba(58,26,28,.10) 22%, rgba(58,26,28,.55) 55%, rgba(20,5,9,.96) 100%)`
          : `radial-gradient(ellipse at 50% 35%, transparent 0%, rgba(122,31,43,.15) 40%, rgba(74,17,25,.85) 100%),
             linear-gradient(180deg, rgba(74,17,25,.55) 0%, transparent 30%, transparent 65%, rgba(20,5,9,.95) 100%)`,
      }}/>
      {/* GOLD GRAIN PATTERN */}
      <div style={{
        position:'absolute', inset:0,
        backgroundImage:'url(../../assets/patterns/kolam-tile.svg)',
        backgroundSize:'180px',
        opacity: .08,
        mixBlendMode:'overlay',
        pointerEvents:'none',
      }}/>
      {/* CORNER ORNAMENTS */}
      {['tl','tr','bl','br'].map((pos, i) => {
        const transforms = { tl:'rotate(0deg)', tr:'scaleX(-1)', bl:'scaleY(-1)', br:'scale(-1,-1)' };
        const positions = {
          tl:{top: narrow?12:24, left: narrow?12:24},
          tr:{top: narrow?12:24, right: narrow?12:24},
          bl:{bottom: narrow?12:24, left: narrow?12:24},
          br:{bottom: narrow?12:24, right: narrow?12:24},
        };
        const sz = narrow ? 56 : 84;
        return (
          <img key={pos} src="../../assets/ornaments/corner.svg" style={{
            position:'absolute', width:sz, height:sz,
            ...positions[pos],
            transform: `${transforms[pos]} scale(${phase >= 1 ? 1 : 0.6})`,
            opacity: phase >= 1 ? .7 : 0,
            transition: `opacity 1.2s ease ${0.2 + i*0.1}s, transform 1.2s ease ${0.2 + i*0.1}s`,
            filter:'drop-shadow(0 0 12px rgba(212,175,107,.4))',
            pointerEvents:'none',
          }}/>
        );
      })}

      {/* CENTER CONTENT — pushed lower on narrow so names sit on the bottom curtain */}
      <div style={{
        position:'absolute', inset:0,
        display:'flex', flexDirection:'column',
        alignItems:'center',
        justifyContent: narrow ? 'flex-end' : 'center',
        padding: narrow ? '0 20px 28px' : '40px 24px',
        textAlign:'center',
      }}>
        {/* mandala glow — on narrow its CENTER aligns with "The Wedding" divider */}
        {(() => {
          const size = narrow ? Math.min(440, w * 0.98) : Math.min(680, w * 0.9);
          // "The Wedding" divider sits ~150px from the bottom on narrow
          // (padding-bottom 70 + date 13 + 16 gap + tagline 22 + 22 gap + divider center ≈ 150)
          return (
            <div style={{
              position:'absolute',
              width: size, height: size,
              left:'50%',
              top: narrow ? 'auto' : '50%',
              bottom: narrow ? 275 : 'auto',
              transform: `translate(-50%, ${narrow ? '50%' : '-50%'}) rotate(${phase >= 1 ? 0 : -25}deg)`,
              backgroundImage:'url(../../assets/ornaments/mandala.svg)',
              backgroundSize:'contain', backgroundRepeat:'no-repeat', backgroundPosition:'center',
              opacity: phase >= 1 ? .14 : 0,
              transition:'all 4s cubic-bezier(.2,.7,.2,1)',
              filter:'invert(1) sepia(1) saturate(2)',
              pointerEvents:'none',
            }}/>
          );
        })()}

        <div style={{ position:'relative', zIndex:1 }}>
          <h1 style={{
            fontFamily:'var(--font-display)', fontStyle:'italic', fontWeight:500,
            fontSize: nameSize, color:'#FFF7E0', lineHeight:.95, margin:'0 0 10px',
            letterSpacing:'-.02em',
            textShadow:'0 2px 4px rgba(0,0,0,.55), 0 6px 30px rgba(0,0,0,.6), 0 0 60px rgba(212,175,107,.18)',
            opacity: phase >= 2 ? 1 : 0,
            transform: phase >= 2 ? 'translateX(0)' : 'translateX(-30px)',
            transition:'all 1.4s cubic-bezier(.2,.7,.2,1)',
          }}>
            Keerthi
          </h1>
          <div style={{
            fontFamily:'var(--font-script)',
            fontSize: ampSize, color:'#F2D27E', lineHeight:.7, margin:'-12px 0',
            textShadow:'0 2px 6px rgba(0,0,0,.5), 0 0 40px rgba(212,175,107,.6)',
            opacity: phase >= 3 ? 1 : 0,
            transform: phase >= 3 ? 'scale(1) rotate(0)' : 'scale(0.5) rotate(-8deg)',
            transition:'all 1.6s cubic-bezier(.2,.7,.2,1)',
          }}>
            &amp;
          </div>
          <h1 style={{
            fontFamily:'var(--font-display)', fontStyle:'italic', fontWeight:500,
            fontSize: nameSize, color:'#FFF7E0', lineHeight:.95, margin:0,
            letterSpacing:'-.02em',
            textShadow:'0 2px 4px rgba(0,0,0,.55), 0 6px 30px rgba(0,0,0,.6), 0 0 60px rgba(212,175,107,.18)',
            opacity: phase >= 2 ? 1 : 0,
            transform: phase >= 2 ? 'translateX(0)' : 'translateX(30px)',
            transition:'all 1.4s cubic-bezier(.2,.7,.2,1) .15s',
          }}>
            Gopichand
          </h1>
        </div>

        <div style={{
          display:'flex', alignItems:'center', gap:14,
          marginTop: 32, width: Math.min(440, w * 0.84),
          opacity: phase >= 4 ? 1 : 0,
          transform: phase >= 4 ? 'scaleX(1)' : 'scaleX(.4)',
          transition:'all 1s cubic-bezier(.2,.7,.2,1)',
        }}>
          <div style={{ flex:1, height:1, background:'linear-gradient(90deg, transparent, #D4AF6B)' }}/>
          <div style={{
            fontFamily:'var(--font-ui)', fontSize:10, letterSpacing:'.4em',
            textTransform:'uppercase', color:'#E5C168',
          }}>
            The Wedding
          </div>
          <div style={{ flex:1, height:1, background:'linear-gradient(-90deg, transparent, #D4AF6B)' }}/>
        </div>

        <div style={{
          fontFamily:'var(--font-display)', fontStyle:'italic',
          fontSize: taglineSize, color:'#FBF3E3', marginTop: 22,
          textShadow:'0 2px 8px rgba(0,0,0,.55)',
          opacity: phase >= 4 ? 1 : 0,
          transition:'opacity 1.2s ease .2s',
        }}>
          we&apos;re getting married
        </div>

        <div style={{
          fontFamily:'var(--font-ui)', fontSize: narrow ? 11 : 12, letterSpacing:'.3em',
          textTransform:'uppercase', color:'#F4E8C8',
          textShadow:'0 2px 8px rgba(0,0,0,.55)',
          marginTop: 16, textAlign:'center', maxWidth:'90%',
          opacity: phase >= 4 ? 1 : 0,
          transition:'opacity 1.2s ease .35s',
        }}>
          {COVER_DATE}
          <br/>
          {COVER_VENUE}
        </div>

        {onEnter && (
          <button
            type="button"
            onClick={(e) => { e.preventDefault(); onEnter(); }}
            style={{
              marginTop: 36,
              fontFamily:'var(--font-ui)', fontSize:12, letterSpacing:'.28em',
              textTransform:'uppercase', color:'#4A1119',
              background:'linear-gradient(180deg, #E5C168, #C79A3A)',
              border:'1px solid #C79A3A', borderRadius:999,
              padding:'14px 32px',
              cursor:'pointer',
              boxShadow:'0 8px 24px rgba(0,0,0,.4), 0 0 0 4px rgba(229,193,104,.15)',
              opacity: phase >= 4 ? 1 : 0,
              transform: phase >= 4 ? 'translateY(0)' : 'translateY(12px)',
              transition:'opacity 1s ease .5s, transform 1s ease .5s',
              // Defensive: keep the button tappable on touch and on top of the
              // mandala/photo decorative layers no matter how they stack.
              position:'relative', zIndex: 20,
              pointerEvents: phase >= 4 ? 'auto' : 'none',
              touchAction:'manipulation',
              WebkitTapHighlightColor:'rgba(229,193,104,.3)',
              WebkitAppearance:'none',
            }}>
            Open the Invitation
          </button>
        )}

        {/* Save the Date — transparent pill with double-rule gold border */}
        <SaveTheDateButton phase={phase} />
      </div>
    </section>
  );
}

// ============================================================
// VARIANT B: REGAL MANDALA ARCH
// ============================================================
function CoverRegal({ onEnter, embedded = false }) {
  const phase = useIntro();
  const [ref, w] = useContainerWidth();
  const narrow = w < 560;

  const nameSize    = scale(w, [320, 1280], [34, 76]);
  const ampSize     = scale(w, [320, 1280], [34, 64]);
  const taglineSize = scale(w, [320, 1280], [15, 22]);
  const photoSize   = narrow ? Math.min(130, w * 0.4) : 180;
  const archMaxW    = Math.min(560, w - 48);

  return (
    <section ref={ref} style={{
      position:'relative',
      width:'100%', height: embedded ? '100%' : '100vh',
      minHeight: embedded ? 700 : undefined,
      overflow:'hidden',
      background:'radial-gradient(ellipse at 50% 0%, #8E2030 0%, #6B1A24 40%, #4A1119 100%)',
      padding: narrow ? '28px 12px' : '40px 16px',
      display:'flex', alignItems:'center', justifyContent:'center',
    }}>
      <div style={{
        position:'absolute', inset:0,
        backgroundImage:'url(../../assets/patterns/kolam-tile.svg)',
        backgroundSize:'160px', opacity: .07, filter:'invert(1)',
        pointerEvents:'none',
      }}/>
      <div style={{ position:'absolute', inset: narrow?'18px':'24px', border:'1px solid rgba(212,175,107,.45)', pointerEvents:'none' }}/>
      <div style={{ position:'absolute', inset: narrow?'24px':'30px', border:'1px solid rgba(212,175,107,.25)', pointerEvents:'none' }}/>

      {[
        { pos:{top: narrow?12:18, left: narrow?12:18}, t:'rotate(0deg)' },
        { pos:{top: narrow?12:18, right: narrow?12:18}, t:'scaleX(-1)' },
        { pos:{bottom: narrow?12:18, left: narrow?12:18}, t:'scaleY(-1)' },
        { pos:{bottom: narrow?12:18, right: narrow?12:18}, t:'scale(-1,-1)' },
      ].map((c,i) => (
        <img key={i} src="../../assets/ornaments/corner.svg" style={{
          position:'absolute', width: narrow?44:64, height: narrow?44:64,
          ...c.pos, transform: c.t,
          opacity: phase >= 1 ? .55 : 0,
          transition:`opacity 1.2s ease ${i*0.08}s`,
        }}/>
      ))}

      <div style={{
        position:'relative', zIndex:1,
        display:'flex', flexDirection:'column', alignItems:'center',
        textAlign:'center', maxWidth: 640, width:'100%',
      }}>
        {/* photo medallion */}
        <div style={{
          width: photoSize, aspectRatio:'1', borderRadius:'50%',
          backgroundImage:'url(../../assets/photos/couple-3.jpeg)',
          backgroundSize:'cover', backgroundPosition:'center 30%',
          border:'2px solid #D4AF6B',
          boxShadow:`0 0 0 6px #4A1119, 0 0 0 7px #D4AF6B, 0 0 0 13px #4A1119, 0 0 0 14px rgba(212,175,107,.5), 0 18px 48px rgba(0,0,0,.5)`,
          opacity: phase >= 1 ? 1 : 0,
          transform: phase >= 1 ? 'scale(1)' : 'scale(.6)',
          transition:'all 1.2s cubic-bezier(.2,.7,.2,1)',
        }}/>

        <div style={{
          fontFamily:'var(--font-ui)', fontSize: narrow?9:11, letterSpacing:'.5em',
          textTransform:'uppercase', color:'#E5C168',
          marginTop: narrow?16:22,
          opacity: phase >= 2 ? 1 : 0,
          transition:'opacity 1s ease .1s',
        }}>
          ✦ &nbsp; Save the Date &nbsp; ✦
        </div>

        {/* THE ARCH */}
        <div style={{ position:'relative', marginTop: narrow?8:14, width:'100%', maxWidth: archMaxW }}>
          <svg viewBox="0 0 600 520" style={{ width:'100%', height:'auto', display:'block' }}>
            <defs>
              <linearGradient id="archGold" x1="0" y1="0" x2="0" y2="1">
                <stop offset="0%" stopColor="#E5C168"/>
                <stop offset="50%" stopColor="#D4AF6B"/>
                <stop offset="100%" stopColor="#A07B2E"/>
              </linearGradient>
            </defs>
            <path d="M 60 510 L 60 240 Q 60 60 300 60 Q 540 60 540 240 L 540 510"
              fill="none" stroke="url(#archGold)" strokeWidth="2.5"
              strokeDasharray="2200" strokeDashoffset={phase >= 1 ? 0 : 2200}
              style={{ transition:'stroke-dashoffset 2.4s cubic-bezier(.4,.1,.2,1)' }} />
            <path d="M 80 510 L 80 248 Q 80 80 300 80 Q 520 80 520 248 L 520 510"
              fill="none" stroke="url(#archGold)" strokeWidth="1"
              strokeDasharray="2200" strokeDashoffset={phase >= 1 ? 0 : 2200}
              opacity=".6"
              style={{ transition:'stroke-dashoffset 2.4s cubic-bezier(.4,.1,.2,1) .15s' }} />
            <circle cx="300" cy="60" r="8" fill="#E5C168" opacity={phase >= 2 ? 1 : 0} style={{transition:'opacity .8s ease .8s'}}/>
            <circle cx="300" cy="60" r="3" fill="#4A1119" opacity={phase >= 2 ? 1 : 0} style={{transition:'opacity .8s ease .8s'}}/>
            <line x1="300" y1="68" x2="300" y2="100" stroke="#D4AF6B" strokeWidth="1" opacity={phase >= 2 ? .7 : 0} style={{transition:'opacity 1s ease 1s'}}/>
            <circle cx="300" cy="106" r="4" fill="#E5C168" opacity={phase >= 2 ? 1 : 0} style={{transition:'opacity 1s ease 1.1s'}}/>
          </svg>

          {/* Names overlaid inside arch */}
          <div style={{
            position:'absolute', inset:0,
            display:'flex', flexDirection:'column',
            alignItems:'center', justifyContent:'center',
            paddingTop:'8%',
          }}>
            <div style={{
              fontFamily:'var(--font-ui)', fontSize: narrow?8:10, letterSpacing:'.5em',
              textTransform:'uppercase', color:'#D4AF6B', marginBottom: 8,
              opacity: phase >= 3 ? 1 : 0,
              transition:'opacity .8s ease',
            }}>
              The Marriage of
            </div>
            <h1 style={{
              fontFamily:'var(--font-display)', fontStyle:'italic', fontWeight:500,
              fontSize: nameSize, color:'#F8EBC8', lineHeight:1, margin:0,
              letterSpacing:'-.01em',
              opacity: phase >= 3 ? 1 : 0,
              transform: phase >= 3 ? 'translateY(0)' : 'translateY(8px)',
              transition:'all 1s cubic-bezier(.2,.7,.2,1)',
            }}>
              Keerthi
            </h1>
            <div style={{
              fontFamily:'var(--font-script)',
              fontSize: ampSize, color:'#E5C168', lineHeight:.7, margin:'-2px 0',
              opacity: phase >= 3 ? 1 : 0,
              transform: phase >= 3 ? 'rotate(0)' : 'rotate(-8deg)',
              transition:'all 1.2s cubic-bezier(.2,.7,.2,1) .1s',
            }}>
              &amp;
            </div>
            <h1 style={{
              fontFamily:'var(--font-display)', fontStyle:'italic', fontWeight:500,
              fontSize: nameSize, color:'#F8EBC8', lineHeight:1, margin:0,
              letterSpacing:'-.01em',
              opacity: phase >= 3 ? 1 : 0,
              transform: phase >= 3 ? 'translateY(0)' : 'translateY(-8px)',
              transition:'all 1s cubic-bezier(.2,.7,.2,1) .2s',
            }}>
              Gopichand
            </h1>
            <div style={{
              fontFamily:'var(--font-telugu)', fontSize: narrow?12:17,
              color:'#D4AF6B', marginTop: 14,
              opacity: phase >= 4 ? .9 : 0,
              transition:'opacity 1s ease',
            }}>
              కీర్తి &amp; గోపి
            </div>
          </div>
        </div>

        <div style={{
          fontFamily:'var(--font-display)', fontStyle:'italic',
          fontSize: taglineSize, color:'#F4E8C8', marginTop: 4,
          opacity: phase >= 4 ? 1 : 0,
          transition:'opacity 1s ease .2s', textAlign:'center', padding:'0 12px',
        }}>
          {COVER_TAGLINE}
        </div>
        <div style={{
          fontFamily:'var(--font-ui)', fontSize: narrow?10:11, letterSpacing:'.32em',
          textTransform:'uppercase', color:'#D4AF6B', marginTop: 10,
          opacity: phase >= 4 ? 1 : 0,
          transition:'opacity 1s ease .35s',
        }}>
          {COVER_DATE}
        </div>
        <div style={{
          fontFamily:'var(--font-ui)', fontSize: narrow?9:10, letterSpacing:'.32em',
          textTransform:'uppercase', color:'rgba(212,175,107,.75)', marginTop: 4,
          textAlign:'center', padding:'0 12px',
          opacity: phase >= 4 ? 1 : 0,
          transition:'opacity 1s ease .45s',
        }}>
          {COVER_VENUE}
        </div>

        {onEnter && (
          <button onClick={onEnter} style={{
            marginTop: 24,
            fontFamily:'var(--font-ui)', fontSize:11, letterSpacing:'.3em',
            textTransform:'uppercase', color:'#4A1119',
            background:'linear-gradient(180deg, #E5C168, #C79A3A)',
            border:'1px solid #A07B2E', borderRadius:999,
            padding:'12px 28px', cursor:'pointer',
            opacity: phase >= 4 ? 1 : 0,
            transition:'opacity 1s ease .55s',
          }}>
            Open the Invitation
          </button>
        )}
      </div>
    </section>
  );
}

// ============================================================
// VARIANT C: EDITORIAL SPLIT
// Wide: 2-col split (marsala names | photo). Narrow: stacked (photo on top, names below).
// ============================================================
function CoverEditorial({ onEnter, embedded = false }) {
  const phase = useIntro();
  const [ref, w] = useContainerWidth();
  const narrow = w < 720;

  const nameSize    = scale(w, [320, 1280], [40, 156]);
  const wedsSize    = scale(w, [320, 1280], [32, 96]);
  const taglineSize = scale(w, [320, 1280], [15, 22]);

  return (
    <section ref={ref} style={{
      position:'relative',
      width:'100%', height: embedded ? '100%' : '100vh',
      minHeight: embedded ? 700 : undefined,
      overflow:'hidden',
      display:'grid',
      gridTemplateColumns: narrow ? '1fr' : '1.05fr 1fr',
      gridTemplateRows: narrow ? 'minmax(220px, 38%) 1fr' : '1fr',
      background:'#FBF3E3',
    }}>
      {/* PHOTO PANEL — first in narrow mode (top), second in wide (right) */}
      <div style={{
        position:'relative', overflow:'hidden',
        order: narrow ? 1 : 2,
      }}>
        <div style={{
          position:'absolute', inset:0,
          backgroundImage:'url(../../assets/photos/couple-3.jpeg)',
          backgroundSize:'cover', backgroundPosition:'center 25%',
          transform: phase >= 1 ? 'scale(1)' : 'scale(1.15)',
          transition:'transform 4s cubic-bezier(.2,.7,.2,1)',
        }}/>
        <div style={{
          position:'absolute', inset:0,
          background:'linear-gradient(135deg, rgba(74,17,25,.18) 0%, transparent 30%, transparent 70%, rgba(74,17,25,.35) 100%)',
        }}/>
        <div style={{
          position:'absolute', inset: narrow?12:24,
          border:'1px solid rgba(229,193,104,.55)',
          opacity: phase >= 1 ? 1 : 0,
          transition:'opacity 1.4s ease .4s',
          pointerEvents:'none',
        }}/>
        {!narrow && [
          { pos:{top:32, left:32}, t:'rotate(0deg)' },
          { pos:{top:32, right:32}, t:'scaleX(-1)' },
          { pos:{bottom:32, left:32}, t:'scaleY(-1)' },
          { pos:{bottom:32, right:32}, t:'scale(-1,-1)' },
        ].map((c,i) => (
          <img key={i} src="../../assets/ornaments/corner.svg" style={{
            position:'absolute', width:48, height:48,
            ...c.pos, transform: c.t,
            opacity: phase >= 2 ? .85 : 0,
            transition:`opacity 1s ease ${.5 + i*0.1}s`,
            filter:'drop-shadow(0 2px 8px rgba(0,0,0,.4))',
          }}/>
        ))}
        {/* monogram seal — only show on wide */}
        {!narrow && (
          <div style={{
            position:'absolute', bottom:60, left:'50%',
            width:90, height:90, borderRadius:'50%',
            background:'linear-gradient(180deg, #E5C168, #C79A3A)',
            display:'flex', alignItems:'center', justifyContent:'center',
            border:'2px solid #4A1119',
            boxShadow:'0 12px 30px rgba(0,0,0,.4), inset 0 0 0 4px rgba(74,17,25,.15)',
            opacity: phase >= 4 ? 1 : 0,
            transform: `translateX(-50%) scale(${phase >= 4 ? 1 : .4}) rotate(${phase >= 4 ? 0 : -180}deg)`,
            transition:'all 1.4s cubic-bezier(.2,.7,.2,1)',
          }}>
            <div style={{ fontFamily:'var(--font-script)', fontSize:42, color:'#4A1119', lineHeight:1, letterSpacing:'-.02em' }}>
              K&amp;G
            </div>
          </div>
        )}
      </div>

      {/* MARSALA NAME PANEL */}
      <div style={{
        position:'relative',
        background:`linear-gradient(160deg, #6B1A24 0%, #4A1119 100%)`,
        padding: narrow ? '28px 22px' : '56px 48px',
        display:'flex', flexDirection:'column', justifyContent: narrow ? 'center' : 'space-between',
        gap: narrow ? 18 : 0,
        overflow:'hidden',
        order: narrow ? 2 : 1,
      }}>
        <div style={{
          position:'absolute', inset:0,
          backgroundImage:'url(../../assets/patterns/kolam-tile.svg)',
          backgroundSize:'200px', opacity:.06, filter:'invert(1)',
        }}/>
        <img src="../../assets/ornaments/mandala.svg" style={{
          position:'absolute', bottom:-180, left:-180,
          width: narrow ? 320 : 540,
          opacity: phase >= 1 ? .12 : 0,
          transform: `rotate(${phase >= 1 ? 0 : -45}deg)`,
          transition:'all 3s cubic-bezier(.2,.7,.2,1)',
          filter:'invert(1) sepia(1) saturate(2)',
        }}/>

        {/* TOP eyebrow */}
        {!narrow && (
          <div style={{ position:'relative', zIndex:1 }}>
            <div style={{
              fontFamily:'var(--font-ui)', fontSize:10, letterSpacing:'.5em',
              textTransform:'uppercase', color:'#D4AF6B',
              opacity: phase >= 2 ? 1 : 0,
              transform: phase >= 2 ? 'translateY(0)' : 'translateY(-8px)',
              transition:'all 1s ease',
            }}>
              ✦ &nbsp; Save the Date
            </div>
            <div style={{
              fontFamily:'var(--font-display)', fontStyle:'italic',
              fontSize:14, color:'#E5C168', marginTop:6,
              opacity: phase >= 2 ? .8 : 0,
              transition:'opacity 1s ease .1s',
            }}>
              Vol. I &nbsp;·&nbsp; № 09.05.26
            </div>
          </div>
        )}

        {/* CENTER stacked names */}
        <div style={{ position:'relative', zIndex:1 }}>
          {narrow && (
            <div style={{
              fontFamily:'var(--font-ui)', fontSize:9, letterSpacing:'.5em',
              textTransform:'uppercase', color:'#D4AF6B', marginBottom: 12,
              textAlign:'center',
              opacity: phase >= 2 ? 1 : 0, transition:'opacity 1s ease',
            }}>
              ✦ &nbsp; Save the Date &nbsp; ✦
            </div>
          )}
          <h1 style={{
            fontFamily:'var(--font-display)', fontWeight:500,
            fontSize: nameSize, color:'#F8EBC8', lineHeight:.88, margin:0,
            letterSpacing:'-.04em', textTransform:'uppercase',
            textAlign: narrow ? 'center' : 'left',
            opacity: phase >= 2 ? 1 : 0,
            transform: phase >= 2 ? 'translateX(0)' : 'translateX(-30px)',
            transition:'all 1.4s cubic-bezier(.2,.7,.2,1)',
          }}>
            Keerthi
          </h1>
          <div style={{
            display:'flex', alignItems:'center', gap: narrow?10:14, margin: narrow ? '6px 0' : '14px 0',
            justifyContent: narrow ? 'center' : 'flex-start',
            opacity: phase >= 3 ? 1 : 0,
            transform: phase >= 3 ? 'scaleX(1)' : 'scaleX(.3)',
            transformOrigin: narrow ? 'center' : 'left',
            transition:'all 1.2s cubic-bezier(.2,.7,.2,1)',
          }}>
            <div style={{ flex:'0 0 40px', height:1, background:'#D4AF6B' }}/>
            <div style={{
              fontFamily:'var(--font-script)',
              fontSize: wedsSize, color:'#E5C168', lineHeight:.7,
            }}>
              weds
            </div>
            <div style={{ flex:'0 0 40px', height:1, background:'#D4AF6B' }}/>
          </div>
          <h1 style={{
            fontFamily:'var(--font-display)', fontWeight:500,
            fontSize: nameSize, color:'#F8EBC8', lineHeight:.88, margin:0,
            letterSpacing:'-.04em', textTransform:'uppercase',
            textAlign: narrow ? 'center' : 'right',
            opacity: phase >= 2 ? 1 : 0,
            transform: phase >= 2 ? 'translateX(0)' : 'translateX(30px)',
            transition:'all 1.4s cubic-bezier(.2,.7,.2,1) .15s',
          }}>
            Gopichand
          </h1>

          <div style={{
            fontFamily:'var(--font-telugu)', fontSize: narrow?14:18,
            color:'#D4AF6B', marginTop: narrow?12:18,
            textAlign: narrow ? 'center' : 'right',
            opacity: phase >= 4 ? .85 : 0,
            transition:'opacity 1s ease',
          }}>
            కీర్తి &amp; గోపి
          </div>
        </div>

        {/* BOTTOM tagline + meta */}
        <div style={{
          position:'relative', zIndex:1,
          textAlign: narrow ? 'center' : 'left',
          opacity: phase >= 4 ? 1 : 0,
          transform: phase >= 4 ? 'translateY(0)' : 'translateY(12px)',
          transition:'all 1s ease',
        }}>
          <div style={{
            fontFamily:'var(--font-display)', fontStyle:'italic',
            fontSize: taglineSize, color:'#F4E8C8',
          }}>
            {COVER_TAGLINE}
          </div>
          <div style={{
            display:'flex', alignItems:'center',
            justifyContent: narrow ? 'center' : 'space-between',
            flexDirection: narrow ? 'column' : 'row',
            gap: narrow?12:18, marginTop: narrow?14:18, flexWrap:'wrap',
          }}>
            <div>
              <div style={{
                fontFamily:'var(--font-ui)', fontSize: narrow?10:11, letterSpacing:'.3em',
                textTransform:'uppercase', color:'#D4AF6B',
              }}>
                {COVER_DATE}
              </div>
              <div style={{
                fontFamily:'var(--font-ui)', fontSize: narrow?9:10, letterSpacing:'.3em',
                textTransform:'uppercase', color:'rgba(212,175,107,.7)', marginTop:4,
              }}>
                {COVER_VENUE}
              </div>
            </div>
            {onEnter && (
              <button onClick={onEnter} style={{
                fontFamily:'var(--font-ui)', fontSize:11, letterSpacing:'.28em',
                textTransform:'uppercase', color:'#4A1119',
                background:'linear-gradient(180deg, #E5C168, #C79A3A)',
                border:'1px solid #A07B2E', borderRadius:0,
                padding:'13px 24px', cursor:'pointer', whiteSpace:'nowrap',
              }}>
                Open Invitation →
              </button>
            )}
          </div>
        </div>
      </div>
    </section>
  );
}

// ============================================================
// VARIANT D: RING CEREMONY (mandap photo, full-bleed)
// ============================================================
function CoverMandap({ onEnter, embedded = false }) {
  const phase = useIntro();
  const [ref, w] = useContainerWidth();
  // Treat anything below 760 as "narrow" so portrait phones/tablets get the
  // stacked layout (photo on top, solid marsala panel for text below).
  const narrow = w < 760;

  const eyebrowSize = scale(w, [320, 1280], [10, 13]);
  const nameSize    = scale(w, [320, 1280], [44, 112]);
  const ampSize     = scale(w, [320, 1280], [40, 88]);
  const dateSize    = scale(w, [320, 1280], [13, 18]);
  const venueSize   = scale(w, [320, 1280], [10, 12]);
  const cornerSize  = scale(w, [320, 1280], [44, 96]);
  const padX        = scale(w, [320, 1280], [18, 64]);
  const padY        = scale(w, [320, 1280], [22, 56]);

  // Photo crop. On narrow viewports the visible window is much taller than
  // the landscape photo's aspect, so we shift X past 50% to favour the right
  // side (bride) — both faces stay in view. On wide viewports center is fine.
  const photoPos = narrow ? '62% 38%' : '50% 42%';

  // Tagline content
  const Eyebrow = (
    <div style={{
      fontFamily:'var(--font-ui)',
      fontSize: eyebrowSize,
      letterSpacing:'.42em', textTransform:'uppercase',
      color:'var(--gold-300)',
      textShadow:'0 2px 14px rgba(0,0,0,.6)',
      // letter-spacing adds trailing space after each glyph; text-indent of
      // the same value pushes the run left so the line is visually centered.
      textIndent:'.42em',
    }}>
      ✦ &nbsp; Save the date — we&apos;re getting married &nbsp; ✦
    </div>
  );

  const Names = (
    <div style={{
      opacity: phase >= 2 ? 1 : 0,
      transform: phase >= 2 ? 'translateY(0)' : 'translateY(12px)',
      transition:'opacity .9s ease-out, transform 1s ease-out',
    }}>
      <div style={{
        fontFamily:'var(--font-display)', fontStyle:'italic', fontWeight:500,
        fontSize: nameSize, lineHeight:1, color:'var(--ivory-50)',
        letterSpacing:'-.02em',
        textShadow:'0 4px 24px rgba(0,0,0,.55)',
      }}>
        Keerthi
      </div>
      <div style={{
        fontFamily:'var(--font-script)', color:'var(--gold-400)',
        fontSize: ampSize, lineHeight:1, margin: narrow ? '-4px 0' : '-12px 0',
        textShadow:'0 4px 18px rgba(0,0,0,.55)',
      }}>
        &amp;
      </div>
      <div style={{
        fontFamily:'var(--font-display)', fontStyle:'italic', fontWeight:500,
        fontSize: nameSize, lineHeight:1, color:'var(--ivory-50)',
        letterSpacing:'-.02em',
        textShadow:'0 4px 24px rgba(0,0,0,.55)',
      }}>
        Gopichand
      </div>
    </div>
  );

  const Meta = (
    <>
      <div style={{
        margin:'18px auto 0', width:'min(280px, 70%)', height:1,
        background:'linear-gradient(90deg, transparent, var(--gold-500), transparent)',
        opacity: phase >= 3 ? 1 : 0, transition:'opacity .8s ease-out',
      }}/>
      <div style={{
        marginTop:14,
        fontFamily:'var(--font-body)', fontStyle:'italic',
        fontSize: dateSize, color:'var(--ivory-100)',
        opacity: phase >= 3 ? 1 : 0,
        transform: phase >= 3 ? 'translateY(0)' : 'translateY(6px)',
        transition:'all .8s ease-out',
        textShadow:'0 2px 10px rgba(0,0,0,.5)',
      }}>
        {COVER_DATE}
      </div>
      <div style={{
        marginTop:8,
        fontFamily:'var(--font-ui)', fontSize: venueSize,
        letterSpacing:'.32em', textTransform:'uppercase',
        color:'var(--gold-300)',
        opacity: phase >= 3 ? 1 : 0,
        transition:'opacity 1s ease-out',
        textShadow:'0 2px 10px rgba(0,0,0,.6)',
      }}>
        {COVER_VENUE}
      </div>
      {!embedded && (
        <div style={{
          marginTop: 24,
          display:'flex', flexDirection:'column', alignItems:'center', gap: 4,
          opacity: phase >= 4 ? 1 : 0,
          transform: phase >= 4 ? 'translateY(0)' : 'translateY(8px)',
          transition:'all .7s ease-out',
        }}>
          <Button variant="gold" onClick={onEnter}>Open the Invitation</Button>
          <SaveTheDateButton phase={phase} />
        </div>
      )}
    </>
  );

  // ───────── NARROW LAYOUT — photo on top, marsala panel below ─────────
  if (narrow) {
    return (
      <section
        ref={ref}
        style={{
          position:'relative', width:'100%',
          height: embedded ? '100%' : '100vh',
          minHeight: embedded ? undefined : '100vh',
          overflow:'hidden',
          display:'flex', flexDirection:'column',
          background:'var(--marsala-900)',
        }}
      >
        {/* Photo half */}
        <div style={{
          position:'relative', flex:'0 0 52%',
          overflow:'hidden', background:'#0e0508',
        }}>
          <div style={{
            position:'absolute', inset:0,
            backgroundImage:'url(../../assets/photos/ring-exchange.jpeg)',
            backgroundSize:'cover',
            backgroundPosition: photoPos,
            transform: phase >= 1 ? 'scale(1.04)' : 'scale(1.14)',
            transition: 'transform 4s cubic-bezier(.2,.8,.2,1), opacity 1.2s',
            opacity: phase >= 1 ? 1 : 0,
          }}/>
          {/* feather into the marsala panel below */}
          <div style={{
            position:'absolute', bottom:0, left:0, right:0, height:'40%',
            background:'linear-gradient(180deg, transparent, rgba(26,8,11,.55) 60%, var(--marsala-900))',
            pointerEvents:'none',
          }}/>
          {/* eyebrow on top */}
          <div style={{
            position:'absolute', top: padY, left:0, right:0, textAlign:'center', zIndex:2,
            padding:`0 ${padX}px`,
            opacity: phase >= 2 ? 1 : 0,
            transform: phase >= 2 ? 'translateY(0)' : 'translateY(-8px)',
            transition:'opacity .9s ease-out, transform .9s ease-out',
          }}>
            {Eyebrow}
          </div>
        </div>

        {/* Marsala name panel */}
        <div style={{
          position:'relative', flex:'1 1 48%',
          padding:`${padY + 18}px ${padX}px ${padY}px`,
          textAlign:'center',
          background:'var(--marsala-900)',
          display:'flex', flexDirection:'column', justifyContent:'flex-end', alignItems:'stretch',
        }}>
          {/* Subtle kolam texture */}
          <div style={{
            position:'absolute', inset:0,
            backgroundImage:'url(../../assets/patterns/kolam-tile.svg)',
            backgroundSize:'180px',
            opacity:.06, mixBlendMode:'overlay', pointerEvents:'none',
          }}/>
          {/* Gold corners on the panel */}
          {[
            { top: 10, left: 10, transform: 'none' },
            { top: 10, right: 10, transform: 'scaleX(-1)' },
            { bottom: 10, left: 10, transform: 'scaleY(-1)' },
            { bottom: 10, right: 10, transform: 'scale(-1,-1)' },
          ].map((pos, i) => (
            <img key={i} src="../../assets/ornaments/corner.svg"
              style={{
                position:'absolute', width:cornerSize * .7, height:cornerSize * .7,
                opacity: phase >= 2 ? .55 : 0,
                transition:'opacity 1.1s ease-out',
                pointerEvents:'none',
                ...pos,
              }}/>
          ))}

          <div style={{ position:'relative', zIndex:2 }}>
            {Names}
            {Meta}
          </div>
        </div>
      </section>
    );
  }

  // ───────── WIDE LAYOUT — full-bleed cinematic ─────────
  return (
    <section
      ref={ref}
      style={{
        position:'relative', width:'100%', height: embedded ? '100%' : '100vh',
        minHeight: embedded ? undefined : '100vh',
        overflow:'hidden', background:'#0e0508',
      }}
    >
      {/* Hero photo */}
      <div style={{
        position:'absolute', inset:0,
        backgroundImage:'url(../../assets/photos/ring-exchange.jpeg)',
        backgroundSize:'cover',
        backgroundPosition: photoPos,
        transform: phase >= 1 ? 'scale(1.04)' : 'scale(1.14)',
        transition: 'transform 4s cubic-bezier(.2,.8,.2,1), opacity 1.2s',
        opacity: phase >= 1 ? 1 : 0,
      }}/>

      {/* Top gradient */}
      <div style={{
        position:'absolute', top:0, left:0, right:0, height:'42%',
        background:'linear-gradient(180deg, rgba(58,26,28,.65), rgba(58,26,28,.18) 60%, transparent)',
        pointerEvents:'none',
      }}/>

      {/* Bottom marsala curtain */}
      <div style={{
        position:'absolute', bottom:0, left:0, right:0, height:'62%',
        background:'linear-gradient(180deg, transparent, rgba(58,26,28,.55) 38%, rgba(26,8,11,.94))',
        pointerEvents:'none',
      }}/>

      {/* Soft kolam pattern */}
      <div style={{
        position:'absolute', inset:0,
        backgroundImage:'url(../../assets/patterns/kolam-tile.svg)',
        backgroundSize:'200px',
        opacity:.05, mixBlendMode:'overlay', pointerEvents:'none',
      }}/>

      {/* Gold corner ornaments */}
      {[
        { top: padY, left: padX, transform: 'none' },
        { top: padY, right: padX, transform: 'scaleX(-1)' },
        { bottom: padY, left: padX, transform: 'scaleY(-1)' },
        { bottom: padY, right: padX, transform: 'scale(-1,-1)' },
      ].map((pos, i) => (
        <img key={i} src="../../assets/ornaments/corner.svg"
          style={{
            position:'absolute', width:cornerSize, height:cornerSize,
            opacity: phase >= 2 ? .82 : 0,
            transition:'opacity 1.1s ease-out',
            filter:'drop-shadow(0 2px 6px rgba(0,0,0,.45))',
            pointerEvents:'none',
            ...pos,
          }}/>
      ))}

      {/* Top eyebrow */}
      <div style={{
        position:'absolute', top: padY + 8, left:0, right:0,
        textAlign:'center', zIndex:2,
        padding:`0 ${padX}px`,
        opacity: phase >= 2 ? 1 : 0,
        transform: phase >= 2 ? 'translateY(0)' : 'translateY(-8px)',
        transition:'opacity .9s ease-out, transform .9s ease-out',
      }}>
        {Eyebrow}
      </div>

      {/* Bottom name block */}
      <div style={{
        position:'absolute', left:0, right:0, bottom: padY + 24,
        textAlign:'center', zIndex:2,
        padding: `0 ${padX}px`,
      }}>
        {Names}
        {Meta}
      </div>
    </section>
  );
}

window.CoverCinematic = CoverCinematic;
window.CoverRegal = CoverRegal;
window.CoverEditorial = CoverEditorial;
window.CoverMandap = CoverMandap;
