// Sasabe Seitai-in — Hero Section
// Yobuko, Karatsu, Saga. Founded 2014.

const { useState, useEffect, useRef } = React;

// ---------- SVG Placeholder: Yobuko port at golden hour ----------
function PortPhotoPlaceholder() {
  return (
    <svg
      viewBox="0 0 1200 1400"
      preserveAspectRatio="xMidYMid slice"
      style={{ width: "100%", height: "100%", display: "block" }}
      aria-label="呼子港 — 夕景プレースホルダ"
    >
      <defs>
        <linearGradient id="sky" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#cdd9d8" />
          <stop offset="38%" stopColor="#e8d4b3" />
          <stop offset="48%" stopColor="#f0c79a" />
          <stop offset="55%" stopColor="#9bb4b8" />
          <stop offset="100%" stopColor="#3e5e6c" />
        </linearGradient>
        <linearGradient id="seaShimmer" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#e8c89a" stopOpacity="0.55" />
          <stop offset="100%" stopColor="#2c7da0" stopOpacity="0" />
        </linearGradient>
        <linearGradient id="warmth" x1="0" y1="0" x2="1" y2="0">
          <stop offset="0%" stopColor="#b89968" stopOpacity="0" />
          <stop offset="55%" stopColor="#d4a972" stopOpacity="0.18" />
          <stop offset="100%" stopColor="#e5d5b7" stopOpacity="0.30" />
        </linearGradient>
        <pattern id="netPattern" patternUnits="userSpaceOnUse" width="14" height="14" patternTransform="rotate(45)">
          <path d="M0 0 L14 0 M0 0 L0 14" stroke="#1f2937" strokeWidth="0.5" opacity="0.55" />
        </pattern>
        <filter id="soft" x="-10%" y="-10%" width="120%" height="120%">
          <feGaussianBlur stdDeviation="0.6" />
        </filter>
      </defs>
      <rect width="1200" height="1400" fill="url(#sky)" />
      <rect x="0" y="510" width="1200" height="80" fill="#f5d6a4" opacity="0.45" filter="url(#soft)" />
      <path d="M0 540 Q 180 520 320 528 T 620 524 Q 780 520 920 530 T 1200 526 L 1200 560 L 0 560 Z" fill="#2c7da0" opacity="0.45" />
      <path d="M0 552 Q 220 544 380 548 T 720 546 Q 900 542 1060 550 T 1200 548 L 1200 600 L 0 600 Z" fill="#1f2937" opacity="0.18" />
      {Array.from({ length: 28 }).map((_, i) => (
        <line key={i} x1="0" x2="1200" y1={600 + i * 28 + (i % 2) * 3} y2={600 + i * 28 + (i % 2) * 3} stroke="#1f2937" strokeWidth="0.6" opacity={0.05 + (i / 28) * 0.08} />
      ))}
      <rect x="0" y="560" width="1200" height="840" fill="url(#seaShimmer)" />
      <rect x="0" y="0" width="1200" height="1400" fill="url(#warmth)" />
      <g opacity="0.78">
        <line x1="120" y1="700" x2="120" y2="430" stroke="#1f2937" strokeWidth="3.5" />
        <line x1="200" y1="710" x2="200" y2="410" stroke="#1f2937" strokeWidth="3.5" />
        <line x1="280" y1="700" x2="280" y2="450" stroke="#1f2937" strokeWidth="3.5" />
        <path d="M120 430 Q 200 470 280 450 L 280 700 L 120 700 Z" fill="url(#netPattern)" opacity="0.95" />
        <path d="M120 430 Q 200 470 280 450" fill="none" stroke="#1f2937" strokeWidth="2" />
      </g>
      <g opacity="0.85">
        <line x1="780" y1="780" x2="780" y2="360" stroke="#1f2937" strokeWidth="4" />
        <line x1="900" y1="790" x2="900" y2="340" stroke="#1f2937" strokeWidth="4" />
        <line x1="1020" y1="780" x2="1020" y2="380" stroke="#1f2937" strokeWidth="4" />
        <line x1="1130" y1="800" x2="1130" y2="420" stroke="#1f2937" strokeWidth="4" />
        <path d="M780 360 Q 850 400 900 340 Q 970 390 1020 380 Q 1080 410 1130 420 L 1130 800 L 780 780 Z" fill="url(#netPattern)" opacity="0.92" />
        <path d="M780 360 Q 850 400 900 340 Q 970 390 1020 380 Q 1080 410 1130 420" fill="none" stroke="#1f2937" strokeWidth="2" />
        <path d="M820 380 Q 830 480 818 600" fill="none" stroke="#1f2937" strokeWidth="0.8" opacity="0.6" />
        <path d="M870 360 Q 882 500 868 640" fill="none" stroke="#1f2937" strokeWidth="0.8" opacity="0.6" />
        <path d="M950 360 Q 962 510 948 660" fill="none" stroke="#1f2937" strokeWidth="0.8" opacity="0.6" />
      </g>
      <ellipse cx="540" cy="640" rx="14" ry="3" fill="#1f2937" opacity="0.55" />
      <line x1="540" y1="640" x2="540" y2="624" stroke="#1f2937" strokeWidth="1" opacity="0.55" />
      <g opacity="0.35">
        <line x1="500" y1="680" x2="600" y2="680" stroke="#f0c79a" strokeWidth="1" />
        <line x1="480" y1="710" x2="620" y2="710" stroke="#f0c79a" strokeWidth="1" />
        <line x1="510" y1="740" x2="610" y2="740" stroke="#f0c79a" strokeWidth="0.7" />
      </g>
      <radialGradient id="vig" cx="20%" cy="85%" r="55%">
        <stop offset="0%" stopColor="#1f2937" stopOpacity="0.28" />
        <stop offset="100%" stopColor="#1f2937" stopOpacity="0" />
      </radialGradient>
      <rect width="1200" height="1400" fill="url(#vig)" />
    </svg>
  );
}

