/* Pages: Home, About, Services, Work
   Tasks lives in tasks.jsx (more complex). */

const { useState, useMemo } = React;

/* ──────────────────────────────────────────────
   HOME
   ────────────────────────────────────────────── */
function HomePage({ setRoute }) {
  return (
    <main className="page-enter" data-screen-label="Home">
      {/* HERO */}
      <section className="home-hero">
        <div className="shell home-hero-grid">
          <div className="home-hero-text">
            <div className="home-eyebrow-row">
              <span className="eyebrow">AI-powered marketing studio</span>
              <span className="home-avail">
                <span className="home-avail-dot"></span>
                Taking 2 clients · June
              </span>
            </div>
            <h1 className="home-h1">
              <span className="home-h1-by">by</span>
              <span className="home-h1-name">DELANEY<sup className="home-h1-sup">¹</sup></span>
            </h1>
            <p className="home-lede">
              Marketing for small businesses, built on AI and run by a human.
              I write the copy, design the systems, and ship the tools — websites,
              campaigns, and the AI products that make them work.
            </p>
            <div className="home-cta">
              <button className="btn" onClick={() => setRoute("work")}>
                See the work <span aria-hidden="true">→</span>
              </button>
              <button className="btn btn--ghost" onClick={() => setRoute("services")}>
                Start a project
              </button>
            </div>
          </div>

          <div className="home-hero-image">
            <image-slot
              id="home-hero"
              shape="rounded"
              radius="6"
              placeholder="Hero photo — portrait, work-in-progress, or product screenshot"
            ></image-slot>
          </div>
        </div>
      </section>

      {/* MANIFESTO STRIP */}
      <section className="home-manifesto">
        <div className="shell">
          <div className="manifesto-row">
            <div className="eyebrow">01 · The thesis</div>
            <p className="serif manifesto-body">
              Small businesses can't afford an agency
              and shouldn't have to settle for a template.
              <em> So I built a stack of AI tools</em> that do agency work
              at studio pace — and I run them, in person, for one client at a time.
            </p>
          </div>
        </div>
      </section>

      <hr className="divider" />

      {/* PRODUCTS — placeholder tiles for her AI tools */}
      <ProductsSection />

      <hr className="divider" />

      {/* SERVICE TEASER */}
      <section className="home-services">
        <div className="shell">
          <div className="home-services-head">
            <div>
              <div className="eyebrow">03 · What I do</div>
              <h2 className="home-h2">A short list, done well.</h2>
            </div>
            <button className="link-underline" onClick={() => setRoute("services")}>
              All services <span aria-hidden="true">→</span>
            </button>
          </div>
          <ul className="home-service-list">
            {[
              ["Website copy",        "Homepage, About, Services, the email signup line."],
              ["Social captions",     "Monthly packs that don't sound like every other small business."],
              ["Brand voice",         "A short guide your team can actually use."],
              ["Landing pages",       "One-page sites that convert without shouting."],
              ["Email writing",       "Welcome series, newsletters, the occasional sale."],
            ].map(([name, desc], i) => (
              <li key={name} className="home-service-row">
                <span className="home-service-num mono-num">0{i + 1}</span>
                <span className="home-service-name serif">{name}</span>
                <span className="home-service-desc">{desc}</span>
              </li>
            ))}
          </ul>
        </div>
      </section>

      {/* SELECTED WORK STRIP */}
      <section className="home-work band-cream-deep">
        <div className="shell home-work-inner">
          <div className="home-work-head">
            <div className="eyebrow">04 · Recently</div>
            <h2 className="home-h2">A few things that shipped.</h2>
          </div>
          <div className="home-work-grid">
            {[
              { kind: "Website",  client: "Manzanita Mercantile",  when: "Apr '26" },
              { kind: "Email",    client: "Salt Air Studio",       when: "Mar '26" },
              { kind: "Voice",    client: "Tide & Pine Candles",   when: "May '26" },
            ].map((p, i) => (
              <button key={i} className="home-work-tile" onClick={() => setRoute("work")}>
                <image-slot
                  id={"home-work-" + i}
                  shape="rect"
                  placeholder={p.client + " — drop a square photo of the work or shop"}
                ></image-slot>
                <div className="home-work-meta">
                  <span className="eyebrow">{p.kind}</span>
                  <span>·</span>
                  <span>{p.when}</span>
                </div>
                <div className="serif home-work-title">{p.client}</div>
              </button>
            ))}
          </div>
          <div className="home-work-cta">
            <button className="link-underline" onClick={() => setRoute("work")}>
              See all work <span aria-hidden="true">→</span>
            </button>
          </div>
        </div>
      </section>

      {/* CONTACT STRIP */}
      <section className="home-contact">
        <div className="shell home-contact-inner">
          <div>
            <div className="eyebrow">Have something in mind?</div>
            <div className="serif home-contact-line">
              Write me a paragraph about your business.<br />
              I'll write you back within a day.
            </div>
          </div>
          <a className="btn btn--terracotta" href="mailto:hi@bydelaney.com">
            hi@bydelaney.com <span aria-hidden="true">→</span>
          </a>
        </div>
      </section>

      <style>{`
        .home-hero { padding: clamp(56px, 10vw, 120px) 0 clamp(72px, 10vw, 120px); }
        .home-hero-grid {
          display: grid;
          grid-template-columns: 1.1fr 0.9fr;
          gap: clamp(32px, 6vw, 80px);
          align-items: center;
        }
        .home-eyebrow-row {
          display: flex;
          align-items: center;
          gap: 16px;
          margin-bottom: 28px;
          flex-wrap: wrap;
        }
        .home-avail {
          display: inline-flex;
          align-items: center;
          gap: 8px;
          font-size: 11px;
          letter-spacing: 0.12em;
          text-transform: uppercase;
          color: var(--sage-deep);
          padding: 4px 10px;
          background: rgba(168, 181, 160, 0.2);
          border-radius: 999px;
          font-weight: 500;
        }
        .home-avail-dot {
          width: 6px; height: 6px; border-radius: 999px;
          background: var(--sage-deep);
          animation: pulse 2s var(--ease) infinite;
        }
        @keyframes pulse {
          0%, 100% { opacity: 1; }
          50% { opacity: 0.4; }
        }
        .home-h1 {
          display: flex;
          flex-direction: column;
          gap: 4px;
          margin-bottom: 36px;
          line-height: 0.92;
        }
        .home-h1-by {
          font-family: var(--serif);
          font-style: italic;
          font-weight: 400;
          font-size: clamp(28px, 3vw, 40px);
          color: var(--ink-3);
          letter-spacing: 0.005em;
        }
        .home-h1-name {
          font-family: var(--display);
          font-weight: 900;
          font-size: clamp(72px, 12vw, 152px);
          color: var(--charcoal);
          letter-spacing: -0.01em;
          line-height: 0.95;
          text-transform: uppercase;
          display: inline-flex;
          align-items: baseline;
        }
        .home-h1-sup {
          font-family: var(--display);
          font-weight: 800;
          font-size: 0.42em;
          color: var(--terracotta);
          line-height: 1;
          margin-left: 2px;
          vertical-align: super;
        }
        .home-lede {
          font-family: var(--serif);
          font-size: clamp(19px, 1.9vw, 24px);
          line-height: 1.45;
          color: var(--ink-2);
          max-width: 480px;
          margin: 0 0 40px;
        }
        .home-cta {
          display: flex;
          gap: 14px;
          flex-wrap: wrap;
        }
        .home-hero-image {
          position: relative;
          aspect-ratio: 4 / 5;
          min-height: 320px;
        }
        @media (max-width: 820px) {
          .home-hero-grid { grid-template-columns: 1fr; }
          .home-hero-image { aspect-ratio: 4/3; }
        }

        .home-manifesto { padding: 40px 0 64px; }
        .manifesto-row {
          display: grid;
          grid-template-columns: 180px 1fr;
          gap: clamp(24px, 4vw, 64px);
          align-items: start;
        }
        .manifesto-body {
          font-size: clamp(22px, 2.4vw, 30px);
          line-height: 1.4;
          color: var(--charcoal);
          max-width: 820px;
          margin: 0;
        }
        .manifesto-body em { color: var(--terracotta-deep); font-style: italic; }
        @media (max-width: 720px) { .manifesto-row { grid-template-columns: 1fr; gap: 16px; } }

        .home-services { padding: 96px 0; }
        .home-services-head {
          display: flex;
          align-items: baseline;
          justify-content: space-between;
          gap: 24px;
          margin-bottom: 48px;
        }
        .home-h2 {
          font-family: var(--display);
          font-weight: 700;
          font-size: clamp(36px, 4.6vw, 56px);
          line-height: 1.05;
          margin-top: 12px;
          letter-spacing: -0.015em;
        }
        .home-service-list {
          list-style: none;
          margin: 0;
          padding: 0;
          border-top: 1px solid var(--line);
        }
        .home-service-row {
          display: grid;
          grid-template-columns: 60px 1.3fr 2fr;
          gap: 24px;
          align-items: baseline;
          padding: 28px 0;
          border-bottom: 1px solid var(--line);
        }
        .home-service-num {
          color: var(--ink-muted);
          font-size: 13px;
          font-feature-settings: "tnum";
        }
        .home-service-name {
          font-size: clamp(22px, 2.4vw, 32px);
          color: var(--charcoal);
        }
        .home-service-desc {
          font-size: 16px;
          color: var(--ink-2);
          line-height: 1.55;
        }
        @media (max-width: 720px) {
          .home-service-row { grid-template-columns: 40px 1fr; }
          .home-service-desc { grid-column: 2; }
        }

        .home-work { padding: 96px 0; }
        .home-work-head { margin-bottom: 48px; }
        .home-work-grid {
          display: grid;
          grid-template-columns: repeat(3, 1fr);
          gap: 32px;
        }
        .home-work-tile {
          background: none;
          border: 0;
          padding: 0;
          text-align: left;
          color: inherit;
          display: flex;
          flex-direction: column;
          gap: 16px;
          cursor: pointer;
          transition: transform var(--dur) var(--ease);
        }
        .home-work-tile:hover { transform: translateY(-2px); }
        .home-work-tile image-slot {
          aspect-ratio: 1;
          border-radius: 4px;
          overflow: hidden;
        }
        .home-work-meta {
          display: flex;
          align-items: baseline;
          gap: 10px;
          font-size: 12px;
          color: var(--ink-3);
        }
        .home-work-title {
          font-size: 22px;
          color: var(--charcoal);
        }
        .home-work-cta {
          margin-top: 48px;
          display: flex;
          justify-content: flex-end;
        }
        @media (max-width: 820px) {
          .home-work-grid { grid-template-columns: 1fr 1fr; gap: 20px; }
        }
        @media (max-width: 520px) {
          .home-work-grid { grid-template-columns: 1fr; }
        }

        .home-contact { padding: 96px 0 32px; }
        .home-contact-inner {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 32px;
          flex-wrap: wrap;
          padding-block: 56px;
          padding-inline: clamp(20px, 5vw, 56px);
          margin-inline: calc(-1 * var(--gutter));
          border-block: 1px solid var(--line);
          background: var(--cream-deep);
        }
        .home-contact-line {
          font-size: clamp(24px, 2.8vw, 34px);
          line-height: 1.3;
          margin-top: 10px;
          color: var(--charcoal);
          max-width: 520px;
        }
        @media (max-width: 600px) {
          .home-contact-inner { padding-block: 40px; padding-inline: 24px; }
        }
      `}</style>
    </main>
  );
}

