// landing-art.jsx — custom vibrant illustrations (no real app screens).
// Each illustration is built from parallax LAYERS that move at different
// speeds on scroll → real depth, not a flat scroll-in.

// ── parallax layer ──────────────────────────────────────────
function PX({ speed = 0.05, className = '', style = {}, children, ...rest }) {
  const ref = useParallax(speed);
  return (
    <div ref={ref} className={className} style={style} data-base-transform={style.transform || ''} {...rest}>
      {children}
    </div>
  );
}

const A = (n) => S2AV(n);

// ── HERO ART — live pulse-radar with orbiting people + cards ─
function HeroArt() {
  return (
    <div className="lp-heroart">
      <PX speed={0.02} className="lp-glowc" style={{ width: 380, height: 380, left: '50%', top: '46%', transform: 'translate(-50%,-50%)' }}></PX>

      <PX speed={0.05} className="lp-disc" style={{ width: 322, height: 322, left: '50%', top: '46%', transform: 'translate(-50%,-50%)' }}>
        <span className="lp-sweep"></span>
        <span className="lp-ringline" style={{ inset: '7%' }}></span>
        <span className="lp-ringline" style={{ inset: '24%' }}></span>
        <span className="lp-ringline" style={{ inset: '41%' }}></span>
        <img className="lp-illu-mark" src="brand/ssup-mark.png" alt="" style={{ width: 72 }} />
      </PX>

      {/* orbiting people */}
      <PX speed={0.10} className="lp-bub lp-live" style={{ width: 64, height: 64, left: '78%', top: '18%' }}><img src={A(47)} alt="" /></PX>
      <PX speed={0.07} className="lp-bub" style={{ width: 52, height: 52, left: '86%', top: '52%' }}><img src={A(12)} alt="" /></PX>
      <PX speed={0.13} className="lp-bub lp-live" style={{ width: 56, height: 56, left: '72%', top: '82%' }}><img src={A(57)} alt="" /></PX>
      <PX speed={0.08} className="lp-bub" style={{ width: 46, height: 46, left: '28%', top: '84%' }}><img src={A(5)} alt="" /></PX>

      {/* live pill */}
      <PX speed={0.06} className="lp-illu-pill" style={{ left: '44%', top: '5%' }}><S2LivePill>Goa · Live</S2LivePill></PX>

      {/* crossing match card */}
      <PX speed={0.16} className="lp-gcard" style={{ left: '0%', top: '50%', width: 244, transform: 'rotate(-5deg)' }}>
        <div className="lp-grow" style={{ gap: 10 }}>
          <S2Av n={32} size={36} ring />
          <span style={{ color: 'var(--accent)', display: 'flex' }}><S2Icon name="zap" size={20} /></span>
          <S2Av n={47} size={36} ring />
          <span style={{ marginLeft: 'auto', padding: '5px 10px', borderRadius: 99, background: 'var(--live)', color: '#0A0E16', fontFamily: 'var(--lp-mono)', fontSize: 11.5, fontWeight: 600 }}>92%</span>
        </div>
        <div style={{ fontSize: 14.5, fontWeight: 800, marginTop: 11, lineHeight: 1.25 }}>You&rsquo;re both feeling street food rn</div>
        <div className="lp-gmeta" style={{ marginTop: 7 }}>1.2 km apart · say ssup</div>
      </PX>

      {/* live drop card */}
      <PX speed={0.13} className="lp-gcard" style={{ right: '-1%', bottom: '5%', width: 218, transform: 'rotate(4deg)' }}>
        <div className="lp-grow" style={{ gap: 11 }}>
          <span style={{ width: 40, height: 40, borderRadius: 11, flex: '0 0 40px', display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'color-mix(in oklab, var(--live) 16%, var(--surface-card))', color: 'var(--live)' }}><S2Icon name="zap" size={19} /></span>
          <div style={{ flex: 1 }}>
            <b>Beach bonfire</b>
            <div className="lp-gmeta" style={{ marginTop: 2 }}>Anjuna · 21:00</div>
          </div>
        </div>
        <div className="lp-grow" style={{ justifyContent: 'space-between', marginTop: 11 }}>
          <S2AvStack ns={[68, 5, 12]} size={24} />
          <span style={{ color: 'var(--live)', fontWeight: 800, fontSize: 12.5 }}>14 going</span>
        </div>
      </PX>
    </div>
  );
}

