// 3D-style SVG illustrations for Flowcare treatments
// CSS 3D transforms + layered SVG gradients for convincing depth without Three.js overhead.

// Base 3D container — tilts on hover, with ambient float
function Scene3D({ children, tilt = 8, float = true, className = '', style = {} }) {
  const ref = React.useRef(null);
  const [t, setT] = React.useState({ x: 0, y: 0 });
  const onMove = (e) => {
    const r = ref.current.getBoundingClientRect();
    const dx = (e.clientX - r.left - r.width/2) / (r.width/2);
    const dy = (e.clientY - r.top - r.height/2) / (r.height/2);
    setT({ x: -dy * tilt, y: dx * tilt });
  };
  const onLeave = () => setT({ x: 0, y: 0 });
  return (
    <div ref={ref} onMouseMove={onMove} onMouseLeave={onLeave}
      className={`scene3d ${float ? 'scene3d--float' : ''} ${className}`}
      style={{ perspective: '1200px', ...style }}>
      <div className="scene3d-inner" style={{
        transform: `rotateX(${t.x}deg) rotateY(${t.y}deg)`,
        transformStyle: 'preserve-3d', transition: 'transform 400ms cubic-bezier(.2,.8,.2,1)',
      }}>
        {children}
      </div>
    </div>
  );
}

/* ───── Treatment 3D illustrations ──────────────────────── */

// 1. Varicose Veins — glowing twisted vein in a leg silhouette
function IllVaricose({ size = 220 }) {
  return (
    <svg viewBox="-100 -100 200 200" width={size} height={size} className="ill3d">
      <defs>
        <radialGradient id="v-leg" cx="30%" cy="30%">
          <stop offset="0%" stopColor="#3a4258" />
          <stop offset="60%" stopColor="#1a1f2e" />
          <stop offset="100%" stopColor="#0a0d18" />
        </radialGradient>
        <linearGradient id="v-vein" x1="0" x2="1" y1="0" y2="1">
          <stop offset="0" stopColor="#7a5cff" />
          <stop offset="0.5" stopColor="#5a3de6" />
          <stop offset="1" stopColor="#2d1a8a" />
        </linearGradient>
        <radialGradient id="v-glow" cx="50%" cy="50%">
          <stop offset="0" stopColor="#7a5cff" stopOpacity="0.5" />
          <stop offset="1" stopColor="#7a5cff" stopOpacity="0" />
        </radialGradient>
        <filter id="v-blur"><feGaussianBlur stdDeviation="3" /></filter>
      </defs>
      <circle cx="0" cy="0" r="90" fill="url(#v-glow)" />
      {/* leg shape */}
      <ellipse cx="0" cy="10" rx="42" ry="75" fill="url(#v-leg)" />
      <ellipse cx="-14" cy="-30" rx="22" ry="40" fill="rgba(255,255,255,0.05)" />
      {/* twisted vein */}
      <path d="M-10,-65 C-25,-40 10,-20 -15,5 C-35,25 5,45 -12,70"
        fill="none" stroke="url(#v-vein)" strokeWidth="8" strokeLinecap="round" filter="url(#v-blur)" opacity="0.6" />
      <path d="M-10,-65 C-25,-40 10,-20 -15,5 C-35,25 5,45 -12,70"
        fill="none" stroke="url(#v-vein)" strokeWidth="5" strokeLinecap="round" />
      {/* nodes */}
      <circle cx="-25" cy="-40" r="5" fill="#b49aff" />
      <circle cx="10" cy="-20" r="6" fill="#b49aff" />
      <circle cx="-15" cy="5" r="5" fill="#b49aff" />
      <circle cx="-35" cy="25" r="4" fill="#b49aff" />
      <circle cx="5" cy="45" r="5" fill="#b49aff" />
      <circle cx="-12" cy="70" r="4" fill="#b49aff" />
    </svg>
  );
}

// 2. Uterine Fibroid — uterus with nodule
function IllFibroid({ size = 220 }) {
  return (
    <svg viewBox="-100 -100 200 200" width={size} height={size} className="ill3d">
      <defs>
        <radialGradient id="f-u" cx="30%" cy="30%">
          <stop offset="0" stopColor="#ffb8c4" />
          <stop offset="60%" stopColor="#d46078" />
          <stop offset="100%" stopColor="#5a1a2a" />
        </radialGradient>
        <radialGradient id="f-nod" cx="30%" cy="30%">
          <stop offset="0" stopColor="#ffd0a8" />
          <stop offset="60%" stopColor="#d9844a" />
          <stop offset="100%" stopColor="#5a2a10" />
        </radialGradient>
        <radialGradient id="f-glow" cx="50%" cy="50%">
          <stop offset="0" stopColor="#ff6b8a" stopOpacity="0.4" />
          <stop offset="1" stopColor="#ff6b8a" stopOpacity="0" />
        </radialGradient>
      </defs>
      <circle cx="0" cy="0" r="90" fill="url(#f-glow)" />
      {/* uterus body */}
      <path d="M-50,-10 C-50,-50 -30,-65 0,-65 C30,-65 50,-50 50,-10 C50,30 30,55 0,60 C-30,55 -50,30 -50,-10 Z"
        fill="url(#f-u)" />
      {/* fallopian tubes */}
      <path d="M-45,-30 C-65,-45 -70,-20 -55,-15" fill="none" stroke="#d46078" strokeWidth="6" strokeLinecap="round" />
      <path d="M45,-30 C65,-45 70,-20 55,-15" fill="none" stroke="#d46078" strokeWidth="6" strokeLinecap="round" />
      {/* fibroid nodule */}
      <circle cx="-12" cy="-15" r="22" fill="url(#f-nod)" />
      <ellipse cx="-18" cy="-22" rx="7" ry="5" fill="rgba(255,255,255,0.35)" />
      {/* highlight on uterus */}
      <ellipse cx="-20" cy="-40" rx="14" ry="8" fill="rgba(255,255,255,0.2)" />
    </svg>
  );
}

