// Hero section — with variants controlled by Tweaks

function Hero({ variant }) {
  return (
    <section id="hero" className="grain" style={{ position: 'relative', overflow: 'hidden', paddingBottom: 40 }}>
      <TopoBackground opacity={0.55}/>
      {/* Decorative purple route line on bg */}
      <svg aria-hidden="true" style={{ position:'absolute', inset:0, width:'100%', height:'100%', opacity: 0.55, pointerEvents:'none' }} viewBox="0 0 1440 900" preserveAspectRatio="xMidYMid slice">
        <path d="M -40 560 C 180 520, 320 640, 500 600 S 780 440, 920 500 S 1200 700, 1520 620"
          stroke="rgba(123,47,255,0.55)" strokeWidth="3" fill="none" strokeLinecap="round"/>
      </svg>

      {variant === 'editorial' && <HeroEditorial/>}
      {variant === 'poster' && <HeroPoster/>}
      {variant === 'split' && <HeroSplit/>}
      {variant === 'full-phone' && <HeroFullPhone/>}
    </section>
  );
}

// ── Variant A: Editorial — big wordmark + phone right ──────────
function HeroEditorial() {
  return (
    <div className="wrap" style={{ paddingTop: 56, paddingBottom: 40, position: 'relative', zIndex: 2 }}>
      <div className="grid-hero">
        <div>
          <div style={{ display:'flex', gap: 10, alignItems:'center', marginBottom: 28 }}>
            <span className="chip"><span className="dot"/> Now on iOS — 1.0</span>
            <span className="mono" style={{opacity: 0.6}}>v1.0 · Apr 2026</span>
          </div>
          <h1 style={{
            fontSize: 'clamp(44px, 5.8vw, 96px)',
            lineHeight: 0.96,
            letterSpacing: '-0.035em',
            fontWeight: 600,
            maxWidth: 720,
          }}>
            Every good ride starts<br/>
            with a <em style={{
              fontFamily: "'Instrument Serif', 'Fraunces', serif",
              fontStyle: 'italic', fontWeight: 400,
              color: 'var(--brand)',
              letterSpacing: '-0.01em'
            }}>coffee stop.</em>
          </h1>
          <p style={{
            marginTop: 24, maxWidth: 520, fontSize: 17, lineHeight: 1.5,
            color: 'var(--ink-2)'
          }}>
            Route Radar surfaces the cafés, bike shops, and essential stops
            along your cycling route — before you clip in. Drop a GPX,
            pull a Strava route, see what matters. Nothing else.
          </p>
          <div style={{ display: 'flex', gap: 14, alignItems: 'center', marginTop: 36, flexWrap: 'wrap' }}>
            <a className="appstore" href="#download">
              <AppleGlyph size={26} color="#fff"/>
              <div style={{display:'flex', flexDirection:'column', lineHeight: 1}}>
                <span className="sm">Download on the</span>
                <span className="lg">App Store</span>
              </div>
            </a>
            <a href="#how" className="btn ghost">See how it works <Icon name="arrow" size={14}/></a>
          </div>
          {/* Stats row */}
          <div style={{ display:'flex', gap: 48, marginTop: 56, paddingTop: 28, borderTop: '1px solid rgba(22,19,15,0.12)', flexWrap: 'wrap' }}>
            <Stat k="1" unit="GPX" label="drag & drop"/>
            <Stat k="3" unit="taps" label="to planned"/>
            <Stat k="0" unit="detours" label="when you ride"/>
          </div>
        </div>

        {/* Phone */}
        <div style={{ position: 'relative', justifySelf: 'center' }}>
          <PhoneCard src="assets/screens/01-find-along-route.png" tilt={-2} w={280} />
          {/* Floating annotations */}
          <div className="hide-mobile">
            <Annotation style={{ top: 60, right: -30 }} pos="left">
              <div className="mono">01 · Along route</div>
              <div style={{fontFamily:'var(--font-display)', fontSize: 14, fontWeight: 600, color:'var(--ink)'}}>Cafés · Shops · Stops</div>
            </Annotation>
          </div>
          <div className="hide-mobile">
            <Annotation style={{ bottom: 100, left: -30 }} pos="right">
              <div className="mono">02 · Filter</div>
              <div style={{fontFamily:'var(--font-display)', fontSize: 14, fontWeight: 600, color:'var(--ink)'}}>Within &lt; 3 mi</div>
            </Annotation>
          </div>
        </div>
      </div>
    </div>
  );
}

