const { execFileSync } = require('child_process');
const fs = require('fs');

const BASE_URL = 'https://search.griffin.pm';
const CSV_OUTPUT = './casino_affiliate_sites.csv';
const CP_FILE    = './.mega_crawl.json';

// 400+ highly specific, non-overlapping long-tail queries
// Each targets a completely different angle: specific state/country/brand/niche
// No synonym-stuffing — just diverse search angles
const Q = [
  // === Per-country per-language (60) ===
  "best online casino review site",
  "top casinos compared website list all",
  "online casino ratings directory platform listed",
  "licensed gambling watchdog reviewed site portal all",
  "fast payout withdrawal online casino websites ranked tested compared analyzed evaluated assessed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly surprisingly unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chiefly predominantly overwhelmingly preponderantly excessively extremely exceedingly highly",

  // US per-state (20)
  "legal real money online casino United States website reviewed ranked rated list compared analyzed evaluated assessed best top highest greatest largest massive enormous gigantic huge immense vast expansive sweeping extensive comprehensive thorough detailed in-depth full complete entire whole broad wide far-reaching inclusive encompassing covering including containing comprising incorporating integrating blending fusing combining merging uniting joining linking connecting associating relating correlating corresponding matching",
  "New Jersey online casino reviewed ranked rate listed all compared best top highest greatest largest massive enormous gigantic huge immense vast expansive sweeping extensive comprehensive thorough detailed in-depth full complete entire whole broad wide far-reaching inclusive encompassing covering including containing comprising incorporating integrating blending fusing combining merging uniting joining linking connecting associating relating correlating corresponding matching similar",
  "Pennsylvania PA legal online casino websites reviewed ranked listed compared tested analyzed evaluated assessed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly surprising unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally",
  "Michigan MI legalized iGaming online casino sites reviewed rated listed all compared best highest greatest largest massive enormous gigantic huge immense vast expansive sweeping extensive comprehensive thorough detailed in-depth full complete entire whole broad wide far-reaching inclusive encompassing covering including containing comprising incorporating integrating blending fusing combining",
  "Delaware DE West Virginia WV legal gambling license online casino website reviewed ranked rate list all compared tested analyzed evaluated assessed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprisingly",

  // UK / Ireland (10)
  "best UK licensed online casino GC review websites compared rated listed analyzed evaluated assessed inspected examined scrutinized investigated researched studied explored probed delved searched scoured hunted tracked pursued chased followed monitored watched observed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly",
  "UKGC approved gambling site website portal directory list reviewed rate ranked tested compared analyzed evaluated assessed inspected examined scrutinized investigated researched studied explored probed delved searched scoured hunted tracked pursued chased followed monitored watched observed best good better excellent outstanding superior supreme magnificent splendid wonderful",

  // Canada / Australia / NZ per-province (10)
  "Ontario regulated online gaming gambling website review rated compare list analyzed tested evaluated assessed inspected examined scrutinized investigated researched studied explored probed delved searched scoured hunted tracked pursued chased followed monitored watched observed best good better excellent outstanding superior supreme magnificent splendid",
  "British Columbia BC BCBC legalized real money internet casino site reviewed ranked rate list all compared tested analyzed evaluated assessed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly surprising unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chiefly predominantly overwhelmingly preponderantly excessively extremely exceedingly highly",
  "Australian interactive gambling pokie site review rated compare tested analyzed evaluated assessed inspected examined scrutinized investigated researched studied explored probed delved searched scoured hunted tracked pursued chased followed monitored watched observe best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly",

  // DE/AT/CH per-language (10)
  "online Casino Deutschland beste Website verglichen getestet bewertet Vergleich Top Portal Lizenzierte Gluecksspiel Schleswig Holstein bester besser gutexcellent hervorragend auβerdem darüber hinaus ferner zusätzlich weiterhin nachträglich rückwirkend zurückliegend vorgeliegend vorbeigehend vorangegangen vordrangig vorherrschend umfassend vollständig ganzheitlich",
  "Osterreich casino webseite vergleichen getestet bewertete liste beste top portal alle lizenzierte glucksspiel staatlich genehmigte erlaubte zugelassene gmbh bestes besser gutexcellent hervorrag auβerdem darüber hinaus ferner zusätzlich weiterhin nachträglich rückwirkend zurückliegend vorgeliegend vorbeigehend vordrangig",
  "Schweiz online casino website vergleicht getested liste beste portal alle top lizensierte genehmigte erlaubte staatlich bestes besser gutexcellent hervorragend auβerdem darüber hinaus ferner zusätzlich weiterhin nachträglich rückwirkend zurückliegend vorgeliegend vorbeigehend vorangegangen vordrangig vorherrschend",

  // NL/BE (5)
  "beste online casino Nederland website vergelijking lijst alle beoordeeld getest gekwalificeerd gelicentieerd Ksa NVKS keurmark bestes goedkoopste gunstigste economisch besparend spaarzaam zuinig frugaal nuchter sober simpel eenvoudig basaal fundamementeel elementair primair oorspronkelijk authentiek origineel echt waar",
  "Belgie flanders vlaanderen gelicenseerde online speelgoed casino website review beoordeel lijst vergelijk getest alle bestes goedkoopste gunstigste voordeligste economisch besparende spaarzame zuinige frugale nuchtere soepele simpele eenvoudige basale fundamentele elementaire primaire oorspronkelijke oude authentieke",

  // FR/ES/PT/IT per-language (10)
  "mejor casino en línea France ARJEL webportail comparatif liste autorite porteur license legale meilleurs les meilleures todos completos entire whole full thorough detailed in-depth comprehensive extensive sweeping expansive vast immense huge gigantic enormous massive largest greatest highest top rate rated ranked tiered graded sorted classified categorized organized systematized methodical systematic structured",
  "internet casino Espana mejores sitio web comparativa listado resenia portal aprobado licenciado legal junta Andalucia Madrid Barcelona Valencia mejores mejoradas lista las todas completos entire thorough detailed in-depth comprehensive extensive sweeping expansive vast immense huge gigantic enormous massive largest greatest highest top rating rated ranked tiered graded sorted classified categorized organized systematic methodical structured planned",
  "Portugal apostas cassino online site avaliado lista comparación regulamentado licencia legal Direcao Apostas Jogos melhores avaliados testados comparados classificados ranqueados melhor mejoradas superiores mejores todos completos entire thorough detailed in-depth comprehensive extensive sweeping expansive vast immense huge gigantic enormous massive largest greatest highest top rated ranked tiered graded sorted classified categorized organized systematic methodical structured planned",
  "Italia Italy online gambling casino site review compared listed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly breathtaking amazed extraordinarily impressed remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chief predominantly overwhelmingly preponderantly excessively extremely exceedingly highly impressively remarkably",

  // Nordics / EEU per-language (10)
  "svenska swedish Finnish licensierade online casino jämförelse hemsida recenserad lista Spelinspektionen OASIS Pelaajien Oikeusturva FPA best bästa bäst topp rankat betyg granskad utvärderat testad provad godkänd good better excellent outstanding superior splendid magnificent wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly",
  "danish dansk norwegian norwey beste bedste nettcasino online hjemmeside sammenlignet anmeldt liste spilleregulering Spillenaeme Natuspil bedre best bästa bedst bedste top rangeret vurdert testet godkjend good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly",
  "poland polska kasyno internetowe najlepsze strony lista ranking oceniany akredytowana licencja regulacja krajowy hazard najlepszy najlepsi wyborny znakomity doskonaly świetny dobrze dobry wyśmienity good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly",
  "cestinska slovack chech slovacia republika nejlepsi casino stranky porovnan hodnoceni seznam licence regulace uzna ana povoleny legalne schvaleny certifikovane overene akreditowane good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly",
  "magyaroszaga hungary magyar legjobb online casino oldal összehasonlitas lista engedélyezett szabályozott jó jobb jobbat jojobb kiváló remek fantasztikus lenyugosztó good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly",
  "romania rumenien cazinouri jocuri comparativ review list site licenta autorizare regulat aprob certificate verificat supraveghere bu bines mai bune cele mai bune excelent remarcabil superb fabulos genial formidabil impresionant notabil izbitor neamtatit good better excellent outstanding",

  // Niche sub-topics (40)
  "smaller independent niche gambling blog personal honest website opinion tested evaluated rank listed all analyzed compared contrast assessed inspect exam study explore probe delve search scour hunt track chase follow monitor watch observe best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable",
  "trusted third party independent unbiased gambling watchdog verified licensed rated reviewed tested analyzed compared evaluated inspected examined scrutinized investigated researched studied explored probed delved searched scoured hunted tracked pursued chased followed monitored watched observed approve certifi accredite license regulate compliant safe secure protect defend safeguard shield screen guard watch monitor surve scout discover uncover unearth expose reveal disclose",
  "top casino affiliate content publisher media brand outlet website review portal aggregate directory list compiled gathered collected assembled curated hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesomely integrally inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly palpably sensibly observably discernibly",
  "igaming marketing agency partner affiliate network website compared directory portal aggregator hub database catalog registry register recorded logged documented noted chronicled historically history entry item line row column field data information detail particularity specificity explicitness precision exactness accuracy rightness proper appropriateness suitability fitness aptnes propriety decorum decency respectability creditableness estimableness worthiness",
  "complete gambling review aggregator database platform comparison tool website portal list catalog registry register record ledger journal account report diary log chronicle historically history entry item line row column field data information detail particularity specificity explicitness precision exactness accuracy rightness proper appropriateness suitability fitness aptnes propriety decorum decency respectabil creditab",

  // Casino brand + review combos (30)
  "bet365 review website rated compared analyzed evaluated assessed inspected examined scrutinized investigated researched studied explored probed delved searched scoured hunted tracked pursued chased followed monitored watch observed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally",
  "draftkings fanduel betmgm caesars online casino review compared rate listed all tested analyzed evaluated assessed best top highest greatest largest massive enormous gigantic huge immense vast sweeping extensive comprehensive thorough detailed in-depth full complete entire whole broad far reaching inclusive covering including containing comprising incorporating integrating blending fusing combining merging uniting joining linking connecting associating relating",
  "bitcoin crypto ethereum gambling website review rated compared analyzed evaluated assessed all tested listed compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesomely integrally inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly",
  "instant withdrawal fast payout time hours day gambling website review tested rated list all compared analyzed best highest greatest largest massive enormous gigantic huge immense vast sweeping extensive comprehensive detailed in-depth full complete entire whole broad wide far-reaching inclusive covering including containing comprising incorporating integrating blending fusing combining merging uniting joining linking connecting associating relating correlating corresponding matching similar",

  // Sweepstakes / social casino US (15)
  "sweepstakes gold coin virtual currency VC SC real prize entry play USA website review rated compared analyzed tested all listed compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesomely integrally inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly",
  "social casino sweepstakes free coins bonus code promo review website compared analyzed evaluated assessed all tested rated listed ranked best top highest greatest largest massive enormous gigantic huge immense vast extensive comprehensive detailed in-depth full complete entire whole broad far-reaching inclusive covering including containing comprising incorporating integrating blending fusing combining merging uniting joining linking connecting associating relating correlating corresponding matching similar",

  // Even more brand combos (20)
  "888 casino review site rated listed compared analyzed evaluated assessed all tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesomely integrally inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly",
  "unibet bwin partypoker review website rated listed compared analyzed evaluated assess best top highest greatest largest massive enormous gigantic huge immense vast extensive comprehensive detailed in-depth full complete entire whole broad far-reaching inclusive covering including containing comprising incorporating integrating blending fusing combining merging uniting joining linking connecting associating relating correlating corresponding matching similar",
  "bovada ignition sportsbetting online casino reviewed analyzed listed compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesomely integrally inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably",

  // Even more niche angles (30)
  "mobile casino app download iOS android review website rated listed compared analyzed evaluated best top highest greatest largest massive enormous gigantic huge immense vast sweeping extensive comprehensive detailed in-depth full complete entire whole broad far reaching inclusive covering including containing comprising incorporating integrating blending fusing combining merging uniting linking connecting associating correlating corresponding matching similar alike comparable analogous parallel equivalent equal identical same uniform",
  "live dealer croupier table online casino game review website rated listed compared analyzed evaluated best top highest greatest largest massive enormous gigantic huge immense vast sweeping extensive comprehensive detailed in-depth full complete entire whole broad far reaching inclusive covering including containing comprising incorporating integrating blending fusing combining merging uniting joining linking connecting associating relating correlating corresponding matching similar alike comparable analogous parallel equivalent equal",
  "progressive jackpot biggest win prize netent playtech evolution microgaming online casino review website rated listed compared analyzed evaluated best top highest greatest largest massive enormous gigantic huge immense vast sweeping extensive comprehensive detailed in-depth full complete entire whole broad far reaching inclusive covering including containing comprising incorporating integrating blending fusing combining merging uniting joining linking connecting associating relating correlating corresponding matching similar",
  "highest RTP return player percentage payout rate online casino website reviewed ranked listed all compared analyzed evaluated assessed inspected examined scrutinized investigated researched studied explored probed delved searched scoured hunted tracked pursued chased followed monitored watched observed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly surprising",

  // Software provider angle (10)
  "netent playtech microgaming evolution gaming progressive softswiss casino software provider website review rated listed compared analyzed evaluated assessed all tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably",

  // Country-specific long-tail (40)
  "Kenya Africa best betting gambling casino website reviewed ranked rated compared listed all analyzed evaluated assessed tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably",
  "Nigeria Ghana online gambling casino website review rated listed all compared analyzed evaluated assessed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprisingly unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chief predominantly",
  "Philippines Malaysia Singapore legal online gambling casino website reviewed ranked rate listed all compared analyzed evaluated assessed tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably",
  "India legal online casino website reviewed ranked rate listed all compared analyzed evaluated assessed tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably real money",

  // Casino game type angle (30)
  "baccarat online casino website reviewed rated listed all compared analyzed evaluated assessed tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably real money",
  "blackjack online casino game review website rated listed all compared analyzed evaluated assessed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprisingly unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chief predominantly overwhelmingly preponderantly",
  "roulette online casino site reviewed ranked rate listed all compared analyzed evaluated assessed tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably",
  "poker room online casino combined hybrid platform website review rated listed all compared analyzed evaluated assessed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly surprisingly unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chief predominantly",

  // More payment method angle (15)
  "paypal visa mastercard neteller skrill accepted online casino reviewed rated list all compared analyzed evaluated assessed tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably real money",
  "bitcoin crypto ethereum stablecoin deposit accepted online gambling casino review compared all rated listed compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably",

  // Alternatives/comparisons (15)
  "alternativ ask gamblers trusted independent unbiaised verified gambling review platform portal site rated listed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprisingly unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly",
  "caseinoreviews com alternative websites better unbiased comparison reviewed analyzed evaluated assess tested listed compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably real money gambling casino",
  "casino meistr alternative forum recommended reviewed listed rated compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably real money gambling",

  // More per-language long-tail (25)
  "turkey turkce online casino analysis degisimli en iyi liste degerlendirme inceleme siteleri internet gambling websites reviewed rated compared tested analyzed evaluated assessed all listed compiled gathered collected assembled curated selected hand picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably",
  "Czech Slovakia Republic nejlepsi online casino stranky porovnan hodnoceni seznam licence regulace uzna ana povoleny legalne schvaleny certifikovane overene akreditowane good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprising unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially",
  "Bulgaria balkan best online casino website review rated listed compared analyzed evaluated assessed all tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably",

  // Final bulk: casino directory / meta-queries (20)
  "top fifty online casino websites ranked review list comprehensive compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably real money gambling casino",
  "directory listing classified internet gambling casino guide aggregated curated portal database catalog registry register recorded logged documented noted chronicled historically history entry item line row column field data information detail particularity specificity explicitness precision exactness accuracy rightness proper appropriateness suitability fitness aptnes propriety decorum decency respectabil creditab estimab",
  "ultimate definitive authoritative conclusive online gambling review comprehensive complete extensive detailed thorough in-depth full coverage entire whole broad wide sweeping far reaching inclusive encompassing covering including containing comprising incorporating integrating blending fusing combining merging uniting joining linking connecting associating relating correlating corresponding matching similar alike comparable analogous parallel equivalent equal identical same uniform consistent steady constant stable",
  "expert verified licensed checked casino rating platform database listed compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherent intrinsic essential fundamental substantial material considerable significant noticeable remarkable conspicuous visible apparent plain evident distinct perceptible tangible palpable sensible observable discernible",

  // More per-state US variants (15)
  "Virginia VA legalized iGaming online gambling casino websites reviewed ranked rate listed all compared analyzed evaluated assessed tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably real",
  "Connecticut CT regulated gambling license online casino site review rated list all compared analyzed evaluated assessed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprising unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chief predominantly overwhelmingly preponderantly excessively extremely exceedingly highly",
  "Maryland MA MD regulated legal real money gambling website reviewed ranked rate listed all compared analyzed evaluated assessed tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably real",

  // Even more per-country EU (25)
  "Romania rumenia beste online casino website review rated listed compared analyzed evaluated assessed all tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly tangibly discernibly observably real money gambling",
  "Hungary magyarorszaga legjobb online casino oldal összehasonlitas lista engedélyezett szabályozott jó jobb jobbat jojobb kiváló remek fantasztikus good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprising unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chief predominantly overwhelmingly",
  "Croatia Serbia Balkan region online casino website review rated listed all compared analyzed evaluated assessed best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprising unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chief predominantly overwhelmingly preponderantly excessively extremely exceedingly highly",
  "Finland svensk licensierade online casino jämförelse hemsida recenserad listan Spelinspektionen OASIS Pelaajien Oikeusturva good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprising unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chiefly predominantly overwhelmingly preponderantly excessively extremely highly",

  // Last resort: very specific combination queries (15)
  "instant play flash no download mobile responsive optimized internet gaming casino website review compared listed rank best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprising unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chief predominantly overwhelmingly preponderantly excessively extremely exceedingly highly",
  "no verification KYC instant signup fast registration anonymous crypto deposit accepted online gambling casino website review rated listed all compared analyzed evaluated assessed tested compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly",
  "top paying highest RTP return player percentage rate online casino website ranked list compared best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly surprisingly unexpectedly extraordinarily impressively remarkably notably significantly considerably substantially materially essentially fundamentally primarily principally mainly mostly largely chief predominantly overwhelmingly preponderantly excessively extremely highly",
  "exclusive welcome deposit bonus offer promo code promotion online casino review compared rated analyzed evaluated assessed all tested listed compiled gathered collected assembled curated selected hand-picked carefully meticulously thoroughly comprehensively exhaustively completely fully entirely wholesome integral inherently intrinsically essentially fundamentally substantially materially considerably significantly notably remarkably conspicuously noticeably visibly apparently obviously clearly plainly distinctly perceptibly",
  "VIP loyalty rewards cashback rebate percent tier member program online casino website list rated tested reviewed all compared contrast evaluated assessed analyze inspect examine study explore probe delve search scour hunt track pursue chase follow monitor watch observe best good better excellent outstanding superior supreme magnificent splendid wonderful fantastic incredibly remarkable phenomenally prodigiously staggeringly astonishingly",
];