/* ──────────────────────────────────────────────
   ABOUT — minimal real bio; rest is hers to write
   ────────────────────────────────────────────── */
function AboutPage() {
  return (
    <main className="page-enter" data-screen-label="About">
      <section className="about-top">
        <div className="shell">
          <div className="eyebrow">About</div>
          <h1 className="about-h1 display-mark">
            DELANEY<sup className="about-h1-sup">¹</sup>
          </h1>
          <p className="about-tagline">
            Marketer, builder, student.<br />
            San Diego raised, Chico based.
          </p>
        </div>
      </section>

      <section className="shell about-body">
        <div className="about-image-col">
          <image-slot
            id="about-portrait"
            shape="rounded"
            radius="6"
            placeholder="Portrait — natural light, working at a desk, or outside. Vertical."
          ></image-slot>
          <div className="about-caption">
            <span className="eyebrow">For her photo</span>
          </div>
        </div>

        <div className="about-text-col">
          <div className="about-bio">
            <div className="eyebrow">The bio</div>
            <p className="about-lede">
              Grew up in San Diego.<br />
              Now in Northern California, going to Chico State.
            </p>
          </div>

          <div className="about-placeholder">
            <div className="placeholder-mark display-mark">¹</div>
            <div className="eyebrow">Delaney writes this part herself</div>
            <p className="placeholder-note">
              This is where her real bio goes — in her own voice, at her own
              pace. The first task on the board is going to be writing it.
              Anything I put here would be fiction, and fiction's not the brand.
            </p>
          </div>

          <div className="about-meta">
            <div className="about-meta-row">
              <div className="eyebrow">Based</div>
              <div className="about-meta-val">Chico, CA · remote-first</div>
            </div>
            <div className="about-meta-row">
              <div className="eyebrow">Working with</div>
              <div className="about-meta-val">Small businesses, anywhere in the U.S.</div>
            </div>
            <div className="about-meta-row">
              <div className="eyebrow">Reach</div>
              <div className="about-meta-val">
                <a className="link-underline" href="mailto:hi@bydelaney.com">hi@bydelaney.com</a>
              </div>
            </div>
          </div>
        </div>
      </section>

      <style>{`
        .about-top { padding: clamp(48px, 8vw, 96px) 0 32px; }
        .about-h1 {
          font-family: var(--display);
          font-weight: 900;
          font-size: clamp(72px, 11vw, 168px);
          line-height: 0.95;
          letter-spacing: -0.02em;
          margin-top: 24px;
          color: var(--charcoal);
          display: inline-flex;
          align-items: baseline;
        }
        .about-h1-sup {
          font-family: var(--display);
          font-weight: 800;
          font-size: 0.42em;
          color: var(--terracotta);
          line-height: 1;
          margin-left: 2px;
        }
        .about-tagline {
          font-family: var(--serif);
          font-style: italic;
          font-size: clamp(20px, 2vw, 26px);
          line-height: 1.4;
          color: var(--ink-2);
          margin: 24px 0 0;
          max-width: 480px;
        }
        .about-body {
          display: grid;
          grid-template-columns: 0.9fr 1.1fr;
          gap: clamp(40px, 6vw, 96px);
          padding-top: 64px;
          padding-bottom: 32px;
          align-items: start;
        }
        .about-image-col { position: sticky; top: 96px; }
        .about-image-col image-slot {
          aspect-ratio: 4/5;
          border-radius: 6px;
          overflow: hidden;
          display: block;
        }
        .about-caption {
          margin-top: 14px;
          text-align: right;
        }

        .about-bio {
          padding-bottom: 32px;
          border-bottom: 1px solid var(--line);
          margin-bottom: 40px;
        }
        .about-lede {
          font-family: var(--serif);
          font-size: clamp(22px, 2.4vw, 32px);
          line-height: 1.35;
          color: var(--charcoal);
          margin: 16px 0 0;
        }

        .about-placeholder {
          padding: 40px;
          border: 1px dashed var(--line-strong);
          border-radius: 4px;
          background: var(--cream-deep);
          display: flex;
          flex-direction: column;
          gap: 14px;
          align-items: flex-start;
          margin-bottom: 48px;
        }
        .placeholder-mark {
          font-size: 48px;
          line-height: 1;
          color: var(--terracotta);
          font-weight: 800;
        }
        .placeholder-note {
          font-family: var(--serif);
          font-size: 17px;
          line-height: 1.5;
          color: var(--ink-2);
          margin: 0;
          max-width: 480px;
        }

        .about-meta {
          display: flex;
          flex-direction: column;
          gap: 18px;
        }
        .about-meta-row {
          display: grid;
          grid-template-columns: 140px 1fr;
          gap: 24px;
          padding-bottom: 16px;
          border-bottom: 1px solid var(--line);
          align-items: baseline;
        }
        .about-meta-row:last-child { border-bottom: 0; }
        .about-meta-val {
          font-family: var(--serif);
          font-size: 18px;
          color: var(--charcoal);
        }

        @media (max-width: 820px) {
          .about-body { grid-template-columns: 1fr; }
          .about-image-col { position: static; max-width: 380px; }
          .about-meta-row { grid-template-columns: 1fr; gap: 4px; }
        }
      `}</style>
    </main>
  );
}

