/* global React, ReactDOM */
const { useState, useEffect, useRef } = React;

/* ========================== ICONS ========================== */
const LiwayMark = ({ size = 36, color = "currentColor" }) => (
  <svg width={size} height={size} viewBox="0 0 1024 1024" fill="none" aria-hidden="true">
    <g stroke={color} fill="none" strokeMiterlimit="10">
      <circle cx="361" cy="292.43" r="69.76" strokeWidth="55"/>
      <circle cx="361" cy="731.57" r="69.76" strokeWidth="55"/>
      <circle cx="663" cy="731.57" r="69.76" strokeWidth="55"/>
    </g>
    <rect x="345.23" y="388.85" width="31.54" height="232.43" fill={color}/>
    <rect x="432.7" y="715.6" width="105.97" height="31.54" fill={color}/>
  </svg>
);

const Wordmark = ({ height = 28, color = "currentColor" }) => (
  <svg height={height} viewBox="0 0 447.04 196.48" fill={color} aria-label="liway">
    <path d="M0,0h21.11v124.61c0,4.96,2.64,7.43,7.93,7.43h7.32v20.5h-9.42c-7.7,0-14.04-1.98-19.04-5.94-5.27-4.03-7.9-10.8-7.9-20.32V0Z"/>
    <path d="M55.87,0h21.11v21.75h-21.11V0ZM55.87,43.94h21.11v108.6h-21.11V43.94Z"/>
    <path d="M168.01,76.46h-.41l-21.99,76.09h-18.65l-33.64-108.6h22.4l20.16,76.18h.41l23.92-76.18h15.3l23.92,76.18h.41l20.06-76.18h22.4l-33.54,108.6h-18.75l-21.99-76.09Z"/>
    <path d="M316.59,142.92h-.41c-1.96,3.69-5,6.41-9.12,8.16-4.05,1.81-9.66,2.72-16.81,2.72-11.75-.14-20.8-3.35-27.14-9.62-6.69-6.14-10.03-13.98-10.03-23.54s2.9-16.7,8.71-22.7c5.81-6.14,14.32-9.27,25.53-9.42h29.27v-11.46c.14-9.6-7.06-14.26-21.58-13.98-5.27,0-9.42.56-12.46,1.68-3.18,1.33-5.68,3.58-7.5,6.73l-16.62-13.09c8.03-10.82,19.88-16.09,35.54-15.81,13.23-.14,23.79,2.44,31.69,7.74,7.9,5.44,11.91,14.79,12.05,28.04v74.18h-21.11v-9.62ZM316.59,106.5h-25.38c-12.32.28-18.41,4.64-18.27,13.09,0,3.7,1.59,6.84,4.77,9.42,3.04,2.86,8.09,4.29,15.12,4.29,8.86.14,15.12-.94,18.78-3.25,3.31-2.3,4.97-7.54,4.97-15.71v-7.85Z"/>
    <path d="M352.06,43.94h22.38l24.91,76.08h.41l24.81-76.08h22.48l-45.26,131.09c-2.9,8.16-6.92,13.81-12.05,16.95-5.2,3-11.07,4.5-17.62,4.5h-6.99v-20.5h6.18c2.77,0,5.33-.77,7.69-2.31,2.36-1.61,4.02-3.98,4.96-7.13l5.77-18.24-37.67-104.38Z"/>
  </svg>
);

