// sections.jsx — page sections for the 2build site.
// Hero, marquee strip, services, process, products, contact, footer.

// ── Stickers (floating SVG decor in hero) ──────────────────────────
const STICKERS = [
{ x: '6%', y: '12%', rot: -8, size: 56, kind: 'plus', color: 'var(--accent)' },
{ x: '88%', y: '8%', rot: 14, size: 80, kind: 'asterisk', color: 'var(--accent-2)' },
{ x: '4%', y: '78%', rot: -22, size: 70, kind: 'cube', color: 'var(--accent-3)' },
{ x: '92%', y: '70%', rot: 8, size: 64, kind: 'arrow', color: 'var(--accent)' },
{ x: '15%', y: '52%', rot: -12, size: 28, kind: 'dot', color: 'var(--accent-2)' },
{ x: '78%', y: '40%', rot: 18, size: 42, kind: 'bracket', color: 'var(--ink)' }];


function StickerShape({ kind, size, color }) {
  switch (kind) {
    case 'plus':
      return (
        <svg width={size} height={size} viewBox="0 0 24 24">
          <path d="M12 3v18M3 12h18" stroke={color} strokeWidth="3.5" strokeLinecap="round" />
        </svg>);

    case 'asterisk':
      return (
        <svg width={size} height={size} viewBox="0 0 24 24">
          <g stroke={color} strokeWidth="3" strokeLinecap="round">
            <path d="M12 4v16" />
            <path d="M4 8l16 8" />
            <path d="M4 16l16-8" />
          </g>
        </svg>);

    case 'cube':
      return (
        <svg width={size} height={size} viewBox="0 0 24 24">
          <g fill="none" stroke={color} strokeWidth="2" strokeLinejoin="round">
            <path d="M12 2L22 7v10l-10 5L2 17V7z" />
            <path d="M12 2v10M22 7l-10 5M2 7l10 5" />
          </g>
        </svg>);

    case 'arrow':
      return (
        <svg width={size} height={size} viewBox="0 0 24 24">
          <path d="M4 12h16M14 6l6 6-6 6" stroke={color} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" fill="none" />
        </svg>);

    case 'dot':
      return (
        <svg width={size} height={size} viewBox="0 0 24 24">
          <circle cx="12" cy="12" r="10" fill={color} />
        </svg>);

    case 'bracket':
      return (
        <svg width={size} height={size} viewBox="0 0 24 24">
          <g fill="none" stroke={color} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
            <path d="M8 3H4v18h4" />
            <path d="M16 3h4v18h-4" />
          </g>
        </svg>);

  }
  return null;
}

function Stickers() {
  return (
    <>
      {STICKERS.map((s, i) =>
      <span
        key={i}
        className="sticker"
        style={{
          left: s.x, top: s.y,
          '--rot': `${s.rot}deg`,
          animationDelay: `${i * 0.15}s, ${i * 0.6}s`
        }}>
        
          <StickerShape kind={s.kind} size={s.size} color={s.color} />
        </span>
      )}
    </>);

}

// ── Headline rotator (cycles through verbs) ─────────────────────────
function HeadlineRotator({ words = ['ship', 'design', 'build', 'launch'], interval = 2200 }) {
  const [idx, setIdx] = React.useState(0);
  React.useEffect(() => {
    const t = setInterval(() => setIdx((i) => (i + 1) % words.length), interval);
    return () => clearInterval(t);
  }, [words, interval]);
  // To loop smoothly we render the list twice and snap back at the end.
  return (
    <span className="rotator" aria-live="polite">
      <span className="rotator-track" style={{ transform: `translateY(-${idx}em)` }}>
        {words.map((w, i) => <span key={i}>{w}</span>)}
      </span>
    </span>);

}

// ── Nav bar ────────────────────────────────────────────────────────
function Nav({ logoVariant }) {
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const on = () => setScrolled(window.scrollY > 40);
    on();
    window.addEventListener('scroll', on, { passive: true });
    return () => window.removeEventListener('scroll', on);
  }, []);
  return (
    <nav className={`nav ${scrolled ? 'scrolled' : ''}`}>
      <a href="#top" aria-label="2build home">
        <Logo variant={logoVariant} size={22} />
      </a>
      <div className="nav-links">
        <a href="#services">Services</a>
        <a href="#process">Process</a>
        <a href="#products">Products</a>
      </div>
      <a href="mailto:ben@2build.me" className="nav-cta">Get in touch →</a>
    </nav>);

}

