solwatch 0.1.18

Real-data Solana memecoin auditor — rug/freeze/bundle scanner with a 0-100 risk score, plain-English flags, and a live dashboard. Sister tool to Hoodwatch.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
<!doctype html>
<html lang="en" data-theme="void">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Solwatch — Solana memecoin auditor</title>
<style>
  :root {
    --bg:#080b10; --panel:#0e141c; --panel2:#121a24; --line:#1d2a38; --line2:#16202c;
    --ink:#e8eef5; --muted:#8ea3b8; --dim:#5a6b7d;
    --cyan:#39d0d8; --cyan2:#2aa7b0; --cyan-dim:rgba(57,208,216,.14);
    --good:#4ade80; --fair:#a3e635; --warn:#fbbf24; --danger:#f87171; --crit:#ef4444;
    --shadow:0 8px 30px rgba(0,0,0,.4);
    --mono:ui-monospace,'JetBrains Mono','Cascadia Code',Menlo,Consolas,monospace;
    --sans:ui-sans-serif,system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;
  }
  * { box-sizing:border-box; }
  html,body { height:100%; }
  body { margin:0; color:var(--ink); font:15px/1.5 var(--sans); -webkit-font-smoothing:antialiased;
    background:
      radial-gradient(1400px 800px at 75% -10%, #0d1620 0%, transparent 60%),
      var(--bg);  zoom: 1.15; }
  /* faint instrument grid on the page floor */
  body::before { content:''; position:fixed; inset:0; pointer-events:none; opacity:.5; z-index:0;
    background:
      linear-gradient(var(--line2) 1px, transparent 1px) 0 0/100% 48px,
      linear-gradient(90deg, var(--line2) 1px, transparent 1px) 0 0/48px 100%;
    mask-image:radial-gradient(1200px 700px at 50% 0%, rgba(0,0,0,.5), transparent 75%); }
  a { color:var(--cyan); text-decoration:none; }
  a:hover { text-decoration:underline; }
  .wrap { position:relative; z-index:1; width:100%; margin:0 auto; padding:18px clamp(14px,2.5vw,36px) 70px; }

  /* ── topbar ── */
  .topbar { display:flex; align-items:center; gap:14px; flex-wrap:wrap; padding:10px 14px;
    background:var(--panel); border:1px solid var(--line); border-radius:12px; margin-bottom:14px; }
  .brand { display:flex; align-items:center; gap:10px; font-weight:800; letter-spacing:.4px; white-space:nowrap; }
  .brand .logo { font-size:20px; }
  .brand b { color:var(--cyan); }
  .brand .chain { font:12px var(--mono); color:var(--dim); border:1px solid var(--line); padding:2px 8px; border-radius:20px; }
  .searchbar { display:flex; gap:8px; flex:1; min-width:260px; }
  .searchbar input { flex:1; min-width:180px; background:var(--bg); border:1px solid var(--line); color:var(--ink);
    padding:9px 12px; border-radius:9px; font:14px var(--mono); outline:none; }
  .searchbar input:focus-visible { border-color:var(--cyan2); box-shadow:0 0 0 2px var(--cyan-dim); }
  button { background:linear-gradient(180deg,var(--cyan),var(--cyan2)); color:#04252a; border:0; font-weight:700;
    padding:9px 16px; border-radius:9px; cursor:pointer; font-size:14px; font-family:var(--sans); }
  button.ghost { background:var(--panel2); color:var(--muted); border:1px solid var(--line); font-weight:600; }
  button:disabled { opacity:.5; cursor:wait; }
  button:focus-visible { outline:2px solid var(--cyan); outline-offset:2px; }
  button:active { transform:scale(.98); }
  .chips { display:flex; gap:8px; flex-wrap:wrap; margin:0 0 14px; }
  .chip { background:var(--panel); border:1px solid var(--line); color:var(--muted); padding:5px 12px; border-radius:20px;
    font:12px var(--mono); cursor:pointer; }
  .chip:hover { border-color:var(--cyan2); color:var(--ink); }

  /* ── HUD grid ── */
  .hud { display:grid; grid-template-columns:repeat(12,1fr); gap:12px; }
  .panel { background:var(--panel); border:1px solid var(--line); border-radius:14px; padding:16px 18px;
    min-width:0; position:relative; overflow:hidden; }
  .panel > h3 { margin:0 0 12px; font:700 12px var(--sans); text-transform:uppercase; letter-spacing:1.4px; color:var(--cyan);
    display:flex; align-items:center; gap:8px; }
  .panel > h3::after { content:''; flex:1; height:1px; background:linear-gradient(90deg,var(--line),transparent); }
  .panel .sub { color:var(--dim); font-size:14px; margin:-8px 0 10px; }
  .c12{grid-column:span 12} .c8{grid-column:span 8} .c6{grid-column:span 6} .c4{grid-column:span 4}
  @media (max-width:1100px){ .c8,.c6,.c4{grid-column:span 12} .c6.keep{grid-column:span 6} }
  @media (max-width:700px){ .c6.keep{grid-column:span 12} }

  /* ── header panel: ring + identity + verdict ── */
  .head { display:flex; align-items:center; gap:clamp(16px,3vw,34px); flex-wrap:wrap; }
  .ringbox { position:relative; width:118px; height:118px; flex:none; }
  .ringbox canvas { width:118px; height:118px; display:block; }
  .ringbox .rv { position:absolute; inset:0; display:grid; place-items:center; text-align:center; }
  .ringbox .rv b { display:block; font:800 30px var(--mono); line-height:1; }
  .ringbox .rv span { font:11.5px var(--sans); color:var(--dim); text-transform:uppercase; letter-spacing:1px; }
  .idc { flex:1; min-width:230px; }
  .sym { font-size:25px; font-weight:800; letter-spacing:.3px; }
  .nm { color:var(--muted); font-size:14px; }
  .addr { display:flex; align-items:center; gap:8px; font:12px var(--mono); color:var(--muted); margin-top:6px; flex-wrap:wrap; }
  .addr code { word-break:break-all; }
  .iconbtn { background:none; border:1px solid var(--line); color:var(--muted); border-radius:6px; padding:2px 8px;
    font:11.5px var(--mono); cursor:pointer; }
  .iconbtn:hover { color:var(--ink); border-color:var(--cyan2); }
  .verdict { padding:10px 20px; border-radius:11px; font-weight:800; font-size:16px; letter-spacing:1px; flex:none;
    border:1px solid; background:var(--panel2); text-shadow:0 0 18px currentColor; }
  .scanned { font:11.5px var(--mono); color:var(--dim); width:100%; margin-top:2px; }
  .warnstrip { margin-top:10px; padding:8px 12px; border:1px solid rgba(251,191,36,.35); background:rgba(251,191,36,.07);
    border-radius:9px; color:var(--warn); font-size:13px; width:100%; }

  /* ── instrument tiles ── */
  .tiles { display:grid; grid-template-columns:repeat(auto-fit,minmax(148px,1fr)); gap:10px; }
  .tile { background:var(--panel2); border:1px solid var(--line); border-radius:11px; padding:10px 12px 12px; min-width:0; }
  .tile .l { font:11.5px var(--sans); text-transform:uppercase; letter-spacing:1px; color:var(--dim); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .tile .v { font:700 18px var(--mono); margin-top:3px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .tile .bar { height:3px; border-radius:2px; background:var(--line); margin-top:8px; overflow:hidden; }
  .tile .bar i { display:block; height:100%; border-radius:2px; }

  /* ── findings ── */
  .sevchips { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:10px; }
  .sevchip { font:12px var(--mono); padding:4px 10px; border-radius:16px; border:1px solid var(--line);
    background:var(--panel2); color:var(--muted); cursor:pointer; user-select:none; }
  .sevchip[data-on="1"] { color:var(--ink); border-color:currentColor; }
  .flaglist { max-height:430px; overflow-y:auto; padding-right:4px; }
  .flag { display:flex; gap:11px; padding:9px 10px; border-radius:9px; border-left:3px solid var(--line); margin-bottom:6px;
    background:var(--panel2); }
  .flag .fico { flex:none; width:18px; text-align:center; font-size:14px; padding-top:1px; }
  .flag .ft { font-weight:700; font-size:14px; }
  .flag .fw { float:right; font:11px var(--mono); color:var(--dim); margin-left:8px; }
  .flag .fd { color:var(--muted); font-size:14px; line-height:1.45; }

  /* ── charts / viz ── */
  .vizrow { display:flex; gap:18px; align-items:center; flex-wrap:wrap; }
  .kv { display:flex; flex-wrap:wrap; gap:6px 20px; color:var(--muted); font-size:14px; }
  .kv span b { color:var(--ink); font-family:var(--mono); }
  .hbar { margin:6px 0 2px; }
  .hbar .row { display:flex; align-items:center; gap:10px; margin-bottom:5px; }
  .hbar .lb { width:124px; flex:none; font:11.5px var(--mono); color:var(--muted); text-align:right; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .hbar .tr { flex:1; height:14px; background:var(--panel2); border-radius:4px; overflow:hidden; display:flex; }
  .hbar .tr i { height:100%; }
  .hbar .vl { width:62px; flex:none; font:12px var(--mono); color:var(--ink); }
  .stack { display:flex; height:26px; border-radius:7px; overflow:hidden; background:var(--panel2); border:1px solid var(--line); }
  .stack i { height:100%; border-right:2px solid var(--panel); min-width:2px; cursor:default; transition:filter .15s; }
  .stack i:hover { filter:brightness(1.35); }
  .legend { display:flex; gap:5px 16px; flex-wrap:wrap; margin-top:8px; font:12px var(--mono); color:var(--muted); }
  .legend .sw { display:inline-block; width:9px; height:9px; border-radius:2px; margin-right:5px; vertical-align:-1px; }
  table.tb { width:100%; border-collapse:collapse; font:13px var(--mono); }
  table.tb th { text-align:left; color:var(--dim); font:11.5px var(--sans); text-transform:uppercase; letter-spacing:.8px;
    padding:4px 8px; border-bottom:1px solid var(--line); }
  table.tb td { padding:5px 8px; border-bottom:1px solid var(--line2); }
  .checkgrid { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:8px; }
  .check { display:flex; gap:9px; align-items:center; background:var(--panel2); border:1px solid var(--line);
    border-radius:9px; padding:8px 11px; font-size:13px; }
  .check .st { font-size:14px; }
  .check .cl { color:var(--muted); }
  .check b { display:block; font-size:14px; }
  .dfn { display:inline-block; font:11.5px var(--mono); border:1px solid var(--line); color:var(--warn);
    border-radius:5px; padding:1px 7px; margin:2px 3px 0 0; }

  /* donut + radar boxes */
  .donutbox { display:flex; gap:16px; align-items:center; }
  .donutbox canvas { width:132px; height:132px; flex:none; }
  canvas.radar { width:100%; height:250px; display:block; }

  /* ── wallet links ── */
  .cltable-dot { display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:6px; vertical-align:-1px; }
  .clleg { color:var(--dim); font-size:14px; margin-top:6px; }
  .cllimits { margin:6px 0 0 0; padding-left:18px; color:var(--dim); font-size:13.5px; }
  .cllimits li { margin:3px 0; }
  .clwallets { display:flex; flex-wrap:wrap; align-items:center; gap:6px; margin:4px 0; }
  .clwallets .clwlabel { color:var(--dim); font:12px var(--mono); min-width:26px; }
  .clwallets a { font:12px var(--mono); color:var(--cyan); text-decoration:none;
    border:1px solid var(--line); border-radius:6px; padding:2px 6px; }
  .clwallets a:hover { border-color:var(--cyan2); color:var(--ink); }

  /* shared tooltip */
  #tip { position:fixed; z-index:50; pointer-events:none; background:#050a0f; border:1px solid var(--cyan2);
    color:var(--ink); font:12px var(--mono); padding:6px 9px; border-radius:7px; box-shadow:var(--shadow);
    display:none; max-width:280px; }

  .foot { color:var(--dim); font-size:13px; padding:14px 4px 0; }
  .empty { color:var(--muted); text-align:center; padding:60px 20px; }
  .spinner { display:inline-block; width:15px; height:15px; border:2px solid var(--line); border-top-color:var(--cyan);
    border-radius:50%; animation:spin .7s linear infinite; vertical-align:-3px; }
  @keyframes spin { to { transform:rotate(360deg); } }
  .feed { margin-top:22px; }
  .feed h2 { font:700 12px var(--sans); color:var(--muted); text-transform:uppercase; letter-spacing:1.2px; margin:0 0 10px; }
  .lrow { display:flex; justify-content:space-between; gap:10px; padding:9px 14px; background:var(--panel); border:1px solid var(--line);
    border-radius:10px; margin-bottom:7px; font:13px var(--mono); cursor:pointer; }
  .lrow:hover { border-color:var(--cyan2); }
  .lrow .a { color:var(--cyan); }
  .reveal { opacity:0; translate:0 10px; animation:reveal .45s ease-out forwards; }
  @keyframes reveal { to { opacity:1; translate:0 0; } }
  @media (prefers-reduced-motion:reduce){ *,*::before,*::after{ animation-duration:.01ms!important; animation-delay:0ms!important; transition-duration:.01ms!important; } }
</style>
</head>
<body>
<div class="wrap">
  <div class="topbar">
    <div class="brand"><span class="logo">☀️</span><span><b>SOLWATCH</b></span><span class="chain">SOLANA</span></div>
    <div class="searchbar">
      <input id="addr" placeholder="token mint address on Solana" spellcheck="false" aria-label="token address" />
      <button id="go">Audit</button>
      <button class="ghost" id="scan">New launches</button>
    </div>
  </div>
  <div class="chips" id="chips"></div>

  <div id="out"><div class="empty">Enter a token mint, tap a reference token, or pull the latest launchpad launches.</div></div>
  <div class="feed" id="reports"></div>
  <div class="feed" id="feed"></div>
</div>
<div id="tip" role="tooltip"></div>
<script>
'use strict';
/* ───────────────────────── constants + utils ───────────────────────── */
const REF = [
  ['BONK','DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263'],
  ['WIF','EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm'],
  ['JUP','JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN'],
];
const VCOLOR = { AVOID:'var(--crit)', HIGH_RISK:'var(--danger)', CAUTION:'var(--warn)', FAIR:'var(--fair)', LOW_RISK:'var(--good)', UNKNOWN:'var(--muted)' };
const VHEX   = { AVOID:'#ef4444', HIGH_RISK:'#f87171', CAUTION:'#fbbf24', FAIR:'#a3e635', LOW_RISK:'#4ade80', UNKNOWN:'#8ea3b8' };
const SEV = { critical:['🛑','var(--crit)'], danger:['🔴','var(--danger)'], warning:['⚠️','var(--warn)'], info:['ℹ️','var(--muted)'], good:['','var(--good)'] };
const SEVORD = ['critical','danger','warning','info','good'];
/* categorical palette — CVD-validated (dark surface); identity also carried by table dots + click panel */
const CLCOLORS = ['hsl(184 70% 62%)','hsl(0 70% 62%)','hsl(218 70% 62%)','hsl(44 70% 62%)','hsl(254 70% 62%)','hsl(142 70% 62%)','hsl(324 70% 62%)','hsl(26 70% 62%)'];
const clA = (c,a) => c.replace(')',' / '+a+')');
const EXPLORER = 'https://solscan.io/account/';
const REDUCED = matchMedia('(prefers-reduced-motion: reduce)').matches;
const usd = n => n==null ? '' : '$'+Number(n).toLocaleString('en-US',{maximumFractionDigits:0});
const pct = n => n==null ? '' : (Math.round(n*100)/100)+'%';
const el = h => { const d=document.createElement('div'); d.innerHTML=h; return d.firstElementChild; };
function esc(s){ return String(s==null?'':s).replace(/[&<>"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c])); }
const shortA = a => a && a.length>14 ? a.slice(0,8)+''+a.slice(-4) : (a||'');
const css = v => getComputedStyle(document.body).getPropertyValue('--'+v).trim() || v;

/* shared tooltip */
const tip = document.getElementById('tip');
function tipShow(html, x, y){ tip.innerHTML=html; tip.style.display='block';
  const r=tip.getBoundingClientRect();
  tip.style.left=Math.min(x+14, innerWidth-r.width-8)+'px';
  tip.style.top=Math.min(y+14, innerHeight-r.height-8)+'px'; }
function tipHide(){ tip.style.display='none'; }
function hookTips(root){
  root.querySelectorAll('[data-tip]').forEach(n => {
    n.addEventListener('pointermove', ev => tipShow(n.dataset.tip, ev.clientX, ev.clientY));
    n.addEventListener('pointerleave', tipHide);
  });
}

/* HiDPI canvas prep */
function prep(cv){ const dpr=devicePixelRatio||1, r=cv.getBoundingClientRect();
  cv.width=r.width*dpr; cv.height=r.height*dpr;
  const ctx=cv.getContext('2d'); ctx.setTransform(dpr,0,0,dpr,0,0); return [ctx, r.width, r.height]; }

const chips = document.getElementById('chips');
REF.forEach(([s,a]) => { const c=el('<div class="chip">'+s+'</div>'); c.onclick=()=>{ document.getElementById('addr').value=a; audit(a); }; chips.appendChild(c); });

/* ───────────────────────── audit fetch + render root ───────────────────────── */
async function audit(a) {
  const out = document.getElementById('out');
  out.innerHTML = '<div class="empty"><span class="spinner"></span> Auditing '+esc(a.slice(0,10))+'… (live chain — full pass, ~40-70s)</div>';
  try {
    const r = await fetch('/api/audit?address='+encodeURIComponent(a)).then(x=>x.json());
    if (r && r.__rokha_pending) { out.innerHTML='<div class="empty">⧗ Sent to Rokha — running on your allowance; this panel refreshes with the result.</div>'; return; }
    if (r.error) { out.innerHTML='<div class="empty">Error: '+esc(r.error)+'</div>'; return; }
    out.innerHTML='';
    out.appendChild(renderHud(r));
  } catch(e) { out.innerHTML='<div class="empty">Error: '+esc(e.message)+'</div>'; }
}

function renderHud(r) {
  const g = VHEX[r.verdict]||VHEX.UNKNOWN;
  const s = r.sections||{};
  const root = el('<div class="hud"></div>');

  root.appendChild(headerPanel(r, g));
  root.appendChild(tilesPanel(r, s));

  const radar = panel('c4','Risk surface','deduction weight per axis — full ring = hard-fail territory');
  const radarCv = el('<canvas class="radar" aria-label="risk radar"></canvas>');
  radar.appendChild(radarCv); root.appendChild(radar);

  root.appendChild(findingsPanel(r));

  const bu = s.bundles;
  if (bu) root.appendChild(launchPanel(bu, r.token));
  if (s.holders) root.appendChild(holdersPanel(s.holders, s.cluster));
  if (s.liquidity) root.appendChild(liquidityPanel(s.liquidity, s.market));
  root.appendChild(authoritiesPanel(s.mint, s.deployer, s.copycats));

  const cl = s.cluster;
  if (cl && cl.schema) { try { root.appendChild(clusterPanel(cl)); } catch(e){ console.warn('cluster render', e); } }

  root.appendChild(el('<div class="c12 foot">Scanned '+esc(r.scannedAt||'')+' · Solwatch · real on-chain data · a snapshot of the chain at scan time — flags and score move as the chain moves (e.g. a revoked authority deletes its flag) · not financial advice'+
    (r.rokhaUrl?' · <a href="'+esc(r.rokhaUrl)+'" target="_blank" rel="noopener">view in Rokha ↗</a>':'')+'</div>'));

  /* draw after layout */
  requestAnimationFrame(() => {
    drawRing(root.querySelector('.ringcv'), r.score, g);
    drawRadar(radarCv, radarAxes(r));
    root.querySelectorAll('canvas.donut').forEach(cv => drawDonut(cv));
    hookTips(root);
  });
  let i=0; root.querySelectorAll('.panel').forEach(p => { p.classList.add('reveal'); p.style.animationDelay=Math.min(240,i++*40)+'ms'; });
  return root;
}
function panel(span, title, sub){ const p=el('<div class="panel '+span+'"></div>');
  p.appendChild(el('<h3>'+esc(title)+'</h3>'));
  if (sub) p.appendChild(el('<div class="sub">'+esc(sub)+'</div>'));
  return p; }

/* ───────────────────────── header + tiles ───────────────────────── */
function headerPanel(r, g){
  const t=r.token||{};
  const p=el('<div class="panel c12"></div>');
  p.style.boxShadow='inset 0 1px 0 '+g+'33';
  const head=el('<div class="head"></div>');
  head.appendChild(el('<div class="ringbox"><canvas class="ringcv" width="118" height="118"></canvas>'+
    '<div class="rv"><div><b style="color:'+g+'">'+r.score+'</b><span>/ 100</span></div></div></div>'));
  head.appendChild(el('<div class="idc"><div class="sym">$'+esc(t.symbol||'?')+'</div><div class="nm">'+esc(t.name||'unknown')+'</div>'+
    '<div class="addr"><code>'+esc(r.address)+'</code>'+
    '<button class="iconbtn" data-copy="'+esc(r.address)+'">copy</button>'+
    '<a href="'+EXPLORER+encodeURIComponent(r.address)+'" target="_blank" rel="noopener">explorer ↗</a></div></div>'));
  head.appendChild(el('<div class="verdict" style="color:'+g+';border-color:'+g+'">'+esc((r.verdict||'').replace('_',' '))+'</div>'));
  if ((r.warnings||[]).length)
    head.appendChild(el('<div class="warnstrip">⚠ '+r.warnings.map(esc).join(' · ')+' — affected checks did NOT run; unknown ≠ safe.</div>'));
  p.appendChild(head);
  p.querySelectorAll('[data-copy]').forEach(b => b.onclick = async () => {
    try { await navigator.clipboard.writeText(b.dataset.copy); b.textContent='copied'; setTimeout(()=>b.textContent='copy',1200); } catch(_){}
  });
  return p;
}
function tone(t){ return t==='bad'?css('danger'):t==='warn'?css('warn'):t==='ok'?css('good'):css('cyan'); }
function tilesPanel(r, s){
  const t=r.token||{}, bu=s.bundles||{}, lq=s.liquidity||{}, ho=s.holders||{}, mk=s.market||{}, ec=(s.cluster||{}).effective_concentration||{};
  const p=panel('c12','Instruments');
  const grid=el('<div class="tiles"></div>');
  const add=(l,v,frac,tn,tipTxt)=>{ if(v==null||v==='')return;
    grid.appendChild(el('<div class="tile"'+(tipTxt?' data-tip="'+esc(tipTxt)+'"':'')+'><div class="l">'+l+'</div><div class="v">'+v+'</div>'+
      (frac!=null?'<div class="bar"><i style="width:'+Math.min(100,Math.max(2,frac))+'%;background:'+tone(tn)+'"></i></div>':'')+'</div>')); };
  add('Market cap', usd(t.marketCapUsd));
  add('24h volume', usd(t.volume24hUsd));
  add('Holders', t.holdersCount!=null?t.holdersCount.toLocaleString():null);
  add('Liquidity', lq.totalLiquidityUsd!=null?usd(lq.totalLiquidityUsd):null, null, null);
  if (lq.liqToFdvPct!=null) add('Liq / FDV', pct(lq.liqToFdvPct), Math.min(100,lq.liqToFdvPct*2), lq.liqToFdvPct<2?'bad':lq.liqToFdvPct<8?'warn':'ok', 'liquidity as a share of fully-diluted value — low = the price is mostly on paper');
  if (bu.analyzed && bu.pctSupplySniped!=null) add('Supply sniped', pct(bu.pctSupplySniped), bu.pctSupplySniped, bu.pctSupplySniped>=40?'bad':bu.pctSupplySniped>=15?'warn':'ok', 'share of supply bought in the launch window');
  if (bu.analyzed && bu.pctDevAllocation!=null) add('Dev allocation', pct(bu.pctDevAllocation), bu.pctDevAllocation, bu.pctDevAllocation>=20?'bad':bu.pctDevAllocation>=5?'warn':'ok', 'supply the dev wallet took at launch');
  if (mk.organicScore!=null) add('Organic score', mk.organicScore+(mk.organicScoreLabel?' ('+mk.organicScoreLabel+')':''), mk.organicScore, mk.organicScore<30?'bad':mk.organicScore<60?'warn':'ok', "Jupiter's bot-vs-organic volume heuristic");
  if (bu.analyzed && bu.pctSnipersStillHold!=null) add('Snipers hold', pct(bu.pctSnipersStillHold), bu.pctSnipersStillHold, bu.pctSnipersStillHold>=20?'bad':bu.pctSnipersStillHold>=5?'warn':'ok', 'what the launch snipers STILL hold now');
  if (ho.top10Pct!=null) add('Top-10 wallets', pct(ho.top10Pct), ho.top10Pct, ho.top10Pct>=60?'bad':ho.top10Pct>=30?'warn':'ok', 'raw per-wallet concentration (pools/burn excluded)');
  if (ec.top10_entity_pct_floor!=null) add('Top-10 entities', '\u2265'+pct(ec.top10_entity_pct_floor), ec.top10_entity_pct_floor, ec.top10_entity_pct_floor>=60?'bad':ec.top10_entity_pct_floor>=30?'warn':'ok', 'concentration after merging PROVEN-linked wallets into entities \u2014 a floor: unfound links can only raise it');
  p.appendChild(grid);
  return p;
}

/* ───────────────────────── score ring + radar ───────────────────────── */
function drawRing(cv, score, color){
  if (!cv) return;
  const [ctx,w,h]=prep(cv); const cx=w/2, cy=h/2, R=w/2-7;
  const target=(Math.max(0,Math.min(100,score))/100)*Math.PI*2;
  function frame(a){
    ctx.clearRect(0,0,w,h);
    ctx.lineWidth=8; ctx.lineCap='round';
    ctx.strokeStyle='#182430';
    ctx.beginPath(); ctx.arc(cx,cy,R,0,7); ctx.stroke();
    /* ticks */
    ctx.strokeStyle='#1d2a38'; ctx.lineWidth=1;
    for(let i=0;i<20;i++){ const t=-Math.PI/2+i*Math.PI/10;
      ctx.beginPath(); ctx.moveTo(cx+Math.cos(t)*(R-8),cy+Math.sin(t)*(R-8));
      ctx.lineTo(cx+Math.cos(t)*(R-12),cy+Math.sin(t)*(R-12)); ctx.stroke(); }
    ctx.lineWidth=8; ctx.strokeStyle=color;
    ctx.shadowColor=color; ctx.shadowBlur=12;
    ctx.beginPath(); ctx.arc(cx,cy,R,-Math.PI/2,-Math.PI/2+a); ctx.stroke();
    ctx.shadowBlur=0;
  }
  if (REDUCED) { frame(target); return; }
  const t0=performance.now();
  (function step(now){ const k=Math.min(1,(now-t0)/700); frame(target*(1-Math.pow(1-k,3)));
    if(k<1) requestAnimationFrame(step); })(t0);
}
/* group flag weights into 6 axes; hard-fail pegs the axis */
function radarAxes(r){
  const AX=[['Authorities',/freeze|mint_auth|authority|metadata|mutable/],
            ['Token-2022',/2022|transfer_fee|transfer_hook|permanent_delegate|non_transferable|extension/],
            ['Holders',/top10|whale|holders/],
            ['Liquidity',/liq|no_pair|socials|organic|bot/],
            ['Launch',/bundle|snip|dev_|alloc|serial|deployer|launch|fresh/],
            ['Clusters',/cluster|entity|jito/]];
  const axes=AX.map(([n])=>({label:n,v:0,flags:[]}));
  (r.flags||[]).forEach(f=>{ if(f.severity==='good'||f.severity==='info'&&f.weight<=0) return;
    const i=AX.findIndex(([,re])=>re.test(f.id));
    const a=axes[i<0?4:i]; a.flags.push(f.title);
    a.v = f.hardFail||f.hard_fail ? 100 : Math.min(100, a.v + f.weight*2.2); });
  return axes;
}
function drawRadar(cv, axes){
  if (!cv) return;
  const [ctx,w,h]=prep(cv); const cx=w/2, cy=h/2+6, R=Math.min(w,h)/2-34, N=axes.length;
  const pt=(i,k)=>{ const a=-Math.PI/2+i*2*Math.PI/N; return [cx+Math.cos(a)*R*k, cy+Math.sin(a)*R*k]; };
  ctx.clearRect(0,0,w,h);
  /* web */
  ctx.strokeStyle='#1d2a38'; ctx.lineWidth=1;
  [0.25,0.5,0.75,1].forEach(k=>{ ctx.beginPath();
    for(let i=0;i<=N;i++){ const [x,y]=pt(i%N,k); i?ctx.lineTo(x,y):ctx.moveTo(x,y); } ctx.stroke(); });
  for(let i=0;i<N;i++){ const [x,y]=pt(i,1); ctx.beginPath(); ctx.moveTo(cx,cy); ctx.lineTo(x,y); ctx.stroke(); }
  /* data */
  ctx.beginPath();
  axes.forEach((a,i)=>{ const [x,y]=pt(i,Math.max(.04,a.v/100)); i?ctx.lineTo(x,y):ctx.moveTo(x,y); });
  ctx.closePath();
  ctx.fillStyle='rgba(57,208,216,.16)'; ctx.fill();
  ctx.strokeStyle='#39d0d8'; ctx.lineWidth=2; ctx.stroke();
  axes.forEach((a,i)=>{ const [x,y]=pt(i,Math.max(.04,a.v/100));
    ctx.beginPath(); ctx.arc(x,y,3.5,0,7);
    ctx.fillStyle=a.v>=100?'#ef4444':a.v>=50?'#fbbf24':'#39d0d8'; ctx.fill(); });
  /* labels */
  ctx.font='12px ui-monospace,monospace'; ctx.fillStyle='#8ea3b8'; ctx.textAlign='center';
  axes.forEach((a,i)=>{ const [x,y]=pt(i,1.17); ctx.fillText(a.label.toUpperCase(),x,y+3); });
  /* hover */
  cv.onpointermove = ev => { const r2=cv.getBoundingClientRect(); const mx=ev.clientX-r2.left,my=ev.clientY-r2.top;
    let best=-1,bd=1e9;
    axes.forEach((a,i)=>{ const [x,y]=pt(i,Math.max(.04,a.v/100)); const d=(mx-x)**2+(my-y)**2; if(d<bd){bd=d;best=i;} });
    if (bd<400){ const a=axes[best];
      tipShow('<b>'+a.label+'</b> · risk '+Math.round(a.v)+'/100'+(a.flags.length?'<br>'+a.flags.slice(0,4).map(esc).join('<br>'):'<br>no findings'), ev.clientX, ev.clientY);
    } else tipHide(); };
  cv.onpointerleave = tipHide;
}

/* ───────────────────────── findings ───────────────────────── */
function findingsPanel(r){
  const p=panel('c8','Findings','click a severity to filter');
  const flags=r.flags||[];
  const counts={}; flags.forEach(f=>counts[f.severity]=(counts[f.severity]||0)+1);
  const on=Object.fromEntries(SEVORD.map(s2=>[s2,true]));
  const chips2=el('<div class="sevchips"></div>');
  SEVORD.forEach(sv=>{ if(!counts[sv])return;
    const [ico,col]=SEV[sv];
    const c=el('<span class="sevchip" data-on="1" style="color:'+col+'">'+ico+' '+sv+' <b>'+counts[sv]+'</b></span>');
    c.onclick=()=>{ on[sv]=!on[sv]; c.dataset.on=on[sv]?'1':'0'; c.style.color=on[sv]?col:''; draw(); };
    chips2.appendChild(c); });
  p.appendChild(chips2);
  const list=el('<div class="flaglist"></div>'); p.appendChild(list);
  function draw(){
    list.innerHTML='';
    flags.filter(f=>on[f.severity]).forEach(f=>{
      const [ico,col]=SEV[f.severity]||['','var(--muted)'];
      list.appendChild(el('<div class="flag" style="border-left-color:'+col+'"><div class="fico">'+ico+'</div><div style="min-width:0">'+
        '<div class="ft" style="color:'+col+'">'+esc(f.title)+
        ((f.hardFail||f.hard_fail)?' <span class="fw">HARD-CAP</span>':'<span class="fw">-'+f.weight+'</span>')+'</div>'+
        '<div class="fd">'+esc(f.detail)+'</div></div></div>'));
    });
    if (!list.children.length) list.appendChild(el('<div class="fd" style="color:var(--dim);padding:8px">nothing at the selected severities</div>'));
  }
  draw();
  return p;
}

/* ───────────────────────── launch forensics ───────────────────────── */
function drawDonut(cv){
  const segs=JSON.parse(cv.dataset.segs||'[]'); if(!segs.length) return;
  const [ctx,w,h]=prep(cv); const cx=w/2,cy=h/2,R=w/2-6,r0=R*0.62;
  let a=-Math.PI/2; const total=segs.reduce((t,s)=>t+s.v,0)||1;
  segs.forEach(s2=>{ const sw=s2.v/total*Math.PI*2;
    ctx.beginPath(); ctx.arc(cx,cy,R,a,a+sw); ctx.arc(cx,cy,r0,a+sw,a,true); ctx.closePath();
    ctx.fillStyle=s2.c; ctx.fill();
    ctx.strokeStyle='#0e141c'; ctx.lineWidth=2; ctx.stroke();
    s2.a0=a; s2.a1=a+sw; a+=sw; });
  ctx.fillStyle='#e8eef5'; ctx.font='700 16px ui-monospace,monospace'; ctx.textAlign='center';
  ctx.fillText(cv.dataset.center||'', cx, cy+1);
  ctx.font='11px ui-sans-serif,system-ui'; ctx.fillStyle='#5a6b7d';
  ctx.fillText((cv.dataset.centersub||'').toUpperCase(), cx, cy+16);
  cv.onpointermove=ev=>{ const rb=cv.getBoundingClientRect(); const mx=ev.clientX-rb.left-cx,my=ev.clientY-rb.top-cy;
    const d=Math.hypot(mx,my); if(d<r0||d>R){ tipHide(); return; }
    let ang=Math.atan2(my,mx); if(ang<-Math.PI/2) ang+=Math.PI*2;
    const s2=segs.find(x=>ang>=x.a0&&ang<x.a1);
    if(s2) tipShow('<b>'+esc(s2.l)+'</b> · '+pct(s2.v), ev.clientX, ev.clientY); else tipHide(); };
  cv.onpointerleave=tipHide;
}
function launchPanel(bu, tok){
  const p=panel('c6 keep','Launch forensics', bu&&bu.note?bu.note:null);
  if (bu && bu.analyzed && bu.pctSupplySniped!=null){
    const sniped=bu.pctSupplySniped||0, held=Math.min(sniped,bu.pctSnipersStillHold||0);
    const box=el('<div class="donutbox"></div>');
    box.appendChild(el('<canvas class="donut" data-center="'+pct(sniped)+'" data-centersub="sniped" data-segs=\''+JSON.stringify([
      {l:'still held by snipers', v:held, c:'#f87171'},
      {l:'sniped, since sold', v:Math.max(0,sniped-held), c:'#a87f10'},
      {l:'organic / later supply', v:Math.max(0,100-sniped), c:'#1d2a38'},
    ]).replace(/'/g,'&#39;')+'\'></canvas>'));
    const kv=el('<div class="kv" style="flex-direction:column;gap:7px">'+
      '<span>Snipers <b>'+(bu.snipers??'')+'</b></span>'+
      '<span>Same-slot buyers <b>'+(bu.sameSlotBuyers??'')+'</b></span>'+
      '<span>Fresh-wallet ratio <b>'+(bu.freshWalletRatio==null?'':pct(bu.freshWalletRatio*100))+'</b></span>'+
      '<span>Dev allocation <b>'+(bu.pctDevAllocation==null?'':pct(bu.pctDevAllocation))+'</b></span>'+
      '<span>Launch slot <b>'+(bu.launchSlot??'')+'</b></span>'+
      (tok&&tok.launchpad?'<span>Launchpad <b>'+esc(tok.launchpad)+'</b></span>':'')+'</div>');
    box.appendChild(kv); p.appendChild(box);
    const sn=bu.topSnipers||[];
    if (sn.length){
      const hb=el('<div class="hbar" style="margin-top:12px"></div>');
      const mx=Math.max(...sn.map(x=>x.pct||0), 0.01);
      sn.slice(0,6).forEach(x=>{
        const addr=x.owner||x.address||'';
        const stillW=Math.min(100,(x.heldPct||0)/mx*100), soldW=Math.max(0,((x.pct||0)-(x.heldPct||0))/mx*100);
        hb.appendChild(el('<div class="row" data-tip="'+esc(shortA(addr))+' — bought '+pct(x.pct)+', still holds '+pct(x.heldPct)+(x.freshWallet?' · fresh wallet':'')+(x.sameSlot?' · same-slot':'')+'">'+
          '<span class="lb">'+esc(shortA(addr))+(x.freshWallet?'':'')+(x.sameSlot?'':'')+'</span>'+
          '<span class="tr"><i style="width:'+stillW+'%;background:#f87171"></i><i style="width:'+soldW+'%;background:#a87f10"></i></span>'+
          '<span class="vl">'+pct(x.pct)+'</span></div>'));
      });
      p.appendChild(el('<div class="sub" style="margin:12px 0 2px">top snipers — <span style="color:#f87171">still holding</span> vs <span style="color:#a87f10">sold</span> · ✦ fresh wallet · ⚡ same-slot</div>'));
      p.appendChild(hb);
    }
    /* launch timeline — % of supply bought per slot offset (tall slot-0 bar = bundle signature) */
    const tl=bu.timeline||[];
    if (tl.length){
      const bySlot={};
      tl.forEach(x=>{ const k=x.slotOffset??0; bySlot[k]=(bySlot[k]||0)+(x.pct||0); });
      const slots=Object.keys(bySlot).map(Number).sort((a,b)=>a-b).slice(0,12);
      const mx2=Math.max(...slots.map(k=>bySlot[k]),0.01);
      const hb2=el('<div class="hbar"></div>');
      slots.forEach(k=>{ hb2.appendChild(el('<div class="row" data-tip="slot +'+k+''+pct(bySlot[k])+' of supply bought ('+tl.filter(x=>(x.slotOffset??0)===k).length+' buyers)">'+
        '<span class="lb">slot +'+k+'</span>'+
        '<span class="tr"><i style="width:'+Math.min(100,bySlot[k]/mx2*100)+'%;background:'+(k===0?'#c74e4e':'#3f74c9')+'"></i></span>'+
        '<span class="vl">'+pct(bySlot[k])+'</span></div>')); });
      p.appendChild(el('<div class="sub" style="margin:12px 0 2px">buy timeline — supply bought per slot after launch (<span style="color:#c74e4e">slot 0</span> = the bundle signature)</div>'));
      p.appendChild(hb2);
    }
  } else if (bu) {
    p.appendChild(el('<div class="fd" style="color:var(--muted)">'+esc(bu.note||'Bundle scan did not run — unknown, not clean.')+'</div>'));
  }
  return p;
}

/* ───────────────────────── holders ───────────────────────── */
function holdersPanel(ho, cl){
  const p=panel('c6 keep','Holder concentration','top wallets, LP/burn/protocol reserves excluded — hover a segment');
  const top=(ho.top||[]).slice(0,10);
  if (top.length){
    const stack=el('<div class="stack" role="img" aria-label="top holder share"></div>');
    let sum=0;
    top.forEach((h2,i)=>{ sum+=h2.pct||0;
      stack.appendChild(el('<i style="width:'+Math.max(1,h2.pct||0)+'%;background:'+CLCOLORS[i%CLCOLORS.length]+'" data-tip="'+esc(shortA(h2.address))+(h2.isContract?' (contract)':'')+''+pct(h2.pct)+'"></i>'));
    });
    stack.appendChild(el('<i style="width:'+Math.max(0,100-sum)+'%;background:#121a24" data-tip="everyone else — '+pct(Math.max(0,100-sum))+'"></i>'));
    p.appendChild(stack);
    p.appendChild(el('<div class="legend"><span>top-10 combined <b style="color:var(--ink)">'+pct(ho.top10Pct)+'</b></span>'+
      '<span>tracked holders <b style="color:var(--ink)">'+(ho.holderCount??'')+'</b></span></div>'));
  } else {
    p.appendChild(el('<div class="fd" style="color:var(--muted)">holder data unavailable this run — unknown, not clean</div>'));
  }
  const ec=(cl||{}).effective_concentration;
  if (ec && (ec.top10_raw_pct!=null||ec.top10_entity_pct_floor!=null)){
    const hb=el('<div class="hbar" style="margin-top:14px"></div>');
    const mx=Math.max(ec.top10_raw_pct||0, ec.top10_entity_pct_floor||0, 1);
    [['raw top-10', ec.top10_raw_pct, '#3f74c9', ''],
     ['entity top-10', ec.top10_entity_pct_floor, '#c74e4e', '\u2265'],
     ['largest entity', ec.largest_entity_pct_floor, '#a87f10', '\u2265']].forEach(([l,v,c,pre])=>{
      if (v==null) return;
      hb.appendChild(el('<div class="row" data-tip="'+l+''+pre+pct(v)+'"><span class="lb">'+l+'</span>'+
        '<span class="tr"><i style="width:'+Math.min(100,v/mx*100)+'%;background:'+c+'"></i></span><span class="vl">'+pre+pct(v)+'</span></div>'));
    });
    p.appendChild(el('<div class="sub" style="margin:12px 0 2px">anti-evasion view \u2014 same supply, PROVEN-linked wallets merged into entities. The entity bars are floors.</div>'));
    p.appendChild(hb);
  }
  return p;
}

/* ───────────────────────── liquidity ───────────────────────── */
function liquidityPanel(lq, mk){
  const p=panel('c6 keep','Liquidity & market');
  p.appendChild(el('<div class="kv"><span>Total <b>'+usd(lq.totalLiquidityUsd)+'</b></span>'+
    '<span>FDV <b>'+usd(lq.fdvUsd)+'</b></span>'+
    '<span>Liq/FDV <b>'+pct(lq.liqToFdvPct)+'</b></span>'+
    '<span>Socials <b>'+(lq.hasSocials?'yes':'none')+'</b></span>'+
    (mk&&mk.organicScore!=null?'<span>Organic score <b>'+mk.organicScore+' ('+esc(mk.organicScoreLabel||'')+')</b></span>':'')+
    (mk&&(mk.tags||[]).length?'<span>Tags <b>'+mk.tags.map(esc).join(', ')+'</b></span>':'')+'</div>'));
  const pairs=lq.pairs||[];
  if (pairs.length){
    const rows=pairs.slice(0,6).map(x=>'<tr><td><b>'+esc(x.dex||'?')+'</b>'+((x.labels||[]).length?' <span style="color:var(--dim)">'+esc(x.labels[0])+'</span>':'')+'</td><td>'+esc(x.quoteSymbol||'')+'</td>'+
      '<td>'+usd(x.liquidityUsd)+'</td><td>'+(x.ageHours==null?'':(x.ageHours<48?x.ageHours+'h':Math.round(x.ageHours/24)+'d'))+'</td></tr>').join('');
    p.appendChild(el('<table class="tb" style="margin-top:12px"><thead><tr><th>venue</th><th>pair</th><th>liquidity</th><th>age</th></tr></thead><tbody>'+rows+'</tbody></table>'));
  }
  return p;
}

/* ───────────────────────── authorities + token program + deployer ───────────────────────── */
const DANGER_EXT = { transferFeeConfig:'transfer fee', transferHook:'transfer hook', permanentDelegate:'permanent delegate', nonTransferable:'non-transferable', defaultAccountState:'default acct state', confidentialTransferMint:'confidential' };
function authoritiesPanel(mint, dep, copy){
  const p=panel('c6 keep','Authorities & token program','the Solana rug levers — revoked = safe, present = the holder can act');
  const grid=el('<div class="checkgrid"></div>');
  const add=(label,ok,txt,bad)=>{ grid.appendChild(el('<div class="check"><span class="st">'+(ok==null?'':ok?'':(bad?'🛑':'⚠️'))+'</span>'+
    '<span class="cl"><b style="color:'+(ok==null?'var(--dim)':ok?'var(--good)':(bad?'var(--crit)':'var(--warn)'))+'">'+esc(txt)+'</b>'+label+'</span></div>')); };
  if (mint){
    add('freeze authority', mint.freezeAuthority==null, mint.freezeAuthority==null?'revoked':shortA(mint.freezeAuthority), mint.freezeAuthority!=null);
    add('mint authority', mint.mintAuthority==null, mint.mintAuthority==null?'revoked':shortA(mint.mintAuthority), mint.mintAuthority!=null);
    add('token program', mint.isToken2022!==true, mint.isToken2022?'Token-2022':'SPL Token');
    const md=mint.metadata||{};
    add('metadata', md.isMutable===false, md.isMutable===false?'immutable':md.isMutable===true?'MUTABLE':'unknown');
  }
  p.appendChild(grid);
  const exts=(mint&&mint.extensions)||[];
  if (mint&&mint.isToken2022){
    if (exts.length) p.appendChild(el('<div style="margin-top:10px"><span class="sub">Token-2022 extensions on this mint:</span><br>'+
      exts.map(e=>'<span class="dfn">'+esc(DANGER_EXT[e]||e)+'</span>').join('')+'</div>'));
    else p.appendChild(el('<div class="sub" style="margin-top:10px">Token-2022 mint with no honeypot-class extensions detected.</div>'));
  }
  if (dep){
    p.appendChild(el('<div class="kv" style="margin-top:12px">'+
      (dep.dev?'<span>Dev wallet <b><a href="'+EXPLORER+encodeURIComponent(dep.dev)+'" target="_blank" rel="noopener">'+shortA(dep.dev)+'</a></b></span>':'')+
      (dep.walletAgeDays!=null?'<span>Wallet age <b>'+dep.walletAgeDays+'d</b></span>':'')+
      (dep.walletTxCount!=null?'<span>Wallet txs <b>'+dep.walletTxCount+'</b></span>':'')+
      (dep.tokensLaunched!=null?'<span>Tokens launched <b>'+dep.tokensLaunched+'</b></span>':'')+
      (dep.devBalancePct!=null?'<span>Dev holds <b>'+pct(dep.devBalancePct)+'</b></span>':'')+
      '</div>'));
  }
  if ((copy||[]).length) p.appendChild(el('<div class="sub" style="margin-top:10px">⚠ '+copy.length+' same-symbol copycat token(s) — verify the mint you hold.</div>'));
  return p;
}

/* ───────────────────────── wallet links (evidence list, not a map) ─────────────────────────
   There was a force-directed bubblemap here. It was removed deliberately.

   A bubblemap is a claim of completeness: every wallet is a node, every
   relationship is a line, and two bubbles with no line between them read as
   "independent". We cannot honor that claim on public-RPC data. The holder set
   stops at the 20 largest token accounts, direct-transfer evidence is a sample
   of a few recent transactions per wallet, and SOL movement between holders is
   never scanned at all. On that input a missing line means "not sampled" far
   more often than "no relationship" — so the map's most confident-looking
   statement was its least reliable one.

   A list can only assert what was observed. Each row carries its evidence and a
   confidence tier, and the panel closes by stating what the pass cannot see.
   Restore a map when the data behind it is complete — an indexed holder list
   and full transfer history — not before. ────────────────────────────────── */
function clusterPanel(cl){
  const root=panel('c12','Wallet links — who is provably one entity',
    'every row states the evidence behind it · proven = we read the transaction · probable = a shared funder · lead = timing only, not an accusation');
  const ec = cl.effective_concentration || null;
  const scope = cl.scope || {};

  let kv='<div class="kv" style="margin-bottom:10px">';
  if (ec) kv+='<span>Top-10 raw <b>'+pct(ec.top10_raw_pct)+'</b></span>'
            +'<span>Top-10 entities <b>&ge;'+pct(ec.top10_entity_pct_floor)+'</b></span>'
            +'<span>Largest entity <b>&ge;'+pct(ec.largest_entity_pct_floor)+'</b></span>';
  kv+='<span>Coverage <b>'+esc(scope.coverage||'?')+'</b></span></div>';
  root.appendChild(el(kv));
  if (ec) root.appendChild(el('<div class="clleg">The entity numbers are floors. Merging wallets can only ADD supply to an entity, so every link we failed to find pushes them up, never down.</div>'));

  const findings = cl.findings || [];
  const CONF = {
    proven:   ['#e0574f','proven'],
    probable: ['#d99a2b','probable'],
    lead:     ['#6f7d92','lead only']
  };
  if (findings.length) {
    const rows = findings.map((c,i) => {
      const conf = CONF[c.confidence] || ['#6f7d92', esc(c.confidence||'?')];
      const badge = '<b style="color:'+conf[0]+'">'+conf[1]+(c.proof?' &#9889; Jito':'')+'</b>';
      return '<tr><td><span class="cltable-dot" style="background:'+conf[0]+'"></span>#'+(c.id||i+1)+'</td>'
        +'<td>'+(c.wallets||[]).length+'</td>'
        +'<td>'+pct(c.pct_combined)+'</td>'
        +'<td>'+(c.pct_bought!=null?pct(c.pct_bought):'&mdash;')+'</td>'
        +'<td>'+esc((c.evidence||'').replace(/_/g,' '))+'</td>'
        +'<td>'+badge+'</td>'
        +'<td style="font-family:var(--sans)">'+esc(c.note||'')+'</td></tr>';
    }).join('');
    root.appendChild(el('<table class="tb" style="margin:8px 0 14px"><thead><tr><th>#</th><th>wallets</th><th>holds</th><th>bought</th><th>evidence</th><th>confidence</th><th>what this means</th></tr></thead><tbody>'+rows+'</tbody></table>'));

    const wl = findings.filter(c => (c.wallets||[]).length).map((c,i) =>
      '<div class="clwallets"><span class="clwlabel">#'+(c.id||i+1)+'</span>'
      + c.wallets.map(w => '<a href="'+EXPLORER+encodeURIComponent(w)+'" target="_blank" rel="noopener">'+esc(w.slice(0,4)+''+w.slice(-4))+'</a>').join('')
      + '</div>').join('');
    if (wl) {
      root.appendChild(el('<div class="clleg" style="margin-top:2px"><b>Wallets in each group</b> &mdash; open any address to check it yourself:</div>'));
      root.appendChild(el('<div style="margin:6px 0 12px">'+wl+'</div>'));
    }
  } else {
    root.appendChild(el('<div class="clleg">No wallet links surfaced in the analyzed set. That is <b>not</b> a finding of independence &mdash; see the limits below.</div>'));
  }

  // Always rendered, findings or none. A quiet result is exactly where a reader
  // over-reads, so the ceiling on what was examined is stated every time.
  const lim = scope.limits || [];
  let foot = '<div class="clleg" style="margin-top:12px"><b>How far this went</b> &mdash; '
    + (scope.wallets_analyzed||0)+' wallets examined ('+(scope.holders_analyzed||0)+' holders, '
    + (scope.snipers_analyzed||0)+' launch buyers), '+(scope.funder_hops||0)+' funding hop(s), '
    + (scope.transfer_txs_sampled||0)+' transaction(s) sampled for direct transfers.</div>';
  if (lim.length) foot += '<ul class="cllimits">'+lim.map(x=>'<li>'+esc(x)+'</li>').join('')+'</ul>';
  if (scope.note) foot += '<div class="clleg">'+esc(scope.note)+'</div>';
  root.appendChild(el(foot));
  return root;
}

/* ───────────────────────── live feeds (serve mode; stubbed → empty in artifacts) ───────────────────────── */
async function scan() {
  const feed = document.getElementById('feed');
  if (typeof __AUDIT !== 'undefined' && window.parent !== window) {
    /* Embedded in Rokha: bridge a REAL scan run to the host (viewer-billed). */
    window.parent.postMessage({ rokha: 'app_action', action: 'scan', input: 'scan' }, '*');
    feed.innerHTML='<div class="empty">⧗ Sent to Rokha — scanning new launches for real; this panel refreshes with the result.</div>';
    return;
  }
  feed.innerHTML = '<h2><span class="spinner"></span> Loading recent launches…</h2>';
  try {
    const r = await fetch('/api/scan').then(x=>x.json());
    const launches = (r && r.launches) || [];
    const rows = launches.slice(0,25).map(l =>
      '<div class="lrow" data-a="'+l.mint+'"><span><b>$'+esc(l.symbol||'?')+'</b> <span class="a">'+l.mint.slice(0,12)+'…</span></span>'+
      '<span>'+(l.launchpad?esc(l.launchpad)+' · ':'')+'holders '+(l.holderCount??'')+' · mcap '+usd(l.mcapUsd)+'</span></div>').join('');
    feed.innerHTML = '<h2>Fresh launches ('+launches.length+')</h2>'+(rows||'<div class="empty">none</div>');
    feed.querySelectorAll('.lrow').forEach(row => row.onclick=()=>{ const a=row.dataset.a; document.getElementById('addr').value=a; audit(a); window.scrollTo({top:0,behavior:'smooth'}); });
  } catch(e) { feed.innerHTML='<h2>Error: '+esc(e.message)+'</h2>'; }
}
async function loadReports() {
  const box = document.getElementById('reports');
  try {
    const list = await fetch('/api/reports').then(x=>x.json());
    if (!Array.isArray(list) || !list.length) { box.innerHTML=''; return; }
    const rows = list.slice(0,20).map(r =>
      '<div class="lrow" data-a="'+r.address+'"><span><span style="color:'+(VCOLOR[r.verdict]||'var(--muted)')+';font-weight:700">'+r.score+'</span> · $'+esc(r.symbol||'?')+' <span class="a">'+r.address.slice(0,12)+'…</span></span><span>'+esc((r.verdict||'').replace("_"," "))+' · '+esc((r.scannedAt||'').slice(0,16).replace("T"," "))+'</span></div>').join('');
    box.innerHTML = '<h2>Saved audit reports ('+list.length+')</h2>'+rows;
    box.querySelectorAll('.lrow').forEach(row => row.onclick=()=>{ const a=row.dataset.a; document.getElementById('addr').value=a; audit(a); window.scrollTo({top:0,behavior:'smooth'}); });
  } catch(e) { box.innerHTML=''; }
}

document.getElementById('go').onclick = () => { const a=document.getElementById('addr').value.trim(); if(/^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(a)) audit(a); };
document.getElementById('addr').addEventListener('keydown', e => { if(e.key==='Enter') document.getElementById('go').click(); });
document.getElementById('scan').onclick = scan;
const _audit = audit;
audit = async (a) => { await _audit(a); loadReports(); };
loadReports();
</script>
</body>
</html>