// ============================================
// RACEFORM — Single-file React app
// Tech / startup aesthetic
// ============================================

const { useState, useEffect, useRef } = React;

const Logo = ({ size = 20, color = "var(--ink)" }) => (
  <div style={{ display: "flex", alignItems: "center", gap: 8, fontFamily: "var(--font-display)", fontWeight: 600, fontSize: size, letterSpacing: "-0.03em", color }}>
    <svg width={size * 1.1} height={size * 1.1} viewBox="0 0 24 24" fill="none">
      <rect x="2" y="2" width="20" height="20" rx="6" fill={color}/>
      <path d="M6 16 L10 9 L13 13 L18 6" stroke="var(--accent)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" fill="none"/>
      <circle cx="18" cy="6" r="1.6" fill="var(--accent)"/>
    </svg>
    <span>Raceform</span>
  </div>
);

const useReveal = () => {
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const io = new IntersectionObserver(es => es.forEach(e => {
      if (e.isIntersecting) { e.target.classList.add("in"); io.unobserve(e.target); }
    }), { threshold: 0.1 });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return ref;
};

// ── NAV ─────────────────────────────────
const Nav = () => {
  const [scrolled, setScrolled] = useState(false);
  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 8);
    window.addEventListener("scroll", onScroll);
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  return (
    <nav className={"topnav" + (scrolled ? " scrolled" : "")}>
      <div className="container nav-row">
        <a href="#top" style={{ textDecoration: "none" }}><Logo/></a>
        <div className="nav-links">
          <a href="#features">Product</a>
          <a href="#how">How it works</a>
          <a href="#plan">Sample week</a>
          <a href="#stories">Athletes</a>
          <a href="#cta">Pricing</a>
        </div>
        <div style={{ display: "flex", gap: 8 }}>
          <a href="#" className="btn btn-ghost" style={{ height: 34, fontSize: 14, padding: "8px 14px" }}>Sign in</a>
          <a href="#cta" className="btn btn-primary" style={{ height: 34, fontSize: 14, padding: "8px 14px" }}>Start free</a>
        </div>
      </div>
    </nav>
  );
};

// ── HERO ────────────────────────────────
const Hero = () => (
  <section id="top" style={{ paddingTop: 140, paddingBottom: 80, position: "relative", overflow: "hidden" }}>
    <div className="accent-glow" style={{ top: -200, right: -200 }}/>
    <div className="container" style={{ position: "relative" }}>
      <div style={{ textAlign: "center", maxWidth: 920, margin: "0 auto" }}>
        <a href="#" style={{ display: "inline-flex", textDecoration: "none", marginBottom: 28 }}>
          <span style={{ display: "inline-flex", alignItems: "center", gap: 10, padding: "5px 14px 5px 6px", borderRadius: 999, background: "var(--surface)", border: "1px solid var(--line)", fontSize: 13, color: "var(--ink-2)" }}>
            <span style={{ padding: "2px 8px", borderRadius: 999, background: "var(--accent-soft)", color: "var(--accent-2)", fontSize: 11, fontWeight: 600 }}>NEW</span>
            Garmin live tracking is here
            <span style={{ color: "var(--ink-4)" }}>→</span>
          </span>
        </a>
        <h1 className="display" style={{ fontSize: "clamp(44px, 7vw, 88px)", marginBottom: 24 }}>
          The training app<br/>that fits your life.
        </h1>
        <p style={{ fontSize: 19, lineHeight: 1.5, color: "var(--ink-3)", maxWidth: 600, margin: "0 auto 36px" }}>
          Connect your watch. Tell us your week. Get an adaptive plan that learns from your data, your feedback, and the days you'd rather skip.
        </p>
        <div style={{ display: "flex", gap: 10, justifyContent: "center", flexWrap: "wrap", marginBottom: 14 }}>
          <a href="#cta" className="btn btn-accent btn-lg">
            Start free for 14 days
            <span>→</span>
          </a>
          <a href="#how" className="btn btn-ghost btn-lg">See how it works</a>
        </div>
        <div className="mono" style={{ fontSize: 12, color: "var(--ink-4)", marginBottom: 64 }}>
          No credit card · Cancel anytime
        </div>
      </div>
      <ProductHero/>
    </div>
  </section>
);

