document.addEventListener('DOMContentLoaded',function(){
  var svg=document.getElementById('atlasSvg');if(!svg)return;
  var NS='http://www.w3.org/2000/svg',CX=320,CY=320;
  var DATA=[
    {cat:'Technology',angle:-90,items:[
      {t:'Digital Marketing & SEO',d:'AI-driven analytics, chatbots and personalised experiences that earn their keep.'},
      {t:'E-learning & Training',d:'Platforms, virtual classrooms and certification programmes for professionals.'},
      {t:'Cloud, AI & ML',d:'Tailored cloud with practical AI on top — chosen for your business, implemented seamlessly.'},
      {t:'Web & Mobile',d:'Custom, responsive builds handled end to end, from first sketch to launch day.'},
      {t:'E-Commerce',d:'Complete storefront, payments and fulfilment — profitability as the metric.'},
      {t:'Online Support',d:'Remote maintenance over the Internet — requests processed live, immediately.'}]},
    {cat:'Consulting',angle:150,items:[
      {t:'Digital Transformation',d:'Technology adoption, process optimisation and change management in the right order.'},
      {t:'Cybersecurity',d:'Innovative protection and advisory that hold up as threats multiply.'},
      {t:'Data & BI',d:'Analytics that turn your data into decisions you can defend.'},
      {t:'Fintech',d:'Banking apps, wallets and blockchain services built to be trusted.'},
      {t:'IoT',d:'Connected devices for manufacturing, healthcare and smart cities.'},
      {t:'AR / VR',d:'Immersive experiences deployed where immersion changes the outcome.'}]},
    {cat:'Outsourcing',angle:30,items:[
      {t:'Application Outsourcing',d:'Teams that plug into your workflow — not the reverse.'},
      {t:'Product Development',d:'Extended capacity with full product ownership through QA and release.'},
      {t:'Managed Contracts',d:'Agreements, SLAs and vendor relationships — handled end to end.'},
      {t:'Support & Helpdesk',d:'Tiered cover across our offices from teams that know your setup.'}]}
  ];
  function el(n,a,p){var e=document.createElementNS(NS,n);for(var k in a)e.setAttribute(k,a[k]);if(p)p.appendChild(e);return e;}
  function pol(a,r){var x=a*Math.PI/180;return [CX+r*Math.cos(x),CY+r*Math.sin(x)];}
  [110,205,275].forEach(function(r){el('circle',{cx:CX,cy:CY,r:r,'class':'a-ring'},svg);});
  var lines=el('g',{},svg),nodes=el('g',{},svg);
  var all=[],alll=[];
  var det={c:document.getElementById('adCat'),t:document.getElementById('adTitle'),b:document.getElementById('adBody')};
  function sel(g,l,cat,it){all.forEach(function(n){n.classList.remove('on');});alll.forEach(function(x){x.classList.remove('hot');});g.classList.add('on');l.classList.add('hot');det.c.textContent=cat;det.t.textContent=it.t;det.b.textContent=it.d;}
  DATA.forEach(function(br){
    var hp=pol(br.angle,110);
    el('line',{x1:CX,y1:CY,x2:hp[0],y2:hp[1],'class':'a-line'},lines);
    var n=br.items.length,spread=n>4?108:72;
    br.items.forEach(function(it,i){
      var a=br.angle-spread/2+(n===1?spread/2:spread*i/(n-1));
      var r=205+(i%2)*52,p2=pol(a,r);
      var ln=el('line',{x1:hp[0],y1:hp[1],x2:p2[0],y2:p2[1],'class':'a-line'},lines);
      var g=el('g',{'class':'nd',tabindex:'0',role:'button','aria-label':br.cat+': '+it.t},nodes);
      el('circle',{cx:p2[0],cy:p2[1],r:20,fill:'transparent',stroke:'none'},g);
      el('circle',{cx:p2[0],cy:p2[1],r:7,'class':'v'},g);
      var c=Math.cos(a*Math.PI/180),sn=Math.sin(a*Math.PI/180);
      var anc=c>0.35?'start':(c<-0.35?'end':'middle');
      var dy=sn>0.5?22:(sn<-0.5?-14:4),dx=anc==='start'?13:(anc==='end'?-13:0);
      el('text',{x:p2[0]+dx,y:p2[1]+dy,'text-anchor':anc},g).textContent=it.t;
      function act(){sel(g,ln,br.cat,it);}
      g.addEventListener('click',act);
      g.addEventListener('keydown',function(ev){if(ev.key==='Enter'||ev.key===' '){ev.preventDefault();act();}});
      all.push(g);alll.push(ln);
    });
    var hub=el('g',{'class':'hub'},nodes);
    el('circle',{cx:hp[0],cy:hp[1],r:15},hub);
    var hc=Math.cos(br.angle*Math.PI/180);
    var ha=hc>0.35?'start':(hc<-0.35?'end':'middle');
    var hdy=Math.sin(br.angle*Math.PI/180)>0.5?36:-26;
    el('text',{x:hp[0]+(ha==='start'?22:ha==='end'?-22:0),y:hp[1]+(ha==='middle'?hdy:5),'text-anchor':ha},hub).textContent=br.cat;
  });
  el('circle',{cx:CX,cy:CY,r:34,'class':'pulse'},svg);
  el('circle',{cx:CX,cy:CY,r:30,fill:'#241B1C',stroke:'#9E0000','stroke-width':'1.4'},svg);
  el('image',{href:'assets/brand/logo-e-platform.svg?v=11',x:CX-15,y:CY-15,width:30,height:30},svg);
});
