// Landing page — warm bone throughout, amber accent, SF system fonts.

function useIsMobile(breakpoint) {
  var bp = breakpoint || 768;
  var [isMobile, setIsMobile] = React.useState(window.innerWidth < bp);
  React.useEffect(() => {
    var check = () => setIsMobile(window.innerWidth < bp);
    window.addEventListener('resize', check, { passive: true });
    return () => window.removeEventListener('resize', check);
  }, [bp]);
  return isMobile;
}

function ScreenPlaceholder({ label, note, aspect = '9 / 16', kind = 'screenshot' }) {
  const paper2 = '#EAE4DA';
  const rule = 'rgba(11,11,12,0.14)';
  const ink = '#15141A';
  const inkMute = 'rgba(21,20,26,0.56)';
  const inkDim = 'rgba(21,20,26,0.4)';
  const font = '-apple-system, "SF Pro Display", system-ui, sans-serif';
  return (
    <div style={{
      aspectRatio: aspect, background: paper2,
      border: `1.5px dashed ${rule}`, borderRadius: 18,
      display: 'flex', flexDirection: 'column',
      alignItems: 'center', justifyContent: 'center',
      padding: 24, textAlign: 'center', position: 'relative',
      fontFamily: font, overflow: 'hidden',
    }}>
      <div style={{
        position: 'absolute', top: 12, left: 14, right: 14,
        display: 'flex', justifyContent: 'space-between',
        fontSize: 10, letterSpacing: 0.8,
        color: inkDim, textTransform: 'uppercase',
      }}>
        <span>Placeholder</span>
        <span>{kind === 'video' ? 'Screen recording' : 'Screenshot'}</span>
      </div>
      <svg width="56" height="84" viewBox="0 0 56 84" fill="none" style={{ opacity: 0.35, marginBottom: 18 }}>
        <rect x="3" y="3" width="50" height="78" rx="9" stroke={ink} strokeWidth="1.5"/>
        <rect x="20" y="6" width="16" height="3" rx="1.5" fill={ink} opacity="0.4"/>
      </svg>
      <div style={{ fontSize: 16, color: ink, fontWeight: 500, letterSpacing: -0.2 }}>
        {label}
      </div>
      {note && (
        <div style={{ fontSize: 12, color: inkMute, marginTop: 8, maxWidth: 220, lineHeight: 1.45 }}>
          {note}
        </div>
      )}
    </div>
  );
}