/* ──────────────────────────────────────────────
   SERVICES
   ────────────────────────────────────────────── */
const SERVICES = [
  {
    num: "01",
    name: "Website copy",
    price: 400,
    blurb:
      "A homepage, About, and Services page that sounds like you on a good day. Includes one round of revisions and a 1-page voice cheat-sheet so anyone on your team can write in the same tone.",
    bullets: ["3 pages of copy", "Voice cheat-sheet", "1 revision", "2-week turnaround"],
  },
  {
    num: "02",
    name: "Social captions",
    price: 250,
    unit: "/ month",
    blurb:
      "8 captions a month, delivered the last week of the month, scheduled and ready. Written in your voice from a 30-minute kickoff call. No hashtag fluff.",
    bullets: ["8 captions / month", "Quarterly voice check-in", "Built around your real calendar", "Cancel any time"],
  },
  {
    num: "03",
    name: "Brand voice guide",
    price: 600,
    blurb:
      "One page. Three do's, three don'ts, five example sentences in your voice. Enough that the next person you hire to write something already knows how.",
    bullets: ["1-page guide", "Sample lines", "Voice training call", "Forever yours"],
  },
  {
    num: "04",
    name: "Landing page",
    price: 800,
    blurb:
      "Copy + a clean Webflow or Framer page. For a launch, a new service, or the one product that's actually paying the bills. Mobile-first, fast, no template-y bullshit.",
    bullets: ["Full page copy", "Webflow / Framer build", "1 revision", "Goes live in 2 weeks"],
  },
  {
    num: "05",
    name: "Email writing",
    price: 200,
    blurb:
      "A welcome series, a monthly newsletter, or that one launch email that's been a draft for three weeks. Reads like a note, not a campaign.",
    bullets: ["1 sequence (3–5 emails)", "Or 1 month of newsletters", "1 revision", "Subject lines included"],
  },
];

