// Stashly Landing — Option C. Composed from design-system components. Assigns window.StashlyLanding.
// Type system: Praliner (--font-display) = TITLES ONLY. Hanken (--font-body) = body/UI.
// Caveat (--font-accent) = handwritten one-liners, eyebrows, taglines ('bestie' voice).
const { Logo, Button, Badge, Card, Chip, Icon, Avatar } = window.StashlyDesignSystem_821802;
const APP_STORE_URL = 'https://apps.apple.com/us/app/stashly-makeup-tracker/id6766150902';

const wrap = { maxWidth: 1240, margin: '0 auto', padding: '0 28px' };

// Hero phone slider — bezel stays fixed, app screens crossfade inside.
const APP_SCREENS = ['../assets/app-screen-1.png', '../assets/app-screen-2.png'];
function PhoneSlider() {
  const [i, setI] = React.useState(0);
  React.useEffect(() => {
    const t = setInterval(() => setI(p => (p + 1) % APP_SCREENS.length), 3200);
    return () => clearInterval(t);
  }, []);
  return (
    <div style={{ position: 'relative', width: '100%', height: '100%', borderRadius: 34, overflow: 'hidden', background: '#160309' }}>
      {APP_SCREENS.map((src, n) => (
        <img key={src} src={src} alt="Stashly app screen" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', display: 'block', opacity: n === i ? 1 : 0, transition: 'opacity .7s ease' }} />
      ))}
      <div style={{ position: 'absolute', bottom: 14, left: 0, right: 0, display: 'flex', justifyContent: 'center', gap: 7 }}>
        {APP_SCREENS.map((_, n) => (
          <button key={n} onClick={() => setI(n)} aria-label={`Screen ${n + 1}`} style={{ width: n === i ? 20 : 7, height: 7, borderRadius: 4, border: 'none', padding: 0, cursor: 'pointer', background: n === i ? 'var(--orange-400)' : 'rgba(255,255,255,0.45)', transition: 'width .3s ease, background .3s ease' }} />
        ))}
      </div>
    </div>
  );
}

// Handwritten eyebrow (Caveat).
const Eyebrow = ({ children, color = 'var(--color-primary)', align = 'left' }) => (
  <div style={{ fontFamily: 'var(--font-accent)', fontWeight: 600, fontSize: 27, letterSpacing: '.01em', color, textAlign: align }}>{children}</div>
);

// White-dot texture (from the style guide) — subtle overlay for dark sections.
const DOTS = 'radial-gradient(rgba(255,255,255,0.22) 1.6px, transparent 1.7px)';
const DotTexture = ({ opacity = 0.5, size = 22 }) => (
  <div aria-hidden style={{ position: 'absolute', inset: 0, backgroundImage: DOTS, backgroundSize: `${size}px ${size}px`, opacity, pointerEvents: 'none', maskImage: 'radial-gradient(120% 100% at 50% 0%, #000 45%, transparent 100%)', WebkitMaskImage: 'radial-gradient(120% 100% at 50% 0%, #000 45%, transparent 100%)' }} />
);

