/* G8well marketing site, landing page sections. Composes DS primitives. */
const DS = window.G8wellDesignSystem_2a45c3;
const { Button, Badge, Card, Icon, IconButton } = DS;
const { useState, useEffect } = React;

/* Hero carousel images. Drop your generated photos into /assets with these
   names and they join the rotation automatically — missing files are skipped,
   so the hero always shows whatever is available. */
const HERO_IMAGES = [
  { src: "assets/hero-4.png", alt: "A traveller mid-stretch in the G8well airport gym, wood-framed equipment and runway beyond" },
  { src: "assets/hero-5.png", alt: "A guest resting in the sauna beside a cold plunge in the G8well recovery zone" },
  { src: "assets/hero-3.png", alt: "A traveller resting in a private G8well nap pod, aircraft on the tarmac outside" },
  { src: "assets/hero-2.png", alt: "Fresh cold-pressed juices poured at the G8well hydration bar, airside" },
  { src: "assets/hero-1.png", alt: "A traveller reclining in a G8well lounge pod, planes on the tarmac beyond" },
  { src: "assets/hero-7.png", alt: "A refreshed traveller leaving a G8well lounge for the gate at golden hour" },
];

function HeroCarousel() {
  const [broken, setBroken] = useState({});
  const slides = HERO_IMAGES.filter((im) => !broken[im.src]);
  const [i, setI] = useState(0);
  useEffect(() => {
    if (slides.length <= 1) return undefined;
    const t = setInterval(() => setI((n) => (n + 1) % slides.length), 4500);
    return () => clearInterval(t);
  }, [slides.length]);
  const cur = slides.length ? i % slides.length : 0;
  return (
    <div className="heroimg" style={{ position: "relative", height: 520, borderRadius: "var(--radius-2xl)", overflow: "hidden", boxShadow: "var(--shadow-md)", background: "linear-gradient(135deg, var(--celadon), var(--tea-green))" }}>
      {HERO_IMAGES.map((im) => {
        const active = slides[cur] && slides[cur].src === im.src;
        return (
          <img key={im.src} src={im.src} alt={im.alt}
            onError={() => setBroken((b) => (b[im.src] ? b : { ...b, [im.src]: true }))}
            style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", opacity: active ? 1 : 0, transition: "opacity 900ms var(--ease-out)" }} />
        );
      })}
      {slides.length > 1 ? (
        <div style={{ position: "absolute", bottom: 16, left: 0, right: 0, display: "flex", justifyContent: "center", gap: 8 }}>
          {slides.map((_, n) => (
            <button key={n} onClick={() => setI(n)} aria-label={`Show slide ${n + 1}`}
              style={{ width: n === cur ? 22 : 8, height: 8, borderRadius: 999, border: "none", padding: 0, cursor: "pointer", background: n === cur ? "var(--ivory-100)" : "rgba(248,255,242,0.55)", boxShadow: "0 1px 3px rgba(0,0,0,0.2)", transition: "width 300ms var(--ease-out), background 300ms var(--ease-out)" }} />
          ))}
        </div>
      ) : null}
    </div>
  );
}

function Eyebrow({ children, dark }) {
  return <div style={{ fontSize: 12, letterSpacing: "0.16em", textTransform: "uppercase", fontWeight: 600, color: dark ? "rgba(248,255,242,0.55)" : "var(--text-subtle)" }}>{children}</div>;
}
function Placeholder({ label, style }) {
  return (
    <div style={{ background: "linear-gradient(135deg, var(--celadon), var(--tea-green))", borderRadius: "var(--radius-2xl)", display: "flex", alignItems: "flex-end", padding: 22, color: "rgba(23,23,23,0.5)", fontSize: 13, fontWeight: 500, ...style }}>
      <span style={{ display: "flex", alignItems: "center", gap: 6 }}><Icon name="star" size={14} />{label}</span>
    </div>
  );
}