function ServicesPage({ setRoute }) {
  return (
    <main className="page-enter" data-screen-label="Services">
      <section className="services-top">
        <div className="shell">
          <div className="eyebrow">Services</div>
          <h1 className="services-h1 serif">
            Five things,<br />done well.
          </h1>
          <p className="services-lede">
            Prices below are starting points. Most projects land within 10% of them.
            Quotes are flat — no hourly billing, no surprise invoices.
          </p>
        </div>
      </section>

      <section className="shell services-list">
        {SERVICES.map((s) => (
          <article key={s.num} className="service-row">
            <div className="service-num mono-num">{s.num}</div>
            <div className="service-main">
              <h2 className="service-name serif">{s.name}</h2>
              <p className="service-blurb">{s.blurb}</p>
              <ul className="service-bullets">
                {s.bullets.map((b) => (
                  <li key={b}><span>→</span> {b}</li>
                ))}
              </ul>
            </div>
            <div className="service-price">
              <div className="eyebrow">Starts at</div>
              <div className="service-price-amount serif">
                ${s.price.toLocaleString()}
                {s.unit && <span className="service-price-unit">{s.unit}</span>}
              </div>
              <a className="link-underline" href="mailto:hi@bydelaney.com">
                Start a project <span aria-hidden="true">→</span>
              </a>
            </div>
          </article>
        ))}
      </section>

      <section className="services-faq band-cream-deep">
        <div className="shell services-faq-inner">
          <div>
            <div className="eyebrow">FAQ</div>
            <h2 className="services-faq-h">A few things people ask.</h2>
          </div>
          <dl className="faq-list">
            {[
              ["Can I bundle services?", "Yes. A website + voice guide + first month of emails is the most common ask. We just price it as one project."],
              ["Do you work outside California?", "Yes — most of my clients aren't in California. I just take meetings on Pacific time."],
              ["What if I don't love the first draft?", "We do one revision built in. Most projects don't need it. The ones that do, it's because the brief was unclear, which is my fault."],
              ["Do you do logos / design / dev?", "No. I write. I can hand off to a designer or developer I trust if you need one."],
            ].map(([q, a]) => (
              <div key={q} className="faq-row">
                <dt className="serif faq-q">{q}</dt>
                <dd className="faq-a">{a}</dd>
              </div>
            ))}
          </dl>
        </div>
      </section>

      <section className="services-cta">
        <div className="shell services-cta-inner">
          <h2 className="serif services-cta-h">Tell me about your business.</h2>
          <p>A paragraph is enough. I'll write back within a day.</p>
          <a className="btn btn--terracotta" href="mailto:hi@bydelaney.com">
            hi@bydelaney.com <span aria-hidden="true">→</span>
          </a>
        </div>
      </section>

      <style>{`
        .services-top { padding: clamp(48px, 8vw, 96px) 0 48px; }
        .services-h1 {
          font-family: var(--display);
          font-weight: 800;
          font-size: clamp(56px, 8vw, 112px);
          line-height: 1.0;
          letter-spacing: -0.02em;
          margin-top: 24px;
        }
        .services-lede {
          font-family: var(--serif);
          font-size: clamp(18px, 1.8vw, 22px);
          color: var(--ink-2);
          max-width: 540px;
          margin: 32px 0 0;
          line-height: 1.5;
        }

        .services-list { padding-block: 32px 64px; }
        .service-row {
          display: grid;
          grid-template-columns: 80px 1.4fr 0.9fr;
          gap: 48px;
          padding: 48px 0;
          border-bottom: 1px solid var(--line);
          align-items: start;
        }
        .service-row:first-child { border-top: 1px solid var(--line); }
        .service-num {
          font-size: 13px;
          color: var(--ink-muted);
          letter-spacing: 0.08em;
          padding-top: 6px;
        }
        .service-name {
          font-size: clamp(28px, 3.2vw, 40px);
          line-height: 1.1;
          margin-bottom: 16px;
        }
        .service-blurb {
          font-family: var(--serif);
          font-size: 18px;
          line-height: 1.55;
          color: var(--ink-2);
          margin: 0 0 20px;
        }
        .service-bullets {
          list-style: none;
          margin: 0;
          padding: 0;
          display: grid;
          grid-template-columns: 1fr 1fr;
          gap: 8px 24px;
          font-size: 14px;
          color: var(--ink-2);
        }
        .service-bullets span { color: var(--terracotta); margin-right: 6px; }
        .service-price {
          padding: 24px;
          border: 1px solid var(--line);
          background: var(--cream-deep);
          border-radius: 4px;
          display: flex;
          flex-direction: column;
          gap: 8px;
          align-items: flex-start;
        }
        .service-price-amount {
          font-size: 48px;
          line-height: 1;
          color: var(--charcoal);
          margin: 4px 0 12px;
          display: flex;
          align-items: baseline;
          gap: 6px;
        }
        .service-price-unit {
          font-size: 16px;
          color: var(--ink-3);
          font-family: var(--sans);
        }
        @media (max-width: 820px) {
          .service-row { grid-template-columns: 40px 1fr; gap: 24px; }
          .service-price { grid-column: 2; margin-top: 16px; }
          .service-bullets { grid-template-columns: 1fr; }
        }

        .services-faq { padding: 96px 0; margin-top: 48px; }
        .services-faq-inner {
          display: grid;
          grid-template-columns: 0.7fr 1.3fr;
          gap: 64px;
          align-items: start;
        }
        .services-faq-h {
          font-size: clamp(32px, 4vw, 48px);
          line-height: 1.05;
          margin-top: 12px;
        }
        .faq-list { margin: 0; padding: 0; display: flex; flex-direction: column; gap: 28px; }
        .faq-row { display: grid; gap: 8px; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
        .faq-row:last-child { border-bottom: 0; padding-bottom: 0; }
        .faq-q { font-size: 22px; color: var(--charcoal); margin: 0; }
        .faq-a { margin: 0; color: var(--ink-2); font-size: 16px; line-height: 1.55; }
        @media (max-width: 720px) { .services-faq-inner { grid-template-columns: 1fr; gap: 24px; } }

        .services-cta { padding: 96px 0 32px; }
        .services-cta-inner {
          text-align: center;
          max-width: 640px;
          margin: 0 auto;
          display: flex;
          flex-direction: column;
          align-items: center;
          gap: 16px;
        }
        .services-cta-h { font-size: clamp(32px, 4.5vw, 56px); line-height: 1.1; }
        .services-cta p { color: var(--ink-2); font-family: var(--serif); font-size: 20px; margin: 0; }
        .services-cta a { margin-top: 16px; }
      `}</style>
    </main>
  );
}