function LandingLight({ accent = '#F59E0B' }) {
  const isMobile = useIsMobile();

  React.useEffect(() => {
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => {
        if (e.isIntersecting) {
          e.target.classList.add('in');
          io.unobserve(e.target);
        }
      });
    }, { threshold: 0.12, rootMargin: '0px 0px -8% 0px' });
    document.querySelectorAll('.ts-reveal').forEach(el => io.observe(el));

    const spy = new IntersectionObserver((entries) => {
      entries.forEach(e => {
        if (e.isIntersecting) {
          const id = e.target.getAttribute('data-ts-section');
          document.querySelectorAll('.ts-nav a[data-nav]').forEach(a => {
            a.classList.toggle('active', a.getAttribute('data-nav') === id);
          });
        }
      });
    }, { rootMargin: '-40% 0px -55% 0px' });
    document.querySelectorAll('[data-ts-section]').forEach(el => spy.observe(el));

    const float = document.querySelector('.ts-hero-float');
    const onScroll = () => {
      if (!float) return;
      const y = Math.min(window.scrollY, 600);
      float.style.transform = `translateY(${y * -0.06}px)`;
    };
    window.addEventListener('scroll', onScroll, { passive: true });
    onScroll();
    return () => { io.disconnect(); spy.disconnect(); window.removeEventListener('scroll', onScroll); };
  }, []);

  const paper    = '#F5F1EA';
  const paper2   = '#EAE4DA';
  const rule     = 'rgba(11,11,12,0.12)';
  const ink      = '#15141A';
  const inkMute  = 'rgba(21,20,26,0.62)';
  const inkDim   = 'rgba(21,20,26,0.42)';
  const bone     = '#FAFAF7';
  const font = '-apple-system, "SF Pro Display", "SF Pro Text", system-ui, sans-serif';

  const px = isMobile ? '20px' : '56px';

  const LightWordmark = ({ size = 22 }) => (
    <div style={{
      fontFamily: font, fontSize: size, letterSpacing: -0.2, lineHeight: 1,
      display: 'inline-flex', alignItems: 'baseline',
    }}>
      <span style={{ color: ink, fontWeight: 500 }}>tempo</span>
      <span style={{ color: accent, fontWeight: 600 }}>step</span>
    </div>
  );

  const Eyebrow = ({ label }) => (
    <div style={{
      display: 'inline-flex', alignItems: 'center', gap: 10,
      fontFamily: font, fontSize: 12, letterSpacing: 1, fontWeight: 500,
      color: inkDim, textTransform: 'uppercase',
    }}>
      <span className="ts-dot-pulse" style={{ width: 6, height: 6, borderRadius: '50%', background: accent }}/>
      {label}
    </div>
  );

  return (
    <div style={{
      background: paper, color: ink, fontFamily: font,
      minHeight: '100%', width: '100%',
      WebkitFontSmoothing: 'antialiased',
    }}>
      <style>{`
        .ts-reveal { opacity: 0; transform: translateY(24px); transition: opacity 900ms cubic-bezier(.2,.7,.1,1), transform 900ms cubic-bezier(.2,.7,.1,1); }
        .ts-reveal.in { opacity: 1; transform: none; }
        .ts-reveal-delay-1 { transition-delay: 80ms; }
        .ts-reveal-delay-2 { transition-delay: 160ms; }
        .ts-reveal-delay-3 { transition-delay: 240ms; }
        .ts-reveal-delay-4 { transition-delay: 320ms; }
        @keyframes ts-halo { 0%, 100% { opacity: 0.55; transform: scale(1); } 50% { opacity: 1; transform: scale(1.04); } }
        .ts-halo { animation: ts-halo 5.2s ease-in-out infinite; }
        @keyframes ts-dot { 0%, 100% { box-shadow: 0 0 0px ${accent}00; } 50% { box-shadow: 0 0 10px ${accent}cc; } }
        .ts-dot-pulse { animation: ts-dot 2.4s ease-in-out infinite; }
        .ts-nav a { position: relative; transition: color 160ms; }
        .ts-nav a.active { color: ${ink}; }
        .ts-nav a.active::after {
          content: ''; position: absolute; left: 0; right: 0; bottom: -22px; height: 2px;
          background: ${accent}; border-radius: 2px;
        }
        .ts-hero-float { transition: transform 120ms linear; }
        @media (prefers-reduced-motion: reduce) {
          .ts-reveal { opacity: 1 !important; transform: none !important; transition: none !important; }
          .ts-halo, .ts-dot-pulse { animation: none !important; }
          .ts-hero-float { transform: none !important; }
        }
      `}</style>

      {/* Nav */}
      <nav className="ts-nav" style={{
        position: 'sticky', top: 0, zIndex: 50,
        display: 'flex', alignItems: 'center', justifyContent: 'space-between',
        padding: isMobile ? '14px 20px' : '22px 56px',
        borderBottom: `1px solid ${rule}`,
        background: 'rgba(245,241,234,0.82)',
        backdropFilter: 'saturate(140%) blur(12px)',
        WebkitBackdropFilter: 'saturate(140%) blur(12px)',
      }}>
        <LightWordmark size={isMobile ? 20 : 22}/>
        <div style={{ display: 'flex', gap: isMobile ? 12 : 32, alignItems: 'center', fontSize: 14, color: inkMute }}>
          {!isMobile && <>
            <a href="#how" data-nav="how" style={{ color: inkMute, textDecoration: 'none' }}>How it works</a>
            <a href="#features" data-nav="features" style={{ color: inkMute, textDecoration: 'none' }}>Features</a>
            <a href="#faq" data-nav="faq" style={{ color: inkMute, textDecoration: 'none' }}>FAQ</a>
          </>}
          <div style={{
            padding: isMobile ? '8px 12px' : '8px 14px',
            borderRadius: 10, background: ink,
            color: bone, fontSize: 13, fontWeight: 500,
            display: 'inline-flex', alignItems: 'center', gap: 6,
          }}>
            <AppleGlyph size={13} color={bone}/>
            {isMobile ? 'Download' : 'Download · $4.99'}
          </div>
        </div>
      </nav>

      {/* Hero */}
      <section data-ts-section="hero" style={{
        padding: isMobile ? '40px 20px 24px' : '80px 56px 24px',
        maxWidth: 1440, margin: '0 auto',
      }}>
        <div style={{
          display: 'grid',
          gridTemplateColumns: isMobile ? '1fr' : '1.1fr 0.9fr',
          gap: isMobile ? 40 : 64,
          alignItems: 'center',
        }}>
          <div>
            <div style={{
              display: 'inline-flex', alignItems: 'center', gap: 8,
              padding: '6px 12px 6px 8px', borderRadius: 999,
              background: paper2, color: inkMute, fontSize: 12,
              border: `1px solid ${rule}`, letterSpacing: 0.2,
            }}>
              <span style={{
                width: 6, height: 6, borderRadius: '50%', background: accent,
                boxShadow: `0 0 8px ${accent}88`,
              }}/>
              iOS 17+ · iPhone
            </div>

            <div style={{ marginTop: 24, marginBottom: 0 }}>
              <LightWordmark size={isMobile ? 34 : 44}/>
            </div>

            <h1 className="ts-reveal ts-reveal-delay-1" style={{
              fontSize: isMobile ? 68 : 104,
              lineHeight: 0.94,
              letterSpacing: isMobile ? -2 : -4,
              fontWeight: 200, marginTop: 16, marginBottom: 0, color: ink,
            }}>
              Play.<br/>Pause.<br/>
              <span style={{ color: accent, fontWeight: 300, fontStyle: 'italic' }}>Progress.</span>
            </h1>

            <p className="ts-reveal ts-reveal-delay-2" style={{
              fontSize: isMobile ? 17 : 22,
              lineHeight: 1.5, color: inkMute,
              marginTop: isMobile ? 20 : 32,
              maxWidth: 540,
            }}>
              A metronome that listens. TempoStep hears when you stop
              playing and steps the tempo up on its own.
            </p>

            <div style={{
              display: 'flex',
              flexDirection: isMobile ? 'column' : 'row',
              gap: 14, marginTop: isMobile ? 28 : 44, alignItems: 'flex-start',
            }}>
              <div style={{
                display: 'inline-flex', alignItems: 'center', gap: 12,
                padding: '14px 22px', borderRadius: 14,
                background: ink, color: bone, cursor: 'pointer',
              }}>
                <AppleGlyph size={18} color={bone}/>
                <div style={{ display: 'flex', flexDirection: 'column', lineHeight: 1.1 }}>
                  <span style={{ fontSize: 10, fontWeight: 400, color: 'rgba(250,250,247,0.6)', letterSpacing: 0.3 }}>Download on the</span>
                  <span style={{ fontSize: 17, fontWeight: 600 }}>App Store</span>
                </div>
              </div>
              <div style={{ fontSize: 14, color: inkDim, marginLeft: isMobile ? 0 : 8 }}>
                <div style={{ color: ink, fontWeight: 500 }}>$4.99, one time</div>
                <div style={{ fontSize: 12 }}>intro $2.99, no subscription</div>
              </div>
            </div>
          </div>

          {/* Hero video */}
          <div style={{
            display: 'flex', justifyContent: 'center', alignItems: 'center',
            position: 'relative',
            minHeight: isMobile ? undefined : 820,
            marginTop: isMobile ? 8 : 0,
          }}>
            <div className="ts-halo" style={{
              position: 'absolute',
              width: isMobile ? '90%' : 480,
              height: isMobile ? '90%' : 760,
              borderRadius: 120,
              background: `radial-gradient(ellipse, ${accent}1a 0%, transparent 65%)`,
              filter: 'blur(40px)', pointerEvents: 'none',
            }}/>
            <div className="ts-hero-float" style={{
              width: isMobile ? '72%' : 360,
              maxWidth: isMobile ? 300 : undefined,
              position: 'relative', zIndex: 1,
            }}>
              {/* Phone frame container — aspect ratio matches the exported clay frame (619×1280).
                   border-radius uses h/v form so corners are circular, not elliptical
                   (container is ~2× taller than wide, so % maps differently on each axis).
                   Outer phone corner ≈ 73px at 619px wide → 11.8% h / 5.7% v */}
              <div style={{ position: 'relative', aspectRatio: '619 / 1280', overflow: 'hidden', borderRadius: '11.8% / 5.7%' }}>
                {/* Video positioned to fill the screen opening */}
                <video
                  src="TempoStep_Screen_Recording.mov"
                  autoPlay
                  loop
                  muted
                  playsInline
                  style={{
                    position: 'absolute',
                    left: '3.72%',
                    top: '1.80%',
                    width: '92.57%',
                    height: '96.48%',
                    objectFit: 'cover',
                    display: 'block',
                    borderRadius: '8.9% / 4.1%',
                  }}
                />
                {/* Clay phone frame overlay — transparent where screen is */}
                <img
                  src="iphone_frame.png"
                  alt=""
                  style={{
                    position: 'absolute',
                    inset: 0,
                    width: '100%',
                    height: '100%',
                    pointerEvents: 'none',
                    display: 'block',
                  }}
                />
              </div>
            </div>
          </div>
        </div>

        {/* Stat band */}
        <div style={{
          marginTop: isMobile ? 40 : 56,
          paddingTop: isMobile ? 28 : 36,
          borderTop: `1px solid ${rule}`,
          display: 'grid',
          gridTemplateColumns: isMobile ? '1fr' : 'repeat(3, 1fr)',
          gap: isMobile ? 24 : 0,
        }}>
          {[
            ['Auto', 'tempo advance', 'The app hears you stop. The tempo advances on its own.'],
            ['Target', 'you set', 'Choose a goal BPM. The app steps toward it, pass by pass.'],
            ['$4.99', 'once, yours', 'No subscription, no account, no ads, ever.'],
          ].map(([big, mid, small], i) => (
            <div key={i} style={{
              paddingRight: isMobile ? 0 : 24,
              borderLeft: (!isMobile && i > 0) ? `1px solid ${rule}` : 'none',
              borderTop: (isMobile && i > 0) ? `1px solid ${rule}` : 'none',
              paddingLeft: (!isMobile && i > 0) ? 24 : 0,
              paddingTop: (isMobile && i > 0) ? 24 : 0,
            }}>
              <div style={{
                fontSize: isMobile ? 28 : 34,
                fontWeight: 300, letterSpacing: -1, color: ink,
                fontVariantNumeric: 'tabular-nums',
              }}>{big}</div>
              <div style={{
                fontSize: 12, color: inkDim,
                letterSpacing: 1, marginTop: 4, fontWeight: 500,
                textTransform: 'uppercase',
              }}>{mid}</div>
              <p style={{ fontSize: 14, color: inkMute, marginTop: 10, marginBottom: 0, lineHeight: 1.5 }}>
                {small}
              </p>
            </div>
          ))}
        </div>
      </section>

      {/* How It Works */}
      <section id="how" data-ts-section="how" style={{
        padding: isMobile ? `60px ${px} 80px` : `120px 56px`,
        maxWidth: 1440, margin: '0 auto',
        borderTop: `1px solid ${rule}`, marginTop: 64,
        scrollMarginTop: 80,
      }}>
        <div className="ts-reveal"><Eyebrow label="How it works"/></div>
        <h2 className="ts-reveal ts-reveal-delay-1" style={{
          fontSize: isMobile ? 36 : 64,
          lineHeight: isMobile ? 1.1 : 1,
          letterSpacing: isMobile ? -1 : -2,
          fontWeight: 200, margin: isMobile ? '16px 0 40px' : '20px 0 64px',
          maxWidth: 1000,
        }}>
          Play. Pause. Detection. Step.{isMobile ? ' ' : <br/>}
          <span style={{ color: inkMute }}>All four happen without your hands leaving the instrument.</span>
        </h2>

        <div style={{
          display: 'grid',
          gridTemplateColumns: isMobile ? 'repeat(2, 1fr)' : 'repeat(4, 1fr)',
          gap: isMobile ? 20 : 24,
          alignItems: 'start',
        }}>
          {[
            { n: '01', title: 'Play',     time: '0:00',
              sub: 'Set your starting BPM. The metronome clicks. The mic listens quietly in the background.',
              placeholder: 'Playing state', img: 'Play.PNG' },
            { n: '02', title: 'Pause',    time: '0:42',
              sub: 'Stop to breathe, reflect on the last pass, stretch. TempoStep notices the silence and waits for you.',
              placeholder: 'Pause / waiting', img: 'Pause.PNG' },
            { n: '03', title: 'Step',     time: '0:58',
              sub: 'When you are ready and begin to play again, the BPM has already advanced. No button, no need to glance at the screen.',
              placeholder: 'Step / BPM advancing', img: 'Step.PNG' },
            { n: '04', title: 'Target',   time: '2:31',
              sub: 'Hit the target BPM you set and the number glows amber.',
              placeholder: 'Target reached', img: 'Target.PNG' },
          ].map((s, i) => (
            <div key={i} className={"ts-reveal ts-reveal-delay-" + Math.min(i + 1, 4)} style={{
              display: 'flex', flexDirection: 'column', gap: 14,
              marginTop: (!isMobile && i % 2 === 1) ? 40 : 0,
            }}>
              <div style={{
                display: 'flex', justifyContent: 'space-between',
                alignItems: 'baseline',
                borderTop: `1px solid ${rule}`, paddingTop: 12,
              }}>
                <div style={{ fontSize: 11, color: inkDim, letterSpacing: 1, fontWeight: 500 }}>
                  STATE {s.n}
                </div>
                <div style={{ fontSize: 11, color: inkDim, fontVariantNumeric: 'tabular-nums' }}>{s.time}</div>
              </div>
              {s.img ? (
                <img
                  src={s.img}
                  alt={s.placeholder}
                  style={{ width: '100%', aspectRatio: '9 / 19.5', borderRadius: 16, objectFit: 'cover', objectPosition: 'top', display: 'block' }}
                />
              ) : (
                <ScreenPlaceholder label={s.placeholder} note="Single screenshot of this state."/>
              )}
              <div>
                <h3 style={{
                  fontSize: isMobile ? 18 : 24,
                  fontWeight: 500, margin: 0,
                  letterSpacing: -0.4, color: ink,
                }}>{s.title}</h3>
                <p style={{ fontSize: isMobile ? 13 : 14, lineHeight: 1.55, color: inkMute, marginTop: 6, marginBottom: 0 }}>
                  {s.sub}
                </p>
              </div>
            </div>
          ))}
        </div>

        <div style={{
          marginTop: 48, display: 'flex', alignItems: 'center', gap: 14,
          fontSize: 11, color: inkDim, letterSpacing: 1, fontWeight: 500,
        }}>
          <div style={{ flex: 1, height: 1, background: rule }}/>
          {!isMobile && <span>LOOP REPEATS AT EACH PAUSE, UNTIL TARGET IS REACHED</span>}
          {isMobile && <span style={{ textAlign: 'center', fontSize: 10 }}>LOOP REPEATS AT EACH PAUSE</span>}
          <div style={{ flex: 1, height: 1, background: rule }}/>
        </div>
      </section>

      {/* The Pause feature callout */}
      <section style={{
        padding: isMobile ? `32px ${px} 60px` : '40px 56px 120px',
        maxWidth: 1100, margin: '0 auto',
      }}>
        <div className="ts-reveal"><Eyebrow label="The pause is the point"/></div>
        <h2 className="ts-reveal ts-reveal-delay-1" style={{
          fontSize: isMobile ? 36 : 56,
          lineHeight: 1.02, letterSpacing: isMobile ? -0.8 : -1.6,
          fontWeight: 300, margin: isMobile ? '16px 0 16px' : '20px 0 24px', color: ink,
        }}>
          Take the time you need.
        </h2>
        <p style={{ fontSize: isMobile ? 16 : 19, lineHeight: 1.55, color: inkMute, margin: 0, maxWidth: 720 }}>
          Because TempoStep can tell when you begin to play, the space
          between passes is yours. Stretch. Think. Reflect on what just
          happened. A physical break. A mental one. The app will be
          waiting, with the next tempo already set, the moment you start
          playing again.
        </p>
      </section>

      {/* Why It's Different */}
      <section style={{
        padding: isMobile ? `0 ${px} 60px` : '0 56px 120px',
        maxWidth: 1440, margin: '0 auto',
      }}>
        <div className="ts-reveal"><Eyebrow label="Why it's different"/></div>
        <h2 className="ts-reveal ts-reveal-delay-1" style={{
          fontSize: isMobile ? 36 : 64,
          lineHeight: isMobile ? 1.1 : 1,
          letterSpacing: isMobile ? -1 : -2,
          fontWeight: 200, margin: isMobile ? '16px 0 16px' : '20px 0 24px', maxWidth: 900,
        }}>
          Every metronome clicks.{isMobile ? ' ' : <br/>}
          <span style={{ color: inkMute }}>Only one of them listens.</span>
        </h2>
        <p className="ts-reveal ts-reveal-delay-2" style={{
          fontSize: isMobile ? 15 : 17,
          color: inkMute, maxWidth: 680, lineHeight: 1.55,
          margin: isMobile ? '0 0 32px' : '0 0 48px',
        }}>
          Other apps that ramp tempo on their own use a bar count, a timer,
          or a smooth climb. They follow the clock. TempoStep follows you.
        </p>

        <div style={{
          display: 'grid',
          gridTemplateColumns: isMobile ? '1fr' : '1fr 1fr',
          gap: 0,
          border: `1px solid ${rule}`, borderRadius: 20, overflow: 'hidden',
        }}>
          <LightCompareCol
            title="Step or ramp apps"
            kicker="OTHER AUTO TEMPO APPS"
            rows={[
              ['Trigger',    'On a bar count or a timer. The clock decides when you advance.'],
              ['Break time', 'The tempo keeps climbing whether you are playing or not.'],
              ['If you stop','You fall behind. The app does not wait for you.'],
              ['Ramp style', 'Either stepped at fixed intervals or a smooth continuous climb.'],
            ]}
            muted isMobile={isMobile}
            paper={paper2} ink={ink} inkMute={inkMute} inkDim={inkDim} rule={rule}
          />
          <LightCompareCol
            title="TempoStep"
            kicker="TEMPOSTEP"
            kickerColor={accent}
            rows={[
              ['Trigger',    'On your silence. The tempo advances only when you stop playing.'],
              ['Break time', 'As long as you need. The app waits for you to begin again.'],
              ['If you stop','Nothing happens until you start playing. Then the next tempo is ready.'],
              ['Ramp style', 'Stepped by a BPM increment you set, paced by your practice, not a clock.'],
            ]}
            isMobile={isMobile}
            paper={paper} ink={ink} inkMute={inkMute} inkDim={inkDim} rule={rule}
          />
        </div>
      </section>

      {/* Features grid */}
      <section id="features" data-ts-section="features" style={{
        padding: isMobile ? `0 ${px} 60px` : '0 56px 120px',
        maxWidth: 1440, margin: '0 auto',
        scrollMarginTop: 80,
      }}>
        <div className="ts-reveal"><Eyebrow label="What's inside"/></div>
        <h2 className="ts-reveal ts-reveal-delay-1" style={{
          fontSize: isMobile ? 34 : 56,
          lineHeight: 1.02, letterSpacing: isMobile ? -0.8 : -1.6,
          fontWeight: 300, margin: isMobile ? '14px 0 32px' : '18px 0 48px', maxWidth: 900,
        }}>
          A small set of features, each one pulling its weight.
        </h2>

        <div style={{
          display: 'grid',
          gridTemplateColumns: isMobile ? '1fr' : 'repeat(3, 1fr)',
          gap: 0, borderTop: `1px solid ${rule}`,
        }}>
          {[
            ['Auto advance',          'The mic hears when you stop and when you begin again. The BPM steps up on its own.'],
            ['Target BPM',            'Set the tempo you are working toward. The app steps toward it and lets you know when you arrive.'],
            ['Microphone calibration',   'A quick baseline sets a threshold for your room. Works in practice rooms, at home, on the road.'],
            ['Runs in the background','Auto advance keeps working while you use forScore, IMSLP, a tuner, or anything else on your phone.'],
            ['Tap tempo',             'A few taps and the BPM matches. Match a recording, a teacher, or your own reference point.'],
            ['Subdivisions',          'Off, 8th, triplet, 16th. Available in the settings menu.'],
            ['Hold tempo',            'A lock pauses the advance. Groove on the current BPM for as long as you want.'],
            ['Manual mode',           'Need a plain metronome? Switch off detection. No mic, no calibration, instant start.'],
            ['One time purchase',     '$4.99 once, yours forever. No subscription, no ads, ever.'],
          ].map(([k, v], i) => {
            const col = isMobile ? 0 : i % 3;
            const isLastInGrid = isMobile ? i === 8 : i >= 6;
            return (
              <div key={i} className={"ts-reveal ts-reveal-delay-" + ((i % 3) + 1)} style={{
                padding: isMobile ? '14px 0 16px' : '28px 24px 32px 0',
                borderRight: (!isMobile && col < 2) ? `1px solid ${rule}` : 'none',
                borderBottom: isLastInGrid ? 'none' : `1px solid ${rule}`,
                paddingLeft: (!isMobile && col > 0) ? 24 : 0,
              }}>
                <div style={{
                  fontSize: 11, color: inkDim,
                  letterSpacing: 1, marginBottom: 10, fontWeight: 500,
                  fontVariantNumeric: 'tabular-nums',
                }}>
                  {String(i + 1).padStart(2, '0')}
                </div>
                <h3 style={{
                  fontSize: isMobile ? 17 : 19,
                  fontWeight: 500, margin: 0,
                  letterSpacing: -0.2, color: ink,
                }}>{k}</h3>
                <p style={{
                  fontSize: 14, lineHeight: 1.55, color: inkMute,
                  marginTop: 8, marginBottom: 0,
                }}>{v}</p>
              </div>
            );
          })}
        </div>
      </section>

      {/* Founder note */}
      <section style={{
        padding: isMobile ? `0 ${px} 60px` : '0 56px 140px',
        maxWidth: 1100, margin: '0 auto',
      }}>
        <div className="ts-reveal"><Eyebrow label="A note from the maker"/></div>
        <blockquote className="ts-reveal ts-reveal-delay-1" style={{
          fontSize: isMobile ? 24 : 42,
          lineHeight: 1.25, letterSpacing: isMobile ? -0.4 : -1.2,
          fontWeight: 300, margin: isMobile ? '20px 0 28px' : '28px 0 40px', color: ink,
          fontFamily: font,
        }}>
          <span style={{ color: accent }}>"</span>
          I've spent decades in practice rooms working through passages
          at gradually climbing tempi. I'd stop
          every few repetitions to increase the tempo by 5 or 10 BPM,
          reaching for the metronome, resetting, starting again.
          <span style={{ color: inkMute }}> It's a small interruption, but
          it breaks momentum more than it should. TempoStep removes that
          moment entirely, letting the tempo move forward on its own.</span>
          <span style={{ color: accent }}>"</span>
        </blockquote>
        <div style={{ display: 'flex', gap: 16, alignItems: 'center' }}>
          <div style={{
            width: 48, height: 48, borderRadius: '50%',
            background: paper2, border: `1px solid ${rule}`,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            fontSize: 14, fontWeight: 500, color: inkMute, flexShrink: 0,
          }}>AM</div>
          <div>
            <div style={{ fontSize: 15, color: ink, fontWeight: 500 }}>Alan Molina</div>
            <div style={{ fontSize: 13, color: inkDim }}>Orchestral violinist. Maker of TempoStep.</div>
          </div>
        </div>
      </section>

      {/* FAQ */}
      <section id="faq" data-ts-section="faq" style={{
        padding: isMobile ? `0 ${px} 60px` : '0 56px 140px',
        maxWidth: 1100, margin: '0 auto',
        scrollMarginTop: 80,
      }}>
        <div className="ts-reveal"><Eyebrow label="Frequently asked"/></div>
        <h2 className="ts-reveal ts-reveal-delay-1" style={{
          fontSize: isMobile ? 34 : 48,
          lineHeight: 1.04, letterSpacing: isMobile ? -0.8 : -1.4,
          fontWeight: 300, margin: isMobile ? '14px 0 28px' : '18px 0 40px',
        }}>
          The short answers.
        </h2>

        <div>
          {[
            ['Does it work in the background?',
             'Yes. The metronome keeps clicking and auto advance keeps working when you switch to forScore, IMSLP, a tuner, or any other app.'],
            ['Will it confuse my playing with other sounds?',
             'On launch, TempoStep calibrates against the ambient level in your room and sets a threshold above that peak. Page turns, HVAC, and traffic sit below the line. Your instrument sits above it.'],
            ['What if I want to hold the tempo longer?',
             'Tap the lock. Detection still runs, but the BPM does not advance. Unlock and it resumes from where you were.'],
            ['Is there a subscription?',
             'No. $4.99 once, yours forever. No ads ever.'],
            ['Android?',
             'Not planned for launch. If iOS demand supports it, we will revisit.'],
          ].map(([q, a], i) => (
            <div key={i} className="ts-reveal" style={{
              padding: isMobile ? '20px 0' : '24px 0',
              borderTop: `1px solid ${rule}`,
            }}>
              {isMobile ? (
                <div>
                  <div style={{ fontSize: 11, color: inkDim, letterSpacing: 0.6, marginBottom: 8, fontWeight: 500, fontVariantNumeric: 'tabular-nums' }}>
                    Q.{String(i + 1).padStart(2, '0')}
                  </div>
                  <div style={{ fontSize: 16, color: ink, fontWeight: 500, letterSpacing: -0.2, marginBottom: 10 }}>{q}</div>
                  <div style={{ fontSize: 14, color: inkMute, lineHeight: 1.6 }}>{a}</div>
                </div>
              ) : (
                <div style={{
                  display: 'grid', gridTemplateColumns: '60px 1fr 2fr', gap: 24,
                  alignItems: 'start',
                }}>
                  <div style={{ fontSize: 12, color: inkDim, letterSpacing: 0.6, paddingTop: 4, fontWeight: 500, fontVariantNumeric: 'tabular-nums' }}>
                    Q.{String(i + 1).padStart(2, '0')}
                  </div>
                  <div style={{ fontSize: 19, color: ink, fontWeight: 500, letterSpacing: -0.2 }}>{q}</div>
                  <div style={{ fontSize: 15, color: inkMute, lineHeight: 1.6 }}>{a}</div>
                </div>
              )}
            </div>
          ))}
          <div style={{ borderTop: `1px solid ${rule}` }}/>
        </div>
      </section>

      {/* Footer */}
      <footer style={{
        padding: isMobile ? '28px 20px' : '36px 56px',
        borderTop: `1px solid ${rule}`,
        display: 'flex',
        flexDirection: isMobile ? 'column' : 'row',
        justifyContent: 'space-between', alignItems: isMobile ? 'flex-start' : 'center',
        gap: isMobile ? 20 : 0,
        fontSize: 13, color: inkDim,
      }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 20 }}>
          <LightWordmark size={16}/>
          <span style={{ fontVariantNumeric: 'tabular-nums' }}>v1.0 · iOS 17+</span>
        </div>
        <div style={{ display: 'flex', gap: 24, alignItems: 'center', flexWrap: 'wrap' }}>
          <a style={{ color: inkDim, textDecoration: 'none' }}>Privacy</a>
          <a style={{ color: inkDim, textDecoration: 'none' }}>Support</a>
          <a style={{ color: ink, textDecoration: 'none', fontWeight: 500 }} href="mailto:tempostepapp@gmail.com">tempostepapp@gmail.com</a>
        </div>
      </footer>
    </div>
  );
}

