// homepage/mobile.jsx — mobile homepage (iPhone shell, single column)
const { useState: uSM, useEffect: uEM } = React;

function MobHeader() {
  return (
    <header style={{
      position: 'sticky', top: 0, zIndex: 40,
      background: 'rgba(241,234,230,0.95)', backdropFilter: 'blur(12px)',
      borderBottom: '1px solid var(--ink-20)',
      padding: '10px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between',
    }}>
      <button style={{ background: 'transparent', border: 'none', padding: 0, fontSize: 18 }}>≡</button>
      <img src="togo/assets/rehaus-dark.png" alt="REHAUS" style={{ height: 14 }} />
      <button className="mono" style={{
        background: 'transparent', border: 'none', fontSize: 10, letterSpacing: '0.1em', textTransform: 'uppercase',
      }}>Bag · 0</button>
    </header>
  );
}

function MobHero() {
  const slides = window.HOME_DATA.heroSlides;
  const [i, setI] = uSM(0);
  const [paused, setPaused] = uSM(false);
  uEM(() => {
    if (paused) return;
    const t = setTimeout(() => setI(p => (p + 1) % slides.length), 7000);
    return () => clearTimeout(t);
  }, [i, paused, slides.length]);

  return (
    <section
      onTouchStart={() => setPaused(true)}
      style={{ position: 'relative', height: 560, background: 'var(--ink)', color: 'var(--paper)', overflow: 'hidden' }}>
      {slides.map((s, idx) => {
        const active = idx === i;
        return (
          <div key={idx} style={{
            position: 'absolute', inset: 0,
            opacity: active ? 1 : 0, transition: 'opacity 600ms',
            pointerEvents: active ? 'auto' : 'none',
          }}>
            <img src={s.image} alt=""
              style={{
                position: 'absolute', inset: 0, width: '100%', height: '100%',
                objectFit: 'cover', objectPosition: s.objectPos,
                transform: active ? 'scale(1.05)' : 'scale(1.0)',
                transition: 'transform 7400ms linear',
                opacity: 0.55,
              }} />
            {s.placeholder && (
              <div style={{
                position: 'absolute', inset: 0,
                background: 'repeating-linear-gradient(135deg, rgba(241,234,230,0.04) 0 12px, rgba(241,234,230,0.08) 12px 24px)',
              }} />
            )}
            <div style={{
              position: 'absolute', inset: 0,
              background: 'linear-gradient(180deg, rgba(54,24,1,0.4) 0%, rgba(54,24,1,0.85) 100%)',
            }} />
            <div style={{
              position: 'relative', zIndex: 2, padding: '40px 18px 90px',
              display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', height: '100%',
            }}>
              <div className="mono" style={{
                fontSize: 9, letterSpacing: '0.16em', color: 'var(--amber)', textTransform: 'uppercase', marginBottom: 14,
              }}>{s.eyebrow}</div>
              <h1 className="serif-display" style={{
                margin: 0, fontSize: s.kind === 'posture' ? 48 : 60, lineHeight: 0.92,
                fontWeight: 600, letterSpacing: '-0.035em', whiteSpace: 'pre-line',
              }}>{s.headline}</h1>
              <div className="serif" style={{
                marginTop: 14, fontSize: 14, lineHeight: 1.45, opacity: 0.88,
              }}>{s.sub}</div>
              <div style={{ display: 'flex', gap: 8, marginTop: 18, flexWrap: 'wrap' }}>
                <a href={s.ctaPrimary.href} className="mono" style={{
                  background: 'var(--amber)', color: 'var(--ink)',
                  padding: '11px 14px', fontSize: 10, letterSpacing: '0.1em', textTransform: 'uppercase',
                  borderRadius: 999, textDecoration: 'none',
                }}>{s.ctaPrimary.label}</a>
                <a href={s.ctaSecondary.href} className="mono" style={{
                  border: '1px solid var(--paper)', color: 'var(--paper)',
                  padding: '11px 14px', fontSize: 10, letterSpacing: '0.1em', textTransform: 'uppercase',
                  borderRadius: 999, textDecoration: 'none',
                }}>{s.ctaSecondary.label}</a>
              </div>
            </div>
          </div>
        );
      })}
      {/* dots */}
      <div style={{
        position: 'absolute', left: 18, bottom: 22, right: 18, zIndex: 5,
        display: 'flex', gap: 8, alignItems: 'center',
      }}>
        {slides.map((_, idx) => (
          <button key={idx} onClick={() => setI(idx)} aria-label={`Slide ${idx+1}`}
            style={{
              flex: 1, height: 2, background: idx === i ? 'var(--paper)' : 'rgba(241,234,230,0.4)',
              border: 'none', padding: 0, cursor: 'pointer',
            }} />
        ))}
        <span className="mono" style={{
          fontSize: 9, letterSpacing: '0.12em', color: 'var(--paper)', marginLeft: 8,
        }}>{String(i+1).padStart(2,'0')}/{String(slides.length).padStart(2,'0')}</span>
      </div>
    </section>
  );
}