// ── DISCOVER — constellation of people, one match lit ───────
function IlluDiscover() {
  return (
    <div className="lp-illu">
      <PX speed={0.03} className="lp-glowc" style={{ width: '78%', height: '78%', left: '11%', top: '11%' }}></PX>
      <svg className="lp-net" viewBox="0 0 460 460" aria-hidden="true">
        <g stroke="color-mix(in oklab, var(--accent) 30%, transparent)" strokeWidth="1.5" fill="none">
          <line x1="230" y1="230" x2="118" y2="120" /><line x1="230" y1="230" x2="350" y2="120" />
          <line x1="230" y1="230" x2="360" y2="300" /><line x1="230" y1="230" x2="120" y2="330" />
        </g>
        <line x1="230" y1="230" x2="350" y2="120" stroke="var(--live)" strokeWidth="2.5" strokeDasharray="5 6">
          <animate attributeName="stroke-dashoffset" from="22" to="0" dur="1s" repeatCount="indefinite" />
        </line>
      </svg>
      <PX speed={0.07} className="lp-bub lp-you" style={{ width: 84, height: 84, left: '50%', top: '50%' }}><img src={A(32)} alt="" /></PX>
      <PX speed={0.12} className="lp-bub lp-live" style={{ width: 64, height: 64, left: '76%', top: '26%' }}><img src={A(47)} alt="" /></PX>
      <PX speed={0.09} className="lp-bub" style={{ width: 52, height: 52, left: '26%', top: '26%' }}><img src={A(12)} alt="" /></PX>
      <PX speed={0.10} className="lp-bub" style={{ width: 50, height: 50, left: '78%', top: '65%' }}><img src={A(57)} alt="" /></PX>
      <PX speed={0.08} className="lp-bub" style={{ width: 46, height: 46, left: '26%', top: '72%' }}><img src={A(68)} alt="" /></PX>
      <PX speed={0.18} className="lp-tag lp-tag-lime" style={{ left: '64%', top: '40%' }}>92% match</PX>
    </div>
  );
}

// ── COMPASS — radar + floating move chips ───────────────────
function IlluCompass() {
  return (
    <div className="lp-illu">
      <PX speed={0.03} className="lp-glowc" style={{ width: '80%', height: '80%', left: '10%', top: '10%' }}></PX>
      <PX speed={0.05} className="lp-disc" style={{ width: '74%', height: '74%', left: '13%', top: '13%' }}>
        <span className="lp-sweep"></span>
        <span className="lp-ringline" style={{ inset: '10%' }}></span>
        <span className="lp-ringline" style={{ inset: '30%' }}></span>
        <span className="lp-ringline" style={{ inset: '50%' }}></span>
        <span style={{ position: 'absolute', left: '50%', top: '50%', transform: 'translate(-50%,-50%)', color: 'var(--accent)' }}><S2Icon name="compass" size={34} sw={1.6} /></span>
      </PX>
      <PX speed={0.07} className="lp-gcard lp-illu-pill" style={{ left: '8%', top: '8%', width: 220, padding: '11px 13px' }}>
        <span style={{ width: 32, height: 32, borderRadius: 9, flex: '0 0 32px', display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'var(--accent-tint-18)', color: 'var(--accent)' }}><S2Icon name="pulse" size={16} sw={2.2} /></span>
        <div style={{ marginLeft: 10 }}>
          <div className="lp-gmeta" style={{ color: 'var(--accent)' }}>YOUR PULSE</div>
          <b style={{ fontSize: 13.5 }}>Social · street food</b>
        </div>
      </PX>
      <PX speed={0.15} className="lp-gcard lp-movechip" style={{ right: '-4%', top: '34%', transform: 'rotate(3deg)' }}>
        <img src={S2PH.streetfood} alt="" />
        <div><b>Night-market crawl</b><div className="lp-gmeta" style={{ marginTop: 2 }}>3 stops · 1.8 km</div></div>
      </PX>
      <PX speed={0.12} className="lp-gcard lp-movechip" style={{ left: '-4%', bottom: '12%', transform: 'rotate(-3deg)' }}>
        <img src={S2PH.beach} alt="" />
        <div><b>Sunset drift</b><div className="lp-gmeta" style={{ marginTop: 2 }}>18:30 · 6 going</div></div>
      </PX>
    </div>
  );
}

