/* Scroll-driven wedding events story.
   Pinned stage, scenes transition as user scrolls.
   Illustrations are line-art on crimson, matching the reference card. */

const { useState: sUseState, useEffect: sUseEffect, useRef: sUseRef, useMemo: sUseMemo } = React;

const SC_CREAM = "#fbf3e1";
const SC_GOLD  = "#e8c97a";
const SC_GOLD2 = "#c9a961";

/* ============================================================
   SCENE ILLUSTRATIONS — one per event, line-art on transparent
============================================================ */

/* 1 · Ganesh Pujan — Ganesh icon with offerings */
function SceneGanesh() {
  return (
    <svg viewBox="0 0 400 460" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
      <g fill="none" stroke={SC_CREAM} strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
        {/* head crown */}
        <path d="M 200,70 L 200,40 L 210,30 L 200,20 L 190,30 L 200,40" />
        {/* big head */}
        <circle cx="200" cy="120" r="64" />
        {/* ears */}
        <path d="M 136,108 Q 110,90 100,130 Q 110,160 138,150" />
        <path d="M 264,108 Q 290,90 300,130 Q 290,160 262,150" />
        {/* ear inner */}
        <path d="M 132,118 Q 118,124 116,140 Q 124,148 134,142" opacity=".7" />
        <path d="M 268,118 Q 282,124 284,140 Q 276,148 266,142" opacity=".7" />
        {/* trunk curl */}
        <path d="M 200,148 C 198,180 230,200 232,170 C 232,154 214,156 218,170" strokeWidth="1.8" />
        {/* tusks */}
        <path d="M 180,160 L 174,178" />
        <path d="M 220,160 L 226,178" />
        {/* eyes (closed lotus eyes) */}
        <path d="M 174,110 Q 184,104 194,110" />
        <path d="M 206,110 Q 216,104 226,110" />
        <circle cx="184" cy="114" r="2" fill={SC_CREAM} stroke="none" />
        <circle cx="216" cy="114" r="2" fill={SC_CREAM} stroke="none" />
        {/* tilak */}
        <path d="M 197,90 L 200,82 L 203,90 Z" fill={SC_GOLD} stroke="none" />
        <circle cx="200" cy="96" r="2" fill={SC_GOLD} stroke="none" />
        {/* body/throne */}
        <path d="M 130,200 L 270,200 L 280,260 L 120,260 Z" />
        <path d="M 130,200 Q 200,180 270,200" />
        {/* hands holding objects */}
        <path d="M 140,230 Q 130,240 130,256" />
        <circle cx="124" cy="262" r="6" />
        <path d="M 260,230 Q 270,240 270,256" />
        <path d="M 270,260 L 274,250 L 280,254 L 278,266 Z" />
        {/* lotus pedestal */}
        {[-50, -25, 0, 25, 50].map((a, i) => (
          <path key={i}
                d="M 0,0 Q -12,-22 0,-40 Q 12,-22 0,0 Z"
                transform={`translate(200,300) rotate(${a})`} />
        ))}
        {/* offerings — small lamps */}
        <g transform="translate(70,360)">
          <path d="M 0,8 Q 12,16 24,8 L 22,14 Q 12,20 2,14 Z" />
          <path d="M 12,4 C 9,0 9,-6 12,-12 C 15,-6 15,0 12,4 Z" fill={SC_GOLD} stroke="none" opacity=".9" />
        </g>
        <g transform="translate(310,360)">
          <path d="M 0,8 Q 12,16 24,8 L 22,14 Q 12,20 2,14 Z" />
          <path d="M 12,4 C 9,0 9,-6 12,-12 C 15,-6 15,0 12,4 Z" fill={SC_GOLD} stroke="none" opacity=".9" />
        </g>
        {/* falling flower petals */}
        {[[120, 40], [160, 30], [220, 30], [280, 40], [100, 70], [300, 70]].map(([x, y], i) => (
          <path key={`p${i}`}
                d={`M ${x},${y} q -4,-6 0,-12 q 4,6 0,12 z`}
                fill={SC_GOLD} stroke="none" opacity=".7" />
        ))}
      </g>
    </svg>
  );
}