const SERVICES = [
  { name: "Movement", icon: "activity", desc: "A full gym plus guided stretch and mobility studios to undo hours in a seat." },
  { name: "Recovery", icon: "waves", desc: "Massage, compression therapy and sauna between flights." },
  { name: "Sleep", icon: "moon", desc: "Private nap pods engineered for a 40-minute deep reset." },
  { name: "Cold", icon: "snowflake", desc: "Cold plunge and contrast therapy to reset circulation." },
  { name: "Hydrate", icon: "droplet", desc: "A functional bar built around what long-haul takes out of you." },
  { name: "Refresh", icon: "bath", desc: "Showers and change rooms so you land ready, not rumpled." },
];

const STEPS = [
  { n: "01", icon: "calendar", title: "Book around your flight", body: "Tell us your itinerary. We time a reset into your layover, gate to gate." },
  { n: "02", icon: "qr-code", title: "Scan in, airside", body: "Your pass opens any G8well space inside the terminal. No detour landside." },
  { n: "03", icon: "sparkles", title: "Reset, then fly", body: "Move, recover, refresh. Your AI trainer adapts the plan to how you feel." },
];

function Nav() {
  return (
    <nav className="nav" style={{ position: "sticky", top: 0, zIndex: 100, display: "flex", alignItems: "center", justifyContent: "space-between", padding: "18px 40px", background: "rgba(248,255,242,0.8)", backdropFilter: "blur(14px)", borderBottom: "1px solid var(--border-subtle)" }}>
      <img className="logo" src="assets/logo-carbon.svg" alt="G8well" style={{ height: 44 }} />
      <div className="navlinks" style={{ display: "flex", gap: 34, fontSize: 15, fontWeight: 500 }}>
        {[["The reset", "#category"], ["Services", "#services"], ["The app", "#app"], ["How it works", "#how"], ["Locations", "#locations"]].map(([l, href]) => <a key={l} href={href} style={{ color: "var(--text-body)", textDecoration: "none" }}>{l}</a>)}
      </div>
      <a href="https://www.kickstarter.com" target="_blank" rel="noopener" style={{ textDecoration: "none" }}><Button size="sm" variant="primary">Get early access</Button></a>
    </nav>
  );
}

function Hero() {
  return (
    <header className="hero" style={{ maxWidth: 1200, margin: "0 auto", padding: "80px 40px 60px", display: "grid", gridTemplateColumns: "1.05fr 0.95fr", gap: 56, alignItems: "center" }}>
      <div>
        <Eyebrow>The world's first airport wellness ecosystem</Eyebrow>
        <h1 style={{ fontSize: 72, lineHeight: 1.0, letterSpacing: "-0.03em", fontWeight: 600, margin: "20px 0 0" }}>Arrive better<br />than you left.</h1>
        <p style={{ fontSize: 20, lineHeight: 1.55, color: "var(--text-muted)", maxWidth: 480, margin: "22px 0 32px" }}>A premium space inside the airport where travellers move, recover and refresh, so you step off your next flight feeling human.</p>
        <div className="herobtns" style={{ display: "flex", gap: 14, flexWrap: "wrap" }}>
          <a href="https://www.kickstarter.com" target="_blank" rel="noopener" style={{ textDecoration: "none" }}><Button size="lg" variant="primary" glow iconRight="arrow-right">Get early access</Button></a>
        </div>
        <div className="herostats" style={{ display: "flex", gap: 28, marginTop: 40, flexWrap: "wrap" }}>
          {[["20 min", "average reset"], ["Airside", "inside security"], ["Gate-to-gate", "timed to your flight"]].map(([n, l]) => (
            <div key={l}><div style={{ fontSize: 22, fontWeight: 600, letterSpacing: "-0.02em" }}>{n}</div><div style={{ fontSize: 13, color: "var(--text-subtle)" }}>{l}</div></div>
          ))}
        </div>
      </div>
      <HeroCarousel />
    </header>
  );
}

