/* Tracklist — shared chrome (topbar + footer) */

const Logo = ({ size = 16 }) =>
<a href="Home.html" className="brand-mark" style={{ fontSize: size }}>
    <img src="logo.jpg" alt="" style={{ width: 32, height: 32, borderRadius: 8, objectFit: 'cover', display: 'block' }} />
    Tracklist
  </a>;


const MenuIcon = () =>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
    <path d="M2 5H16M2 13H10" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
  </svg>;


const Topbar = ({ active }) => {
  const [open, setOpen] = React.useState(false);
  const ref = React.useRef(null);
  React.useEffect(() => {
    const onDoc = (e) => { if (ref.current && !ref.current.contains(e.target)) setOpen(false); };
    document.addEventListener('mousedown', onDoc);
    return () => document.removeEventListener('mousedown', onDoc);
  }, []);
  return (
    <header className="topbar">
      <Logo />
      <nav style={{ display: 'flex', gap: 6, alignItems: 'center' }}>
        <div className="nav-links">
          <a href="Home.html" className={active === 'home' ? 'nav-active' : ''}>Home</a>
          <a href="Product.html" className={active === 'product' ? 'nav-active' : ''}>Product</a>
          <a href="About.html" className={active === 'about' ? 'nav-active' : ''}>About</a>
          <a href="Contact.html" className={active === 'contact' ? 'nav-active' : ''}>Contact</a>
        </div>
        <a href="https://apps.apple.com/us/app/tracklist-live-music-ratings/id6758921363" className="appstore-btn" aria-label="Download on the App Store" style={{
          display: 'inline-flex', alignItems: 'center', gap: 6,
          background: '#000', border: '1px solid rgba(255,255,255,0.25)',
          borderRadius: 10, padding: '6px 10px', color: '#fff', textDecoration: 'none'
        }}>
          <svg width="14" height="16" viewBox="0 0 22 26" fill="none" aria-hidden="true">
            <path d="M16.5 13.7c0-3 2.5-4.4 2.6-4.5-1.4-2.1-3.6-2.4-4.4-2.4-1.9-.2-3.6 1.1-4.6 1.1-.9 0-2.4-1.1-4-1.1-2 0-3.9 1.2-5 3-2.1 3.7-.5 9.1 1.5 12 1 1.4 2.2 3 3.8 2.9 1.5-.1 2.1-1 4-1s2.4 1 4 1c1.7 0 2.7-1.4 3.7-2.9 1.2-1.7 1.6-3.3 1.7-3.4-.1 0-3.3-1.3-3.3-5zM13.6 4.9c.8-1 1.4-2.4 1.3-3.9-1.3.1-2.8.8-3.7 1.9-.8.9-1.5 2.4-1.3 3.7 1.5.1 3-.7 3.7-1.7z" fill="#fff" />
          </svg>
          <span style={{ display: 'flex', flexDirection: 'column', lineHeight: 1, gap: 2, alignItems: 'flex-start' }}>
            <span style={{ fontSize: 9, fontWeight: 400, letterSpacing: '0.02em' }}>Download on</span>
            <span style={{ fontSize: 14, fontWeight: 600, letterSpacing: '-0.01em' }}>App Store</span>
          </span>
        </a>
        <div ref={ref} style={{ position: 'relative' }}>
          <button className="icon-btn menu-btn" aria-label="Menu" aria-expanded={open} onClick={() => setOpen(o => !o)}><MenuIcon /></button>
          {open && (
            <div style={{
              position: 'absolute', top: 'calc(100% + 8px)', right: 0,
              minWidth: 180,
              background: 'var(--surface)',
              border: '1px solid var(--line)',
              borderRadius: 14,
              padding: 6,
              boxShadow: '0 20px 40px rgba(0,0,0,0.5)',
              display: 'flex', flexDirection: 'column',
              zIndex: 100
            }}>
              <a href="Home.html" style={{
                padding: '12px 14px', borderRadius: 10,
                fontSize: 14, fontWeight: 500,
                color: active === 'home' ? '#fff' : 'var(--text)',
                background: active === 'home' ? 'var(--brand)' : 'transparent'
              }}>Home</a>
              <a href="Product.html" style={{
                padding: '12px 14px', borderRadius: 10,
                fontSize: 14, fontWeight: 500,
                color: active === 'product' ? '#fff' : 'var(--text)',
                background: active === 'product' ? 'var(--brand)' : 'transparent'
              }}>Product</a>
              <a href="About.html" style={{
                padding: '12px 14px', borderRadius: 10,
                fontSize: 14, fontWeight: 500,
                color: active === 'about' ? '#fff' : 'var(--text)',
                background: active === 'about' ? 'var(--brand)' : 'transparent'
              }}>About</a>
              <a href="Contact.html" style={{
                padding: '12px 14px', borderRadius: 10,
                fontSize: 14, fontWeight: 500,
                color: active === 'contact' ? '#fff' : 'var(--text)',
                background: active === 'contact' ? 'var(--brand)' : 'transparent'
              }}>Contact Us</a>
            </div>
          )}
        </div>
      </nav>
    </header>
  );
};