/* 2 · Haldi — pot with turmeric, hands, splashes */
function SceneHaldi() {
  return (
    <svg viewBox="0 0 400 460" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
      <g fill="none" stroke={SC_CREAM} strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
        {/* pot — kalash style */}
        <ellipse cx="200" cy="290" rx="100" ry="20" />
        <path d="M 100,290 C 100,200 180,180 200,180 C 220,180 300,200 300,290" />
        <ellipse cx="200" cy="180" rx="50" ry="10" />
        <path d="M 150,180 L 150,160 L 250,160 L 250,180" />
        <ellipse cx="200" cy="160" rx="50" ry="10" />
        {/* turmeric inside */}
        <ellipse cx="200" cy="178" rx="45" ry="6" fill={SC_GOLD} stroke="none" opacity=".75" />
        {/* pot ornament bands */}
        <path d="M 110,240 Q 200,250 290,240" />
        <path d="M 120,260 Q 200,270 280,260" opacity=".7" />
        {Array.from({ length: 7 }).map((_, i) => (
          <circle key={i} cx={130 + i * 23} cy="250" r="2" fill={SC_GOLD} stroke="none" />
        ))}
        {/* leaves on top — mango leaves */}
        {[-50, -25, 0, 25, 50].map((a, i) => (
          <g key={i} transform={`translate(200,155) rotate(${a})`}>
            <path d="M 0,0 Q -8,-26 0,-46 Q 8,-26 0,0 Z" />
            <line x1="0" y1="-2" x2="0" y2="-40" opacity=".7" />
          </g>
        ))}
        {/* coconut on top */}
        <circle cx="200" cy="106" r="14" />
        <line x1="194" y1="98" x2="206" y2="98" />
        {/* hands reaching in */}
        <path d="M 60,310 Q 90,300 120,320 L 116,340 Q 80,350 50,332 Z" />
        <path d="M 60,310 L 64,300 M 74,304 L 76,294 M 88,304 L 92,294 M 102,308 L 108,300" />
        <path d="M 340,310 Q 310,300 280,320 L 284,340 Q 320,350 350,332 Z" />
        <path d="M 340,310 L 336,300 M 326,304 L 324,294 M 312,304 L 308,294 M 298,308 L 292,300" />
        {/* splash droplets */}
        {[[200, 150], [180, 130], [220, 130], [160, 140], [240, 140], [100, 200], [300, 200], [140, 100], [260, 100]].map(([x, y], i) => (
          <circle key={i} cx={x} cy={y} r={2 + (i % 3)} fill={SC_GOLD} stroke="none" opacity={0.5 + (i % 3) * 0.15} />
        ))}
        {/* swirly steam */}
        <path d="M 180,130 q 8,-12 -4,-24 q -8,-10 4,-22" opacity=".55" />
        <path d="M 220,130 q -8,-12 4,-24 q 8,-10 -4,-22" opacity=".55" />
        {/* base mat */}
        <path d="M 50,310 L 350,310" opacity=".4" />
      </g>
    </svg>
  );
}

/* 3 · Mehendi — open palm with henna paisley patterns */
function SceneMehendi() {
  return (
    <svg viewBox="0 0 400 460" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
      <g fill="none" stroke={SC_CREAM} strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
        {/* palm outline */}
        <path d="M 200,420 C 150,420 130,380 130,340 L 125,210 Q 122,180 138,178 Q 152,180 152,210
                 L 150,160 Q 148,124 168,124 Q 188,128 186,160 L 188,200
                 L 200,150 Q 204,116 222,116 Q 240,118 232,150 L 224,200
                 L 242,168 Q 256,134 274,144 Q 286,152 270,182 L 252,224
                 L 268,210 Q 286,196 296,206 Q 302,216 286,236 L 254,288
                 C 248,300 256,340 252,360 C 248,400 240,420 200,420 Z" />
        {/* fingernails */}
        <path d="M 140,184 Q 138,180 142,180 L 146,180 Q 150,180 148,184" fill={SC_GOLD} stroke="none" opacity=".5" />
        <path d="M 170,128 Q 168,124 174,124 L 180,124 Q 184,124 182,128" fill={SC_GOLD} stroke="none" opacity=".5" />
        <path d="M 212,120 Q 210,116 216,116 L 222,116 Q 226,116 224,120" fill={SC_GOLD} stroke="none" opacity=".5" />
        <path d="M 256,144 Q 256,140 262,142 L 268,144 Q 272,146 270,148" fill={SC_GOLD} stroke="none" opacity=".5" />
        {/* mehendi central lotus */}
        <g transform="translate(195,300)">
          {[-60, -30, 0, 30, 60, 90, -90, 180].map((a, i) => (
            <path key={i} d="M 0,0 Q -8,-16 0,-30 Q 8,-16 0,0 Z" transform={`rotate(${a})`} />
          ))}
          <circle r="6" />
          <circle r="2" fill={SC_GOLD} stroke="none" />
        </g>
        {/* paisley swirl on each finger */}
        <path d="M 142,200 q -6,-10 0,-20 q 6,10 0,20 m 0,-20 q 2,-6 6,-4" opacity=".95" />
        <path d="M 176,160 q -6,-10 0,-20 q 6,10 0,20" />
        <path d="M 220,150 q -6,-10 0,-20 q 6,10 0,20" />
        <path d="M 260,200 q -10,-4 -4,-14 q 12,4 4,14" />
        {/* wrist bracelets */}
        <path d="M 158,420 L 246,420" />
        <path d="M 162,430 L 240,430" />
        <path d="M 166,440 L 232,440" />
        {Array.from({ length: 8 }).map((_, i) => (
          <circle key={i} cx={170 + i * 9} cy="425" r="1.6" fill={SC_GOLD} stroke="none" />
        ))}
        {/* radiating dots around lotus */}
        {Array.from({ length: 12 }).map((_, i) => {
          const a = (i / 12) * Math.PI * 2;
          return <circle key={`d${i}`} cx={195 + Math.cos(a) * 56} cy={300 + Math.sin(a) * 56} r="1.6" fill={SC_GOLD} stroke="none" />;
        })}
        {/* small paisleys around */}
        <g transform="translate(180,360)">
          <path d="M 0,0 c 12,-6 20,-2 18,8 c -2,8 -10,8 -12,2" />
        </g>
        <g transform="translate(210,360)">
          <path d="M 0,0 c -12,-6 -20,-2 -18,8 c 2,8 10,8 12,2" />
        </g>
      </g>
    </svg>
  );
}