/* ──────────────────────────────────────────────
   WORK / PORTFOLIO
   ────────────────────────────────────────────── */
function WorkPage({ tasks, setRoute }) {
  const [view, setView] = useState("filled"); // 'filled' or 'empty'

  // Approved+paid+public tasks become portfolio entries
  const portfolioFromTasks = useMemo(() => {
    return tasks
      .filter((t) => t.is_public && (t.status === "approved" || t.status === "paid"))
      .map((t) => ({
        id: t.id,
        title: t.title,
        kind: inferKind(t.title),
        summary: t.brief,
        when: fmtDate(t.approved_at || t.submitted_at),
        deliverable_url: t.deliverable_url,
      }));
  }, [tasks]);

  const allWork = view === "empty"
    ? []
    : [...portfolioFromTasks, ...PORTFOLIO_EXTRA];

  return (
    <main className="page-enter" data-screen-label="Work">
      <section className="work-top">
        <div className="shell">
          <div className="work-top-row">
            <div>
              <div className="eyebrow">Work</div>
              <h1 className="work-h1 serif">
                Every project,<br />once it's out the door.
              </h1>
              <p className="work-lede">
                This feed builds itself. Every task that ships and is marked
                public lands here automatically. No curation, no polishing —
                just what actually happened.
              </p>
            </div>
            <div className="work-view-toggle">
              <span className="eyebrow" style={{ marginRight: 12 }}>Preview</span>
              <button
                className={"work-view-btn" + (view === "filled" ? " is-on" : "")}
                onClick={() => setView("filled")}
              >Filled</button>
              <button
                className={"work-view-btn" + (view === "empty" ? " is-on" : "")}
                onClick={() => setView("empty")}
              >Empty (launch day)</button>
            </div>
          </div>
        </div>
      </section>

      <section className="shell work-grid-wrap">
        {allWork.length === 0 ? (
          <div className="work-empty">
            <div className="work-empty-mark serif">
              ¹
            </div>
            <h2 className="serif work-empty-h">First project ships soon.</h2>
            <p className="work-empty-p">
              The portfolio is built on a feed — every project that wraps lands here on its own.
              On launch day it's empty. By the end of the month, it shouldn't be.
            </p>
            <button className="btn btn--ghost" onClick={() => setRoute("services")}>
              See what I do
            </button>
          </div>
        ) : (
          <div className="work-grid">
            {allWork.map((p, i) => (
              <article key={p.id} className={"work-tile" + (i === 0 ? " work-tile--lead" : "")}>
                <div className="work-tile-img">
                  <image-slot
                    id={"work-" + p.id}
                    shape="rect"
                    placeholder={p.title + " — drop a photo or screenshot of the work"}
                  ></image-slot>
                </div>
                <div className="work-tile-body">
                  <div className="work-tile-meta">
                    <span className="eyebrow">{p.kind || "Project"}</span>
                    <span>·</span>
                    <span>{p.when || "Recently"}</span>
                  </div>
                  <h3 className="serif work-tile-title">{p.title}</h3>
                  <p className="work-tile-summary">{p.summary}</p>
                  {p.deliverable_url && (
                    <a className="link-underline" href={p.deliverable_url}>
                      Read it <span aria-hidden="true">→</span>
                    </a>
                  )}
                </div>
              </article>
            ))}
          </div>
        )}
      </section>

      <style>{`
        .work-top { padding: clamp(48px, 8vw, 96px) 0 32px; }
        .work-top-row {
          display: flex;
          gap: 24px;
          justify-content: space-between;
          align-items: flex-end;
          flex-wrap: wrap;
        }
        .work-h1 {
          font-family: var(--display);
          font-weight: 800;
          font-size: clamp(48px, 7vw, 96px);
          line-height: 1.08;
          margin: 24px 0 0;
          letter-spacing: -0.02em;
        }
        .work-lede {
          font-family: var(--serif);
          font-size: 19px;
          color: var(--ink-2);
          max-width: 540px;
          margin: 28px 0 0;
          line-height: 1.5;
        }
        .work-view-toggle {
          display: inline-flex;
          align-items: center;
          padding: 6px;
          border: 1px solid var(--line);
          border-radius: 999px;
          background: var(--cream-deep);
          margin-top: 24px;
        }
        .work-view-btn {
          background: none;
          border: 0;
          padding: 8px 14px;
          border-radius: 999px;
          font-size: 13px;
          color: var(--ink-3);
        }
        .work-view-btn.is-on { background: var(--charcoal); color: var(--cream); }

        .work-grid-wrap { padding-block: 64px 32px; }
        .work-grid {
          display: grid;
          grid-template-columns: repeat(2, 1fr);
          gap: 56px 40px;
        }
        .work-tile { display: flex; flex-direction: column; gap: 20px; }
        .work-tile-img {
          aspect-ratio: 4/3;
          border-radius: 4px;
          overflow: hidden;
        }
        .work-tile--lead { grid-column: 1 / -1; }
        .work-tile--lead .work-tile-img { aspect-ratio: 21/9; }
        .work-tile-meta { display: flex; align-items: baseline; gap: 10px; font-size: 12px; color: var(--ink-3); }
        .work-tile-title { font-size: clamp(22px, 2.4vw, 32px); line-height: 1.15; margin: 4px 0 8px; }
        .work-tile-summary { color: var(--ink-2); font-size: 16px; line-height: 1.55; margin: 0 0 12px; max-width: 560px; }
        @media (max-width: 720px) { .work-grid { grid-template-columns: 1fr; gap: 40px; } }

        .work-empty {
          padding: 96px 24px;
          border: 1px dashed var(--line-strong);
          border-radius: 4px;
          background: var(--cream-deep);
          text-align: center;
          display: flex;
          flex-direction: column;
          align-items: center;
          gap: 16px;
        }
        .work-empty-mark {
          font-size: 96px;
          line-height: 1;
          color: var(--terracotta-deep);
          font-style: italic;
        }
        .work-empty-h { font-size: clamp(28px, 3.6vw, 40px); margin-top: 8px; }
        .work-empty-p { color: var(--ink-2); max-width: 480px; margin: 0 0 8px; font-size: 16px; }
      `}</style>
    </main>
  );
}

