/* eslint-disable */
const { useState, useMemo, useEffect, useRef } = React;

// ---------- shared atoms ----------

function Pill({ children, dark = false, style }) {
  return (
    <span
      style={{
        display: "inline-flex",
        alignItems: "center",
        gap: 8,
        padding: "10px 18px",
        borderRadius: 999,
        background: dark ? "var(--ink)" : "transparent",
        color: dark ? "var(--on-dark)" : "var(--ink)",
        fontFamily: "La Villa",
        fontSize: 11,
        letterSpacing: "0.22em",
        textTransform: "uppercase",
        fontWeight: 500,
        whiteSpace: "nowrap",
        ...style
      }}>
      
      {children}
    </span>);

}

function PillButton({ children, dark = true, onClick, href, style, arrow = true }) {
  const Tag = href ? "a" : "button";
  return (
    <Tag
      href={href}
      onClick={onClick}
      style={{
        display: "inline-flex",
        alignItems: "center",
        gap: 14,
        padding: "16px 28px",
        borderRadius: 999,
        background: dark ? "#A9C8E8" : "transparent",
        border: dark ? "0" : "1px solid var(--ink)",
        color: dark ? "#17110F" : "var(--ink)",
        fontFamily: "La Villa",
        fontSize: 12,
        letterSpacing: "0.22em",
        textTransform: "uppercase",
        fontWeight: 500,
        cursor: "pointer",
        transition: "transform 160ms ease, opacity 160ms ease",
        ...style
      }}
      onMouseDown={(e) => e.currentTarget.style.transform = "scale(0.98)"}
      onMouseUp={(e) => e.currentTarget.style.transform = "scale(1)"}
      onMouseLeave={(e) => e.currentTarget.style.transform = "scale(1)"}>
      
      <span>{children}</span>
      {arrow && <span style={{ fontSize: 14 }}>→</span>}
    </Tag>);

}

// ---------- nav ----------

function NavBar({ active = "Pricing" }) {
  const items = ["Overview", "Examples", "Capabilities", "Pricing", "FAQ"];
  return (
    <nav
      style={{
        position: "sticky",
        top: 0,
        zIndex: 50,
        display: "grid",
        gridTemplateColumns: "1fr auto 1fr",
        alignItems: "center",
        padding: "26px 40px",
        background: "color-mix(in oklab, var(--bg) 88%, transparent)",
        backdropFilter: "blur(8px)",
        WebkitBackdropFilter: "blur(8px)"
      }}>
      
      <a href="#" style={{ display: "inline-flex", alignItems: "center", gap: 12 }}>
        <YGlyph />
        <span
          style={{
            fontFamily: "La Villa",
            fontSize: 13,
            letterSpacing: "0.22em",
            textTransform: "uppercase",
            fontWeight: 600
          }}>
          
          Creative Studio
        </span>
      </a>
      <div style={{ display: "flex", alignItems: "center", gap: 36 }}>
        {items.map((it) =>
        <a
          key={it}
          href="#"
          style={{
            fontFamily: "La Villa",
            fontSize: 14,
            fontWeight: 500,
            color: it === active ? "var(--ink)" : "var(--ink-soft)",
            borderBottom: it === active ? "1.5px solid var(--ink)" : "1.5px solid transparent",
            paddingBottom: 4,
            transition: "color 160ms ease"
          }}>
          
            {it}
          </a>
        )}
      </div>
      <div style={{ justifySelf: "end" }}>
        <PillButton href="/dashboard/product-studio">Open Creative Studio</PillButton>
      </div>
    </nav>);

}

function YGlyph() {
  // Simple stylized "Y" mark — original placeholder, not a logo
  return (
    <div
      aria-hidden
      style={{
        width: 30,
        height: 30,
        borderRadius: 6,
        display: "grid",
        placeItems: "center",
        color: "var(--ink)",
        fontFamily: "Big Shoulders Display, Anton, Impact, sans-serif",
        fontWeight: 900,
        fontSize: 28,
        lineHeight: 1,
        fontStretch: "75%",
        letterSpacing: "-0.04em"
      }}>
      
      Y
    </div>);

}

// ---------- hero ----------

function Hero() {
  return (
    <header className="pp-hero" style={{ padding: "100px 40px 30px", textAlign: "center" }}>
      <h1
        className="display pp-hero-h1"
        style={{
          margin: "0 auto",
          maxWidth: 1280,
          fontSize: "120px"
        }}>
        Buy credits,
        <br />
        <span style={{ fontWeight: 700, fontStretch: "100%", letterSpacing: "-0.02em" }}>
          or save with a monthly plan.
        </span>
      </h1>
      <p style={{ margin: "28px auto 0", fontFamily: '"La Villa", sans-serif', fontSize: 16, lineHeight: 1.5, color: "var(--ink-mute)" }}>
        Not sure yet? <a href="/free-try" style={{ color: "var(--ink)", fontWeight: 600, textDecoration: "underline", textUnderlineOffset: "4px" }}>Try it free first</a>, no signup needed.
      </p>
    </header>);

}