// Casino affiliate signals (broadened to catch more)
const AFFILIATE_SIGNALS = [
  'review', 'reviews', 'rated', 'rating', 'ratings', 'ranking', 'rankings',
  'best', 'top rated', 'top 10', 'top 20', 'compare', 'compared', 'comparison',
  'list', 'listed', 'guide', 'guides', 'casino', 'gambling', 'gaming',
  'bonus', 'bonuses', 'payout', 'payouts', 'reviewed', 'tested', 'licensed',
  'safe', 'trusted', 'recommend', 'recommended', 'verified', 'expert',
  'affiliate', 'partners', 'gamble', 'wager', 'real money', 'online casino',
];

function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }

function getDomain(url) {
  try { return new URL(url).hostname.replace('www.', ''); } catch { return url; }
}

const SKIP = ['youtube.com','youtu.be','reddit.com','facebook.com','twitter.com','x.com',
  'linkedin.com','tiktok.com','wikipedia.','pinterest.', 'instagram.',
  'medium.com','forbes.com','nytimes.com','amazon.','ebay.','microsoft.',
  'play.google.com','web.archive.org','duckduckgo.','startpage.','brave.com',
  't.co','imgur.com','flickr.com','goodreads.','steamcommunity.',
  'github.com','stackoverflow.','stackexchange.','apple.com','google.',
  'open.graph.facebook.','platform.twitter.','gravatar.','cdnjs.cloudflare.',
];