// ── Variant B: Poster — centered oversized type, phone below ──
function HeroPoster() {
  return (
    <div className="wrap" style={{ paddingTop: 84, paddingBottom: 40, position: 'relative', zIndex: 2, textAlign:'center' }}>
      <div className="chip" style={{margin:'0 auto'}}><span className="dot"/> Planning for cyclists, not commuters</div>
      <h1 style={{
        marginTop: 28,
        fontSize: 'clamp(60px, 10vw, 156px)',
        lineHeight: 0.9,
        letterSpacing: '-0.04em',
        fontWeight: 600,
        textAlign: 'center'
      }}>
        Know the stops.<br/>
        <span style={{
          fontFamily: "'Instrument Serif', 'Fraunces', serif",
          fontStyle: 'italic', fontWeight: 400,
          color: 'var(--brand)'
        }}>Ride the route.</span>
      </h1>
      <p style={{margin: '32px auto 0', maxWidth: 620, fontSize: 19, color: 'var(--ink-2)', lineHeight: 1.5}}>
        Cafés, coffee, and bike shops mapped against your GPX — so a 64-mile
        ride never turns into a bonk at mile 42.
      </p>
      <div style={{ display: 'flex', gap: 14, justifyContent: 'center', marginTop: 36 }}>
        <a className="appstore" href="#download">
          <AppleGlyph size={26} color="#fff"/>
          <div style={{display:'flex', flexDirection:'column', lineHeight: 1}}>
            <span className="sm">Download on the</span>
            <span className="lg">App Store</span>
          </div>
        </a>
        <a href="#how" className="btn ghost">How it works <Icon name="arrow" size={14}/></a>
      </div>
      <div style={{ marginTop: 56, display:'flex', justifyContent:'center', gap: 24, flexWrap:'wrap' }}>
        <PhoneCard src="assets/screens/01-find-along-route.png" tilt={-5} w={260}/>
        <div className="hide-mobile"><PhoneCard src="assets/screens/02-stop-detail.png" tilt={2} w={260}/></div>
        <div className="hide-mobile"><PhoneCard src="assets/screens/03-filter.png" tilt={-2} w={260}/></div>
      </div>
    </div>
  );
}