// ---------- Header ----------
function Header({ onOpenMenu, scrolled, sea }) {
  const navItems = ["院長", "症状別", "お客様の声", "料金", "アクセス", "ご予約"];
  return (
    <header style={{ position: "fixed", top: 0, left: 0, right: 0, zIndex: 50, backgroundColor: scrolled ? "rgba(251, 248, 242, 0.88)" : "rgba(251, 248, 242, 0.55)", backdropFilter: "saturate(140%) blur(14px)", WebkitBackdropFilter: "saturate(140%) blur(14px)", borderBottom: scrolled ? "1px solid rgba(31,41,55,0.08)" : "1px solid transparent", transition: "all 280ms ease" }}>
      <div style={{ maxWidth: 1480, margin: "0 auto", padding: "14px 36px", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 24 }}>
        <a href="#" style={{ display: "flex", alignItems: "center", gap: 14, textDecoration: "none", color: "#1F2937" }}>
          <div style={{ display: "flex", flexDirection: "column", lineHeight: 1 }}>
            <span style={{ fontFamily: "Inter, sans-serif", fontSize: 9.5, letterSpacing: "0.32em", fontWeight: 500, color: "#1F2937", textTransform: "uppercase" }}>Sasabe Seitai-in</span>
            <span style={{ height: 1, background: sea, margin: "6px 0", width: 38 }} />
            <span style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 17, fontWeight: 500, letterSpacing: "0.14em", color: "#1F2937" }}>笹部整体院</span>
          </div>
        </a>
        <nav className="desktop-nav" style={{ display: "flex", gap: 30 }}>
          {navItems.map((item, i) => (
            <a key={i} href="#" style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 13.5, fontWeight: 500, color: "#1F2937", textDecoration: "none", letterSpacing: "0.16em", position: "relative", paddingBottom: 4 }} onMouseEnter={(e) => (e.currentTarget.style.color = sea)} onMouseLeave={(e) => (e.currentTarget.style.color = "#1F2937")}>{item}</a>
          ))}
        </nav>
        <div className="desktop-phone" style={{ display: "flex", alignItems: "center", gap: 12 }}>
          <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end", lineHeight: 1 }}>
            <span style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 10.5, color: "#6b6b6b", letterSpacing: "0.32em", marginBottom: 4 }}>お電話</span>
            <a href="tel:0955826062" style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 22, fontWeight: 500, color: sea, textDecoration: "none", letterSpacing: "0.04em" }}>0955-82-6062</a>
          </div>
        </div>
        <button className="mobile-menu-btn" onClick={onOpenMenu} style={{ display: "none", background: "none", border: "none", padding: 8, cursor: "pointer", color: "#1F2937" }} aria-label="メニュー">
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none">
            <line x1="3" y1="7" x2="21" y2="7" stroke="currentColor" strokeWidth="1.5" />
            <line x1="3" y1="13" x2="21" y2="13" stroke="currentColor" strokeWidth="1.5" />
            <line x1="3" y1="19" x2="14" y2="19" stroke="currentColor" strokeWidth="1.5" />
          </svg>
        </button>
      </div>
    </header>
  );
}