const ProductHero = () => {
  const ref = useReveal();
  return (
    <div ref={ref} className="reveal" style={{ maxWidth: 1080, margin: "0 auto", padding: 10, background: "var(--surface)", border: "1px solid var(--line)", borderRadius: 20, boxShadow: "0 30px 80px -30px rgba(0,0,0,0.18)" }}>
      <div style={{ display: "flex", alignItems: "center", gap: 8, padding: "6px 8px 12px" }}>
        <div style={{ display: "flex", gap: 6 }}>
          {["#FF5F57","#FEBC2E","#28C840"].map(c => <div key={c} style={{ width: 10, height: 10, borderRadius: "50%", background: c }}/>)}
        </div>
        <div className="mono" style={{ flex: 1, marginLeft: 12, height: 24, borderRadius: 6, background: "var(--bg-2)", fontSize: 11, color: "var(--ink-4)", display: "flex", alignItems: "center", justifyContent: "center" }}>
          app.raceform.app/today
        </div>
      </div>
      <div className="prod-hero" style={{ background: "var(--bg)", borderRadius: 14, padding: 22, display: "grid", gridTemplateColumns: "220px 1fr", gap: 20 }}>
        <aside style={{ display: "flex", flexDirection: "column", gap: 4 }}>
          <Logo size={17}/>
          <div style={{ height: 16 }}/>
          {[
            { l: "Today", i: "○", a: true },
            { l: "This week", i: "▦" },
            { l: "Insights", i: "↗" },
            { l: "Race plan", i: "⚐" },
            { l: "Coach", i: "✦" },
          ].map(it => (
            <div key={it.l} style={{ display: "flex", alignItems: "center", gap: 10, padding: "8px 12px", fontSize: 13, fontWeight: 500, color: it.a ? "var(--ink)" : "var(--ink-3)", background: it.a ? "var(--surface)" : "transparent", border: it.a ? "1px solid var(--line)" : "1px solid transparent", borderRadius: 8 }}>
              <span className="mono" style={{ width: 14, fontSize: 12 }}>{it.i}</span>
              {it.l}
            </div>
          ))}
        </aside>
        <main style={{ display: "flex", flexDirection: "column", gap: 12 }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start" }}>
            <div>
              <div className="eyebrow">TUE · APR 28</div>
              <div className="display" style={{ fontSize: 26, marginTop: 6 }}>Good morning, Anders.</div>
            </div>
            <span className="chip"><span className="chip-dot"/>Apple Watch synced</span>
          </div>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 10 }}>
            {[
              { l: "Readiness", v: "87", t: "+12 vs avg", up: true },
              { l: "Resting HR", v: "52", t: "−2 bpm", up: true },
              { l: "Sleep", v: "7h 24m", t: "Quality 84%" },
              { l: "Load (7d)", v: "412", t: "Productive" },
            ].map(s => (
              <div key={s.l} className="card" style={{ padding: 12 }}>
                <div className="eyebrow" style={{ fontSize: 10 }}>{s.l.toUpperCase()}</div>
                <div className="display" style={{ fontSize: 22, marginTop: 6 }}>{s.v}</div>
                <div className="mono" style={{ fontSize: 11, color: s.up ? "var(--green)" : "var(--ink-4)", marginTop: 4 }}>
                  {s.up && "↑ "}{s.t}
                </div>
              </div>
            ))}
          </div>
          <div className="card" style={{ padding: 18, background: "var(--ink)", color: "white", border: "none", position: "relative", overflow: "hidden" }}>
            <div style={{ position: "absolute", top: 0, right: 0, width: 220, height: 220, background: "radial-gradient(circle at top right, rgba(255,79,23,0.25), transparent 60%)" }}/>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start", position: "relative" }}>
              <div>
                <div className="mono" style={{ fontSize: 11, color: "rgba(255,255,255,0.5)" }}>TODAY · 52 MIN</div>
                <div className="display" style={{ fontSize: 24, marginTop: 6, color: "white" }}>Threshold intervals</div>
                <div style={{ fontSize: 13, color: "rgba(255,255,255,0.7)", marginTop: 4 }}>5 × 4min @ 4:30/km · 2min recovery</div>
              </div>
              <button className="btn btn-accent" style={{ height: 34 }}>Start</button>
            </div>
            <div style={{ marginTop: 18, display: "flex", gap: 5, height: 30 }}>
              {["WU","1","R","2","R","3","R","4","R","5","CD"].map((s, i) => (
                <div key={i} className="mono" style={{
                  flex: ["WU","CD"].includes(s) ? 2 : (s === "R" ? 0.6 : 1.4),
                  background: s === "R" ? "rgba(255,255,255,0.08)" : (["WU","CD"].includes(s) ? "rgba(255,255,255,0.18)" : "var(--accent)"),
                  borderRadius: 4,
                  display: "flex", alignItems: "center", justifyContent: "center",
                  fontSize: 10,
                  color: s === "R" ? "rgba(255,255,255,0.5)" : "white",
                }}>{s}</div>
              ))}
            </div>
          </div>
        </main>
      </div>
    </div>
  );
};

// ── MARQUEE ─────────────────────────────
const Marquee = () => {
  const items = ["Apple Watch","Apple Fitness","Apple Health","Garmin","Polar"];
  return (
    <section style={{ padding: "60px 0", borderTop: "1px solid var(--line)", borderBottom: "1px solid var(--line)", background: "var(--surface)" }}>
      <div className="container" style={{ marginBottom: 32 }}>
        <p className="eyebrow" style={{ textAlign: "center" }}>WORKS WITH EVERY DEVICE YOU ALREADY OWN</p>
      </div>
      <div style={{ overflow: "hidden", maskImage: "linear-gradient(to right, transparent, black 10%, black 90%, transparent)", WebkitMaskImage: "linear-gradient(to right, transparent, black 10%, black 90%, transparent)" }}>
        <div className="marquee-track">
          {[...items, ...items].map((w, i) => (
            <span key={i} style={{ fontFamily: "var(--font-display)", fontWeight: 500, fontSize: 22, color: "var(--ink-3)", letterSpacing: "-0.02em", whiteSpace: "nowrap", display: "inline-flex", alignItems: "center", gap: 56 }}>
              {w}<span style={{ width: 4, height: 4, borderRadius: "50%", background: "var(--ink-4)" }}/>
            </span>
          ))}
        </div>
      </div>
    </section>
  );
};