// ─────────── Makeup props: flat filled illustrations, one set reused hero → sections ───────────
const PROP_ART = {
  lipstick: (
    <g>
      <rect x="30" y="42" width="24" height="40" rx="4" fill="#d9a441" />
      <rect x="30" y="38" width="24" height="6" rx="2" fill="#b9862f" />
      <rect x="33" y="19" width="18" height="21" fill="#2a1418" />
      <path d="M35 19 L35 5 L50 1 L53 12 L53 19 Z" fill="#cf7d8f" />
    </g>
  ),
  compact: (
    <g>
      <rect x="6" y="26" width="72" height="40" rx="9" fill="#2a1418" />
      <rect x="11" y="30" width="30" height="32" rx="4" fill="#efe4dd" />
      <path d="M15 34 L26 34" stroke="#fff" strokeWidth="2" strokeLinecap="round" opacity="0.7" />
      <rect x="43" y="30" width="30" height="32" rx="4" fill="#3a2026" />
      <circle cx="58" cy="46" r="12" fill="#cf7d8f" />
    </g>
  ),
  palette: (
    <g>
      <rect x="8" y="16" width="68" height="52" rx="7" fill="#2a1418" />
      {[['#e7c3a0', 15, 23], ['#d99a76', 34, 23], ['#c9785e', 53, 23], ['#e0b48f', 15, 44], ['#b5654d', 34, 44], ['#8a4535', 53, 44]].map(([c, x, y], k) => (
        <rect key={k} x={x} y={y} width="16" height="16" rx="3" fill={c} />
      ))}
    </g>
  ),
  perfume: (
    <g>
      <rect x="34" y="8" width="16" height="17" rx="3" fill="#d9a441" />
      <rect x="37" y="24" width="10" height="9" fill="#e6a9a0" />
      <path d="M28 33 Q42 27 56 33 L58 74 Q58 80 52 80 L32 80 Q26 80 26 74 Z" fill="#e6a9a0" />
      <path d="M31 40 Q42 36 53 40 L53 52 Q42 56 31 52 Z" fill="#f3cfc9" opacity="0.8" />
    </g>
  ),
  brush: (
    <g>
      <rect x="38" y="34" width="9" height="46" rx="4.5" fill="#c98a6a" />
      <rect x="36" y="26" width="13" height="10" rx="1.5" fill="#d9a441" />
      <path d="M34 27 Q42.5 3 51 27 Z" fill="#6b4a3a" />
    </g>
  ),
};
const MakeupProp = ({ type, size = 90, className, style }) => (
  <svg viewBox="0 0 84 84" width={size} height={size} aria-hidden className={className}
    style={{ position: 'absolute', pointerEvents: 'none', filter: 'drop-shadow(0 10px 18px rgba(83,26,39,0.20))', ...style }}>
    {PROP_ART[type]}
  </svg>
);

/* ─────────── HERO ─────────── */
function Hero() {
  return (
    <section className="sec" style={{ position: 'relative', overflow: 'hidden', background: 'radial-gradient(120% 90% at 82% 30%, var(--bg-page-alt) 0%, var(--bg-page) 60%)' }}>
      <div className="wrap-pad hero-grid" style={{ ...wrap, display: 'grid', gridTemplateColumns: 'minmax(0,1.05fr) minmax(0,0.95fr)', gap: 48, alignItems: 'center', padding: '64px 28px 72px' }}>
        <div>
          <p style={{ fontFamily: 'var(--font-accent)', fontWeight: 600, fontSize: 32, color: 'var(--color-primary)', margin: '10px 0 4px' }}>Hey girl,</p>
          <h1 className="hero-h1 display-lg" style={{ fontFamily: 'var(--font-display)', fontSize: 66, lineHeight: 1.0, letterSpacing: '-0.015em', color: 'var(--text-strong)', margin: '0 0 22px' }}>Fall back in love with your beauty stash</h1>
          <p style={{ fontFamily: 'var(--font-body)', fontSize: 18, lineHeight: 1.55, color: 'var(--text-body)', maxWidth: 520, margin: '0 0 16px' }}>
            Stashly helps you organize your beauty collection, rediscover forgotten favorites, and make the most of every product you own.
          </p>
          <p style={{ fontFamily: 'var(--font-body)', fontWeight: 600, fontSize: 30, lineHeight: 1.15, color: 'var(--text-strong)', margin: '0 0 26px', maxWidth: 460 }}>Your beauty collection deserves more than a drawer.</p>
          <window.StoreButtons />
          <p style={{ fontFamily: 'var(--font-body)', fontSize: 15, color: 'var(--text-muted)', marginTop: 18 }}>♡ Free to download · Premium from $2.99/month</p>
        </div>
        <div className="hero-phone-wrap" style={{ position: 'relative', display: 'flex', justifyContent: 'center', minHeight: 660 }}>
          {/* flat-lay makeup arrangement behind the phone */}
          <div style={{ position: 'absolute', width: 440, height: 560, top: '50%', left: '50%', transform: 'translate(-50%,-50%)', background: 'radial-gradient(circle at 50% 45%, rgba(207,125,143,0.16), transparent 70%)', borderRadius: '50%', pointerEvents: 'none' }} />
          <div className="hero-props" aria-hidden style={{ position: 'absolute', inset: 0, pointerEvents: 'none' }}>
            <MakeupProp type="palette" size={146} style={{ top: 8, right: '0%', transform: 'rotate(14deg)' }} />
            <MakeupProp type="lipstick" size={112} style={{ top: '37%', right: '-4%', transform: 'rotate(-10deg)' }} />
            <MakeupProp type="perfume" size={126} style={{ bottom: 0, right: '6%', transform: 'rotate(6deg)' }} />
            <MakeupProp type="compact" size={140} style={{ bottom: 10, left: '-4%', transform: 'rotate(-12deg)' }} />
            <MakeupProp type="brush" size={122} style={{ top: '28%', left: '-6%', transform: 'rotate(38deg)' }} />
          </div>
          <div className="hero-phone" style={{ position: 'relative', width: 320, height: 620, background: 'var(--surface-raised)', borderRadius: 44, padding: 10, boxShadow: '0 30px 70px rgba(83,26,39,0.28), 0 0 0 10px #1c080d' }}>
            <PhoneSlider />
          </div>
        </div>
      </div>
    </section>
  );
}

