function Events() {
  const sectionRef = React.useRef(null);
  const [visible, setVisible] = React.useState(false);
  const [data, setData] = React.useState(null);

  // Load events from data/events.json — edit that file to update events
  React.useEffect(() => {
    fetch('./data/events.json')
      .then(r => r.json())
      .then(setData)
      .catch(console.error);
  }, []);

  React.useEffect(() => {
    const observer = new IntersectionObserver(
      ([entry]) => { if (entry.isIntersecting) { setVisible(true); observer.disconnect(); } },
      { threshold: 0.08 }
    );
    if (sectionRef.current) observer.observe(sectionRef.current);
    return () => observer.disconnect();
  }, [data]); // re-observe when data loads so the ref points to the real section

  if (!data) return <section className="ev" ref={sectionRef} id="events" style={{ minHeight: '60vh', background: '#0F0F0F' }} />;

  const { featured, upcoming } = data;

  return (
    <>
      <style>{`
        /* ── Section ── */
        .ev {
          background: #0F0F0F;
          padding: 100px 0 0;
          overflow: hidden;
        }

        /* ── Header ── */
        .ev-header {
          display: flex;
          align-items: flex-end;
          justify-content: space-between;
          padding: 0 96px 64px;
          gap: 40px;
          opacity: 0; transform: translateY(16px);
          transition: opacity 0.8s cubic-bezier(0.16,1,0.3,1) 0.1s,
                      transform 0.8s cubic-bezier(0.16,1,0.3,1) 0.1s;
        }
        .ev-header.in { opacity: 1; transform: translateY(0); }

        .ev-eyebrow {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 11px; font-weight: 400;
          letter-spacing: 0.35em; text-transform: uppercase;
          color: #E84800;
          display: flex; align-items: center; gap: 12px;
          margin-bottom: 18px;
        }
        .ev-eyebrow-rule { width: 32px; height: 1px; background: #E84800; opacity: 0.6; }

        .ev-title {
          font-family: 'Playfair Display', serif;
          font-size: clamp(32px, 3vw, 50px);
          font-weight: 400; font-style: italic;
          color: #F5F0EA;
          line-height: 1.15; letter-spacing: -0.02em;
        }

        .ev-header-cta {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 11px; font-weight: 400;
          letter-spacing: 0.28em; text-transform: uppercase;
          color: rgba(255,255,255,0.35);
          text-decoration: none;
          flex-shrink: 0;
          display: flex; align-items: center; gap: 10px;
          transition: color 0.25s ease;
        }
        .ev-header-cta:hover { color: rgba(255,255,255,0.8); }
        .ev-header-cta-arrow {
          width: 18px; height: 1px;
          background: currentColor; position: relative; flex-shrink: 0;
          transition: width 0.3s cubic-bezier(0.16,1,0.3,1);
        }
        .ev-header-cta-arrow::after {
          content: '';
          position: absolute; right: 0; top: 50%;
          transform: translateY(-50%) rotate(45deg);
          width: 4px; height: 4px;
          border-right: 1px solid currentColor;
          border-top: 1px solid currentColor;
        }
        .ev-header-cta:hover .ev-header-cta-arrow { width: 28px; }

        /* ── Featured card ── */
        .ev-featured {
          position: relative;
          height: 62vh;
          min-height: 440px;
          overflow: hidden;
          cursor: pointer;
          margin: 0 96px;
          border-radius: 2px;
          background: #111;
          opacity: 0; transform: translateY(24px);
          transition: opacity 0.9s cubic-bezier(0.16,1,0.3,1) 0.2s,
                      transform 0.9s cubic-bezier(0.16,1,0.3,1) 0.2s;
        }
        .ev-featured.in { opacity: 1; transform: translateY(0); }

        /* Atmospheric dark background — no image */
        .ev-featured-bg {
          position: absolute; inset: 0;
          background:
            radial-gradient(ellipse 80% 60% at 70% 50%, rgba(232,72,0,0.08) 0%, transparent 65%),
            radial-gradient(ellipse 50% 80% at 20% 80%, rgba(200,114,10,0.05) 0%, transparent 60%),
            #0D0D0D;
        }
        /* Grain texture */
        .ev-featured-grain {
          position: absolute; inset: 0; pointer-events: none; opacity: 0.18;
          background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.72' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23g)' opacity='0.08'/%3E%3C/svg%3E");
        }
        /* Hairline border */
        .ev-featured-border {
          position: absolute; inset: 0;
          border: 1px solid rgba(255,255,255,0.05);
          pointer-events: none;
        }

        .ev-featured-overlay { display: none; }

        /* Orange left edge */
        .ev-featured-accent {
          position: absolute; top: 0; left: 0; bottom: 0;
          width: 2px; z-index: 3;
          background: linear-gradient(to bottom, #E84800, transparent 70%);
        }

        .ev-featured-content {
          position: absolute; inset: 0; z-index: 2;
          display: flex; flex-direction: column;
          justify-content: flex-end;
          padding: 52px 56px;
        }

        /* Date badge */
        .ev-date-badge {
          position: absolute;
          top: 36px; right: 40px;
          text-align: center;
          background: rgba(15,15,15,0.72);
          backdrop-filter: blur(12px);
          border: 1px solid rgba(255,255,255,0.1);
          padding: 16px 22px;
          border-radius: 2px;
          z-index: 3;
        }
        .ev-date-day {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 9px; font-weight: 400;
          letter-spacing: 0.35em; text-transform: uppercase;
          color: #E84800;
          display: block; margin-bottom: 6px;
        }
        .ev-date-num {
          font-family: 'Playfair Display', serif;
          font-size: 26px; font-weight: 400;
          color: #F5F0EA;
          line-height: 1; display: block; margin-bottom: 4px;
        }
        .ev-date-time {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 9px; font-weight: 300;
          letter-spacing: 0.2em;
          color: rgba(255,255,255,0.38);
          display: block;
        }

        /* Tag pill */
        .ev-tag {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 9px; font-weight: 400;
          letter-spacing: 0.35em; text-transform: uppercase;
          color: #E84800;
          margin-bottom: 14px;
          display: flex; align-items: center; gap: 10px;
        }
        .ev-tag::before {
          content: ''; display: block;
          width: 3px; height: 3px; border-radius: 50%;
          background: #E84800; flex-shrink: 0;
        }

        .ev-featured-title {
          font-family: 'Playfair Display', serif;
          font-size: clamp(32px, 4vw, 58px);
          font-weight: 400; font-style: italic;
          color: #F5F0EA;
          line-height: 1.08; letter-spacing: -0.02em;
          margin-bottom: 10px;
        }

        .ev-featured-artist {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 11px; font-weight: 300;
          letter-spacing: 0.2em; text-transform: uppercase;
          color: rgba(255,255,255,0.5);
          margin-bottom: 20px;
        }

        .ev-featured-desc {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 12px; font-weight: 300;
          letter-spacing: 0.06em; line-height: 1.85;
          color: rgba(245,240,234,0.42);
          max-width: 500px;
          margin-bottom: 36px;
        }

        .ev-featured-btn {
          display: inline-flex; align-items: center; gap: 12px;
          font-family: 'Josefin Sans', sans-serif;
          font-size: 11px; font-weight: 600;
          letter-spacing: 0.22em; text-transform: uppercase;
          color: #fff;
          background: #E84800;
          text-decoration: none;
          padding: 14px 32px;
          border-radius: 100px;
          box-shadow: 0 4px 28px rgba(232,72,0,0.35);
          align-self: flex-start;
          transition: background 0.22s ease,
                      transform 0.22s cubic-bezier(0.34,1.56,0.64,1),
                      box-shadow 0.22s ease;
        }
        .ev-featured-btn:hover {
          background: #FF5C1A;
          transform: translateY(-2px);
          box-shadow: 0 8px 40px rgba(232,72,0,0.5);
        }
        .ev-featured-btn:active { transform: translateY(0); }

        /* ── Upcoming cards grid ── */
        .ev-grid {
          display: grid;
          grid-template-columns: repeat(3, 1fr);
          gap: 2px;
          margin: 2px 96px 0;
        }

        .ev-card {
          position: relative;
          height: 44vh;
          min-height: 300px;
          overflow: hidden;
          cursor: pointer;
          opacity: 0; transform: translateY(20px);
          transition: opacity 0.8s cubic-bezier(0.16,1,0.3,1),
                      transform 0.8s cubic-bezier(0.16,1,0.3,1);
        }
        .ev-card:nth-child(1) { transition-delay: 0.25s; }
        .ev-card:nth-child(2) { transition-delay: 0.38s; }
        .ev-card:nth-child(3) { transition-delay: 0.51s; }
        .ev-card.in { opacity: 1; transform: translateY(0); }

        .ev-card-img {
          width: 100%; height: 100%;
          object-fit: cover; object-position: center;
          display: block;
          transform: scale(1.06);
          transition: transform 0.9s cubic-bezier(0.16,1,0.3,1);
        }
        .ev-card:hover .ev-card-img { transform: scale(1); }

        .ev-card-overlay {
          position: absolute; inset: 0; z-index: 1;
          background: linear-gradient(
            to top,
            rgba(0,0,0,0.92) 0%,
            rgba(0,0,0,0.45) 45%,
            rgba(0,0,0,0.1)  100%
          );
          transition: background 0.4s ease;
        }
        .ev-card:hover .ev-card-overlay {
          background: linear-gradient(
            to top,
            rgba(0,0,0,0.96) 0%,
            rgba(0,0,0,0.4)  45%,
            rgba(0,0,0,0.05) 100%
          );
        }

        /* Orange top accent */
        .ev-card-accent {
          position: absolute; top: 0; left: 0; right: 0;
          height: 2px; z-index: 3;
          background: #E84800;
          transform: scaleX(0); transform-origin: left;
          transition: transform 0.45s cubic-bezier(0.16,1,0.3,1);
        }
        .ev-card:hover .ev-card-accent { transform: scaleX(1); }

        .ev-card-content {
          position: absolute; inset: 0; z-index: 2;
          display: flex; flex-direction: column;
          justify-content: flex-end;
          padding: 32px 32px;
        }

        .ev-card-date {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 9px; font-weight: 400;
          letter-spacing: 0.3em; text-transform: uppercase;
          color: #E84800;
          margin-bottom: 8px;
        }

        .ev-card-title {
          font-family: 'Playfair Display', serif;
          font-size: clamp(20px, 1.8vw, 30px);
          font-weight: 400; font-style: italic;
          color: #F5F0EA;
          line-height: 1.15; letter-spacing: -0.01em;
          margin-bottom: 6px;
        }

        .ev-card-artist {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 10px; font-weight: 300;
          letter-spacing: 0.15em; text-transform: uppercase;
          color: rgba(255,255,255,0.38);
          margin-bottom: 18px;
          transition: color 0.25s ease;
        }
        .ev-card:hover .ev-card-artist { color: rgba(255,255,255,0.65); }

        .ev-card-tag {
          display: inline-block;
          font-family: 'Josefin Sans', sans-serif;
          font-size: 9px; font-weight: 400;
          letter-spacing: 0.28em; text-transform: uppercase;
          color: rgba(255,255,255,0.35);
          border: 1px solid rgba(255,255,255,0.12);
          padding: 5px 12px;
          border-radius: 100px;
          align-self: flex-start;
          transition: border-color 0.25s ease, color 0.25s ease;
        }
        .ev-card:hover .ev-card-tag {
          border-color: rgba(232,72,0,0.5);
          color: #E84800;
        }

        /* ── Footer CTA ── */
        .ev-footer {
          display: flex; align-items: center; justify-content: center;
          gap: 16px;
          padding: 48px 96px;
          margin: 2px 96px 0;
          border-top: 1px solid rgba(255,255,255,0.05);
          opacity: 0; transform: translateY(12px);
          transition: opacity 0.8s cubic-bezier(0.16,1,0.3,1) 0.65s,
                      transform 0.8s cubic-bezier(0.16,1,0.3,1) 0.65s;
        }
        .ev-footer.in { opacity: 1; transform: translateY(0); }

        .ev-footer-text {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 10px; font-weight: 400;
          letter-spacing: 0.3em; text-transform: uppercase;
          color: rgba(255,255,255,0.25);
        }
        .ev-footer-link {
          font-family: 'Josefin Sans', sans-serif;
          font-size: 10px; font-weight: 600;
          letter-spacing: 0.25em; text-transform: uppercase;
          color: #E84800;
          text-decoration: none;
          transition: color 0.22s ease;
        }
        .ev-footer-link:hover { color: #FF5C1A; }

        /* ── Responsive ── */
        @media (max-width: 1100px) {
          .ev-featured, .ev-grid, .ev-footer { margin-left: 48px; margin-right: 48px; }
        }
        @media (max-width: 900px) {
          .ev { padding: 72px 0 0; }
          .ev-header { padding: 0 32px 48px; flex-direction: column; align-items: flex-start; gap: 20px; }
          .ev-featured { margin: 0; height: 72vw; min-height: 280px; border-radius: 0; }
          .ev-featured-content { padding: 32px; }
          .ev-grid { grid-template-columns: 1fr; grid-template-rows: auto; margin: 2px 0 0; }
          .ev-card { height: 64vw; }
          .ev-footer { margin: 2px 0 0; padding: 36px 32px; flex-direction: column; gap: 12px; }
        }
        @media (max-width: 480px) {
          .ev-featured-title { font-size: 26px; }
          .ev-featured-content { padding: 24px; }
          .ev-date-badge { top: 20px; right: 20px; }
        }
      `}</style>

      <section className="ev" ref={sectionRef} id="events" aria-label="Events and entertainment">

        {/* Header */}
        <div className={`ev-header ${visible ? 'in' : ''}`}>
          <div>
            <p className="ev-eyebrow">
              <span className="ev-eyebrow-rule" />
              What's On
            </p>
            <h2 className="ev-title">
              Every night,<br />a new show.
            </h2>
          </div>
        </div>

        {/* Featured event */}
        <div className={`ev-featured ${visible ? 'in' : ''}`}>
          <div className="ev-featured-bg" />
          <div className="ev-featured-grain" />
          <div className="ev-featured-border" />
          <div className="ev-featured-accent" />

          <div className="ev-featured-content">
            <p className="ev-tag">{featured.tag}</p>
            <h3 className="ev-featured-title">{featured.title}</h3>
            <p className="ev-featured-artist">{featured.artist}</p>
            <p className="ev-featured-desc">{featured.desc}</p>
            <a
              href="https://wa.me/23058582020?text=Hi%2C%20I'd%20like%20to%20reserve%20a%20table"
              className="ev-featured-btn"
              target="_blank"
              rel="noopener noreferrer"
            >
              <svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
                <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/>
              </svg>
              Reserve a Table
            </a>
          </div>
        </div>

        {/* Upcoming cards */}
        <div className="ev-grid">
          {upcoming.map((ev, i) => (
            <div key={i} className={`ev-card ${visible ? 'in' : ''}`}>
              <img
                src={ev.image}
                alt={ev.title}
                className="ev-card-img"
                loading="lazy"
                style={ev.position ? { objectPosition: ev.position } : undefined}
              />
              <div className="ev-card-overlay" />
              <div className="ev-card-accent" />
              <div className="ev-card-content">
                <span className="ev-card-title">{ev.title}</span>
                <span className="ev-card-artist">{ev.artist}</span>
                <span className="ev-card-tag">{ev.tag}</span>
              </div>
            </div>
          ))}
        </div>

      </section>
    </>
  );
}