// ── HOW IT WORKS ────────────────────────
const HowItWorks = () => {
  const steps = [
    { n: "01", t: "Connect your devices", b: "Apple Watch, Garmin, Whoop, Coros — link in one tap. We pull six months of history and start learning what good looks like for you." },
    { n: "02", t: "Tell us your week", b: "Travel Tuesday? Big lift Thursday? Tell Raceform what life looks like — your plan reshapes around it, not the other way around." },
    { n: "03", t: "Train, recover, race", b: "A session that fits today. A weekly recap that makes you smarter. A race-day predictor that sharpens with every run." },
  ];
  return (
    <section id="how" className="section">
      <div className="container">
        <div style={{ maxWidth: 720, marginBottom: 56 }}>
          <span className="eyebrow">— How it works</span>
          <h2 className="display" style={{ fontSize: "clamp(36px, 5vw, 56px)", marginTop: 14 }}>
            Three steps to a plan<br/>that actually fits.
          </h2>
        </div>
        <div className="how-grid" style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 16 }}>
          {steps.map((s, i) => {
            const ref = useReveal();
            return (
              <div key={i} ref={ref} className="reveal card" style={{ padding: 28, transitionDelay: `${i * 0.08}s` }}>
                <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 36 }}>
                  <span className="mono" style={{ fontSize: 12, color: "var(--ink-4)" }}>{s.n}</span>
                  <div style={{ flex: 1, height: 1, background: "var(--line)" }}/>
                </div>
                <h3 className="display" style={{ fontSize: 22, marginBottom: 10 }}>{s.t}</h3>
                <p style={{ fontSize: 15, color: "var(--ink-3)", lineHeight: 1.55 }}>{s.b}</p>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
};

// ── FEATURES ────────────────────────────
const Features = () => (
  <section id="features" className="section" style={{ background: "var(--surface)", borderTop: "1px solid var(--line)", borderBottom: "1px solid var(--line)" }}>
    <div className="container">
      <div style={{ maxWidth: 720, marginBottom: 56 }}>
        <span className="eyebrow">— Product</span>
        <h2 className="display" style={{ fontSize: "clamp(36px, 5vw, 56px)", marginTop: 14 }}>
          Built for the messy<br/>middle of your week.
        </h2>
      </div>
      <div className="features-grid" style={{ display: "grid", gridTemplateColumns: "2fr 1fr 1fr", gridAutoRows: "minmax(220px, auto)", gap: 14 }}>
        <FCard wide tag="ADAPTIVE PLAN" t="A plan that bends — but won't break." b="Skip a session, crush a tempo, travel for work. Raceform rebalances volume, intensity, and recovery the moment your week shifts." v={<AdaptiveVis/>}/>
        <FCard tag="READINESS" t="Daily readiness, decoded." b="HRV, sleep, soreness — one honest number." v={<ReadinessRing/>}/>
        <FCard tag="HYBRID" t="Lift days that respect run days." b="Squat day shouldn't sit next to long run day. We get it." tone="dark"/>
        <FCard tag="PREDICTOR" t="Race-day time, calibrated weekly." b="A goal time that sharpens as fitness arrives." v={<Predictor/>}/>
        <FCard tag="WEEKLY REPLAY" t="Sunday recaps that hit different." b="Five minutes. Wins, weak spots, what's next." tone="accent"/>
      </div>
    </div>
  </section>
);

const FCard = ({ wide, tag, t, b, v, tone = "paper" }) => {
  const ref = useReveal();
  const styles = {
    paper: { background: "var(--bg)", color: "var(--ink)", border: "1px solid var(--line)" },
    dark: { background: "var(--ink)", color: "white", border: "1px solid var(--ink)" },
    accent: { background: "var(--accent)", color: "white", border: "1px solid var(--accent-2)" },
  }[tone];
  return (
    <div ref={ref} className="reveal" style={{ ...styles, gridRow: wide ? "span 2" : undefined, padding: 24, borderRadius: 16, display: "flex", flexDirection: "column", gap: 14 }}>
      <span className="eyebrow" style={{ color: tone !== "paper" ? "rgba(255,255,255,0.7)" : undefined }}>{tag}</span>
      <h3 className="display" style={{ fontSize: wide ? 30 : 20 }}>{t}</h3>
      <p style={{ fontSize: wide ? 16 : 14, color: tone === "paper" ? "var(--ink-3)" : "rgba(255,255,255,0.75)", lineHeight: 1.55 }}>{b}</p>
      {v && <div style={{ marginTop: "auto" }}>{v}</div>}
    </div>
  );
};

const AdaptiveVis = () => (
  <div style={{ background: "var(--surface)", borderRadius: 10, padding: 16, border: "1px solid var(--line)" }}>
    <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 10 }}>
      <span className="eyebrow" style={{ fontSize: 10 }}>WEEK 6 · ADAPTED</span>
      <span className="mono" style={{ fontSize: 10, color: "var(--green)" }}>● live</span>
    </div>
    <div style={{ display: "grid", gridTemplateColumns: "repeat(7, 1fr)", gap: 4 }}>
      {[{h:30,c:"var(--bg-3)"},{h:70,c:"var(--accent)"},{h:50,c:"var(--ink)"},{h:18,c:"var(--bg-3)"},{h:60,c:"var(--accent)"},{h:95,c:"var(--ink)"},{h:8,c:"var(--bg-3)"}].map((d, i) => (
        <div key={i} style={{ width: "100%", height: 80, background: "var(--bg-2)", borderRadius: 4, position: "relative", overflow: "hidden" }}>
          <div style={{ position: "absolute", bottom: 0, left: 0, right: 0, height: `${d.h}%`, background: d.c }}/>
        </div>
      ))}
    </div>
    <div className="mono" style={{ marginTop: 12, fontSize: 11, color: "var(--ink-3)" }}>↳ Thursday flight detected — long run moved to Saturday</div>
  </div>
);