// ---------- mode toggle (Credit Packs / Monthly Plans) ----------

function ModeToggle({ mode, onChange }) {
  return (
    <div
      role="tablist"
      className="pp-mode-toggle"
      style={{
        margin: "44px auto 56px",
        width: "fit-content",
        display: "flex",
        background: "var(--card)",
        border: "1px solid var(--card-line)",
        borderRadius: 999,
        padding: 6,
        position: "relative"
      }}>
      
      {[
      { id: "packs", title: "Credit Packs", sub: "Pay as you go" },
      { id: "plans", title: "Monthly Plans", sub: "Save 15%" }].
      map((opt) => {
        const active = mode === opt.id;
        return (
          <button
            key={opt.id}
            role="tab"
            aria-selected={active}
            onClick={() => onChange(opt.id)}
            style={{
              position: "relative",
              padding: "14px 32px",
              borderRadius: 999,
              background: active ? "#A9C8E8" : "transparent",
              color: active ? "#17110F" : "var(--ink)",
              transition: "background 220ms ease, color 220ms ease",
              cursor: "pointer",
              minWidth: 200,
              textAlign: "center"
            }}>
            
            <div
              style={{
                fontFamily: "La Villa",
                fontSize: 12,
                letterSpacing: "0.22em",
                textTransform: "uppercase",
                fontWeight: 500
              }}>
              
              {opt.title}
            </div>
            <div
              className="italic-serif"
              style={{
                fontSize: 12,
                marginTop: 4,
                opacity: active ? 0.78 : 0.6
              }}>
              
              {opt.sub}
            </div>
          </button>);

      })}
    </div>);

}

// ---------- price card ----------

function PriceCard({ plan, mode, selected, onSelect, expanded, onToggleExpand }) {
  const dark = selected;
  const showMo = mode === "plans";
  return (
    <div
      onClick={onSelect}
      style={{
        position: "relative",
        background: dark ? "var(--ink)" : "var(--card)",
        color: dark ? "var(--on-dark)" : "var(--ink)",
        borderRadius: "var(--radius-card)",
        padding: "30px 28px 24px",
        cursor: "pointer",
        transition: "transform 280ms cubic-bezier(.2,.7,.2,1), box-shadow 280ms ease",
        transform: dark ? "translateY(-10px)" : "translateY(0)",
        boxShadow: dark ? "0 24px 60px -24px rgba(39,36,28,0.45)" : "none",
        display: "flex",
        flexDirection: "column",
        gap: 22,
        minHeight: 360
      }}>
      
      <div
        style={{
          fontFamily: "La Villa",
          fontSize: 11,
          letterSpacing: "0.22em",
          textTransform: "uppercase",
          fontWeight: 500,
          color: dark ? "var(--on-dark-soft)" : "var(--ink-soft)"
        }}>
        
        {plan.name}
      </div>

      <div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
        <span
          className="num"
          style={{ fontSize: 76, lineHeight: 0.95, letterSpacing: "-0.04em" }}>
          
          ${plan.price}
        </span>
        {showMo &&
        <span
          style={{
            fontFamily: "La Villa",
            fontSize: 16,
            color: dark ? "var(--on-dark-soft)" : "var(--ink-soft)"
          }}>
          
            /mo
          </span>
        }
      </div>

      <div>
        <div style={{ display: "flex", alignItems: "baseline", gap: 10 }}>
          <span
            className="num"
            style={{ fontSize: 22, letterSpacing: "-0.02em" }}>
            
            {plan.credits.toLocaleString()}
          </span>
          <span
            style={{
              fontFamily: "La Villa",
              fontSize: 11,
              letterSpacing: "0.22em",
              textTransform: "uppercase",
              color: dark ? "var(--on-dark-soft)" : "var(--ink-soft)"
            }}>
            
            credits
          </span>
        </div>
        <div
          style={{
            marginTop: 10,
            fontSize: 15,
            color: dark ? "var(--on-dark)" : "var(--ink-soft)"
          }}>
          
          {plan.blurb}
        </div>
      </div>

      <div style={{ flex: 1 }} />

      <div
        style={{
          borderTop: dark ?
          "1px solid rgba(239,233,220,0.18)" :
          "1px solid var(--card-line)",
          paddingTop: 16,
          display: "flex",
          flexDirection: "column",
          gap: 12
        }}>
        
        <Row>
          <span
            style={{
              fontFamily: "La Villa",
              fontSize: 11,
              letterSpacing: "0.22em",
              textTransform: "uppercase",
              fontWeight: 500
            }}>
            
            {selected ? "Selected" : "Select"}
          </span>
          <Radio checked={selected} dark={dark} />
        </Row>
        <button
          onClick={(e) => {
            e.stopPropagation();
            onToggleExpand();
          }}
          style={{
            display: "flex",
            alignItems: "center",
            justifyContent: "space-between",
            cursor: "pointer",
            color: "inherit"
          }}>
          
          <span
            style={{
              fontFamily: "La Villa",
              fontSize: 11,
              letterSpacing: "0.22em",
              textTransform: "uppercase",
              fontWeight: 500,
              opacity: 0.85
            }}>
            
            {expanded ? "Hide details" : "What's included"}
          </span>
          <span style={{ fontSize: 13, opacity: 0.7 }}>{expanded ? "↑" : "↓"}</span>
        </button>

        <div
          style={{
            display: "grid",
            gridTemplateRows: expanded ? "1fr" : "0fr",
            transition: "grid-template-rows 320ms cubic-bezier(.2,.7,.2,1)"
          }}>
          
          <div style={{ overflow: "hidden" }}>
            <div
              style={{
                paddingTop: 12,
                display: "flex",
                flexDirection: "column",
                gap: 10,
                fontSize: 14
              }}>
              
              <DetailRow k="Billing" v={mode === "plans" ? "Monthly" : "One-time"} dark={dark} />
              <DetailRow k="Per 100 credits" v={`$${plan.perHundred.toFixed(2)}`} dark={dark} />
              <DetailRow k="Images" v={plan.images} dark={dark} />
              <DetailRow k="Videos (5s)" v={plan.videos} dark={dark} />
              <DetailRow
                k={mode === "plans" ? "Cancel" : "Expires"}
                v={mode === "plans" ? plan.cancel : plan.expires}
                dark={dark} />
              
            </div>
          </div>
        </div>
      </div>
    </div>);

}