function Category() {
  return (
    <section id="category" className="sec" style={{ background: "var(--carbon-900)", color: "var(--ivory-100)", padding: "110px 40px", textAlign: "center" }}>
      <Eyebrow dark>A new category</Eyebrow>
      <h2 style={{ fontSize: 60, fontWeight: 600, letterSpacing: "-0.02em", lineHeight: 1.05, margin: "22px auto 0", maxWidth: 900 }}>
        Not a gym. Not a spa.<br /><span style={{ color: "var(--accent)" }}>A new wellness category.</span>
      </h2>
      <p style={{ fontSize: 19, color: "rgba(248,255,242,0.7)", maxWidth: 620, margin: "26px auto 0", lineHeight: 1.6 }}>The pre-flight and post-flight wellness reset. Built for the way the body actually travels, not for a membership you visit twice a year.</p>
    </section>
  );
}

function Services() {
  return (
    <section id="services" className="sec" style={{ maxWidth: 1200, margin: "0 auto", padding: "100px 40px" }}>
      <div className="rowwrap" style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", marginBottom: 44 }}>
        <div><Eyebrow>Six ways to reset</Eyebrow><h2 style={{ fontSize: 44, fontWeight: 600, letterSpacing: "-0.02em", margin: "14px 0 0" }}>Everything the body loses<br />in the air, given back.</h2></div>
        <Button variant="ghost" iconRight="arrow-right">See all services</Button>
      </div>
      <div className="cols3 swipe" style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 20 }}>
        {SERVICES.map((s) => (
          <Card key={s.name} radius="xl" padding="lg" interactive elevation="sm">
            <div style={{ width: 54, height: 54, borderRadius: "var(--radius-lg)", background: "var(--surface-sunken)", display: "flex", alignItems: "center", justifyContent: "center", color: "var(--muted-olive)" }}><Icon name={s.icon} size={28} /></div>
            <h3 style={{ fontSize: 22, fontWeight: 600, margin: "18px 0 8px" }}>{s.name}</h3>
            <p style={{ fontSize: 15, lineHeight: 1.55, color: "var(--text-muted)", margin: 0 }}>{s.desc}</p>
          </Card>
        ))}
      </div>
    </section>
  );
}

/* ---------- App store badges (custom-drawn, "coming soon") ---------- */
function AppleMark({ size = 20 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
      <path d="M17.05 12.54c-.02-2.02 1.65-2.99 1.72-3.04-0.94-1.37-2.4-1.56-2.92-1.58-1.24-.12-2.42.73-3.05.73-.63 0-1.6-.71-2.63-.69-1.35.02-2.6.79-3.3 2-1.4 2.44-.36 6.05 1.01 8.03.67.97 1.47 2.06 2.51 2.02 1.01-.04 1.39-.65 2.61-.65 1.22 0 1.56.65 2.63.63 1.09-.02 1.78-.99 2.44-1.96.77-1.12 1.09-2.21 1.11-2.27-.02-.01-2.13-.82-2.15-3.25zM15.04 6.35c.56-.68.94-1.62.83-2.56-.81.03-1.79.54-2.37 1.21-.52.6-.98 1.56-.86 2.48.9.07 1.83-.46 2.4-1.13z" />
    </svg>
  );
}
function PlayMark({ size = 20 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" aria-hidden="true">
      <path d="M4 3.2c-.3.17-.5.5-.5.94v15.72c0 .44.2.77.5.94l8.63-8.8L4 3.2z" fill="#33d685" />
      <path d="M17.6 9.1l-3.4-1.96-3.02 3.08 3.02 3.08 3.42-1.97c.86-.5.86-1.74-.02-2.23z" fill="#ffce3d" />
      <path d="M3.5 20.8c.23.13.52.12.85-.07l10.42-6.02-3.02-3.08L3.5 20.8z" fill="#f83b4c" />
      <path d="M14.77 7.14L4.35 1.12C4.02.93 3.73.92 3.5 1.05l8.25 10.37 3.02-3.08z" fill="#48b3e6" />
    </svg>
  );
}
function StoreBadge({ mark, top, bottom }) {
  return (
    <a href="#app" onClick={(e) => e.preventDefault()} title="Coming soon"
      style={{ display: "inline-flex", alignItems: "center", gap: 11, background: "var(--carbon-900)", color: "var(--ivory-100)", borderRadius: 12, padding: "10px 18px", textDecoration: "none", position: "relative", boxShadow: "var(--shadow-sm)" }}>
      {mark}
      <span style={{ display: "flex", flexDirection: "column", lineHeight: 1.1 }}>
        <span style={{ fontSize: 10, letterSpacing: "0.04em", opacity: 0.75 }}>{top}</span>
        <span style={{ fontSize: 17, fontWeight: 600, letterSpacing: "-0.01em" }}>{bottom}</span>
      </span>
      <span style={{ position: "absolute", top: -9, right: -9, background: "var(--accent)", color: "var(--carbon-900)", fontSize: 9.5, fontWeight: 700, letterSpacing: "0.04em", textTransform: "uppercase", padding: "2px 7px", borderRadius: "var(--radius-pill)" }}>Soon</span>
    </a>
  );
}

