// urlapi.me — SP SECTIONS
// All non-hero sections, redesigned mobile-first.

const { useState: spsUS, useEffect: spsUE, useRef: spsUR } = React;

// ── Section title helper ──────────────────────────────
function SPSectionHead({ eyebrow, title, sub }) {
  return (
    <div style={{ textAlign: "center", marginBottom: 22 }}>
      {eyebrow && (
        <div className="mono" style={{
          fontSize: 10, color: "var(--accent-2)", letterSpacing: 0.2,
          textTransform: "uppercase", marginBottom: 10,
        }}>{eyebrow}</div>
      )}
      <h2 className="display" style={{
        fontSize: "clamp(24px, 7vw, 30px)", fontWeight: 700,
        margin: 0, letterSpacing: -0.025, lineHeight: 1.2,
      }}>{title}</h2>
      {sub && (
        <p style={{
          fontSize: 13, color: "var(--text-mid)",
          marginTop: 12, lineHeight: 1.7,
        }}>{sub}</p>
      )}
    </div>
  );
}

// ── Problem ───────────────────────────────────────────
function SPProblem() {
  const items = [
    { stat: "−42%", label: "iOS 14+ のCV計測欠損", desc: "ATTで広告プラットフォームにCVが届かず、最適化が止まる。" },
    { stat: "1日", label: "Bitlyブラックリスト解除", desc: "他社の不正利用でドメインがブロック、自社広告が届かない。" },
    { stat: "5+", label: "媒体ごとに個別実装",   desc: "Meta CAPI / Google Enhanced CV / TikTok… 全部自前で書く?" },
    { stat: "?",   label: "管理画面で迷子",       desc: "Bitly Enterprise の操作研修に半日。" },
  ];
  return (
    <section style={{ padding: "36px 18px", borderTop: "1px solid var(--border-soft)" }}>
      <SPSectionHead
        eyebrow="Why now"
        title={<>計測できないCVは、<br />存在しないCVと同じ。</>}
        sub="ATT・Cookie規制・ブラックリスト被害・分散したAPI実装。広告運用の現場は壊れたままだ。"
      />
      <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
        {items.map((it, i) => (
          <div key={i} style={{
            padding: 18, background: "var(--bg-1)",
            border: "1px solid var(--border)", borderRadius: 12,
            display: "grid", gridTemplateColumns: "auto 1fr", gap: 16,
            alignItems: "center",
          }}>
            <div className="display" style={{
              fontSize: 30, fontWeight: 700, color: "var(--danger)",
              letterSpacing: -0.02, lineHeight: 1, minWidth: 70,
            }}>{it.stat}</div>
            <div>
              <div style={{ fontSize: 13, fontWeight: 600 }}>{it.label}</div>
              <div style={{ fontSize: 11.5, color: "var(--text-mute)", marginTop: 4, lineHeight: 1.5 }}>{it.desc}</div>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ── Pillars (3 stacked rows w/ small mocks) ──────────
function SPPillarChatMock() {
  return (
    <div style={{ background: "var(--bg-2)", border: "1px solid var(--border)", borderRadius: 10, padding: 12, fontFamily: "var(--font-mono)" }}>
      <div className="mono" style={{ fontSize: 9.5, color: "var(--text-mute)", marginBottom: 8 }}>claude · MCP urlapi</div>
      <div style={{ display: "flex", flexDirection: "column", gap: 5 }}>
        {[
          ["create_campaign", '{ name:"spring" }'],
          ["connect_meta",    '{ pixel:"auto" }'],
          ["schedule_report", '{ to:"#growth" }'],
        ].map(([t, a], i) => (
          <div key={i} className="mono" style={{
            display: "flex", alignItems: "center", gap: 6,
            padding: "4px 7px",
            background: "rgba(124,92,255,0.06)",
            border: "1px solid var(--accent-soft)",
            borderRadius: 4, fontSize: 10,
          }}>
            <I.Check size={8} style={{ color: "var(--success)", flexShrink: 0 }} />
            <span style={{ color: "var(--accent)" }}>{t}</span>
            <span style={{ color: "var(--text-mute)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{a}</span>
          </div>
        ))}
      </div>
      <div style={{ fontSize: 11, marginTop: 8, lineHeight: 1.5 }}>
        <span style={{ color: "var(--success)", fontWeight: 600 }}>spring-2026</span> 発行 / Meta 接続済 / 毎週月曜
        <span className="mono" style={{ color: "var(--accent)", padding: "0 3px" }}>#growth</span>
        へ。
      </div>
    </div>
  );
}

function SPPillarDomainMock() {
  return (
    <div style={{ background: "var(--bg-2)", border: "1px solid var(--border)", borderRadius: 10, padding: 12, fontFamily: "var(--font-mono)", fontSize: 11 }}>
      <div className="mono" style={{ fontSize: 9.5, color: "var(--text-mute)", marginBottom: 8, display: "flex", alignItems: "center", justifyContent: "space-between" }}>
        DNS / Setup
        <span style={{ color: "var(--success)", padding: "1px 6px", background: "rgba(46,230,168,0.10)", border: "1px solid rgba(46,230,168,0.25)", borderRadius: 3, fontSize: 8.5 }}>● LIVE</span>
      </div>
      <div style={{ color: "var(--text-mute)", fontSize: 10 }}># Single CNAME record</div>
      <div style={{ display: "flex", gap: 8, padding: "6px 10px", background: "rgba(0,0,0,0.40)", border: "1px solid var(--border)", borderRadius: 6, marginTop: 4 }}>
        <span style={{ color: "var(--accent-2)" }}>CNAME</span>
        <span style={{ color: "var(--info)" }}>go</span>
        <span style={{ color: "var(--text-mute)" }}>→</span>
        <span style={{ color: "var(--success)", overflow: "hidden", textOverflow: "ellipsis" }}>cname.urlapi.me</span>
      </div>
      <div style={{ marginTop: 10, display: "flex", flexDirection: "column", gap: 2 }}>
        {[
          ["SSL", "auto"],
          ["CDN", "14 PoPs"],
          ["WHOIS Privacy", "on"],
          ["Blacklist immunity", "100%"],
        ].map(([k, v]) => (
          <div key={k} style={{ display: "flex", justifyContent: "space-between", fontSize: 10.5 }}>
            <span style={{ color: "var(--text-mid)" }}>✓ {k}</span>
            <span style={{ color: "var(--text-mute)" }}>{v}</span>
          </div>
        ))}
      </div>
      <div style={{
        marginTop: 10, padding: "7px 10px",
        background: "rgba(124,92,255,0.08)",
        borderLeft: "2px solid var(--accent)",
        borderRadius: 3, fontSize: 10.5,
        overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap",
      }}>
        https://go.your-brand.co/spring
      </div>
    </div>
  );
}

function SPPillarAdsMock() {
  const platforms = [
    { n: "Meta CAPI",     v: 847, pct: 96 },
    { n: "Google ECV",    v: 293, pct: 91 },
    { n: "TikTok Events", v: 164, pct: 88 },
    { n: "LINE Tag",      v: 92,  pct: 95 },
    { n: "X CAPI",        v: 41,  pct: 84 },
  ];
  return (
    <div style={{ background: "var(--bg-2)", border: "1px solid var(--border)", borderRadius: 10, padding: 12 }}>
      <div className="mono" style={{
        fontSize: 9.5, color: "var(--text-mute)", marginBottom: 10,
        display: "flex", justifyContent: "space-between",
      }}>
        <span>CV · Last 24h</span>
        <span style={{ color: "var(--accent-2)" }}>1,437 total</span>
      </div>
      <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
        {platforms.map((p, i) => {
          const ent = BRAND[p.n];
          const L = ent ? ent.L : null;
          const c = ent ? ent.c : "#A88BFF";
          return (
            <div key={i}>
              <div style={{ display: "flex", alignItems: "center", gap: 7, marginBottom: 3 }}>
                {L ? <L size={14} /> : <span style={{ width: 14, height: 14, borderRadius: 3, background: c }} />}
                <span style={{ flex: 1, fontSize: 11, fontWeight: 600 }}>{p.n}</span>
                <span className="mono" style={{ fontSize: 10, color: "var(--text-mid)" }}>{p.v}</span>
                <span className="mono" style={{ fontSize: 9.5, color: "var(--success)", minWidth: 28, textAlign: "right" }}>{p.pct}%</span>
              </div>
              <div style={{ height: 3, background: "var(--bg-3)", borderRadius: 2, overflow: "hidden" }}>
                <div style={{ width: `${p.pct}%`, height: "100%", background: c, opacity: 0.85 }} />
              </div>
            </div>
          );
        })}
      </div>
    </div>
  );
}

function SPPillars() {
  const pillars = [
    {
      tag: "01 / AI",
      title: "AIチャットで全機能操作",
      desc: "「春キャンペーン作って、Metaに送って、結果を週次でSlackに」— 自然言語が業務UIになる。",
      logos: ["Claude", "ChatGPT", "MCP", "Slack"],
      mock: <SPPillarChatMock />,
    },
    {
      tag: "02 / Domain",
      title: "自社ドメイン運用",
      desc: "go.your-brand.co で短縮。CNAME 1行・SSL自動。Bitlyのブラックリスト被害から永久に独立。",
      logos: ["Shopify", "BASE", "WordPress"],
      mock: <SPPillarDomainMock />,
    },
    {
      tag: "03 / Ads",
      title: "広告API自動連携",
      desc: "Meta CAPI / Google Enhanced CV / LINE Tag / TikTok / X — 5媒体に同時送信、CV回復率 平均+38%。",
      logos: ["Meta", "Google", "LINE", "TikTok", "X"],
      mock: <SPPillarAdsMock />,
    },
  ];
  return (
    <section style={{ padding: "36px 18px", borderTop: "1px solid var(--border-soft)" }}>
      <SPSectionHead
        eyebrow="The 3 pillars"
        title={<>3つの武器で、<br />広告運用を取り戻す。</>}
      />
      <div style={{ display: "flex", flexDirection: "column", gap: 18 }}>
        {pillars.map((p, i) => (
          <div key={i} style={{
            position: "relative",
            padding: 18,
            background: "var(--bg-1)",
            border: "1px solid var(--border)",
            borderRadius: 14,
            overflow: "hidden",
          }}>
            <div style={{
              position: "absolute", top: -30, right: -30,
              width: 120, height: 120,
              background: "radial-gradient(circle, var(--accent-glow), transparent 60%)",
              opacity: 0.3, pointerEvents: "none",
            }} />
            <div className="mono" style={{
              fontSize: 9.5, color: "var(--accent-2)",
              letterSpacing: 0.18, marginBottom: 6, position: "relative",
            }}>{p.tag}</div>
            <h3 className="display" style={{
              fontSize: 20, fontWeight: 700, margin: 0,
              lineHeight: 1.3, letterSpacing: -0.02, position: "relative",
            }}>{p.title}</h3>
            <p style={{
              fontSize: 12.5, color: "var(--text-mid)",
              lineHeight: 1.65, margin: "10px 0 14px", position: "relative",
            }}>{p.desc}</p>

            <div style={{ marginBottom: 14, position: "relative" }}>{p.mock}</div>

            {/* brand chips */}
            <div style={{
              paddingTop: 12, borderTop: "1px dashed var(--border)",
              display: "flex", flexWrap: "wrap", gap: 6, position: "relative",
            }}>
              {p.logos.map((b) => {
                const ent = BRAND[b];
                if (!ent) return null;
                const L = ent.L;
                return (
                  <span key={b} style={{
                    display: "inline-flex", alignItems: "center", gap: 5,
                    padding: "5px 10px 5px 7px",
                    background: "var(--bg-2)",
                    border: "1px solid var(--border-strong)",
                    borderRadius: 999, fontSize: 11, fontWeight: 600,
                  }}>
                    <L size={13} />
                    <span>{b}</span>
                  </span>
                );
              })}
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ── Developer (tabs + code, horizontal scroll) ─────────
function SPDeveloper() {
  const [tab, setTab] = spsUS("api");
  const codes = {
    api: { lang: "bash", body: `# 短縮URL + 全広告に自動接続
curl -X POST https://api.urlapi.me/v1/links \\
  -H "Authorization: Bearer urlapi_sk_..." \\
  -d '{
    "url": "https://acme.co/sale",
    "domain": "go.acme.co",
    "slug": "spring",
    "track": ["meta","google","tiktok"]
  }'

# → https://go.acme.co/spring` },
    mcp: { lang: "json", body: `// claude_desktop_config.json
{
  "mcpServers": {
    "urlapi": {
      "command": "npx",
      "args": ["@urlapi/mcp"],
      "env": {
        "URLAPI_KEY": "urlapi_sk_live_..."
      }
    }
  }
}

// Claudeに「春キャンペーン作って」と言うだけ` },
    sdk: { lang: "ts", body: `import { urlapi } from "@urlapi/sdk";

const c = urlapi({ key: process.env.URLAPI_KEY });

// CVを5プラットフォーム同時送信
await c.track("purchase", {
  value: 4980,
  currency: "JPY",
  items: [{ id: "sku_42" }],
  user: { email_hash: "..." },
});` },
  };
  const code = codes[tab];

  return (
    <section style={{ padding: "36px 18px", background: "var(--bg-1)", borderTop: "1px solid var(--border-soft)" }}>
      <SPSectionHead
        eyebrow="Built for builders"
        title={<>API・MCPファースト。<br />開発者が直接組み込める。</>}
        sub="管理画面はオプション。すべてAPIから呼べる。Claude / ChatGPT は MCP 1行で。"
      />

      {/* tabs */}
      <div style={{
        display: "flex", gap: 3, marginBottom: 12, padding: 3,
        background: "var(--bg-2)", border: "1px solid var(--border)",
        borderRadius: 9, width: "100%",
      }}>
        {[{ k: "api", l: "REST" }, { k: "mcp", l: "MCP" }, { k: "sdk", l: "SDK" }].map(t => (
          <button key={t.k} onClick={() => setTab(t.k)} className="mono" style={{
            flex: 1, padding: "8px 0",
            background: tab === t.k ? "var(--bg-3)" : "transparent",
            border: tab === t.k ? "1px solid var(--border-strong)" : "1px solid transparent",
            color: tab === t.k ? "var(--text)" : "var(--text-mute)",
            borderRadius: 6, fontSize: 11.5, fontWeight: 600, cursor: "pointer",
          }}>{t.l}</button>
        ))}
      </div>

      <div style={{
        background: "#06060A", border: "1px solid var(--border-strong)",
        borderRadius: 12, overflow: "hidden",
        boxShadow: "0 16px 40px -12px rgba(124,92,255,0.2)",
      }}>
        <div style={{
          padding: "9px 14px", background: "var(--bg-2)",
          borderBottom: "1px solid var(--border)",
          display: "flex", alignItems: "center", gap: 8,
        }}>
          <span style={{ width: 8, height: 8, borderRadius: 4, background: "#FF5F57" }} />
          <span style={{ width: 8, height: 8, borderRadius: 4, background: "#FEBC2E" }} />
          <span style={{ width: 8, height: 8, borderRadius: 4, background: "#28C840" }} />
          <span className="mono" style={{ flex: 1, textAlign: "center", fontSize: 10, color: "var(--text-mute)" }}>{code.lang}</span>
          <button className="mono" style={{
            padding: "3px 8px", background: "var(--bg-3)",
            border: "1px solid var(--border)", color: "var(--text-mid)",
            borderRadius: 3, fontSize: 9.5, cursor: "pointer",
          }}>COPY</button>
        </div>
        <pre className="mono" style={{
          margin: 0, padding: 14, fontSize: 11, lineHeight: 1.65,
          color: "var(--text-mid)", overflowX: "auto",
        }}>
          <code dangerouslySetInnerHTML={{ __html: code.body
            .replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
            .replace(/(#[^\n]*|\/\/[^\n]*)/g, '<span style="color:#6B6B78">$1</span>')
            .replace(/("[^"]*")/g, '<span style="color:#2EE6A8">$1</span>')
            .replace(/\b(curl|import|const|await|from|process)\b/g, '<span style="color:#FF9A3C">$1</span>')
            .replace(/\b(POST|GET|Bearer)\b/g, '<span style="color:#5CC8FF">$1</span>')
          }} />
        </pre>
      </div>
    </section>
  );
}

// ── Features (accordion-style by category) ────────────
function SPFeatures() {
  const cats = [
    { title: "コア機能",     icon: "Link",    items: ["短縮URL作成", "独自ドメイン", "UTM管理", "キャンペーン", "ABテスト", "ブラックリスト管理"] },
    { title: "トラッキング", icon: "Chart",   items: ["クリック計測", "リファラー解析", "CV計測", "CV属性記録", "ユーザー識別", "EP計測"] },
    { title: "広告連携",     icon: "Bolt",    items: ["Meta CAPI", "Google ECV", "LINE Tag", "X CAPI", "TikTok Events", "オーディエンス自動生成"] },
    { title: "AI / MCP",     icon: "Sparkle", items: ["MCPサーバー", "AIチャットUI", "AI分析・要約", "改善提案", "AIキャンペーン作成", "API/MCPキー発行"] },
  ];
  const [open, setOpen] = spsUS(0);
  return (
    <section style={{ padding: "36px 18px", borderTop: "1px solid var(--border-soft)" }}>
      <SPSectionHead
        eyebrow="29 features · 1 platform"
        title={<>機能、全部入り。<br />1ヶ月で全リリース。</>}
      />
      <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
        {cats.map((c, i) => {
          const Ico = I[c.icon];
          const isOpen = open === i;
          return (
            <div key={i} style={{
              background: "var(--bg-1)",
              border: "1px solid var(--border)",
              borderRadius: 12, overflow: "hidden",
            }}>
              <button onClick={() => setOpen(isOpen ? -1 : i)} style={{
                width: "100%", padding: "14px 16px",
                background: "transparent", border: "none", color: "var(--text)",
                display: "flex", alignItems: "center", gap: 12, cursor: "pointer",
              }}>
                <div style={{
                  width: 32, height: 32, borderRadius: 8,
                  background: "var(--accent-soft)", color: "var(--accent-2)",
                  display: "grid", placeItems: "center", flexShrink: 0,
                }}>
                  <Ico size={15} />
                </div>
                <span className="display" style={{ flex: 1, textAlign: "left", fontSize: 15, fontWeight: 700 }}>{c.title}</span>
                <span className="mono" style={{ fontSize: 10, color: "var(--text-mute)" }}>{c.items.length}</span>
                <span style={{ color: "var(--text-mute)", transform: isOpen ? "rotate(45deg)" : "rotate(0)", transition: "transform .2s" }}>
                  <I.Plus size={14} />
                </span>
              </button>
              {isOpen && (
                <div style={{
                  padding: "0 16px 14px",
                  display: "flex", flexWrap: "wrap", gap: 6,
                }}>
                  {c.items.map((it) => {
                    const ent = BRAND[it];
                    const L = ent ? ent.L : null;
                    return (
                      <span key={it} className="mono" style={{
                        padding: "5px 10px",
                        background: "transparent",
                        border: "1px solid var(--border)",
                        color: "var(--text-mid)",
                        borderRadius: 999, fontSize: 10.5,
                        display: "inline-flex", alignItems: "center", gap: 5,
                      }}>
                        {L ? <L size={11} /> : <I.Check size={9} style={{ color: "var(--success)" }} />}
                        {it}
                      </span>
                    );
                  })}
                </div>
              )}
            </div>
          );
        })}
      </div>
    </section>
  );
}

// ── Pricing (swipeable horizontal carousel) ───────────
function SPPricing() {
  const plans = [
    {
      name: "Free", price: "¥0", sub: "お試し",
      metrics: [["クリック","5万"],["events","—"],["独自ドメイン","—"],["AI","体験のみ"],["広告連携","—"],["アカウント","1"]],
      footer: "クレカ登録なし",
      items: ["共有ドメイン体験", "Dashboard 閲覧", "AI Console お試し"],
      primary: false,
    },
    {
      name: "Starter", price: "¥2,980", sub: "個人EC・小規模",
      metrics: [["クリック","150万"],["events","5万"],["独自ドメイン","1個"],["AI","30万 tok/月"],["MCP接続","読取1本"],["広告連携","—"]],
      footer: "年払い 20%OFF / 14日無料",
      items: ["独自ドメイン 1個", "events計測 5万/月", "AIコンソール 30万 tok/月", "メールサポート"],
      primary: false,
    },
    {
      name: "Pro", price: "¥9,800", sub: "中堅EC・D2C",
      metrics: [["クリック","500万"],["events","50万"],["独自ドメイン","3個"],["AI","100万 tok/月"],["MCP接続","書込 1/アカウント"],["広告連携","標準装備"]],
      footer: "年払い 20%OFF / 14日無料",
      items: ["AIコンソール 100万 tok/月", "MCP 書込 1/アカウント", "広告CAPI 標準", "CV計測 + A/Bテスト"],
      primary: true,
    },
    {
      name: "Business", price: "¥39,800", sub: "代理店・大手",
      metrics: [["クリック","2,000万"],["events","500万"],["独自ドメイン","無制限"],["AI","500万 tok/月"],["MCP接続","1/アカウント"],["広告連携","標準＋Webhook"]],
      footer: "年払い 20%OFF / 法人請求書対応",
      items: ["AIコンソール 500万 tok/月", "MCP アカウント数分", "8アカウント標準・99.9% SLA", "監査ログ + 専任オンボ"],
      primary: false,
    },
  ];

  const railRef = spsUR(null);
  const [idx, setIdx] = spsUS(2); // default to Pro
  const mountedRef = spsUR(false);
  const programmaticScrollRef = spsUR(false);

  // On first mount: scroll INSTANTLY to Pro (no animation, no observer race)
  spsUE(() => {
    const rail = railRef.current;
    if (!rail) return;
    const card = rail.children[2]; // Pro
    if (card) {
      programmaticScrollRef.current = true;
      rail.scrollLeft = card.offsetLeft - 18;
      // Reset flag after frame so observer ignores this scroll
      requestAnimationFrame(() => {
        requestAnimationFrame(() => { programmaticScrollRef.current = false; });
      });
    }
    mountedRef.current = true;
  }, []);

  // On subsequent idx changes (from dot clicks): smooth scroll
  spsUE(() => {
    if (!mountedRef.current) return;
    const rail = railRef.current;
    if (!rail) return;
    const card = rail.children[idx];
    if (card) {
      programmaticScrollRef.current = true;
      rail.scrollTo({ left: card.offsetLeft - 18, behavior: "smooth" });
      setTimeout(() => { programmaticScrollRef.current = false; }, 500);
    }
  }, [idx]);

  // observe scroll to update dot indicator (skip programmatic scrolls)
  spsUE(() => {
    const rail = railRef.current;
    if (!rail) return;
    const onScroll = () => {
      if (programmaticScrollRef.current) return;
      const cards = Array.from(rail.children);
      const center = rail.scrollLeft + rail.offsetWidth / 2;
      let best = 0, bestDist = Infinity;
      cards.forEach((c, i) => {
        const cardCenter = c.offsetLeft + c.offsetWidth / 2;
        const d = Math.abs(cardCenter - center);
        if (d < bestDist) { bestDist = d; best = i; }
      });
      setIdx(best);
    };
    rail.addEventListener("scroll", onScroll, { passive: true });
    return () => rail.removeEventListener("scroll", onScroll);
  }, []);

  return (
    <section id="pricing" style={{ padding: "36px 0", borderTop: "1px solid var(--border-soft)" }}>
      <div style={{ padding: "0 18px" }}>
        <SPSectionHead
          eyebrow="Transparent pricing"
          title={<>成長フェーズに、<br />ぴったり合うプラン。</>}
          sub="月額固定 + CV従量のハイブリッド。Free〜Business 4プラン、加えて Enterprise (応相談)。"
        />
      </div>

      {/* dot indicator + name */}
      <div style={{ display: "flex", justifyContent: "center", alignItems: "center", gap: 6, marginBottom: 12 }}>
        {plans.map((p, i) => (
          <button key={i} onClick={() => setIdx(i)} aria-label={p.name} style={{
            width: idx === i ? 24 : 8, height: 6,
            borderRadius: 3, border: "none",
            background: idx === i ? "var(--accent)" : "var(--border-strong)",
            transition: "width .2s, background .2s", cursor: "pointer",
          }} />
        ))}
      </div>

      {/* horizontal rail */}
      <div ref={railRef} style={{
        display: "flex", gap: 12,
        padding: "4px 18px 18px",
        overflowX: "auto", scrollSnapType: "x mandatory",
        WebkitOverflowScrolling: "touch",
        scrollbarWidth: "none",
      }}>
        <style>{`.sp-pricing-rail::-webkit-scrollbar { display: none; }`}</style>
        {plans.map((p, i) => (
          <div key={i} style={{
            flex: "0 0 86%", scrollSnapAlign: "center",
            padding: 22,
            background: p.primary ? "linear-gradient(180deg, var(--accent-soft), transparent), var(--bg-1)" : "var(--bg-1)",
            border: `1px solid ${p.primary ? "var(--accent)" : "var(--border)"}`,
            borderRadius: 14,
            display: "flex", flexDirection: "column", gap: 12,
            boxShadow: p.primary ? "0 0 30px var(--accent-glow)" : "none",
            position: "relative",
          }}>
            {p.primary && (
              <span className="mono" style={{
                position: "absolute", top: -10, left: 18,
                padding: "3px 10px",
                background: "var(--accent)", color: "white",
                borderRadius: 4, fontSize: 9.5, fontWeight: 600, letterSpacing: 0.1,
              }}>POPULAR</span>
            )}
            <div>
              <div className="display" style={{ fontSize: 20, fontWeight: 700 }}>{p.name}</div>
              <div className="mono" style={{ fontSize: 10, color: "var(--text-mute)", marginTop: 2 }}>{p.sub}</div>
            </div>
            <div className="display" style={{ fontSize: 32, fontWeight: 700, letterSpacing: -0.02 }}>
              {p.price}<span style={{ fontSize: 12, color: "var(--text-mute)", fontWeight: 400 }}> / 月</span>
            </div>
            <div style={{
              display: "flex", flexDirection: "column", gap: 3,
              padding: "10px 0",
              borderTop: "1px solid var(--border)", borderBottom: "1px solid var(--border)",
            }}>
              {p.metrics.map(([k, v]) => (
                <div key={k} style={{ display: "flex", justifyContent: "space-between", fontSize: 11 }}>
                  <span className="mono" style={{ color: "var(--text-mute)", letterSpacing: 0.04 }}>{k}</span>
                  <span>{v}</span>
                </div>
              ))}
            </div>
            <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "flex", flexDirection: "column", gap: 5, flex: 1 }}>
              {p.items.map((it) => (
                <li key={it} style={{ fontSize: 11.5, color: "var(--text-mid)", display: "flex", gap: 6, alignItems: "flex-start" }}>
                  <I.Check size={10} style={{ color: "var(--success)", marginTop: 3, flexShrink: 0 }} />
                  <span>{it}</span>
                </li>
              ))}
            </ul>
            <div className="mono" style={{ fontSize: 9.5, color: "var(--text-mute)", letterSpacing: 0.04 }}>{p.footer}</div>
            <button onClick={() => location.href = '/app/signup'} style={{
              padding: "11px 14px",
              background: p.primary ? "var(--accent)" : "var(--bg-3)",
              color: p.primary ? "white" : "var(--text)",
              border: p.primary ? "none" : "1px solid var(--border-strong)",
              borderRadius: 7, fontSize: 13, fontWeight: 600, cursor: "pointer",
              boxShadow: p.primary ? "0 0 20px var(--accent-glow)" : "none",
            }}>無料ではじめる</button>
          </div>
        ))}
      </div>

      {/* Enterprise tile */}
      <div style={{ padding: "0 18px" }}>
        <div style={{
          padding: "16px 18px",
          background: "var(--bg-1)",
          border: "1px dashed var(--border-strong)",
          borderRadius: 12,
        }}>
          <div className="display" style={{ fontSize: 17, fontWeight: 700 }}>
            Enterprise
            <span className="mono" style={{ fontSize: 10, color: "var(--text-mute)", fontWeight: 400, marginLeft: 8 }}>応相談</span>
          </div>
          <p style={{ margin: "6px 0 12px", fontSize: 12, color: "var(--text-mid)", lineHeight: 1.55 }}>
            ホワイトラベル・専属サポート・カスタムSLA・プライベートデプロイ。
          </p>
          <button onClick={() => location.href = '/teaser/'} style={{
            padding: "10px 18px",
            background: "var(--bg-3)", color: "var(--text)",
            border: "1px solid var(--border-strong)", borderRadius: 7,
            fontSize: 12.5, fontWeight: 500, cursor: "pointer",
          }}>お問い合わせ</button>
        </div>
      </div>
    </section>
  );
}

// ── FAQ ──────────────────────────────────────────────
function SPFAQ() {
  const [open, setOpen] = spsUS(0);
  const qs = [
    { q: "自分のドメインを使うのに、既存サイトに影響はある?", a: "ありません。サブドメインを1つ追加するだけ。メール（MX）には一切触れません。link.example.co や go.example.co 等を新規追加する形です。" },
    { q: "iOS 14 / ATT でCV計測が落ちないの?", a: "urlapi はクリックを基点とした計測なので、ATTの影響を受けにくい設計。さらに Meta CAPI / Google Enhanced CV といったサーバーサイドAPIを通じて、Pixel/Tag単独より高い計測精度を実現します。" },
    { q: "Bitlyとの違いは?", a: "Bitlyは管理画面中心の汎用短縮URL。urlapi は API / MCP / AIチャットでの操作が前提で、広告API連携が標準装備。データの所有権は完全に顧客側にあります。" },
    { q: "MCPって何?", a: "Model Context Protocol。Claude や ChatGPT から外部ツールを呼び出すための標準プロトコル。urlapi MCP を入れると、AIに「春キャンペーン作って」と言うだけで全部自動実行されます。" },
    { q: "解約したらドメインはどうなる?", a: "顧客のもの。CNAMEレコードを削除すれば切り離し完了。urlapi に何も残りません。" },
    { q: "Enterprise プランはどんな企業向け?", a: "ホワイトラベル・カスタムSLA・専属サポート・プライベートデプロイなどが必要な代理店や大手向け。応相談です。" },
  ];
  return (
    <section style={{ padding: "36px 18px", borderTop: "1px solid var(--border-soft)" }}>
      <SPSectionHead eyebrow="Questions" title={<>よくある質問。</>} />
      <div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
        {qs.map((f, i) => (
          <div key={i} onClick={() => setOpen(open === i ? -1 : i)} style={{
            background: "var(--bg-1)",
            border: "1px solid var(--border)",
            borderRadius: 10, cursor: "pointer", overflow: "hidden",
          }}>
            <div style={{ padding: "14px 14px", display: "flex", alignItems: "flex-start", gap: 10 }}>
              <span style={{ flex: 1, fontSize: 13, fontWeight: 600, lineHeight: 1.45 }}>{f.q}</span>
              <span style={{
                color: "var(--text-mute)",
                transform: open === i ? "rotate(45deg)" : "rotate(0)",
                transition: "transform .2s", flexShrink: 0, marginTop: 2,
              }}><I.Plus size={14} /></span>
            </div>
            {open === i && (
              <div style={{ padding: "0 14px 14px", fontSize: 12, color: "var(--text-mid)", lineHeight: 1.7 }}>{f.a}</div>
            )}
          </div>
        ))}
      </div>
    </section>
  );
}

// ── Final CTA + Footer ───────────────────────────────
function SPFinalCTA() {
  return (
    <section style={{ padding: "36px 18px", position: "relative", overflow: "hidden", borderTop: "1px solid var(--border-soft)" }}>
      <div style={{ position: "absolute", inset: 0, background: "radial-gradient(ellipse 400px 300px at 50% 50%, var(--accent-glow), transparent 70%)", pointerEvents: "none" }} />
      <div style={{ position: "relative", textAlign: "center" }}>
        <h2 className="display" style={{
          fontSize: "clamp(32px, 9.5vw, 44px)", fontWeight: 800,
          margin: 0, letterSpacing: -0.03, lineHeight: 1.08,
        }}>
          クリックを、<br />データ資産に変えるAI。
        </h2>
        <p style={{ fontSize: 13.5, color: "var(--text-mid)", marginTop: 18, lineHeight: 1.65 }}>
          クレカ登録なしで、いますぐ無料ではじめられます。
        </p>
        <button onClick={() => {
          const el = document.getElementById('signup');
          if (el) el.scrollIntoView({ behavior: 'smooth', block: 'center' });
        }} style={{
          marginTop: 24,
          padding: "14px 28px",
          background: "var(--accent)", color: "white",
          border: "none", borderRadius: 10,
          fontSize: 14, fontWeight: 700, cursor: "pointer",
          display: "inline-flex", alignItems: "center", gap: 8,
          boxShadow: "0 0 36px var(--accent-glow), 0 8px 24px rgba(124,92,255,0.3)",
        }}>
          <I.Sparkle size={13} /> 無料ではじめる
        </button>
      </div>
    </section>
  );
}

function SPFooter() {
  return (
    <footer style={{
      borderTop: "1px solid var(--border)",
      padding: "32px 18px 100px",
      background: "var(--bg-1)",
    }}>
      <div style={{ marginBottom: 24 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 12 }}>
          <div style={{ width: 22, height: 22, borderRadius: 5, background: "linear-gradient(135deg, var(--accent), var(--accent-2))", display: "grid", placeItems: "center" }}>
            <I.Logo size={12} color="#0A0A0A" />
          </div>
          <span className="display" style={{ fontSize: 15, fontWeight: 700 }}>urlapi<span style={{ color: "var(--accent)" }}>.</span>me</span>
        </div>
        <p className="mono" style={{ fontSize: 10.5, color: "var(--text-mute)", lineHeight: 1.7, margin: 0 }}>
          AIで完結する、<br />トラッキング & データ分析プラットフォーム<br /><br />
          © 2026 株式会社9lick.me
        </p>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20 }}>
        {[
          { t: "Product",    l: [["機能", "#features"], ["API/MCP", "#developer"], ["料金", "#pricing"], ["TQO 白書", "/tqo"]] },
          { t: "Developers", l: [["Docs", "/docs/"], ["API Ref", "/docs/api/events"], ["MCP", "/docs/auth#mcp-key"], ["Status", "/status"]] },
          { t: "Company",    l: [["About", "#"], ["Blog", "#"], ["Careers", "#"], ["Press", "#"]] },
          { t: "Legal",      l: [["利用規約", "/terms"], ["プライバシー", "/privacy"], ["トラッキング", "/tracking"], ["特商法", "/tokutei"]] },
        ].map((c) => (
          <div key={c.t}>
            <div className="mono" style={{
              fontSize: 10, color: "var(--text-mute)", letterSpacing: 0.14,
              textTransform: "uppercase", marginBottom: 10,
            }}>{c.t}</div>
            <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "flex", flexDirection: "column", gap: 7 }}>
              {c.l.map(([label, href]) => (
                <li key={label}>
                  <a href={href} style={{ fontSize: 11.5, color: "var(--text-mid)", textDecoration: "none" }}>{label}</a>
                </li>
              ))}
            </ul>
          </div>
        ))}
      </div>
    </footer>
  );
}

window.SPProblem = SPProblem;
window.SPPillars = SPPillars;
window.SPDeveloper = SPDeveloper;
window.SPFeatures = SPFeatures;
window.SPPricing = SPPricing;
window.SPFAQ = SPFAQ;
window.SPFinalCTA = SPFinalCTA;
window.SPFooter = SPFooter;