/* ─────────── WHAT STASHLY DOES (compact) ─────────── */
const FEATURES = [
  ['package', 'Remember everything you own', 'Scan a barcode, search, or add it by hand.'],
  ['heart', 'Rediscover forgotten favorites', 'See what has been gathering dust.'],
  ['hourglass', 'Track expirations', 'PAO tracking and alerts before things go bad.'],
  ['star', 'Log every use', 'Know what you love and your cost-per-use.'],
  ['palette', 'Every shade, tracked', 'Multi-shade palettes, pan by pan.'],
  ['sparkles', 'Spin the Lucky Wheel', "Can't choose? Let Stashly decide."],
  ['trophy', 'Project Pan goals', 'Set a 10, 20, 50 or 100 Pan goal and track it.'],
  ['chart-pie', 'Stash stats', 'Collection value, most used and usage streaks.'],
  ['scan-face', 'Built-in mirror', 'A full-screen mirror, one tap away.'],
];
function WhatItDoes() {
  return (
    <section id="how" className="sec" style={{ padding: '72px 0', background: 'var(--bg-page)', position: 'relative', overflow: 'hidden' }}>
      <MakeupProp type="brush" size={96} className="section-prop" style={{ top: 26, right: '3%', transform: 'rotate(24deg)' }} />
      <div className="wrap-pad" style={{ ...wrap, position: 'relative' }}>
        <div style={{ textAlign: 'center', marginBottom: 40 }}>
          <Eyebrow align="center">Everything in one place</Eyebrow>
          <h2 style={{ fontFamily: 'var(--font-display)', fontSize: 46, color: 'var(--text-strong)', margin: '10px 0 0' }}>What Stashly does for you</h2>
        </div>
        <div className="grid-3" style={{ display: 'grid', gridTemplateColumns: 'repeat(3,minmax(0,1fr))', columnGap: 40, rowGap: 26 }}>
          {FEATURES.map(([icon, title, body]) => (
            <div key={title} style={{ display: 'flex', gap: 14, alignItems: 'flex-start' }}>
              <span style={{ width: 44, height: 44, borderRadius: 'var(--radius-md)', background: 'var(--orange-50)', display: 'grid', placeItems: 'center', flex: '0 0 auto' }}>
                <Icon name={icon} size={22} style={{ color: 'var(--color-primary)' }} />
              </span>
              <div>
                <div style={{ fontFamily: 'var(--font-body)', fontWeight: 600, fontSize: 20, color: 'var(--text-strong)', lineHeight: 1.1 }}>{title}</div>
                <div style={{ fontFamily: 'var(--font-body)', fontSize: 14.5, color: 'var(--text-muted)', lineHeight: 1.4, marginTop: 3 }}>{body}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ─────────── NO MORE ─────────── */
function NoMore() {
  const items = ['Forgotten products.', 'Buying the same lipstick twice.', 'Stash chaos.'];
  return (
    <section className="sec" style={{ background: 'var(--burgundy-500)', color: 'var(--cream-200)', padding: '84px 0', position: 'relative', overflow: 'hidden' }}>
      <DotTexture opacity={0.6} />
      <div className="wrap-pad" style={{ ...wrap, position: 'relative' }}>
        <div className="grid-2" style={{ display: 'grid', gridTemplateColumns: 'minmax(0,1fr) minmax(0,1fr)', gap: 48, alignItems: 'center' }}>
          <div>
            <h2 className="display-lg" style={{ fontFamily: 'var(--font-display)', fontSize: 58, margin: '0 0 24px', lineHeight: 1 }}>No more</h2>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
              {items.map(it => (
                <div key={it} style={{ display: 'flex', alignItems: 'center', gap: 12, fontFamily: 'var(--font-body)', fontWeight: 600, fontSize: 22 }}>
                  <Icon name="x" size={20} style={{ color: 'var(--orange-400)', flex: '0 0 auto' }} />{it}
                </div>
              ))}
            </div>
          </div>
          <div style={{ fontFamily: 'var(--font-accent)', fontWeight: 500, fontSize: 28, lineHeight: 1.3, color: 'var(--cream-100)' }}>
            <p style={{ margin: 0, color: 'var(--cream-300)' }}>You bought it with excitement.</p>
            <p style={{ margin: '6px 0', color: 'var(--cream-300)' }}>Then it disappeared.</p>
            <p style={{ margin: 0, color: 'var(--orange-400)' }}>Stashly brings it back.</p>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ─────────── COMING SOON (vision, not yet in the app) ─────────── */
function ComingSoon() {
  const cards = [
    ['trophy', 'Community challenges', 'Play Projects, Review Challenges and more ways to enjoy your stash together.'],
    ['gift', 'Rewards & perks', 'Earn points for using your stash and unlock rewards, discounts and beauty surprises.'],
  ];
  return (
    <section id="next" className="sec" style={{ padding: '84px 0', background: 'var(--bg-page)' }}>
      <div className="wrap-pad" style={wrap}>
        <div style={{ background: 'var(--burgundy-500)', color: 'var(--cream-200)', borderRadius: 'var(--radius-2xl)', padding: '56px 48px', position: 'relative', overflow: 'hidden' }}>
          <div style={{ position: 'absolute', bottom: -50, right: -20, fontFamily: 'var(--font-stroke)', fontSize: 180, color: 'rgba(238,115,36,0.12)', lineHeight: 1, pointerEvents: 'none' }}>♡</div>
          <Eyebrow color="var(--orange-400)">Coming soon</Eyebrow>
          <h2 style={{ fontFamily: 'var(--font-display)', fontSize: 44, margin: '12px 0 10px', lineHeight: 1.05 }}>We're building something exciting.</h2>
          <p style={{ fontFamily: 'var(--font-body)', fontSize: 17, color: 'var(--cream-300)', lineHeight: 1.6, maxWidth: 640, margin: '0 0 32px' }}>
            Stashly is just getting started. These features aren't in the app yet — they're what we're working on next. Download Stashly today and be part of what's next.
          </p>
          <div className="grid-2" style={{ display: 'grid', gridTemplateColumns: 'repeat(2,minmax(0,1fr))', gap: 20, maxWidth: 760 }}>
            {cards.map(([icon, title, body]) => (
              <Card key={title} padding="md" tone="orange" style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
                <Icon name={icon} size={28} />
                <div style={{ fontFamily: 'var(--font-body)', fontWeight: 600, fontSize: 24, lineHeight: 1.1 }}>{title}</div>
                <div style={{ fontFamily: 'var(--font-body)', fontSize: 15, lineHeight: 1.5, opacity: 0.95 }}>{body}</div>
              </Card>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

/* ─────────── PRICING (Free + Premium, as in the App Store) ─────────── */
const TIERS = [
  { name: 'Free', price: '$0', cadence: 'forever', tone: 'default', cta: 'Download free', feats: ['Add products by barcode, search or by hand', 'Expiry alerts / PAO tracking', 'Log every use & cost-per-use', 'Multi-shade palette support', 'Lucky Wheel', 'Project Pan goals', 'Stats & daily usage streak', 'Built-in makeup mirror'] },
  { name: 'Premium', price: '$2.99', cadence: 'per month · or $9.99/year', tone: 'featured', cta: 'Go Premium', feats: ['Everything in Free', 'Unlimited barcode scans', 'Unlimited product search', 'No ads, ever', 'Full premium experience'] },
];
function Pricing() {
  return (
    <section id="pricing" className="sec" style={{ background: 'var(--bg-page-alt)', padding: '84px 0', position: 'relative', overflow: 'hidden' }}>
      <MakeupProp type="compact" size={104} className="section-prop" style={{ bottom: 26, left: '2%', transform: 'rotate(-8deg)' }} />
      <div className="wrap-pad" style={{ ...wrap, textAlign: 'center', position: 'relative' }}>
        <Eyebrow align="center">Pricing</Eyebrow>
        <h2 style={{ fontFamily: 'var(--font-display)', fontSize: 46, color: 'var(--text-strong)', margin: '10px 0 4px' }}>Simple now. Powerful later.</h2>
        <div className="grid-2" style={{ display: 'grid', gridTemplateColumns: 'repeat(2,minmax(0,1fr))', gap: 20, marginTop: 44, textAlign: 'left', alignItems: 'start', maxWidth: 760, marginLeft: 'auto', marginRight: 'auto' }}>
          {TIERS.map(t => {
            const featured = t.tone === 'featured';
            return (
              <div key={t.name} style={{
                background: featured ? 'var(--burgundy-500)' : 'var(--surface-card)', color: featured ? 'var(--cream-200)' : 'var(--text-strong)',
                borderRadius: 'var(--radius-xl)', padding: '30px 26px', boxShadow: featured ? 'var(--shadow-lg)' : 'var(--shadow-sm)',
                position: 'relative', transform: featured ? 'translateY(-10px)' : 'none',
              }}>
                {featured && <div style={{ position: 'absolute', top: 20, right: 20 }}><Badge tone="primary">Ad-free</Badge></div>}
                <div style={{ fontFamily: 'var(--font-display)', fontSize: 26 }}>{t.name}</div>
                <div style={{ display: 'flex', alignItems: 'baseline', gap: 8, margin: '10px 0 20px' }}>
                  <span style={{ fontFamily: 'var(--font-display)', fontSize: 44, color: featured ? 'var(--orange-400)' : 'var(--color-primary)' }}>{t.price}</span>
                  <span style={{ fontFamily: 'var(--font-body)', fontSize: 14, color: featured ? 'var(--cream-300)' : 'var(--text-muted)' }}>{t.cadence}</span>
                </div>
                <a href={APP_STORE_URL} target="_blank" rel="noopener" style={{ textDecoration: 'none', display: 'block' }}>
                  <Button variant={featured ? 'primary' : 'outline'} fullWidth>{t.cta}</Button>
                </a>
                <div style={{ display: 'flex', flexDirection: 'column', gap: 11, marginTop: 22 }}>
                  {t.feats.map(f => (
                    <div key={f} style={{ display: 'flex', alignItems: 'flex-start', gap: 10, fontFamily: 'var(--font-body)', fontSize: 14.5, lineHeight: 1.4 }}>
                      <Icon name="check" size={17} style={{ color: featured ? 'var(--orange-400)' : 'var(--status-success)', flex: '0 0 auto', marginTop: 2 }} />
                      <span style={{ color: featured ? 'var(--cream-200)' : 'var(--text-body)' }}>{f}</span>
                    </div>
                  ))}
                </div>
              </div>
            );
          })}
        </div>
        <div style={{ display: 'flex', justifyContent: 'center', marginTop: 44 }}><window.StoreButtons align="center" /></div>
      </div>
    </section>
  );
}

/* ─────────── FINAL CTA ─────────── */
function FinalCTA() {
  return (
    <section className="sec" style={{ padding: '0 0 90px', background: 'var(--bg-page)' }}>
      <div className="wrap-pad" style={wrap}>
        <div style={{ background: 'var(--color-primary)', color: 'var(--text-on-primary)', borderRadius: 'var(--radius-2xl)', padding: '68px 48px', textAlign: 'center', boxShadow: 'var(--shadow-orange)' }}>
          <Eyebrow align="center" color="var(--burgundy-500)">Join the Stashly beautyverse</Eyebrow>
          <h2 className="display-lg" style={{ fontFamily: 'var(--font-display)', fontSize: 60, margin: '12px 0 26px', lineHeight: 1 }}>Unlock more beauty!</h2>
          <div style={{ display: 'flex', justifyContent: 'center' }}><window.StoreButtons align="center" dark /></div>
          <p style={{ fontFamily: 'var(--font-body)', fontSize: 15, color: 'var(--cream-100)', marginTop: 20, opacity: 0.9 }}>♡ Free to download · Premium from $2.99/month</p>
        </div>
      </div>
    </section>
  );
}

function Landing() {
  return (
    <div style={{ background: 'var(--bg-page)' }}>
      <window.Nav />
      <Hero /><NoMore /><WhatItDoes /><Pricing /><ComingSoon /><FinalCTA />
      <window.Footer />
    </div>
  );
}
window.StashlyLanding = Landing;
