<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My VOD & Live TV</title>
<style>
  body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background: radial-gradient(circle at top, #222 0, #000 60%);
    color: #fff;
  }
  .app {
    padding: 20px;
  }
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
  }
  .card {
    background: linear-gradient(145deg, #1b1b1b, #2a2a2a);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.6);
    cursor: pointer;
    transition: transform .2s, box-shadow .2s;
  }
  .card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 18px 40px rgba(0,0,0,0.8);
  }
  .badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    background: #ff3366;
    margin-bottom: 6px;
  }
  .title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
  }
  .meta {
    font-size: 12px;
    opacity: .7;
  }
</style>
</head>
<body>
<div class="app">
  <h1>VOD & Live TV</h1>
  <div id="grid" class="grid"></div>
</div>

<script>
async function loadNetworks() {
  const res = await fetch('backend-engine.php');
  const json = await res.json();
  if (json.status !== 'ok') {
    console.error(json);
    return;
  }

  const grid = document.getElementById('grid');
  grid.innerHTML = '';

  json.networks.forEach(net => {
    // You decide schema; here I assume net.data.channels is an array
    const channels = net.data.channels || [];
    channels.forEach(ch => {
      const card = document.createElement('div');
      card.className = 'card';
      card.innerHTML = `
        <div class="badge">${net.file.replace('.json','')}</div>
        <div class="title">${ch.name || 'Untitled channel'}</div>
        <div class="meta">${ch.type || 'Live/VOD'} • ${ch.category || 'General'}</div>
      `;
      card.onclick = () => {
        // play stream, open modal, etc.
        if (ch.url) {
          window.open(ch.url, '_blank');
        }
      };
      grid.appendChild(card);
    });
  });
}

loadNetworks();
</script>
</body>
</html>