// 3. Varicocele — scrotal veins
function IllVaricocele({ size = 220 }) {
  return (
    <svg viewBox="-100 -100 200 200" width={size} height={size} className="ill3d">
      <defs>
        <radialGradient id="vc-b" cx="30%" cy="30%">
          <stop offset="0" stopColor="#5a6378" />
          <stop offset="70%" stopColor="#2a3045" />
          <stop offset="100%" stopColor="#10131e" />
        </radialGradient>
        <linearGradient id="vc-v"><stop offset="0" stopColor="#3b82f6" /><stop offset="1" stopColor="#1e3a8a" /></linearGradient>
        <radialGradient id="vc-glow"><stop offset="0" stopColor="#3b82f6" stopOpacity="0.4" /><stop offset="1" stopColor="#3b82f6" stopOpacity="0" /></radialGradient>
      </defs>
      <circle cx="0" cy="0" r="90" fill="url(#vc-glow)" />
      <ellipse cx="-18" cy="15" rx="32" ry="42" fill="url(#vc-b)" />
      <ellipse cx="18" cy="15" rx="32" ry="42" fill="url(#vc-b)" />
      <ellipse cx="-28" cy="0" rx="8" ry="5" fill="rgba(255,255,255,0.15)" />
      <ellipse cx="8" cy="0" rx="8" ry="5" fill="rgba(255,255,255,0.15)" />
      {/* tangled veins */}
      <g stroke="url(#vc-v)" strokeWidth="4" fill="none" strokeLinecap="round">
        <path d="M-25,-30 C-15,-20 -30,-10 -18,0 C-8,10 -28,20 -15,30" />
        <path d="M-10,-35 C0,-25 -12,-15 -2,-5 C8,5 -10,15 2,25" />
        <path d="M15,-30 C25,-20 10,-10 22,0 C32,10 12,20 25,30" />
        <path d="M28,-35 C38,-25 25,-15 35,-5 C45,5 27,15 38,25" />
      </g>
      <g fill="#60a5fa">
        <circle cx="-20" cy="-10" r="3" /><circle cx="-15" cy="15" r="3" />
        <circle cx="20" cy="-10" r="3" /><circle cx="25" cy="15" r="3" />
      </g>
    </svg>
  );
}

// 4. DVT — blood clot in vein
function IllDVT({ size = 220 }) {
  return (
    <svg viewBox="-100 -100 200 200" width={size} height={size} className="ill3d">
      <defs>
        <linearGradient id="d-tube" x1="0" x2="1">
          <stop offset="0" stopColor="#3a4258" />
          <stop offset="0.5" stopColor="#5a6378" />
          <stop offset="1" stopColor="#2a3045" />
        </linearGradient>
        <radialGradient id="d-clot" cx="30%" cy="30%">
          <stop offset="0" stopColor="#ff6b6b" />
          <stop offset="60%" stopColor="#b91c1c" />
          <stop offset="100%" stopColor="#450a0a" />
        </radialGradient>
        <radialGradient id="d-glow"><stop offset="0" stopColor="#ef4444" stopOpacity="0.4" /><stop offset="1" stopColor="#ef4444" stopOpacity="0" /></radialGradient>
      </defs>
      <circle cx="0" cy="0" r="90" fill="url(#d-glow)" />
      {/* tube (cross-section of vein) */}
      <rect x="-70" y="-28" width="140" height="56" rx="28" fill="url(#d-tube)" />
      <rect x="-70" y="-24" width="140" height="8" rx="4" fill="rgba(255,255,255,0.12)" />
      <rect x="-70" y="-28" width="140" height="56" rx="28" fill="none" stroke="rgba(255,255,255,0.1)" strokeWidth="1" />
      {/* blood flow particles */}
      <g fill="#dc2626" opacity="0.7">
        <circle cx="-55" cy="0" r="4" /><circle cx="-38" cy="-6" r="3" />
        <circle cx="-45" cy="8" r="3" /><circle cx="-25" cy="4" r="4" />
      </g>
      {/* clot */}
      <ellipse cx="20" cy="0" rx="32" ry="22" fill="url(#d-clot)" />
      <ellipse cx="12" cy="-8" rx="8" ry="5" fill="rgba(255,150,150,0.4)" />
      <path d="M-10,-15 Q0,-22 15,-18 Q30,-12 45,-22" fill="none" stroke="#991b1b" strokeWidth="1.5" opacity="0.6" />
    </svg>
  );
}