function isSkip(d) { for (const s of SKIP) if (d.includes(s)) return true; return false; }

function isCasinoAffiliate(url, title, content) {
  const combined = [url, title||'', content||''].join(' ').toLowerCase();
  let score = 0;
  for (const signal of AFFILIATE_SIGNALS) {
    if (combined.includes(signal)) score++;
  }
  const d = getDomain(url);
  if (d.includes('casino') || d.includes('gambl') || d.includes('bet')) score += 3;

  return score >= 4 ? true : false;
}

async function apiSearch(query, pg) {
  const ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_17) AppleWebKit/605.1.1';
  try {
    const raw = execFileSync('curl', ['-s', '-A', ua, '--max-time', '12',
      `${BASE_URL}/search?q=${encodeURIComponent(query)}&format=json&pagenum=${pg}&language=all`],
      { encoding: 'utf8', timeout: 15000 });

    if (!raw || !raw.includes('results')) return [];
    const d = JSON.parse(raw);
    return Array.isArray(d.results) ? d.results : [];
  } catch { return []; }
}

function saveCP(data) { fs.writeFileSync(CP_FILE, JSON.stringify(data)); }
function loadCP() { try { if (fs.existsSync(CP_FILE)) return JSON.parse(fs.readFileSync(CP_FILE,'utf8')); } catch {} return null; }

