// Shared atoms — logo, nav, footer, hero scene, placeholder imagery

// ════════════════════════ LOGO ════════════════════════
function LogoMark({ size = 38, stroke = "var(--kin)" }) {
  // Abstract 華 (flower) + 曜 (radiance) mark — concentric rings with a tsubaki petal
  return (
    <svg width={size} height={size} viewBox="0 0 60 60" fill="none" style={{ flex: "none" }}>
      <circle cx="30" cy="30" r="28.5" stroke={stroke} strokeWidth="0.8" />
      <circle cx="30" cy="30" r="22" stroke={stroke} strokeWidth="0.5" opacity="0.6" />
      {/* Stylized 華 inside */}
      <g stroke={stroke} strokeWidth="1" strokeLinecap="round" fill="none">
        <path d="M30 12 L30 48" />
        <path d="M18 22 Q30 18 42 22" />
        <path d="M16 32 L44 32" />
        <path d="M20 40 Q30 44 40 40" />
      </g>
      <circle cx="30" cy="30" r="1.6" fill={stroke} />
    </svg>
  );
}

// ════════════════════════ NAV ════════════════════════
function Nav({ current, onNav }) {
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 40);
    window.addEventListener("scroll", onScroll);
    onScroll();
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  const go = (p) => (e) => { e.preventDefault(); onNav(p); };
  const items = [
    ["home", "表紙", "HOME"],
    ["omakase", "お任せ", "OMAKASE"],
    ["shokunin", "店主", "CHEF"],
    ["sake", "日本酒", "SAKE"],
    ["interior", "店内", "INTERIOR"],
    ["access", "所在", "ACCESS"],
    ["journal", "便り", "JOURNAL"],
  ];
  return (
    <nav className={"nav" + (scrolled ? " scrolled" : "")}>
      <div className="nav-links">
        {items.map(([k, jp]) => (
          <a key={k} href="#" className={current === k ? "active" : ""} onClick={go(k)}>{jp}</a>
        ))}
      </div>
      <a className="nav-brand" href="#" onClick={go("home")}>
        <LogoMark size={36} />
        <div>
          <div className="wordmark">華曜</div>
          <div className="sub">KAYOU · GINZA</div>
        </div>
      </a>
      <div className="nav-cta">
        <div className="lang"><span className="on">JP</span><span>/</span><span>EN</span></div>
        <a href="#" className="book" onClick={go("reservation")}>御予約</a>
      </div>
    </nav>
  );
}

// ════════════════════════ FOOTER ════════════════════════
function Footer({ onNav }) {
  const go = (p) => (e) => { e.preventDefault(); onNav(p); };
  return (
    <footer className="footer">
      <div className="footer-grid">
        <div className="footer-brand">
          <LogoMark size={56} />
          <h3>鮨 華曜</h3>
          <p>
            銀座六丁目、ビルの地下に静かに佇む八席の鮨屋。江戸前の仕事を守りつつ、季節の一期一会を捧げる。
            Est. 昭和六十二年。
          </p>
        </div>
        <div>
          <h5>Discover</h5>
          <ul>
            <li onClick={go("omakase")}>お任せ</li>
            <li onClick={go("shokunin")}>店主</li>
            <li onClick={go("sake")}>日本酒</li>
            <li onClick={go("interior")}>店内</li>
          </ul>
        </div>
        <div>
          <h5>Visit</h5>
          <ul>
            <li onClick={go("reservation")}>御予約</li>
            <li onClick={go("access")}>所在</li>
            <li onClick={go("journal")}>便り</li>
          </ul>
        </div>
        <div>
          <h5>Contact</h5>
          <ul>
            <li>東京都中央区銀座六丁目</li>
            <li>03-0000-0000</li>
            <li>info@sushi-kayou.jp</li>
            <li style={{ marginTop: 16, color: "var(--kin)" }}>定休日 日曜・祝日</li>
          </ul>
        </div>
      </div>
      <div className="footer-bottom">
        <div>© 2026 Sushi Kayou · All rights reserved</div>
        <div>Ginza · Tokyo · 東京</div>
      </div>
    </footer>
  );
}

