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

// ---------- Nav ----------
function Nav() {
  const [scrolled, setScrolled] = useState(false);
  const [open, setOpen] = useState(false);
  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 12);
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  const links = [
    { label: 'Services', href: '#features' },
    { label: 'Process', href: '#process' },
    { label: 'Pricing', href: '#calculator-section' },
    { label: 'Work', href: '#testimonials' },
    { label: 'FAQ', href: '#faq' },
  ];

  return (
    <nav
      className={`fixed top-0 left-0 right-0 z-40 transition-all duration-300 ${
        scrolled ? 'bg-[#0A0A0A]/80 backdrop-blur-md border-b border-white/[0.06]' : 'bg-transparent'
      }`}
    >
      <div className="max-w-7xl mx-auto px-4 md:px-8 h-16 flex items-center justify-between">
        <a href="#top" className="flex items-center gap-2 group">
          <span className="w-8 h-8 rounded-lg bg-gradient-to-br from-[#FF5656] to-[#FF9E4F] flex items-center justify-center text-white font-bold text-sm">
            W
          </span>
          <span className="text-white font-medium tracking-tight">Webfluin <span className="text-white/50 font-normal">Studio</span></span>
        </a>

        <div className="hidden md:flex items-center gap-1">
          {links.map(l => (
            <a
              key={l.href}
              href={l.href}
              className="px-3 py-2 text-sm text-white/70 hover:text-white transition-colors rounded-md"
            >
              {l.label}
            </a>
          ))}
        </div>

        <div className="flex items-center gap-2">
          <a
            href="#calculator-section"
            className="hidden md:inline-flex items-center gap-2 bg-white text-black text-sm font-medium px-4 py-2 rounded-full hover:bg-white/90 transition-colors"
          >
            Get an estimate
            <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
              <line x1="5" y1="12" x2="19" y2="12"></line>
              <polyline points="12 5 19 12 12 19"></polyline>
            </svg>
          </a>
          <button
            className="md:hidden w-9 h-9 rounded-md border border-white/10 flex items-center justify-center text-white/70"
            onClick={() => setOpen(o => !o)}
            aria-label="Menu"
          >
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round">
              {open ? <><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></> : <><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></>}
            </svg>
          </button>
        </div>
      </div>

      {open && (
        <div className="md:hidden border-t border-white/[0.06] bg-[#0A0A0A]/95 backdrop-blur-md px-4 py-4 flex flex-col gap-1">
          {links.map(l => (
            <a
              key={l.href}
              href={l.href}
              onClick={() => setOpen(false)}
              className="px-3 py-2.5 text-sm text-white/70 hover:text-white rounded-md hover:bg-white/[0.04]"
            >
              {l.label}
            </a>
          ))}
          <a
            href="#calculator-section"
            onClick={() => setOpen(false)}
            className="mt-2 inline-flex items-center justify-center gap-2 bg-white text-black text-sm font-medium px-4 py-2.5 rounded-full"
          >
            Get an estimate
          </a>
        </div>
      )}
    </nav>
  );
}