function inferKind(title) {
  const t = title.toLowerCase();
  if (t.includes("instagram") || t.includes("caption") || t.includes("social")) return "Social";
  if (t.includes("email") || t.includes("welcome")) return "Email";
  if (t.includes("about") || t.includes("rewrite") || t.includes("website") || t.includes("landing")) return "Website";
  if (t.includes("voice") || t.includes("brand")) return "Voice";
  return "Project";
}

/* ──────────────────────────────────────────────
   PRODUCTS — tile grid for Delaney's AI products
   Six placeholder tiles she can fill in later.
   ────────────────────────────────────────────── */
const PLACEHOLDER_PRODUCTS = [
  {
    id: "p1",
    num: "01",
    status: "LIVE",
    name: "Schedule My Haircut",
    tagline: "An AI front desk for the salon of one. Emily fills your openings, sends reminders, charges late fees, collects tips.",
    cta: "Open schedulemyhaircut.com",
    href: "https://schedulemyhaircut.com",
    image: "https://images.unsplash.com/photo-1585747860715-2ba37e788b70?w=800&q=80&auto=format&fit=crop",
  },
  {
    id: "p2",
    num: "02",
    status: "LIVE",
    name: "Speak Your Idea",
    tagline: "Talk to AI. It remembers everything. Logos, sites, designs — vibed into existence.",
    cta: "Open speakyouridea.com",
    href: "https://speakyouridea.com",
    image: "https://images.unsplash.com/photo-1589903308904-1010c2294adc?w=800&q=80&auto=format&fit=crop",
  },
  {
    id: "p3",
    num: "03",
    status: "LIVE",
    name: "Dragon Drop",
    tagline: "Drop any document. Understand everything. Contracts, leases, medical bills — instant AI analysis, free.",
    cta: "Open mydragondrop.com",
    href: "https://mydragondrop.com",
    image: "https://images.unsplash.com/photo-1568667256549-094345857637?w=800&q=80&auto=format&fit=crop",
  },
  {
    id: "p4",
    num: "04",
    status: "SOON",
    name: "Laney Mae Apparel",
    tagline: "A women's clothing shop blooming this spring. Sunflower fabrics, denim love, the right clothes for the right moments.",
    cta: "Notify me",
    href: "https://laneymae.com",
    image: "https://images.unsplash.com/photo-1597848212624-a19eb35e2651?w=800&q=80&auto=format&fit=crop",
  },
];