function Row({ children }) {
  return (
    <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
      {children}
    </div>);

}

function DetailRow({ k, v, dark }) {
  return (
    <div style={{ display: "flex", justifyContent: "space-between", gap: 12 }}>
      <span style={{ opacity: dark ? 0.7 : 0.7 }}>{k}</span>
      <span style={{ textAlign: "right" }}>{v}</span>
    </div>);

}

function Radio({ checked, dark }) {
  return (
    <span
      style={{
        width: 18,
        height: 18,
        borderRadius: "50%",
        border: `1.5px solid ${dark ? "var(--on-dark)" : "var(--ink)"}`,
        display: "inline-flex",
        alignItems: "center",
        justifyContent: "center",
        background: "transparent"
      }}>
      
      <span
        style={{
          width: 8,
          height: 8,
          borderRadius: "50%",
          background: checked ? dark ? "var(--on-dark)" : "var(--ink)" : "transparent",
          transition: "background 160ms ease"
        }} />
      
    </span>);

}

// ---------- comparison table ----------

function ComparisonTable({ rows }) {
  const cols = rows[0].cols;
  return (
    <section className="pp-section pp-cmp-section" style={{ padding: "120px 40px 40px", maxWidth: 1480, margin: "0 auto" }}>
      <div style={{ textAlign: "center", marginBottom: 56 }}>
        <Pill>Compare</Pill>
        <h2 className="pp-section-h2" style={{ fontFamily: "La Villa", fontWeight: 500, fontSize: "clamp(28px, 3vw, 40px)", letterSpacing: "-0.02em", margin: "16px 0 0" }}>What's in every pack.

        </h2>
      </div>
      <div
        className="pp-cmp-wrap"
        style={{
          background: "var(--card)",
          borderRadius: "var(--radius-card)",
          overflow: "hidden",
          border: "1px solid var(--card-line)"
        }}>
        
        <table
          style={{
            width: "100%",
            borderCollapse: "collapse",
            fontSize: 14
          }}>
          
          <thead>
            <tr>
              <th
                style={{
                  textAlign: "left",
                  padding: "26px 28px",
                  fontFamily: "La Villa",
                  fontSize: 11,
                  letterSpacing: "0.22em",
                  textTransform: "uppercase",
                  fontWeight: 500,
                  color: "var(--ink-soft)",
                  width: "32%"
                }}>
                
                Capability
              </th>
              {cols.map((c) =>
              <th
                key={c}
                style={{
                  textAlign: "center",
                  padding: "26px 16px",
                  fontFamily: "La Villa",
                  fontSize: 11,
                  letterSpacing: "0.22em",
                  textTransform: "uppercase",
                  fontWeight: 500,
                  color: "var(--ink-soft)"
                }}>
                
                  {c}
                </th>
              )}
            </tr>
          </thead>
          <tbody>
            {rows.map((r, i) =>
            <tr
              key={r.label}
              style={{
                borderTop: "1px solid var(--card-line)",
                background: r.section ? "rgba(39,36,28,0.04)" : "transparent"
              }}>
              
                <td
                style={{
                  padding: "20px 28px",
                  fontWeight: r.section ? 600 : 400,
                  textTransform: r.section ? "uppercase" : "none",
                  letterSpacing: r.section ? "0.16em" : "0",
                  fontSize: r.section ? 11 : 14,
                  color: r.section ? "var(--ink-soft)" : "var(--ink)"
                }}>
                
                  {r.label}
                </td>
                {r.values.map((v, j) =>
              <td
                key={j}
                style={{
                  padding: "20px 16px",
                  textAlign: "center",
                  color: typeof v === "boolean" ?
                  "var(--ink)" :
                  "var(--ink)"
                }}>
                
                    {v === true ?
                <Check /> :
                v === false ?
                <Dash /> :

                v
                }
                  </td>
              )}
              </tr>
            )}
          </tbody>
        </table>
      </div>
    </section>);

}