// ---------- Hero ----------
function Hero() {
  return (
    <section id="top" className="relative w-full pt-32 md:pt-40 pb-16 md:pb-24 overflow-hidden">
      {/* Background grid + glow */}
      <div aria-hidden className="absolute inset-0 pointer-events-none">
        <div
          className="absolute inset-0 opacity-[0.07]"
          style={{
            backgroundImage:
              'linear-gradient(to right, rgba(255,255,255,0.6) 1px, transparent 1px), linear-gradient(to bottom, rgba(255,255,255,0.6) 1px, transparent 1px)',
            backgroundSize: '64px 64px',
            maskImage: 'radial-gradient(ellipse at 50% 0%, black 30%, transparent 75%)',
            WebkitMaskImage: 'radial-gradient(ellipse at 50% 0%, black 30%, transparent 75%)',
          }}
        />
        <div
          className="absolute left-1/2 -translate-x-1/2 top-0 w-[1200px] h-[800px] -translate-y-1/4 opacity-40"
          style={{ background: 'radial-gradient(closest-side, rgba(255,86,86,0.35), rgba(255,86,86,0) 70%)' }}
        />
      </div>

      <div className="relative max-w-7xl mx-auto px-4 md:px-8">
        {/* Eyebrow chip */}
        <div className="flex justify-center mb-7 reveal">
          <a href="#calculator-section" className="group inline-flex items-center gap-2 bg-white/[0.04] hover:bg-white/[0.07] border border-white/10 rounded-full px-3 py-1.5 text-xs text-white/80 transition-colors">
            <span className="font-mono uppercase tracking-widest text-[10px] text-[#FF8E55]">New</span>
            <span className="text-white/30">|</span>
            <span>Estimate any project in under 60 seconds</span>
            <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="group-hover:translate-x-0.5 transition-transform">
              <polyline points="9 18 15 12 9 6"></polyline>
            </svg>
          </a>
        </div>

        {/* Headline */}
        <h1 className="text-center text-[44px] sm:text-6xl md:text-7xl lg:text-[88px] leading-[0.95] tracking-tight text-white font-normal max-w-5xl mx-auto reveal">
          Premium websites,
          <br />
          <span className="font-serif italic text-white/95">without the </span>
          <span className="grad-text font-serif italic">premium price.</span>
        </h1>

        {/* Sub */}
        <p className="text-center text-base md:text-lg text-white/55 max-w-2xl mx-auto mt-7 leading-relaxed reveal">
          We design and build conversion-focused websites for ambitious founders, in weeks, not months — at a fraction of what agencies charge.
        </p>

        {/* CTAs */}
        <div className="flex items-center justify-center gap-3 mt-9 flex-wrap reveal">
          <a
            href="#calculator-section"
            className="group inline-flex items-center gap-2 bg-white text-black rounded-full pl-5 pr-2 py-2 text-[15px] font-medium hover:bg-white/90 transition-colors"
          >
            Calculate your project
            <span className="w-8 h-8 rounded-full bg-black flex items-center justify-center group-hover:translate-x-0.5 transition-transform">
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="white" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                <line x1="5" y1="12" x2="19" y2="12"></line>
                <polyline points="12 5 19 12 12 19"></polyline>
              </svg>
            </span>
          </a>
          <a
            href="#testimonials"
            className="inline-flex items-center gap-2 bg-white/[0.05] hover:bg-white/[0.08] border border-white/10 text-white rounded-full px-5 py-3 text-[15px] font-medium transition-colors"
          >
            <span className="w-2 h-2 rounded-full bg-[#3FCF8E]" />
            See recent work
          </a>
        </div>

        {/* Stats */}
        <div className="mt-16 md:mt-20 grid grid-cols-2 md:grid-cols-4 gap-px bg-white/[0.06] border border-white/[0.06] rounded-2xl overflow-hidden reveal">
          {[
            { k: '120+', v: 'Websites shipped' },
            { k: '14 days', v: 'Average delivery' },
            { k: '4.9 / 5', v: 'Client satisfaction' },
            { k: '$3.4M', v: 'Saved vs agencies' },
          ].map((s, i) => (
            <div key={i} className="bg-[#0A0A0A] p-5 md:p-7 text-center">
              <div className="text-2xl md:text-3xl font-medium text-white tracking-tight tabular-nums">{s.k}</div>
              <div className="text-xs md:text-sm text-white/45 mt-1.5">{s.v}</div>
            </div>
          ))}
        </div>

        {/* Logo marquee */}
        <div className="mt-16 md:mt-20 reveal">
          <div className="text-center text-[11px] font-mono uppercase tracking-[0.22em] text-white/35 mb-7">
            Trusted by founders & teams at
          </div>
          <div className="relative overflow-hidden" style={{ maskImage: 'linear-gradient(90deg, transparent, black 12%, black 88%, transparent)', WebkitMaskImage: 'linear-gradient(90deg, transparent, black 12%, black 88%, transparent)' }}>
            <div className="flex gap-12 md:gap-16 animate-marquee whitespace-nowrap">
              {[...Array(2)].map((_, dup) => (
                <div key={dup} className="flex gap-12 md:gap-16 items-center shrink-0">
                  {['◆ Northrift', 'Lumenly', '✦ Paperloop', 'KAYO', 'Modula', '◐ Quartzo', 'Bramble', 'Veld&Co'].map((name) => (
                    <span key={`${dup}-${name}`} className="text-white/40 hover:text-white/70 transition-colors text-lg md:text-xl tracking-tight font-medium whitespace-nowrap">
                      {name}
                    </span>
                  ))}
                </div>
              ))}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ---------- Features ----------
function Features() {
  const items = [
    {
      icon: (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
          <path d="M12 2 L3 7 v10 l9 5 9-5 V7 z" />
          <path d="M12 22 V12" />
          <path d="M3 7 l9 5 9-5" />
        </svg>
      ),
      title: 'Pixel-perfect design',
      copy: 'Hand-crafted layouts that look intentional, not templated. Every element placed with reason.',
    },
    {
      icon: (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
          <polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" />
        </svg>
      ),
      title: 'Lightning performance',
      copy: 'Sub-second loads, perfect Lighthouse scores, optimized for Core Web Vitals out of the gate.',
    },
    {
      icon: (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
          <circle cx="12" cy="12" r="10" />
          <circle cx="12" cy="12" r="6" />
          <circle cx="12" cy="12" r="2" />
        </svg>
      ),
      title: 'Built to convert',
      copy: 'Every section maps to a funnel goal. We measure scroll depth, clicks, and form starts from day one.',
    },
    {
      icon: (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
          <circle cx="11" cy="11" r="7" />
          <line x1="21" y1="21" x2="16.5" y2="16.5" />
        </svg>
      ),
      title: 'SEO from day one',
      copy: 'Semantic markup, structured data, fast LCP, real keyword research — not SEO bolted on later.',
    },
    {
      icon: (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
          <rect x="3" y="3" width="18" height="18" rx="2" />
          <line x1="3" y1="9" x2="21" y2="9" />
          <line x1="9" y1="21" x2="9" y2="9" />
        </svg>
      ),
      title: 'CMS your team can run',
      copy: 'Update copy, swap images, ship blog posts without us. No dev tickets, no waiting on changes.',
    },
    {
      icon: (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
          <circle cx="12" cy="12" r="10" />
          <polyline points="12 6 12 12 16 14" />
        </svg>
      ),
      title: 'Weeks, not months',
      copy: 'Two-week sprints with daily Loom updates. Most projects ship in under 30 days.',
    },
  ];

  return (
    <section id="features" className="relative w-full bg-background py-16 md:py-28 scroll-mt-20">
      <div className="max-w-7xl mx-auto px-4 md:px-8">
        <div className="flex flex-col md:flex-row md:items-end md:justify-between gap-6 mb-10 md:mb-14 reveal">
          <div>
            <div className="font-mono uppercase tracking-[0.22em] text-xs text-white/40 mb-4">/ What you get</div>
            <h2 className="text-3xl md:text-4xl lg:text-5xl text-white font-normal tracking-tight max-w-2xl leading-[1.05]">
              Everything an agency promises.
              <br />
              <span className="font-serif italic text-white/60">Without the bloat.</span>
            </h2>
          </div>
          <p className="text-white/55 max-w-sm text-[15px] leading-relaxed">
            We strip the deliverables list down to what actually moves the needle — and then obsess over those things.
          </p>
        </div>

        <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-px bg-white/[0.06] border border-white/[0.06] rounded-2xl overflow-hidden reveal">
          {items.map((item, i) => (
            <div key={i} className="bg-[#0A0A0A] p-7 md:p-8 hover:bg-white/[0.015] transition-colors group">
              <div className="flex items-center gap-3 mb-5">
                <div className="w-10 h-10 rounded-xl bg-white/[0.04] border border-white/10 flex items-center justify-center text-white/80 group-hover:text-[#FF8E55] group-hover:border-[#FF5656]/30 transition-colors">
                  {item.icon}
                </div>
                <span className="text-[10px] font-mono uppercase tracking-widest text-white/30">
                  {String(i + 1).padStart(2, '0')}
                </span>
              </div>
              <h3 className="text-lg md:text-xl text-white font-normal tracking-tight mb-2">{item.title}</h3>
              <p className="text-sm text-white/55 leading-relaxed">{item.copy}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ---------- Process ----------
function Process() {
  const steps = [
    {
      n: '01',
      title: 'Discovery call',
      copy: 'A 30-min call to understand your business, goals and current site. You leave with a clear plan and your fixed quote.',
      meta: 'Day 0',
    },
    {
      n: '02',
      title: 'Design sprint',
      copy: 'We design every key screen in Figma. Two rounds of revisions. You sign off — no surprises later.',
      meta: 'Day 1–7',
    },
    {
      n: '03',
      title: 'Build & iterate',
      copy: 'Pixel-perfect build in Webflow or Next.js. Daily Loom updates. Real content, not lorem ipsum.',
      meta: 'Day 7–21',
    },
    {
      n: '04',
      title: 'Launch & support',
      copy: 'We push live, transfer ownership, train your team, and stick around for two weeks of free tuning.',
      meta: 'Day 21–30',
    },
  ];

  return (
    <section id="process" className="relative w-full bg-background py-16 md:py-28 scroll-mt-20">
      <div className="max-w-7xl mx-auto px-4 md:px-8">
        <div className="text-center mb-12 md:mb-16 reveal">
          <div className="font-mono uppercase tracking-[0.22em] text-xs text-white/40 mb-4">/ How it works</div>
          <h2 className="text-3xl md:text-4xl lg:text-5xl text-white font-normal tracking-tight max-w-3xl mx-auto leading-[1.05]">
            From kickoff to live site,
            <span className="font-serif italic text-white/70"> a calm 30-day rhythm.</span>
          </h2>
        </div>

        <div className="relative">
          {/* Connector line */}
          <div aria-hidden className="hidden lg:block absolute top-12 left-[12%] right-[12%] h-px bg-gradient-to-r from-transparent via-white/15 to-transparent" />

          <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-5 lg:gap-6 reveal">
            {steps.map((s, i) => (
              <div key={i} className="relative">
                {/* dot */}
                <div className="hidden lg:flex absolute -top-1 left-0 w-6 h-6 rounded-full bg-[#0A0A0A] border border-white/15 items-center justify-center">
                  <div className="w-2 h-2 rounded-full bg-[#FF5656]" />
                </div>

                <div className="lg:mt-12 bg-[#0D0D0D] border border-white/[0.06] rounded-2xl p-6 md:p-7 h-full hover:border-white/15 transition-colors">
                  <div className="flex items-center justify-between mb-5">
                    <span className="font-serif italic text-4xl text-[#FF5656]/90">{s.n}</span>
                    <span className="text-[10px] font-mono uppercase tracking-widest text-white/35 border border-white/10 rounded-full px-2 py-1">
                      {s.meta}
                    </span>
                  </div>
                  <h3 className="text-lg md:text-xl text-white font-normal tracking-tight mb-2">{s.title}</h3>
                  <p className="text-sm text-white/55 leading-relaxed">{s.copy}</p>
                </div>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

// ---------- Testimonials ----------
function Testimonials() {
  const items = [
    {
      quote: "We'd been quoted $42k by two agencies for the same scope. Webfluin shipped it in 17 days for under five. The site outperforms our old one on every metric we track.",
      name: 'Mira Aldenhoven',
      role: 'Founder, Northrift Coffee',
      stat: '+38% conversion',
    },
    {
      quote: "What sold me was the daily Looms. I always knew where we were. No 2am Slack panics, no surprises. They actually do what they say they will.",
      name: 'Daniel Park',
      role: 'Head of Growth, Lumenly',
      stat: 'Shipped in 21 days',
    },
    {
      quote: "I'm a non-designer founder and they made me feel taken care of without dumbing anything down. The Figma file they handed back is genuinely gorgeous.",
      name: 'Sasha Kovač',
      role: 'CEO, Paperloop',
      stat: '99 Lighthouse',
    },
    {
      quote: "We tried a freelancer twice before. Both times it dragged for months and looked fine but not great. Webfluin nailed the brand on the first design round.",
      name: 'Theo Renaud',
      role: 'Co-founder, KAYO',
      stat: '4.9 / 5 NPS',
    },
  ];

  return (
    <section id="testimonials" className="relative w-full bg-background py-16 md:py-28 scroll-mt-20">
      <div className="max-w-7xl mx-auto px-4 md:px-8">
        <div className="flex flex-col md:flex-row md:items-end md:justify-between gap-6 mb-10 md:mb-14 reveal">
          <div>
            <div className="font-mono uppercase tracking-[0.22em] text-xs text-white/40 mb-4">/ Social proof</div>
            <h2 className="text-3xl md:text-4xl lg:text-5xl text-white font-normal tracking-tight max-w-2xl leading-[1.05]">
              120+ founders have built
              <br />
              <span className="font-serif italic text-white/65">with us already.</span>
            </h2>
          </div>
          <div className="flex items-center gap-4">
            <div className="flex">
              {[...Array(5)].map((_, i) => (
                <svg key={i} width="18" height="18" viewBox="0 0 24 24" fill="#FF5656" className="-ml-0.5">
                  <polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>
                </svg>
              ))}
            </div>
            <div className="text-white/70 text-sm">
              <span className="font-medium text-white">4.9 / 5</span> · 84 verified reviews
            </div>
          </div>
        </div>

        <div className="grid grid-cols-1 md:grid-cols-2 gap-4 md:gap-5 reveal">
          {items.map((t, i) => (
            <figure key={i} className="bg-[#0D0D0D] border border-white/[0.06] rounded-2xl p-7 md:p-8 hover:border-white/15 transition-colors flex flex-col">
              <svg className="text-[#FF5656]/70 mb-5" width="28" height="22" viewBox="0 0 28 22" fill="currentColor">
                <path d="M0 22V13.4C0 9.93 0.733 6.93 2.2 4.4C3.67 1.87 6.13 0.4 9.6 0V4.4C7.6 4.8 6.13 5.67 5.2 7C4.27 8.33 3.8 9.93 3.8 11.8H9.6V22H0ZM18.4 22V13.4C18.4 9.93 19.13 6.93 20.6 4.4C22.07 1.87 24.53 0.4 28 0V4.4C26 4.8 24.53 5.67 23.6 7C22.67 8.33 22.2 9.93 22.2 11.8H28V22H18.4Z" />
              </svg>
              <blockquote className="text-white text-base md:text-lg leading-relaxed flex-1">
                "{t.quote}"
              </blockquote>
              <figcaption className="mt-7 pt-5 border-t border-white/[0.07] flex items-center justify-between gap-4">
                <div className="flex items-center gap-3">
                  <div className="w-9 h-9 rounded-full bg-gradient-to-br from-white/15 to-white/[0.04] border border-white/10 flex items-center justify-center text-white/80 text-sm font-medium">
                    {t.name.split(' ').map(n => n[0]).join('').slice(0,2)}
                  </div>
                  <div>
                    <div className="text-white text-sm font-medium">{t.name}</div>
                    <div className="text-white/45 text-xs">{t.role}</div>
                  </div>
                </div>
                <div className="text-[11px] font-mono text-[#FF8E55] bg-[#FF5656]/10 border border-[#FF5656]/20 rounded-full px-2.5 py-1">
                  {t.stat}
                </div>
              </figcaption>
            </figure>
          ))}
        </div>
      </div>
    </section>
  );
}

// ---------- FAQ ----------
function FAQItem({ q, a, open, onClick }) {
  return (
    <div className="border-b border-white/[0.07]">
      <button
        onClick={onClick}
        className="w-full flex items-center justify-between gap-6 text-left py-6 group"
      >
        <span className="text-white text-base md:text-lg font-normal tracking-tight pr-4">{q}</span>
        <span className={`shrink-0 w-9 h-9 rounded-full border border-white/15 flex items-center justify-center transition-all duration-300 ${open ? 'bg-[#FF5656] border-[#FF5656] rotate-45' : 'bg-transparent group-hover:border-white/35'}`}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={open ? 'text-white' : 'text-white/70'}>
            <line x1="12" y1="5" x2="12" y2="19"></line>
            <line x1="5" y1="12" x2="19" y2="12"></line>
          </svg>
        </span>
      </button>
      <div
        className="overflow-hidden transition-all duration-300 ease-out"
        style={{ maxHeight: open ? '320px' : '0', opacity: open ? 1 : 0 }}
      >
        <p className="text-white/60 leading-relaxed pb-6 pr-12 text-[15px]">{a}</p>
      </div>
    </div>
  );
}

function FAQ() {
  const items = [
    {
      q: 'How long does a typical project take?',
      a: 'Most projects ship in 14 to 30 days from kickoff. A landing page usually takes two weeks; a full multi-page site is closer to four. We give you a fixed delivery date in your quote and stick to it.',
    },
    {
      q: 'What if I need changes after we sign off on design?',
      a: 'You get two full revision rounds baked into every project. Small tweaks during build are always on the house. Bigger scope changes are quoted upfront — never billed by surprise.',
    },
    {
      q: 'Do you build on Webflow, or custom code?',
      a: 'Both. Webflow for marketing sites that your team needs to run independently. Next.js when you need custom logic, dashboards, or deep integrations. We help you pick during the discovery call.',
    },
    {
      q: 'Do you offer ongoing support after launch?',
      a: 'Yes — two weeks of free tuning are included with every project. After that, we offer optional monthly care plans starting at $290/mo for updates, performance monitoring and small changes.',
    },
    {
      q: 'What about hosting and domains?',
      a: 'You own everything. We help you set up hosting on Webflow, Vercel or wherever you prefer, point your domain, and hand the keys over. No vendor lock-in, no hidden fees.',
    },
    {
      q: 'Can you work with our existing brand and content?',
      a: 'Absolutely. If you have a brand book and ready copy, we move faster. If you don\'t, we can help shape both — or recommend a copywriter we trust.',
    },
    {
      q: 'How do payments work?',
      a: '50% to kick off, 50% on launch. No hourly billing, no scope-creep invoices. Bank transfer, card or Stripe Invoice — whatever\'s easiest for you.',
    },
  ];

  const [openIdx, setOpenIdx] = useState(0);

  return (
    <section id="faq" className="relative w-full bg-background py-16 md:py-28 scroll-mt-20">
      <div className="max-w-5xl mx-auto px-4 md:px-8">
        <div className="grid grid-cols-1 lg:grid-cols-[1fr_2fr] gap-10 md:gap-16">
          <div className="reveal">
            <div className="font-mono uppercase tracking-[0.22em] text-xs text-white/40 mb-4">/ FAQ</div>
            <h2 className="text-3xl md:text-4xl text-white font-normal tracking-tight leading-[1.05] mb-5">
              Questions, <span className="font-serif italic text-white/65">answered.</span>
            </h2>
            <p className="text-white/55 text-[15px] leading-relaxed mb-6">
              Can't find what you're looking for? Drop us a note — we usually reply within a few hours.
            </p>
            <a href="#contact" className="inline-flex items-center gap-2 text-sm text-white/80 hover:text-white border-b border-white/30 pb-0.5 transition-colors">
              Talk to a human
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                <line x1="5" y1="12" x2="19" y2="12"></line>
                <polyline points="12 5 19 12 12 19"></polyline>
              </svg>
            </a>
          </div>
          <div className="reveal">
            {items.map((it, i) => (
              <FAQItem
                key={i}
                q={it.q}
                a={it.a}
                open={openIdx === i}
                onClick={() => setOpenIdx(openIdx === i ? -1 : i)}
              />
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

// ---------- Final CTA ----------
function FinalCTA() {
  return (
    <section id="contact" className="relative w-full bg-background py-16 md:py-24 scroll-mt-20">
      <div className="max-w-7xl mx-auto px-4 md:px-8">
        <div className="relative rounded-3xl overflow-hidden border border-white/[0.06] reveal" style={{ background: 'linear-gradient(135deg, #141414 0%, #0A0A0A 100%)' }}>
          {/* glow */}
          <div aria-hidden className="absolute -top-40 -right-40 w-[600px] h-[600px] rounded-full opacity-50 pointer-events-none" style={{ background: 'radial-gradient(closest-side, rgba(255,86,86,0.35), transparent 70%)' }} />
          <div aria-hidden className="absolute -bottom-40 -left-40 w-[500px] h-[500px] rounded-full opacity-40 pointer-events-none" style={{ background: 'radial-gradient(closest-side, rgba(255,158,79,0.25), transparent 70%)' }} />
          {/* grid */}
          <div aria-hidden className="absolute inset-0 opacity-[0.05] pointer-events-none" style={{
            backgroundImage: 'linear-gradient(to right, rgba(255,255,255,0.6) 1px, transparent 1px), linear-gradient(to bottom, rgba(255,255,255,0.6) 1px, transparent 1px)',
            backgroundSize: '48px 48px',
          }} />

          <div className="relative p-8 md:p-16 lg:p-20 text-center">
            <div className="inline-flex items-center gap-2 bg-white/[0.06] border border-white/10 rounded-full px-3 py-1.5 text-xs text-white/75 mb-6">
              <span className="w-1.5 h-1.5 rounded-full bg-[#3FCF8E] animate-pulse" />
              Booking projects for June 2026
            </div>
            <h2 className="text-4xl md:text-5xl lg:text-6xl text-white font-normal tracking-tight max-w-3xl mx-auto leading-[1.02]">
              Ready to ship the website
              <br />
              <span className="font-serif italic grad-text">your company deserves?</span>
            </h2>
            <p className="text-white/55 max-w-xl mx-auto mt-6 text-[15px] md:text-base leading-relaxed">
              Two free strategy spots open this month. Book in for 30 minutes — we'll leave you with a plan and a fixed quote, whether you hire us or not.
            </p>
            <div className="flex items-center justify-center gap-3 mt-9 flex-wrap">
              <a href="#calculator-section" className="group inline-flex items-center gap-2 bg-white text-black rounded-full pl-5 pr-2 py-2 text-[15px] font-medium hover:bg-white/90 transition-colors">
                Get your estimate
                <span className="w-8 h-8 rounded-full bg-black flex items-center justify-center group-hover:translate-x-0.5 transition-transform">
                  <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="white" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                    <line x1="5" y1="12" x2="19" y2="12"></line>
                    <polyline points="12 5 19 12 12 19"></polyline>
                  </svg>
                </span>
              </a>
              <a href="mailto:hi@webfluin.studio" className="inline-flex items-center gap-2 bg-white/[0.05] hover:bg-white/[0.08] border border-white/10 text-white rounded-full px-5 py-3 text-[15px] font-medium transition-colors">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                  <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z" />
                  <polyline points="22,6 12,13 2,6" />
                </svg>
                hi@webfluin.studio
              </a>
            </div>
            <div className="text-xs font-mono text-white/30 mt-6 tracking-wider uppercase">
              No commitment · 30-min call · Plan delivered same week
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ---------- Footer ----------
function Footer() {
  const cols = [
    {
      title: 'Studio',
      links: [
        { label: 'Services', href: '#features' },
        { label: 'Process', href: '#process' },
        { label: 'Pricing', href: '#calculator-section' },
        { label: 'Case studies', href: '#testimonials' },
      ],
    },
    {
      title: 'Company',
      links: [
        { label: 'About', href: '#' },
        { label: 'Journal', href: '#' },
        { label: 'Careers', href: '#' },
        { label: 'Contact', href: '#contact' },
      ],
    },
    {
      title: 'Resources',
      links: [
        { label: 'Free brand audit', href: '#' },
        { label: 'Webflow templates', href: '#' },
        { label: 'Newsletter', href: '#' },
        { label: 'Refer & earn', href: '#' },
      ],
    },
    {
      title: 'Legal',
      links: [
        { label: 'Privacy', href: '#' },
        { label: 'Terms', href: '#' },
        { label: 'Cookies', href: '#' },
        { label: 'DPA', href: '#' },
      ],
    },
  ];

  return (
    <footer className="relative w-full bg-background border-t border-white/[0.06] pt-16 md:pt-20 pb-8">
      <div className="max-w-7xl mx-auto px-4 md:px-8">

        {/* Top: Logo + columns */}
        <div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-8 md:gap-12">
          <div className="col-span-2 lg:col-span-2">
            <a href="#top" className="flex items-center gap-2 mb-5">
              <span className="w-9 h-9 rounded-lg bg-gradient-to-br from-[#FF5656] to-[#FF9E4F] flex items-center justify-center text-white font-bold">W</span>
              <span className="text-white font-medium text-lg tracking-tight">Webfluin <span className="text-white/50 font-normal">Studio</span></span>
            </a>
            <p className="text-white/50 text-sm leading-relaxed max-w-xs mb-6">
              A two-person design & development studio building premium websites for ambitious founders.
            </p>
            <div className="flex items-center gap-2">
              <a href="#" aria-label="Twitter" className="w-9 h-9 rounded-full bg-white/[0.04] border border-white/10 flex items-center justify-center text-white/60 hover:text-white hover:border-white/25 transition-colors">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2H21l-6.52 7.45L22 22h-6.802l-4.97-6.5L4.6 22H2l7.005-8L2 2h6.93l4.5 5.94L18.244 2zm-1.18 18h1.84L7.06 4H5.1l11.964 16z"/></svg>
              </a>
              <a href="#" aria-label="Dribbble" className="w-9 h-9 rounded-full bg-white/[0.04] border border-white/10 flex items-center justify-center text-white/60 hover:text-white hover:border-white/25 transition-colors">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"/><path d="M8 2.5c4 5 6 11 6.5 19"/><path d="M2.5 14c5-1 11-1 19 1.5"/><path d="M21.5 9c-7 1.5-13 0-17.5-3"/></svg>
              </a>
              <a href="#" aria-label="LinkedIn" className="w-9 h-9 rounded-full bg-white/[0.04] border border-white/10 flex items-center justify-center text-white/60 hover:text-white hover:border-white/25 transition-colors">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M20.5 2h-17A1.5 1.5 0 002 3.5v17A1.5 1.5 0 003.5 22h17a1.5 1.5 0 001.5-1.5v-17A1.5 1.5 0 0020.5 2zM8 19H5v-9h3zM6.5 8.25A1.75 1.75 0 118.3 6.5a1.78 1.78 0 01-1.8 1.75zM19 19h-3v-4.74c0-1.42-.6-1.93-1.38-1.93-.83 0-1.62.62-1.62 1.95V19h-3v-9h2.9v1.3a3.11 3.11 0 012.7-1.4c1.55 0 3.36.86 3.36 3.66z"/></svg>
              </a>
              <a href="#" aria-label="Instagram" className="w-9 h-9 rounded-full bg-white/[0.04] border border-white/10 flex items-center justify-center text-white/60 hover:text-white hover:border-white/25 transition-colors">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><rect x="2" y="2" width="20" height="20" rx="5"/><path d="M16 11.4A4 4 0 1112.6 8 4 4 0 0116 11.4z"/><line x1="17.5" y1="6.5" x2="17.51" y2="6.5"/></svg>
              </a>
            </div>
          </div>

          {cols.map((col) => (
            <div key={col.title}>
              <div className="text-[10px] font-mono uppercase tracking-widest text-white/35 mb-4">{col.title}</div>
              <ul className="space-y-3">
                {col.links.map((l) => (
                  <li key={l.label}>
                    <a href={l.href} className="text-sm text-white/70 hover:text-white transition-colors">
                      {l.label}
                    </a>
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </div>

        {/* Mid: contact card */}
        <div className="mt-14 md:mt-20 grid grid-cols-1 md:grid-cols-3 gap-px bg-white/[0.06] border border-white/[0.06] rounded-2xl overflow-hidden">
          <div className="bg-[#0A0A0A] p-6">
            <div className="text-[10px] font-mono uppercase tracking-widest text-white/35 mb-2">Email</div>
            <a href="mailto:hi@webfluin.studio" className="text-white text-base hover:text-[#FF8E55] transition-colors">hi@webfluin.studio</a>
          </div>
          <div className="bg-[#0A0A0A] p-6">
            <div className="text-[10px] font-mono uppercase tracking-widest text-white/35 mb-2">Studio</div>
            <div className="text-white text-base">Lisbon, PT · Remote-first</div>
          </div>
          <div className="bg-[#0A0A0A] p-6">
            <div className="text-[10px] font-mono uppercase tracking-widest text-white/35 mb-2">Hours</div>
            <div className="text-white text-base">Mon–Fri · 9am–6pm WET</div>
          </div>
        </div>

        {/* Bottom: legal */}
        <div className="mt-12 pt-6 border-t border-white/[0.06] flex flex-col md:flex-row md:items-center justify-between gap-4">
          <div className="text-xs font-mono text-white/35">
            © 2026 Webfluin Studio. Crafted with care in Lisbon.
          </div>
          <div className="flex items-center gap-5 text-xs text-white/45">
            <div className="flex items-center gap-2">
              <span className="w-1.5 h-1.5 rounded-full bg-[#3FCF8E] animate-pulse" />
              <span>All systems operational</span>
            </div>
            <span className="text-white/20">·</span>
            <span>v2.4.1</span>
          </div>
        </div>
      </div>
    </footer>
  );
}

// ---------- App ----------
function App() {
  // Scroll-reveal observer
  useEffect(() => {
    const els = document.querySelectorAll('.reveal');
    if (!('IntersectionObserver' in window) || window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
      els.forEach(el => el.classList.add('is-visible'));
      return;
    }
    const io = new IntersectionObserver((entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          entry.target.classList.add('is-visible');
          io.unobserve(entry.target);
        }
      });
    }, { threshold: 0.08, rootMargin: '0px 0px -40px 0px' });
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  });

  const { Calculator } = window;

  return (
    <>
      <Nav />
      <main>
        <Hero />
        <Features />
        <Process />
        <Calculator />
        <Testimonials />
        <FAQ />
        <FinalCTA />
      </main>
      <Footer />
    </>
  );
}

Object.assign(window, { App });