// ── Variant C: Split — elevation on left, phone on right ──────
function HeroSplit() {
  return (
    <div className="wrap" style={{ paddingTop: 72, paddingBottom: 40, position: 'relative', zIndex: 2 }}>
      <div className="grid-2-split">
        <div>
          <div className="chip"><span className="dot"/> GPX-native</div>
          <h1 style={{
            marginTop: 24,
            fontSize: 'clamp(48px, 6.4vw, 92px)',
            lineHeight: 0.98, letterSpacing: '-0.035em', fontWeight: 600
          }}>
            Your route,<br/> plus everywhere<br/>
            <em style={{fontFamily:"'Instrument Serif', serif", fontStyle:'italic', fontWeight:400, color:'var(--brand)'}}>worth stopping.</em>
          </h1>
          <p style={{marginTop: 28, fontSize: 18, color:'var(--ink-2)', maxWidth: 520}}>
            Drop a GPX or import from Strava. Route Radar threads your line
            past cafés, convenience stores, and bike shops — with distance-from-route baked in.
          </p>
          {/* Mock elevation profile */}
          <div style={{marginTop: 36, background:'var(--cream)', borderRadius: 20, padding: 24, border:'1px solid rgba(22,19,15,0.08)'}}>
            <div style={{display:'flex', justifyContent:'space-between', marginBottom: 12}}>
              <div className="mono">Yosemite — Glacier Point</div>
              <div className="mono" style={{color:'var(--brand-deep)'}}>63.7 mi · 4,120 ft</div>
            </div>
            <ElevationSvg/>
            <div style={{display:'flex', justifyContent:'space-between', marginTop: 10}}>
              <span className="mono">0 mi</span>
              <span className="mono">32 mi</span>
              <span className="mono">64 mi</span>
            </div>
          </div>
          <div style={{ display: 'flex', gap: 14, alignItems: 'center', marginTop: 32 }}>
            <a className="appstore" href="#download">
              <AppleGlyph size={26} color="#fff"/>
              <div style={{display:'flex', flexDirection:'column', lineHeight: 1}}>
                <span className="sm">Download on the</span>
                <span className="lg">App Store</span>
              </div>
            </a>
          </div>
        </div>
        <div style={{position:'relative', justifySelf:'center'}}>
          <PhoneCard src="assets/screens/01-find-along-route.png" tilt={0}/>
        </div>
      </div>
    </div>
  );
}

// ── Variant D: Full phone centered, type behind it ─────────────
function HeroFullPhone() {
  return (
    <div className="wrap" style={{ paddingTop: 64, paddingBottom: 24, position: 'relative', zIndex: 2 }}>
      <div style={{textAlign:'center', marginBottom: 32}}>
        <div className="chip" style={{margin:'0 auto'}}><span className="dot"/> Built for cyclists</div>
        <h1 style={{
          marginTop: 22,
          fontSize: 'clamp(56px, 9vw, 132px)',
          lineHeight: 0.92, letterSpacing: '-0.04em', fontWeight: 600
        }}>
          Plan the stops.<br/>
          <span style={{color:'var(--brand)'}}>Skip the surprises.</span>
        </h1>
      </div>
      <div style={{position:'relative', display:'flex', justifyContent:'center'}}>
        <div style={{
          position:'absolute', inset: '40% 0 0 0',
          fontFamily:'var(--font-display)', fontWeight: 700,
          fontSize: 'clamp(120px, 22vw, 340px)',
          letterSpacing:'-0.05em', color:'rgba(123,47,255,0.09)',
          textAlign:'center', lineHeight: 0.8, zIndex: 0
        }}>RIDE</div>
        <div style={{position:'relative', zIndex:2, display:'flex', gap: 24, alignItems:'end', justifyContent:'center'}}>
          <div className="hide-mobile"><PhoneCard src="assets/screens/02-stop-detail.png" tilt={-4} w={260}/></div>
          <PhoneCard src="assets/screens/01-find-along-route.png" tilt={0} w={300}/>
          <div className="hide-mobile"><PhoneCard src="assets/screens/03-filter.png" tilt={4} w={260}/></div>
        </div>
      </div>
      <div style={{ display: 'flex', gap: 14, justifyContent:'center', marginTop: 40 }}>
        <a className="appstore" href="#download">
          <AppleGlyph size={26} color="#fff"/>
          <div style={{display:'flex', flexDirection:'column', lineHeight: 1}}>
            <span className="sm">Download on the</span>
            <span className="lg">App Store</span>
          </div>
        </a>
      </div>
    </div>
  );
}

function Stat({ k, unit, label }) {
  return (
    <div>
      <div style={{display:'flex', alignItems:'baseline', gap: 6}}>
        <span style={{fontFamily:'var(--font-display)', fontSize: 44, fontWeight: 600, letterSpacing:'-0.03em', color:'var(--ink)', lineHeight: 1}}>{k}</span>
        <span className="mono" style={{color:'var(--ink-2)'}}>{unit}</span>
      </div>
      <div className="mono" style={{marginTop: 6}}>{label}</div>
    </div>
  );
}

