<?php
$route = $_GET['route'] ?? '';
$route = trim($route, '/');

// API routes — pass through to PHP endpoints
if (str_starts_with($route, 'api/')) {
    $apiFile = str_replace('api/', '', $route);
    $apiPath = __DIR__ . '/api/' . basename($apiFile) . '.php';
    if (file_exists($apiPath)) {
        require $apiPath;
    } else {
        http_response_code(404);
        echo json_encode(['error' => 'endpoint not found']);
    }
    exit;
}

// Everything else: serve the SPA shell
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
  <meta name="theme-color" content="#030A12">
  <title>EL3AB</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700;800&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="/app/styles/tokens.css">
  <link rel="stylesheet" href="/app/styles/reset.css">
  <link rel="stylesheet" href="/app/styles/animations.css">
  <link rel="stylesheet" href="/app/styles/shell.css">
  <link rel="stylesheet" href="/app/styles/components.css">
</head>
<body>
<div id="app">

  <!-- Header -->
  <header class="hdr" id="hdr">
    <a href="/" class="hdr-brand">EL3AB</a>
    <div class="hdr-center">
      <span class="hdr-level" id="hdr-level">Lv 1</span>
      <div class="hdr-currency">
        <svg class="hdr-currency-icon icon-sm icon-fill" style="color:var(--gold)"><use href="/public/icons/sprite.svg#icon-coin"></use></svg>
        <span id="hdr-coins">0</span>
      </div>
      <div class="hdr-currency">
        <svg class="hdr-currency-icon icon-sm icon-fill" style="color:var(--purple)"><use href="/public/icons/sprite.svg#icon-gem"></use></svg>
        <span id="hdr-gems">0</span>
      </div>
    </div>
    <div class="hdr-actions">
      <a href="/notifications" class="hdr-btn" aria-label="الاشعارات">
        <svg class="icon"><use href="/public/icons/sprite.svg#icon-bell"></use></svg>
      </a>
    </div>
  </header>

  <!-- Main Content (SPA renders here) -->
  <div class="main" id="main"></div>

  <!-- Bottom Navigation -->
  <nav class="nav" id="nav">
    <a href="/" class="nav-item active">
      <svg class="icon"><use href="/public/icons/sprite.svg#icon-home"></use></svg>
      <span>الرئيسية</span>
    </a>
    <a href="/games" class="nav-item">
      <svg class="icon"><use href="/public/icons/sprite.svg#icon-games"></use></svg>
      <span>العاب</span>
    </a>
    <a href="/leaderboard" class="nav-item">
      <svg class="icon"><use href="/public/icons/sprite.svg#icon-leaderboard"></use></svg>
      <span>ترتيب</span>
    </a>
    <a href="/friends" class="nav-item">
      <svg class="icon"><use href="/public/icons/sprite.svg#icon-friends"></use></svg>
      <span>اجتماعي</span>
    </a>
    <a href="/profile" class="nav-item">
      <svg class="icon"><use href="/public/icons/sprite.svg#icon-profile"></use></svg>
      <span>حسابي</span>
    </a>
  </nav>

  <!-- Toast Layer -->
  <div class="toast-layer" id="toasts"></div>

  <!-- Particle Canvas -->
  <canvas id="particles"></canvas>

</div>

<script type="module" src="/app/main.js"></script>
</body>
</html>