const ReadinessRing = () => (
  <div style={{ display: "flex", alignItems: "center", gap: 14, padding: 12, background: "var(--surface)", borderRadius: 10, border: "1px solid var(--line)" }}>
    <svg width="56" height="56" viewBox="0 0 56 56">
      <circle cx="28" cy="28" r="22" stroke="var(--line)" strokeWidth="5" fill="none"/>
      <circle cx="28" cy="28" r="22" stroke="var(--accent)" strokeWidth="5" fill="none" strokeDasharray={`${0.82*138.2} 138.2`} strokeLinecap="round" transform="rotate(-90 28 28)"/>
      <text x="28" y="33" textAnchor="middle" fontFamily="var(--font-display)" fontSize="16" fontWeight="600" fill="var(--ink)">82</text>
    </svg>
    <div>
      <div style={{ fontSize: 13, fontWeight: 500 }}>Push it just a bit</div>
      <div style={{ fontSize: 11, color: "var(--ink-3)" }}>HRV up · sleep solid</div>
    </div>
  </div>
);

const Predictor = () => (
  <div style={{ padding: 14, background: "var(--surface)", borderRadius: 10, border: "1px solid var(--line)" }}>
    <div className="eyebrow" style={{ fontSize: 10 }}>MARATHON</div>
    <div className="display" style={{ fontSize: 28, marginTop: 4 }}>3:24<span style={{ color: "var(--ink-4)", fontSize: 16 }}>:18</span></div>
    <div className="mono" style={{ fontSize: 11, color: "var(--green)", marginTop: 2 }}>↓ 4:42 since week 1</div>
  </div>
);