function LightCompareCol({ title, kicker, kickerColor, rows, muted, isMobile, paper, ink, inkMute, inkDim, rule }) {
  return (
    <div style={{ background: paper, padding: isMobile ? 24 : 36 }}>
      <div style={{
        fontSize: 12, letterSpacing: 1, fontWeight: 500,
        color: kickerColor || inkDim, marginBottom: 20,
      }}>{kicker}</div>
      <h3 style={{
        fontSize: isMobile ? 22 : 28, fontWeight: 400, letterSpacing: -0.6,
        color: muted ? inkMute : ink,
        margin: '0 0 20px',
      }}>{title}</h3>
      <dl style={{ margin: 0, display: 'grid', gap: 14 }}>
        {rows.map(([k, v], i) => (
          <div key={i} style={{
            display: 'grid',
            gridTemplateColumns: isMobile ? '80px 1fr' : '120px 1fr',
            gap: isMobile ? 10 : 16,
            paddingTop: 14, borderTop: `1px solid ${rule}`,
          }}>
            <dt style={{ fontSize: 11, color: inkDim, letterSpacing: 0.6, paddingTop: 2, fontWeight: 500, textTransform: 'uppercase' }}>{k}</dt>
            <dd style={{
              margin: 0, fontSize: isMobile ? 13 : 15,
              color: muted ? inkMute : ink,
              lineHeight: 1.5,
              fontWeight: muted ? 300 : 500,
            }}>{v}</dd>
          </div>
        ))}
      </dl>
    </div>
  );
}

function AppleGlyph({ size = 16, color = '#000' }) {
  return (
    <svg width={size} height={size * 1.2} viewBox="0 0 20 24" fill={color}>
      <path d="M16.37 12.63c-.03-2.78 2.27-4.12 2.37-4.19-1.29-1.89-3.3-2.15-4-2.18-1.7-.17-3.32.99-4.19.99-.87 0-2.2-.97-3.61-.94-1.86.03-3.58 1.08-4.53 2.74-1.93 3.35-.49 8.3 1.39 11.03.92 1.33 2.01 2.83 3.43 2.78 1.38-.06 1.9-.89 3.57-.89 1.67 0 2.13.89 3.58.86 1.48-.03 2.42-1.36 3.33-2.7.85-1.28 1.39-2.56 1.76-3.87-.03-.01-3.07-1.17-3.1-4.63zM13.57 4.37c.77-.93 1.29-2.23 1.14-3.52-1.11.05-2.45.74-3.25 1.67-.71.82-1.34 2.13-1.17 3.39 1.24.1 2.51-.63 3.28-1.54z"/>
    </svg>
  );
}

Object.assign(window, { LandingLight, ScreenPlaceholder });
