const { useState, useEffect, useRef } = React;

// ── Hero EP Widget ────────────────────────────────────────────
function HeroEpWidget() {
  const auth = typeof useAuth !== 'undefined' ? useAuth() : {};
  const { user, hasPass, openModal } = auth;
  const [showPurchase, setShowPurchase] = useState(false);
  const unlocked = hasPass ? hasPass('transmission-vip') : false;

  const handleClick = () => {
    if (unlocked) { window.location.href = 'transmission.html'; return; }
    alert('Access passes go live tonight! Check back soon.');
  };

  return (
    <>
      <div onClick={handleClick} className="liquid-glass" style={{
        borderRadius: 20, padding: '16px 20px', display: 'flex', alignItems: 'center', gap: 18,
        cursor: 'pointer', maxWidth: 380, transition: 'transform 0.2s, box-shadow 0.2s',
        border: '1px solid rgba(201,168,76,0.25)',
      }}
        onMouseEnter={e => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 8px 32px rgba(0,0,0,0.5)'; }}
        onMouseLeave={e => { e.currentTarget.style.transform = 'none'; e.currentTarget.style.boxShadow = 'none'; }}
      >
        <img src="uploads/Transmission Artwork no title.jpg" alt="Transmission"
          style={{ width: 80, height: 80, borderRadius: 12, objectFit: 'cover', flexShrink: 0, boxShadow: '0 4px 12px rgba(0,0,0,0.4)' }} />
        <div style={{ flex: 1, minWidth: 0 }}>
          <div style={{ fontSize: '0.68rem', fontWeight: 600, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--accent)', marginBottom: 5 }}>
            {unlocked ? 'Now Available' : 'New Release'}
          </div>
          <div style={{ fontFamily: "'Instrument Serif', serif", fontStyle: 'italic', fontSize: '1.35rem', color: '#fff', lineHeight: 1.1, marginBottom: 6 }}>
            Transmission <span style={{ fontSize: '0.45em', opacity: 0.7 }}>EP</span>
          </div>
          <div style={{ fontSize: '0.78rem', color: unlocked ? 'rgba(255,255,255,0.5)' : 'var(--accent)', fontWeight: 500 }}>
            {unlocked ? 'Click to listen →' : 'Available Tonight — VIP Access'}
          </div>
        </div>
        <div style={{ color: 'rgba(255,255,255,0.4)', flexShrink: 0 }}>
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><polyline points="9 18 15 12 9 6"/></svg>
        </div>
      </div>
      {showPurchase && typeof PassModal !== 'undefined' && <PassModal passId="transmission-vip" onClose={() => setShowPurchase(false)} />}
    </>
  );
}

// ── Hero ──────────────────────────────────────────────────────
function Hero() {
  const [loaded, setLoaded] = useState(false);
  const [streamOpen, setStreamOpen] = useState(false);
  const streamRef = useRef(null);

  useEffect(() => { setTimeout(() => setLoaded(true), 100); }, []);

  // Close dropdown when clicking outside
  useEffect(() => {
    const handler = e => { if (streamRef.current && !streamRef.current.contains(e.target)) setStreamOpen(false); };
    document.addEventListener('mousedown', handler);
    return () => document.removeEventListener('mousedown', handler);
  }, []);

  const streamLinks = [
    { label: 'Spotify', href: 'https://open.spotify.com/artist/1QbliGbXD2XPwfszhDWpbj?si=lY3KzEnXQ-G1x0Ngekxf3w', color: '#1DB954', icon: <IconSpotify /> },
    { label: 'Apple Music', href: 'https://music.apple.com/us/artist/fondew/1805463033', color: '#FA253E', icon: <IconMusic /> },
  ];

  return (
    <section id="hero" style={{ position: 'relative', minHeight: '100vh', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', overflow: 'hidden', background: '#000' }}>
      {/* Background photo */}
      <div style={{ position: 'absolute', inset: 0, backgroundImage: 'url("uploads/BKG Img clean.png")', backgroundSize: 'cover', backgroundPosition: 'center top', zIndex: 0, filter: 'brightness(0.45)' }} />
      {/* Dark overlay for contrast */}
      <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(to bottom, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0.1) 40%, rgba(0,0,0,0.5) 80%, #000 100%)', zIndex: 1, pointerEvents: 'none' }} />

      {/* Content */}
      <div style={{ position: 'relative', zIndex: 3, textAlign: 'center', padding: '0 24px', width: '100%' }}>
        {/* Logo */}
        <div style={{
          opacity: loaded ? 1 : 0, transform: loaded ? 'none' : 'translateY(20px)',
          transition: 'opacity 0.9s ease, transform 0.9s ease',
          marginBottom: 16,
        }}>
          <img src="uploads/logo_upload-1776702310334.png" alt="FonDeW"
            style={{ width: 'min(1060px, 88vw)', filter: 'invert(1)', objectFit: 'contain', display: 'block', margin: '0 auto' }} />
        </div>

        {/* Heading */}
        <h1 style={{
          fontFamily: "'Instrument Serif', serif", fontStyle: 'italic',
          fontSize: 'clamp(1.2rem, 2.8vw, 2rem)', lineHeight: 1,
          letterSpacing: '-0.5px', color: '#fff', marginBottom: 32,
          opacity: loaded ? 1 : 0, transform: loaded ? 'none' : 'translateY(30px)',
          transition: 'opacity 1s ease 0.15s, transform 1s ease 0.15s',
          whiteSpace: 'nowrap',
        }}>
          Indie Fusion <em style={{ color: 'var(--accent)', fontStyle: 'italic' }}>from the underground.</em>
        </h1>

        {/* CTAs */}
        <div style={{
          display: 'flex', gap: 12, justifyContent: 'center', flexWrap: 'wrap',
          opacity: loaded ? 1 : 0, transform: loaded ? 'none' : 'translateY(20px)',
          transition: 'opacity 1s ease 0.4s, transform 1s ease 0.4s',
        }}>
          <div ref={streamRef} style={{ position: 'relative', display: 'inline-block' }}>
            <button className="btn-accent" onClick={() => setStreamOpen(o => !o)}
              style={{ padding: '10px 22px', fontSize: '0.82rem', textDecoration: 'none' }}>
              <IconMusic /> Listen Now
              <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" style={{ marginLeft: 4, transition: 'transform 0.2s', transform: streamOpen ? 'rotate(180deg)' : 'none' }}><polyline points="6 9 12 15 18 9"/></svg>
            </button>
            {streamOpen && (
              <div className="liquid-glass" style={{
                position: 'absolute', top: 'calc(100% + 10px)', left: '50%', transform: 'translateX(-50%)',
                borderRadius: 14, padding: '6px', minWidth: 180,
                display: 'flex', flexDirection: 'column', gap: 2, zIndex: 100,
              }}>
                {streamLinks.map(s => (
                  <a key={s.label} href={s.href} target="_blank" rel="noopener noreferrer"
                    style={{
                      display: 'flex', alignItems: 'center', gap: 10,
                      padding: '10px 14px', borderRadius: 9, textDecoration: 'none',
                      color: '#fff', fontSize: '0.85rem', fontWeight: 500,
                      transition: 'background 0.15s',
                    }}
                    onMouseEnter={e => e.currentTarget.style.background = 'rgba(255,255,255,0.08)'}
                    onMouseLeave={e => e.currentTarget.style.background = 'transparent'}
                  >
                    <span style={{ color: s.color }}>{s.icon}</span>
                    {s.label}
                  </a>
                ))}
              </div>
            )}
          </div>
          <a href="#videos" className="liquid-glass-strong" style={{
            borderRadius: 9999, padding: '10px 22px', fontSize: '0.82rem',
            color: '#fff', textDecoration: 'none', display: 'inline-flex', alignItems: 'center', gap: 8, fontWeight: 500
          }}>
            <IconPlay /> Watch Videos
          </a>
        </div>

        {/* Partner-style tag */}
        <div className="hero-platform-row" style={{
          marginTop: 80, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 20,
          opacity: loaded ? 1 : 0,
          transition: 'opacity 1.2s ease 0.9s',
        }}>
          <div className="liquid-glass" style={{ borderRadius: 9999, padding: '6px 16px', fontSize: '0.72rem', color: 'rgba(255,255,255,0.45)', letterSpacing: '0.08em', textTransform: 'uppercase' }}>
            As heard on
          </div>
          {['Spotify', 'Apple Music', 'Tidal', 'Pandora'].map(p => (
            <span key={p} style={{ fontFamily: "'Instrument Serif', serif", fontStyle: 'italic', fontSize: '1.1rem', color: 'rgba(255,255,255,0.35)' }}>{p}</span>
          ))}
        </div>
      </div>

      {/* Scroll cue */}
      <div style={{
        position: 'absolute', bottom: 36, left: '50%', transform: 'translateX(-50%)',
        zIndex: 3, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 8,
        opacity: loaded ? 0.5 : 0, transition: 'opacity 1.5s ease 1.2s',
      }}>
        <div style={{ width: 1, height: 48, background: 'linear-gradient(to bottom, transparent, rgba(255,255,255,0.4))', animation: 'scrollPulse 2s ease-in-out infinite' }} />
      </div>

      {/* EP Advertisement Widget — bottom right */}
      <div style={{
        position: 'absolute', bottom: 32, right: 32, zIndex: 4,
        opacity: loaded ? 1 : 0, transition: 'opacity 1.2s ease 1.2s',
      }}>
        <HeroEpWidget />
      </div>
      <style>{`@keyframes scrollPulse { 0%,100%{opacity:0.3;transform:scaleY(0.8)} 50%{opacity:1;transform:scaleY(1)} }`}</style>
    </section>
  );
}

// ── New Release ───────────────────────────────────────────────
const transmissionTracks = [
  { num: '01', title: 'Platinum Frame' },
  { num: '02', title: 'Finger Paint' },
  { num: '03', title: 'Lullaby' },
  { num: '04', title: 'Ocean Drive' },
  { num: '05', title: 'Silhouette' },
];

function NewRelease() {
  const ref = useReveal();
  const [streamOpen, setStreamOpen] = useState(false);
  const streamRef = useRef(null);

  useEffect(() => {
    const handler = e => { if (streamRef.current && !streamRef.current.contains(e.target)) setStreamOpen(false); };
    document.addEventListener('mousedown', handler);
    return () => document.removeEventListener('mousedown', handler);
  }, []);

  const streamLinks = [
    { label: 'Spotify', href: 'https://open.spotify.com/artist/1QbliGbXD2XPwfszhDWpbj?si=lY3KzEnXQ-G1x0Ngekxf3w', color: '#1DB954', icon: <IconSpotify /> },
    { label: 'Apple Music', href: 'https://music.apple.com/us/artist/fondew/1805463033', color: '#FA253E', icon: <IconMusic /> },
  ];

  return (
    <section id="transmission" style={{ background: '#000', padding: '100px 24px', overflow: 'hidden' }}>
      <div style={{ maxWidth: 1200, margin: '0 auto', display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 80, alignItems: 'center' }}>

        {/* Left: Info */}
        <div ref={ref} className="reveal">
          <div style={{ display: 'flex', gap: 10, alignItems: 'center', marginBottom: 28, flexWrap: 'wrap' }}>
            <div className="section-badge">Coming Soon</div>
            <div style={{ fontSize: '0.72rem', color: 'rgba(255,255,255,0.3)', letterSpacing: '0.06em', textTransform: 'uppercase' }}>EP · 2026</div>
          </div>

          <h2 style={{
            fontFamily: "'Instrument Serif', serif", fontStyle: 'italic',
            fontSize: 'clamp(3.5rem, 7vw, 6rem)', lineHeight: 0.88,
            letterSpacing: '-3px', color: '#fff', marginBottom: 20,
          }}>
            Transmission
          </h2>

          <p style={{ color: 'rgba(255,255,255,0.5)', fontWeight: 300, fontSize: '0.9rem', lineHeight: 1.7, marginBottom: 36, maxWidth: 400 }}>
            A collection of live studio performances featuring Pugz — honest, unguarded, and captured in the moment.
          </p>

          {/* Track list */}
          <div style={{ marginBottom: 36, display: 'flex', flexDirection: 'column', gap: 1 }}>
            {transmissionTracks.map((t, i) => (
              <div key={i} style={{
                display: 'flex', alignItems: 'center', gap: 16,
                padding: '10px 0', borderBottom: '1px solid rgba(255,255,255,0.06)',
                transition: 'opacity 0.2s',
              }}
                onMouseEnter={e => e.currentTarget.style.opacity = '0.7'}
                onMouseLeave={e => e.currentTarget.style.opacity = '1'}
              >
                <span style={{ fontFamily: 'monospace', fontSize: '0.7rem', color: 'var(--accent)', minWidth: 20 }}>{t.num}</span>
                <span style={{ color: 'rgba(255,255,255,0.7)', fontSize: '0.85rem', fontWeight: 400 }}>{t.title}</span>
              </div>
            ))}
          </div>

          {/* Streaming buttons */}
          <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', alignItems: 'center' }}>
            <div ref={streamRef} style={{ position: 'relative' }}>
          {/* VIP Access button — wired to pass purchase */}
          <TransmissionVipContent />
            </div>
          </div>
        </div>

        {/* Right: Artwork */}
        <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', position: 'relative' }}>
          {/* Glow behind */}
          <div style={{
            position: 'absolute', width: '75%', height: '75%', borderRadius: '50%',
            background: 'radial-gradient(ellipse, rgba(100,160,200,0.18) 0%, transparent 70%)',
            filter: 'blur(40px)', pointerEvents: 'none',
          }} />
          {/* Album art — natural square shape */}
          <div style={{
            width: 'min(420px, 88vw)',
            borderRadius: 16, overflow: 'hidden',
            border: '1px solid rgba(255,255,255,0.12)',
            boxShadow: '0 0 60px rgba(100,160,200,0.12), 0 20px 60px rgba(0,0,0,0.5)',
            position: 'relative', flexShrink: 0,
          }}>
            <img src="uploads/Transmission Artwork no title.jpg" alt="Transmission EP"
              style={{ width: '100%', height: 'auto', display: 'block' }} />
          </div>
        </div>
      </div>
      <style>{`
        @media(max-width:768px) { #transmission > div { grid-template-columns: 1fr !important; } }
      `}</style>
    </section>
  );
}

// ── About ─────────────────────────────────────────────────────

// ── Contact Popup ─────────────────────────────────────────────
function ContactPopup({ onClose }) {
  const [form, setForm] = React.useState({ name: '', email: '', type: 'booking', message: '' });
  const [sent, setSent] = React.useState(false);
  const overlayRef = React.useRef(null);
  const handleSubmit = e => {
    e.preventDefault();
    fetch('https://formspree.io/f/mvzdvgoq', {
      method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
      body: JSON.stringify(form),
    }).then(r => r.ok ? setSent(true) : alert('Something went wrong.'))
      .catch(() => alert('Something went wrong.'));
  };
  return ReactDOM.createPortal(
    <div ref={overlayRef} onClick={e => e.target === overlayRef.current && onClose()}
      style={{ position: 'fixed', inset: 0, zIndex: 1000, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24, background: 'rgba(0,0,0,0.75)', backdropFilter: 'blur(8px)' }}>
      <div className="liquid-glass" style={{ borderRadius: 24, padding: '36px 32px', width: '100%', maxWidth: 500, position: 'relative' }}>
        <button onClick={onClose} style={{ position: 'absolute', top: 16, right: 16, background: 'none', border: 'none', color: 'rgba(255,255,255,0.4)', fontSize: '1.2rem', cursor: 'pointer' }}>✕</button>
        {sent ? (
          <div style={{ textAlign: 'center', padding: '24px 0' }}>
            <div style={{ fontFamily: "'Instrument Serif', serif", fontStyle: 'italic', fontSize: '2rem', color: 'var(--accent)', marginBottom: 12 }}>Message received.</div>
            <p style={{ color: 'rgba(255,255,255,0.5)', fontWeight: 300 }}>We'll be in touch soon.</p>
            <button className="btn-accent" onClick={onClose} style={{ marginTop: 24, padding: '10px 28px' }}>Close</button>
          </div>
        ) : (
          <>
            <h2 style={{ fontFamily: "'Instrument Serif', serif", fontStyle: 'italic', fontSize: '1.8rem', color: '#fff', marginBottom: 6, letterSpacing: '-0.5px' }}>Get in touch.</h2>
            <p style={{ color: 'rgba(255,255,255,0.4)', fontSize: '0.82rem', marginBottom: 24 }}>Booking, press, licensing, or just to say hi.</p>
            <form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
              <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
                <div>
                  <label style={{ display: 'block', fontSize: '0.72rem', color: 'rgba(255,255,255,0.4)', marginBottom: 6, textTransform: 'uppercase', letterSpacing: '0.06em' }}>Name</label>
                  <input className="glass-input" type="text" placeholder="Your name" required value={form.name} onChange={e => setForm({...form, name: e.target.value})} />
                </div>
                <div>
                  <label style={{ display: 'block', fontSize: '0.72rem', color: 'rgba(255,255,255,0.4)', marginBottom: 6, textTransform: 'uppercase', letterSpacing: '0.06em' }}>Email</label>
                  <input className="glass-input" type="email" placeholder="your@email.com" required value={form.email} onChange={e => setForm({...form, email: e.target.value})} />
                </div>
              </div>
              <div>
                <label style={{ display: 'block', fontSize: '0.72rem', color: 'rgba(255,255,255,0.4)', marginBottom: 6, textTransform: 'uppercase', letterSpacing: '0.06em' }}>Inquiry Type</label>
                <select className="glass-input" value={form.type} onChange={e => setForm({...form, type: e.target.value})} style={{ cursor: 'pointer' }}>
                  <option value="booking">Booking / Shows</option>
                  <option value="press">Press & Media</option>
                  <option value="licensing">Sync & Licensing</option>
                  <option value="other">Other</option>
                </select>
              </div>
              <div>
                <label style={{ display: 'block', fontSize: '0.72rem', color: 'rgba(255,255,255,0.4)', marginBottom: 6, textTransform: 'uppercase', letterSpacing: '0.06em' }}>Message</label>
                <textarea className="glass-input" placeholder="Tell us what you have in mind..." required value={form.message} onChange={e => setForm({...form, message: e.target.value})} style={{ resize: 'vertical', minHeight: 100 }} />
              </div>
              <button type="submit" className="btn-accent" style={{ alignSelf: 'flex-start', padding: '11px 28px' }}>Send Message <IconArrow /></button>
            </form>
          </>
        )}
      </div>
    </div>,
    document.body
  );
}

function About() {
  const ref = useReveal();
  const [contactOpen, setContactOpen] = React.useState(false);
  return (
    <section id="about" style={{ padding: '120px 24px', maxWidth: 1200, margin: '0 auto' }}>
      <div ref={ref} className="reveal" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 80, alignItems: 'center' }}>
        {/* Text */}
        <div>
          <div className="section-badge" style={{ marginBottom: 24 }}>About</div>
          <h2 style={{ fontFamily: "'Instrument Serif', serif", fontStyle: 'italic', fontSize: 'clamp(2.4rem, 5vw, 4rem)', lineHeight: 0.92, letterSpacing: '-2px', marginBottom: 28, color: '#fff' }}>
            Music that heals<br />the soul.
          </h2>
          <p style={{ color: 'rgba(255,255,255,0.6)', fontWeight: 300, fontSize: '0.95rem', lineHeight: 1.75, marginBottom: 20 }}>
            FonDeW is a musician without boundaries, blurring the lines between genres and rooted in depths of raw emotion.
          </p>
          <p style={{ color: 'rgba(255,255,255,0.45)', fontWeight: 300, fontSize: '0.9rem', lineHeight: 1.75, marginBottom: 36 }}>
            Every track is a moment in time — unfiltered, uncompromising, entirely its own.
          </p>
          <>
          <button onClick={() => setContactOpen(true)} className="liquid-glass-strong" style={{ borderRadius: 9999, padding: '10px 24px', color: '#fff', fontSize: '0.85rem', fontWeight: 500, display: 'inline-flex', alignItems: 'center', gap: 8, border: 'none', cursor: 'pointer', background: 'none' }}>
            Booking Inquiries <IconArrow />
          </button>
          {contactOpen && <ContactPopup onClose={() => setContactOpen(false)} />}
          </>
        </div>
        {/* Photo */}
        <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'flex-start' }}>
          <img src="uploads/HeartBasel-clean.png" alt="FonDeW live"
            style={{ width: '100%', maxWidth: 220, borderRadius: 20, display: 'block', objectFit: 'contain' }} />
        </div>
      </div>
      <style>{`
        @media(max-width:768px) {
          #transmission > div { grid-template-columns: 1fr !important; }
        }
        @media(max-width:480px) {
          #about > div > div { grid-template-columns:1fr!important; gap:32px!important; }
          #music { padding: 60px 16px !important; }
          #shows { padding: 60px 16px !important; }
          #contact { padding: 60px 16px !important; }
        }
      `}</style>
    </section>
  );
}