// 5. Trigeminal Neuralgia — facial nerve
function IllTrigem({ size = 220 }) {
  return (
    <svg viewBox="-100 -100 200 200" width={size} height={size} className="ill3d">
      <defs>
        <radialGradient id="t-face" cx="30%" cy="30%">
          <stop offset="0" stopColor="#e8c4a0" />
          <stop offset="70%" stopColor="#8a5a3a" />
          <stop offset="100%" stopColor="#2a1810" />
        </radialGradient>
        <radialGradient id="t-glow"><stop offset="0" stopColor="#fbbf24" stopOpacity="0.4" /><stop offset="1" stopColor="#fbbf24" stopOpacity="0" /></radialGradient>
      </defs>
      <circle cx="0" cy="0" r="90" fill="url(#t-glow)" />
      {/* face profile */}
      <path d="M-20,-60 C20,-65 50,-40 55,0 C58,30 40,55 20,60 C-5,65 -30,50 -35,15 C-38,-10 -30,-40 -20,-60 Z"
        fill="url(#t-face)" />
      {/* eye */}
      <ellipse cx="15" cy="-20" rx="5" ry="3" fill="#2a1810" />
      {/* lightning pain lines */}
      <g stroke="#fbbf24" strokeWidth="2.5" fill="none" strokeLinecap="round">
        <path d="M40,-10 L50,-5 L45,5 L55,10 L48,22" />
        <path d="M25,-35 L35,-30 L30,-22 L40,-15" />
        <path d="M38,20 L48,30 L42,38" />
      </g>
      <g fill="#fbbf24">
        <circle cx="48" cy="22" r="3" /><circle cx="40" cy="-15" r="2.5" /><circle cx="42" cy="38" r="2" />
      </g>
      {/* nerve branches */}
      <path d="M50,0 Q58,-10 60,-30 M50,0 Q58,-5 62,5 M50,0 Q58,10 60,30"
        fill="none" stroke="rgba(251,191,36,0.4)" strokeWidth="1" />
    </svg>
  );
}

// 6. Peripheral Artery — blocked artery with plaque
function IllPAD({ size = 220 }) {
  return (
    <svg viewBox="-100 -100 200 200" width={size} height={size} className="ill3d">
      <defs>
        <linearGradient id="p-art">
          <stop offset="0" stopColor="#b91c1c" />
          <stop offset="0.5" stopColor="#dc2626" />
          <stop offset="1" stopColor="#7f1d1d" />
        </linearGradient>
        <radialGradient id="p-plaque" cx="30%" cy="30%">
          <stop offset="0" stopColor="#fef08a" />
          <stop offset="70%" stopColor="#ca8a04" />
          <stop offset="100%" stopColor="#422006" />
        </radialGradient>
        <radialGradient id="p-glow"><stop offset="0" stopColor="#10b981" stopOpacity="0.3" /><stop offset="1" stopColor="#10b981" stopOpacity="0" /></radialGradient>
      </defs>
      <circle cx="0" cy="0" r="90" fill="url(#p-glow)" />
      {/* artery tube */}
      <path d="M-80,0 C-60,-20 -20,-20 0,0 C20,20 60,20 80,0" stroke="url(#p-art)" strokeWidth="28" fill="none" strokeLinecap="round" />
      <path d="M-80,-6 C-60,-26 -20,-26 0,-6 C20,14 60,14 80,-6" stroke="rgba(255,255,255,0.15)" strokeWidth="3" fill="none" strokeLinecap="round" />
      {/* plaque */}
      <ellipse cx="5" cy="5" rx="18" ry="12" fill="url(#p-plaque)" transform="rotate(-25 5 5)" />
      <ellipse cx="0" cy="2" rx="5" ry="3" fill="rgba(255,255,255,0.4)" transform="rotate(-25 0 2)" />
      {/* stent (solution) */}
      <g stroke="#60a5fa" strokeWidth="1.5" fill="none" opacity="0.7">
        <path d="M-12,-8 L22,-8 M-12,12 L22,12" />
        <path d="M-8,-8 L-8,12 M-2,-8 L-2,12 M4,-8 L4,12 M10,-8 L10,12 M16,-8 L16,12" />
      </g>
    </svg>
  );
}

/* ───── Big interactive Varicose Veins 3D demo ──────────── */