function PhoneCard({ src, tilt = 0, w = 320 }) {
  const h = Math.round(w * (2556 / 1179));
  return (
    <div style={{
      width: w, height: h,
      borderRadius: 44,
      background: '#0b0a08',
      padding: 10,
      boxShadow: '0 40px 80px -30px rgba(60,40,120,0.45), 0 16px 30px -10px rgba(0,0,0,0.2), inset 0 0 0 2px rgba(255,255,255,0.04)',
      transform: `rotate(${tilt}deg)`,
      transition: 'transform .3s ease'
    }}>
      <div style={{
        width: '100%', height: '100%',
        borderRadius: 36,
        backgroundImage: `url(${src})`,
        backgroundSize: 'cover',
        backgroundPosition: 'center',
        overflow: 'hidden',
        position: 'relative'
      }}>
        {/* Notch */}
        <div style={{
          position:'absolute', top: 10, left: '50%', transform:'translateX(-50%)',
          width: Math.round(w*0.32), height: Math.round(w*0.085),
          background: '#0b0a08', borderRadius: 999
        }}/>
      </div>
    </div>
  );
}

function Annotation({ children, style, pos }) {
  return (
    <div style={{
      position: 'absolute',
      background: 'var(--cream)', border:'1px solid rgba(22,19,15,0.1)',
      borderRadius: 14, padding: '12px 16px',
      boxShadow: '0 10px 30px -12px rgba(0,0,0,0.15)',
      minWidth: 180, ...style
    }}>
      {children}
      {/* connector */}
      <svg style={{position:'absolute', [pos==='right'?'right':'left']: pos==='right'? -48 : -48, top: '50%'}}
        width="48" height="24" viewBox="0 0 48 24" fill="none">
        <path d={pos==='right'
          ? "M 0 12 C 16 12, 32 20, 48 12"
          : "M 48 12 C 32 12, 16 20, 0 12"}
          stroke="rgba(22,19,15,0.35)" strokeWidth="1.5" strokeDasharray="3 3" fill="none"/>
        <circle cx={pos==='right'? 46 : 2} cy="12" r="2" fill="var(--ink)"/>
      </svg>
    </div>
  );
}

function ElevationSvg() {
  return (
    <svg width="100%" height="120" viewBox="0 0 520 120" preserveAspectRatio="none">
      <defs>
        <linearGradient id="eg" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="rgba(123,47,255,0.35)"/>
          <stop offset="100%" stopColor="rgba(123,47,255,0.02)"/>
        </linearGradient>
      </defs>
      <path d="M 0 90 L 30 78 L 60 62 L 95 84 L 140 48 L 190 30 L 230 56 L 275 22 L 320 48 L 360 74 L 410 44 L 450 68 L 490 86 L 520 96 L 520 120 L 0 120 Z"
        fill="url(#eg)"/>
      <path d="M 0 90 L 30 78 L 60 62 L 95 84 L 140 48 L 190 30 L 230 56 L 275 22 L 320 48 L 360 74 L 410 44 L 450 68 L 490 86 L 520 96"
        stroke="var(--brand)" strokeWidth="2.2" fill="none"/>
      {/* Stop pins */}
      {[{x:60, km:'Mile 8 · Coffee'},{x:230, km:'Mile 29 · Shop'},{x:410, km:'Mile 50 · Café'}].map((p,i) =>
        <g key={i} transform={`translate(${p.x}, 0)`}>
          <line x1="0" y1="0" x2="0" y2="120" stroke="rgba(123,47,255,0.3)" strokeDasharray="2 3"/>
          <circle cx="0" cy={i===0?62:i===1?56:44} r="4" fill="var(--brand)" stroke="var(--cream)" strokeWidth="2"/>
        </g>
      )}
    </svg>
  );
}

Object.assign(window, { Hero });