function MobUSP() {
  const usps = [
    { k: 'Forever Trade-In', d: 'Trade back any time.', icon: '∞' },
    { k: 'Next-Day UK', d: 'Order by 12pm.', icon: '→' },
    { k: '30-Day Trial', d: 'Live with it first.', icon: '30' },
    { k: 'Authenticated', d: 'By a specialist.', icon: '✓' },
  ];
  return (
    <section style={{
      background: 'var(--paper-cool)', borderTop: '1px solid var(--ink)', borderBottom: '1px solid var(--ink)',
      padding: '14px 0', display: 'flex', overflowX: 'auto', gap: 0,
    }} className="noscroll">
      {usps.map((u, i) => (
        <div key={i} style={{
          flex: '0 0 auto', padding: '4px 16px',
          borderRight: i < usps.length - 1 ? '1px solid var(--ink-20)' : 'none',
          minWidth: 150,
        }}>
          <div className="mono" style={{ fontSize: 9, letterSpacing: '0.1em', textTransform: 'uppercase' }}>{u.icon} · {u.k}</div>
          <div className="serif" style={{ fontSize: 11, color: 'var(--ink-80)', marginTop: 2 }}>{u.d}</div>
        </div>
      ))}
    </section>
  );
}

function MobExplore() {
  const axes = window.HOME_DATA.exploreAxes;
  const [active, setActive] = uSM(axes[0].id);
  const axis = axes.find(a => a.id === active);
  const [lead, ...rest] = axis.cells;
  return (
    <section style={{ background: 'var(--paper)', padding: '40px 0 44px' }}>
      <div style={{ padding: '0 16px 16px' }}>
        <div className="kicker" style={{ marginBottom: 8 }}>§02 — Explore</div>
        <h2 className="serif-display" style={{
          margin: 0, fontSize: 38, lineHeight: 0.94, letterSpacing: '-0.025em', fontWeight: 500,
        }}>Pick a thread.<br/>Pull on it.</h2>
        <div className="serif" style={{
          marginTop: 12, fontSize: 14, lineHeight: 1.45, color: 'var(--ink-80)',
        }}>412 pieces, four ways in. Pick the one that matches how you shop.</div>
      </div>
      {/* horizontally-scrolling tab bar */}
      <div style={{
        display: 'flex', gap: 0, overflowX: 'auto', padding: '0 16px',
        borderBottom: '1px solid var(--ink-20)',
      }} className="noscroll">
        {axes.map(a => {
          const isA = a.id === active;
          return (
            <button key={a.id} onClick={() => setActive(a.id)} style={{
              background: 'transparent', border: 'none', cursor: 'pointer',
              padding: '14px 14px',
              borderBottom: isA ? '2px solid var(--ink)' : '2px solid transparent',
              marginBottom: -1, whiteSpace: 'nowrap',
            }}>
              <div className="mono" style={{
                fontSize: 9, letterSpacing: '0.14em', textTransform: 'uppercase',
                color: isA ? 'var(--ink)' : 'var(--ink-60)',
              }}>{a.label}</div>
            </button>
          );
        })}
      </div>
      <div className="serif" style={{
        padding: '14px 16px 0', fontSize: 13, lineHeight: 1.45, color: 'var(--ink-80)',
      }}>{axis.hint}</div>
      {/* lead card */}
      <a href="#" style={{
        margin: '16px 16px 0', position: 'relative',
        aspectRatio: '5 / 4', overflow: 'hidden', display: 'block',
        background: 'var(--paper-deep)', textDecoration: 'none', color: 'var(--paper)',
      }}>
        <img src={lead.img} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }} />
        <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(180deg, rgba(0,0,0,0) 30%, rgba(0,0,0,0.7) 100%)' }} />
        <div className="mono" style={{
          position: 'absolute', left: 12, top: 12, padding: '4px 7px',
          background: 'rgba(241,234,230,0.94)', color: 'var(--ink)',
          fontSize: 8, letterSpacing: '0.14em', textTransform: 'uppercase',
        }}>{axis.label} · Lead</div>
        <div style={{ position: 'absolute', left: 14, right: 14, bottom: 14 }}>
          <div className="mono" style={{ fontSize: 9, letterSpacing: '0.12em', color: 'var(--amber)', textTransform: 'uppercase' }}>
            {lead.years || lead.range} · {lead.count} pieces
          </div>
          <h3 className="serif-display" style={{ margin: '6px 0 0', fontSize: 36, lineHeight: 0.95, fontWeight: 600, letterSpacing: '-0.025em' }}>{lead.name}</h3>
          <div className="serif" style={{ fontSize: 13, lineHeight: 1.4, opacity: 0.92, marginTop: 8 }}>{lead.blurb}</div>
        </div>
      </a>
      {/* 2-col grid for rest */}
      <div style={{ padding: '14px 16px 0', display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
        {rest.map((c, idx) => (
          <a key={idx} href="#" style={{
            textDecoration: 'none', color: 'var(--ink)',
            border: '1px solid var(--ink-20)', background: 'var(--paper-cool)',
            display: 'flex', flexDirection: 'column',
          }}>
            <div style={{ position: 'relative', aspectRatio: '4 / 3', background: 'var(--paper-deep)', overflow: 'hidden' }}>
              <img src={c.img} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }} />
              <div className="mono" style={{
                position: 'absolute', right: 6, top: 6, padding: '2px 5px',
                background: 'rgba(241,234,230,0.92)', fontSize: 8, letterSpacing: '0.1em', textTransform: 'uppercase',
              }}>{c.count}</div>
            </div>
            <div style={{ padding: '10px 10px 12px' }}>
              <div className="serif-display" style={{ fontSize: 17, letterSpacing: '-0.02em', fontWeight: 500, lineHeight: 1 }}>{c.name}</div>
              <div className="mono" style={{ fontSize: 8, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--ink-60)', marginTop: 4 }}>{c.years || c.range}</div>
            </div>
          </a>
        ))}
      </div>
    </section>
  );
}

