// 天水島ヒルズ components
const { useState, useEffect, useRef, useMemo } = React;

const PHOTOS = {
  exterior: 'https://amamizushima.com/images/photos/landscape/building_exterior.jpg',
  spring: 'https://amamizushima.com/images/photos/landscape/tanada_00.jpg',
  summer: 'https://amamizushima.com/images/photos/landscape/tanada_02.jpg',
  autumn: 'https://amamizushima.com/images/photos/landscape/autumn_rice.jpg',
  winter: 'https://amamizushima.com/images/photos/landscape/snow_00.jpg',
  amami:  'https://amamizushima.com/images/photos/landscape/amami_00.jpg',
};

// ============== NAV ==============
function Nav({ t, lang, setLang, tweaksOpen, setTweaksOpen, editMode }) {
  const [scrolled, setScrolled] = useState(false);
  useEffect(() => {
    const onS = () => setScrolled(window.scrollY > 40);
    window.addEventListener('scroll', onS, { passive: true });
    return () => window.removeEventListener('scroll', onS);
  }, []);
  return (
    <nav className={`nav ${scrolled ? 'scrolled' : ''}`}>
      <div className="nav-inner">
        <a href="#top" className="brand">
          <span className="mark">天</span>
          <span>天水島ヒルズ <small>Amamizushima</small></span>
        </a>
        <div className="nav-links">
          <a href="#house">{t.nav.house}</a>
          <a href="#floorplan">{t.nav.floorplan}</a>
          <a href="#rooms">{t.nav.rooms}</a>
          <a href="#day">{t.nav.day}</a>
          <a href="#pricing">{t.nav.pricing}</a>
          <a href="#seasons">{t.nav.seasons}</a>
          <a href="#access">{t.nav.access}</a>
        </div>
        <div className="nav-right">
          <div className="lang" role="tablist">
            {['ja','en','zh'].map(l => (
              <button key={l} className={lang === l ? 'on' : ''} onClick={() => setLang(l)}>
                {l.toUpperCase()}
              </button>
            ))}
          </div>
          <a href="#book" className="btn">{t.nav.book} <span className="arr">→</span></a>
        </div>
      </div>
    </nav>
  );
}

// ============== HERO ==============
function Hero({ t, heroMode }) {
  const seasons = ['spring','summer','autumn','winter'];
  const [idx, setIdx] = useState(0);
  useEffect(() => {
    if (heroMode === 'static') return;
    const v = setInterval(() => setIdx(i => (i + 1) % 4), 4500);
    return () => clearInterval(v);
  }, [heroMode]);

  const seasonLabels = { ja: ['春','夏','秋','冬'], en: ['SPRING','SUMMER','AUTUMN','WINTER'], zh: ['春','夏','秋','冬'] };
  const lbls = seasonLabels[t.__lang] || seasonLabels.ja;

  return (
    <header className="hero" id="top">
      <div className="hero-stage">
        {seasons.map((s, i) => (
          <div
            key={s}
            className={`hero-layer ${i === idx ? 'on' : ''}`}
            style={{ backgroundImage: `url(${PHOTOS[s]})`, transform: i === idx ? 'scale(1.08)' : 'scale(1.02)', transitionProperty: 'opacity, transform', transitionDuration: i === idx ? '6s, 9s' : '2.2s, 2.2s' }}
          />
        ))}
        <div className="hero-grid" />
      </div>

      <div className="hero-top">
        <div className="hero-kicker"><span className="dot" /> {t.hero.kicker}</div>
        <div className="hero-open">{t.hero.open}</div>
      </div>

      <div className="hero-main">
        <div>
          <h1 className="hero-title">
            <span className="r1">{t.hero.title1}</span>
            <span className="r2">{t.hero.title2}</span>
          </h1>
          <p className="hero-sub">{t.hero.sub}</p>
          <div className="hero-ctas">
            <a href="#book" className="btn">{t.hero.cta1} <span className="arr">→</span></a>
            <a href="#house" className="btn ghost">{t.hero.cta2}</a>
          </div>
        </div>
        <div className="hero-side">
          <div className="line">
            <div className="lbl">{t.stats.capacity}</div>
            <div className="val">11 <span style={{ fontSize: 13, opacity: .7, letterSpacing: '.1em' }}>{t.stats.people}</span></div>
          </div>
          <div className="line">
            <div className="lbl">{t.stats.onsen}</div>
            <div className="val">3<span style={{ fontSize: 13, opacity: .7, letterSpacing: '.1em' }}> {t.stats.min}</span></div>
          </div>
          <div className="line">
            <div className="lbl">{t.stats.rate}</div>
            <div className="val">¥40,000</div>
          </div>
        </div>
      </div>

      <div className="season-bar">
        {seasons.map((s, i) => (
          <div key={s} className={`sb ${i === idx ? 'on' : ''}`} onClick={() => setIdx(i)}>
            <span>{lbls[i]}</span>
          </div>
        ))}
      </div>

      <div className="hero-scroll">
        <div>{t.hero.scroll}</div>
        <div className="bar" />
      </div>
    </header>
  );
}

