
const { useState, useEffect } = React;

const Logo = ({ size = 'normal' }) => {
  const big = size === 'normal';
  return (
    <div style={{ lineHeight: 1, userSelect: 'none' }}>
      <div style={{
        fontFamily: "'Bebas Neue', sans-serif",
        fontSize: big ? '30px' : '22px',
        letterSpacing: '3px',
        color: '#F5F0EB',
      }}>
        EGG<span style={{ color: '#E86A00' }}>BOY</span><span style={{ color: 'rgba(245,240,235,0.5)', fontSize: big ? '22px' : '16px' }}>GH</span>
      </div>
      <div style={{
        fontFamily: "'JetBrains Mono', monospace",
        fontSize: '8px',
        color: '#E86A00',
        letterSpacing: '5px',
        marginTop: '2px',
      }}>STREET FUEL</div>
    </div>
  );
};

const Nav = () => {
  const [scrolled, setScrolled] = useState(false);
  const [open, setOpen] = useState(false);

  useEffect(() => {
    const fn = () => setScrolled(window.scrollY > 50);
    window.addEventListener('scroll', fn);
    return () => window.removeEventListener('scroll', fn);
  }, []);

  const links = [
    ['Products', '#products'],
    ['Track', 'track.html'],
    ['Loyalty', 'loyalty.html'],
    ['Reserve', 'reservation.html'],
  ];

  return (
    <>
      <nav style={{
        position: 'fixed', top: 0, left: 0, right: 0, zIndex: 1000,
        padding: '18px 48px',
        display: 'flex', alignItems: 'center', justifyContent: 'space-between',
        background: scrolled ? 'rgba(26,26,26,0.97)' : 'transparent',
        backdropFilter: scrolled ? 'blur(24px)' : 'none',
        borderBottom: scrolled ? '1px solid rgba(232,106,0,0.12)' : 'none',
        transition: 'all 0.35s ease',
      }}>
        <a href="index.html" style={{ textDecoration: 'none' }}><Logo /></a>

        {/* Desktop */}
        <div className="hidden-mobile" style={{ alignItems: 'center', gap: '40px' }}>
          {links.map(([label, href]) => (
            <a key={label} href={href} style={{
              color: 'rgba(245,240,235,0.7)',
              fontFamily: "'Space Grotesk', sans-serif",
              fontWeight: '500', fontSize: '14px', letterSpacing: '0.3px',
              textDecoration: 'none', transition: 'color 0.2s',
            }}
              onMouseEnter={e => e.currentTarget.style.color = '#F5F0EB'}
              onMouseLeave={e => e.currentTarget.style.color = 'rgba(245,240,235,0.7)'}
            >{label}</a>
          ))}
          <a href="order.html" style={{
            background: '#E86A00', color: '#1A1A1A',
            padding: '12px 28px',
            fontFamily: "'Space Grotesk', sans-serif",
            fontWeight: '700', fontSize: '13px', letterSpacing: '0.8px',
            textDecoration: 'none', display: 'inline-block',
            transition: 'background 0.2s, transform 0.15s',
          }}
            onMouseEnter={e => { e.currentTarget.style.background = '#FF7B15'; e.currentTarget.style.transform = 'translateY(-1px)'; }}
            onMouseLeave={e => { e.currentTarget.style.background = '#E86A00'; e.currentTarget.style.transform = 'none'; }}
          >ORDER NOW →</a>
        </div>

        {/* Mobile hamburger */}
        <button className="show-mobile" onClick={() => setOpen(!open)} style={{
          background: 'none', border: 'none', cursor: 'pointer',
          padding: '6px', flexDirection: 'column', gap: '5px',
        }}>
          {[0, 1, 2].map(i => (
            <div key={i} style={{
              width: '24px', height: '2px', background: '#F5F0EB',
              transform: open
                ? i === 0 ? 'rotate(45deg) translate(5px, 5px)'
                  : i === 2 ? 'rotate(-45deg) translate(4px, -4px)'
                  : 'scaleX(0)'
                : 'none',
              opacity: open && i === 1 ? 0 : 1,
              transition: 'all 0.3s ease',
            }} />
          ))}
        </button>
      </nav>

      {/* Mobile menu */}
      <div style={{
        position: 'fixed', top: '62px', left: 0, right: 0, zIndex: 999,
        background: 'rgba(18,18,18,0.99)', backdropFilter: 'blur(24px)',
        padding: open ? '32px 28px 40px' : '0 28px',
        display: 'flex', flexDirection: 'column', gap: '0',
        borderBottom: open ? '1px solid rgba(232,106,0,0.18)' : 'none',
        maxHeight: open ? '400px' : '0',
        overflow: 'hidden',
        transition: 'max-height 0.4s ease, padding 0.3s ease',
      }}>
        {links.map(([label, href]) => (
          <a key={label} href={href} onClick={() => setOpen(false)} style={{
            color: '#F5F0EB',
            fontFamily: "'Space Grotesk', sans-serif",
            fontWeight: '600', fontSize: '22px',
            textDecoration: 'none', padding: '12px 0',
            borderBottom: '1px solid rgba(245,240,235,0.06)',
          }}>{label}</a>
        ))}
        <a href="order.html" style={{
          background: '#E86A00', color: '#1A1A1A',
          padding: '16px 24px', marginTop: '20px',
          fontFamily: "'Space Grotesk', sans-serif",
          fontWeight: '700', fontSize: '16px',
          textAlign: 'center', letterSpacing: '1px',
          textDecoration: 'none',
        }}>ORDER NOW →</a>
      </div>
    </>
  );
};

Object.assign(window, { Logo, Nav });