/* 4 · Sangeet — musicians + dancing silhouettes */
function SceneSangeet() {
  return (
    <svg viewBox="0 0 400 460" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
      <g fill="none" stroke={SC_CREAM} strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
        {/* big crescent moon background */}
        <circle cx="320" cy="80" r="42" />
        <circle cx="334" cy="74" r="42" fill="#9b1d1d" stroke="none" />
        <circle cx="334" cy="74" r="42" />
        {/* stars */}
        {[[60, 50], [140, 30], [200, 70], [270, 110], [110, 100], [40, 110]].map(([x, y], i) => (
          <path key={i} d={`M ${x},${y - 4} L ${x + 1},${y - 1} L ${x + 4},${y} L ${x + 1},${y + 1} L ${x},${y + 4} L ${x - 1},${y + 1} L ${x - 4},${y} L ${x - 1},${y - 1} Z`}
                fill={SC_GOLD} stroke="none" />
        ))}

        {/* string-lights swag */}
        <path d="M 0,160 Q 200,200 400,160" />
        {Array.from({ length: 14 }).map((_, i) => {
          const t = i / 13;
          const x = t * 400;
          const y = 160 + Math.sin(t * Math.PI) * 38;
          return (
            <g key={i} transform={`translate(${x},${y})`}>
              <line x1="0" y1="0" x2="0" y2="8" />
              <circle cx="0" cy="12" r="3" fill={SC_GOLD} stroke="none" opacity=".95" />
            </g>
          );
        })}

        {/* dholki (drum) center */}
        <g transform="translate(200,360)">
          <ellipse cx="0" cy="0" rx="34" ry="10" />
          <path d="M -34,0 L -32,38 Q 0,46 32,38 L 34,0" />
          <ellipse cx="0" cy="38" rx="32" ry="8" />
          {/* drum laces */}
          {[-26, -12, 0, 12, 26].map((x, i) => (
            <line key={i} x1={x} y1="0" x2={x} y2="38" opacity=".75" />
          ))}
        </g>

        {/* dancer left */}
        <g transform="translate(80,300)">
          <circle cx="0" cy="0" r="12" />
          <path d="M -8,12 L -16,40 L -10,70 L -16,98" />
          <path d="M 8,12 L 16,40 L 22,30" />
          <path d="M 0,16 Q -16,28 -28,18" />
          <path d="M 0,16 Q 18,30 26,16" />
          {/* skirt/lehenga */}
          <path d="M -16,40 Q 0,52 16,40 L 26,98 Q 0,108 -26,98 Z" />
          {/* lehenga lines */}
          <path d="M -22,72 Q 0,80 22,72" opacity=".7" />
          <path d="M -24,86 Q 0,94 24,86" opacity=".7" />
        </g>

        {/* dancer right */}
        <g transform="translate(320,300)">
          <circle cx="0" cy="0" r="12" />
          <path d="M -8,12 L -16,40 L -22,30" />
          <path d="M 8,12 L 16,40 L 10,70 L 16,98" />
          <path d="M 0,16 Q -18,30 -26,16" />
          <path d="M 0,16 Q 16,28 28,18" />
          {/* sherwani */}
          <path d="M -14,40 L -18,98 L 18,98 L 14,40 Z" />
          <line x1="0" y1="40" x2="0" y2="98" opacity=".7" />
        </g>

        {/* music notes */}
        {[[60, 130, "♪"], [180, 110, "♫"], [260, 130, "♪"], [340, 140, "♫"]].map(([x, y, n], i) => (
          <text key={i} x={x} y={y} fill={SC_GOLD} stroke="none" fontFamily="serif" fontSize="22" opacity=".85">{n}</text>
        ))}
      </g>
    </svg>
  );
}