function Check() {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" style={{ display: "inline-block" }}>
      <path d="M3 8.5L6.5 12L13 4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
    </svg>);

}
function Dash() {
  return <span style={{ opacity: 0.3 }}>—</span>;
}

// ---------- testimonials ----------

function Testimonials({ items }) {
  return (
    <section className="pp-section pp-testimonials-section" style={{ padding: "120px 40px 40px", maxWidth: 1480, margin: "0 auto" }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "end", marginBottom: 48, flexWrap: "wrap", gap: 20 }}>
        <div>
          <Pill>Studio in the wild</Pill>
          <h2
            style={{ fontFamily: "La Villa", fontWeight: 500, fontSize: "clamp(28px, 3vw, 40px)", letterSpacing: "-0.02em", margin: "16px 0 0", maxWidth: 720 }}>
            Used by the people who shoot, ship, and sell.
          </h2>
        </div>
      </div>
      <div
        className="pp-testimonials"
        style={{
          display: "grid",
          gridTemplateColumns: "repeat(3, minmax(0, 1fr))",
          gap: 20
        }}>

        {items.map((t, i) =>
        <figure
          key={i}
          style={{
            margin: 0,
            background: i === 1 ? "var(--ink)" : "var(--card)",
            color: i === 1 ? "var(--on-dark)" : "var(--ink)",
            borderRadius: "var(--radius-card)",
            padding: "32px 28px",
            display: "flex",
            flexDirection: "column",
            gap: 28,
            minHeight: 320
          }}>
          
            <blockquote
            style={{
              margin: 0,
              fontSize: 22,
              lineHeight: 1.35,
              letterSpacing: "-0.01em",
              fontWeight: 400
            }}>
            
              <span className="italic-serif" style={{ fontSize: 28, marginRight: 6 }}>“</span>
              {t.quote}
            </blockquote>
            <div style={{ marginTop: "auto", display: "flex", alignItems: "center", gap: 14 }}>
              <Avatar name={t.name} dark={i === 1} />
              <div>
                <div style={{ fontWeight: 600, fontSize: 14 }}>{t.name}</div>
                <div
                style={{
                  fontSize: 12,
                  opacity: 0.7,
                  letterSpacing: "0.06em"
                }}>
                
                  {t.role}
                </div>
              </div>
            </div>
          </figure>
        )}
      </div>
    </section>);

}

function Avatar({ name, dark }) {
  const initials = name.split(" ").map((s) => s[0]).slice(0, 2).join("");
  return (
    <span
      style={{
        width: 38,
        height: 38,
        borderRadius: "50%",
        background: dark ? "rgba(239,233,220,0.14)" : "rgba(39,36,28,0.08)",
        color: "inherit",
        display: "inline-grid",
        placeItems: "center",
        fontFamily: "La Villa",
        fontWeight: 600,
        fontSize: 12,
        letterSpacing: "0.06em"
      }}>
      
      {initials}
    </span>);

}

// ---------- competitor comparison ----------

