<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/includes/facebook_pixel.php';

// Cache-busting automatico: muda a versao sempre que o arquivo for alterado.
function asset_v($file) {
    $path = __DIR__ . '/' . ltrim($file, '/');
    return is_file($path) ? (string)filemtime($path) : (string)time();
}
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Expires: 0');
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
  <title>Subway Halloween — Corra e Ganhe</title>
  <meta name="description" content="Subway Halloween: corra pelos trilhos assombrados, desvie dos obstáculos e dispute prêmios com saque via PIX.">
  <?php echo fb_pixel_html('PageView'); ?>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&amp;family=Nosifer&amp;family=Poppins:wght@400;600;700;800&amp;display=swap" rel="stylesheet">
  <link rel="stylesheet" href="css/style.css?v=<?php echo asset_v('css/style.css'); ?>">
  <link rel="stylesheet" href="/css/copa-tower-theme.css?v=<?php echo asset_v('css/copa-tower-theme.css'); ?>">
  <link rel="stylesheet" href="/css/reference-home.css?v=<?php echo asset_v('css/reference-home.css'); ?>">
  <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='17' r='13' fill='%23ff7518' stroke='%234a2f1a' stroke-width='2'/%3E%3Cpath d='M16 4c-1.5 1.5-1.5 3.5 0 5' stroke='%234a2f1a' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3Cpath d='M10 15l3 3-3 3M22 15l-3 3 3 3M16 16l-2 5h4z' fill='%230a0612'/%3E%3C/svg%3E">
</head>
<body>

  <!-- Loading global -->
  <div id="global-loading" class="global-loading hidden">
    <div class="loading-spinner"></div>
  </div>

  <!-- Toast container -->
  <div id="toast-container" class="toast-container"></div>

  <div id="app">
    <section id="page-landing"  class="page"></section>
    <section id="page-login"    class="page"></section>
    <section id="page-cadastro" class="page"></section>
    <section id="page-painel"   class="page"></section>
    <section id="page-jogo"     class="page"></section>
  </div>

  <script>
  // Remove Service Workers/caches antigos que podem manter tema velho no navegador.
  (function(){
    try {
      if ('serviceWorker' in navigator) {
        navigator.serviceWorker.getRegistrations().then(function(regs){
          regs.forEach(function(reg){ reg.unregister(); });
        });
      }
      if ('caches' in window) {
        caches.keys().then(function(keys){
          keys.forEach(function(key){ caches.delete(key); });
        });
      }
    } catch(e) {}
  })();
  </script>

  <!-- QR Code local (sem depender de APIs externas) -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>

  <!-- Utilitários antes de tudo -->
  <script src="js/utils.js?v=<?php echo asset_v('js/utils.js'); ?>"></script>
  <script src="js/api.js?v=<?php echo asset_v('js/api.js'); ?>"></script>

  <!-- Páginas -->
  <script src="js/landing.js?v=<?php echo asset_v('js/landing.js'); ?>"></script>
  <script src="js/login.js?v=<?php echo asset_v('js/login.js'); ?>"></script>
  <script src="js/cadastro.js?v=<?php echo asset_v('js/cadastro.js'); ?>"></script>
  <script src="js/painel.js?v=<?php echo asset_v('js/painel.js'); ?>"></script>
  <script src="js/jogo.js?v=<?php echo asset_v('js/jogo.js'); ?>"></script>

  <!-- Router — carregado por último -->
  <script src="js/app.js?v=<?php echo asset_v('js/app.js'); ?>"></script>

</body>
</html>