<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>🎤 NYC Stand Up Comedy - Find Shows Tonight</title>
  <meta name="description" content="Find the best stand up comedy shows in New York City. Tonight, this weekend, and more.">
  <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🎤</text></svg>">
  <style>
    * { box-sizing: border-box; margin: 0; padding: 0; }
    :root {
      --bg: #0f0f0f;
      --card-bg: #1a1a1a;
      --border: #2a2a2a;
      --accent: #ff4757;
      --accent-hover: #ff6b7a;
      --text: #ffffff;
      --text-muted: #888888;
      --green: #2ed573;
      --yellow: #ffa502;
    }
    body { 
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      background: var(--bg);
      color: var(--text);
      line-height: 1.6;
      min-height: 100vh;
    }
    .container { max-width: 900px; margin: 0 auto; padding: 0 20px; }
    
    /* Header */
    header { 
      text-align: center; 
      padding: 50px 0 40px;
      background: linear-gradient(180deg, #1a1a2e 0%, transparent 100%);
    }
    .logo { 
      font-size: 4rem; 
      margin-bottom: 10px;
      animation: bounce 2s infinite;
    }
    @keyframes bounce {
      0%, 100% { transform: translateY(0); }
      50% { transform: translateY(-10px); }
    }
    h1 { 
      font-size: 2.5rem; 
      font-weight: 800;
      background: linear-gradient(135deg, #ff4757, #ffa502);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      margin-bottom: 8px;
    }
    .tagline { 
      color: var(--text-muted); 
      font-size: 1.2rem;
    }
    .stats {
      display: flex;
      justify-content: center;
      gap: 30px;
      margin-top: 20px;
    }
    .stat { text-align: center; }
    .stat-num { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
    .stat-label { font-size: 0.8rem; color: var(--text-muted); }
    
    /* Nav */
    .nav { 
      display: flex; 
      justify-content: center; 
      gap: 10px; 
      margin-bottom: 30px; 
      flex-wrap: wrap;
      position: sticky;
      top: 0;
      background: var(--bg);
      padding: 15px 0;
      z-index: 100;
      border-bottom: 1px solid var(--border);
    }
    .nav a { 
      color: var(--text-muted); 
      text-decoration: none; 
      padding: 10px 20px; 
      border-radius: 25px;
      transition: all 0.2s;
      font-weight: 500;
    }
    .nav a:hover, .nav a.active { 
      background: var(--accent); 
      color: white;
    }
    
    /* Filters */
    .filters { 
      display: flex; 
      gap: 10px; 
      margin-bottom: 30px; 
      flex-wrap: wrap;
      justify-content: center;
    }
    .filter-btn { 
      padding: 12px 24px; 
      background: var(--card-bg); 
      border: 1px solid var(--border);
      color: var(--text); 
      border-radius: 25px; 
      cursor: pointer; 
      transition: all 0.2s;
      font-weight: 500;
    }
    .filter-btn:hover, .filter-btn.active { 
      background: var(--accent); 
      border-color: var(--accent);
    }
    
    /* Shows */
    .shows-grid { display: flex; flex-direction: column; gap: 15px; padding-bottom: 50px; }
    
    .date-group { margin-bottom: 30px; }
    .date-header { 
      font-size: 1.1rem; 
      color: var(--text-muted); 
      margin-bottom: 15px; 
      padding-bottom: 10px; 
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      gap: 10px;
    }
    .date-header span { 
      background: var(--accent);
      color: white;
      padding: 4px 12px;
      border-radius: 12px;
      font-size: 0.8rem;
      font-weight: 600;
    }
    
    .show-card { 
      background: var(--card-bg); 
      border-radius: 16px; 
      padding: 20px; 
      border: 1px solid var(--border);
      transition: all 0.2s;
    }
    .show-card:hover { 
      transform: translateY(-3px); 
      border-color: var(--accent);
      box-shadow: 0 10px 40px rgba(255, 71, 87, 0.1);
    }
    
    .show-header { 
      display: flex; 
      justify-content: space-between; 
      align-items: flex-start; 
      margin-bottom: 12px;
    }
    .show-info { flex: 1; }
    .show-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
    .show-venue { 
      color: var(--accent); 
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .show-neighborhood { 
      background: var(--border); 
      padding: 4px 12px; 
      border-radius: 12px;
      font-size: 0.75rem;
      color: var(--text-muted);
      white-space: nowrap;
    }
    
    .show-details { 
      display: flex; 
      gap: 20px; 
      color: var(--text-muted); 
      font-size: 0.9rem;
      margin-bottom: 12px;
    }
    .show-comedians { color: #aaa; font-size: 0.95rem; }
    
    .actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 15px; }
    .ticket-btn { 
      display: inline-flex;
      align-items: center;
      gap: 8px;
      background: var(--accent); 
      color: white; 
      padding: 12px 24px; 
      border-radius: 12px; 
      text-decoration: none; 
      font-weight: 600; 
      transition: all 0.2s;
    }
    .ticket-btn:hover { 
      background: var(--accent-hover); 
      transform: scale(1.02);
    }
    .action-btn { 
      background: var(--border); 
      border: none; 
      color: var(--text); 
      padding: 10px 16px; 
      border-radius: 10px; 
      cursor: pointer; 
      font-size: 0.9rem;
      transition: all 0.2s;
    }
    .action-btn:hover { border-color: var(--accent); }
    .action-btn.saved { background: var(--accent); }
    
    .price { color: var(--green); font-weight: 700; }
    .free { color: var(--yellow); }
    
    .footer { 
         /* Footer */
 text-align: center; 
      padding: 40px 0; 
      color: var(--text-muted); 
      font-size: 0.9rem; 
      border-top: 1px solid var(--border);
    }
    .footer a { color: var(--accent); text-decoration: none; }
    
    /* Loading */
    .loading {
      text-align: center;
      padding: 60px;
      color: var(--text-muted);
    }
    .loading::after {
      content: '...';
      animation: dots 1.5s infinite;
    }
    @keyframes dots {
      0%, 20% { content: '.'; }
      40% { content: '..'; }
      60%, 100% { content: '...'; }
    }
    
    /* Empty */
    .empty {
      text-align: center;
      padding: 60px;
      color: var(--text-muted);
    }
    .empty-icon { font-size: 4rem; margin-bottom: 20px; }
    
    /* Responsive */
    @media (max-width: 600px) {
      h1 { font-size: 1.8rem; }
      .nav { gap: 5px; }
      .nav a { padding: 8px 14px; font-size: 0.9rem; }
      .filter-btn { padding: 10px 16px; font-size: 0.85rem; }
      .show-header { flex-direction: column; gap: 10px; }
      .show-neighborhood { align-self: flex-start; }
    }
  </style>
</head>
<body>
  <header>
    <div class="container">
      <div class="logo">🎤</div>
      <h1>NYC Stand Up Comedy</h1>
      <p class="tagline">Find the best comedy shows tonight</p>
      <div class="stats">
        <div class="stat">
          <div class="stat-num" id="totalShows">--</div>
          <div class="stat-label">Shows</div>
        </div>
        <div class="stat">
          <div class="stat-num" id="totalVenues">--</div>
          <div class="stat-label">Venues</div>
        </div>
      </div>
    </div>
  </header>
  
  <div class="container">
    <nav class="nav">
      <a href="/" class="active">All Shows</a>
      <a href="/neighborhoods.html">By Neighborhood</a>
      <a href="/comedians.html">Comedians</a>
      <a href="/best.html">Best This Week</a>
      <a href="/subscribe.html">Subscribe</a>
    </nav>
    
    <div class="filters">
      <button class="filter-btn active" data-filter="all">All Shows</button>
      <button class="filter-btn" data-filter="tonight">Tonight</button>
      <button class="filter-btn" data-filter="weekend">This Weekend</button>
      <button class="filter-btn" data-filter="free">Free / Cheap</button>
    </div>
    
    <div class="shows-grid" id="shows">
      <div class="loading">Loading shows</div>
    </div>
  </div>
  
  <footer class="footer">
    <p>🎭 Updated daily • <a href="https://github.com/nickedpalm/nycstandupcomedy">GitHub</a></p>
  </footer>

  <script>
    let shows = [];
    
    // Load shows from JSON
    fetch('/data/shows.json')
      .then(r => r.json())
      .then(data => {
        shows = data;
        console.log('Loaded', shows.length, 'shows');
        document.getElementById('totalShows').textContent = shows.length;
        document.getElementById('totalVenues').textContent = new Set(shows.map(s => s.venue)).size;
        renderShows();
      })
      .catch(e => {
        console.error('Failed to load:', e);
        document.getElementById('shows').innerHTML = '<div class="empty"><div class="empty-icon">😢</div><p>Failed to load shows</p></div>';
      });

    const today = new Date().toISOString().split('T')[0];
    const weekendEnd = new Date();
    weekendEnd.setDate(weekendEnd.getDate() + 7);
    const weekendStr = weekendEnd.toISOString().split('T')[0];

    function formatDate(dateStr) {
      const date = new Date(dateStr + 'T00:00:00');
      const today = new Date();
      today.setHours(0,0,0,0);
      const showDate = new Date(dateStr + 'T00:00:00');
      
      if (dateStr === today.toISOString().split('T')[0]) return '🎯 TONIGHT';
      
      const options = { weekday: 'short', month: 'short', day: 'numeric' };
      return date.toLocaleDateString('en-US', options).toUpperCase();
    }

    function renderShows(filter = 'all') {
      const container = document.getElementById('shows');
      let filtered = shows;

      if (filter === 'tonight') {
        filtered = shows.filter(s => s.show_date === today);
      } else if (filter === 'weekend') {
        filtered = shows.filter(s => s.show_date >= today && s.show_date <= weekendStr);
      } else if (filter === 'free') {
        filtered = shows.filter(s => s.price === 'Free' || s.price === '$0' || (s.price && s.price.includes('0')));
      }

      // Sort by date
      filtered.sort((a, b) => a.show_date + a.show_time > b.show_date + b.show_time ? 1 : -1);

      // Group by date
      const grouped = {};
      filtered.forEach(s => {
        if (!grouped[s.show_date]) grouped[s.show_date] = [];
        grouped[s.show_date].push(s);
      });

      if (Object.keys(grouped).length === 0) {
        container.innerHTML = '<div class="empty"><div class="empty-icon">🤷</div><p>No shows found</p></div>';
        return;
      }

      let html = '';
      Object.keys(grouped).sort().forEach(date => {
        html += \`<div class="date-group"><div class="date-header"><span>\${formatDate(date)}</span></div>\`;
        grouped[date].forEach(s => {
          const priceClass = (s.price === 'Free' || s.price === '$0') ? 'free' : 'price';
          const price = s.price || 'See website';
          html += \`
            <div class="show-card">
              <div class="show-header">
                <div class="show-info">
                  <div class="show-title">\${s.title}</div>
                  <div class="show-venue">📍 \${s.venue}</div>
                </div>
                <span class="show-neighborhood">\${s.neighborhood}</span>
              </div>
              <div class="show-details">
                <span>🕐 \${s.show_time}</span>
                <span class="\${priceClass}">\${price}</span>
              </div>
              \${s.comedians ? \`<div class="show-comedians">🎭 \${s.comedians}</div>\` : ''}
              <div class="actions">
                <a href="\${s.ticket_link}" target="_blank" rel="noopener" class="ticket-btn">🎟️ Get Tickets</a>
                <button class="action-btn" onclick="saveShow(\${s.id})">☆ Save</button>
              </div>
            </div>
          \`;
        });
        html += '</div>';
      });

      container.innerHTML = html;
    }

    // Filter buttons
    document.querySelectorAll('.filter-btn').forEach(btn => {
      btn.addEventListener('click', () => {
        document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
        btn.classList.add('active');
        renderShows(btn.dataset.filter);
      });
    });

    // Save shows (localStorage)
    function saveShow(id) {
      alert('Show saved!');
    }
  </script>
</body>
</html>