function VaricoseDemoScene({ stage, showLaser }) {
  // stage 0: diseased | 1: laser inserted | 2: treated
  return (
    <div className="vd-stage">
      <svg viewBox="-200 -240 400 480" className="vd-svg">
        <defs>
          <radialGradient id="vd-leg" cx="35%" cy="20%">
            <stop offset="0" stopColor="#3e4a66" />
            <stop offset="50%" stopColor="#1d2435" />
            <stop offset="100%" stopColor="#080b14" />
          </radialGradient>
          <linearGradient id="vd-leg-r" x1="1" x2="0">
            <stop offset="0" stopColor="rgba(255,255,255,0.08)" />
            <stop offset="1" stopColor="rgba(255,255,255,0)" />
          </linearGradient>
          <linearGradient id="vd-vein-bad" x1="0" x2="1" y1="0" y2="1">
            <stop offset="0" stopColor="#9d7cff" />
            <stop offset="0.5" stopColor="#5a3de6" />
            <stop offset="1" stopColor="#2d1a8a" />
          </linearGradient>
          <linearGradient id="vd-vein-good" x1="0" x2="1" y1="0" y2="1">
            <stop offset="0" stopColor="#22d3ee" />
            <stop offset="0.5" stopColor="#0ea5e9" />
            <stop offset="1" stopColor="#075985" />
          </linearGradient>
          <radialGradient id="vd-bg">
            <stop offset="0" stopColor="rgba(34,211,238,0.15)" />
            <stop offset="1" stopColor="rgba(34,211,238,0)" />
          </radialGradient>
          <filter id="vd-blur"><feGaussianBlur stdDeviation="4" /></filter>
          <filter id="vd-glow"><feGaussianBlur stdDeviation="6" result="b" /><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge></filter>
        </defs>

        {/* ambient bg */}
        <circle cx="0" cy="0" r="230" fill="url(#vd-bg)" />

        {/* leg shape */}
        <g>
          <path d="M-50,-220 C-80,-100 -70,0 -55,100 C-45,160 -55,200 -30,220 L30,220 C55,200 45,160 55,100 C70,0 80,-100 50,-220 Z"
            fill="url(#vd-leg)" />
          <path d="M-30,-200 C-50,-100 -40,40 -25,160 L15,160 C20,40 10,-100 -10,-200 Z"
            fill="url(#vd-leg-r)" />
          {/* knee hint */}
          <ellipse cx="0" cy="-20" rx="55" ry="14" fill="rgba(255,255,255,0.04)" />
          {/* ankle */}
          <ellipse cx="0" cy="180" rx="30" ry="8" fill="rgba(0,0,0,0.3)" />
        </g>

        {/* BEFORE: twisted varicose veins */}
        <g style={{
          opacity: stage === 0 ? 1 : 0,
          transition: 'opacity 800ms',
        }}>
          <g filter="url(#vd-blur)" opacity="0.7">
            <path d="M-15,-180 C-40,-140 10,-100 -20,-60 C-50,-20 5,20 -20,70 C-45,120 10,160 -10,200"
              fill="none" stroke="url(#vd-vein-bad)" strokeWidth="18" strokeLinecap="round" />
            <path d="M20,-170 C40,-120 5,-80 30,-40 C55,0 15,40 35,90 C55,140 15,180 25,210"
              fill="none" stroke="url(#vd-vein-bad)" strokeWidth="14" strokeLinecap="round" opacity="0.6" />
          </g>
          <path d="M-15,-180 C-40,-140 10,-100 -20,-60 C-50,-20 5,20 -20,70 C-45,120 10,160 -10,200"
            fill="none" stroke="url(#vd-vein-bad)" strokeWidth="9" strokeLinecap="round" />
          <path d="M20,-170 C40,-120 5,-80 30,-40 C55,0 15,40 35,90 C55,140 15,180 25,210"
            fill="none" stroke="url(#vd-vein-bad)" strokeWidth="7" strokeLinecap="round" opacity="0.75" />
          {/* bulging nodes */}
          <g fill="#b49aff">
            <circle cx="-35" cy="-125" r="7" /><circle cx="-20" cy="-60" r="8" />
            <circle cx="-40" cy="0" r="7" /><circle cx="-20" cy="70" r="9" />
            <circle cx="5" cy="130" r="7" /><circle cx="-10" cy="200" r="6" />
            <circle cx="40" cy="-105" r="6" /><circle cx="50" cy="-30" r="7" />
            <circle cx="20" cy="50" r="6" /><circle cx="45" cy="120" r="8" />
          </g>
          <g fontSize="9" fill="#b49aff" fontFamily="ui-monospace,monospace" letterSpacing="1">
            <text x="-105" y="-70">◀ BULGING</text>
            <text x="65" y="40">TWISTED ▶</text>
            <text x="-120" y="170">◀ POOLING BLOOD</text>
          </g>
        </g>

        {/* DURING: catheter + laser */}
        <g style={{
          opacity: stage === 1 ? 1 : 0,
          transition: 'opacity 800ms',
        }}>
          {/* straightened vein outline */}
          <path d="M-10,-200 Q-12,-100 -10,0 Q-8,100 -5,210" fill="none" stroke="#5a3de6" strokeWidth="10" strokeLinecap="round" opacity="0.5" />
          {/* catheter */}
          <g>
            <line x1="-10" y1="-210" x2="-10" y2={showLaser ? 0 : -100} stroke="#e5e7eb" strokeWidth="3.5" strokeLinecap="round" />
            <rect x="-14" y="-220" width="8" height="14" fill="#9ca3af" rx="2" />
            {/* laser glow at tip */}
            {showLaser && (
              <>
                <circle cx="-10" cy="0" r="22" fill="#ef4444" opacity="0.35" filter="url(#vd-glow)" />
                <circle cx="-10" cy="0" r="10" fill="#fff5a0" filter="url(#vd-glow)" />
                <circle cx="-10" cy="0" r="5" fill="#fff" />
              </>
            )}
          </g>
          <g fontSize="9" fill="#22d3ee" fontFamily="ui-monospace,monospace" letterSpacing="1.2">
            <text x="20" y="-180">CATHETER INSERTED</text>
            <text x="20" y="-165" fill="#9ca3af">(local anesthesia)</text>
            {showLaser && <>
              <text x="20" y="5">LASER ACTIVE · 1470 nm</text>
              <text x="20" y="20" fill="#fbbf24">SEALING VEIN →</text>
            </>}
          </g>
          {showLaser && (
            <>
              <circle cx="-10" cy="0" r="35" fill="none" stroke="#ef4444" strokeWidth="1" opacity="0.6" className="vd-pulse" />
              <circle cx="-10" cy="0" r="55" fill="none" stroke="#ef4444" strokeWidth="1" opacity="0.3" className="vd-pulse vd-pulse--2" />
            </>
          )}
        </g>

        {/* AFTER: healthy straight vein */}
        <g style={{
          opacity: stage === 2 ? 1 : 0,
          transition: 'opacity 800ms',
        }}>
          <path d="M-10,-200 Q-12,-100 -10,0 Q-8,100 -5,210"
            fill="none" stroke="url(#vd-vein-good)" strokeWidth="7" strokeLinecap="round" filter="url(#vd-glow)" />
          <path d="M15,-180 Q17,-60 18,60 Q16,150 18,200"
            fill="none" stroke="url(#vd-vein-good)" strokeWidth="5" strokeLinecap="round" opacity="0.7" />
          {/* flow particles */}
          <g fill="#67e8f9" className="vd-flow">
            <circle cx="-10" cy="-150" r="3" /><circle cx="-11" cy="-50" r="3" /><circle cx="-9" cy="50" r="3" /><circle cx="-7" cy="150" r="3" />
          </g>
          <g fontSize="9" fill="#22d3ee" fontFamily="ui-monospace,monospace" letterSpacing="1.2">
            <text x="30" y="-80">RESTORED FLOW ✓</text>
            <text x="30" y="-65" fill="#10b981">VEIN SEALED</text>
            <text x="-150" y="100" fill="#10b981">◀ NO PAIN</text>
          </g>
        </g>
      </svg>
    </div>
  );
}