/* 5 · Baraat — groom on horse with band procession */
function SceneBaraat() {
  return (
    <svg viewBox="0 0 400 460" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
      <g fill="none" stroke={SC_CREAM} strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
        {/* horse */}
        <g transform="translate(200,280)">
          {/* body */}
          <path d="M -60,0 C -70,-26 -40,-40 0,-36 C 50,-32 70,-20 70,4 L 60,20 L -56,18 Z" />
          {/* neck */}
          <path d="M 60,-10 Q 78,-30 92,-60 L 102,-50 Q 90,-20 70,-2" />
          {/* head */}
          <path d="M 92,-60 C 110,-66 122,-58 120,-42 L 110,-36 L 104,-46 L 96,-46 Z" />
          {/* ear */}
          <path d="M 102,-58 L 106,-66 L 110,-58 Z" />
          {/* eye */}
          <circle cx="110" cy="-50" r="1.6" fill={SC_CREAM} stroke="none" />
          {/* mane */}
          <path d="M 70,-30 q -2,-8 6,-12 q -2,8 -4,16 m 4,-8 q 2,-8 8,-10" opacity=".85" />
          {/* tail */}
          <path d="M -60,-10 q -22,8 -28,28 q -2,10 6,14" />
          <path d="M -60,-4 q -22,16 -22,40" opacity=".7" />
          {/* legs */}
          <line x1="-46" y1="18" x2="-50" y2="62" />
          <line x1="-22" y1="18" x2="-26" y2="62" />
          <line x1="38" y1="20" x2="44" y2="62" />
          <line x1="58" y1="20" x2="62" y2="62" />
          {/* hooves */}
          {[-50, -26, 44, 62].map((x, i) => <line key={i} x1={x - 4} y1="62" x2={x + 4} y2="62" strokeWidth="2" />)}
          {/* saddle blanket */}
          <path d="M -40,-26 L 40,-22 L 36,-4 L -34,-8 Z" />
          <path d="M -34,-22 L 36,-18 M -36,-14 L 36,-10" opacity=".7" />
          {/* tassels */}
          <line x1="-40" y1="-4" x2="-44" y2="6" />
          <line x1="40" y1="-4" x2="44" y2="6" />
        </g>

        {/* groom on horse */}
        <g transform="translate(195,228)">
          {/* turban (sehra would be too detailed) */}
          <path d="M -16,-20 Q 0,-32 16,-20 Q 18,-10 0,-6 Q -18,-10 -16,-20 Z" />
          {/* sehra strands */}
          {[-12, -4, 0, 4, 12].map((x, i) => (
            <g key={i} transform={`translate(${x},-12)`}>
              <line x1="0" y1="0" x2="0" y2="14" opacity=".8" />
              {[2, 5, 8, 11, 14].map((y, j) => <circle key={j} cx="0" cy={y} r="1.2" fill={SC_GOLD} stroke="none" />)}
            </g>
          ))}
          {/* feather plume on turban */}
          <path d="M 0,-22 Q -6,-36 -2,-46" />
          <circle cx="-2" cy="-46" r="3" fill={SC_GOLD} stroke="none" />
          {/* face */}
          <circle cx="0" cy="4" r="8" />
          {/* body */}
          <path d="M -12,16 L -16,42 L 16,42 L 12,16 Z" />
          {/* arm holding sword */}
          <path d="M 12,20 L 26,18 L 30,6" />
          <line x1="30" y1="6" x2="30" y2="-14" />
        </g>

        {/* path / ground */}
        <path d="M 0,360 L 400,360" strokeDasharray="6 4" opacity=".6" />

        {/* lanterns / floating dhol notes above */}
        <g transform="translate(60,100)">
          <circle cx="0" cy="0" r="12" />
          <path d="M -3,-12 L 3,-12 L 0,-18 Z" />
          <line x1="0" y1="12" x2="0" y2="20" />
          {[0, 4, 8, 12].map((y, i) => <circle key={i} cx="0" cy={20 + y} r="1.4" fill={SC_GOLD} stroke="none" />)}
        </g>
        <g transform="translate(340,140)">
          <circle cx="0" cy="0" r="14" />
          <path d="M -3,-14 L 3,-14 L 0,-22 Z" />
          <line x1="0" y1="14" x2="0" y2="22" />
        </g>

        {/* confetti / petals */}
        {[[80, 60], [130, 40], [200, 30], [270, 50], [330, 70], [100, 200], [300, 200]].map(([x, y], i) => (
          <path key={i} d={`M ${x},${y} q -4,-6 0,-12 q 4,6 0,12 z`} fill={SC_GOLD} stroke="none" opacity=".75" />
        ))}
      </g>
    </svg>
  );
}

