function askAI(q){ if(!q||!q.trim())return; setAiAnswering(true); setAiAnswer(""); const r0=result; const ctx="Player: "+r0.skillLevel+", "+r0.skillScore+"/5, racket "+(r0.rackets&&r0.rackets[0]?r0.rackets[0].name:"unknown")+", strings "+r0.specs.stringType.value+", tension "+r0.specs.tension.value+", budget "+r0.priceRange+". Q: "+q; const prompt="Tennis equipment expert. Answer in 2-3 sentences using this player profile. Be specific. "+ctx; fetch("https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key="+GEMINI_KEY,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contents:[{parts:[{text:prompt}]}]})}) .then(function(res){return res.ok?res.json():null;}) .then(function(d){setAiAnswer(d&&d.candidates&&d.candidates[0]&&d.candidates[0].content&&d.candidates[0].content.parts&&d.candidates[0].content.parts[0]?d.candidates[0].content.parts[0].text.trim():"Sorry, no answer.");setAiAnswering(false);}) .catch(function(){setAiAnswer("Sorry, could not connect.");setAiAnswering(false);}); }