// ── Music ─────────────────────────────────────────────────────
const releases = [
  { title: 'Transmission', type: 'EP', year: '2026', desc: 'A collection of live studio performances featuring Pugz — honest, unguarded, and captured in the moment.', color: 'rgba(40,80,120,0.4)', gated: false, noStream: false, isTransmission: true, artwork: 'uploads/Transmission Artwork no title.jpg' },
  { title: 'Fan Club', type: 'Fan Club', year: '', desc: 'Exclusive access to FonDeW\'s inner circle. Members-only content, early releases, and more.', color: 'rgba(20,20,40,0.8)', gated: true, comingSoon: true, artwork: 'uploads/Club Pass v2 art.png' },
  { title: 'Outta My Hands', type: 'Single', year: '2026', desc: 'A single born from struggle, released specifically to reward the community.', color: 'rgba(30,30,30,0.8)', gated: false, noStream: true, comingSoon: true, artwork: 'uploads/Outta My Hands Thumbnail.png' },
  { title: 'The Sounds EP', type: 'EP', year: '2025', desc: 'Five tracks originally released exclusively on the Ethereum Blockchain.', color: 'rgba(80,40,60,0.5)', gated: false, hasVip: false, comingSoon: true, artwork: 'uploads/The Sounds EP artwork.png' },
  { title: 'Garage Sessions', type: 'Sessions', year: '', desc: 'Intimate recordings from garages across the country. Unpolished, unfiltered, live.', color: 'rgba(30,25,20,0.8)', gated: true, comingSoon: true, artwork: 'uploads/sIIyGx1RnaIAinOdhITP--1--55zcp.jpg' },
  { title: "We've Only Just Begun", type: 'EP', year: '2012', desc: "FonDeW's first ever release with his former band EOS: Evolution Of Sound. Where it all began.", color: 'rgba(60,10,10,0.6)', gated: false, noStream: true, comingSoon: true, artwork: "uploads/We'veOnlyEPFrontCover.jpg" },
  { title: "Don't Talk To Me: FonDeW ReMix", type: 'Cover', year: '2025', desc: "A bold reimagining — FonDeW puts his classic spin on this well known Rocky2Grimey track.", color: 'rgba(30,30,50,0.8)', gated: false, noStream: false, artwork: "uploads/Don't Talk to Me full color.png", spotifyHref: 'https://open.spotify.com/album/5QTiDO9CsAZJpTYntjDAYU?si=8zci-akNRSyCA2jvZcqmUw', appleMusicHref: 'https://music.apple.com/us/album/dont-talk-to-me-radio-edit-single/1805490765' },
  { 
    title: 'Ocean Drive', type: 'Single', year: '2025',
    desc: 'An original composition dedicated to the Shiba Sequoia Forest Project.',
    longDesc: 'An original composition dedicated to the Shiba Sequoia Forest Project — a community-driven initiative working to protect and restore the ancient sequoia populations across the US. Extreme wildfires have killed 98% of all mature giant sequoias in California since 2015, with the vast majority of these losses occurring during the 2020 and 2021 megafires. Ocean Drive was written as a reminder of what we stand to lose, and the magic of time spent in the company of these ancient giants.',
    color: 'rgba(20,50,80,0.6)', gated: false, noStream: false, artwork: 'uploads/Ocean_Drive_Colored.png',
    spotifyHref: 'https://open.spotify.com/track/7CuXXcssfcA6YmxEeqNqck?si=87ed6e310bf94c84',
    appleMusicHref: 'https://music.apple.com/us/album/ocean-drive-single/1805489521'
  },
];