// ── Hero ───────────────────────────────────────────────────────────
function Hero({ logoVariant, layout, headline }) {
  const heroRef = React.useRef(null);
  const glowRef = React.useRef(null);

  // Mouse-tracking glow blob.
  React.useEffect(() => {
    const el = heroRef.current;
    const g = glowRef.current;
    if (!el || !g) return;
    const on = (e) => {
      const r = el.getBoundingClientRect();
      g.style.left = `${e.clientX - r.left}px`;
      g.style.top = `${e.clientY - r.top}px`;
    };
    el.addEventListener('mousemove', on);
    return () => el.removeEventListener('mousemove', on);
  }, []);

  // The default headline is composed of pieces so we can italicize / rotate parts.
  // If the user retypes it via a Tweak we render it as plain text.
  const isCustom = headline && headline.trim().length > 0;

  return (
    <section
      ref={heroRef}
      className="hero"
      id="top"
      data-layout={layout}
      data-screen-label="01 Hero">
      
      <div className="mouse-glow" ref={glowRef} />
      <div className="hero-grid container">
        <div>
          <span className="eyebrow reveal in">Software design & development studio</span>
          <h1 className="hero-heading reveal in" data-delay="1">
            {isCustom ?
            headline :

            <>
                We <HeadlineRotator /><br />
                software that<br />
                <span className="italic">earns its weight.</span>
              </>
            }
          </h1>
          <p className="hero-sub reveal in" data-delay="2">
            2build is a product studio crafting mobile apps, web platforms and
            on-chain products. We design, engineer and ship — end to end, with
            taste.
          </p>
          <div className="hero-actions reveal in" data-delay="3">
            <a href="mailto:ben@2build.me" className="btn btn-primary">
              Start a project <span className="arrow">→</span>
            </a>
            <a href="#services" className="btn btn-ghost">
              See what we do
            </a>
          </div>
        </div>
        {layout === 'split' && <HeroOrnament logoVariant={logoVariant} />}
      </div>
    </section>);

}

// Decorative ornament for split layout — an oversized "2" that hints at the logo.
function HeroOrnament({ logoVariant }) {
  return (
    <div
      style={{
        position: 'relative',
        aspectRatio: '1 / 1',
        maxWidth: 460,
        margin: '0 auto',
        justifySelf: 'end'
      }}>
      
      <svg viewBox="0 0 200 200" width="100%" height="100%">
        <defs>
          <linearGradient id="og" x1="0" x2="1" y1="0" y2="1">
            <stop offset="0%" stopColor="var(--accent)" />
            <stop offset="100%" stopColor="var(--accent-2)" />
          </linearGradient>
        </defs>
        <rect x="4" y="4" width="192" height="192" rx="36" fill="none" stroke="var(--line)" strokeWidth="1" />
        <text
          x="100"
          y="138"
          textAnchor="middle"
          fontFamily="var(--display)"
          fontWeight="500"
          fontSize="160"
          fill="url(#og)"
          style={{ letterSpacing: '-0.04em' }}>
          2</text>
        {/* construction marks */}
        <g stroke="var(--ink)" strokeWidth="1" opacity="0.4">
          <path d="M20 20 h12 M20 20 v12" />
          <path d="M180 20 h-12 M180 20 v12" />
          <path d="M20 180 h12 M20 180 v-12" />
          <path d="M180 180 h-12 M180 180 v-12" />
        </g>
        {/* annotated dimension */}
        <g fontFamily="var(--mono)" fontSize="9" fill="var(--ink-mute)">
          <text x="100" y="190" textAnchor="middle">2BUILD · MARK · 01</text>
        </g>
      </svg>
    </div>);

}

// ── Marquee strip ──────────────────────────────────────────────────
function Marquee() {
  const items = [
  'Design',
  'Build',
  'Ship',
  'Repeat'];

  const row =
  <div className="marquee-item">
      {items.map((it, i) =>
    <React.Fragment key={i}>
          <span className={i % 2 ? 'italic' : ''}>{it}</span>
          <span className="dot" />
        </React.Fragment>
    )}
    </div>;

  return (
    <div className="marquee" aria-hidden="true">
      <div className="marquee-track">
        {row}{row}{row}{row}
      </div>
    </div>);

}