// ── SAMPLE WEEK ─────────────────────────
const SampleWeek = () => {
  const [active, setActive] = useState(1);
  const week = [
    { day: "MON", date: "27", type: "Easy run", time: "32 min", detail: "Z2 · keep it boring", c: "muted" },
    { day: "TUE", date: "28", type: "Threshold", time: "52 min", detail: "5 × 4min @ 4:30/km", c: "accent", today: true },
    { day: "WED", date: "29", type: "Strength", time: "48 min", detail: "Squat · pull · accessories", c: "ink" },
    { day: "THU", date: "30", type: "Recovery", time: "20 min", detail: "Mobility + walk", c: "muted", note: "Lower readiness — kept light." },
    { day: "FRI", date: "01", type: "Hill repeats", time: "44 min", detail: "8 × 60s @ 5k effort", c: "accent" },
    { day: "SAT", date: "02", type: "Long run", time: "1h 38m", detail: "20km · last 5 @ MP", c: "ink" },
    { day: "SUN", date: "03", type: "Rest", time: "—", detail: "Earned. Take it.", c: "muted" },
  ];
  const colors = { accent: { bg: "var(--accent)", fg: "white" }, ink: { bg: "var(--ink)", fg: "white" }, muted: { bg: "var(--bg-2)", fg: "var(--ink-3)" } };
  const a = week[active];

  return (
    <section id="plan" className="section">
      <div className="container">
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", marginBottom: 40, gap: 24, flexWrap: "wrap" }}>
          <div style={{ maxWidth: 600 }}>
            <span className="eyebrow">— Sample week</span>
            <h2 className="display" style={{ fontSize: "clamp(36px, 5vw, 56px)", marginTop: 14 }}>
              A real week,<br/>planned for you.
            </h2>
          </div>
          <span className="chip">Hybrid · Marathon · Wk 6/14</span>
        </div>

        <div className="week-strip" style={{ display: "grid", gridTemplateColumns: "repeat(7, 1fr)", gap: 8, marginBottom: 16 }}>
          {week.map((d, i) => {
            const isActive = i === active;
            const c = colors[d.c];
            return (
              <button key={i} onClick={() => setActive(i)} style={{
                background: isActive ? c.bg : "var(--surface)",
                color: isActive ? c.fg : "var(--ink)",
                border: isActive ? "1px solid transparent" : "1px solid var(--line)",
                borderRadius: 10, padding: "14px 12px", cursor: "pointer", textAlign: "left",
                transition: "all .15s ease", position: "relative", fontFamily: "inherit",
              }}>
                {d.today && <span style={{ position: "absolute", top: 8, right: 8, width: 6, height: 6, borderRadius: "50%", background: isActive ? "white" : "var(--accent)" }}/>}
                <div className="mono" style={{ fontSize: 10, opacity: 0.7 }}>{d.day}</div>
                <div className="display" style={{ fontSize: 18, marginTop: 2 }}>{d.date}</div>
                <div style={{ fontSize: 12, fontWeight: 500, marginTop: 8 }}>{d.type}</div>
                <div className="mono" style={{ fontSize: 11, opacity: 0.7, marginTop: 1 }}>{d.time}</div>
              </button>
            );
          })}
        </div>

        <div className="card week-detail" style={{ padding: 28, display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: 28 }}>
          <div>
            <div style={{ display: "flex", gap: 10, alignItems: "center", marginBottom: 16 }}>
              <span className="eyebrow">{a.day} · APR {a.date}</span>
              {a.note && <span className="mono" style={{ padding: "3px 10px", fontSize: 11, borderRadius: 999, background: "var(--accent-soft)", color: "var(--accent-2)", fontWeight: 600 }}>ADAPTED</span>}
            </div>
            <h3 className="display" style={{ fontSize: 44, marginBottom: 6 }}>{a.type}</h3>
            <p style={{ fontSize: 18, color: "var(--ink-3)", marginBottom: 20 }}>{a.detail}</p>
            {a.note && (
              <div style={{ padding: "12px 14px", background: "var(--accent-soft)", borderRadius: 10, border: "1px solid #FFD9C8", marginBottom: 20, fontSize: 14 }}>
                <strong style={{ color: "var(--accent-2)" }}>Today —</strong> {a.note} Tomorrow we pick volume back up.
              </div>
            )}
            <div style={{ display: "flex", gap: 24, paddingTop: 20, borderTop: "1px solid var(--line)" }}>
              {[["Duration", a.time], ["Type", a.type], ["RPE", a.c === "accent" ? "8/10" : a.c === "ink" ? "7/10" : "4/10"]].map(([l, v]) => (
                <div key={l}>
                  <div className="eyebrow" style={{ fontSize: 10 }}>{l}</div>
                  <div className="display" style={{ fontSize: 22, marginTop: 4 }}>{v}</div>
                </div>
              ))}
            </div>
          </div>
          <div style={{ background: "var(--bg)", borderRadius: 12, padding: 18, border: "1px solid var(--line)" }}>
            <div className="eyebrow">SESSION PACING</div>
            <div style={{ marginTop: 14, display: "flex", flexDirection: "column", gap: 10 }}>
              {[
                { l: "Warm-up", p: "10min · 6:10/km", w: 30 },
                { l: "Work × 5", p: "4min · 4:30/km", w: 95, hot: true },
                { l: "Recover × 4", p: "2min · 6:00/km", w: 22 },
                { l: "Cool-down", p: "10min · 6:30/km", w: 30 },
              ].map((p, i) => (
                <div key={i}>
                  <div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, marginBottom: 4 }}>
                    <span style={{ fontWeight: 500 }}>{p.l}</span>
                    <span className="mono" style={{ color: "var(--ink-4)", fontSize: 11 }}>{p.p}</span>
                  </div>
                  <div style={{ height: 8, borderRadius: 4, background: p.hot ? "var(--accent)" : "var(--bg-3)", width: `${p.w}%` }}/>
                </div>
              ))}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
};