// ════════════════════════ HERO SCENE — Photorealistic ════════════════════════
function HeroScene() {
  return (
    <div className="hero-stage">
      {/* Deep background — warm key light from above-right */}
      <div className="layer" style={{
        background: "radial-gradient(ellipse 70% 60% at 60% 30%, #3A2820 0%, #1A1411 30%, #0A0706 65%, #020101 100%)",
      }} />

      {/* Hinoki counter wood — turbulence grain */}
      <svg className="layer" style={{ opacity: .9, mixBlendMode: "normal" }} preserveAspectRatio="xMidYMid slice" viewBox="0 0 1920 1080">
        <defs>
          <linearGradient id="hcg" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#0A0706" stopOpacity="0"/>
            <stop offset="70%" stopColor="#5A3818" stopOpacity=".5"/>
            <stop offset="85%" stopColor="#A07A48" stopOpacity=".7"/>
            <stop offset="100%" stopColor="#3A2410" stopOpacity=".9"/>
          </linearGradient>
          <filter id="h-wood">
            <feTurbulence type="fractalNoise" baseFrequency="0.005 0.55" numOctaves="3" seed="5" />
            <feColorMatrix values="0 0 0 0 .35  0 0 0 0 .22  0 0 0 0 .12  0 0 0 .85 0" />
          </filter>
        </defs>
        <rect y="600" width="1920" height="480" fill="url(#hcg)" />
        <rect y="700" width="1920" height="380" filter="url(#h-wood)" opacity=".7"/>
        {/* Wood grain lines */}
        <g stroke="#6A4828" strokeWidth="1" fill="none" opacity=".4">
          <path d="M 0 760 Q 480 754 960 758 Q 1440 762 1920 754"/>
          <path d="M 0 800 Q 480 794 960 798 Q 1440 802 1920 794"/>
          <path d="M 0 840 Q 480 834 960 838 Q 1440 842 1920 834"/>
          <path d="M 0 880 Q 480 874 960 878 Q 1440 882 1920 874"/>
          <path d="M 0 920 Q 480 914 960 918 Q 1440 922 1920 914"/>
        </g>
        {/* Counter front edge highlight */}
        <rect y="700" width="1920" height="4" fill="#E8C896" opacity=".5"/>
      </svg>

      {/* Hero subject — photorealistic nigiri close-up */}
      <svg className="layer" preserveAspectRatio="xMidYMid slice" viewBox="0 0 1920 1080">
        <defs>
          <radialGradient id="h-spot" cx="50%" cy="40%" r="55%">
            <stop offset="0%" stopColor="#FFE0B0" stopOpacity=".32"/>
            <stop offset="40%" stopColor="#C9A961" stopOpacity=".1"/>
            <stop offset="100%" stopColor="#000" stopOpacity="0"/>
          </radialGradient>

          {/* Sushi rice — warm, glistening */}
          <linearGradient id="h-rice" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#FCF5DE"/>
            <stop offset="35%" stopColor="#F2E2B8"/>
            <stop offset="70%" stopColor="#D8B888"/>
            <stop offset="100%" stopColor="#9C7644"/>
          </linearGradient>
          <linearGradient id="h-rice-shade" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#000" stopOpacity="0"/>
            <stop offset="100%" stopColor="#000" stopOpacity=".55"/>
          </linearGradient>

          {/* Otoro — deeply marbled */}
          <linearGradient id="h-toro" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#F2B8A4"/>
            <stop offset="25%" stopColor="#E68874"/>
            <stop offset="55%" stopColor="#C24A38"/>
            <stop offset="85%" stopColor="#7A2A20"/>
            <stop offset="100%" stopColor="#3A1410"/>
          </linearGradient>
          <linearGradient id="h-toro-side" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#8E3A2F"/><stop offset="100%" stopColor="#3A1410"/>
          </linearGradient>
          <radialGradient id="h-gloss" cx="30%" cy="20%" r="45%">
            <stop offset="0%" stopColor="#FFFFFF" stopOpacity=".7"/>
            <stop offset="100%" stopColor="#FFFFFF" stopOpacity="0"/>
          </radialGradient>
          <radialGradient id="h-rice-gloss" cx="40%" cy="30%" r="55%">
            <stop offset="0%" stopColor="#FFFFFF" stopOpacity=".4"/>
            <stop offset="100%" stopColor="#FFFFFF" stopOpacity="0"/>
          </radialGradient>

          <filter id="h-soft"><feGaussianBlur stdDeviation="2"/></filter>
          <filter id="h-blurBg"><feGaussianBlur stdDeviation="14"/></filter>
          <filter id="h-blurMid"><feGaussianBlur stdDeviation="6"/></filter>
        </defs>

        <ellipse cx="960" cy="620" rx="1000" ry="380" fill="url(#h-spot)"/>

        {/* Out-of-focus back row — heavy bokeh */}
        <g filter="url(#h-blurBg)" opacity=".7">
          <ellipse cx="300" cy="460" rx="140" ry="50" fill="#C99063"/>
          <ellipse cx="240" cy="430" rx="120" ry="36" fill="#5A2A20"/>
          <ellipse cx="1620" cy="470" rx="120" ry="42" fill="#A4624A"/>
          <ellipse cx="1740" cy="500" rx="100" ry="34" fill="#E0B17A"/>
          <ellipse cx="1560" cy="440" rx="100" ry="32" fill="#3A1A12"/>
        </g>
        {/* Mid bokeh */}
        <g filter="url(#h-blurMid)" opacity=".75">
          <ellipse cx="380" cy="540" rx="80" ry="22" fill="#7A4830"/>
          <ellipse cx="1500" cy="530" rx="90" ry="24" fill="#9A5A40"/>
        </g>

        {/* Bokeh dots — golden light */}
        <g opacity=".7">
          <circle cx="180" cy="820" r="22" fill="#FFE0B0" filter="url(#h-blurMid)"/>
          <circle cx="280" cy="880" r="14" fill="#C9A961" filter="url(#h-blurMid)"/>
          <circle cx="1700" cy="860" r="26" fill="#FFE0B0" filter="url(#h-blurMid)" opacity=".7"/>
          <circle cx="1820" cy="820" r="14" fill="#E8C870" filter="url(#h-blurMid)"/>
          <circle cx="120" cy="380" r="10" fill="#C9A961" filter="url(#h-blurMid)" opacity=".5"/>
          <circle cx="1830" cy="320" r="12" fill="#FFE0B0" filter="url(#h-blurMid)" opacity=".5"/>
        </g>

        {/* Hero nigiri — slightly tilted, with proper subsurface depth */}
        <g transform="translate(960 640) rotate(-5)">
          {/* Cast shadow */}
          <ellipse cx="20" cy="105" rx="320" ry="22" fill="#000" opacity=".75" filter="url(#h-soft)"/>
          <ellipse cx="0" cy="98" rx="270" ry="14" fill="#000" opacity=".7" filter="url(#h-soft)"/>

          {/* Rice base — front face */}
          <path d="M -260 30 Q -260 -10 -230 -38 Q -200 -52 -160 -56 L 160 -56 Q 200 -52 230 -38 Q 260 -10 260 30 Q 260 70 230 80 Q 200 88 160 90 L -160 90 Q -200 88 -230 80 Q -260 70 -260 30 Z" fill="url(#h-rice)"/>

          {/* Rice grain micro-texture — many tiny ovals */}
          <g>
            {Array.from({length: 110}).map((_, i) => {
              const r = i / 110;
              const angle = (i * 137.5) * Math.PI / 180;
              const dist = 30 + (i % 9) * 22;
              const x = Math.cos(angle) * dist;
              const y = -10 + Math.sin(angle) * (dist * 0.35);
              const rx = 3 + (i % 3);
              return <ellipse key={i} cx={x} cy={y} rx={rx} ry="1.6" fill="#A07A4A" opacity={.25 + (i%4)*.1} transform={`rotate(${(i*23)%180} ${x} ${y})`}/>;
            })}
          </g>
          <g>
            {Array.from({length: 90}).map((_, i) => {
              const angle = (i * 137.5 + 47) * Math.PI / 180;
              const dist = 40 + (i % 7) * 26;
              const x = Math.cos(angle) * dist;
              const y = -5 + Math.sin(angle) * (dist * 0.32);
              return <ellipse key={i} cx={x} cy={y} rx="2.5" ry="1.2" fill="#FFFFFF" opacity={.5 + (i%3)*.15} transform={`rotate(${(i*31)%180} ${x} ${y})`}/>;
            })}
          </g>
          {/* Rice gloss */}
          <ellipse cx="-30" cy="-10" rx="180" ry="35" fill="url(#h-rice-gloss)"/>
          {/* Underside shadow */}
          <path d="M -260 30 Q -260 70 -230 80 Q -200 88 -160 90 L 160 90 Q 200 88 230 80 Q 260 70 260 30 L 260 90 L -260 90 Z" fill="url(#h-rice-shade)" opacity=".55"/>

          {/* Toro slice side (depth) */}
          <path d="M -268 -30 L -268 -10 Q -268 0 -240 2 L 240 2 Q 268 0 268 -10 L 268 -30 Z" fill="url(#h-toro-side)"/>

          {/* Toro slice — top */}
          <path d="M -268 -70 Q -268 -100 -222 -106 L 222 -106 Q 268 -100 268 -70 L 268 -30 Q 268 -16 240 -14 L -240 -14 Q -268 -16 -268 -30 Z" fill="url(#h-toro)"/>

          {/* Marbling — many soft white striations */}
          <g stroke="#FFFFFF" fill="none" strokeLinecap="round">
            <path d="M -250 -88 Q -180 -100 -100 -92 Q -20 -84 80 -94 Q 160 -102 240 -90" strokeWidth="3.5" opacity=".55"/>
            <path d="M -240 -72 Q -160 -82 -60 -74 Q 40 -66 140 -76 Q 200 -82 245 -70" strokeWidth="2.8" opacity=".5"/>
            <path d="M -250 -56 Q -160 -64 -40 -56 Q 60 -48 160 -58 Q 220 -64 250 -52" strokeWidth="2.2" opacity=".45"/>
            <path d="M -230 -42 Q -120 -50 0 -42 Q 120 -34 220 -42 Q 240 -44 248 -40" strokeWidth="1.7" opacity=".4"/>
            <path d="M -220 -28 Q -100 -36 40 -28 Q 160 -20 240 -26" strokeWidth="1.3" opacity=".35"/>
            {/* Short marbling flecks */}
            <path d="M -190 -78 Q -170 -82 -150 -78" strokeWidth="2" opacity=".55"/>
            <path d="M -100 -86 Q -80 -90 -60 -86" strokeWidth="1.8" opacity=".5"/>
            <path d="M 30 -82 Q 50 -86 70 -82" strokeWidth="1.8" opacity=".5"/>
            <path d="M 140 -76 Q 160 -80 180 -76" strokeWidth="1.6" opacity=".45"/>
          </g>

          {/* Top gloss */}
          <ellipse cx="-50" cy="-78" rx="200" ry="14" fill="url(#h-gloss)"/>
          <ellipse cx="-100" cy="-72" rx="100" ry="5" fill="#FFFFFF" opacity=".35"/>

          {/* Nikiri (soy brush) — wet streak */}
          <ellipse cx="80" cy="-38" rx="48" ry="5" fill="#1A0A06" opacity=".5"/>
          <ellipse cx="80" cy="-40" rx="20" ry="2" fill="#FFFFFF" opacity=".4"/>

          {/* Tiny salt crystals */}
          <g fill="#F5F0E6">
            <rect x="-60" y="-92" width="2" height="2"/>
            <rect x="-25" y="-86" width="1.6" height="1.6"/>
            <rect x="30" y="-94" width="2" height="2"/>
            <rect x="105" y="-88" width="1.5" height="1.5"/>
          </g>

          {/* Wasabi tucked under */}
          <ellipse cx="0" cy="-10" rx="20" ry="4" fill="#5A7A38" opacity=".7"/>
        </g>

        {/* Foreground bokeh — extreme depth */}
        <g opacity=".6">
          <circle cx="240" cy="980" r="42" fill="#C9A961" filter="url(#h-blurMid)"/>
          <circle cx="380" cy="1020" r="26" fill="#E4CC8A" filter="url(#h-blurMid)"/>
          <circle cx="1680" cy="1000" r="48" fill="#C9A961" filter="url(#h-blurMid)" opacity=".7"/>
          <circle cx="1820" cy="960" r="30" fill="#FFDDB0" filter="url(#h-blurMid)"/>
        </g>
      </svg>

      {/* Drifting highlight */}
      <div className="layer" style={{
        background: "radial-gradient(ellipse 40% 60% at 30% 30%, rgba(255,220,170,0.08) 0%, transparent 60%)",
        animation: "kenburns 18s ease-in-out infinite alternate-reverse",
        mixBlendMode: "screen",
      }} />
    </div>
  );
}

// ════════════════════════ PLACEHOLDER IMAGERY ════════════════════════
// Drag-and-drop slots for real photographs.

function Ph({ kind, slotId, placeholder, style }) {
  const map = {
    counter: "檜のカウンター",
    chef: "店主の姿",
    sake: "酒瓶と盃",
    tatami: "離れ・障子",
    fish: "本鮪のフィレ",
    washi: "和紙・書",
    plate: "黒楽の皿と握り",
    moon: "卯月の床の間",
  };
  const id = slotId || `kayou-${kind}`;
  const ph = placeholder || `${map[kind] || kind} の写真をドロップ`;
  return (
    <image-slot
      id={id}
      shape="rect"
      placeholder={ph}
      style={{ width: "100%", height: "100%", display: "block", ...style }}
    ></image-slot>
  );
}

Object.assign(window, { LogoMark, Nav, Footer, HeroScene, Ph });