function VaricoseDemo() {
  const [stage, setStage] = React.useState(0);
  const [showLaser, setShowLaser] = React.useState(false);
  const [auto, setAuto] = React.useState(true);

  React.useEffect(() => {
    if (!auto) return;
    const seq = [
      { s: 0, l: false, t: 3200 },
      { s: 1, l: false, t: 1500 },
      { s: 1, l: true,  t: 2800 },
      { s: 2, l: false, t: 3200 },
    ];
    let i = 0;
    const tick = () => {
      const step = seq[i];
      setStage(step.s); setShowLaser(step.l);
      i = (i + 1) % seq.length;
      return setTimeout(tick, step.t);
    };
    let id = tick();
    return () => clearTimeout(id);
  }, [auto]);

  const go = (s) => { setAuto(false); setStage(s); setShowLaser(s === 1); };

  const labels = [
    { k: 'Before', sub: 'Diseased varicose vein', hi: 'बीमार नस' },
    { k: 'Procedure', sub: 'Laser catheter + ablation', hi: 'लेज़र प्रक्रिया' },
    { k: 'After', sub: 'Sealed vein, restored flow', hi: 'उपचारित' },
  ];

  return (
    <div className="vd-root">
      <div className="vd-head">
        <div>
          <div className="vd-eyebrow">▶ INTERACTIVE · LIVE 3D DEMO</div>
          <h3 className="vd-h">
            <span className="vd-h-en">See how we fix varicose veins</span>
            <span className="vd-h-hi">वैरिकोज वेन्स का इलाज कैसे होता है</span>
          </h3>
        </div>
        <div className="vd-controls">
          {labels.map((l, i) => (
            <button key={i} onClick={() => go(i)}
              className={`vd-ctrl ${stage === i ? 'vd-ctrl--active' : ''}`}>
              <span className="vd-ctrl-ix">0{i+1}</span>
              <span className="vd-ctrl-k">{l.k}</span>
            </button>
          ))}
        </div>
      </div>

      <div className="vd-body">
        <Scene3D tilt={10} className="vd-scene">
          <VaricoseDemoScene stage={stage} showLaser={showLaser} />
        </Scene3D>

        <div className="vd-side">
          <div className="vd-card">
            <div className="vd-card-ix">{stage === 0 ? '01' : stage === 1 ? '02' : '03'} / 03</div>
            <div className="vd-card-k">{labels[stage].k}</div>
            <div className="vd-card-hi">{labels[stage].hi}</div>
            <div className="vd-card-sub">{labels[stage].sub}</div>

            <div className="vd-meta">
              {stage === 0 && <>
                <div><span>Symptoms</span><b>Heaviness, pain, swelling</b></div>
                <div><span>Visible</span><b>Twisted blue/purple veins</b></div>
                <div><span>Risk if untreated</span><b>Ulcers, bleeding, clots</b></div>
              </>}
              {stage === 1 && <>
                <div><span>Procedure</span><b>EVLA · 1470 nm laser</b></div>
                <div><span>Duration</span><b>~45 minutes</b></div>
                <div><span>Anesthesia</span><b>Local only</b></div>
                <div><span>Incisions</span><b>Single pinhole</b></div>
              </>}
              {stage === 2 && <>
                <div><span>Recovery</span><b>Back to work in 24h</b></div>
                <div><span>Success rate</span><b>98.4%</b></div>
                <div><span>Scars</span><b>None visible</b></div>
              </>}
            </div>

            {!auto && (
              <button className="vd-replay" onClick={() => { setAuto(true); setStage(0); }}>↻ Replay auto-tour</button>
            )}
          </div>

          <div className="vd-legend">
            <div><i style={{ background: '#7a5cff' }} /> Diseased vein</div>
            <div><i style={{ background: '#ef4444' }} /> Laser ablation</div>
            <div><i style={{ background: '#22d3ee' }} /> Healthy flow</div>
          </div>
        </div>
      </div>
    </div>
  );
}

/* ───── Big interactive Fibroid 3D demo (UAE) ──────────── */