// ---------- Mobile Drawer ----------
function MobileDrawer({ open, onClose, sea }) {
  const items = ["院長", "症状別", "お客様の声", "料金", "アクセス", "ご予約"];
  return (
    <div style={{ position: "fixed", inset: 0, zIndex: 100, pointerEvents: open ? "auto" : "none" }}>
      <div onClick={onClose} style={{ position: "absolute", inset: 0, background: "rgba(31,41,55,0.4)", opacity: open ? 1 : 0, transition: "opacity 260ms ease" }} />
      <aside style={{ position: "absolute", top: 0, right: 0, bottom: 0, width: "min(86vw, 360px)", background: "#FBF8F2", padding: "28px 30px", transform: open ? "translateX(0)" : "translateX(100%)", transition: "transform 320ms cubic-bezier(.2,.7,.2,1)", display: "flex", flexDirection: "column", gap: 18 }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
          <span style={{ fontFamily: "Inter, sans-serif", fontSize: 9.5, letterSpacing: "0.32em", textTransform: "uppercase", color: "#1F2937" }}>Menu</span>
          <button onClick={onClose} style={{ background: "none", border: "none", fontSize: 22, color: "#1F2937", cursor: "pointer" }} aria-label="閉じる">✕</button>
        </div>
        <span style={{ height: 1, background: sea, width: 32 }} />
        <nav style={{ display: "flex", flexDirection: "column", gap: 4, marginTop: 10 }}>
          {items.map((it, i) => (
            <a key={i} href="#" onClick={onClose} style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 18, color: "#1F2937", textDecoration: "none", padding: "14px 0", borderBottom: "1px solid rgba(31,41,55,0.08)", letterSpacing: "0.18em" }}>{it}</a>
          ))}
        </nav>
        <a href="tel:0955826062" style={{ marginTop: "auto", fontFamily: '"Noto Serif JP", serif', fontSize: 22, color: sea, textDecoration: "none", letterSpacing: "0.04em" }}>0955-82-6062</a>
        <span style={{ fontFamily: "Inter, sans-serif", fontSize: 10, letterSpacing: "0.3em", color: "#6b6b6b" }}>OPEN · WEEKDAYS 10–21</span>
      </aside>
    </div>
  );
}

// ---------- Trust Badge (Google ★4.84) ----------
function TrustBadge({ sea, gold }) {
  return (
    <div className="trust-badge" style={{ background: "#FBF8F2", border: `1px solid ${sea}`, padding: "22px 28px 20px", display: "flex", flexDirection: "column", gap: 10, boxShadow: "0 18px 48px -20px rgba(31,41,55,0.25)", position: "relative", minWidth: 280 }}>
      <span style={{ position: "absolute", top: -1, left: -1, width: 10, height: 10, borderTop: `1px solid ${sea}`, borderLeft: `1px solid ${sea}`, transform: "translate(-3px,-3px)" }} />
      <span style={{ position: "absolute", top: -1, right: -1, width: 10, height: 10, borderTop: `1px solid ${sea}`, borderRight: `1px solid ${sea}`, transform: "translate(3px,-3px)" }} />
      <span style={{ position: "absolute", bottom: -1, left: -1, width: 10, height: 10, borderBottom: `1px solid ${sea}`, borderLeft: `1px solid ${sea}`, transform: "translate(-3px,3px)" }} />
      <span style={{ position: "absolute", bottom: -1, right: -1, width: 10, height: 10, borderBottom: `1px solid ${sea}`, borderRight: `1px solid ${sea}`, transform: "translate(3px,3px)" }} />
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
        <span style={{ fontFamily: "Inter, sans-serif", fontSize: 10, letterSpacing: "0.34em", textTransform: "uppercase", color: "#7a7a7a", fontWeight: 500 }}>Google</span>
        <span style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 10, letterSpacing: "0.24em", color: gold }}>認定の声</span>
      </div>
      <div style={{ display: "flex", alignItems: "baseline", gap: 14 }}>
        <span style={{ display: "flex", gap: 2, color: sea, fontSize: 22, lineHeight: 1, letterSpacing: "0.05em" }}>★★★★★</span>
        <span style={{ fontFamily: '"Cormorant Garamond", "Noto Serif JP", serif', fontSize: 44, fontWeight: 500, color: "#1F2937", lineHeight: 1, letterSpacing: "0.01em" }}>4.84</span>
      </div>
      <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
        <span style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 13, color: "#1F2937", letterSpacing: "0.14em" }}>口コミ <span style={{ fontFamily: '"Cormorant Garamond", serif', fontSize: 17, margin: "0 2px" }}>119</span>件</span>
        <span style={{ width: 1, height: 12, background: "rgba(31,41,55,0.2)" }} />
        <span style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 13, color: sea, letterSpacing: "0.16em", fontWeight: 500 }}>呼子で1番</span>
      </div>
    </div>
  );
}