// ── GO — route between pins + a live plan card ──────────────
function IlluGo() {
  return (
    <div className="lp-illu">
      <PX speed={0.03} className="lp-glowc" style={{ width: '70%', height: '70%', left: '15%', top: '18%' }}></PX>
      <svg className="lp-net" viewBox="0 0 460 460" aria-hidden="true">
        <path d="M96 360 C 150 250, 230 300, 270 200 S 360 110, 372 96" fill="none"
          stroke="color-mix(in oklab, var(--accent) 55%, transparent)" strokeWidth="3" strokeDasharray="2 10" strokeLinecap="round" />
      </svg>
      <PX speed={0.08} className="lp-pin" style={{ left: '21%', top: '80%' }}><S2Icon name="pin" size={34} /></PX>
      <PX speed={0.10} className="lp-pin lp-pin-live" style={{ left: '81%', top: '22%' }}><S2Icon name="pin" size={40} /></PX>
      <PX speed={0.07} className="lp-bub lp-you" style={{ width: 46, height: 46, left: '21%', top: '88%' }}><img src={A(32)} alt="" /></PX>
      <PX speed={0.16} className="lp-gcard" style={{ left: '24%', top: '30%', width: 222, transform: 'rotate(-3deg)' }}>
        <div className="lp-grow" style={{ justifyContent: 'space-between' }}>
          <span className="lp-gmeta" style={{ color: 'var(--accent)' }}>PLAN · LIVE</span>
          <S2LivePill>Go</S2LivePill>
        </div>
        <b style={{ display: 'block', fontSize: 15, marginTop: 9 }}>Street food crawl</b>
        <div className="lp-grow" style={{ gap: 10, marginTop: 10 }}>
          <span style={{ color: 'var(--accent)', display: 'flex' }}><S2Icon name="pin" size={16} /></span>
          <span className="lp-gmeta">Market Gate 2 · 21:30</span>
        </div>
        <div className="lp-grow" style={{ justifyContent: 'space-between', marginTop: 11 }}>
          <S2AvStack ns={[47, 57, 32]} size={24} />
          <span style={{ color: 'var(--live)', fontWeight: 800, fontSize: 12.5 }}>2 on the way</span>
        </div>
      </PX>
    </div>
  );
}

// ── PASSPORT — fanned photo stamps ──────────────────────────
function IlluPassport() {
  const stamps = [
    { src: S2PH.sunset, cap: 'Anjuna', date: 'Jun 8', x: '8%', y: '40%', r: -9, s: 0.08 },
    { src: S2PH.market, cap: 'Mapusa', date: 'Jun 6', x: '34%', y: '24%', r: -1, s: 0.13 },
    { src: S2PH.party, cap: 'Vagator', date: 'Jun 4', x: '58%', y: '36%', r: 8, s: 0.18 },
  ];
  return (
    <div className="lp-illu">
      <PX speed={0.03} className="lp-glowc" style={{ width: '76%', height: '70%', left: '12%', top: '14%' }}></PX>
      {stamps.map((st) => (
        <PX key={st.cap} speed={st.s} className="lp-stamp" style={{ left: st.x, top: st.y, transform: `rotate(${st.r}deg)` }}>
          <img src={st.src} alt="" />
          <div className="lp-stamp-cap">
            <div><b>{st.cap}</b><div className="lp-gmeta">{st.date}</div></div>
            <span style={{ color: 'var(--accent)', display: 'flex' }}><S2Icon name="check" size={16} sw={2.6} /></span>
          </div>
        </PX>
      ))}
      <PX speed={0.22} className="lp-tag" style={{ left: '76%', top: '74%' }}>12 stamps</PX>
    </div>
  );
}

// ── SAFETY — glowing shield over a frosted map ──────────────
function IlluSafety() {
  return (
    <div className="lp-illu">
      <PX speed={0.03} className="lp-glowc" style={{ width: '76%', height: '76%', left: '12%', top: '12%' }}></PX>
      <PX speed={0.06} className="lp-frost" style={{ width: '64%', height: '64%', left: '18%', top: '18%' }}>
        <img src={S2PH.market} alt="" />
      </PX>
      <PX speed={0.05} className="lp-shield"><S2Icon name="shield" size={150} sw={1.2} /></PX>
      <span style={{ position: 'absolute', left: '50%', top: '52%', transform: 'translate(-50%,-50%)', color: 'var(--accent)' }}><S2Icon name="check" size={52} sw={2.4} /></span>
      <PX speed={0.16} className="lp-tag lp-tag-lime" style={{ left: '24%', top: '24%' }}>Verified</PX>
      <PX speed={0.14} className="lp-gcard lp-illu-pill" style={{ right: '4%', bottom: '14%', padding: '9px 13px', alignItems: 'center', gap: 9 }}>
        <span style={{ color: 'var(--danger-400, #FF6B6B)', display: 'flex' }}><S2Icon name="sos" size={18} /></span>
        <b style={{ fontSize: 13.5 }}>Hold for SOS</b>
      </PX>
      <PX speed={0.18} className="lp-tag" style={{ left: '20%', top: '74%' }}>Location blurred</PX>
    </div>
  );
}