const releaseLinks = {
  'Fan Club': 'release.html#fan-club',
  'Outta My Hands': 'release.html#outta-my-hands',
  'The Sounds EP': 'sounds-ep.html',
  'Garage Sessions': 'release.html#garage-sessions',
  "We've Only Just Begun": 'release.html#weve-only-just-begun',
};

function MusicCard({ r, index }) {
  const href = releaseLinks[r.title] || '#';
  const [expanded, setExpanded] = useState(false);
  const [showPassModal, setShowPassModal] = useState(false);
  const auth = typeof useAuth !== 'undefined' ? useAuth() : {};
  const { user, hasPass, openModal } = auth;

  const handleCardClick = (e) => {
    if (e.target.closest('a') || e.target.closest('button')) return;
    if (r.isTransmission) {
      if (hasPass && hasPass('transmission-vip')) { window.location.href = 'transmission.html'; return; }
      alert('Access passes go live tonight! Check back soon.');
      return;
    }
    if (href !== '#') window.location.href = href;
  };
  const shortDesc = r.shortDesc || r.desc;
  const hasMore = !!r.longDesc;
  return (
    <>
    <div onClick={handleCardClick} style={{ textDecoration: 'none', cursor: href !== '#' || r.isTransmission ? 'pointer' : 'default' }}>
    <div className={`liquid-glass reveal reveal-delay-${index + 1}`} style={{ borderRadius: 20, overflow: 'hidden', display: 'flex', flexDirection: 'column', height: '100%', cursor: 'pointer', transition: 'transform 0.2s, box-shadow 0.2s' }}
      onMouseEnter={e => { e.currentTarget.style.transform = 'translateY(-4px)'; e.currentTarget.style.boxShadow = '0 12px 40px rgba(0,0,0,0.4)'; }}
      onMouseLeave={e => { e.currentTarget.style.transform = 'none'; e.currentTarget.style.boxShadow = 'none'; }}>
      {/* Artwork */}
      <div style={{ aspectRatio: '1 / 1', background: r.color, position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'center', overflow: 'hidden' }}>
        <div style={{ position: 'absolute', inset: 0, background: 'repeating-linear-gradient(45deg, rgba(255,255,255,0.015) 0px, rgba(255,255,255,0.015) 1px, transparent 1px, transparent 8px)' }} />
        {r.artwork
          ? <div style={{ position: 'absolute', inset: 0, backgroundImage: `url('${r.artwork}')`, backgroundSize: 'cover', backgroundPosition: 'center', imageRendering: 'auto' }} />
          : <div style={{ color: 'rgba(255,255,255,0.2)', fontSize: '0.7rem', fontFamily: 'monospace', textAlign: 'center', position: 'relative' }}>
              <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.2)" strokeWidth="1.5" style={{ display: 'block', margin: '0 auto 6px' }}><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21,15 16,10 5,21"/></svg>
              artwork coming
            </div>
        }
        {/* Coming Soon overlay */}
        {r.comingSoon && (
          <div style={{ position: 'absolute', inset: 0, background: 'rgba(0,0,0,0.55)', backdropFilter: 'blur(3px)', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 6 }}>
            <div style={{ fontSize: '0.65rem', fontWeight: 700, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--accent)', padding: '5px 14px', borderRadius: 9999, border: '1px solid rgba(201,168,76,0.4)', background: 'rgba(201,168,76,0.08)' }}>Coming Soon</div>
          </div>
        )}
        <div style={{ position: 'absolute', top: 12, left: 12, display: 'flex', gap: 6 }}>
          {r.type !== 'Fan Club' && r.type !== 'Sessions' && <div style={{ fontSize: '0.65rem', fontWeight: 600, padding: '4px 12px', borderRadius: 9999, background: 'rgba(0,0,0,0.65)', backdropFilter: 'blur(8px)', border: '1px solid rgba(255,255,255,0.25)', color: '#fff', letterSpacing: '0.06em', textTransform: 'uppercase' }}>{r.type}</div>}
          {(r.gated || r.noStream) && r.title !== "We've Only Just Begun" && <div style={{ fontSize: '0.65rem', fontWeight: 600, padding: '4px 10px', borderRadius: 9999, background: 'rgba(0,0,0,0.65)', backdropFilter: 'blur(8px)', border: '1px solid rgba(201,168,76,0.5)', color: 'var(--accent)', letterSpacing: '0.04em' }}>🔑 VIP</div>}
        </div>
      </div>
      {/* Info */}
      <div style={{ padding: '18px 20px 20px', flex: 1, display: 'flex', flexDirection: 'column', minHeight: 160 }}>
        <h3 style={{ fontFamily: "'Instrument Serif', serif", fontStyle: 'italic', fontSize: '1.25rem', color: '#fff', marginBottom: 4 }}>{r.title}</h3>
        <p style={{ color: 'rgba(255,255,255,0.4)', fontSize: '0.78rem', marginBottom: 12, minHeight: '1.2em' }}>{r.year}</p>
        <p style={{ color: 'rgba(255,255,255,0.55)', fontSize: '0.8rem', fontWeight: 300, lineHeight: 1.6, marginBottom: hasMore ? 6 : 16, flex: 1 }}>
          {shortDesc}
        </p>
        {hasMore && (
          <button onClick={e => { e.stopPropagation(); setExpanded(true); }}
            style={{ background: 'none', border: 'none', color: 'var(--accent)', fontSize: '0.75rem', cursor: 'pointer', padding: '0 0 12px', fontWeight: 500, textAlign: 'left' }}>
            Read more
          </button>
        )}
        {expanded && ReactDOM.createPortal(
          <div onClick={() => setExpanded(false)}
            style={{ position: 'fixed', inset: 0, zIndex: 1000, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24, background: 'rgba(0,0,0,0.75)', backdropFilter: 'blur(8px)' }}>
            <div className="liquid-glass" style={{ borderRadius: 24, padding: '36px 32px', width: '100%', maxWidth: 500, position: 'relative' }} onClick={e => e.stopPropagation()}>
              <button onClick={() => setExpanded(false)} style={{ position: 'absolute', top: 16, right: 16, background: 'none', border: 'none', color: 'rgba(255,255,255,0.4)', fontSize: '1.2rem', cursor: 'pointer' }}>✕</button>
              {r.artwork && <img src={r.artwork} alt={r.title} style={{ width: '100%', borderRadius: 12, marginBottom: 20, display: 'block' }} />}
              <h3 style={{ fontFamily: "'Instrument Serif', serif", fontStyle: 'italic', fontSize: '1.6rem', color: '#fff', marginBottom: 8, letterSpacing: '-0.5px' }}>{r.title}</h3>
              <p style={{ color: 'rgba(255,255,255,0.35)', fontSize: '0.78rem', marginBottom: 20 }}>{r.year}</p>
              <p style={{ color: 'rgba(255,255,255,0.65)', fontSize: '0.88rem', lineHeight: 1.75, fontWeight: 300 }}>{r.longDesc}</p>
            </div>
          </div>,
          document.body
        )}
        {r.isTransmission ? (
          <div onClick={e => e.stopPropagation()}>
            <TransmissionVipContent compact />
          </div>
        ) : r.gated ? (
          <button style={{ padding: '5px 12px', borderRadius: 9999, background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.10)', color: '#fff', fontSize: '0.75rem', fontWeight: 500, cursor: 'pointer', display: 'inline-flex', alignItems: 'center', gap: 6, alignSelf: 'flex-start' }}>Explore</button>
        ) : r.noStream ? (
          <button style={{ padding: '5px 12px', borderRadius: 9999, background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.10)', color: '#fff', fontSize: '0.75rem', fontWeight: 500, cursor: 'pointer', display: 'inline-flex', alignItems: 'center', gap: 6, alignSelf: 'flex-start' }}>Explore</button>
        ) : (
          <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
            <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
              {[
                { label: 'Spotify', color: '#1DB954', icon: <IconSpotify />, href: r.spotifyHref || 'https://open.spotify.com/artist/1QbliGbXD2XPwfszhDWpbj?si=lY3KzEnXQ-G1x0Ngekxf3w' },
                { label: 'Apple Music', color: '#FA253E', icon: <IconMusic />, href: r.appleMusicHref || 'https://music.apple.com/us/artist/fondew/1805463033' },
              ].map(s => (
                <a key={s.label} href={s.href} target="_blank" rel="noopener noreferrer"
                  style={{ display: 'inline-flex', alignItems: 'center', gap: 6, padding: '5px 12px', borderRadius: 9999, background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.10)', color: s.color, fontSize: '0.75rem', fontWeight: 500, textDecoration: 'none' }}>
                  {s.icon} {s.label}
                </a>
              ))}
            </div>
            {r.hasVip && (
              <a href="sounds-ep.html" style={{ textDecoration: 'none' }}>
                <button style={{ padding: '5px 12px', borderRadius: 9999, background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.10)', color: '#fff', fontSize: '0.75rem', fontWeight: 500, cursor: 'pointer', display: 'inline-flex', alignItems: 'center', gap: 6 }}>🔑 VIP Content</button>
              </a>
            )}
          </div>
        )}
      </div>
    </div>
    </div>
    {showPassModal && typeof PassModal !== 'undefined' && ReactDOM.createPortal(
      <PassModal passId="transmission-vip" onClose={() => setShowPassModal(false)} />,
      document.body
    )}
    </>
  );
}

function Music() {
  const ref = useReveal();
  return (
    <section id="music" style={{ padding: '100px 24px', background: '#000', maxWidth: 1200, margin: '0 auto' }}>
      <div ref={ref} className="reveal" style={{ marginBottom: 60 }}>
        <div className="section-badge" style={{ marginBottom: 20 }}>Discography</div>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(220px, 1fr))', gap: 20, alignItems: 'stretch' }}>
        {releases.map((r, i) => <MusicCard key={r.title} r={r} index={i} />)}
      </div>
    </section>
  );
}

// ── Shows ─────────────────────────────────────────────────────
const shows = [
  { date: 'Apr 25', day: 'Sat', city: 'Palisade, CO', venue: 'Carboy Vineyards', status: '21+', free: true },
  { date: 'May 2',  day: 'Sat', city: 'Palisade, CO', venue: 'Terravin Vineyards', status: '21+', free: true },
  { date: 'May 8',  day: 'Fri', city: 'Palisade, CO', venue: 'Carboy Vineyards', status: '21+', free: true },
];

function Shows() {
  const ref = useReveal();
  return (
    <section id="shows" style={{ padding: '100px 24px', background: '#000' }}>
      <div style={{ maxWidth: 900, margin: '0 auto' }}>
        <div ref={ref} className="reveal" style={{ marginBottom: 52 }}>
          <div className="section-badge" style={{ marginBottom: 20 }}>Tour Dates</div>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
          {shows.map((s, i) => (
            <div key={i} className={`liquid-glass reveal reveal-delay-${Math.min(i + 1, 4)}`} style={{
              borderRadius: 14, padding: '18px 24px',
              display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 20, flexWrap: 'wrap'
            }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 24, flex: 1 }}>
                {/* Date */}
                <div style={{ minWidth: 64, textAlign: 'center' }}>
                  <div style={{ fontFamily: "'Instrument Serif', serif", fontStyle: 'italic', fontSize: '1.5rem', color: 'var(--accent)', lineHeight: 1 }}>{s.date.split(' ')[0]}</div>
                  <div style={{ fontSize: '0.72rem', color: 'rgba(255,255,255,0.4)', textTransform: 'uppercase', letterSpacing: '0.05em' }}>{s.date.split(' ')[1]} · {s.day}</div>
                </div>
                {/* Divider */}
                <div style={{ width: 1, height: 36, background: 'rgba(255,255,255,0.10)' }} />
                {/* Venue */}
                <div>
                  <div style={{ color: '#fff', fontWeight: 500, fontSize: '0.92rem' }}>{s.city}</div>
                  <div style={{ color: 'rgba(255,255,255,0.45)', fontSize: '0.8rem', marginTop: 2 }}>{s.venue}</div>
                </div>
              </div>
              {/* Status + Ticket */}
              <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
                <span style={{
                  fontSize: '0.72rem', fontWeight: 500, padding: '3px 10px', borderRadius: 9999,
                  background: 'rgba(255,255,255,0.06)',
                  color: 'rgba(255,255,255,0.45)',
                  border: '1px solid rgba(255,255,255,0.10)',
                }}>{s.status}</span>
                {s.free ? (
                  <span style={{ fontSize: '0.78rem', fontWeight: 500, color: 'rgba(255,255,255,0.5)', padding: '6px 16px', borderRadius: 9999, border: '1px solid rgba(255,255,255,0.12)' }}>Free Entry</span>
                ) : (
                  <button className="btn-accent" style={{ padding: '7px 18px', fontSize: '0.8rem' }}>Tickets</button>
                )}
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { Hero, About, Music, Shows, NewRelease });
