(()=>{'use strict';const $=s=>document.querySelector(s),money=new Intl.NumberFormat('pt-BR',{style:'currency',currency:'BRL'});const nav=$('.nav'),menu=$('.menu');menu.addEventListener('click',()=>nav.classList.toggle('open'));document.querySelectorAll('.links a').forEach(a=>a.addEventListener('click',()=>nav.classList.remove('open')));const observer=new IntersectionObserver(es=>es.forEach(e=>{if(e.isIntersecting){e.target.classList.add('visible');observer.unobserve(e.target)}}),{threshold:.12});document.querySelectorAll('.reveal').forEach(e=>observer.observe(e));const form=$('#form'),initial=$('#initial'),monthly=$('#monthly'),rate=$('#rate'),months=$('#months'),invested=$('#invested'),earnings=$('#earnings'),future=$('#future'),canvas=$('#growth'),ctx=canvas.getContext('2d');function simulate(){const start=Math.max(0,+initial.value||0),aporte=Math.max(0,+monthly.value||0),taxa=Math.max(0,+rate.value||0)/100,n=Math.min(600,Math.max(1,+months.value||1));let saldo=start,data=[saldo];for(let i=0;i{const y=10+ch*(1-v);ctx.beginPath();ctx.moveTo(pad,y);ctx.lineTo(w-pad,y);ctx.stroke()});ctx.setLineDash([]);const pts=data.map((v,i)=>({x:pad+i/(data.length-1)*(w-2*pad),y:10+ch-(v/max)*ch}));const g=ctx.createLinearGradient(0,10,0,h);g.addColorStop(0,'rgba(37,99,235,.24)');g.addColorStop(1,'rgba(37,99,235,0)');ctx.beginPath();ctx.moveTo(pts[0].x,h-20);pts.forEach(p=>ctx.lineTo(p.x,p.y));ctx.lineTo(pts.at(-1).x,h-20);ctx.closePath();ctx.fillStyle=g;ctx.fill();ctx.beginPath();pts.forEach((p,i)=>i?ctx.lineTo(p.x,p.y):ctx.moveTo(p.x,p.y));ctx.strokeStyle='#2563eb';ctx.lineWidth=3;ctx.stroke();const p=pts.at(-1);ctx.beginPath();ctx.arc(p.x,p.y,4,0,Math.PI*2);ctx.fillStyle='#2563eb';ctx.fill()}form.addEventListener('submit',e=>{e.preventDefault();simulate()});[initial,monthly,rate,months].forEach(x=>x.addEventListener('input',simulate));addEventListener('resize',simulate);simulate();let pct=64;$('#advance').addEventListener('click',()=>{pct=pct>=100?10:Math.min(100,pct+5);$('#progress').style.width=pct+'%';$('#percent').textContent=pct+'%'});$('#year').textContent=new Date().getFullYear()})();