// ── Services ───────────────────────────────────────────────────────
const SERVICES = [
{
  num: '01',
  name: 'UX & Product Design',
  desc: 'Research, flows, wireframes, hi-fi mocks and design systems. We start with the problem and design until the solution is obvious.',
  tags: ['Research', 'Systems', 'Prototyping', 'Brand'],
  span: 8,
  viz: 'design'
},
{
  num: '02',
  name: 'React Native',
  desc: 'Native-feeling iOS and Android apps from one codebase — Expo, custom modules, App Store delivery.',
  tags: ['Expo', 'iOS', 'Android'],
  span: 4,
  viz: 'rn'
},
{
  num: '03',
  name: 'Flutter',
  desc: 'When the design demands its own physics — Flutter\'s canvas gives us a clean slate.',
  tags: ['Dart', 'Skia', 'Custom UI'],
  span: 4,
  viz: 'flutter'
},
{
  num: '04',
  name: 'Next.js',
  desc: 'Production-grade web — App Router, server components, edge runtimes, the whole stack. Built to be fast and stay fast.',
  tags: ['App Router', 'RSC', 'Edge', 'Vercel'],
  span: 8,
  viz: 'next'
},
{
  num: '05',
  name: 'Web3',
  desc: 'Smart contracts, wallet flows, and frontends that don\'t feel like crypto. We make on-chain feel like product.',
  tags: ['EVM', 'Solidity', 'Wagmi', 'Viem'],
  span: 12,
  viz: 'web3'
}];


function ServiceViz({ kind }) {
  switch (kind) {
    case 'design':
      return (
        <svg viewBox="0 0 100 100" width="100%" height="100%">
          <circle cx="50" cy="50" r="36" fill="none" stroke="var(--accent)" strokeWidth="1.5" strokeDasharray="2 4" />
          <rect x="32" y="32" width="36" height="36" fill="none" stroke="var(--accent)" strokeWidth="1.5" />
          <path d="M14 50h72M50 14v72" stroke="var(--accent)" strokeWidth="1" />
        </svg>);

    case 'rn':
      return (
        <svg viewBox="0 0 100 100" width="100%" height="100%">
          <rect x="28" y="14" width="44" height="72" rx="8" fill="none" stroke="var(--accent)" strokeWidth="2" />
          <circle cx="50" cy="80" r="2" fill="var(--accent)" />
          <path d="M44 22h12" stroke="var(--accent)" strokeWidth="1.5" />
        </svg>);

    case 'flutter':
      return (
        <svg viewBox="0 0 100 100" width="100%" height="100%">
          <path d="M60 14L24 50l36 36M60 14L84 38 48 74M48 74l24 24" fill="none" stroke="var(--accent)" strokeWidth="2" strokeLinejoin="round" />
        </svg>);

    case 'next':
      return (
        <svg viewBox="0 0 100 100" width="100%" height="100%">
          <circle cx="50" cy="50" r="36" fill="none" stroke="var(--accent)" strokeWidth="2" />
          <path d="M38 32v36M38 32l28 36" stroke="var(--accent)" strokeWidth="2" strokeLinecap="round" />
        </svg>);

    case 'web3':
      return (
        <svg viewBox="0 0 100 100" width="100%" height="100%">
          <path d="M50 10L18 30v40l32 20 32-20V30z" fill="none" stroke="var(--accent)" strokeWidth="2" strokeLinejoin="round" />
          <path d="M50 10v80M18 30l64 40M82 30L18 70" stroke="var(--accent)" strokeWidth="1" />
        </svg>);

  }
  return null;
}

function Services() {
  return (
    <section className="section" id="services" data-screen-label="03 Services">
      <div className="container">
        <div className="services-head reveal">
          <div>
            <span className="eyebrow">What we do · 02</span>
            <h2 className="section-title">
              Generalists, with<br />
              <span className="italic">conviction.</span>
            </h2>
          </div>
          <p className="section-blurb">
            We're a small, opinionated team that handles design and engineering
            under one roof — so the brief, the pixels and the production code
            never drift apart.
          </p>
        </div>
        <div className="service-grid">
          {SERVICES.map((s, i) =>
          <article
            key={s.num}
            className="service-card reveal"
            data-span={s.span}
            data-delay={Math.min(i, 4)}>
            
              <div className="service-viz"><ServiceViz kind={s.viz} /></div>
              <div>
                <div className="service-num">— {s.num}</div>
                <h3 className="service-name">{s.name}</h3>
                <p className="service-desc">{s.desc}</p>
              </div>
            </article>
          )}
        </div>
      </div>
    </section>);

}

// ── Process ────────────────────────────────────────────────────────
const PROCESS = [
{ num: '01', name: 'Frame', desc: 'We start by getting embarrassingly specific about who you\'re for, what success looks like, and what we\'re not going to build.' },
{ num: '02', name: 'Sketch', desc: 'Cheap, ugly, fast. We move through ten directions before getting precious about any one of them.' },
{ num: '03', name: 'Design', desc: 'High-fidelity flows in a shared file. You poke at it daily; we iterate until it feels right.' },
{ num: '04', name: 'Build', desc: 'Production code on the same rails as the design. No throwaway prototypes, no hand-off cliff.' },
{ num: '05', name: 'Ship', desc: 'Launch, measure, sharpen. We stick around past the ribbon-cutting.' }];