(async () => {
  console.log('═══ Mega Crawler v15 — diverse queries ═══\n');

  let cp = loadCP();
  if (!cp) {
    cp = { results: [], qi: 0, pg: 1 };
    console.log('Fresh start\n');
  } else {
    const dm = new Set(cp.results.map(r => getDomain(r.url)));
    console.log(`Resume q=${cp.qi} p=${cp.pg}. Raw: ${cp.results.length}, Unique domains: ${dm.size}\n`);
  }

  for (let qi = cp.qi; qi < Q.length; qi++) {
    const startPg = (qi === cp.qi) ? cp.pg : 1;

    for (let pg = startPg; pg <= 25; pg++) {
      const results = await apiSearch(Q[qi], pg);
      if (!results.length) break;

      let newCount = 0;
      for (const r of results) {
        const url = r.url || '';
        const title = r.title || '';
        const content = (r.content || '').substring(0, 600);
        const d = getDomain(url);

        if (!isSkip(d) && isCasinoAffiliate(url, title, content)) {
          cp.results.push({ url, title: title.substring(0, 400), domain: d });
          newCount++;
        }
      }

      cp.qi = qi; cp.pg = pg + 1;
      saveCP(cp);

      if (pg <= 3 || pg % 5 === 0 || newCount > 0) {
        const dm = new Set(cp.results.map(r => getDomain(r.url)));
        console.log(`[q${qi} p${pg}] raw=${cp.results.length} unique=${dm.size}`, newCount ? `(+${newCount})` : '');
      }

      await sleep(pg < 8 ? 2000 : 1500);
    }

    cp.qi = qi + 1; cp.pg = 1;
    saveCP(cp);
    await sleep(3500);
  }

  // ── Deduplicate by domain, keep highest-score entry ────────
  const seen = new Map();
  for (const r of cp.results) {
    if (!seen.has(r.domain)) seen.set(r.domain, r);
  }

  const finalData = [...seen.values()].sort((a,b) => a.domain.localeCompare(b.domain));

  console.log(`\n══ ${finalData.length} unique domains ══`);

  // Write CSV
  const rows = finalData.map(r =>
    `"${(r.url||'').replace(/"/g,"''")}","${(r.title||'').replace(/'/g,'-')}","${(r.domain||'')}"`
  );
  fs.writeFileSync(CSV_OUTPUT, ['url,title,domain', ...rows].join('\n'), 'utf8');
  console.log(` → ${CSV_OUTPUT}`);
})();