function CompetitorTable({ rows, cols }) {
  return (
    <section className="pp-section pp-comp-section" style={{ padding: "120px 40px 40px", maxWidth: 1480, margin: "0 auto" }}>
      <div style={{ textAlign: "center", marginBottom: 56 }}>
        <Pill>How we stack up</Pill>
        <h2 className="pp-section-h2" style={{ fontFamily: "La Villa", fontWeight: 500, fontSize: "clamp(28px, 3vw, 40px)", letterSpacing: "-0.02em", margin: "16px 0 0" }}>
          The honest comparison.
        </h2>
        <p
          className="italic-serif"
          style={{ marginTop: 12, color: "var(--ink-mute)", fontSize: 15 }}>
        </p>
      </div>
      <div className="pp-comp-scroll">
      <div
        className="pp-comp-grid"
        style={{
          display: "grid",
          gridTemplateColumns: `1.4fr repeat(${cols.length}, 1fr)`,
          background: "var(--card)",
          borderRadius: "var(--radius-card)",
          border: "1px solid var(--card-line)",
          overflow: "hidden"
        }}>
        
        <CellHead label="" />
        {cols.map((c, i) =>
        <CellHead key={c.name} label={c.name} highlight={i === 0} sub={c.sub} />
        )}
        {rows.map((r) =>
        <React.Fragment key={r.label}>
            <Cell label={r.label} k />
            {r.values.map((v, i) =>
          <Cell key={i} label={v} highlight={i === 0} />
          )}
          </React.Fragment>
        )}
      </div>
      </div>
    </section>);

}

function CellHead({ label, sub, highlight }) {
  return (
    <div
      style={{
        padding: "24px 22px",
        background: highlight ? "var(--ink)" : "transparent",
        color: highlight ? "var(--on-dark)" : "var(--ink-soft)",
        borderBottom: "1px solid var(--card-line)"
      }}>
      
      <div
        style={{
          fontFamily: "La Villa",
          fontSize: 11,
          letterSpacing: "0.22em",
          textTransform: "uppercase",
          fontWeight: 600
        }}>
        
        {label}
      </div>
      {sub &&
      <div
        className="italic-serif"
        style={{
          fontSize: 12,
          opacity: 0.7,
          marginTop: 4
        }}>
        
          {sub}
        </div>
      }
    </div>);

}

function Cell({ label, k, highlight }) {
  return (
    <div
      style={{
        padding: "20px 22px",
        background: highlight ? "var(--ink)" : "transparent",
        color: highlight ? "var(--on-dark)" : "var(--ink)",
        borderTop: "1px solid var(--card-line)",
        fontSize: 14,
        fontWeight: k ? 500 : 400,
        opacity: k ? 0.75 : 1,
        letterSpacing: k ? "0.04em" : "0",
        textTransform: k ? "uppercase" : "none",
        fontFamily: k ? "La Villa" : "La Villa",
        fontSize: k ? 11 : 14
      }}>
      
      {label}
    </div>);

}

// ---------- FAQ ----------

function FAQ({ items }) {
  const [open, setOpen] = useState(0);
  return (
    <section
      className="pp-section pp-faq"
      style={{
        padding: "120px 40px 60px",
        maxWidth: 1080,
        margin: "0 auto"
      }}>

      <div style={{ textAlign: "center", marginBottom: 56 }}>
        <Pill>Questions</Pill>
        <h2 className="pp-section-h2" style={{ fontFamily: "La Villa", fontWeight: 500, fontSize: "clamp(28px, 3vw, 40px)", letterSpacing: "-0.02em", margin: "16px 0 0" }}>Asked and answered.</h2>
      </div>
      <div style={{ display: "flex", flexDirection: "column" }}>
        {items.map((it, i) => {
          const isOpen = open === i;
          return (
            <div
              key={it.q}
              style={{
                borderTop: i === 0 ? "1px solid var(--card-line)" : "none",
                borderBottom: "1px solid var(--card-line)"
              }}>
              
              <button
                onClick={() => setOpen(isOpen ? -1 : i)}
                style={{
                  width: "100%",
                  display: "flex",
                  justifyContent: "space-between",
                  alignItems: "center",
                  padding: "26px 4px",
                  cursor: "pointer",
                  textAlign: "left",
                  gap: 24,
                  background: "transparent",
                  border: 0,
                  outline: "none",
                  color: "inherit",
                  font: "inherit"
                }}>
                
                <span
                  style={{
                    fontSize: 22,
                    fontWeight: 500,
                    letterSpacing: "-0.01em"
                  }}>
                  
                  {it.q}
                </span>
                <span
                  style={{
                    fontSize: 18,
                    transform: isOpen ? "rotate(45deg)" : "rotate(0deg)",
                    transition: "transform 220ms cubic-bezier(.2,.7,.2,1)",
                    color: "var(--ink-soft)"
                  }}>
                  
                  +
                </span>
              </button>
              <div
                style={{
                  display: "grid",
                  gridTemplateRows: isOpen ? "1fr" : "0fr",
                  transition: "grid-template-rows 280ms cubic-bezier(.2,.7,.2,1)"
                }}>
                
                <div style={{ overflow: "hidden" }}>
                  <p
                    style={{
                      margin: 0,
                      paddingBottom: 28,
                      paddingRight: 60,
                      fontSize: 16,
                      lineHeight: 1.6,
                      color: "var(--ink-soft)",
                      maxWidth: 760
                    }}>
                    
                    {it.a}
                  </p>
                </div>
              </div>
            </div>);

        })}
      </div>
    </section>);

}