function Process() {
  return (
    <section className="section" id="process" data-screen-label="04 Process">
      <div className="container">
        <div className="services-head reveal">
          <div>
            <span className="eyebrow">How we work · 03</span>
            <h2 className="section-title">
              Five steps,<br />
              <span className="italic">no surprises.</span>
            </h2>
          </div>
          <p className="section-blurb">
            Every engagement runs the same shape. We tell you where we are,
            what's next, and what we'd cut if we had to cut something today.
          </p>
        </div>
        <div className="process-list">
          {PROCESS.map((p, i) =>
          <div key={p.num} className="process-row reveal" data-delay={Math.min(i, 4)}>
              <div className="process-num">{p.num}</div>
              <div className="process-name">{p.name}</div>
              <div className="process-desc">{p.desc}</div>
            </div>
          )}
        </div>
      </div>
    </section>);

}

// ── Products ───────────────────────────────────────────────────────
// TopSet brand: "Top" + "Set" (accent) + small "+" (accent), JetBrains Mono 800.
function TopSetWordmark({ size = 56 }) {
  return (
    <span
      style={{
        fontFamily: '"JetBrains Mono", ui-monospace, monospace',
        fontWeight: 800,
        fontSize: size,
        letterSpacing: '-0.08em',
        lineHeight: 0.85,
        color: '#F4F4F5',
        display: 'inline-flex',
        alignItems: 'flex-end',
        gap: size * 0.04
      }}>
      
      Top<span style={{ color: '#FF4D2E' }}>Set</span>
      <span style={{ color: '#FF4D2E', fontSize: size * 0.5, fontWeight: 700, lineHeight: 1 }}>+</span>
    </span>);

}

function Products() {
  return (
    <section className="section" id="products" data-screen-label="05 Products">
      <div className="container">
        <div className="services-head reveal">
          <div>
            <span className="eyebrow">From our shelf · 04</span>
            <h2 className="section-title">
              Products we<br />
              <span className="italic">stand behind.</span>
            </h2>
          </div>
          <p className="section-blurb">
            Alongside client work, we build and run our own. They keep us
            honest — every problem you'd find in a client codebase, we feel it
            first.
          </p>
        </div>

        <a
          href="https://topset.2build.me"
          target="_blank"
          rel="noopener noreferrer"
          className="topset-card reveal">
          
          <div className="topset-copy">
            <div className="topset-brand">
              <TopSetWordmark size={64} />
            </div>
            <p className="topset-tagline">Earn the right to add weight.</p>
            <p className="topset-desc">
              The strength training journal we wanted to use. Plan your sets,
              track every rep, watch your numbers climb. Native iOS, Android
              and Apple Watch.
            </p>
            <div className="topset-meta" data-comment-anchor="c5a1161a5d-div-490-13">
              <span>iOS · Android · watchOS · Wear OS</span>
            </div>
            <div className="topset-link">
              Visit topset.2build.me <span className="arrow">↗</span>
            </div>
          </div>
          <div className="topset-stage" aria-hidden="true">
            <iframe
              src="topset/showcase.html"
              title="TopSet app screens"
              loading="lazy"
              tabIndex={-1} />
            
            <div className="topset-stage-fade" />
          </div>
        </a>
      </div>
    </section>);

}

// ── Contact ────────────────────────────────────────────────────────
function Contact() {
  return (
    <section className="section contact" id="contact" data-screen-label="06 Contact">
      <div className="container" style={{ position: 'relative', zIndex: 2 }}>
        <span className="contact-pre">Let's make something · 05</span>
        <h2 className="contact-headline">
          Got an idea<br />
          worth <span className="italic">building?</span>
        </h2>
        <a href="mailto:ben@2build.me" className="contact-email" data-comment-anchor="d020b76124-a-545-9">
          Let's talk!
        </a>
      </div>
    </section>);

}

// ── Footer ─────────────────────────────────────────────────────────
function Footer({ logoVariant }) {
  return (
    <footer className="footer">
      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        <LogoGlyph size={24} />
        <span>© 2026 2build LLC</span>
      </div>
      <div className="footer-links">
        <a href="#services">Services</a>
        <a href="#process">Process</a>
        <a href="#products">Products</a>
        <a href="mailto:ben@2build.me">Contact</a>
      </div>
      <span>Made with care, shipped with intent.</span>
    </footer>);

}

Object.assign(window, {
  Nav, Hero, Marquee, Services, Process, Products, Contact, Footer,
  HeadlineRotator, Stickers
});