// ============== TICKER ==============
function Ticker({ t }) {
  const items = [
    '新潟 · 十日町市 · 松之山', 'AMAMIZUSHIMA HILLS', '定員 11名', '2026.04.25 開業',
    '日本三大薬湯「松之山温泉」徒歩15分', 'ONE PARTY PER DAY', '第M150062846号', '豪雪と棚田の山里',
  ];
  const row = items.join('  ·  ');
  return (
    <div className="ticker">
      <div className="ticker-track">
        <span>{row}</span>
        <span>{row}</span>
      </div>
    </div>
  );
}

// ============== HOUSE ==============
function House({ t }) {
  return (
    <section id="house">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.house.tag}</div>
          <div>
            <h2>{t.house.h}</h2>
          </div>
        </div>

        <div className="house-body">
          <div className="prose">
            <p>{t.house.body}</p>
            <p>{t.house.body2}</p>
            <dl className="house-specs" style={{ marginTop: 36 }}>
              {Object.keys(t.house.spec).filter(k => !k.endsWith('V')).map(k => (
                <div className="row" key={k}>
                  <dt>{t.house.spec[k]}</dt>
                  <dd>{t.house.spec[k + 'V']}</dd>
                </div>
              ))}
            </dl>
          </div>
          <div className="house-photo">
            <img src={PHOTOS.exterior} alt="" loading="lazy" />
          </div>
        </div>

        <div className="stat-row">
          <div className="st">
            <div className="lbl">{t.stats.area}</div>
            <div className="val">286<sub>{t.stats.m2}</sub></div>
          </div>
          <div className="st">
            <div className="lbl">{t.stats.capacity}</div>
            <div className="val">11<sub>{t.stats.people}</sub></div>
          </div>
          <div className="st">
            <div className="lbl">{t.stats.onsen}</div>
            <div className="val">3<sub>{t.stats.min}</sub></div>
          </div>
          <div className="st">
            <div className="lbl">{t.stats.ski}</div>
            <div className="val">3<sub>{t.stats.min}</sub></div>
          </div>
          <div className="st">
            <div className="lbl">{t.stats.rate}</div>
            <div className="val">¥40k</div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============== FLOORPLAN (SVG) ==============
function Floorplan({ t }) {
  const [hover, setHover] = useState(null);
  const rooms = [
    { id: 'r1', num: '1', key: 'r1', x: 40, y: 40, w: 180, h: 160 },     // NW 6帖
    { id: 'r2', num: '2', key: 'r2', x: 240, y: 40, w: 240, h: 160 },    // 8帖 with alcove
    { id: 'l',  num: 'L', key: 'l',  x: 40, y: 220, w: 440, h: 180 },    // living
    { id: 'r3', num: '3', key: 'r3', x: 500, y: 220, w: 260, h: 180 },   // 8帖 near entrance
    { id: 'hall', num: '', key: null, x: 500, y: 40, w: 260, h: 160, label: 'ホール / 玄関' },
    { id: 'bath', num: '', key: null, x: 40, y: 420, w: 220, h: 140, label: '台所・浴室・洗面' },
    { id: 'stair', num: '', key: null, x: 280, y: 420, w: 480, h: 140, label: '廊下・階段' },
  ];
  const labelMap = { r1: t.floorplan.legend.r1, r2: t.floorplan.legend.r2, r3: t.floorplan.legend.r3, l: t.floorplan.legend.l };

  return (
    <section id="floorplan">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.floorplan.tag}</div>
          <div>
            <h2>{t.floorplan.h}</h2>
            <p className="lead">{t.floorplan.body}</p>
          </div>
        </div>

        <div className="fp-wrap">
          <div className="fp-svg-wrap">
            <svg className="fp-svg" viewBox="0 0 800 600" xmlns="http://www.w3.org/2000/svg">
              {/* grid */}
              <defs>
                <pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse">
                  <path d="M 40 0 L 0 0 0 40" fill="none" stroke="#e2dcc8" strokeWidth="0.5" />
                </pattern>
                <pattern id="tatami" width="20" height="40" patternUnits="userSpaceOnUse">
                  <rect width="20" height="40" fill="transparent"/>
                  <path d="M0 0 L0 40 M20 0 L20 40" stroke="#d6ceb5" strokeWidth="0.5"/>
                </pattern>
              </defs>
              <rect x="0" y="0" width="800" height="600" fill="url(#grid)" />

              {/* outer building outline */}
              <rect x="30" y="30" width="740" height="540" fill="none" stroke="#3a372f" strokeWidth="2" />

              {/* rooms */}
              {rooms.map(r => {
                const isRoom = !!r.key;
                const active = hover === r.key;
                return (
                  <g key={r.id} onMouseEnter={() => isRoom && setHover(r.key)} onMouseLeave={() => setHover(null)} style={{ cursor: isRoom ? 'pointer' : 'default' }}>
                    <rect x={r.x} y={r.y} width={r.w} height={r.h}
                      fill={active ? '#f7d9c5' : (isRoom ? '#efe7cf' : '#e8e1ca')}
                      stroke="#3a372f" strokeWidth={active ? 2 : 1}
                    />
                    {isRoom && r.key !== 'l' && <rect x={r.x + 8} y={r.y + 8} width={r.w - 16} height={r.h - 16} fill="url(#tatami)" opacity="0.6" />}
                    {r.num && (
                      <g>
                        <circle cx={r.x + 24} cy={r.y + 24} r="14" fill={active ? '#8a3b1c' : '#1c1b17'} />
                        <text x={r.x + 24} y={r.y + 28} fontSize="14" fill="#f3efe6" textAnchor="middle" fontFamily="'Noto Serif JP', serif">{r.num}</text>
                      </g>
                    )}
                    <text x={r.x + r.w / 2} y={r.y + r.h / 2 + 6} fontSize="12" textAnchor="middle" fill="#3a372f" fontWeight="500">
                      {r.key ? labelMap[r.key] : r.label}
                    </text>
                  </g>
                );
              })}

              {/* alcove in r2 */}
              <rect x="420" y="48" width="50" height="24" fill="#d9cfb1" stroke="#3a372f" strokeWidth="0.8" />
              <text x="445" y="64" fontSize="8" textAnchor="middle" fill="#6b6656">床の間</text>

              {/* compass */}
              <g transform="translate(740 60)">
                <circle r="18" fill="none" stroke="#6b6656" strokeWidth="0.8" />
                <path d="M 0 -18 L 3 0 L -3 0 Z" fill="#8a3b1c" />
                <path d="M 0 18 L 3 0 L -3 0 Z" fill="#3a372f" />
                <text y="-24" fontSize="10" textAnchor="middle" fill="#6b6656" fontFamily="'JetBrains Mono', monospace">N</text>
              </g>

              {/* scale */}
              <g transform="translate(50 560)">
                <line x1="0" y1="0" x2="80" y2="0" stroke="#3a372f" strokeWidth="1" />
                <line x1="0" y1="-4" x2="0" y2="4" stroke="#3a372f" />
                <line x1="40" y1="-4" x2="40" y2="4" stroke="#3a372f" />
                <line x1="80" y1="-4" x2="80" y2="4" stroke="#3a372f" />
                <text x="0" y="16" fontSize="9" fill="#6b6656" fontFamily="'JetBrains Mono', monospace">0</text>
                <text x="40" y="16" fontSize="9" textAnchor="middle" fill="#6b6656" fontFamily="'JetBrains Mono', monospace">910</text>
                <text x="80" y="16" fontSize="9" textAnchor="middle" fill="#6b6656" fontFamily="'JetBrains Mono', monospace">1820mm</text>
              </g>
            </svg>
            <div className="fp-label">
              <span>2F · 119.24 {t.stats.m2}</span>
              <span>{t.floorplan.tag}</span>
            </div>
          </div>

          <div>
            <div className="fp-legend">
              {['r1','r2','r3','l'].map(k => (
                <div key={k} className={`item ${hover === k ? 'active' : ''}`}
                     onMouseEnter={() => setHover(k)} onMouseLeave={() => setHover(null)}>
                  <div className="num">{k === 'l' ? 'L' : k[1]}</div>
                  <div>
                    <div className="name">{t.floorplan.legend[k]}</div>
                    <div className="meta">{t.floorplan.legend[k + 's']}</div>
                  </div>
                  <div className="area">→</div>
                </div>
              ))}
            </div>
            <a href="https://amamizushima.com/docs/amamizushima_2f_plan.pdf" target="_blank" rel="noopener" className="fp-link">
              {t.floorplan.pdf} ↗
            </a>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============== ROOMS ==============
function Rooms({ t }) {
  const cap = [
    { room: 1, n: 2 }, { room: 2, n: 3 }, { room: 3, n: 3 }, { room: 4, n: 3 }
  ];
  return (
    <section id="rooms">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.rooms.tag}</div>
          <div>
            <h2>{t.rooms.h}</h2>
          </div>
        </div>

        <div className="rooms-grid">
          {t.rooms.items.map((r, i) => (
            <div className="room" key={i}>
              <div className="no">{r.no}</div>
              <div className="sz">{r.size}</div>
              <div className="name">{r.name}</div>
              <div className="area">{r.area}</div>
              <div className="body">{r.body}</div>
              <div className="cap">· {r.cap}</div>
            </div>
          ))}
        </div>

        <div className="cap-viz">
          <div className="lbl">{t.stats.capacity}<br/>Total</div>
          <div className="people">
            {Array.from({ length: 11 }).map((_, i) => (
              <div className="p" key={i} />
            ))}
          </div>
          <div className="total">11<small>{t.stats.people} · MAX</small></div>
        </div>
      </div>
    </section>
  );
}

// ============== DAY TIMELINE ==============
function DayTimeline({ t }) {
  return (
    <section id="day">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.day.tag}</div>
          <div>
            <h2>{t.day.h}</h2>
          </div>
        </div>
        <div className="day-rail">
          {t.day.items.map((it, i) => (
            <div className="day-item" key={i}>
              <div className="t">{it.t}</div>
              <div className="title">{it.title}</div>
              <div className="body">{it.body}</div>
              <div className="n">{String(i + 1).padStart(2, '0')} / {String(t.day.items.length).padStart(2, '0')}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ============== PRICING ==============
function Pricing({ t }) {
  return (
    <section id="pricing">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.pricing.tag}</div>
          <div>
            <h2>{t.pricing.h}</h2>
            <p className="lead">{t.pricing.body}</p>
          </div>
        </div>

        <div className="price-wrap">
          <div className="price-card">
            <div className="lbl">{t.pricing.single}</div>
            <div className="amt"><span className="cur">¥</span>40,000</div>
            <div className="per">{t.pricing.per}</div>
            <div className="note">
              {t.pricing.body}
            </div>
          </div>
          <div className="price-opts">
            <dl>
              {Object.keys(t.pricing.opts).filter(k => !k.endsWith('V')).map(k => (
                <div className="row" key={k}>
                  <dt>{t.pricing.opts[k]}</dt>
                  <dd>{t.pricing.opts[k + 'V']}</dd>
                </div>
              ))}
            </dl>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============== EVENTS ==============
function Events({ t }) {
  return (
    <section id="events">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.events.tag}</div>
          <div>
            <h2>{t.events.h}</h2>
            <p className="lead">{t.events.body}</p>
          </div>
        </div>

        <div className="events-grid">
          <div>
            <ul className="events-uses">
              {t.events.uses.map((u, i) => (<li key={i}>{u}</li>))}
            </ul>
            <a href="#book" className="btn">{t.events.cta} <span className="arr">→</span></a>
          </div>
          <div className="events-viz">
            <div className="lbl">MAX CAPACITY (DAY-USE)</div>
            <div className="big">25<small>{t.stats.people} · ¥40,000〜</small></div>
            <div className="dots">
              {Array.from({ length: 25 }).map((_, i) => (
                <div className="p" key={i} />
              ))}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============== SEASONS ==============
function Seasons({ t }) {
  const pics = [PHOTOS.spring, PHOTOS.summer, PHOTOS.autumn, PHOTOS.winter];
  return (
    <section id="seasons">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.seasons.tag}</div>
          <div>
            <h2>{t.seasons.h}</h2>
            <p className="lead">{t.seasons.body}</p>
          </div>
        </div>
        <div className="seasons-grid">
          {t.seasons.items.map((s, i) => (
            <div className="season" key={i}>
              <img src={pics[i]} alt="" loading="lazy" />
              <div className="lbl">
                <div className="n">{s.n}</div>
                <div className="m">{s.m}</div>
                <div className="body">{s.body}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ============== AROUND ==============
function Around({ t }) {
  return (
    <section id="around">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.around.tag}</div>
          <div>
            <h2>{t.around.h}</h2>
          </div>
        </div>
        <div className="around-grid">
          {t.around.items.map((n, i) => (
            <a key={i} className="near" href={n.link} target="_blank" rel="noopener">
              <div className="t">{n.t}</div>
              <div className="n">{n.n}</div>
              <div className="body">{n.body}</div>
              <div className="arr">→ OPEN</div>
            </a>
          ))}
        </div>
      </div>
    </section>
  );
}

// ============== ACCESS ==============
function Access({ t }) {
  return (
    <section id="access">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.access.tag}</div>
          <div>
            <h2 style={{ fontSize: 'clamp(22px, 2.4vw, 34px)', fontWeight: 600 }}>{t.access.h}</h2>
          </div>
        </div>

        <div className="access-wrap">
          <div>
            <h3>ROUTES</h3>
            <dl className="rows">
              <div className="row">
                <dt>{t.access.train}</dt>
                <dd>{t.access.trainV}</dd>
              </div>
              <div className="row">
                <dt>{t.access.car}</dt>
                <dd>{t.access.carV}</dd>
              </div>
              <div className="row">
                <dt>{t.access.tokyo}</dt>
                <dd>{t.access.tokyoV}</dd>
              </div>
            </dl>
            <a href="https://www.google.com/maps/search/?api=1&query=%E6%96%B0%E6%BD%9F%E7%9C%8C%E5%8D%81%E6%97%A5%E7%94%BA%E5%B8%82%E6%9D%BE%E4%B9%8B%E5%B1%B1%E5%A4%A9%E6%B0%B4%E5%B3%B6575-4"
               target="_blank" rel="noopener" className="btn ghost" style={{ marginTop: 24 }}>
              {t.access.map} ↗
            </a>
          </div>
          <div className="map-card">
            <div className="coords">37.1° N · 138.6° E</div>
            <div className="addr">{t.access.h}</div>
            <div className="star" />
            <div className="coords" style={{ textAlign: 'right' }}>NIIGATA · MATSUNOYAMA</div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============== BOOK ==============
function Book({ t }) {
  return (
    <section id="book">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.book.tag}</div>
          <div>
            <h2>{t.book.h}</h2>
            <p className="lead">{t.book.body}</p>
          </div>
        </div>

        <div className="book-grid">
          <a className="book-card primary" href="mailto:info@amamizushima.com">
            <div className="lbl">DIRECT</div>
            <div className="big">info@amamizushima.com</div>
            <div className="arr">{t.book.email} →</div>
          </a>
          <div className="book-card disabled">
            <div className="lbl">AIRBNB</div>
            <div className="big">Airbnb</div>
            <div className="small">{t.book.soon}</div>
          </div>
          <div className="book-card disabled">
            <div className="lbl">BOOKING.COM</div>
            <div className="big">Booking.com</div>
            <div className="small">{t.book.soon}</div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============== INFO ==============
function Info({ t }) {
  return (
    <section id="info">
      <div className="page">
        <div className="sec-head">
          <div className="tag">{t.info.tag}</div>
          <div>
            <h2 style={{ fontSize: 'clamp(18px, 1.8vw, 22px)', fontWeight: 600 }}>{t.info.h}</h2>
          </div>
        </div>
        <div className="info-grid">
          <div className="info-box">
            <h4>{t.info.s1}</h4>
            <dl>
              <div className="row"><dt>商号</dt><dd>TOMOTOMO合同会社</dd></div>
              <div className="row"><dt>代表</dt><dd>代表社員 簗田友子</dd></div>
              <div className="row"><dt>所在地</dt><dd>〒104-0054 東京都中央区勝どき6-3-2-4808</dd></div>
              <div className="row"><dt>届出</dt><dd>第M150062846号／令和8年4月8日（新潟県知事）</dd></div>
            </dl>
          </div>
          <div className="info-box">
            <h4>{t.info.s2}</h4>
            <dl>
              <div className="row"><dt>商号</dt><dd>珈琲ハウス株式会社</dd></div>
              <div className="row"><dt>代表</dt><dd>代表取締役 森野航平</dd></div>
              <div className="row"><dt>所在地</dt><dd>〒130-0002 東京都墨田区業平4-8-3 吉田マンション804</dd></div>
              <div className="row"><dt>登録番号</dt><dd>国土交通大臣(01)第F02745号</dd></div>
              <div className="row"><dt>苦情窓口</dt><dd>090-3231-8088</dd></div>
            </dl>
          </div>
          <div className="info-box">
            <h4>{t.info.s3}</h4>
            <p style={{ fontSize: 13, color: 'var(--ink-2)', margin: '0 0 12px', lineHeight: 1.7 }}>{t.info.s3V}</p>
            <ul>
              {t.info.fire.map((f, i) => <li key={i}>{f}</li>)}
            </ul>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============== FOOTER ==============
function Footer({ t }) {
  return (
    <footer className="foot">
      <div className="foot-inner">
        <div>
          <div className="brand">
            <span className="mark">天</span>
            <span>天水島ヒルズ <small style={{ color: 'rgba(243,239,230,.6)' }}>Amamizushima</small></span>
          </div>
          <div className="foot-addr">{t.foot.addr}</div>
          <div className="foot-license">{t.foot.license}</div>
        </div>
        <div>
          <h5>{t.nav.book}</h5>
          <ul>
            <li><a href="#book">{t.book.email}</a></li>
            <li><a href="#floorplan">{t.nav.floorplan}</a></li>
            <li><a href="#rooms">{t.nav.rooms}</a></li>
            <li><a href="#access">{t.nav.access}</a></li>
          </ul>
        </div>
        <div>
          <h5>CONTACT</h5>
          <ul>
            <li><a href="mailto:info@amamizushima.com">info@amamizushima.com</a></li>
            <li>TOMOTOMO合同会社</li>
            <li>代表社員 簗田友子</li>
          </ul>
        </div>
      </div>
      <div className="foot-bottom">
        <div>© 2026 TOMOTOMO合同会社</div>
        <div>AMAMIZUSHIMA · MATSUNOYAMA · NIIGATA</div>
      </div>
    </footer>
  );
}

// ============== STICKY CTA ==============
function StickyCta({ t }) {
  const [on, setOn] = useState(false);
  useEffect(() => {
    const onS = () => setOn(window.scrollY > window.innerHeight * 0.8);
    window.addEventListener('scroll', onS, { passive: true });
    return () => window.removeEventListener('scroll', onS);
  }, []);
  return (
    <div className={`sticky-cta ${on ? 'on' : ''}`}>
      <span className="dot" />
      <span>1{t.stats.people === 'pax' ? ' party / day' : (t.stats.people === '人' ? '日1組 · 空室確認' : '日1組 · 受付中')} · ¥40,000/{t.pricing.per.replace(/[/／ ]/g, '')}</span>
      <a href="#book" className="bk">{t.nav.book} →</a>
    </div>
  );
}

// ============== TWEAKS PANEL ==============
function TweaksPanel({ editMode, theme, setTheme, font, setFont, heroMode, setHeroMode, dispatchEdit }) {
  if (!editMode) return null;
  const T = (obj, v, set, k) => {
    set(v);
    dispatchEdit({ [k]: v });
  };
  return (
    <div className={`tw-panel on`}>
      <h6>Tweaks</h6>
      <div className="tw-group">
        <div className="glbl">Season theme</div>
        <div className="tw-chips">
          {['default','spring','summer','autumn','winter'].map(s => (
            <button key={s} className={theme === s ? 'on' : ''} onClick={() => T(null, s, setTheme, 'theme')}>{s}</button>
          ))}
        </div>
      </div>
      <div className="tw-group">
        <div className="glbl">Typeface</div>
        <div className="tw-chips">
          {['sans','serif'].map(f => (
            <button key={f} className={font === f ? 'on' : ''} onClick={() => T(null, f, setFont, 'font')}>{f}</button>
          ))}
        </div>
      </div>
      <div className="tw-group">
        <div className="glbl">Hero</div>
        <div className="tw-chips">
          {['auto','static'].map(h => (
            <button key={h} className={heroMode === h ? 'on' : ''} onClick={() => T(null, h, setHeroMode, 'heroMode')}>{h}</button>
          ))}
        </div>
      </div>
    </div>
  );
}

// ============== APP ==============
const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "theme": "default",
  "font": "sans",
  "heroMode": "auto",
  "lang": "ja"
}/*EDITMODE-END*/;

function App() {
  const saved = (() => {
    try { return JSON.parse(localStorage.getItem('amamizu.tweaks') || 'null'); } catch(e) { return null; }
  })();
  const init = { ...TWEAK_DEFAULTS, ...(saved || {}) };

  const [lang, setLang] = useState(init.lang);
  const [theme, setTheme] = useState(init.theme);
  const [font, setFont] = useState(init.font);
  const [heroMode, setHeroMode] = useState(init.heroMode);
  const [editMode, setEditMode] = useState(false);

  const t = useMemo(() => {
    const o = window.I18N[lang] || window.I18N.ja;
    return { ...o, __lang: lang };
  }, [lang]);

  useEffect(() => {
    document.body.classList.remove('theme-default','theme-spring','theme-summer','theme-autumn','theme-winter');
    document.body.classList.add(`theme-${theme}`);
    document.body.classList.toggle('ff-serif', font === 'serif');
  }, [theme, font]);

  const dispatchEdit = (edits) => {
    const merged = { ...TWEAK_DEFAULTS, theme, font, heroMode, lang, ...edits };
    localStorage.setItem('amamizu.tweaks', JSON.stringify(merged));
    window.parent.postMessage({ type: '__edit_mode_set_keys', edits }, '*');
  };

  useEffect(() => {
    dispatchEdit({ lang });
  }, [lang]);

  useEffect(() => {
    const onMsg = (e) => {
      if (!e.data) return;
      if (e.data.type === '__activate_edit_mode') setEditMode(true);
      if (e.data.type === '__deactivate_edit_mode') setEditMode(false);
    };
    window.addEventListener('message', onMsg);
    window.parent.postMessage({ type: '__edit_mode_available' }, '*');
    return () => window.removeEventListener('message', onMsg);
  }, []);

  return (
    <>
      <Nav t={t} lang={lang} setLang={setLang} editMode={editMode} />
      <Hero t={t} heroMode={heroMode} />
      <Ticker t={t} />
      <House t={t} />
      <Floorplan t={t} />
      <Rooms t={t} />
      <DayTimeline t={t} />
      <Pricing t={t} />
      <Events t={t} />
      <Seasons t={t} />
      <Around t={t} />
      <Access t={t} />
      <Book t={t} />
      <Info t={t} />
      <Footer t={t} />
      <StickyCta t={t} />
      <TweaksPanel editMode={editMode} theme={theme} setTheme={setTheme} font={font} setFont={setFont} heroMode={heroMode} setHeroMode={setHeroMode} dispatchEdit={dispatchEdit} />
    </>
  );
}

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