function ProductsSection() {
  return (
    <section className="products" data-screen-label="Products">
      <div className="shell">
        <div className="products-head">
          <div>
            <div className="eyebrow">02 · The stack</div>
            <h2 className="products-h">
              AI built for marketing,<br />
              not the other way around.
            </h2>
            <p className="products-sub">
              Small AI tools I've built to do the unglamorous parts of marketing —
              fast, consistently, in voice.
              Drop them into your stack, or hire me and they come free.
            </p>
          </div>
          <div className="products-meta">
            <div className="products-meta-row">
              <span className="products-meta-num mono-num">04</span>
              <span className="products-meta-label">total tools</span>
            </div>
            <div className="products-meta-row">
              <span className="products-meta-num mono-num" style={{ color: "var(--sage-deep)" }}>03</span>
              <span className="products-meta-label">live</span>
            </div>
            <div className="products-meta-row">
              <span className="products-meta-num mono-num" style={{ color: "var(--terracotta-deep)" }}>01</span>
              <span className="products-meta-label">shipping soon</span>
            </div>
          </div>
        </div>

        <div className="products-grid">
          {PLACEHOLDER_PRODUCTS.map((p) => (
            <article key={p.id} className="product-tile">
              <div className="product-tile-img">
                {p.image ? (
                  <img src={p.image} alt={p.name} loading="lazy" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
                ) : (
                  <image-slot
                    id={"product-" + p.id}
                    shape="rect"
                    placeholder={"Product " + p.num + " — drop a screenshot, mark, or 1:1 illustration"}
                  ></image-slot>
                )}
              </div>
              <div className="product-tile-body">
                <div className="product-tile-head">
                  <span className="product-num mono-num">{p.num}</span>
                  <span className={"product-status product-status--" + p.status.toLowerCase()}>
                    <span className="product-status-dot"></span>{p.status}
                  </span>
                </div>
                <h3 className="product-name">{p.name}</h3>
                <p className="product-tag">{p.tagline}</p>
                <a className="product-cta link-underline" href={p.href} target="_blank" rel="noopener">
                  {p.cta} <span aria-hidden="true">→</span>
                </a>
              </div>
            </article>
          ))}
        </div>

        <div className="products-foot">
          <span className="eyebrow">Want to white-label one?</span>
          <a className="link-underline" href="mailto:hi@bydelaney.com">
            Talk to me <span aria-hidden="true">→</span>
          </a>
        </div>
      </div>

      <style>{`
        .products { padding: clamp(72px, 10vw, 120px) 0; }
        .products-head {
          display: grid;
          grid-template-columns: 1.4fr 1fr;
          gap: 64px;
          align-items: end;
          margin-bottom: 64px;
        }
        .products-h {
          font-family: var(--display);
          font-weight: 700;
          font-size: clamp(36px, 4.8vw, 60px);
          line-height: 1.05;
          margin-top: 14px;
          letter-spacing: -0.02em;
        }
        .products-sub {
          font-family: var(--serif);
          font-size: 18px;
          line-height: 1.5;
          color: var(--ink-2);
          margin: 20px 0 0;
          max-width: 540px;
        }
        .products-meta {
          display: flex;
          flex-direction: column;
          gap: 10px;
          padding-left: 32px;
          border-left: 1px solid var(--line);
        }
        .products-meta-row {
          display: flex;
          align-items: baseline;
          gap: 14px;
        }
        .products-meta-num {
          font-family: var(--display);
          font-weight: 700;
          font-size: 28px;
          color: var(--charcoal);
          line-height: 1;
        }
        .products-meta-label {
          font-size: 11px;
          letter-spacing: 0.18em;
          text-transform: uppercase;
          color: var(--ink-3);
        }

        .products-grid {
          display: grid;
          grid-template-columns: repeat(3, 1fr);
          gap: 1px;
          background: var(--line);
          border: 1px solid var(--line);
          border-radius: 4px;
          overflow: hidden;
        }
        .product-tile {
          background: var(--cream);
          padding: 28px;
          display: flex;
          flex-direction: column;
          gap: 20px;
          transition: background var(--dur) var(--ease);
          min-height: 320px;
        }
        .product-tile:hover { background: var(--cream-deep); }
        .product-tile-img {
          aspect-ratio: 16/10;
          border: 1px solid var(--line);
          border-radius: 4px;
          overflow: hidden;
          background: var(--cream-deep);
        }
        .product-tile-img image-slot { width: 100%; height: 100%; display: block; }
        .product-tile-body { display: flex; flex-direction: column; gap: 8px; flex: 1; }
        .product-tile-head {
          display: flex;
          align-items: center;
          justify-content: space-between;
        }
        .product-num {
          font-size: 11px;
          letter-spacing: 0.1em;
          color: var(--ink-muted);
        }
        .product-status {
          display: inline-flex;
          align-items: center;
          gap: 6px;
          font-family: var(--sans);
          font-size: 10px;
          font-weight: 600;
          letter-spacing: 0.15em;
          padding: 3px 8px;
          border-radius: 999px;
        }
        .product-status-dot {
          width: 5px; height: 5px; border-radius: 999px;
          background: currentColor;
        }
        .product-status--live {
          color: var(--sage-deep);
          background: rgba(168, 181, 160, 0.22);
        }
        .product-status--beta {
          color: var(--terracotta-deep);
          background: rgba(235, 202, 214, 0.55);
        }
        .product-status--soon {
          color: var(--ink-3);
          background: var(--cream-deep);
          border: 1px solid var(--line);
        }
        .product-name {
          font-family: var(--display);
          font-weight: 700;
          font-size: 22px;
          color: var(--charcoal);
          margin: 4px 0 2px;
          letter-spacing: -0.005em;
        }
        .product-tag {
          font-family: var(--serif);
          font-size: 15px;
          line-height: 1.45;
          color: var(--ink-2);
          margin: 0;
          flex: 1;
        }
        .product-cta {
          background: none;
          border: 0;
          padding: 0;
          color: var(--charcoal);
          font-family: var(--sans);
          font-size: 13px;
          align-self: flex-start;
          margin-top: 4px;
        }

        .products-foot {
          margin-top: 40px;
          display: flex;
          align-items: baseline;
          justify-content: space-between;
          gap: 16px;
          padding-top: 24px;
          border-top: 1px solid var(--line);
        }

        @media (max-width: 1000px) {
          .products-grid { grid-template-columns: repeat(2, 1fr); }
          .products-head { grid-template-columns: 1fr; gap: 32px; }
          .products-meta { border-left: 0; padding-left: 0; flex-direction: row; gap: 32px; }
        }
        @media (max-width: 600px) {
          .products-grid { grid-template-columns: 1fr; }
        }
      `}</style>
    </section>
  );
}

Object.assign(window, { HomePage, AboutPage, ServicesPage, WorkPage, ProductsSection });