// ---------- footer CTA ----------

function FooterCTA() {
  return (
    <section
      className="pp-footer-cta"
      style={{
        margin: "120px 40px 40px",
        padding: "80px 40px",
        background: "var(--ink)",
        color: "var(--on-dark)",
        borderRadius: 28,
        textAlign: "center",
        position: "relative",
        overflow: "hidden"
      }}>
      
      <Pill style={{ color: "var(--on-dark-soft)", border: "1px solid rgba(239,233,220,0.2)" }}>
        Free to explore
      </Pill>
      <h2
        style={{
          fontFamily: "La Villa",
          fontWeight: 500,
          fontSize: "clamp(40px, 5vw, 72px)",
          letterSpacing: "-0.02em",
          lineHeight: 1.05,
          margin: "24px auto 0",
          maxWidth: 900
        }}>
        Drop a product in.
        <br />
        <span style={{ opacity: 0.55 }}>Pull a campaign out.</span>
      </h2>
      <div
        style={{
          marginTop: 40,
          display: "flex",
          justifyContent: "center",
          gap: 14,
          flexWrap: "wrap"
        }}>
        
        <PillButton href="/dashboard/product-studio" dark={false} style={{ background: "var(--on-dark)", color: "var(--ink)", border: "0" }}>
          Open Creative Studio
        </PillButton>
        <PillButton href="/landing/Examples.html" dark={false} style={{ borderColor: "rgba(239,233,220,0.4)", color: "var(--on-dark)" }} arrow={false}>
          See examples
        </PillButton>
      </div>
    </section>);

}

function FooterMeta() {
  return (
    <footer
      style={{
        padding: "20px 40px 60px",
        display: "flex",
        justifyContent: "space-between",
        alignItems: "center",
        flexWrap: "wrap",
        gap: 16,
        color: "var(--ink-soft)",
        fontSize: 13
      }}>
      
      <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
        <YGlyph />
        <span style={{ letterSpacing: "0.04em" }}>The Vault Stock · Creative Studio</span>
      </div>
      <div style={{ display: "flex", gap: 28 }}>
        <a href="/landing/Terms.html">Terms</a>
        <a href="mailto:studio@thevaultstock.com">studio@thevaultstock.com</a>
      </div>
    </footer>);

}