const Arrow = ({ size = 14 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
    <path d="M5 12h14M13 5l7 7-7 7"/>
  </svg>
);

/* ========================== NAV ========================== */
const Nav = () => {
  // Reveal the small nav logo only after the big hero wordmark scrolls
  // out of view. Watching the hero wordmark itself with an IntersectionObserver.
  const [showLogo, setShowLogo] = useState(false);

  useEffect(() => {
    const target = document.querySelector(".hero-wordmark");
    if (!target || typeof IntersectionObserver === "undefined") return;
    const observer = new IntersectionObserver(
      ([entry]) => setShowLogo(!entry.isIntersecting),
      { threshold: 0, rootMargin: "-64px 0px 0px 0px" }
    );
    observer.observe(target);
    return () => observer.disconnect();
  }, []);

  return (
    <header className="nav">
      <div className="container nav-inner">
        <a href="/" className={`nav-logo ${showLogo ? "is-visible" : ""}`} aria-label="liway home">
          <LiwayMark size={28} />
        </a>
        <nav className="nav-links">
          <a href="#how">How it works</a>
          <a href="#why">Why liway</a>
          <a href="#download">Download</a>
          <a href="https://my.liway.app" className="nav-cta">My liway <Arrow size={12}/></a>
        </nav>
      </div>
    </header>
  );
};

/* ========================== HERO ========================== */
const HeroVisual = () => (
  // Stylized subway-map "L" — uses the brand mark vocabulary but expanded.
  // Three stations + connecting tracks. The "leeway" line.
  <div className="hero-visual" aria-hidden="true">
    <svg viewBox="0 0 520 520" className="hero-mark">
      {/* faint grid */}
      <defs>
        <pattern id="dots" x="0" y="0" width="24" height="24" patternUnits="userSpaceOnUse">
          <circle cx="1" cy="1" r="1" fill="var(--euc-200)" opacity="0.5"/>
        </pattern>
      </defs>
      <rect x="0" y="0" width="520" height="520" fill="url(#dots)"/>

      {/* the L mark, scaled up */}
      <g stroke="var(--euc-300)" fill="none" strokeWidth="38" strokeLinecap="round">
        <line x1="120" y1="100" x2="120" y2="400"/>
        <line x1="120" y1="400" x2="420" y2="400"/>
      </g>
      {/* stations */}
      <g>
        <circle cx="120" cy="100" r="44" fill="var(--slate-950)" stroke="var(--euc-300)" strokeWidth="20"/>
        <circle cx="120" cy="400" r="44" fill="var(--slate-950)" stroke="var(--euc-300)" strokeWidth="20"/>
        <circle cx="420" cy="400" r="44" fill="var(--slate-950)" stroke="var(--euc-300)" strokeWidth="20"/>
      </g>
    </svg>
  </div>
);

const Hero = () => (
  <section className="hero">
    <div className="container hero-grid">
      <div className="hero-copy">
        <div className="hero-wordmark" aria-hidden="true">
          <Wordmark height={120} color="var(--cream-100)" />
        </div>
        <p className="eyebrow">
          <span className="eyebrow-dot"/>
          Know before you spend.
        </p>
        <h1 className="display">
          Know your{" "}
          <em className="serif-newsreader">real headroom</em>
          <br/>
          before payday.
        </h1>
        <p className="lede">
          We show you what's safe to spend before payday, so you can stop overthinking it.
        </p>

        <LeewayMeter />
        <p className="hero-leeway-link">
          <a href="/how-liway-works/">See how it works →</a>
        </p>

        {/* mobile-only phone screenshot — sits between lede and CTAs */}
        <div className="hero-phone-mobile" aria-hidden="true">
          <img src="assets/screen-results.png" alt=""/>
        </div>

        <div className="hero-ctas">
          <a href="/beta/" className="store-badge" aria-label="Join the beta — App Store coming soon">
            <img src="assets/appstore-badge.png" alt="Download on the App Store"/>
          </a>
          <a href="/beta/" className="store-badge" aria-label="Join the beta — Google Play coming soon">
            <img src="assets/googleplay-badge.png" alt="Get it on Google Play"/>
          </a>
        </div>

        <p className="hero-meta">
          <span className="meta-dot"/> Connects via Plaid · Read-only · Free to start
        </p>
      </div>

      <HeroVisual/>
    </div>
  </section>
);

/* ========================== LEEWAY METER (live mini-component) ========================== */
const LeewayMeter = () => {
  const pos = 60;
  return (
    <div className="leeway-card" role="figure" aria-label="Sample leeway projection">
      <div className="leeway-head">
        <span className="leeway-label">YOUR LEEWAY</span>
        <span className="leeway-status safe">● SAFE through payday</span>
      </div>
      <div className="leeway-track">
        <div className="leeway-fill" style={{width: `${pos}%`}}/>
        <div className="leeway-bill" style={{left: '25%'}}>
          <span className="leeway-bill-tick"/>
          <span className="leeway-bill-label">$1,400</span>
        </div>
        <div className="leeway-bill" style={{left: '87.5%'}}>
          <span className="leeway-bill-tick"/>
          <span className="leeway-bill-label">$280</span>
        </div>
        <div className="leeway-marker" style={{left: `${pos}%`}}>
          <div className="leeway-marker-bubble">$1,184</div>
          <div className="leeway-marker-today">today</div>
        </div>
      </div>
      <div className="leeway-foot">
        <span><strong>Apr 22</strong> · last paycheck</span>
        <span><strong>Apr 30</strong> · payday</span>
      </div>
    </div>
  );
};

/* ========================== WHAT IS LIWAY (feature cards) ========================== */
const FeatureCard = ({ num, title, body, icon }) => (
  <article className="feature-card">
    <div className="feature-card-head">
      <span className="feature-num">{num}</span>
      <span className="feature-icon" aria-hidden="true">{icon}</span>
    </div>
    <h3>{title}</h3>
    <p>{body}</p>
  </article>
);

const WhatIsLiway = () => (
  <section className="section section-what" id="why">
    <div className="container">
      <header className="section-head">
        <p className="eyebrow">What is liway</p>
        <h2 className="section-title">One question, answered the moment you open the app: <em>how much room do I actually have?</em></h2>
        <p className="section-intro">Three things liway does without asking.</p>
      </header>

      <div className="feature-grid">
        <FeatureCard
          num="01"
          title="Continuous headroom"
          body="Your headroom updates in real time as bills hit and paychecks land. The number is alive, not a snapshot."
          icon={
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round">
              <path d="M3 12c2-4 4-4 6 0s4 4 6 0 4-4 6 0"/>
            </svg>
          }
        />
        <FeatureCard
          num="02"
          title="Risk projection"
          body="SAFE / TIGHT / RISK callouts tell you exactly how much pressure you're carrying, and which day the math turns."
          icon={
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
              <circle cx="12" cy="12" r="9"/>
              <path d="M12 7v5l3 2"/>
            </svg>
          }
        />
        <FeatureCard
          num="03"
          title="Actionable nudges"
          body="When you're tight, we suggest the one or two specific moves that buy you the most days, not generic advice."
          icon={
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
              <path d="M12 2v6M12 22v-4M4.93 4.93l4.24 4.24M14.83 14.83l4.24 4.24M2 12h6M22 12h-6"/>
            </svg>
          }
        />
      </div>
    </div>
  </section>
);

/* ========================== FEATURE SHOWCASE ========================== */
const StatCallout = () => (
  <section className="section stat-section">
    <div className="container">
      <header className="section-head">
        <p className="eyebrow">What makes liway different</p>
        <h2 className="section-title">Answers your bank app won't give you.</h2>
      </header>

      <div className="prime-grid">
        {/* 01 — Depletion date */}
        <article className="prime-card">
          <div className="prime-meta">
            <span className="prime-icon" aria-hidden="true">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
                <rect x="3" y="5" width="18" height="16" rx="2"/>
                <path d="M3 9h18M8 3v4M16 3v4"/>
                <circle cx="12" cy="14" r="2.4" fill="currentColor" stroke="none"/>
              </svg>
            </span>
            <span className="prime-num">01</span>
            <span className="prime-tag">The depletion date</span>
          </div>
          <h3 className="prime-title">We tell you the day, <em>not just the balance</em>.</h3>
          <p className="prime-body">We compute your daily burn rate from your outflows and show the exact date your balance hits zero. So you can act before it does.</p>
        </article>

        {/* 02 — Honest detection */}
        <article className="prime-card">
          <div className="prime-meta">
            <span className="prime-icon" aria-hidden="true">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
                <path d="M12 3l8 3v5c0 5-3.5 8.5-8 10-4.5-1.5-8-5-8-10V6l8-3z"/>
                <path d="M9 12l2 2 4-4"/>
              </svg>
            </span>
            <span className="prime-num">02</span>
            <span className="prime-tag">Honest detection</span>
          </div>
          <h3 className="prime-title">We auto-detect bills. <em>If we're unsure, we say so</em>.</h3>
          <p className="prime-body">We score every recurring charge by confidence: high, medium, or low. High auto-fills. Medium and low surface for your approval. Never silently.</p>
        </article>

        {/* 03 — Simulator */}
        <article className="prime-card">
          <div className="prime-meta">
            <span className="prime-icon" aria-hidden="true">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
                <line x1="4" y1="8" x2="20" y2="8"/>
                <line x1="4" y1="16" x2="20" y2="16"/>
                <circle cx="9" cy="8" r="2.6" fill="var(--cream-50)"/>
                <circle cx="15" cy="16" r="2.6" fill="var(--cream-50)"/>
              </svg>
            </span>
            <span className="prime-num">03</span>
            <span className="prime-tag">The simulator</span>
          </div>
          <h3 className="prime-title">Slide. <em>Watch your headroom change.</em> Decide.</h3>
          <p className="prime-body">Move planned spending up or down. The depletion date and risk level recompute instantly. Most apps show you a budget. We show what happens if you break it.</p>
        </article>
      </div>
    </div>
  </section>
);

/* ========================== HOW IT WORKS ========================== */
const HowItWorks = () => (
  <section className="section section-how" id="how">
    <div className="container">
      <header className="section-head">
        <p className="eyebrow">How it works</p>
        <h2 className="section-title">Set up in four minutes. Then never wonder where you stand again.</h2>
      </header>

      <ol className="steps">
        <li className="step">
          <div className="step-num">1</div>
          <h3>Connect your accounts</h3>
          <p>Use Plaid (read-only, no passwords) or enter your numbers by hand. Either way works.</p>
          <span className="step-meta">~2 minutes</span>
        </li>
        <li className="step">
          <div className="step-num">2</div>
          <h3>Confirm your bills</h3>
          <p>We detect what's recurring; you confirm what we got right and add what we missed.</p>
          <span className="step-meta">~2 minutes</span>
        </li>
      </ol>

      <p className="steps-closer">
        <strong>That's it.</strong> Open liway whenever you need a real answer. <em>Am I safe through this month?</em> The app tells you in one screen.
      </p>
    </div>
  </section>
);

/* ========================== PRODUCT SHOWCASE ========================== */
const PhoneFrame = ({ label, children, accent, image }) => (
  <div className={`phone ${accent ? "phone-accent" : ""} ${image ? "phone-image" : ""}`}>
    <div className="phone-notch"/>
    <div className="phone-screen">
      {children}
    </div>
    <span className="phone-label">{label}</span>
  </div>
);

const PhoneResults = () => (
  <div className="ps ps-results">
    <div className="ps-bar"><span>9:41</span><span>●●●</span></div>
    <div className="ps-greet">Hey Maya,</div>
    <div className="ps-status">
      <span className="ps-status-pill safe">● SAFE</span>
      <span className="ps-status-sub">through Apr 30</span>
    </div>
    <div className="ps-headline">
      <span className="ps-amount">$1,184</span>
      <span className="ps-amount-cap">leeway</span>
    </div>
    <div className="ps-track">
      <div className="ps-track-fill" style={{width: "62%"}}/>
    </div>
    <div className="ps-row"><span>Apr 26 · today</span><span>Apr 30 · payday</span></div>
    <div className="ps-cards">
      <div className="ps-card"><span className="ps-card-cap">Next bill</span><span className="ps-card-val">Rent · $1,420</span></div>
      <div className="ps-card"><span className="ps-card-cap">Daily pace</span><span className="ps-card-val">$48 / day</span></div>
    </div>
    <div className="ps-section-cap">UPCOMING</div>
    <div className="ps-tx">
      <div className="ps-tx-row"><span>Apr 27</span><span>Spotify</span><span className="ps-tx-amt">−$11.99</span></div>
      <div className="ps-tx-row"><span>Apr 29</span><span>Verizon</span><span className="ps-tx-amt">−$78.00</span></div>
      <div className="ps-tx-row ps-tx-pos"><span>Apr 30</span><span>Paycheck</span><span className="ps-tx-amt">+$3,240</span></div>
    </div>
  </div>
);

const PhoneOnboarding = () => (
  <div className="ps ps-onboarding">
    <div className="ps-bar"><span>9:41</span><span>●●●</span></div>
    <div className="ps-back">←</div>
    <div className="ps-step-cap">STEP 2 OF 3</div>
    <h4 className="ps-step-h">Add your fixed bills.</h4>
    <p className="ps-step-p">We'll detect the rest from your transactions.</p>
    <div className="ps-bills">
      <div className="ps-bill"><span className="ps-bill-name">Rent</span><span className="ps-bill-amt">$1,420</span></div>
      <div className="ps-bill"><span className="ps-bill-name">Spotify</span><span className="ps-bill-amt">$11.99</span></div>
      <div className="ps-bill"><span className="ps-bill-name">Verizon</span><span className="ps-bill-amt">$78.00</span></div>
      <div className="ps-bill"><span className="ps-bill-name">ClassPass</span><span className="ps-bill-amt">$49.00</span></div>
      <div className="ps-bill"><span className="ps-bill-name">Renters insurance</span><span className="ps-bill-amt">$22.50</span></div>
      <div className="ps-bill ps-bill-add">+ Add another</div>
    </div>
    <div className="ps-detected">
      <span className="ps-detected-dot"/>
      <span>liway found 3 more recurring charges. <span className="ps-detected-link">Review →</span></span>
    </div>
    <div className="ps-cta">Continue →</div>
  </div>
);

const PhoneEdit = () => (
  <div className="ps ps-edit">
    <div className="ps-bar"><span>9:41</span><span>●●●</span></div>
    <div className="ps-step-cap">WHAT-IF SIMULATOR</div>
    <h4 className="ps-step-h">If I skip eating out…</h4>
    <div className="ps-slider">
      <div className="ps-slider-cap"><span>Restaurants</span><span>$120 → $40</span></div>
      <div className="ps-slider-track"><div className="ps-slider-fill" style={{width: "33%"}}/><div className="ps-slider-thumb" style={{left: "33%"}}/></div>
    </div>
    <div className="ps-slider">
      <div className="ps-slider-cap"><span>Rideshare</span><span>$60 → $30</span></div>
      <div className="ps-slider-track"><div className="ps-slider-fill" style={{width: "50%"}}/><div className="ps-slider-thumb" style={{left: "50%"}}/></div>
    </div>
    <div className="ps-slider">
      <div className="ps-slider-cap"><span>Coffee runs</span><span>$54 → $20</span></div>
      <div className="ps-slider-track"><div className="ps-slider-fill" style={{width: "37%"}}/><div className="ps-slider-thumb" style={{left: "37%"}}/></div>
    </div>
    <div className="ps-spark">
      <svg viewBox="0 0 200 40" preserveAspectRatio="none">
        <path d="M0,30 L40,28 L80,22 L120,18 L160,12 L200,8" stroke="var(--euc-500)" strokeWidth="2" fill="none"/>
        <path d="M0,30 L40,28 L80,22 L120,18 L160,12 L200,8 L200,40 L0,40 Z" fill="var(--euc-100)" opacity="0.6"/>
      </svg>
    </div>
    <div className="ps-result">
      <div className="ps-result-cap">PROJECTED LEEWAY</div>
      <div className="ps-result-val">$1,294 <span className="ps-delta">+$110</span></div>
      <div className="ps-result-sub">Stays SAFE through May 14</div>
    </div>
  </div>
);

const Showcase = () => (
  <section className="section section-showcase">
    <div className="container">
      <header className="section-head">
        <p className="eyebrow">In the app</p>
        <h2 className="section-title">Am I safe through this month?</h2>
        <p className="section-intro">The most important money question, answered the second you open the app. No tagging, no categories, no spreadsheet. Just your real balance, real bills, and real next paycheck.</p>
      </header>

      <div className="phone-grid phone-grid-2">
        <PhoneFrame label="Results" image><img src="assets/screen-results.png" alt="liway home screen showing $792.42 available until May 8 paycheck, breakdown, and what-if controls" loading="lazy"/></PhoneFrame>
        <PhoneFrame label="Onboarding" accent image><img src="assets/screen-onboarding.png" alt="liway paycheck check screen showing detected balance, next paycheck, and detected recurring bills" loading="lazy"/></PhoneFrame>
      </div>
    </div>
  </section>
);

/* ========================== TESTIMONIAL ========================== */
const Testimonial = () => (
  <section className="section testimonial-section">
    <div className="container testimonial-inner">
      <svg className="quote-mark" width="56" height="44" viewBox="0 0 56 44" fill="none" aria-hidden="true">
        <path d="M0 44V24C0 11 8 2 22 0v8c-7 2-12 8-12 16h12v20H0zm32 0V24C32 11 40 2 54 0v8c-7 2-12 8-12 16h12v20H32z" fill="var(--euc-300)"/>
      </svg>
      <blockquote className="testimonial-quote">
        I stopped checking my bank app every two days. liway tells me what I need to know <em>before</em> I overthink it.
      </blockquote>
      <div className="testimonial-byline">
        <div className="testimonial-avatar">M</div>
        <div>
          <div className="testimonial-name">Maya R.</div>
          <div className="testimonial-role">Beta user · two banks, one paycheck · since March 2026</div>
        </div>
      </div>
    </div>
  </section>
);

/* ========================== FINAL CTA ========================== */
const FinalCTA = () => (
  <section className="cta-block" id="download">
    <div className="cta-bg" aria-hidden="true">
      {/* the L mark, dramatic, oversized, behind the type */}
      <svg viewBox="0 0 1024 1024" className="cta-bg-mark" fill="none" stroke="currentColor" strokeWidth="55">
        <circle cx="361" cy="292.43" r="69.76"/>
        <circle cx="361" cy="731.57" r="69.76"/>
        <circle cx="663" cy="731.57" r="69.76"/>
      </svg>
    </div>
    <div className="container cta-inner">
      <p className="eyebrow eyebrow-on-dark">Free to start · No credit card</p>
      <h2 className="cta-title">
        Stop guessing.
        <br/>
        <em className="serif-newsreader">Know your headroom.</em>
      </h2>
      <p className="cta-sub">Connect a bank in two minutes, or try with sample data first. Either way, you'll see your number before your next coffee.</p>
      <div className="cta-actions">
        <a href="/beta/" className="store-badge store-badge-lg" aria-label="Join the beta — App Store coming soon">
          <img src="assets/appstore-badge.png" alt="Download on the App Store"/>
        </a>
        <a href="/beta/" className="store-badge store-badge-lg" aria-label="Join the beta — Google Play coming soon">
          <img src="assets/googleplay-badge.png" alt="Get it on Google Play"/>
        </a>
      </div>
      <p className="cta-meta">Or open <a href="https://my.liway.app" className="cta-link">liway on the web →</a></p>
    </div>
  </section>
);

/* ========================== FOOTER ========================== */
const Footer = () => (
  <footer className="footer">
    <div className="container">
      <div className="footer-grid">
        <div className="footer-brand">
          <div className="footer-lockup">
            <LiwayMark size={28} color="var(--slate-950)"/>
            <Wordmark height={22} color="var(--slate-950)"/>
          </div>
          <p>Cashflow leeway, paycheck to paycheck.</p>
        </div>
        <div>
          <h4>Product</h4>
          <ul>
            <li><a href="#how">How it works</a></li>
            <li><a href="#why">Why liway</a></li>
            <li><a href="https://my.liway.app">Web app</a></li>
            <li><a href="/beta/">Beta program</a></li>
          </ul>
        </div>
        <div>
          <h4>Connect</h4>
          <ul>
            <li><a href="mailto:hello@liway.app">Contact</a></li>
          </ul>
        </div>
        <div>
          <h4>Legal</h4>
          <ul>
            <li><a href="/privacy.html">Privacy</a></li>
            <li><a href="/terms.html">Terms</a></li>
          </ul>
        </div>
      </div>
      <div className="footer-bottom">
        <span>© 2026 liway, LLC</span>
        <span className="footer-tag">Made for the days between paydays.</span>
      </div>
    </div>
  </footer>
);

/* ========================== SCROLL PROGRESS BAR ========================== */
const ScrollProgress = () => {
  const ref = useRef(null);
  useEffect(() => {
    const update = () => {
      const doc = document.documentElement;
      const max = doc.scrollHeight - doc.clientHeight;
      const pct = max > 0 ? (doc.scrollTop / max) * 100 : 0;
      if (ref.current) ref.current.style.width = pct + "%";
    };
    update();
    window.addEventListener("scroll", update, { passive: true });
    window.addEventListener("resize", update);
    return () => {
      window.removeEventListener("scroll", update);
      window.removeEventListener("resize", update);
    };
  }, []);
  return <div className="scroll-progress" aria-hidden="true"><div ref={ref}/></div>;
};

/* ========================== SECTION REVEAL ========================== */
// Adds .is-visible to any .reveal element when it enters the viewport.
// Respects prefers-reduced-motion (CSS handles the visual fallback).
const useRevealOnScroll = () => {
  useEffect(() => {
    if (typeof IntersectionObserver === "undefined") return;
    const targets = document.querySelectorAll(".reveal");
    if (!targets.length) return;
    const observer = new IntersectionObserver(
      (entries) => {
        entries.forEach((e) => {
          if (e.isIntersecting) {
            e.target.classList.add("is-visible");
            observer.unobserve(e.target);
          }
        });
      },
      { threshold: 0.12, rootMargin: "0px 0px -8% 0px" }
    );
    targets.forEach((t) => observer.observe(t));
    return () => observer.disconnect();
  }, []);
};

/* ========================== APP ========================== */
const App = () => {
  useRevealOnScroll();
  return (
    <>
      <ScrollProgress/>
      <Nav/>
      <main id="main">
        <Hero/>
        <div className="reveal"><Showcase/></div>
        <div className="reveal"><WhatIsLiway/></div>
        <div className="reveal"><StatCallout/></div>
        <div className="reveal"><HowItWorks/></div>
        <div className="reveal"><Testimonial/></div>
        <div className="reveal"><FinalCTA/></div>
      </main>
      <Footer/>
    </>
  );
};

ReactDOM.createRoot(document.getElementById("root")).render(<App/>);