// ── PHONE DEMO ──────────────────────────
const PhoneDemo = () => {
  const [screen, setScreen] = useState("home");
  return (
    <section className="section" style={{ background: "var(--ink)", color: "white", position: "relative", overflow: "hidden" }}>
      <div className="container">
        <div className="demo-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 60, alignItems: "center" }}>
          <div>
            <span className="eyebrow" style={{ color: "var(--accent)" }}>— Try it</span>
            <h2 className="display" style={{ fontSize: "clamp(36px, 5vw, 56px)", marginTop: 14, marginBottom: 20, color: "white" }}>
              Tap around.<br/>It's the real product.
            </h2>
            <p style={{ fontSize: 17, color: "rgba(255,255,255,0.65)", lineHeight: 1.55, marginBottom: 28, maxWidth: 460 }}>
              Same flows our beta athletes wake up to every morning.
            </p>
            <div style={{ display: "flex", flexDirection: "column", gap: 8, maxWidth: 360 }}>
              {[
                { id: "home", l: "Today" },
                { id: "plan", l: "Choose your sport" },
                { id: "workout", l: "Live workout" },
              ].map((s, i) => (
                <button key={s.id} onClick={() => setScreen(s.id)} style={{
                  background: screen === s.id ? "var(--accent)" : "rgba(255,255,255,0.04)",
                  color: "white",
                  border: screen === s.id ? "1px solid var(--accent-2)" : "1px solid rgba(255,255,255,0.08)",
                  borderRadius: 10, padding: "12px 16px", cursor: "pointer", textAlign: "left",
                  display: "flex", justifyContent: "space-between", alignItems: "center",
                  fontFamily: "var(--font-display)", fontWeight: 500, fontSize: 14,
                }}>
                  <span style={{ display: "flex", alignItems: "center", gap: 12 }}>
                    <span className="mono" style={{ fontSize: 11, opacity: 0.6 }}>0{i+1}</span>
                    {s.l}
                  </span>
                  <span>→</span>
                </button>
              ))}
            </div>
          </div>
          <div style={{ display: "flex", justifyContent: "center" }}>
            <div className="phone-frame">
              <div className="phone-notch"/>
              <div className="phone-screen">
                {screen === "home" && (
                  <img
                    src="assets/ai-training-plan.png"
                    alt="Raceform AI training plan screen"
                    style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }}
                  />
                )}
                {screen === "plan" && (
                  <img
                    src="assets/your-sport.png"
                    alt="Raceform choose your sport onboarding screen"
                    style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }}
                  />
                )}
                {screen === "workout" && (
                  <div>
                    <div className="mono" style={{ padding: "16px 20px 0", display: "flex", justifyContent: "space-between", fontSize: 11, color: "var(--ink)" }}>
                      <span>9:41</span><span style={{ color: "var(--ink-3)" }}>● ▮</span>
                    </div>
                    <div style={{ padding: "20px 18px" }}>
                      <LiveWorkout/>
                    </div>
                  </div>
                )}
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
};

const LiveWorkout = () => {
  const [running, setRunning] = useState(false);
  const [t, setT] = useState(0);
  useEffect(() => {
    if (!running) return;
    const id = setInterval(() => setT(x => x + 1), 1000);
    return () => clearInterval(id);
  }, [running]);
  const m = String(Math.floor(t / 60)).padStart(2, "0");
  const s = String(t % 60).padStart(2, "0");
  return (
    <div>
      <div className="eyebrow" style={{ fontSize: 10 }}>INTERVAL 2 OF 5</div>
      <div className="display" style={{ fontSize: 52, lineHeight: 1, marginTop: 10 }}>{m}:{s}</div>
      <div style={{ fontSize: 14, color: "var(--ink-3)" }}>4:30/km · stay smooth</div>
      <div style={{ marginTop: 16, padding: 14, background: "var(--bg-2)", borderRadius: 12, display: "flex", justifyContent: "space-between" }}>
        {[["HR", "168"], ["PACE", "4:28"], ["DIST", "2.4"]].map(([l, v]) => (
          <div key={l}>
            <div className="mono" style={{ fontSize: 9, color: "var(--ink-3)" }}>{l}</div>
            <div className="display" style={{ fontSize: 18, marginTop: 2 }}>{v}</div>
          </div>
        ))}
      </div>
      <button onClick={() => setRunning(r => !r)} style={{
        marginTop: 20, width: "100%", padding: 14,
        background: running ? "var(--bg-2)" : "var(--accent)",
        color: running ? "var(--ink)" : "white",
        border: "none", borderRadius: 10, fontSize: 14, fontWeight: 600, cursor: "pointer",
        fontFamily: "inherit",
      }}>
        {running ? "Pause" : "Start workout"}
      </button>
    </div>
  );
};