/* ---------- App showcase — live, scrollable app inside a phone ---------- */
function AppShowcase() {
  const SCREEN_W = 300, SCREEN_H = 640;
  const SCALE = SCREEN_W / 390; // render the app at its native 390px width, scaled to the screen
  const features = [
    ["plane", "Books itself around your flight", "Add your itinerary; the app times a reset into your layover."],
    ["sparkles", "An AI trainer that adapts", "A plan built around how far you've flown and how you feel."],
    ["qr-code", "One pass, every terminal", "Scan in airside — gate to gate, no detour landside."],
  ];
  return (
    <section id="app" className="sec" style={{ position: "relative", padding: "104px 40px", overflow: "hidden", background: "var(--surface-page)" }}>
      {/* soft sage glow behind the device */}
      <div style={{ position: "absolute", top: "8%", right: "6%", width: 620, height: 620, background: "radial-gradient(circle, rgba(178,201,158,0.55), rgba(178,201,158,0) 68%)", filter: "blur(8px)", pointerEvents: "none" }} />
      <div className="appcols" style={{ position: "relative", maxWidth: 1200, margin: "0 auto", display: "grid", gridTemplateColumns: "1fr 0.9fr", gap: 64, alignItems: "center" }}>
        <div>
          <Eyebrow>The G8well app</Eyebrow>
          <h2 style={{ fontSize: 48, fontWeight: 600, letterSpacing: "-0.02em", lineHeight: 1.04, margin: "16px 0 18px" }}>Your reset,<br />in your pocket.</h2>
          <p style={{ fontSize: 19, lineHeight: 1.6, color: "var(--text-muted)", maxWidth: 460, margin: "0 0 32px" }}>Book a session, carry your pass, and let the AI trainer plan every layover. Try it right here — scroll and tap through the real app.</p>
          <div style={{ display: "flex", flexDirection: "column", gap: 18, marginBottom: 36 }}>
            {features.map(([icon, title, body]) => (
              <div key={title} style={{ display: "flex", gap: 14, alignItems: "flex-start" }}>
                <div style={{ flex: "none", width: 44, height: 44, borderRadius: "var(--radius-lg)", background: "var(--surface-sunken)", display: "flex", alignItems: "center", justifyContent: "center", color: "var(--muted-olive)" }}><Icon name={icon} size={22} /></div>
                <div><div style={{ fontSize: 17, fontWeight: 600 }}>{title}</div><div style={{ fontSize: 15, color: "var(--text-muted)", lineHeight: 1.5, marginTop: 2 }}>{body}</div></div>
              </div>
            ))}
          </div>
          <div style={{ display: "flex", gap: 14, flexWrap: "wrap" }}>
            <StoreBadge mark={<AppleMark />} top="Download on the" bottom="App Store" />
            <StoreBadge mark={<PlayMark />} top="Get it on" bottom="Google Play" />
          </div>
        </div>

        {/* Device — the live app runs inside, scrollable. The bezel's content
            box is sized to the screen so the black frame stays symmetric. */}
        <div className="phonewrap" style={{ display: "flex", justifyContent: "center" }}>
          <div style={{ position: "relative" }}>
            <div style={{ position: "relative", width: SCREEN_W, background: "var(--carbon-900)", borderRadius: 46, padding: 11, boxShadow: "var(--shadow-lg)" }}>
              <div style={{ position: "absolute", top: 11, left: "50%", transform: "translateX(-50%)", width: 96, height: 24, background: "var(--carbon-900)", borderRadius: "0 0 15px 15px", zIndex: 5 }} />
              <div style={{ position: "relative", width: SCREEN_W, height: SCREEN_H, borderRadius: 36, overflow: "hidden", background: "var(--surface-page)" }}>
                <iframe src="app/embed.html" title="G8well app — interactive preview" scrolling="yes"
                  style={{ width: 390, height: Math.round(SCREEN_H / SCALE), border: 0, transformOrigin: "top left", transform: `scale(${SCALE})`, display: "block" }} />
              </div>
            </div>
            <div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 7, marginTop: 18, color: "var(--text-subtle)", fontSize: 13, fontWeight: 500 }}>
              <Icon name="chevron-down" size={15} /> Scroll &amp; tap to explore the live app
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