function MobRecent() {
  const items = window.HOME_DATA.recent;
  return (
    <section style={{ background: 'var(--paper-cool)', padding: '40px 0 44px', borderTop: '1px solid var(--ink)' }}>
      <div style={{ padding: '0 16px 14px', display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
        <div>
          <div className="kicker" style={{ marginBottom: 6 }}>§03 — Inventory</div>
          <h2 className="serif-display" style={{ margin: 0, fontSize: 30, lineHeight: 0.95, letterSpacing: '-0.025em', fontWeight: 500 }}>Recently authenticated.</h2>
        </div>
        <a href="#" className="mono" style={{ fontSize: 9, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--ink)', borderBottom: '1px solid var(--ink)', paddingBottom: 2 }}>All →</a>
      </div>
      <div style={{ display: 'flex', gap: 10, padding: '0 16px 6px', overflowX: 'auto' }} className="noscroll">
        {items.map(p => (
          <a key={p.id} href="#" style={{ flex: '0 0 180px', textDecoration: 'none', color: 'var(--ink)' }}>
            <div style={{ position: 'relative', aspectRatio: '4 / 5', background: 'var(--paper-deep)', overflow: 'hidden' }}>
              <img src={p.img} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }} />
            </div>
            <div className="serif" style={{ fontSize: 13, marginTop: 8, letterSpacing: '-0.005em' }}>{p.model}</div>
            <div className="mono" style={{ fontSize: 8, letterSpacing: '0.1em', color: 'var(--ink-60)', textTransform: 'uppercase', marginTop: 3 }}>{p.designer} · {p.year}</div>
            <div className="serif" style={{ fontSize: 12, fontWeight: 500, marginTop: 4 }}>£{p.price.toLocaleString()}</div>
          </a>
        ))}
      </div>
    </section>
  );
}

function MobJournal() {
  const items = window.HOME_DATA.editorial;
  return (
    <section style={{ background: 'var(--paper)', padding: '40px 0 44px', borderTop: '1px solid var(--ink-20)' }}>
      <div style={{ padding: '0 16px 14px', display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
        <div>
          <div className="kicker" style={{ marginBottom: 6 }}>§04 — Journal</div>
          <h2 className="serif-display" style={{ margin: 0, fontSize: 30, lineHeight: 0.95, letterSpacing: '-0.025em', fontWeight: 500 }}>From the journal.</h2>
        </div>
        <a href="#" className="mono" style={{ fontSize: 9, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--ink)', borderBottom: '1px solid var(--ink)', paddingBottom: 2 }}>All →</a>
      </div>
      <div style={{ display: 'flex', gap: 12, padding: '0 16px 6px', overflowX: 'auto' }} className="noscroll">
        {items.map((a, i) => (
          <a key={i} href="#" style={{ flex: '0 0 220px', textDecoration: 'none', color: 'var(--ink)' }}>
            <div style={{ position: 'relative', aspectRatio: '4 / 5', overflow: 'hidden', background: 'var(--paper-deep)' }}>
              <img src={a.cover} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }} />
              <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(180deg, rgba(0,0,0,0) 50%, rgba(0,0,0,0.5) 100%)' }} />
              <div className="mono" style={{
                position: 'absolute', left: 10, top: 10, padding: '3px 6px',
                background: 'rgba(241,234,230,0.94)', fontSize: 8, letterSpacing: '0.12em', textTransform: 'uppercase',
              }}>{a.kicker}</div>
            </div>
            <div className="serif" style={{ fontSize: 14, lineHeight: 1.25, marginTop: 10, letterSpacing: '-0.005em' }}>{a.title}</div>
            <div className="mono" style={{ fontSize: 8, letterSpacing: '0.08em', color: 'var(--ink-60)', textTransform: 'uppercase', marginTop: 4 }}>{a.meta}</div>
          </a>
        ))}
      </div>
    </section>
  );
}

function MobEmail() {
  return (
    <section style={{ background: 'var(--paper-cool)', borderTop: '1px solid var(--ink-20)', padding: '32px 16px' }}>
      <div className="kicker" style={{ marginBottom: 6 }}>§05 — Newsletter</div>
      <h3 className="serif-display" style={{ margin: 0, fontSize: 24, lineHeight: 1, letterSpacing: '-0.02em', fontWeight: 500 }}>The list.</h3>
      <div className="serif" style={{ fontSize: 13, lineHeight: 1.5, color: 'var(--ink-80)', marginTop: 10 }}>
        One email a week. New arrivals before they're listed. Unsubscribe in one click.
      </div>
      <form onSubmit={e => e.preventDefault()} style={{ display: 'flex', gap: 6, marginTop: 12 }}>
        <input type="email" placeholder="email@domain.com" style={{
          flex: 1, padding: '11px 12px', border: '1px solid var(--ink)', background: 'var(--paper)', fontSize: 13, fontFamily: 'inherit',
        }} />
        <button className="mono" style={{
          background: 'var(--ink)', color: 'var(--paper)', border: 'none', padding: '11px 14px',
          fontSize: 10, letterSpacing: '0.1em', textTransform: 'uppercase',
        }}>Subscribe →</button>
      </form>
    </section>
  );
}

function MobFooter() {
  return (
    <footer style={{ background: 'var(--ink)', color: 'var(--paper)', padding: '32px 16px 28px' }}>
      <img src="togo/assets/rehaus-white.png" alt="REHAUS" style={{ height: 16, marginBottom: 14 }} />
      <div className="serif" style={{ fontSize: 12, lineHeight: 1.5, opacity: 0.7, maxWidth: 280 }}>
        A resale house for design objects. Authenticated, restored, photographed, and guaranteed forever.
      </div>
      <div className="mono" style={{
        marginTop: 22, paddingTop: 14, borderTop: '1px solid rgba(241,234,230,0.2)',
        fontSize: 9, letterSpacing: '0.08em', textTransform: 'uppercase',
        color: 'rgba(241,234,230,0.6)', display: 'flex', justifyContent: 'space-between',
      }}>
        <span>© 2026 REHAUS</span>
        <span>London · Paris · Milan</span>
      </div>
    </footer>
  );
}

function HomeMobilePage() {
  return (
    <div style={{ height: '100%', overflowY: 'auto', background: 'var(--paper)' }}>
      <MobHeader />
      <MobHero />
      <MobUSP />
      <MobExplore />
      <MobRecent />
      <MobJournal />
      <MobEmail />
      <MobFooter />
    </div>
  );
}

Object.assign(window, { HomeMobilePage });