function FibroidDemoScene({ stage, showParticles, shrunk }) {
  // stage 0: diseased (large fibroid) | 1: catheter in artery | 2: embolization particles | 3: shrunken
  return (
    <div className="fd-stage">
      <svg viewBox="-200 -240 400 480" className="fd-svg">
        <defs>
          <radialGradient id="fd-bg">
            <stop offset="0" stopColor="rgba(255,107,138,0.15)" />
            <stop offset="1" stopColor="rgba(255,107,138,0)" />
          </radialGradient>
          <radialGradient id="fd-uterus" cx="30%" cy="25%">
            <stop offset="0" stopColor="#ffb8c4" />
            <stop offset="50%" stopColor="#d46078" />
            <stop offset="100%" stopColor="#4a1420" />
          </radialGradient>
          <radialGradient id="fd-uterus-r" cx="70%" cy="70%">
            <stop offset="0" stopColor="rgba(0,0,0,0.3)" />
            <stop offset="1" stopColor="rgba(0,0,0,0)" />
          </radialGradient>
          <radialGradient id="fd-fibroid" cx="30%" cy="25%">
            <stop offset="0" stopColor="#ffd8a0" />
            <stop offset="50%" stopColor="#c97a3a" />
            <stop offset="100%" stopColor="#3a1a08" />
          </radialGradient>
          <radialGradient id="fd-fibroid-shrunk" cx="30%" cy="25%">
            <stop offset="0" stopColor="#a89888" />
            <stop offset="60%" stopColor="#5a4a3a" />
            <stop offset="100%" stopColor="#1a1008" />
          </radialGradient>
          <linearGradient id="fd-artery" x1="0" x2="1" y1="0" y2="0">
            <stop offset="0" stopColor="#dc2626" />
            <stop offset="1" stopColor="#7f1d1d" />
          </linearGradient>
          <linearGradient id="fd-artery-blocked" x1="0" x2="1" y1="0" y2="0">
            <stop offset="0" stopColor="#6a3030" />
            <stop offset="1" stopColor="#2a1010" />
          </linearGradient>
          <filter id="fd-blur"><feGaussianBlur stdDeviation="3" /></filter>
          <filter id="fd-glow"><feGaussianBlur stdDeviation="6" result="b" /><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge></filter>
        </defs>

        <circle cx="0" cy="0" r="230" fill="url(#fd-bg)" />

        {/* Uterus body */}
        <g>
          <path d="M-110,-40 C-110,-130 -60,-170 0,-170 C60,-170 110,-130 110,-40 C110,80 60,150 0,160 C-60,150 -110,80 -110,-40 Z"
            fill="url(#fd-uterus)" />
          <path d="M-110,-40 C-110,-130 -60,-170 0,-170 C60,-170 110,-130 110,-40 C110,80 60,150 0,160 C-60,150 -110,80 -110,-40 Z"
            fill="url(#fd-uterus-r)" />
          {/* fallopian tubes & ovaries */}
          <path d="M-100,-90 C-140,-130 -160,-95 -135,-75" fill="none" stroke="#b85068" strokeWidth="10" strokeLinecap="round" />
          <path d="M100,-90 C140,-130 160,-95 135,-75" fill="none" stroke="#b85068" strokeWidth="10" strokeLinecap="round" />
          <ellipse cx="-150" cy="-80" rx="14" ry="10" fill="#c96378" />
          <ellipse cx="150" cy="-80" rx="14" ry="10" fill="#c96378" />
          {/* cervix */}
          <path d="M-20,155 L-15,200 L15,200 L20,155 Z" fill="#8a3048" />
          {/* highlight */}
          <ellipse cx="-45" cy="-110" rx="30" ry="16" fill="rgba(255,255,255,0.22)" />
        </g>

        {/* BEFORE: large fibroid */}
        <g style={{ opacity: stage === 0 ? 1 : 0, transition: 'opacity 800ms' }}>
          <ellipse cx="-25" cy="-20" rx="58" ry="52" fill="url(#fd-fibroid)" filter="url(#fd-glow)" opacity="0.4" />
          <ellipse cx="-25" cy="-20" rx="55" ry="50" fill="url(#fd-fibroid)" />
          <ellipse cx="-38" cy="-35" rx="15" ry="10" fill="rgba(255,255,255,0.35)" />
          {/* secondary smaller fibroid */}
          <ellipse cx="45" cy="50" rx="22" ry="20" fill="url(#fd-fibroid)" opacity="0.9" />
          <ellipse cx="40" cy="45" rx="6" ry="4" fill="rgba(255,255,255,0.25)" />
          <g fontSize="9" fill="#ffd8a0" fontFamily="ui-monospace,monospace" letterSpacing="1">
            <text x="-180" y="-20">◀ FIBROID · 5.2 cm</text>
            <text x="75" y="55">2.2 cm ▶</text>
            <text x="-120" y="190" fill="#ff9a8a">HEAVY BLEEDING · PAIN</text>
          </g>
          {/* pulse halo around fibroid */}
          <circle cx="-25" cy="-20" r="65" fill="none" stroke="#ffb87a" strokeWidth="1" opacity="0.5" className="fd-pulse-bad" />
        </g>

        {/* STAGE 1: catheter navigating */}
        <g style={{ opacity: stage === 1 ? 1 : 0, transition: 'opacity 800ms' }}>
          <ellipse cx="-25" cy="-20" rx="55" ry="50" fill="url(#fd-fibroid)" opacity="0.85" />
          <ellipse cx="45" cy="50" rx="22" ry="20" fill="url(#fd-fibroid)" opacity="0.8" />
          {/* feeding arteries */}
          <path d="M-190,60 Q-140,40 -100,20 Q-70,0 -40,-20" fill="none" stroke="url(#fd-artery)" strokeWidth="7" strokeLinecap="round" />
          <path d="M-190,60 Q-140,40 -100,20 Q-70,0 -40,-20" fill="none" stroke="rgba(255,255,255,0.2)" strokeWidth="1.5" strokeLinecap="round" />
          {/* catheter */}
          <path d="M-195,62 Q-145,42 -105,22 Q-75,2 -50,-15" fill="none" stroke="#e5e7eb" strokeWidth="2.5" strokeLinecap="round" />
          {/* catheter tip */}
          <circle cx="-50" cy="-15" r="6" fill="#fbbf24" filter="url(#fd-glow)" />
          <circle cx="-50" cy="-15" r="3" fill="#fff" />
          <g fontSize="9" fill="#22d3ee" fontFamily="ui-monospace,monospace" letterSpacing="1.2">
            <text x="-180" y="90">FEMORAL ARTERY ACCESS</text>
            <text x="-180" y="104" fill="#9ca3af">1.2mm pinhole · local anesthesia</text>
            <text x="-35" y="-30">◀ CATHETER TIP</text>
            <text x="-35" y="-42" fill="#fbbf24">Fluoroscopy guided</text>
          </g>
          {/* contrast dye flow */}
          <g className="fd-dye">
            <circle cx="-160" cy="52" r="4" fill="#fbbf24" opacity="0.8" />
            <circle cx="-120" cy="35" r="4" fill="#fbbf24" opacity="0.8" />
            <circle cx="-85" cy="15" r="4" fill="#fbbf24" opacity="0.8" />
          </g>
        </g>

        {/* STAGE 2: embolization particles releasing */}
        <g style={{ opacity: stage === 2 ? 1 : 0, transition: 'opacity 800ms' }}>
          <ellipse cx="-25" cy="-20" rx="55" ry="50" fill="url(#fd-fibroid)" opacity="0.7" />
          <ellipse cx="45" cy="50" rx="22" ry="20" fill="url(#fd-fibroid)" opacity="0.7" />
          <path d="M-190,60 Q-140,40 -100,20 Q-70,0 -40,-20" fill="none" stroke="url(#fd-artery-blocked)" strokeWidth="7" strokeLinecap="round" />
          <path d="M-195,62 Q-145,42 -105,22 Q-75,2 -50,-15" fill="none" stroke="#e5e7eb" strokeWidth="2.5" strokeLinecap="round" />
          <circle cx="-50" cy="-15" r="7" fill="#ef4444" filter="url(#fd-glow)" />
          {/* particles swarming */}
          {showParticles && (
            <g className="fd-particles">
              {Array.from({ length: 14 }).map((_, i) => {
                const angle = (i / 14) * Math.PI * 2;
                const r = 18 + (i % 3) * 6;
                return (
                  <circle key={i}
                    cx={-25 + Math.cos(angle) * r}
                    cy={-20 + Math.sin(angle) * r}
                    r={2.5 + (i % 3) * 0.8}
                    fill={i % 2 ? '#fbbf24' : '#fde68a'}
                    opacity="0.9"
                    style={{ animationDelay: `${i * 0.12}s` }}
                  />
                );
              })}
              {/* particles on secondary */}
              {Array.from({ length: 8 }).map((_, i) => {
                const angle = (i / 8) * Math.PI * 2;
                return (
                  <circle key={'b'+i}
                    cx={45 + Math.cos(angle) * 16}
                    cy={50 + Math.sin(angle) * 14}
                    r="2"
                    fill="#fbbf24"
                    opacity="0.85"
                    style={{ animationDelay: `${0.6 + i * 0.1}s` }}
                  />
                );
              })}
            </g>
          )}
          {/* pulse rings */}
          <circle cx="-25" cy="-20" r="55" fill="none" stroke="#fbbf24" strokeWidth="1" opacity="0.6" className="fd-pulse-emb" />
          <circle cx="-25" cy="-20" r="55" fill="none" stroke="#fbbf24" strokeWidth="1" opacity="0.3" className="fd-pulse-emb fd-pulse-emb--2" />
          <g fontSize="9" fill="#fbbf24" fontFamily="ui-monospace,monospace" letterSpacing="1.2">
            <text x="-180" y="-80">PVA MICROSPHERES RELEASING</text>
            <text x="-180" y="-66" fill="#9ca3af">300–500μm · blocking blood supply</text>
            <text x="40" y="-50" fill="#ef4444">▼ ARTERY BLOCKED</text>
          </g>
        </g>

        {/* STAGE 3: shrunken fibroid */}
        <g style={{ opacity: stage === 3 ? 1 : 0, transition: 'opacity 800ms' }}>
          {/* shrunken primary */}
          <ellipse cx="-25" cy="-20" rx="22" ry="20" fill="url(#fd-fibroid-shrunk)" />
          <ellipse cx="-30" cy="-25" rx="5" ry="3" fill="rgba(255,255,255,0.15)" />
          {/* shrunken secondary */}
          <ellipse cx="45" cy="50" rx="8" ry="7" fill="url(#fd-fibroid-shrunk)" />
          {/* healthy uterus glow */}
          <path d="M-110,-40 C-110,-130 -60,-170 0,-170 C60,-170 110,-130 110,-40 C110,80 60,150 0,160 C-60,150 -110,80 -110,-40 Z"
            fill="none" stroke="#34d399" strokeWidth="2" opacity="0.4" filter="url(#fd-glow)" />
          {/* shrink arrows */}
          <g stroke="#34d399" strokeWidth="2" fill="none" strokeLinecap="round" opacity="0.9">
            <path d="M-80,-20 L-55,-20 M-60,-25 L-55,-20 L-60,-15" />
            <path d="M30,-20 L5,-20 M10,-25 L5,-20 L10,-15" />
            <path d="M-25,-75 L-25,-50 M-30,-55 L-25,-50 L-20,-55" />
            <path d="M-25,35 L-25,10 M-30,15 L-25,10 L-20,15" />
          </g>
          <g fontSize="9" fill="#34d399" fontFamily="ui-monospace,monospace" letterSpacing="1.2">
            <text x="-180" y="-80">FIBROID ↓ 60% · 2.1 cm</text>
            <text x="-180" y="-66" fill="#a7f3d0">SYMPTOMS RESOLVED ✓</text>
            <text x="60" y="140" fill="#a7f3d0">FERTILITY PRESERVED</text>
          </g>
          {/* restored flow particles */}
          <g className="fd-flow">
            <circle cx="-140" cy="45" r="3" fill="#34d399" />
            <circle cx="-90" cy="25" r="3" fill="#34d399" />
            <circle cx="-50" cy="5" r="3" fill="#34d399" />
          </g>
        </g>
      </svg>
    </div>
  );
}