// ── TESTIMONIALS ────────────────────────
const Testimonials = () => {
  const data = [
    { q: "I went from spreadsheet hell to actually showing up. Hit a 7-min marathon PR while still squatting twice a week.", n: "Sara M.", r: "Hyrox · Marathon 3:18" },
    { q: "First app where the strength and run sides talk to each other. The adaptive plan saved my hamstrings.", n: "Daniel K.", r: "Hybrid athlete" },
    { q: "I've tried six coaching apps. Raceform is the only one I haven't quit after week three.", n: "Maja T.", r: "First-time runner" },
  ];
  return (
    <section id="stories" className="section">
      <div className="container">
        <div style={{ maxWidth: 720, marginBottom: 56 }}>
          <span className="eyebrow">— Athletes</span>
          <h2 className="display" style={{ fontSize: "clamp(36px, 5vw, 56px)", marginTop: 14 }}>
            Built by athletes.<br/>Loved by athletes.
          </h2>
        </div>
        <div className="t-grid" style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 16 }}>
          {data.map((t, i) => (
            <div key={i} className="card" style={{ padding: 28, display: "flex", flexDirection: "column", gap: 24 }}>
              <p className="display" style={{ fontSize: 18, lineHeight: 1.4, color: "var(--ink)" }}>"{t.q}"</p>
              <div style={{ display: "flex", alignItems: "center", gap: 12, marginTop: "auto" }}>
                <div style={{ width: 36, height: 36, borderRadius: "50%", background: ["var(--accent)","var(--ink)","var(--green)"][i], color: "white", display: "flex", alignItems: "center", justifyContent: "center", fontSize: 13, fontWeight: 600 }}>
                  {t.n[0]}
                </div>
                <div>
                  <div style={{ fontSize: 14, fontWeight: 600 }}>{t.n}</div>
                  <div className="mono" style={{ fontSize: 11, color: "var(--ink-3)" }}>{t.r}</div>
                </div>
              </div>
            </div>
          ))}
        </div>
        <div style={{ marginTop: 40, padding: "28px 32px", background: "var(--ink)", color: "white", borderRadius: 16, display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 24 }} className="stat-strip">
          {[
            { v: "2,847", l: "Active athletes" },
            { v: "94%", l: "Stick with their plan" },
            { v: "4.9/5", l: "App Store rating" },
            { v: "12 min", l: "Avg PR drop in 12 wks" },
          ].map(s => (
            <div key={s.l}>
              <div className="display" style={{ fontSize: 36, color: "white" }}>{s.v}</div>
              <div className="mono" style={{ fontSize: 11, color: "rgba(255,255,255,0.5)", marginTop: 4 }}>{s.l.toUpperCase()}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
};

// ── FAQ ─────────────────────────────────
const FAQ = () => {
  const items = [
    { q: "Do I need a smartwatch?", a: "Strongly recommended. Apple Watch, Garmin, Coros, Whoop and Polar all work natively. You can use the iPhone alone, but readiness gets less precise without HRV/sleep data." },
    { q: "Is this just ChatGPT in a tracksuit?", a: "No. Our adaptive engine is a custom training model built on years of coaching IP, not a wrapped LLM. The optional human coach is, well, a real human." },
    { q: "I'm new to running. Is this too advanced?", a: "Raceform meets you where you are. Tell us your goal — finish a 5k, run without stopping, lose weight — and we'll build from there." },
    { q: "Can I keep lifting?", a: "Yes — that's the whole point. Hybrid is our default mode. We balance strength and run volume so neither side suffers." },
    { q: "What if I miss a workout?", a: "We rebalance the week. No catch-up doom-runs, no shame. Move on." },
    { q: "How much does it cost?", a: "$14/month or $120/year after a 14-day free trial. Add a human coach for $40/month." },
  ];
  return (
    <section id="faq" className="section" style={{ background: "var(--surface)", borderTop: "1px solid var(--line)", borderBottom: "1px solid var(--line)" }}>
      <div className="container faq-grid" style={{ display: "grid", gridTemplateColumns: "1fr 2fr", gap: 64 }}>
        <div>
          <span className="eyebrow">— FAQ</span>
          <h2 className="display" style={{ fontSize: "clamp(32px, 4vw, 48px)", marginTop: 14 }}>
            Asked<br/>and answered.
          </h2>
        </div>
        <div>
          {items.map((it, i) => (
            <details key={i} className="faq">
              <summary>
                <span>{it.q}</span>
                <span className="plus">+</span>
              </summary>
              <p>{it.a}</p>
            </details>
          ))}
        </div>
      </div>
    </section>
  );
};

// ── CTA ─────────────────────────────────
const CTA = () => {
  const [submitted, setSubmitted] = useState(false);

  return (
    <section id="cta" className="section">
      <div className="container">
        <div style={{ background: "var(--accent)", color: "white", borderRadius: 24, padding: "64px 56px", position: "relative", overflow: "hidden" }}>
          <div style={{ position: "absolute", top: -100, right: -100, width: 400, height: 400, borderRadius: "50%", background: "radial-gradient(circle, rgba(255,255,255,0.18), transparent 60%)" }}/>
          <div style={{ display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: 40, alignItems: "center", position: "relative" }} className="cta-grid">
            <div>
              <span className="eyebrow" style={{ color: "rgba(255,255,255,0.8)" }}>— Get started</span>
              <h2 className="display" style={{ fontSize: "clamp(40px, 6vw, 72px)", marginTop: 14, color: "white" }}>
                Train like<br/>it's yours.
              </h2>
              <p style={{ fontSize: 18, color: "rgba(255,255,255,0.85)", marginTop: 16, maxWidth: 460 }}>
                Join the Raceform early access list. Enter your email and confirm it from your inbox to complete signup.
              </p>
            </div>
            <div style={{ background: "rgba(0,0,0,0.18)", border: "1px solid rgba(255,255,255,0.15)", borderRadius: 14, padding: 24 }}>
              {submitted ? (
                <div>
                  <div className="mono" style={{ fontSize: 11, color: "rgba(255,255,255,0.7)", marginBottom: 10 }}>CHECK YOUR EMAIL</div>
                  <div className="display" style={{ fontSize: 28, color: "white", marginBottom: 10 }}>Almost there.</div>
                  <p style={{ fontSize: 14, lineHeight: 1.55, color: "rgba(255,255,255,0.78)" }}>
                    We’ve sent a verification email to confirm your spot on the Raceform early access list.
                    <br/><br/>
                    <strong style={{ color: "white" }}>Click the confirmation link to complete signup — and check your spam or promotions folder if you don’t see it.</strong>
                  </p>
                </div>
              ) : (
                <>
                <iframe name="raceform_mailerlite_iframe" title="Raceform MailerLite signup" style={{ display: "none" }}></iframe>
                <form
                  action="https://assets.mailerlite.com/jsonp/2364321/forms/187974071448765850/subscribe"
                  method="post"
                  target="raceform_mailerlite_iframe"
                  onSubmit={() => { setTimeout(() => setSubmitted(true), 900); }}
                >
                  <div className="mono" style={{ fontSize: 11, color: "rgba(255,255,255,0.7)", marginBottom: 10 }}>EMAIL</div>
                  <input
                    aria-label="Email"
                    aria-required="true"
                    type="email"
                    name="fields[email]"
                    placeholder="you@training.com"
                    autoComplete="email"
                    required
                    style={{ width: "100%", padding: "12px 14px", borderRadius: 8, border: "none", background: "white", color: "var(--ink)", fontSize: 15, fontFamily: "inherit", marginBottom: 10 }}
                  />
                  <input type="hidden" name="ml-submit" value="1" />
                  <input type="hidden" name="anticsrf" value="true" />
                  <button type="submit" className="btn" style={{ width: "100%", background: "var(--ink)", color: "white", border: "none", height: 46, fontSize: 15, justifyContent: "center" }}>
                    Join early access →
                  </button>
                  <div className="mono" style={{ fontSize: 11, color: "rgba(255,255,255,0.6)", marginTop: 10, textAlign: "center" }}>
                    Two-step email verification · no spam
                  </div>
                  
                </form>
                </>
              )}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
};

// ── FOOTER ──────────────────────────────
const Footer = () => (
  <footer style={{ padding: "56px 0 40px", borderTop: "1px solid var(--line)" }}>
    <div className="container">
      <div style={{ display: "grid", gridTemplateColumns: "2fr 1fr 1fr 1fr", gap: 40, marginBottom: 56 }} className="footer-grid">
        <div>
          <Logo/>
          <p style={{ fontSize: 14, color: "var(--ink-3)", marginTop: 14, maxWidth: 280 }}>
            Adaptive training for hybrid athletes. Made by runners and lifters in Copenhagen.
          </p>
        </div>
        {[
          { t: "Product", links: ["Features", "Sample week", "Pricing", "Changelog"] },
          { t: "Company", links: ["About", "Coaches", "Press kit", "Careers"] },
          { t: "Resources", links: ["Help", "Privacy", "Terms", "Contact"] },
        ].map(col => (
          <div key={col.t}>
            <div className="eyebrow" style={{ marginBottom: 12 }}>{col.t}</div>
            {col.links.map(l => (
              <a key={l} href="#" style={{ display: "block", color: "var(--ink-2)", textDecoration: "none", fontSize: 14, padding: "5px 0" }}>{l}</a>
            ))}
          </div>
        ))}
      </div>
      <div style={{ paddingTop: 28, borderTop: "1px solid var(--line)", display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: 12 }}>
        <span className="mono" style={{ fontSize: 12, color: "var(--ink-3)" }}>© 2026 Raceform ApS · Copenhagen</span>
        <span className="mono" style={{ fontSize: 12, color: "var(--ink-4)" }}>v 2.4.1</span>
      </div>
    </div>
  </footer>
);

// ── APP ─────────────────────────────────
const App = () => (
  <>
    <Nav/>
    <Hero/>
    <Marquee/>
    <HowItWorks/>
    <Features/>
    <SampleWeek/>
    <PhoneDemo/>
    <Testimonials/>
    <FAQ/>
    <CTA/>
    <Footer/>
    <style>{`
      @media (max-width: 1000px) {
        .features-grid { grid-template-columns: 1fr 1fr !important; }
        .features-grid > *:first-child { grid-row: span 1 !important; grid-column: span 2 !important; }
      }
      @media (max-width: 900px) {
        .prod-hero, .demo-grid, .week-detail, .cta-grid, .faq-grid { grid-template-columns: 1fr !important; }
        .how-grid, .t-grid { grid-template-columns: 1fr !important; }
        .week-strip { grid-template-columns: repeat(4, 1fr) !important; }
        .stat-strip { grid-template-columns: repeat(2, 1fr) !important; }
        .footer-grid { grid-template-columns: 1fr 1fr !important; }
      }
      @media (max-width: 600px) {
        .features-grid { grid-template-columns: 1fr !important; }
        .features-grid > *:first-child { grid-column: span 1 !important; }
        .week-strip { grid-template-columns: repeat(3, 1fr) !important; }
        .footer-grid { grid-template-columns: 1fr !important; }
      }
    `}</style>
  </>
);

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