// SignupModal: collects email + password before checkout. Auto-detects new
// vs existing accounts on the server (a returning customer can sign in by
// just typing their existing password). Once submitted, the user is signed
// in server-side and we redirect them straight to Stripe with their account
// already attached, so no magic-link email is needed.
function SignupModal({ open, onClose, selected, mode }) {
  const [email, setEmail] = React.useState("");
  const [password, setPassword] = React.useState("");
  const [loading, setLoading] = React.useState(false);
  const [error, setError] = React.useState("");
  const [touchedExisting, setTouchedExisting] = React.useState(false);

  React.useEffect(() => {
    if (!open) {
      setEmail("");
      setPassword("");
      setError("");
      setLoading(false);
      setTouchedExisting(false);
    }
  }, [open]);

  React.useEffect(() => {
    if (!open) return;
    const onKey = (e) => { if (e.key === "Escape") onClose(); };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, [open, onClose]);

  if (!open) return null;

  const handleSubmit = async (e) => {
    e.preventDefault();
    if (loading) return;
    setError("");

    if (!email.includes("@")) {
      setError("Please enter a valid email");
      return;
    }
    if (password.length < 8) {
      setError("Password must be at least 8 characters");
      return;
    }

    setLoading(true);
    try {
      const tier = String(selected.id).replace(/-m$/, "");
      const apiMode = mode === "plans" ? "subscription" : "payment";
      const res = await fetch("/api/auth/signup-and-checkout", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ email, password, tier, mode: apiMode }),
      });
      const data = await res.json().catch(() => ({}));
      if (!res.ok || !data.url) {
        if (data?.existingAccount) setTouchedExisting(true);
        throw new Error(data?.error || "Could not continue to checkout");
      }
      window.location.href = data.url;
    } catch (err) {
      setError(err.message || "Something went wrong, please try again");
      setLoading(false);
    }
  };

  const priceLabel = selected
    ? `$${selected.price}${mode === "plans" ? "/mo" : ""} · ${selected.credits.toLocaleString()} credits`
    : "";

  return (
    <div
      onClick={onClose}
      style={{
        position: "fixed", inset: 0, zIndex: 100,
        background: "rgba(20,16,14,0.55)",
        backdropFilter: "blur(4px)",
        WebkitBackdropFilter: "blur(4px)",
        display: "flex", alignItems: "center", justifyContent: "center",
        padding: "24px",
      }}
    >
      <div
        onClick={(e) => e.stopPropagation()}
        style={{
          background: "var(--cream, #F2ECE4)",
          borderRadius: 8,
          padding: "40px 36px",
          width: "100%", maxWidth: 420,
          boxShadow: "0 24px 80px -20px rgba(0,0,0,0.4)",
          fontFamily: "Georgia, serif",
        }}
      >
        <button
          onClick={onClose}
          aria-label="Close"
          style={{
            position: "absolute", marginTop: -28, marginLeft: 348,
            background: "transparent", border: 0, cursor: "pointer",
            color: "var(--ink-mute)", fontSize: 20, lineHeight: 1,
          }}
        >×</button>

        <div style={{
          fontFamily: "La Villa", fontSize: 11, letterSpacing: "0.22em",
          textTransform: "uppercase", fontWeight: 500, color: "var(--ink-mute)",
          marginBottom: 12, textAlign: "center",
        }}>
          Almost there
        </div>
        <h2 className="italic-serif" style={{
          fontSize: 28, lineHeight: 1.15, color: "var(--ink)",
          margin: "0 0 8px 0", textAlign: "center", letterSpacing: "-0.01em",
        }}>
          Create your account
        </h2>
        <p style={{
          fontSize: 13, color: "var(--ink-mute)", textAlign: "center",
          margin: "0 0 24px 0", lineHeight: 1.5,
        }}>
          {selected ? (<>You picked <strong style={{ color: "var(--ink)" }}>{selected.name}</strong> · {priceLabel}</>) : "Continue to checkout"}
        </p>

        <form onSubmit={handleSubmit}>
          <label style={{ display: "block", marginBottom: 14 }}>
            <span style={{
              display: "block", fontFamily: "La Villa", fontSize: 10,
              letterSpacing: "0.22em", textTransform: "uppercase",
              color: "var(--ink-mute)", marginBottom: 6,
            }}>Email</span>
            <input
              type="email"
              value={email}
              onChange={(e) => setEmail(e.target.value)}
              placeholder="you@example.com"
              autoFocus
              autoComplete="email"
              required
              style={{
                width: "100%", padding: "12px 14px", fontSize: 14,
                fontFamily: "Georgia, serif",
                background: "transparent",
                border: "1px solid var(--card-line)",
                borderRadius: 6, outline: "none",
                color: "var(--ink)",
              }}
            />
          </label>

          <label style={{ display: "block", marginBottom: 8 }}>
            <span style={{
              display: "block", fontFamily: "La Villa", fontSize: 10,
              letterSpacing: "0.22em", textTransform: "uppercase",
              color: "var(--ink-mute)", marginBottom: 6,
            }}>Password</span>
            <input
              type="password"
              value={password}
              onChange={(e) => setPassword(e.target.value)}
              placeholder="At least 8 characters"
              autoComplete="new-password"
              required
              minLength={8}
              style={{
                width: "100%", padding: "12px 14px", fontSize: 14,
                fontFamily: "Georgia, serif",
                background: "transparent",
                border: "1px solid var(--card-line)",
                borderRadius: 6, outline: "none",
                color: "var(--ink)",
              }}
            />
          </label>

          <p style={{ fontSize: 11, color: "var(--ink-mute)", margin: "0 0 18px 0", lineHeight: 1.5 }}>
            If you already have an account, just enter your existing password. Your purchase will be added to it.
          </p>

          {error && (
            <div style={{
              fontSize: 12, color: "#A8473A", marginBottom: 16,
              padding: "10px 12px", background: "rgba(168,71,58,0.08)",
              border: "1px solid rgba(168,71,58,0.2)", borderRadius: 6,
              lineHeight: 1.4,
            }}>
              {error}
              {touchedExisting && (
                <div style={{ marginTop: 6, fontSize: 11, opacity: 0.8 }}>
                  Forgot it? <a href="/auth/login?next=/dashboard/product-studio" style={{ color: "#A8473A", textDecoration: "underline" }}>Reset password</a>
                </div>
              )}
            </div>
          )}

          <button
            type="submit"
            disabled={loading}
            style={{
              width: "100%", padding: "14px 24px",
              background: "var(--ink)", color: "var(--on-dark)",
              border: 0, borderRadius: 999,
              fontFamily: "La Villa", fontSize: 12,
              letterSpacing: "0.22em", textTransform: "uppercase",
              fontWeight: 500, cursor: loading ? "default" : "pointer",
              opacity: loading ? 0.7 : 1,
              transition: "opacity 160ms",
            }}
          >
            {loading ? "Continuing…" : "Continue to checkout"}
          </button>
        </form>

        <p style={{
          fontSize: 10, color: "var(--ink-mute)", textAlign: "center",
          margin: "20px 0 0 0", lineHeight: 1.5,
        }}>
          Secure payment via Stripe. By continuing you agree to our <a href="/terms" style={{ color: "var(--ink)", textDecoration: "underline" }}>Terms</a>.
        </p>
      </div>
    </div>
  );
}