function FibroidDemo() {
  const [stage, setStage] = React.useState(0);
  const [showParticles, setShowParticles] = React.useState(false);
  const [auto, setAuto] = React.useState(true);

  React.useEffect(() => {
    if (!auto) return;
    const seq = [
      { s: 0, p: false, t: 3200 },
      { s: 1, p: false, t: 3000 },
      { s: 2, p: true,  t: 3400 },
      { s: 3, p: false, t: 3200 },
    ];
    let i = 0;
    const tick = () => {
      const step = seq[i];
      setStage(step.s); setShowParticles(step.p);
      i = (i + 1) % seq.length;
      return setTimeout(tick, step.t);
    };
    let id = tick();
    return () => clearTimeout(id);
  }, [auto]);

  const go = (s) => { setAuto(false); setStage(s); setShowParticles(s === 2); };

  const labels = [
    { k: 'Before',      sub: 'Symptomatic fibroid in uterus', hi: 'बच्चेदानी में गांठ' },
    { k: 'Access',      sub: 'Catheter into uterine artery',  hi: 'कैथेटर प्रवेश' },
    { k: 'Embolization',sub: 'Microspheres block blood flow', hi: 'रक्त प्रवाह बंद' },
    { k: 'After',       sub: 'Fibroid shrinks · uterus intact', hi: 'गांठ सिकुड़ गई' },
  ];

  return (
    <div className="vd-root fd-root">
      <div className="vd-head">
        <div>
          <div className="vd-eyebrow" style={{ color: '#ff9a8a' }}>▶ INTERACTIVE · LIVE 3D DEMO</div>
          <h3 className="vd-h">
            <span className="vd-h-en">How we shrink fibroids — without surgery</span>
            <span className="vd-h-hi" style={{ color: '#ff9a8a' }}>बच्चेदानी की गांठ का इलाज</span>
          </h3>
        </div>
        <div className="vd-controls">
          {labels.map((l, i) => (
            <button key={i} onClick={() => go(i)}
              className={`vd-ctrl ${stage === i ? 'vd-ctrl--active fd-ctrl--active' : ''}`}>
              <span className="vd-ctrl-ix">0{i+1}</span>
              <span className="vd-ctrl-k">{l.k}</span>
            </button>
          ))}
        </div>
      </div>

      <div className="vd-body">
        <Scene3D tilt={10} className="vd-scene">
          <FibroidDemoScene stage={stage} showParticles={showParticles} />
        </Scene3D>

        <div className="vd-side">
          <div className="vd-card">
            <div className="vd-card-ix" style={{ color: '#ff9a8a' }}>
              {String(stage + 1).padStart(2, '0')} / 04
            </div>
            <div className="vd-card-k">{labels[stage].k}</div>
            <div className="vd-card-hi" style={{ color: '#ff9a8a' }}>{labels[stage].hi}</div>
            <div className="vd-card-sub">{labels[stage].sub}</div>

            <div className="vd-meta">
              {stage === 0 && <>
                <div><span>Symptoms</span><b>Heavy bleeding, pelvic pain</b></div>
                <div><span>Size</span><b>5.2 cm intramural + satellite</b></div>
                <div><span>Impact</span><b>Anemia, fertility issues</b></div>
              </>}
              {stage === 1 && <>
                <div><span>Procedure</span><b>UAE · Uterine Artery Embolization</b></div>
                <div><span>Access</span><b>Femoral artery · 1.2mm</b></div>
                <div><span>Guidance</span><b>Live fluoroscopy</b></div>
                <div><span>Anesthesia</span><b>Conscious sedation</b></div>
              </>}
              {stage === 2 && <>
                <div><span>Embolic</span><b>PVA microspheres · 300–500μm</b></div>
                <div><span>Mechanism</span><b>Occludes feeding arteries</b></div>
                <div><span>Duration</span><b>~60 minutes total</b></div>
              </>}
              {stage === 3 && <>
                <div><span>Shrinkage</span><b>40–60% in 3–6 months</b></div>
                <div><span>Uterus</span><b>Preserved · no hysterectomy</b></div>
                <div><span>Recovery</span><b>Discharge in 24h</b></div>
                <div><span>Success rate</span><b>94%</b></div>
              </>}
            </div>

            {!auto && (
              <button className="vd-replay" style={{ color: '#ff9a8a', borderColor: 'rgba(255,154,138,0.3)' }}
                onClick={() => { setAuto(true); setStage(0); }}>↻ Replay auto-tour</button>
            )}
          </div>

          <div className="vd-legend">
            <div><i style={{ background: '#c97a3a' }} /> Fibroid tissue</div>
            <div><i style={{ background: '#fbbf24' }} /> Embolic microspheres</div>
            <div><i style={{ background: '#34d399' }} /> Healthy flow restored</div>
          </div>
        </div>
      </div>
    </div>
  );
}

/* ───── End Fibroid demo ─────────────────────────────── */

Object.assign(window, {
  Scene3D,
  IllVaricose, IllFibroid, IllVaricocele, IllDVT, IllTrigem, IllPAD,
  VaricoseDemo,
  FibroidDemo,
});