function HowItWorks() {
  return (
    <section id="how" className="sec" style={{ background: "var(--surface-sunken)", padding: "100px 40px" }}>
      <div style={{ maxWidth: 1200, margin: "0 auto" }}>
        <Eyebrow>How it works</Eyebrow>
        <h2 style={{ fontSize: 44, fontWeight: 600, letterSpacing: "-0.02em", margin: "14px 0 48px" }}>Three steps between two flights.</h2>
        <div className="cols3" style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 24 }}>
          {STEPS.map((s) => (
            <div key={s.n}>
              <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
                <div style={{ width: 52, height: 52, borderRadius: "50%", background: "var(--carbon-900)", color: "var(--accent)", display: "flex", alignItems: "center", justifyContent: "center" }}><Icon name={s.icon} size={24} /></div>
                <span style={{ fontSize: 15, fontWeight: 600, color: "var(--text-subtle)" }}>{s.n}</span>
              </div>
              <h3 style={{ fontSize: 24, fontWeight: 600, margin: "22px 0 10px", letterSpacing: "-0.01em" }}>{s.title}</h3>
              <p style={{ fontSize: 16, lineHeight: 1.6, color: "var(--text-muted)", margin: 0 }}>{s.body}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function Membership() {
  return (
    <section id="membership" className="sec" style={{ maxWidth: 1200, margin: "0 auto", padding: "100px 40px" }}>
      <Card tone="accent" radius="2xl" padding="lg">
        <div className="memcols" style={{ padding: "40px 32px", display: "grid", gridTemplateColumns: "1.2fr 1fr", gap: 40, alignItems: "center" }}>
          <div>
            <Eyebrow>Back us on Kickstarter</Eyebrow>
            <h2 style={{ fontSize: 46, fontWeight: 600, letterSpacing: "-0.02em", margin: "16px 0 14px", lineHeight: 1.05 }}>Help build the first airport reset.</h2>
            <p style={{ fontSize: 18, lineHeight: 1.55, color: "rgba(23,23,23,0.7)", margin: "0 0 28px" }}>Back the founding campaign and become a member for life. Priority booking, the AI trainer, and every new location the day it opens, for everyone who gets us off the ground.</p>
            <div style={{ display: "flex", gap: 14 }}>
              <a href="https://www.kickstarter.com" target="_blank" rel="noopener" style={{ textDecoration: "none" }}><Button size="lg" variant="secondary" iconRight="arrow-right">Back us on Kickstarter</Button></a>
            </div>
          </div>
          <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
            {["Unlimited sessions, airside", "AI trainer around your itinerary", "One pass, every G8well location", "Guided audio & recovery content"].map((f) => (
              <div key={f} style={{ display: "flex", alignItems: "center", gap: 12, fontSize: 16, fontWeight: 500, color: "var(--carbon-900)" }}><Icon name="check" size={20} stroke={2.2} />{f}</div>
            ))}
          </div>
        </div>
      </Card>
    </section>
  );
}

function Locations() {
  const airports = [["MAN", "Manchester", "Coming soon"], ["DXB", "Dubai", "2027"], ["SIN", "Singapore", "2027"], ["LHR", "London", "2027"], ["PMI", "Palma de Mallorca", "2028"], ["HND", "Tokyo", "2029"]];
  return (
    <section id="locations" className="sec" style={{ background: "var(--carbon-900)", color: "var(--ivory-100)", padding: "100px 40px" }}>
      <div style={{ maxWidth: 1200, margin: "0 auto" }}>
        <Eyebrow dark>Locations</Eyebrow>
        <h2 style={{ fontSize: 44, fontWeight: 600, letterSpacing: "-0.02em", margin: "14px 0 44px" }}>Rolling out across the world's<br />busiest terminals.</h2>
        <div className="cols3" style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 16 }}>
          {airports.map(([code, city, status]) => (
            <div key={code} style={{ border: "1px solid var(--border-on-dark)", borderRadius: "var(--radius-xl)", padding: "24px 26px", display: "flex", alignItems: "center", justifyContent: "space-between" }}>
              <div style={{ display: "flex", alignItems: "center", gap: 16 }}>
                <span style={{ fontSize: 26, fontWeight: 600, letterSpacing: "-0.01em" }}>{code}</span>
                <span style={{ color: "rgba(248,255,242,0.6)" }}>{city}</span>
              </div>
              <Badge tone={(status === "Now open" || status === "Coming soon") ? "accent" : "outline"} size="sm" style={(status !== "Now open" && status !== "Coming soon") ? { color: "var(--ivory-100)", boxShadow: "inset 0 0 0 1px var(--border-on-dark)" } : undefined}>{status}</Badge>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function Footer() {
  return (
    <footer style={{ background: "var(--carbon-900)", color: "rgba(248,255,242,0.6)", padding: "48px 40px", borderTop: "1px solid var(--border-on-dark)" }}>
      <div style={{ maxWidth: 1200, margin: "0 auto", display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: 20 }}>
        <img src="assets/logo-ivory.svg" alt="G8well" style={{ height: 54 }} />
        <div style={{ display: "flex", gap: 28, fontSize: 14, flexWrap: "wrap" }}>{[["Careers", "career.html", false], ["Press", "press.html", false], ["Healf", "https://healf.com/", true], ["Privacy", "privacy.html", false]].map(([l, href, ext]) => <a key={l} href={href} {...(ext ? { target: "_blank", rel: "noopener" } : {})} style={{ color: "rgba(248,255,242,0.6)", textDecoration: "none" }}>{l}</a>)}</div>
        <span style={{ fontSize: 13 }}>© 2026 G8well</span>
      </div>
    </footer>
  );
}

function Site() {
  return (
    <div style={{ fontFamily: "var(--font-sans)", color: "var(--text-body)", background: "var(--surface-page)" }}>
      <Nav /><Hero /><Category /><Services /><AppShowcase /><HowItWorks /><Membership /><Locations /><Footer />
    </div>
  );
}

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