// ---------- Vertical-tate catchphrase ----------
function VerticalCatch({ sea, accentColor, columns }) {
  return (
    <div className="tate-catch" style={{ display: "flex", flexDirection: "row-reverse", gap: "0.55em", alignItems: "flex-start", fontFamily: '"Noto Serif JP", serif', writingMode: "vertical-rl", WebkitWritingMode: "vertical-rl" }}>
      {columns.map((col, i) => {
        const isAccent = !!col.accent;
        return (
          <div key={i} style={{ writingMode: "vertical-rl", WebkitWritingMode: "vertical-rl", fontSize: isAccent ? "clamp(30px, 2.8vw, 44px)" : "clamp(24px, 2.2vw, 36px)", fontWeight: isAccent ? 600 : 500, letterSpacing: "0.18em", lineHeight: 1.9, color: isAccent ? accentColor : "#1F2937", fontFeatureSettings: '"palt"', transition: "color 260ms ease", paddingTop: isAccent ? 6 : 14 }}>
            {col.text}
          </div>
        );
      })}
    </div>
  );
}

// ---------- Hero ----------
function Hero({ accentColor }) {
  const [scrolled, setScrolled] = useState(false);
  const [menuOpen, setMenuOpen] = useState(false);

  const sea = "#2C7DA0";
  const gold = "#B89968";
  const ink = "#1F2937";
  const ivory = "#FBF8F2";

  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 12);
    window.addEventListener("scroll", onScroll);
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  const columns = [
    { text: "呼子に根ざして" },
    { text: "十二年" },
    { text: "治療家620名が", accent: true },
    { text: "学ぶ手技を、地域へ" },
  ];

  return (
    <div style={{ background: ivory, color: ink, minHeight: "100vh", position: "relative", overflow: "hidden" }}>
      <Header onOpenMenu={() => setMenuOpen(true)} scrolled={scrolled} sea={sea} />
      <MobileDrawer open={menuOpen} onClose={() => setMenuOpen(false)} sea={sea} />

      <div className="year-mark" style={{ position: "absolute", top: 96, right: 36, fontFamily: '"Cormorant Garamond", serif', fontSize: 12, letterSpacing: "0.36em", color: "rgba(31,41,55,0.45)", zIndex: 5 }}>
        2014—2026
      </div>

      <main className="hero-grid" style={{ display: "grid", gridTemplateColumns: "minmax(0, 40fr) minmax(0, 60fr)", minHeight: "100vh", paddingTop: 72 }}>
        <section className="hero-left" style={{ padding: "80px 56px 64px 56px", display: "flex", flexDirection: "column", justifyContent: "space-between", position: "relative", zIndex: 4 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
            <span style={{ width: 28, height: 1, background: sea }} />
            <span style={{ fontFamily: "Inter, sans-serif", fontSize: 10.5, letterSpacing: "0.38em", textTransform: "uppercase", fontWeight: 400, color: "#1F2937" }}>
              Sasabe Seitai-in &nbsp;|&nbsp; Est. 2014 &nbsp;|&nbsp; Yobuko
            </span>
          </div>

          <div style={{ display: "flex", flexDirection: "column", gap: 32, marginTop: 36 }}>
            <VerticalCatch sea={sea} accentColor={accentColor} columns={columns} />

            <p style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 11.5, color: "rgba(31,41,55,0.6)", letterSpacing: "0.18em", lineHeight: 2, margin: 0, maxWidth: 480 }}>
              院長：笹部豪 ／ 一般社団法人疲労回復協会 認定インストラクター ／ 全国620名指導
            </p>

            <div style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 16, color: "#1F2937", lineHeight: 2, letterSpacing: "0.14em", fontWeight: 500 }}>
              <p style={{ margin: 0 }}>腰痛・肩こり・骨盤・産後・スポーツ。</p>
              <p style={{ margin: 0 }}>ボキボキしない、根本から整える整体。</p>
            </div>

            <div style={{ display: "flex", gap: 14, flexWrap: "wrap", marginTop: 4 }}>
              <a href="tel:0955826062" className="cta-primary" style={{ background: sea, color: ivory, padding: "18px 30px", fontFamily: '"Noto Serif JP", serif', fontSize: 15, letterSpacing: "0.18em", fontWeight: 500, textDecoration: "none", display: "inline-flex", alignItems: "center", gap: 12, transition: "transform 200ms ease, background 200ms ease" }}
                onMouseEnter={(e) => { e.currentTarget.style.background = "#235f7a"; e.currentTarget.style.transform = "translateY(-1px)"; }}
                onMouseLeave={(e) => { e.currentTarget.style.background = sea; e.currentTarget.style.transform = "translateY(0)"; }}>
                お電話で予約
                <span style={{ fontFamily: '"Cormorant Garamond", serif', fontSize: 18 }}>→</span>
              </a>
              <a href="#" className="cta-secondary" style={{ background: "transparent", color: ink, padding: "17px 30px", fontFamily: '"Noto Serif JP", serif', fontSize: 15, letterSpacing: "0.18em", fontWeight: 500, textDecoration: "none", display: "inline-flex", alignItems: "center", gap: 12, border: `1px solid ${ink}`, transition: "all 200ms ease" }}
                onMouseEnter={(e) => { e.currentTarget.style.background = ink; e.currentTarget.style.color = ivory; }}
                onMouseLeave={(e) => { e.currentTarget.style.background = "transparent"; e.currentTarget.style.color = ink; }}>
                症状別に見る
                <span style={{ fontFamily: '"Cormorant Garamond", serif', fontSize: 18 }}>→</span>
              </a>
            </div>
          </div>

          <div style={{ fontFamily: '"Noto Serif JP", serif', fontSize: 11.5, color: "rgba(31,41,55,0.55)", letterSpacing: "0.16em", lineHeight: 2, marginTop: 56, borderTop: "1px solid rgba(31,41,55,0.1)", paddingTop: 18 }}>
            営業 平日 10:00–21:00 ／ 土曜 9:00–20:00<br />
            佐賀県唐津市呼子町殿ノ浦 1595-3
          </div>
        </section>

        <section className="hero-right" style={{ position: "relative", overflow: "hidden", minHeight: 600 }}>
          {/* Real photo first, SVG fallback if image fails */}
          <img src="images/hero_main.jpg" alt="呼子港の朝" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block", position: "absolute", inset: 0 }} />

          <div className="trust-wrap" style={{ position: "absolute", left: -64, bottom: 56, zIndex: 6 }}>
            <TrustBadge sea={sea} gold={gold} />
          </div>
        </section>
      </main>

      <div style={{ height: 80, borderTop: "1px solid rgba(31,41,55,0.06)", display: "flex", alignItems: "center", justifyContent: "center", fontFamily: "Inter, sans-serif", fontSize: 10, letterSpacing: "0.4em", color: "rgba(31,41,55,0.35)", background: ivory }}>
        — 院について
      </div>
    </div>
  );
}

// ---------- App (production: Tweaks removed, fixed accent) ----------
function App() {
  return <Hero accentColor="#2C7DA0" />;
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
