const x=window.__IDENTIFY_SYSTEMS__||{},g=window.__IDENTIFY_NAMES__||[],h=window.__IDENTIFY_BANDS__||[],b=window.__IDENTIFY_ANGELS__||[];document.getElementById("identify-submit").addEventListener("click",f);document.getElementById("identify-input").addEventListener("keydown",o=>{o.key==="Enter"&&f()});const u={};for(const o of h)u[o.number]=o.name;function E(o){const e=new Array(72).fill(0),i=o.trim(),s=parseInt(i,10);if(!isNaN(s)&&i===s.toString()){const c=i.split("").map(Number),d=c.reduce((a,l)=>a+l,0),m=c.reduce((a,l)=>a*l,1),p=d*m%72;e[p]=.08+d/72*.02;const y=b.find(a=>a.n===s);if(y){const a=y.s2%72;e[a]=(e[a]||0)+.05;const l=y.s%72;e[l]=(e[l]||0)+.03}if(i.length>1&&c.every(a=>a===c[0])){const a=c[0];for(let l=0;l<72;l++)(l+1)%a===0&&(e[l]+=.01)}return{vec:e,type:"angel number",detail:`Sum: ${d}, Product: ${m}`}}const n=[...i];for(const c of n){const d=c.codePointAt(0),m=(d*7+13)%72;e[m]+=.06+d%100/100*.04,m>0&&(e[m-1]+=.02),m<71&&(e[m+1]+=.02);const y=Math.floor(d/256)%6*12+d%12;y<72&&(e[y]+=.03)}const r=Math.max(...e,.001);for(let c=0;c<72;c++)e[c]/=r;const t=n[0].codePointAt(0);return{vec:e,type:"character",detail:`Codepoint: U+${t.toString(16).toUpperCase().padStart(4,"0")} (${t})`}}function v(o){let e=0,i=0;for(let s=0;s<72;s++)s<36?i+=o[s]:e+=o[s];return i>0?e/i:0}function I(o,e){let i=0,s=0,n=0;for(let t=0;t<72;t++)i+=o[t]*e[t],s+=o[t]*o[t],n+=e[t]*e[t];const r=Math.sqrt(s)*Math.sqrt(n);return r>0?i/r:0}function $(o,e=5){const i=[];for(const s of g){const n=x[s];if(!n)continue;const r=I(o,n.vector);i.push({name:s,similarity:r,cz:n.cz,category:n.category})}return i.sort((s,n)=>n.similarity-s.similarity),i.slice(0,e)}function C(o){const e=document.getElementById("identify-heatmap");e.innerHTML="";const i=Math.max(...o,.001),s=[{start:1,end:12,color:"#ff6b6b"},{start:13,end:24,color:"#8844ff"},{start:25,end:36,color:"#44ccff"},{start:37,end:48,color:"#44ff88"},{start:49,end:60,color:"#ffaa44"},{start:61,end:72,color:"#ffdd66"}];for(let n=0;n<72;n++){const r=o[n]/i,t=document.createElement("div");let c="#333";for(const d of s)if(n+1>=d.start&&n+1<=d.end){c=d.color;break}t.style.background=c,t.style.opacity=Math.max(.05,r),t.style.width="auto",t.style.minWidth="2px",t.style.height="24px",t.style.flex="1 1 auto",t.style.maxWidth="12px",t.style.borderRadius="2px",t.style.cursor="pointer",t.title=`Band ${n+1}: ${o[n].toFixed(5)} (${u[n+1]||""})`,t.addEventListener("mouseenter",()=>{t.style.transform="scaleY(1.3)",t.style.zIndex="5"}),t.addEventListener("mouseleave",()=>{t.style.transform="",t.style.zIndex=""}),e.appendChild(t)}}function _(o){const e=document.getElementById("cz-spectrum-bar"),i=document.getElementById("cz-label"),s=.67,n=4.16,r=Math.max(0,Math.min(1,(o-s)/(n-s)));e.innerHTML="";const t=document.createElement("div");t.style.position="absolute",t.style.left=`calc(${r*100}% - 8px)`,t.style.top="-8px",t.style.width="0",t.style.height="0",t.style.borderLeft="8px solid transparent",t.style.borderRight="8px solid transparent",t.style.borderTop="12px solid white",t.style.filter="drop-shadow(0 0 6px rgba(255,255,255,0.5))",e.style.position="relative",e.appendChild(t);const c=document.createElement("div");c.style.display="flex",c.style.justifyContent="space-between",c.style.fontSize="0.7rem",c.style.color="var(--color-text-muted)",c.style.marginTop="4px",c.innerHTML=`<span>${s.toFixed(2)} (Pure Z)</span><span>${n.toFixed(2)} (Pure C)</span>`,e.appendChild(c),i.textContent=`CZ Ratio: ${o.toFixed(4)} — Position: ${(r*100).toFixed(1)}% toward C-domain`}function w(o){const e=document.getElementById("identify-matches");e.innerHTML="";const i=["#ffd700","#c0c0c0","#cd7f32","#9090b0","#606080"],s=["🥇","🥈","🥉","4th","5th"];for(let n=0;n<o.length;n++){const r=o[n],t=document.createElement("div");t.className="glass-card glass-card--compact match-card",t.style.borderLeft=`3px solid ${i[n]}`,t.innerHTML=`
        <div style="display: flex; justify-content: space-between; align-items: center; gap: var(--spacing-md); flex-wrap: wrap;">
          <div>
            <strong style="font-size: 1.1rem;">${s[n]} ${r.name}</strong>
            <span class="match-badge" style="background: ${i[n]}33; color: ${i[n]};">
              ${(r.similarity*100).toFixed(1)}% match
            </span>
          </div>
          <div style="text-align: right; font-size: 0.85rem; color: var(--color-text-muted); font-family: var(--font-mono);">
            CZ: ${r.cz.toFixed(3)} | ${r.category}
          </div>
        </div>
        <div class="match-bar-container" style="margin-top: var(--spacing-sm);">
          <div class="match-bar" style="width: ${(r.similarity*100).toFixed(1)}%;"></div>
        </div>
      `,e.appendChild(t)}}function f(){const o=document.getElementById("identify-input").value,e=document.getElementById("identify-results"),i=document.getElementById("identify-empty");if(!o){e.style.display="none",i.style.display="block";return}const{vec:s,type:n,detail:r}=E(o);document.getElementById("identify-input-type").textContent=`Detected: ${n} — ${r}`,document.getElementById("identify-vector-desc").textContent=`72-band vector computed from "${o}" (${n})`,C(s);const t=v(s);_(t);const c=$(s,5);w(c),e.style.display="block",i.style.display="none"}document.addEventListener("DOMContentLoaded",()=>{document.getElementById("identify-input").addEventListener("keydown",o=>{o.key==="Enter"&&f()})});
