/** Shopify CDN: Minification failed

Line 10:0 Unexpected "("
Line 29:41 Expected ")" to end URL token
Line 67:32 Expected ")" to end URL token
Line 70:57 Expected ")" to end URL token

**/
/* Robgamer v13 — pesquisa confiável + capas mais rápidas */
(() => {
  if (window.RobgamerV13) return; window.RobgamerV13 = true;
  const root = window.Shopify?.routes?.root || '/';
  const cache = new Map();
  const norm = q => q.trim().toLowerCase().replace(/\s+/g, ' ');
  const searchUrl = q => `${root}search?${new URLSearchParams({ q, type: 'product', 'options[prefix]': 'last', 'options[unavailable_products]': 'show' })}`;
  async function suggest(q, signal) {
    const params = new URLSearchParams({ q, 'resources[type]': 'product', 'resources[limit]': '6', 'resources[options][unavailable_products]': 'show', 'resources[options][fields]': 'title,product_type,variants.title,tag,vendor' });
    const r = await fetch(`${root}search/suggest.json?${params}`, { signal, headers: { Accept: 'application/json' }, cache: 'no-store' });
    if (!r.ok) throw new Error('suggest');
    const d = await r.json();
    return (d.resources?.results?.products || []).map(p => ({ url: p.url, title: p.title, image: p.featured_image?.url || p.image }));
  }
  async function fullSearch(q, signal) {
    const r = await fetch(searchUrl(q), { signal, headers: { Accept: 'text/html' } });
    if (!r.ok) throw new Error('search');
    const doc = new DOMParser().parseFromString(await r.text(), 'text/html');
    const seen = new Set(), out = [];
    doc.querySelectorAll('a[href*="/products/"]').forEach(a => {
      const href = new URL(a.getAttribute('href'), location.origin);
      const key = href.pathname.split('?')[0];
      if (seen.has(key) || out.length >= 6) return;
      const card = a.closest('article, li, .card-wrapper, .grid__item') || a;
      const title = card.querySelector('.product-title, .card__heading, h3')?.textContent?.trim() || a.getAttribute('aria-label')?.replace(/^Ver\s+/, '') || a.textContent.trim();
      if (!title) return;
      seen.add(key);
      const img = card.querySelector('img');
      out.push({ url: key, title, image: img?.currentSrc || img?.getAttribute('src') });
    });
    return out;
  }
  async function find(q, signal) {
    const k = norm(q);
    if (cache.has(k)) return cache.get(k);
    let list = [];
    for (let attempt = 0; attempt < 2 && !list.length; attempt++) {
      try { list = await suggest(q, signal); } catch (e) { if (e.name === 'AbortError') throw e; }
    }
    if (!list.length) list = await fullSearch(q, signal);
    cache.set(k, list);
    return list;
  }
  function mount(form) {
    if (form.dataset.rgV13) return; form.dataset.rgV13 = '1';
    const input = form.querySelector('input[name="q"]'); const box = form.closest('.store-search');
    if (!input || !box) return;
    if (!form.querySelector('input[name="type"]')) { const t = document.createElement('input'); t.type = 'hidden'; t.name = 'type'; t.value = 'product'; form.append(t); }
    box.querySelectorAll('.rg-live-search').forEach(n => n.remove());
    const panel = document.createElement('div'); panel.className = 'rg-live-search'; panel.hidden = true; panel.setAttribute('aria-label', 'Sugestões de jogos'); box.append(panel);
    input.autocomplete = 'off';
    let timer = 0, ctrl, seq = 0;
    const hide = () => { panel.hidden = true; };
    const msg = t => { panel.replaceChildren(); const p = document.createElement('p'); p.className = 'rg-live-status'; p.setAttribute('role', 'status'); p.textContent = t; panel.append(p); panel.hidden = false; };
    const all = q => { const a = document.createElement('a'); a.className = 'rg-live-all'; a.href = searchUrl(q); a.textContent = 'Ver todos os resultados →'; panel.append(a); };
    function render(list, q) {
      msg(list.length ? 'Jogos encontrados' : 'Nenhum jogo encontrado com esse nome');
      list.forEach(p => {
        const u = new URL(p.url || '', location.origin); if (u.origin !== location.origin) return;
        const a = document.createElement('a'); a.className = 'rg-live-product'; a.href = u.href;
        const img = document.createElement('img'); img.alt = ''; img.width = 44; img.height = 52; img.decoding = 'async';
        if (p.image) { try { const iu = new URL(p.image, location.origin); iu.searchParams.set('width', '100'); img.src = iu.href; } catch {} }
        const s = document.createElement('span'); const st = document.createElement('strong'); st.textContent = p.title; s.append(st);
        const ar = document.createElement('span'); ar.textContent = '→'; ar.setAttribute('aria-hidden', 'true');
        a.append(img, s, ar); panel.append(a);
      });
      all(q);
    }
    function run(delay) {
      clearTimeout(timer); ctrl?.abort();
      const q = input.value.trim(); const my = ++seq;
      if (q.length < 2) { hide(); return; }
      if (cache.has(norm(q))) { render(cache.get(norm(q)), q); return; }
      msg('Buscando jogos…');
      timer = setTimeout(async () => {
        ctrl = new AbortController();
        try { const list = await find(q, ctrl.signal); if (my === seq) render(list, q); }
        catch (e) { if (e.name !== 'AbortError' && my === seq) { msg('Não foi possível buscar agora.'); all(q); } }
      }, delay);
    }
    input.addEventListener('input', () => run(200));
    input.addEventListener('focus', () => { if (input.value.trim().length >= 2) run(0); });
    input.addEventListener('keydown', e => { if (e.key === 'Escape') hide(); });
    form.addEventListener('submit', () => { clearTimeout(timer); hide(); });
    document.addEventListener('pointerdown', e => { if (!box.contains(e.target)) hide(); });
  }
  const initSearch = s => s.querySelectorAll('.rg .store-search form, .store-search form').forEach(mount);

  /* Capas: carregar antes de aparecer no carrossel */
  function warm(scope) {
    const imgs = scope.querySelectorAll('.rg .product-image-wrap img[loading="lazy"]');
    if (!('IntersectionObserver' in window)) { imgs.forEach(i => i.loading = 'eager'); return; }
    const io = new IntersectionObserver(es => es.forEach(e => {
      if (!e.isIntersecting) return;
      e.target.closest('[data-rg-shelf], .shelf, .rg-collection-grid')?.querySelectorAll('img[loading="lazy"]').forEach(i => { i.loading = 'eager'; });
      io.unobserve(e.target);
    }), { rootMargin: '800px 0px' });
    imgs.forEach(i => { io.observe(i); if (!i.complete) { i.classList.add('rg-img-wait'); const done = () => i.classList.remove('rg-img-wait'); i.addEventListener('load', done, { once: true }); i.addEventListener('error', done, { once: true }); } });
  }
  function init(s) { initSearch(s); warm(s); }
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(document)); else init(document);
  document.addEventListener('shopify:section:load', e => init(e.target));
})();