    </div>
  </main>

  <?php require __DIR__ . '/../templates/nav-bottom.php'; ?>

</div>

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

<script src="/public/js/app.js"></script>
<script>
if (window.__themeAssets) {
  document.addEventListener('DOMContentLoaded', () => {
    const a = window.__themeAssets;
    if (a['logo-text']) {
      document.querySelectorAll('.header-logo, .nav-desktop-logo').forEach(el => { el.textContent = a['logo-text']; });
    }
    if (a['logo-image']) {
      document.querySelectorAll('.header-logo').forEach(el => {
        el.innerHTML = '<img src="' + a['logo-image'] + '" alt="Logo" style="height:28px;">';
      });
    }
    if (a['favicon']) {
      let link = document.querySelector('link[rel="icon"]') || document.createElement('link');
      link.rel = 'icon'; link.href = a['favicon'];
      document.head.appendChild(link);
    }
    if (a['sprite-svg']) {
      document.querySelectorAll('use[href^="/public/icons/sprite.svg"]').forEach(el => {
        el.setAttribute('href', el.getAttribute('href').replace('/public/icons/sprite.svg', a['sprite-svg']));
      });
    }
    // Individual icon overrides
    Object.keys(a).forEach(k => {
      if (k.startsWith('icon-')) {
        const iconName = k;
        document.querySelectorAll('use[href$="#' + iconName + '"]').forEach(useEl => {
          const svg = useEl.closest('svg');
          if (svg) {
            const img = document.createElement('img');
            img.src = a[k];
            img.style.cssText = 'width:100%;height:100%;object-fit:contain;';
            img.alt = iconName;
            svg.replaceWith(img);
          }
        });
      }
      if (k.startsWith('piece-')) {
        const piece = k.replace('piece-', '');
        document.documentElement.style.setProperty('--piece-' + piece, 'url(' + a[k] + ')');
      }
    });
  });
}
</script>
<?php if (isset($extraJs)): ?>
<?php if (is_array($extraJs)): ?>
<?php foreach ($extraJs as $js): ?>
<script src="<?= $js ?>"></script>
<?php endforeach; ?>
<?php else: ?>
<script src="<?= $extraJs ?>"></script>
<?php endif; ?>
<?php endif; ?>
<?php
// Prefetch adjacent pages
$prefetchMap = [
  '' => ['/games', '/profile'],
  'home' => ['/games', '/profile'],
  'games' => ['/play', '/ludo'],
  'play' => ['/games', '/game'],
  'ludo' => ['/games', '/ludo-game'],
];
$currentRoute = $route ?? '';
if (isset($prefetchMap[$currentRoute])):
  foreach ($prefetchMap[$currentRoute] as $pf): ?>
<link rel="prefetch" href="<?= $pf ?>">
<?php endforeach; endif; ?>
</body>
</html>