/* 6 · Pheras — mandap with sacred fire and couple */
function ScenePheras() {
  return (
    <svg viewBox="0 0 400 460" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
      <g fill="none" stroke={SC_CREAM} strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
        {/* mandap canopy - dome */}
        <path d="M 60,180 Q 200,80 340,180" />
        <path d="M 60,180 L 60,420" />
        <path d="M 340,180 L 340,420" />
        {/* canopy drape swags */}
        <path d="M 60,180 Q 90,210 120,180 Q 150,210 180,180 Q 210,210 240,180 Q 270,210 300,180 Q 330,210 340,180" opacity=".75" />
        {/* canopy tassels */}
        {[120, 180, 240, 300].map((x, i) => (
          <g key={i} transform={`translate(${x},200)`}>
            <line x1="0" y1="0" x2="0" y2="14" />
            <circle cx="0" cy="18" r="3" fill={SC_GOLD} stroke="none" />
          </g>
        ))}
        {/* finial */}
        <path d="M 196,80 L 200,60 L 204,80" />
        <circle cx="200" cy="56" r="3" fill={SC_GOLD} stroke="none" />
        {/* floral arch */}
        {Array.from({ length: 12 }).map((_, i) => {
          const t = i / 11;
          const x = 60 + t * 280;
          const y = 180 - Math.sin(t * Math.PI) * 100;
          return (
            <g key={i} transform={`translate(${x},${y})`}>
              {Array.from({ length: 5 }).map((_, j) => {
                const a = (j / 5) * Math.PI * 2;
                return <circle key={j} cx={Math.cos(a) * 4} cy={Math.sin(a) * 4} r="2.4" fill={SC_GOLD} stroke="none" opacity=".85" />;
              })}
              <circle r="2" fill={SC_CREAM} stroke="none" />
            </g>
          );
        })}

        {/* sacred fire pit (hawan kund) */}
        <g transform="translate(200,360)">
          <path d="M -50,0 L 50,0 L 40,32 L -40,32 Z" />
          <line x1="-46" y1="8" x2="46" y2="8" opacity=".7" />
          <line x1="-44" y1="16" x2="44" y2="16" opacity=".7" />
          {/* fire flames */}
          <g fill={SC_GOLD} stroke="none">
            <path d="M -20,0 C -28,-20 -22,-40 -10,-30 C -16,-20 -14,-12 -20,0 Z" opacity=".9" />
            <path d="M 0,-4 C -10,-28 -2,-56 14,-40 C 6,-26 10,-12 0,-4 Z" opacity=".95" />
            <path d="M 20,0 C 14,-22 22,-38 30,-28 C 26,-18 26,-10 20,0 Z" opacity=".85" />
          </g>
          <g fill="#fff3b0" stroke="none">
            <path d="M -2,-8 C -6,-22 -2,-40 6,-30 C 2,-22 4,-14 -2,-8 Z" opacity=".95" />
          </g>
        </g>

        {/* bride and groom seated */}
        {/* groom */}
        <g transform="translate(135,310)">
          <path d="M -14,-18 Q 0,-30 14,-18 Q 16,-10 0,-6 Q -16,-10 -14,-18 Z" />
          <circle cx="0" cy="6" r="9" />
          <path d="M -16,18 L -22,52 L 22,52 L 16,18 Z" />
          <path d="M 0,18 L 0,52" opacity=".7" />
        </g>
        {/* bride with veil */}
        <g transform="translate(265,310)">
          {/* veil drape */}
          <path d="M -22,-24 Q 0,-38 22,-24 Q 30,-4 22,12 L -22,12 Q -30,-4 -22,-24 Z" />
          <path d="M -16,-12 L 16,-12" opacity=".7" />
          {/* face partial */}
          <circle cx="0" cy="2" r="8" />
          {/* bindi */}
          <circle cx="0" cy="-6" r="2" fill={SC_GOLD} stroke="none" />
          {/* body / lehenga */}
          <path d="M -16,12 L -28,52 L 28,52 L 16,12 Z" />
          {/* lehenga lines */}
          <path d="M -24,30 Q 0,38 24,30" opacity=".7" />
          <path d="M -26,42 Q 0,50 26,42" opacity=".7" />
        </g>

        {/* floor base */}
        <path d="M 30,420 L 370,420" />
        <path d="M 50,430 L 350,430" opacity=".6" />
      </g>
    </svg>
  );
}