// CheckoutCTA: hands off to the in-app Product Studio gate, which already
// has the polished signup-and-pick-a-pack modal. For anonymous visitors we
// redirect to /dashboard/product-studio?tier=<id> — the in-app code reads
// the param and opens the gate at the signup screen with the right pack
// pre-selected. For authed visitors we still go straight to Stripe.
function CheckoutCTA({ selected, mode }) {
  const [loading, setLoading] = React.useState(false);
  const [error, setError] = React.useState("");
  const [authChecked, setAuthChecked] = React.useState(false);
  const [authed, setAuthed] = React.useState(false);

  React.useEffect(() => {
    fetch("/api/auth/me", { credentials: "include" })
      .then((r) => r.json())
      .then((d) => { setAuthed(!!d.authed); setAuthChecked(true); })
      .catch(() => setAuthChecked(true));
  }, []);

  const goDirectToCheckout = async () => {
    if (!selected || loading) return;
    setError("");
    setLoading(true);
    try {
      const tier = String(selected.id).replace(/-m$/, "");
      const apiMode = mode === "plans" ? "subscription" : "payment";
      const toltReferral = typeof window !== "undefined" ? window.tolt_referral : undefined;
      const psPixel = typeof window !== "undefined" ? window.psPixel : null;
      const fbp = psPixel ? psPixel.getFbp() : null;
      const fbc = psPixel ? psPixel.getFbc() : null;
      // Fire AddToCart (deduped per-tier) then InitiateCheckout.
      // No CAPI dedup needed — no server twin for these client events.
      // AddToCart covers users who don't re-click the pre-selected default tile,
      // and the Set guards against double-firing for users who DID click first.
      if (psPixel) {
        const data = { content_ids: [tier], content_type: "product" };
        if (selected.price) data.value = selected.price;
        if (selected.price) data.currency = "USD";
        const fired = window._psAddedToCart || (window._psAddedToCart = new Set());
        if (!fired.has(tier)) {
          psPixel.track("AddToCart", data);
          fired.add(tier);
        }
        psPixel.track("InitiateCheckout", data);
      }
      const res = await fetch("/api/stripe/checkout-public", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        credentials: "include",
        body: JSON.stringify({ tier, mode: apiMode, tolt_referral: toltReferral, fbp: fbp, fbc: fbc }),
      });
      const data = await res.json().catch(() => ({}));
      if (!res.ok || !data.url) throw new Error(data?.error || "Could not start checkout");
      window.location.href = data.url;
    } catch (err) {
      setError(err.message || "Something went wrong, please try again");
      setLoading(false);
    }
  };

  const goToInAppGate = () => {
    if (!selected) return;
    setLoading(true);
    // Landing-page subscription IDs use "-m"; the in-app gate's deep-link
    // param expects "-mo". Bridge the two here.
    const rawId = String(selected.id);
    const tierParam = mode === "plans"
      ? rawId.replace(/-m$/, "-mo")
      : rawId;
    window.location.href = `/dashboard/product-studio?tier=${encodeURIComponent(tierParam)}`;
  };

  const handleClick = () => {
    if (!authChecked) return;
    if (authed) goDirectToCheckout();
    else goToInAppGate();
  };

  return (
    <div style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 8 }}>
      <PillButton onClick={handleClick} dark={true} arrow={!loading}>
        {loading ? "Opening checkout…" : "Get started"}
      </PillButton>
      {error && (
        <div style={{ fontSize: 12, color: "#A8473A", letterSpacing: "0.04em" }}>
          {error}
        </div>
      )}
    </div>
  );
}

window.NavBar = NavBar;
window.Hero = Hero;
window.ModeToggle = ModeToggle;
window.PriceCard = PriceCard;
window.ComparisonTable = ComparisonTable;
window.Testimonials = Testimonials;
window.CompetitorTable = CompetitorTable;
window.FAQ = FAQ;
window.FooterCTA = FooterCTA;
window.FooterMeta = FooterMeta;
window.PillButton = PillButton;
window.Pill = Pill;
window.CheckoutCTA = CheckoutCTA;