// ── LIVE MAP — real dark CARTO tiles + live overlays ────────
function MapTiles() {
  const z = 13, x0 = 2410, y0 = 3081, cols = 5, rows = 3;
  const tiles = [];
  for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) tiles.push([x0 + c, y0 + r]);
  return (
    <div className="lp-maptiles" style={{ gridTemplateColumns: `repeat(${cols}, 256px)`, width: cols * 256, height: rows * 256 }}>
      {tiles.map(([x, y]) => (
        <img key={x + '_' + y} src={`https://a.basemaps.cartocdn.com/dark_all/${z}/${x}/${y}.png`} width="256" height="256" alt="" />
      ))}
    </div>
  );
}

function MapPin({ x, y, live, label, sub, speed = 0.1 }) {
  return (
    <PX speed={speed} className={'lp-mappin' + (live ? ' lp-live' : '')} style={{ left: x, top: y }}>
      <div className="lp-mlabel">
        <span className="lp-mdot"></span><b>{label}</b>{sub ? <small>{sub}</small> : null}
      </div>
      <span className="lp-mppoint"></span>
    </PX>
  );
}

function MapLive() {
  return (
    <div className="lp-maplive">
      <MapTiles />
      <div className="lp-map-blue"></div>
      <div className="lp-map-vig"></div>

      <PX speed={0.04} className="lp-disc lp-mapradar" style={{ width: 300, height: 300, left: '50%', top: '46%', transform: 'translate(-50%,-50%)' }}>
        <span className="lp-sweep"></span>
        <span className="lp-ringline" style={{ inset: '22%' }}></span>
        <span className="lp-ringline" style={{ inset: '46%' }}></span>
      </PX>

      <PX speed={0.06} className="lp-illu-pill" style={{ left: '5%', top: '7%' }}><S2LivePill>Goa · Live</S2LivePill></PX>

      <MapPin x="29%" y="40%" live label="Beach bonfire" sub="21:00 · 14" speed={0.12} />
      <MapPin x="63%" y="31%" label="Night-market crawl" sub="rn" speed={0.17} />
      <MapPin x="77%" y="63%" live label="Live set" sub="22:30" speed={0.10} />
      <MapPin x="41%" y="72%" label="Sunset drift" sub="18:30" speed={0.15} />

      <PX speed={0.13} className="lp-bub lp-live" style={{ width: 44, height: 44, left: '53%', top: '52%' }}><img src={A(47)} alt="" /></PX>
      <PX speed={0.10} className="lp-bub" style={{ width: 40, height: 40, left: '36%', top: '57%' }}><img src={A(12)} alt="" /></PX>
      <PX speed={0.11} className="lp-bub" style={{ width: 38, height: 38, left: '67%', top: '49%' }}><img src={A(57)} alt="" /></PX>

      <PX speed={0.19} className="lp-gcard" style={{ right: '4%', top: '9%', width: 206, transform: 'rotate(3deg)' }}>
        <div className="lp-grow" style={{ gap: 10 }}>
          <span style={{ width: 38, height: 38, borderRadius: 10, flex: '0 0 38px', display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'var(--accent-tint-18)', color: 'var(--accent)' }}><S2Icon name="zap" size={18} /></span>
          <div><b>6 crossings</b><div className="lp-gmeta" style={{ marginTop: 2 }}>within 1 km · rn</div></div>
        </div>
      </PX>
    </div>
  );
}

Object.assign(window, { PX, HeroArt, IlluDiscover, IlluCompass, IlluGo, IlluPassport, IlluSafety, MapTiles, MapPin, MapLive, MapBgTiles });

// ── full-page faint map backdrop (real CARTO tiles) ─────────
function MapBgTiles() {
  const z = 14, x0 = 4820, y0 = 6159, cols = 8, rows = 6;
  const tiles = [];
  for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) tiles.push([x0 + c, y0 + r]);
  return (
    <div className="lp-mapbg-grid" style={{ gridTemplateColumns: `repeat(${cols}, 256px)`, width: cols * 256, height: rows * 256 }}>
      {tiles.map(([x, y]) => (
        <img key={x + '_' + y} src={`https://a.basemaps.cartocdn.com/dark_all/${z}/${x}/${y}.png`} width="256" height="256" alt="" />
      ))}
    </div>
  );
}