/* 7 · Reception — couple under floral arch + champagne */
function SceneReception() {
  return (
    <svg viewBox="0 0 400 460" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
      <g fill="none" stroke={SC_CREAM} strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
        {/* heart-shaped floral arch */}
        <path d="M 200,100 C 130,30 60,90 100,160 C 130,220 200,260 200,260 C 200,260 270,220 300,160 C 340,90 270,30 200,100 Z" />
        {/* roses on arch */}
        {[[100, 110], [120, 150], [150, 195], [200, 230], [250, 195], [280, 150], [300, 110], [200, 75]].map(([x, y], i) => (
          <g key={i} transform={`translate(${x},${y})`}>
            {Array.from({ length: 5 }).map((_, j) => {
              const a = (j / 5) * Math.PI * 2;
              return <ellipse key={j} cx={Math.cos(a) * 4} cy={Math.sin(a) * 4} rx="5" ry="3"
                              transform={`rotate(${a * 180 / Math.PI})`}
                              fill={SC_GOLD} stroke="none" opacity=".85" />;
            })}
            <circle r="3" fill={SC_CREAM} stroke="none" />
          </g>
        ))}
        {/* leaves on arch */}
        {[[140, 130, -30], [260, 130, 30], [110, 180, -60], [290, 180, 60], [180, 250, -10], [220, 250, 10]].map(([x, y, r], i) => (
          <g key={`l${i}`} transform={`translate(${x},${y}) rotate(${r})`}>
            <path d="M 0,0 Q 7,-12 14,0 Q 7,12 0,0 Z" opacity=".85" />
          </g>
        ))}

        {/* couple silhouettes */}
        <g transform="translate(165,320)">
          <circle cx="0" cy="0" r="10" />
          <path d="M -14,12 L -18,58 L 18,58 L 14,12 Z" />
          <path d="M 14,18 L 30,16" />
        </g>
        <g transform="translate(235,320)">
          {/* veil */}
          <path d="M -16,-12 Q 0,-22 16,-12 Q 22,4 16,20 L -16,20 Q -22,4 -16,-12 Z" />
          <circle cx="0" cy="4" r="8" />
          <path d="M -16,20 L -22,58 L 22,58 L 16,20 Z" />
          <path d="M -14,18 L -30,16" />
        </g>

        {/* champagne glasses clinking */}
        <g transform="translate(200,304)">
          <path d="M -30,0 L -26,-12 L -14,-12 L -10,0 Z" />
          <line x1="-20" y1="0" x2="-20" y2="14" />
          <path d="M -28,18 L -12,18" />
          <path d="M 30,0 L 26,-12 L 14,-12 L 10,0 Z" />
          <line x1="20" y1="0" x2="20" y2="14" />
          <path d="M 28,18 L 12,18" />
          {/* bubbles */}
          {[[-22, -16], [-18, -22], [18, -20], [22, -16]].map(([x, y], i) => (
            <circle key={i} cx={x} cy={y} r="1.5" fill={SC_GOLD} stroke="none" />
          ))}
          {/* sparkle between */}
          <g fill={SC_GOLD} stroke="none">
            <path d="M 0,-6 L 1,-2 L 5,0 L 1,2 L 0,6 L -1,2 L -5,0 L -1,-2 Z" />
          </g>
        </g>

        {/* base */}
        <path d="M 40,420 L 360,420" />
        <path d="M 60,432 L 340,432" opacity=".6" />

        {/* hanging string lights */}
        <path d="M 0,40 Q 200,80 400,40" opacity=".7" />
        {Array.from({ length: 12 }).map((_, i) => {
          const t = i / 11;
          const x = t * 400;
          const y = 40 + Math.sin(t * Math.PI) * 40;
          return (
            <g key={i} transform={`translate(${x},${y})`}>
              <line x1="0" y1="0" x2="0" y2="6" />
              <circle cx="0" cy="10" r="2.4" fill={SC_GOLD} stroke="none" />
            </g>
          );
        })}
      </g>
    </svg>
  );
}