const FooterCTA = () => null;

const Footer = () => {
  const CTABox = () => (
    <div style={{
      padding: '20px 20px', borderRadius: 20, position: 'relative', overflow: 'hidden',
      background: 'linear-gradient(160deg, #6444FF 0%, #3A1FB8 100%)',
    }}>
      <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(circle at 80% 20%, rgba(255,255,255,0.18) 0%, transparent 50%)', pointerEvents: 'none' }} />
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16, position: 'relative' }}>
        <h2 style={{ fontSize: 20, lineHeight: 1.1, margin: 0, color: '#fff', fontWeight: 600 }}>
          Build your<br />
          <span style={{ fontFamily: "'Unbounded', sans-serif", fontWeight: 600, letterSpacing: '-0.02em' }}>Tracklist</span>
        </h2>
        <a href="https://apps.apple.com/us/app/tracklist-live-music-ratings/id6758921363" className="appstore-btn" style={{
          display: 'inline-flex', alignItems: 'center', gap: 8, flexShrink: 0,
          background: '#000', color: '#fff', padding: '8px 14px',
          borderRadius: 12, border: '1px solid rgba(255,255,255,0.25)', textDecoration: 'none'
        }} aria-label="Download on the App Store">
          <svg width="18" height="22" viewBox="0 0 22 26" fill="none" aria-hidden="true">
            <path d="M16.5 13.7c0-3 2.5-4.4 2.6-4.5-1.4-2.1-3.6-2.4-4.4-2.4-1.9-.2-3.6 1.1-4.6 1.1-.9 0-2.4-1.1-4-1.1-2 0-3.9 1.2-5 3-2.1 3.7-.5 9.1 1.5 12 1 1.4 2.2 3 3.8 2.9 1.5-.1 2.1-1 4-1s2.4 1 4 1c1.7 0 2.7-1.4 3.7-2.9 1.2-1.7 1.6-3.3 1.7-3.4-.1 0-3.3-1.3-3.3-5zM13.6 4.9c.8-1 1.4-2.4 1.3-3.9-1.3.1-2.8.8-3.7 1.9-.8.9-1.5 2.4-1.3 3.7 1.5.1 3-.7 3.7-1.7z" fill="#fff" />
          </svg>
          <span style={{ display: 'flex', flexDirection: 'column', lineHeight: 1, gap: 2 }}>
            <span style={{ fontSize: 9, fontWeight: 400 }}>Download on the</span>
            <span style={{ fontSize: 14, fontWeight: 600, letterSpacing: '-0.01em' }}>App Store</span>
          </span>
        </a>
      </div>
    </div>
  );

  return (
    <footer className="footer">
      {/* Mobile: CTA above Tracklist header */}
      <div className="footer-cta-mobile"><CTABox /></div>

      {/* Desktop: Tracklist header + CTA side by side */}
      <div className="footer-top">
        <h2 className="footer-mark" style={{ letterSpacing: '-1.76px', lineHeight: '0.9', margin: 0 }}>
          <span style={{ color: '#fff' }}>Tracklist</span>
        </h2>
        <div className="footer-cta-desktop"><CTABox /></div>
      </div>

      <p style={{ color: 'var(--muted)', fontSize: 14, margin: '24px 0 32px', maxWidth: 320 }}>For the love of live music.</p>
      <div className="footer-grid" style={{ gridTemplateColumns: 'repeat(3, 1fr)', gap: 24 }}>
        <div className="footer-col">
          <h4>Product</h4>
          <ul>
            <li><a href="Product.html">Features</a></li>
          </ul>
        </div>
        <div className="footer-col">
          <h4>Company</h4>
          <ul>
            <li><a href="About.html">About</a></li>
            <li><a href="Contact.html">Contact</a></li>
          </ul>
        </div>
        <div className="footer-col">
          <h4>Legal</h4>
          <ul>
            <li><a href="Privacy.html">Privacy</a></li>
            <li><a href="Terms.html">Terms</a></li>
          </ul>
        </div>
      </div>
      <div className="footer-meta">
        <span>© 2026 Tracklist, Inc.</span>
        <span className="mono">v1.0.0</span>
      </div>
    </footer>
  );
};


Object.assign(window, { Logo, Topbar, Footer, FooterCTA, MenuIcon });