/* TEN GROW — Home (トップページ) */
const DS_Home = window.TENGROWDesignSystem_8927da;

function TG_Home() {
  const { SectionHeading, Button, CircleButton, ServiceCard, NewsCard, Stat, Badge } = DS_Home;
  const { Container, Section, Photo, GhostWord, VideoSlot, ParticleText } = window;
  const [sceneI, setSceneI] = React.useState(0);
  const heroScenes = [
    { word: "TEN GROW", cap: "成果報酬型広告のプロフェッショナル" },
    { word: "PERFORMANCE", cap: "成果に、まっすぐ向き合う。" },
    { word: "CREATIVE", cap: "動かす、SNS動画クリエイティブ。" },
    { word: "GROWTH", cap: "その先の、成長まで伴走する。" },
  ];
  const Arrow = () => <svg width="14" height="14" viewBox="0 0 24 24" fill="none"><path d="M5 12h14M13 6l6 6-6 6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/></svg>;

  const services = [
    { index: "01", badge: "成果報酬型", badgeColor: "red", en: "Performance Marketing", title: "成果報酬型マーケティング支援", description: "広告を運用するだけでなく、事業の利益構造から逆算して戦略を設計。成果に連動した支援体制で、継続的な売上成長を目指します。" },
    { index: "02", badge: "販売導線", badgeColor: "amber", en: "Sales Funnel Design", title: "集客・販売導線構築", description: "集客して終わりではなく、問い合わせ・商談・成約につながる導線をLP・Web・LINEまで一気通貫で構築します。" },
    { index: "03", badge: "SNS・ブランド", badgeColor: "ink", en: "Brand / SNS Growth", title: "SNS・ブランド成長支援", description: "企業や経営者の価値を言語化し、認知・採用・集客につながるブランドをSNS運用と発信で育てます。" },
  ];
  const news = [
    { date: "2026.07.03", category: "お知らせ", categoryColor: "ink", title: "株式会社TEN GROWを設立しました" },
    { date: "2026.07.10", category: "プレス", categoryColor: "amber", title: "コーポレートサイトを公開しました" },
    { date: "2026.07.16", category: "サービス", categoryColor: "teal", title: "成果報酬型広告運用サービスの提供を開始しました" },
  ];
  const strengths = [
    { src: "./assets/strength-1.png", en: "Marketing", title: "マーケティング", desc: "成果から逆算した広告設計で、獲得と売上に直結させます。" },
    { src: "./assets/strength-2.png", en: "One-stop", title: "ワンストップ", desc: "媒体運用・クリエイティブ制作・分析改善までを一気通貫で。" },
    { src: "./assets/strength-3.png", en: "Performance", title: "成果報酬型", desc: "費用は成果に応じて。リスクを抑えて成果に投資できます。" },
  ];

  const StrengthCard = ({ s, i }) => {
    const [hover, setHover] = React.useState(false);
    return (
      <a href="#services" onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}
        style={{ display: "flex", flexDirection: "column", height: "100%", textDecoration: "none", color: "var(--color-text)", background: "#fff", boxShadow: hover ? "var(--shadow-lg)" : "var(--shadow-sm)", transform: hover ? "translateY(-6px)" : "none", transition: "transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out)" }}>
        <div style={{ overflow: "hidden" }}>
          <Photo ratio="16 / 10" src={s.src} alt={s.title} radius="0" style={{ transform: hover ? "scale(1.05)" : "scale(1)", transition: "transform 0.6s var(--ease-out)" }} />
        </div>
        <div style={{ display: "flex", flexDirection: "column", flexGrow: 1, padding: "var(--space-5) var(--space-5) var(--space-6)" }}>
          <div style={{ fontFamily: "var(--font-en-ui)", fontWeight: 800, textTransform: "uppercase", letterSpacing: "0.1em", fontSize: "0.8125rem", background: "var(--gradient-brand)", WebkitBackgroundClip: "text", backgroundClip: "text", WebkitTextFillColor: "transparent", marginBottom: "0.5rem" }}>{String(i + 1).padStart(2, "0")}. {s.en}</div>
          <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: "var(--space-3)" }}>
            <h3 style={{ fontFamily: "var(--font-jp-heading)", fontWeight: 800, fontSize: "1.375rem", letterSpacing: "-0.02em", margin: 0 }}>{s.title}</h3>
            <span style={{ flexShrink: 0, width: 34, height: 34, background: hover ? "var(--color-primary)" : "var(--ink-900)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", transition: "background var(--dur) var(--ease-out)" }}>
              <svg width="15" height="15" viewBox="0 0 24 24" fill="none"><path d="M5 12h14M13 6l6 6-6 6" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/></svg>
            </span>
          </div>
          <p style={{ margin: "var(--space-3) 0 0", color: "var(--color-text-secondary)", fontSize: "var(--fs-body-sm)", lineHeight: 1.8 }}>{s.desc}</p>
        </div>
      </a>
    );
  };

  const ServiceCarousel = () => {
    const trackRef = React.useRef(null);
    const [idx, setIdx] = React.useState(0);
    const idxRef = React.useRef(0);
    const progRef = React.useRef(false);
    const goTo = (i) => {
      const el = trackRef.current; if (!el) return;
      const cards = el.querySelectorAll("[data-card]"); if (!cards.length) return;
      const n = (i + cards.length) % cards.length;
      const left = cards[n].offsetLeft - cards[0].offsetLeft;
      progRef.current = true;
      el.scrollTo({ left, behavior: "smooth" });
      idxRef.current = n; setIdx(n);
      clearTimeout(el._progT); el._progT = setTimeout(() => { progRef.current = false; }, 800);
    };
    const onScroll = () => {
      if (progRef.current) return; // don't clobber the counter during auto/programmatic scroll
      const el = trackRef.current; if (!el) return;
      const cards = el.querySelectorAll("[data-card]"); if (!cards.length) return;
      const base = cards[0].offsetLeft;
      let best = 0, bd = Infinity;
      cards.forEach((c, i) => { const d = Math.abs((c.offsetLeft - base) - el.scrollLeft); if (d < bd) { bd = d; best = i; } });
      idxRef.current = best; setIdx(best);
    };
    // auto-advance: ping-pong 01→06→01 (no jarring full rewind), pauses on hover/touch
    const dirRef = React.useRef(1);
    React.useEffect(() => {
      if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
      const el = trackRef.current; if (!el) return;
      let paused = false;
      const pause = () => { paused = true; }, resume = () => { paused = false; };
      el.addEventListener("pointerenter", pause);
      el.addEventListener("pointerleave", resume);
      el.addEventListener("pointerdown", pause);
      const last = services.length - 1;
      const id = setInterval(() => {
        if (paused) return;
        let next = idxRef.current + dirRef.current;
        if (next > last) { dirRef.current = -1; next = last - 1; }
        else if (next < 0) { dirRef.current = 1; next = 1; }
        goTo(next);
      }, 3200);
      return () => { clearInterval(id); el.removeEventListener("pointerenter", pause); el.removeEventListener("pointerleave", resume); el.removeEventListener("pointerdown", pause); };
    }, []);
    const catColors = { "成果報酬型": "var(--red-500)", "販売導線": "var(--amber-600)", "SNS・ブランド": "var(--ink-900)" };
    return (
      <div>
        <div ref={trackRef} onScroll={onScroll} className="tg-svc-track" style={{ display: "flex", gap: "24px", overflowX: "auto", scrollSnapType: "x mandatory", padding: "0 var(--gutter) var(--space-4)", WebkitOverflowScrolling: "touch" }}>
          {services.map((s, i) => (
            <a key={i} data-card href="#services" style={{ scrollSnapAlign: "start", flex: "0 0 clamp(280px, 34vw, 420px)", background: "#fff", color: "var(--color-text)", textDecoration: "none", display: "flex", flexDirection: "column", minHeight: 320 }}>
              <div style={{ height: 3, background: "var(--gradient-brand)" }} />
              <div style={{ padding: "var(--space-6) var(--space-6) var(--space-5)", borderBottom: "1px solid var(--color-border)" }}>
                <div style={{ display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "var(--space-4)" }}>
                  <span style={{ fontFamily: "var(--font-en-ui)", fontWeight: 800, fontStyle: "italic", fontSize: "clamp(3rem, 2rem + 2vw, 4.25rem)", lineHeight: 0.85, background: "var(--gradient-brand)", WebkitBackgroundClip: "text", backgroundClip: "text", WebkitTextFillColor: "transparent" }}>{String(i + 1).padStart(2, "0")}</span>
                  <span style={{ fontFamily: "var(--font-jp-heading)", fontWeight: 700, fontSize: "0.6875rem", letterSpacing: ".08em", color: "#fff", background: catColors[s.badge] || "var(--color-primary)", padding: "0.3rem 0.7rem", marginTop: "0.5rem" }}>{s.badge}</span>
                </div>
                <div style={{ fontFamily: "var(--font-jp-heading)", fontWeight: 900, fontSize: "1.3rem", letterSpacing: "-0.01em", marginTop: "var(--space-3)" }}>{s.title}</div>
              </div>
              <div style={{ padding: "var(--space-5) var(--space-6)", flexGrow: 1 }}>
                <p style={{ margin: 0, color: "var(--color-text-secondary)", fontSize: "var(--fs-body-sm)", lineHeight: 1.9 }}>{s.description}</p>
              </div>
              <div style={{ display: "flex", justifyContent: "flex-end" }}>
                <span style={{ width: 40, height: 40, background: "var(--color-primary)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center" }}>
                  <svg width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M5 12h14M13 6l6 6-6 6" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/></svg>
                </span>
              </div>
            </a>
          ))}
        </div>
        <div style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: "var(--space-3)", marginTop: "var(--space-6)" }}>
          <div style={{ display: "flex", gap: "0.6rem" }}>
            {services.map((_, i) => (
              <button key={i} onClick={() => goTo(i)} aria-label={`サービス${i + 1}`} style={{ width: 11, height: 11, padding: 0, borderRadius: "50%", border: "1px solid rgba(25,22,19,0.25)", background: i === idx ? "var(--color-primary)" : "transparent", borderColor: i === idx ? "var(--color-primary)" : "rgba(25,22,19,0.25)", cursor: "pointer", transition: "all var(--dur) var(--ease-out)" }} />
            ))}
          </div>
          <div style={{ fontFamily: "var(--font-en-ui)", fontWeight: 700, fontSize: "0.875rem", letterSpacing: ".1em", color: "var(--ink-500)" }}>
            {String(idx + 1).padStart(2, "0")} / {String(services.length).padStart(2, "0")}
          </div>
        </div>
      </div>
    );
  };

  return (
    <div>
      {/* ---------- HERO (sticky — light field, auto-cycling particle scenes) ---------- */}
      <section style={{ position: "sticky", top: 0, zIndex: 0, overflow: "hidden", background: "linear-gradient(180deg, #FFFFFF 0%, #FBF7F0 100%)", height: "100svh", minHeight: 520, display: "flex" }}>
        {/* auto-cycling particle scenes */}
        <ParticleText scenes={heroScenes.map((s) => s.word)} interval={3600} onScene={setSceneI} />
        {/* fixed eyebrow, top — small & refined so the particle wordmark stays the hero */}
        <div style={{ position: "absolute", top: "clamp(6rem, 5rem + 4vh, 8.5rem)", left: 0, right: 0, zIndex: 2, textAlign: "center", pointerEvents: "none", padding: "0 var(--gutter)" }}>
          <p style={{ margin: 0, fontFamily: "var(--font-en-ui)", fontWeight: 700, textTransform: "uppercase", color: "var(--ink-500)", fontSize: "0.8125rem", letterSpacing: ".26em", lineHeight: 1.6 }}>
            Performance Advertising Partner
          </p>
        </div>
        {/* scene caption, lower third — synced to the cycling word */}
        <div style={{ position: "absolute", bottom: "clamp(5.5rem, 4rem + 8vh, 10rem)", left: 0, right: 0, zIndex: 2, textAlign: "center", pointerEvents: "none", padding: "0 var(--gutter)" }}>
          <p key={sceneI} style={{ margin: 0, fontFamily: "var(--font-jp-heading)", fontWeight: 700, fontSize: "clamp(1rem, 0.85rem + 0.9vw, 1.5rem)", letterSpacing: ".08em", color: "var(--ink-800)", animation: "tgFadeUp 0.6s var(--ease-out) both" }}>
            {heroScenes[sceneI].cap}
          </p>
        </div>
        {/* date + scroll chevron */}
        <div aria-hidden="true" style={{ position: "absolute", left: "50%", transform: "translateX(-50%)", bottom: "var(--space-6)", zIndex: 2, display: "flex", flexDirection: "column", alignItems: "center", gap: "0.9rem", color: "var(--ink-500)" }}>
          <span style={{ fontFamily: "var(--font-en-ui)", fontSize: "0.75rem", letterSpacing: ".28em", fontWeight: 700 }}>2026 — GROWTH</span>
          <svg width="20" height="20" viewBox="0 0 24 24" fill="none" style={{ animation: "tgBob 1.8s var(--ease-soft) infinite" }}><path d="M6 9l6 6 6-6" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg>
        </div>
      </section>

      {/* ---------- everything below scrolls up over the pinned hero ---------- */}
      <div style={{ position: "relative", zIndex: 1 }}>
      {/* ---------- STRENGTHS (About TEN GROW) — first over the hero ---------- */}
      <Section tone="sand" id="about" size="wide" style={{ position: "relative", overflow: "hidden", background: "#EEEAE3" }}>
        <div style={{ display: "flex", flexWrap: "wrap", alignItems: "flex-end", justifyContent: "space-between", gap: "var(--space-5)", marginBottom: "var(--space-8)" }}>
          <div>
            <div style={{ fontFamily: "var(--font-jp-heading)", fontWeight: 700, fontSize: "var(--fs-body)", letterSpacing: ".08em", color: "var(--color-text-secondary)", marginBottom: "var(--space-3)" }}>TEN GROWの強み</div>
            <div style={{ display: "flex", alignItems: "center", gap: "var(--space-4)" }}>
              <h2 style={{ fontFamily: "var(--font-en-ui)", fontWeight: 800, textTransform: "uppercase", fontSize: "clamp(2.25rem,1.4rem + 3.2vw,4rem)", letterSpacing: "0.08em", margin: 0, lineHeight: 1.05 }}>About TEN GROW</h2>
              <a href="#company" aria-label="会社概要へ" style={{ flexShrink: 0, width: 48, height: 48, background: "var(--color-primary)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center" }}>
                <svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M5 12h14M13 6l6 6-6 6" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/></svg>
              </a>
            </div>
          </div>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: "var(--space-6)" }} className="tg-3col">
          {strengths.map((s, i) => <StrengthCard key={i} s={s} i={i} />)}
        </div>
      </Section>

      {/* ---------- SERVICE (dark, horizontal scroll) ---------- */}
      <section id="services" style={{ background: "var(--color-bg)", color: "var(--color-text)", position: "relative", overflow: "hidden", padding: "var(--section-y) 0" }}>
        <Container size="wide">
          <div style={{ display: "flex", alignItems: "center", gap: "var(--space-4)", marginBottom: "var(--space-8)" }}>
            <h2 style={{ fontFamily: "var(--font-en-ui)", fontWeight: 800, textTransform: "uppercase", color: "var(--ink-900)", fontSize: "clamp(2.25rem, 1.4rem + 3.2vw, 4rem)", letterSpacing: "0.08em", margin: 0, lineHeight: 1.05 }}>Service</h2>
            <a href="#services" aria-label="事業内容へ" style={{ flexShrink: 0, width: 48, height: 48, background: "var(--color-primary)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center" }}>
              <svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M5 12h14M13 6l6 6-6 6" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/></svg>
            </a>
          </div>
        </Container>
        <ServiceCarousel />
      </section>

      {/* ---------- COMPANY / RECRUIT split tiles ---------- */}
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr" }} className="tg-2col">
        {[
          { label: "会社情報", en: "Company", href: "#company", src: "./assets/office.png" },
          { label: "採用情報", en: "Recruit", href: "#contact", src: "./assets/team.png" },
        ].map((t) => (
          <a key={t.en} href={t.href} className="tg-split-tile" style={{ position: "relative", display: "block", minHeight: "clamp(320px, 38vw, 520px)", overflow: "hidden", textDecoration: "none" }}>
            <Photo ratio="auto" src={t.src} alt={t.label} radius="0" style={{ position: "absolute", inset: 0, height: "100%" }} />
            <div aria-hidden="true" style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(23,20,17,0.15) 0%, rgba(23,20,17,0.5) 100%)" }} />
            <div style={{ position: "absolute", left: "var(--gutter)", bottom: "var(--space-8)", display: "flex", alignItems: "center", gap: "var(--space-4)" }}>
              <div>
                <div style={{ color: "#fff", fontFamily: "var(--font-jp-heading)", fontWeight: 700, fontSize: "var(--fs-body)", letterSpacing: ".08em", marginBottom: "0.3rem" }}>{t.label}</div>
                <div style={{ color: "#fff", fontFamily: "var(--font-en-ui)", fontWeight: 800, textTransform: "uppercase", fontSize: "clamp(2.25rem, 1.4rem + 3.2vw, 4rem)", lineHeight: 1.05, letterSpacing: "0.08em" }}>{t.en}</div>
              </div>
              <span style={{ flexShrink: 0, width: 48, height: 48, background: "var(--color-primary)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", alignSelf: "flex-end" }}>
                <svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M5 12h14M13 6l6 6-6 6" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/></svg>
              </span>
            </div>
          </a>
        ))}
      </div>

      {/* ---------- NEWS ---------- */}
      <Section tone="surface" id="news">
        <div style={{ display: "grid", gridTemplateColumns: "0.7fr 1.3fr", gap: "var(--space-9)" }} className="tg-2col">
          <div>
            <SectionHeading en="News" title="お知らせ" />
            <div style={{ marginTop: "var(--space-5)" }}>
              <Button variant="ghost" href="#news">一覧を見る</Button>
            </div>
          </div>
          <div style={{ borderTop: "1px solid var(--color-border)" }}>
            {news.map((n,i)=><NewsCard key={i} {...n} href="#news" />)}
          </div>
        </div>
      </Section>

      {/* ---------- CTA ---------- */}
      <section style={{ background: "var(--gradient-brand)", color: "#fff" }}>
        <Container size="base" style={{ padding: "var(--section-y) var(--gutter)", textAlign: "center" }}>
          <h2 style={{ color: "#fff", fontSize: "clamp(1.75rem,1.2rem + 2.4vw,3rem)", margin: "0 0 var(--space-4)", letterSpacing: ".04em", fontWeight: 900 }}>売上の相談は、お気軽に。</h2>
          <p style={{ color: "rgba(255,255,255,0.88)", maxWidth: "32em", margin: "0 auto var(--space-7)", lineHeight: "var(--lh-body)" }}>まずは現状の課題をお聞かせください。成果報酬型だからこそ、最適な一手をご提案します。</p>
          <Button variant="dark" size="lg" href="#contact" icon={<Arrow/>}>お問い合わせフォームへ</Button>
        </Container>
      </section>
      </div>
    </div>
  );
}
window.TG_Home = TG_Home;