/* ============================================================
   SCENE DEFINITIONS
============================================================ */
const SCENES = [
  {
    key: "ganesh",
    day: "Day 1 · 9 AM",
    name: "Ganesh Pujan",
    hindi: "गणेश पूजन",
    blurb: "We begin with Lord Ganesha — the remover of obstacles. A small puja, incense in the morning light, the first diya of the wedding.",
    Component: SceneGanesh,
    bg: "#7a1818",
    accent: "#e8c97a",
  },
  {
    key: "haldi",
    day: "Day 1 · 11 AM",
    name: "Haldi",
    hindi: "हल्दी",
    blurb: "Turmeric, mustard oil and laughter. Family takes turns applying haldi for the bride and groom's glow. Expect a yellow mess. Expect joy.",
    Component: SceneHaldi,
    bg: "#8a1f1f",
    accent: "#ffc857",
  },
  {
    key: "mehendi",
    day: "Day 1 · 1:30 PM",
    name: "Mehendi",
    hindi: "मेहंदी",
    blurb: "Henna for the bride, palms-out joy for everyone. Dholki under the canopy, masala chai, a long catch-up that runs into evening.",
    Component: SceneMehendi,
    bg: "#7c2222",
    accent: "#e8c97a",
  },
  {
    key: "sangeet",
    day: "Day 1 · 7:30 PM",
    name: "Sangeet",
    hindi: "संगीत",
    blurb: "Choreographed numbers, family roasts, open dance floor. The kind of night photographs can never quite capture, but everyone remembers.",
    Component: SceneSangeet,
    bg: "#681616",
    accent: "#e8c97a",
  },
  {
    key: "baraat",
    day: "Day 2 · 4 PM",
    name: "Baraat",
    hindi: "बारात",
    blurb: "Madhurendra arrives — horse, band, baaja, and a procession of dancers refusing to take the next street faster than fifteen minutes.",
    Component: SceneBaraat,
    bg: "#8c1d1d",
    accent: "#e8c97a",
  },
  {
    key: "pheras",
    day: "Day 2 · 6:30 PM",
    name: "Pheras",
    hindi: "विवाह",
    blurb: "Seven sacred vows around the holy fire. The whole reason we're all here. Quiet, important, beautiful.",
    Component: ScenePheras,
    bg: "#5e1212",
    accent: "#ffc857",
  },
  {
    key: "reception",
    day: "Day 2 · 9 PM",
    name: "Reception",
    hindi: "स्वागत समारोह",
    blurb: "Dinner, photos with the new couple, a kulfi station, a dessert table that does not believe in moderation. Dance until your feet hurt.",
    Component: SceneReception,
    bg: "#7a1818",
    accent: "#e8c97a",
  },
];

/* ============================================================
   SCROLL STORY COMPONENT
============================================================ */
function ScrollStory() {
  const wrapRef = sUseRef(null);
  const [active, setActive] = sUseState(0);
  const [progress, setProgress] = sUseState(0); // 0..scenes.length

  // scroll listener — compute which scene is active
  sUseEffect(() => {
    let raf = 0;
    const onScroll = () => {
      cancelAnimationFrame(raf);
      raf = requestAnimationFrame(() => {
        const el = wrapRef.current;
        if (!el) return;
        const r = el.getBoundingClientRect();
        const vh = window.innerHeight;
        // Total scrollable range = height - vh
        const totalScroll = el.offsetHeight - vh;
        if (totalScroll <= 0) return;
        const scrolled = Math.max(0, Math.min(totalScroll, -r.top));
        const t = scrolled / totalScroll;
        const p = t * SCENES.length;
        setProgress(p);
        const idx = Math.min(SCENES.length - 1, Math.floor(p));
        setActive(idx);
      });
    };
    window.addEventListener("scroll", onScroll, { passive: true });
    onScroll();
    return () => { window.removeEventListener("scroll", onScroll); cancelAnimationFrame(raf); };
  }, []);

  const jumpToScene = (i) => {
    const el = wrapRef.current;
    if (!el) return;
    const totalScroll = el.offsetHeight - window.innerHeight;
    const targetTop = el.offsetTop + (totalScroll * (i + 0.5)) / SCENES.length;
    window.scrollTo({ top: targetTop, behavior: "smooth" });
  };

  // height = one viewport per scene
  const totalHeight = `${SCENES.length * 100}vh`;

  return (
    <section
      id="celebration"
      className="story"
      data-screen-label="02 The Celebration"
      ref={wrapRef}
      style={{ height: totalHeight, padding: 0 }}
    >
      <div className="story-pin">
        {/* progress rail */}
        <ol className="story-rail" aria-label="Wedding events">
          {SCENES.map((s, i) => (
            <li key={s.key} className={i === active ? "active" : i < active ? "passed" : ""}>
              <button onClick={() => jumpToScene(i)} aria-label={s.name}>
                <span className="rail-dot" />
                <span className="rail-label">{s.name}</span>
              </button>
            </li>
          ))}
        </ol>

        {/* progress bar */}
        <div className="story-progress">
          <div className="story-progress-fill" style={{ height: `${(progress / SCENES.length) * 100}%` }} />
        </div>

        {/* scenes stack — all rendered, one visible */}
        <div className="story-stage">
          {SCENES.map((s, i) => {
            const dist = i - progress; // -inf..+inf, 0 = exactly on
            const visible = Math.abs(dist) < 1.05;
            // each scene fades in/out and translates
            const opacity = visible ? Math.max(0, 1 - Math.abs(dist) * 1.4) : 0;
            const ty = dist * 60;       // vertical drift in px
            const scale = 0.94 + (1 - Math.min(1, Math.abs(dist))) * 0.06;
            const rotZ = dist * -2;
            return (
              <article
                key={s.key}
                className={`story-scene ${i === active ? "is-active" : ""}`}
                style={{
                  opacity,
                  background: i === active ? `radial-gradient(ellipse at 50% 0%, ${s.bg} 0%, #4f0f0f 100%)` : "transparent",
                  zIndex: i === active ? 2 : 1,
                  pointerEvents: i === active ? "auto" : "none",
                }}
                aria-hidden={i !== active}
              >
                <div className="story-illu" style={{
                  transform: `translate3d(0, ${ty}px, 0) scale(${scale}) rotate(${rotZ}deg)`,
                  opacity,
                }}>
                  <s.Component />
                  {/* floating petals overlay specific to scene */}
                  <div className="story-petals" aria-hidden="true">
                    {Array.from({ length: 8 }).map((_, j) => (
                      <span key={j} className="petal" style={{
                        left: `${(j * 13 + 5) % 95}%`,
                        animationDelay: `${j * 0.7}s`,
                        animationDuration: `${8 + (j % 3) * 2}s`,
                        background: s.accent,
                      }} />
                    ))}
                  </div>
                </div>
                <div className="story-copy" style={{
                  transform: `translate3d(${dist * -40}px, ${dist * 24}px, 0)`,
                  opacity,
                }}>
                  <div className="story-eyebrow">
                    <span /> {s.day}
                  </div>
                  <h2 className="story-name">{s.name}</h2>
                  <div className="story-hindi">{s.hindi}</div>
                  <p className="story-blurb">{s.blurb}</p>
                  <div className="story-counter">
                    <span>{String(i + 1).padStart(2, "0")}</span>
                    <span className="dash">/</span>
                    <span>{String(SCENES.length).padStart(2, "0")}</span>
                  </div>
                </div>
              </article>
            );
          })}
        </div>

        {/* scroll hint shown only on first scene */}
        {progress < 0.3 && (
          <div className="story-hint">
            <span className="line" />
            <span>scroll to walk through the days</span>
            <span className="line" />
          </div>
        )}
      </div>
    </section>
  );
}

Object.assign(window, {
  SceneGanesh, SceneHaldi, SceneMehendi, SceneSangeet, SceneBaraat,
  ScenePheras, SceneReception, ScrollStory, SCENES,
});

/* ============================================================
   EVENTS TIMELINE TABS — flat reference of all events
============================================================ */
function EventsTabs() {
  const [active, setActive] = sUseState(0);
  const S = SCENES[active];
  const Illu = S.Component;
  return (
    <section id="timeline" className="events-tabs scroll-in" data-screen-label="03 Timeline">
      <div className="et-head">
        <div className="et-eyebrow">
          <span /> The Two Days <span />
        </div>
        <h2 className="et-title">Timeline at a glance</h2>
        <p className="et-sub">Pick an event to peek at — or scroll back up to walk through them one by one.</p>
      </div>

      <div className="et-tabs" role="tablist">
        {SCENES.map((s, i) => (
          <button
            key={s.key}
            role="tab"
            aria-selected={i === active}
            className={`et-tab ${i === active ? "is-active" : ""}`}
            onClick={() => setActive(i)}
          >
            <span className="et-tab-num">{String(i + 1).padStart(2, "0")}</span>
            <span className="et-tab-name">{s.name}</span>
            <span className="et-tab-day">{s.day}</span>
          </button>
        ))}
      </div>

      <div className="et-card" key={S.key}>
        <div className="et-illu">
          <Illu />
        </div>
        <div className="et-copy">
          <div className="et-day">{S.day}</div>
          <h3 className="et-name">{S.name}</h3>
          <div className="et-hindi">{S.hindi}</div>
          <p className="et-blurb">{S.blurb}</p>
          <div className="et-nav">
            <button onClick={() => setActive((a) => (a - 1 + SCENES.length) % SCENES.length)} aria-label="Previous">←</button>
            <span>{String(active + 1).padStart(2, "0")} / {String(SCENES.length).padStart(2, "0")}</span>
            <button onClick={() => setActive((a) => (a + 1) % SCENES.length)} aria-label="Next">→</button>
          </div>
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { EventsTabs });
