truscan / templates /forensics.html
Manar55's picture
Deploy 25e8b1a
2b35ff1 verified
Raw History Blame Contribute Delete
87 kB
<!doctype html>
<html lang="ar" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TrueScan</title>
<style>
:root{--bg:#0b1426;--panel:#111d35;--panel2:#0f1a30;--line:#22345a;--txt:#e6eeff;--mut:#8ea3c7;--acc:#2563eb;--ok:#22c55e;--warn:#f59e0b;--bad:#ef4444;--info:#60a5fa}
:root[data-theme="light"]{--bg:#f4f6fb;--panel:#ffffff;--panel2:#f1f4fa;--line:#d6deeb;--txt:#0f172a;--mut:#5b6b85}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--txt);font:15px "Segoe UI",Tahoma,system-ui,sans-serif}
.lang-en body,.lang-en body *{unicode-bidi:plaintext}
main{max-width:1100px;margin:0 auto;padding:4px 0 40px}
.tabs{display:flex;gap:8px;margin-bottom:14px;flex-wrap:wrap}
.tabs button{display:flex;align-items:center;gap:8px;padding:10px 16px;border-radius:12px;border:1px solid var(--line);background:var(--panel);color:var(--txt);font:inherit;font-weight:600;cursor:pointer}
.tabs button.on{background:var(--acc);border-color:var(--acc);color:#fff}
.card{background:var(--panel);border:1px solid var(--line);border-radius:16px;padding:16px;margin-bottom:14px}
.card h2{font-size:15px;margin:0 0 10px}
.mut{color:var(--mut);font-size:12.5px;line-height:1.7}
.drop{border:2px dashed var(--line);border-radius:16px;padding:34px 16px;text-align:center;cursor:pointer;background:var(--panel2)}
.drop.over{border-color:var(--acc)}
.ico{width:58px;height:58px;border-radius:16px;margin:0 auto 12px;display:flex;align-items:center;justify-content:center;background:rgba(37,99,235,.12);color:var(--acc)}
.btn{padding:11px 18px;border-radius:10px;border:0;background:var(--acc);color:#fff;font:inherit;font-weight:700;cursor:pointer}
.btn.sec{background:var(--panel2);color:var(--txt);border:1px solid var(--line)}
.btn:disabled{opacity:.5;cursor:wait}
.verdict{display:flex;gap:12px;align-items:flex-start;padding:14px;border-radius:12px;border:1px solid var(--line);background:var(--panel2)}
.verdict.high{border-color:var(--bad);background:rgba(239,68,68,.10)}
.verdict.medium{border-color:var(--warn);background:rgba(245,158,11,.10)}
.verdict.low{border-color:var(--ok);background:rgba(34,197,94,.10)}
.verdict b{font-size:16px}
.f{display:flex;gap:10px;padding:8px 0;border-top:1px solid var(--line);font-size:13.5px;line-height:1.65}
.f:first-child{border-top:0}
.f i{flex:0 0 9px;height:9px;border-radius:50%;margin-top:7px}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:14px}
.map img{width:100%;border-radius:10px;display:block;cursor:zoom-in;border:1px solid var(--line)}
.map h3{font-size:14px;margin:0 0 6px}
.kv{display:flex;justify-content:space-between;gap:10px;padding:6px 0;border-top:1px solid var(--line);font-size:13.5px}
.kv:first-child{border-top:0}.kv span:last-child{direction:ltr;unicode-bidi:plaintext}
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
.files{font-size:12.5px;color:var(--mut);margin-top:6px}
.spin{display:inline-block;width:16px;height:16px;border:2px solid currentColor;border-top-color:transparent;border-radius:50%;animation:s 1s linear infinite;vertical-align:-3px}
@keyframes s{to{transform:rotate(360deg)}}
.pce{font-size:34px;font-weight:800;direction:ltr}
.note{font-size:11.5px;color:var(--mut);margin-top:12px;line-height:1.6}
.qt{display:grid;grid-template-columns:repeat(8,1fr);gap:2px;direction:ltr;font:11px ui-monospace,Menlo,monospace;text-align:center}
.qt span{padding:3px 0;border-radius:3px}
.tbl{width:100%;border-collapse:collapse;font-size:12.5px;direction:ltr}
.tbl td,.tbl th{padding:5px 6px;border-top:1px solid var(--line);text-align:left;white-space:nowrap}
.mono{font:11.5px ui-monospace,Menlo,monospace;direction:ltr;white-space:pre;overflow:auto;max-height:340px;background:var(--panel2);border-radius:10px;padding:10px;line-height:1.55}
.str{font:12px ui-monospace,Menlo,monospace;direction:ltr;padding:4px 0;border-top:1px solid var(--line);word-break:break-all}
.str.flag{color:var(--warn);font-weight:700}
.gwrap{position:relative;touch-action:none;user-select:none;-webkit-user-select:none}
.gwrap img{width:100%;display:block;border-radius:10px}
.gwrap canvas{position:absolute;inset:0;width:100%;height:100%;border-radius:10px;pointer-events:none}
.gsel{position:absolute;border:2px dashed #fff;box-shadow:0 0 0 1px #000;pointer-events:none;display:none}
input[type=range]{width:100%}
.badge{display:inline-block;padding:1px 8px;border-radius:999px;font-size:11px;border:1px solid var(--line);margin-inline-start:6px}
.fb button{padding:8px 14px;border-radius:9px;font:inherit;font-size:12.5px;font-weight:700;cursor:pointer;border:1px solid var(--line);background:var(--panel2);color:var(--txt);margin:0 0 6px 6px}
.fb button.ok{color:var(--ok);border-color:rgba(34,197,94,.45)}.fb button.no{color:var(--bad);border-color:rgba(239,68,68,.45)}
.fb button.sel{background:var(--acc);color:#fff;border-color:var(--acc)}
.fb input{width:100%;padding:8px 10px;border-radius:8px;border:1px solid var(--line);background:var(--panel2);color:var(--txt);font:inherit;font-size:12.5px;margin:4px 0 8px}
.ev{display:flex;flex-wrap:wrap;gap:8px}
.ev button{display:inline-flex;align-items:center;gap:8px;padding:9px 13px;border-radius:11px;border:1px solid var(--line);background:var(--panel2);color:var(--txt);font:inherit;font-size:13px;font-weight:700;cursor:pointer}
.ev button i{width:9px;height:9px;border-radius:50%;flex:0 0 9px}
.ev button.on{outline:2px solid var(--acc);outline-offset:1px}
.evd{margin-top:12px;border:1px solid var(--line);border-radius:12px;padding:14px;background:var(--panel2)}
.evd h4{margin:12px 0 4px;font-size:12.5px;color:var(--mut);font-weight:700}
.evd h4:first-of-type{margin-top:0}
.evd p{margin:0;font-size:13.5px;line-height:1.75;white-space:pre-line}
.evd .ref{font-size:12px;direction:ltr;text-align:left;unicode-bidi:plaintext;color:var(--mut)}
.evd img{max-width:100%;border-radius:10px;margin-top:6px;cursor:zoom-in;border:1px solid var(--line)}
.bar{align-self:stretch;width:100%;height:10px;border-radius:6px;background:var(--panel2);border:1px solid var(--line);overflow:hidden;display:flex}
.bar span{display:block;height:100%}
.op{display:grid;grid-template-columns:1fr 1fr;gap:12px}
@media (max-width:700px){.op{grid-template-columns:1fr}}
.reg{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:12px}
.reg img{width:100%;border-radius:10px;cursor:zoom-in;border:1px solid var(--line)}
.dct select{padding:7px 10px;border-radius:8px;border:1px solid var(--line);background:var(--panel2);color:var(--txt);font:inherit}
.gt{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:8px;margin-top:10px}
.gt div{position:relative}.gt img{width:100%;display:block;border-radius:8px}.gt canvas{position:absolute;inset:0;width:100%;height:100%;border-radius:8px;image-rendering:pixelated}
.gt b{display:block;text-align:center;font-size:12px;margin-top:3px}
/* ---- dashboard ---- */
.hero{display:grid;grid-template-columns:200px 1fr 150px;gap:18px;align-items:center}
@media (max-width:760px){.hero{grid-template-columns:1fr}.hero .thumb{display:none}}
.gauge{position:relative;width:200px;margin:0 auto}
.gauge svg{width:100%;display:block}
.gauge .num{position:absolute;left:0;right:0;bottom:6px;text-align:center;direction:ltr}
.gauge .num b{font-size:34px;font-weight:800;letter-spacing:-1px}.gauge .num span{display:block;font-size:11px;color:var(--mut);margin-top:-2px}
.hero h3{margin:0 0 4px;font-size:19px;line-height:1.35}
.hero .lead{font-size:13px;color:var(--mut);line-height:1.7}
.chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:10px}
.chip{display:inline-flex;align-items:center;gap:6px;padding:5px 10px;border-radius:999px;font-size:12px;font-weight:600;border:1px solid var(--line);background:var(--panel2);color:var(--txt)}
.chip svg{width:14px;height:14px;flex:0 0 14px}
.chip.w{border-color:rgba(245,158,11,.45);color:#fbbf24}.chip.g{border-color:rgba(34,197,94,.45);color:#4ade80}
:root[data-theme="light"] .chip.w{color:#b45309}:root[data-theme="light"] .chip.g{color:#15803d}
.stats{display:flex;gap:16px;margin-top:12px;flex-wrap:wrap}
.stat{display:flex;flex-direction:column}.stat b{font-size:18px;line-height:1.1}.stat span{font-size:11px;color:var(--mut)}
.thumb img{width:100%;aspect-ratio:1;object-fit:cover;border-radius:12px;border:1px solid var(--line);cursor:zoom-in;display:block}
.cbar{display:flex;height:8px;border-radius:6px;overflow:hidden;background:var(--panel2);margin-top:14px}
.cbar span{height:100%}
.clegend{display:flex;flex-wrap:wrap;gap:4px 14px;margin-top:6px;font-size:11.5px;color:var(--mut)}
.clegend i{display:inline-block;width:8px;height:8px;border-radius:2px;margin-inline-end:5px}
.sech{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:2px 0 10px}
.sech h2{margin:0}
.grp{font-size:11.5px;font-weight:700;color:var(--mut);letter-spacing:.3px;margin:14px 0 8px;text-transform:uppercase}
.grp:first-of-type{margin-top:0}
.tiles{display:grid;grid-template-columns:repeat(auto-fill,minmax(178px,1fr));gap:10px}
.tile{position:relative;text-align:start;padding:12px;border-radius:14px;border:1px solid var(--line);background:var(--panel2);color:var(--txt);font:inherit;cursor:pointer;display:flex;flex-direction:column;gap:9px;transition:border-color .15s,transform .15s}
.tile:hover{transform:translateY(-1px);border-color:color-mix(in srgb,var(--c) 55%,var(--line))}
.tile.on{border-color:var(--c);box-shadow:0 0 0 1px var(--c) inset}
.tile .top{display:flex;align-items:center;gap:10px}
.tile .ic{width:34px;height:34px;border-radius:10px;display:flex;align-items:center;justify-content:center;flex:0 0 34px;background:color-mix(in srgb,var(--c) 16%,transparent);color:var(--c)}
.tile .ic svg{width:18px;height:18px}
.tile .nm{font-size:13px;font-weight:700;line-height:1.35}
.tile .st{display:flex;align-items:center;justify-content:space-between;font-size:11.5px;color:var(--c);font-weight:700}
.tile .meter{height:4px;border-radius:3px;background:color-mix(in srgb,var(--mut) 22%,transparent);overflow:hidden}
.tile .meter span{display:block;height:100%;background:var(--c);border-radius:3px}
.dpanel{margin-top:12px;border:1px solid var(--line);border-radius:14px;background:var(--panel2);overflow:hidden}
.dhead{display:flex;align-items:center;gap:10px;padding:12px 14px;border-bottom:1px solid var(--line)}
.dhead .ic{width:30px;height:30px;border-radius:9px;display:flex;align-items:center;justify-content:center;background:color-mix(in srgb,var(--c) 16%,transparent);color:var(--c)}
.dhead .ic svg{width:16px;height:16px}
.dhead b{font-size:14.5px}.dhead .pill{margin-inline-start:auto;font-size:11.5px;font-weight:700;color:var(--c);border:1px solid color-mix(in srgb,var(--c) 45%,transparent);padding:2px 10px;border-radius:999px}
.seg{display:flex;gap:4px;padding:4px;border-radius:11px;background:var(--panel);border:1px solid var(--line);width:max-content;max-width:100%;overflow-x:auto}
.seg button{padding:7px 13px;border-radius:8px;border:0;background:none;color:var(--mut);font:inherit;font-size:12.5px;font-weight:700;cursor:pointer;white-space:nowrap}
.seg button.on{background:var(--acc);color:#fff}
.dbody{padding:14px}
.dbody p{margin:0;font-size:13.5px;line-height:1.8;white-space:pre-line}
.dbody .ref{font-size:12px;direction:ltr;text-align:left;unicode-bidi:plaintext;color:var(--mut)}
.dsplit{display:grid;grid-template-columns:1fr 240px;gap:14px;align-items:start}
@media (max-width:700px){.dsplit{grid-template-columns:1fr}}
.dsplit img{width:100%;border-radius:10px;border:1px solid var(--line);cursor:zoom-in}
.mrow{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}
.mbox{padding:7px 11px;border-radius:10px;background:var(--panel);border:1px solid var(--line);font-size:12px}
.mbox span{color:var(--mut);display:block;font-size:10.5px}.mbox b{direction:ltr;unicode-bidi:plaintext}
.lbl{font-size:11px;font-weight:700;color:var(--mut);margin:12px 0 4px}.lbl:first-child{margin-top:0}
.viewer img.main{width:100%;max-height:560px;object-fit:contain;border-radius:12px;background:#000;display:block;cursor:zoom-in}
.strip{display:flex;gap:8px;overflow-x:auto;padding:10px 0 2px}
.strip button{flex:0 0 96px;padding:0;border:2px solid transparent;border-radius:10px;background:none;cursor:pointer;color:var(--mut);font:inherit;font-size:10.5px;text-align:center}
.strip button img{width:100%;height:64px;object-fit:cover;border-radius:8px;display:block}
.strip button.on{border-color:var(--acc);color:var(--txt)}
.strip button span{display:block;padding:3px 2px;line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.vcap{font-size:12.5px;color:var(--mut);margin-top:8px;line-height:1.7}
.pane .card{background:none;border:0;padding:0;margin:0 0 14px}
.tools{display:flex;flex-wrap:wrap;gap:8px}
.tbtn{display:inline-flex;align-items:center;gap:8px;padding:9px 14px;border-radius:11px;border:1px solid var(--line);background:var(--panel2);color:var(--txt);font:inherit;font-size:13px;font-weight:700;cursor:pointer}
.tbtn svg{width:16px;height:16px;color:var(--acc)}
details.tech{background:var(--panel);border:1px solid var(--line);border-radius:16px;margin-bottom:14px}
details.tech summary{padding:14px 16px;cursor:pointer;font-weight:700;font-size:14px;list-style:none;display:flex;align-items:center;justify-content:space-between}
details.tech summary::-webkit-details-marker{display:none}
details.tech summary svg{width:16px;height:16px;transition:transform .2s;color:var(--mut)}
details.tech[open] summary svg{transform:rotate(180deg)}
details.tech .in{padding:0 16px 14px}
.info{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;border-radius:50%;border:1px solid var(--line);background:var(--panel2);color:var(--mut);cursor:pointer;font:700 12px system-ui;padding:0}
.ipop{display:none;margin-top:8px;font-size:12px;color:var(--mut);line-height:1.75;background:var(--panel2);border:1px solid var(--line);border-radius:10px;padding:10px 12px}
.ipop.on{display:block}
@media (max-width:560px){.tiles{grid-template-columns:1fr 1fr;gap:8px}.tile{padding:10px;gap:7px}.tile .nm{font-size:12px}.tile .ic{width:28px;height:28px;flex-basis:28px;border-radius:8px}.tile .ic svg{width:15px;height:15px}.tile .top{gap:8px;align-items:flex-start}}
.foot{display:grid;grid-template-columns:1fr 1fr;gap:14px}
@media (max-width:760px){.foot{grid-template-columns:1fr}}
.foot .card{margin:0}
@media (max-width:700px){main{padding:0}.grid{grid-template-columns:1fr}.card{padding:12px}}
</style>
</head>
<body>
<main>
<div class="tabs">
<button id="tJ" class="on" data-i18n="tabJ"></button>
<button id="tP" data-i18n="tabP"></button>
<button id="tV" data-i18n="tabV"></button>
<button id="tS" data-i18n="tabS"></button>
</div>
<!-- JPEG analysis -->
<section id="pJ">
<div class="card">
<h2 data-i18n="jTitle"></h2>
<div class="mut" data-i18n="jSub"></div>
</div>
<div class="card" id="jDropCard">
<label class="drop" id="jDrop">
<div class="ico"><svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2.5"/><path d="M3 9h18M9 21V9"/></svg></div>
<div style="font-weight:700;margin-bottom:6px" data-i18n="jDrop"></div>
<div class="mut">JPG, JPEG, PNG</div>
<input id="jFile" type="file" accept="image/*" hidden>
</label>
</div>
<div id="jOut"></div>
</section>
<!-- Video analysis -->
<section id="pV" style="display:none">
<div class="card"><h2 data-i18n="vTitle"></h2><div class="mut" data-i18n="vSub"></div></div>
<div class="card" id="vDropCard">
<label class="drop" id="vDrop">
<div class="ico"><svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="5" width="15" height="14" rx="2"/><path d="m17 10 5-3v10l-5-3"/></svg></div>
<div style="font-weight:700;margin-bottom:6px" data-i18n="vDrop"></div>
<div class="mut">MP4, MOV, MKV, AVI</div>
<input id="vFile" type="file" accept="video/*" hidden>
</label>
</div>
<div id="vOut"></div>
</section>
<!-- File structure -->
<section id="pS" style="display:none">
<div class="card"><h2 data-i18n="sTitle"></h2><div class="mut" data-i18n="sSub"></div></div>
<div class="card" id="sDropCard">
<label class="drop" id="sDrop">
<div class="ico"><svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M8 13h2M8 17h2M12 13h4M12 17h4"/></svg></div>
<div style="font-weight:700;margin-bottom:6px" data-i18n="sDrop"></div>
<div class="mut">JPG, PNG, MP4, MOV</div>
<input id="sFile" type="file" accept="image/*,video/*" hidden>
</label>
</div>
<div id="sOut"></div>
</section>
<!-- PRNU -->
<section id="pP" style="display:none">
<div class="card">
<h2 data-i18n="pTitle"></h2>
<div class="mut" data-i18n="pSub"></div>
</div>
<div class="card">
<h2 data-i18n="pRefs"></h2>
<div class="mut" data-i18n="pRefsHint"></div>
<div class="row" style="margin-top:10px">
<button class="btn sec" id="pRefBtn" data-i18n="pickRefs"></button>
<input id="pRefs" type="file" accept="image/*,video/*" multiple hidden>
</div>
<div class="files" id="pRefList"></div>
</div>
<div class="card">
<h2 data-i18n="pQ"></h2>
<div class="row">
<button class="btn sec" id="pQBtn" data-i18n="pickQ"></button>
<input id="pQ" type="file" accept="image/*,video/*" hidden>
</div>
<div class="files" id="pQName"></div>
</div>
<div class="row" style="margin-bottom:14px"><button class="btn" id="pRun" disabled data-i18n="pRun"></button></div>
<div id="pOut"></div>
</section>
</main>
<script src="/ts-viewer.js"></script>
<script src="/ts-gps.js"></script>
<script src="/ts-ela.js"></script>
<script src="/ts-scene.js"></script>
<script src="/ts-report.js"></script>
<script>
const P=new URLSearchParams(location.search);
const LANG=P.get('lang')==='en'?'en':'ar';
document.documentElement.lang=LANG; document.documentElement.dir='rtl';
if(LANG!=='ar') document.documentElement.classList.add('lang-en');
if(P.get('theme')==='light') document.documentElement.dataset.theme='light';
const T={
ar:{tabJ:'كشف التلاعب',tabP:'مطابقة بصمة الكاميرا',
jTitle:'كشف التلاعب في الصورة',
jSub:'فحوص مستقلة منشورة علميًا: نموذج تحديد مواضع التلاعب، وADJPEG وNADJPEG، وأشباح JPEG، ومخطط DCT، وجداول التكميم، والصورة المصغّرة، وبصمة الملف. كل فحص يظهر كدليل مستقل بتفاصيله، ويُبنى الرأي من أوزانها، مع فصل سلامة المحتوى عن سجل المعالجة.',
jDrop:'اسحب الصورة إلى هنا أو اضغط للاختيار',analyzing:'جارٍ التحليل…',
vHigh:'مؤشرات قوية على التعديل',vMed:'مؤشرات تستدعي المراجعة',vLow:'لم تظهر مؤشرات تعديل واضحة',
findings:'النتائج',maps:'الخرائط',zoomHint:'اضغط على الخريطة لتكبيرها',original:'الصورة الأصلية',
details:'تفاصيل الضغط',quality:'جودة الحفظ التقديرية',stdTables:'جداول المكتبة القياسية',yes:'نعم',no:'لا',
dqScore:'مؤشر الضغط المزدوج',format:'الصيغة',size:'الأبعاد',thumb:'الصورة المصغّرة داخل الملف',current:'الصورة الحالية',
similarity:'التطابق',another:'صورة أخرى',elaBtn:'تحليل مستوى الخطأ (ELA)',
gTitle:'منحنى أشباح JPEG',gHelp:'يُعاد حفظ الصورة بكل الجودات من 50 إلى 100 ويُقاس الفرق. الانخفاض الأعمق (أخضر) هو جودة آخر حفظ وهو متوقع؛ وأي انخفاض واضح آخر بجودة أقل (أحمر) يعني أن الصورة حُفظت قبل ذلك بتلك الجودة. الحفظ السابق بجودة أعلى من الأخيرة لا يظهر.',
gWhole:'الصورة كاملة',gRegion:'المنطقة المحددة',gAxisQ:'الجودة',gLast:q=>`آخر حفظ ≈ ${q}`,gNoLast:'لم يتضح آخر حفظ',gPrev:q=>`حفظ سابق ≈ ${q}`,gNoPrev:'لا يظهر حفظ سابق',
gMapTitle:'خريطة الأشباح',gMapHelp:'حرّك الشريط لاختيار الجودة. المناطق الحمراء فيها «شبح» عند هذه الجودة: إذا غطّى الصورة كلها فهي إعادة حفظ، وإذا ظهر على منطقة واحدة فقط فقد تكون ملصوقة من مصدر آخر.',
gPick:'تحديد منطقة للمقارنة',gClear:'إلغاء التحديد',gPickHint:'اسحب مستطيلًا على المنطقة المشتبه بها لمقارنة منحناها بمنحنى الصورة كاملة.',
tabS:'بنية الملف',sTitle:'بنية الملف والعرض السداسي',sSub:'يعرض مكوّنات الملف بترتيبها ومواقعها، والبيانات الملحقة بعد نهاية الصورة، والنصوص المقروءة داخله مع إبراز أسماء البرامج والمنصات، والعرض السداسي (Hex) لبداية الملف ونهايته.',
sDrop:'اسحب الملف إلى هنا أو اضغط للاختيار',sNone:'لا توجد ملاحظات على بنية الملف.',sSize:'حجم الملف',sSegs:'مكوّنات الملف',sSegsSub:'كل مقطع بموقعه (Offset) وحجمه؛ وجود مقاطع غير معتادة أو ترتيب مختلف قد يدل على برنامج تحرير.',
sName:'المقطع',sLen:'الحجم (بايت)',sStr:'النصوص داخل الملف (Hex strings)',sStrSub:'النصوص المميّزة بالبرتقالي تذكر برامج تحرير أو منصات أو أدوات توليد.',sAll:n=>`عرض بقية النصوص (${n})`,
sHex:'العرض السداسي (Hex view)',sHexHead:'أول 1024 بايت من الملف',sHexTrail:'البيانات الموجودة بعد نهاية الصورة',sHexTail:'آخر 512 بايت من الملف',
sNote:'بنية الملف تكشف البرامج التي مرّ بها والمحتوى الملحق، لكنها لا تُثبت بمفردها تعديل محتوى الصورة.',
qtTitle:'جداول التكميم (Quantization tables)',qtSub:'الجدول 0 للإضاءة، و1 و2 للألوان. كل كاميرا وبرنامج يستخدم جداول مميّزة؛ مقارنتها تبيّن آخر برنامج حفظ الصورة.',
qtName:i=>i===0?'الجدول 0 (الإضاءة)':`الجدول ${i} (الألوان)`,qtStd:'قياسي',qtCustom:'خاص',
ptTitle:'خريطة التلاعب ببصمة الحسّاس (PRNU)',ptSub:'المناطق الملوّنة تغيب فيها بصمة الكاميرا رغم تطابق الصورة إجمالًا مع الجهاز — قد تكون ملصوقة أو معدّلة. تُطبَّق على منتصف الصورة.',ptFrac:'نسبة المناطق المشتبه بها',
fbTitle:'تقييم النتيجة',fbOk:'صحيحة',fbNo:'غير صحيحة',fbWhich:'ما النتيجة الصحيحة؟',fbNote:'ملاحظة (اختياري)',fbSend:'إرسال التقييم',fbCancel:'إلغاء',
fbDone:'تم تسجيل التقييم. شكرًا لك.',fbErr:'تعذّر الإرسال، يُرجى المحاولة مرة أخرى.',fbAuth:'الصورة أصلية',fbManip:'الصورة معدّلة',fbSame:'من الجهاز نفسه',fbDiff:'من جهاز آخر',
platTitle:'المنصة التي مرّت بها الصورة',strong:'مؤشرات قوية',possible:'محتمل',noPlat:'لم تُطابق سمات الملف منصة معروفة (قد يكون أصليًا أو مُعدًّا ببرنامج).',
progressive:'ترميز تدريجي',subsampling:'أخذ عينات الألوان',icc:'ملف الألوان (ICC)',
platNote:'يعتمد التحديد على سمات معروفة لكل منصة (الأبعاد، جداول الضغط، البيانات المتبقية، اسم الملف)، وقد تتغيّر هذه السمات أو تتشابه بين فيسبوك وإنستغرام، فهو مؤشر للتوجيه.',
noteJ:'هذه الفحوص مؤشرات وليست دليلًا قاطعًا: إعادة الحفظ عبر المنصات وتطبيقات المراسلة تُحدث بعض الآثار نفسها دون تلاعب، وغياب المؤشرات لا يُثبت الأصالة.',
grpContent:'سلامة المحتوى',grpHistory:'سجل المعالجة والتوثيق',dTabRes:'النتيجة',dTabWhy:'السبب',dTabRef:'المرجع',dTabLim:'الحدود',
stChecks:'فحوص منطبقة',stStrong:'مؤشرات قوية',stReview:'تستدعي المراجعة',visTitle:'التحليل البصري',vMaps:'الخرائط',vRegions:'المناطق',vGhosts:'الأشباح',vDct:'معاملات DCT',vQt:'جداول التكميم',vThumb:'المصغّرة',
toolsTitle:'أدوات يدوية',techTitle:'التفاصيل التقنية',noRegions:'لا توجد مناطق تتفق عليها أكثر من طريقة.',heroSub:{high:'أكثر من طريقة مستقلة رصدت أثر تعديل.',medium:'رُصد مؤشر يحتاج إلى تأكيد بفحص آخر.',low:'لم ترصد الفحوص المنطبقة أثرًا واضحًا للتعديل.'},
noHist:'الملف أصلي من الجهاز على الأرجح',
evTitle:'الأدلة',evSub:'كل زر فحص مستقل. اضغطي عليه لعرض ما وُجد، ولماذا يُعدّ مؤشرًا، والطريقة ومرجعها العلمي، والفلتر المقابل في Amped Authenticate، وحدود الطريقة، ووزنه في الرأي.',
rSusp:'مؤشر قوي',rAtt:'يستدعي المراجعة',rOk:'متسق',rNa:'لا ينطبق',rInfo:'معلومة',
dFound:'ما وُجد',dWhy:'لماذا يُعدّ مؤشرًا',dMethod:'الطريقة',dAmped:'الفلتر المقابل في Amped Authenticate',dRef:'المرجع العلمي',dLimits:'حدود الطريقة',dMeasure:'القياسات',dWeight:'الوزن في الرأي',dMap:'الخريطة',
wText:(r,st,c)=>`موثوقية الطريقة ${r}%. قوة هذا الدليل وحده ${st} من 100، وحصته من درجة الاشتباه النهائية ${c} نقطة.`,wNone:'لا تدخل في درجة الاشتباه (تخص سجل المعالجة أو للتوثيق).',
opContent:'سلامة المحتوى',opHistory:'سجل المعالجة',opScore:s=>`درجة الاشتباه ${s} من 100`,
hOrig:'لا مؤشرات على إعادة الحفظ أو القص؛ قد يكون الملف أصليًا من الجهاز.',hEdited:'الملف ليس الأصل الصادر من الجهاز:',
hf:{qt:'حُفظ بجداول برنامج أو منصة',double:'حُفظ بصيغة JPEG أكثر من مرة',cropped:'قُصّ بعد الحفظ',platform:'مرّ بمنصة تواصل',resized:'أُعيد تحجيمه',container:'يحمل علامات برنامج تحرير أو تحويل',gop:'بنية إطارات غير منتظمة',vpf:'رُمِّز أكثر من مرة'},
hNote:'إعادة الحفظ أو القص ليست تلاعبًا بالمحتوى بالضرورة، لكنها تعني أن الملف ليس الأصل، وتُضعف بعض الفحوص.',
opLimited:'عدد الفحوص التي انطبقت على هذه الصورة قليل، لذا الرأي محدود ولا يكفي فحص واحد لرفعه.',opHow:'كيف حُسب الرأي',opHowText:(n)=>`تُجمع نتائج ${n} فحوص مستقلة كأدلة مستقلة: كل مؤشر يرفع الدرجة بقدر قوته وموثوقية طريقته، والفحص الذي لم يجد شيئًا لا يخفضها (لأنه قد يبحث عن نوع آخر من التلاعب). 50 فأكثر مع مؤشرين مستقلين: مؤشرات قوية، ومن 28 إلى 49: يستدعي المراجعة.`,
ampedNote:'TruScan لا يستخدم برنامج Amped. أسماء الفلاتر مذكورة ليتمكّن أي خبير من إعادة الفحص نفسه ببرنامج معتمد والتحقق من النتيجة.',
regTitle:'المناطق المشتبه بها',regSub:'قصّات من الصورة للمناطق التي ظهرت في خريطة الدمج، مع الطرق التي اتفقت عليها.',regArea:a=>`نحو ${a}% من الصورة`,regBy:'رصدتها:',
hashTitle:'بصمة الملف',
dctTitle:'مخطط معاملات DCT (DCT Plot)',dctSub:'مدرّج قيم معامل DCT في كل كتل الصورة. الحفظ مرة واحدة يعطي شكلًا أملس متناقصًا؛ الحفظ مرتين يعطي «مشطًا» تتباعد أعمدته بانتظام، وتباعدها يكشف جودة الحفظ الأول. الأعمدة الحمراء قيم يجب أن تكون شبه فارغة لو حُفظت الصورة كلها مرتين؛ امتلاؤها يعني أن جزءًا من الصورة لم يمر بالحفظ الأول.',
dctCoef:'المعامل',dctQ2:'خطوة الحفظ الأخير',dctQ1:'خطوة الحفظ الأول المقدّرة',dctFirst:'جودة الحفظ الأول المقدّرة',dctNone:'لا يظهر مشط',dctAll:n=>`مشط في ${n} من 15 معاملًا`,
gtTitle:'خريطة الأشباح لكل جودة',
tabV:'تحليل الفيديو',vTitle:'تحليل بنية الفيديو',vSub:'يقرأ بنية الفيديو من الملف مباشرة: بيانات الحاوية والمرمِّز، وأنواع الإطارات (I وP وB) وطول GOP، وكشف الترميز المزدوج (VPF) مع تقدير GOP الترميز الأول. كل فحص يظهر كدليل مستقل بتفاصيله.',
vDrop:'اسحبي الفيديو هنا أو اضغطي للاختيار',vFrames:'بنية الإطارات',vFramesSub:'كل عمود إطار وارتفاعه حجمه. أحمر: إطار I (كامل)، أزرق: P، رمادي: B، برتقالي: قمم VPF (إطارات P كبرت بسبب ترميز سابق).',
vInfo:'خصائص الفيديو',vCodec:'الترميز',vDur:'المدة',vFps:'معدل الإطارات',vBr:'معدل البت',vRes:'الدقة',
repTitle:'التقرير',repSub:'تقرير قابل للطباعة أو الحفظ PDF، يضم كل الفحوص التي أُجريت في هذه الجلسة: البصمة، والرأي، وكل دليل مع سببه وطريقته ومرجعه العلمي والفلتر المقابل في Amped Authenticate، والقصّات والخرائط، والمنهجية والحدود.',repAr:'التقرير بالعربية',repEn:'English report',
scTitle:'الظلال والانعكاسات',scSub:'فحص يدوي: ترسمين خطوطًا من الظلال إلى الأجسام، أو من الأجسام إلى انعكاساتها، ويتحقق البرنامج هندسيًا من التقائها في نقطة واحدة. النتيجة تُضاف إلى التقرير.',scSh:'فحص الظلال',scRef:'فحص الانعكاسات',scOk:'متسقة',scBad:'غير متسقة',scLines:n=>`${n} خطوط`,
pVidNote:n=>`الملف المفحوص فيديو: استُخرجت بصمته من ${n} إطارًا.`,
pTitle:'مطابقة بصمة حسّاس الكاميرا (PRNU)',
pSub:'لكل حسّاس كاميرا بصمة دقيقة ثابتة تظهر في كل صورة يلتقطها. تُستخرج البصمة من صور مرجعية مؤكدة من الجهاز، ثم تُقارن بالصورة محل الفحص لمعرفة ما إذا كانت ملتقطة بالجهاز نفسه.',
pRefs:'1) الصور أو الفيديوهات المرجعية من الجهاز',
pRefsHint:'من 10 إلى 30 صورة أصلية من الجهاز نفسه وبالدقة نفسها (يُفضَّل مشاهد فاتحة ومتجانسة مثل السماء أو الجدران). يجب أن تكون منقولة مباشرة من الجهاز، لا عبر واتساب أو مواقع التواصل.',
pickRefs:'اختيار المراجع',pQ:'2) الصورة أو الفيديو محل الفحص',pickQ:'اختيار الملف',pRun:'بدء المطابقة',
files:n=>`${n} صورة مختارة`,
match:'الملف ملتقط بالجهاز نفسه على الأرجح',noMatch:'لا تتطابق البصمة مع الجهاز',
pceExp:t=>`قيمة PCE: كلما ارتفعت زاد التطابق. الحد المعتمد في الأبحاث للتطابق هو ${t}.`,
sizeErr:(r,q)=>`لا يمكن المقارنة: أبعاد الصورة (${q}) تختلف عن أبعاد الصور المرجعية (${r}). البصمة لا تبقى بعد تغيير الدقة أو القص، وهذا يحدث عادة عند الإرسال عبر واتساب أو مواقع التواصل.`,
noRefs:'لم تُقبل أي صورة مرجعية — تأكد أن الصور المرجعية بالدقة نفسها.',
refsUsed:n=>`استُخدمت ${n} صورة مرجعية`,
fewRefs:'عدد الصور المرجعية قليل؛ يُفضَّل 10 صور على الأقل لنتيجة موثوقة.',
noteP:'المطابقة مؤشر علمي قوي لكنه ليس معتمدًا كدليل رسمي من هذا البرنامج. النتيجة السلبية لا تنفي بالضرورة أن الصورة من الجهاز إذا كانت قد عُدِّلت أو أُعيد تحجيمها.'},
en:{tabJ:'Tampering detection',tabP:'Camera fingerprint match',
jTitle:'Image tampering detection',
jSub:'Independent, published checks: forgery localization model, ADJPEG and NADJPEG, JPEG ghosts, DCT plot, quantization tables, thumbnail and file hash. Each appears as its own piece of evidence with details; the opinion is built from their weights, keeping content integrity separate from processing history.',
jDrop:'Drag an image here or tap to choose',analyzing:'Analyzing…',
vHigh:'Strong signs of editing',vMed:'Signs that need review',vLow:'No clear signs of editing',
findings:'Findings',maps:'Maps',zoomHint:'Tap a map to zoom',original:'Original image',
details:'Compression details',quality:'Estimated save quality',stdTables:'Standard library tables',yes:'Yes',no:'No',
dqScore:'Double-compression indicator',format:'Format',size:'Dimensions',thumb:'Thumbnail stored in the file',current:'Current picture',
similarity:'Similarity',another:'Another image',elaBtn:'Error Level Analysis (ELA)',
gTitle:'JPEG ghost plot',gHelp:'The image is re-saved at every quality from 50 to 100 and the difference measured. The deepest dip (green) is the last save quality and is expected; another clear dip at a lower quality (red) means it was saved before at that quality. An earlier save at a higher quality does not show.',
gWhole:'Whole image',gRegion:'Selected region',gAxisQ:'Quality',gLast:q=>`last save ≈ ${q}`,gNoLast:'last save unclear',gPrev:q=>`earlier save ≈ ${q}`,gNoPrev:'no earlier save visible',
gMapTitle:'Ghost map',gMapHelp:'Move the slider to choose a quality. Red areas have a ghost at that quality: across the whole image it is a re-save; on one area only, that area may have been pasted from another source.',
gPick:'Select a region to compare',gClear:'Clear selection',gPickHint:'Drag a rectangle over the suspicious area to compare its curve with the whole image.',
tabS:'File structure',sTitle:'File structure & hex view',sSub:'Shows the file blocks with their offsets, data appended after the end of the image, readable strings with software and platform names highlighted, and a hex view of the start and end of the file.',
sDrop:'Drag a file here or tap to choose',sNone:'No remarks on the file structure.',sSize:'File size',sSegs:'File blocks',sSegsSub:'Each block with its offset and size; unusual blocks or order can point to editing software.',
sName:'Block',sLen:'Size (bytes)',sStr:'Text inside the file (hex strings)',sStrSub:'Strings in amber name editing software, platforms or generators.',sAll:n=>`Show the remaining strings (${n})`,
sHex:'Hex view',sHexHead:'First 1024 bytes',sHexTrail:'Data after the end of the image',sHexTail:'Last 512 bytes',
sNote:'File structure reveals the software a file passed through and appended content, but on its own it does not prove the picture content was changed.',
qtTitle:'Quantization tables',qtSub:'Table 0 is luminance, 1 and 2 are colour. Cameras and programs use distinctive tables; comparing them shows the last program that saved the image.',
qtName:i=>i===0?'Table 0 (luminance)':`Table ${i} (colour)`,qtStd:'standard',qtCustom:'custom',
ptTitle:'PRNU tampering map',ptSub:'Coloured areas lack the camera fingerprint although the photo matches the device overall — possibly pasted or edited. Applied to the centre of the image.',ptFrac:'Share of suspicious areas',
fbTitle:'Rate this result',fbOk:'Correct',fbNo:'Incorrect',fbWhich:'What is the correct result?',fbNote:'Note (optional)',fbSend:'Submit',fbCancel:'Cancel',
fbDone:'Evaluation recorded. Thank you.',fbErr:'Could not send — please try again.',fbAuth:'Authentic',fbManip:'Manipulated',fbSame:'Same device',fbDiff:'Different device',
platTitle:'Platform the image passed through',strong:'strong signs',possible:'possible',noPlat:'The file traits did not match a known platform (it may be an original or saved by software).',
progressive:'Progressive encoding',subsampling:'Chroma subsampling',icc:'Colour profile (ICC)',
platNote:'Based on known per-platform traits (dimensions, tables, remaining metadata, file name). These change over time and Facebook/Instagram can look alike, so treat it as a lead.',
noteJ:'These checks are indicators, not proof: re-saving by platforms and messaging apps leaves some of the same traces without tampering, and no signs does not prove authenticity.',
grpContent:'Content integrity',grpHistory:'Processing history and documentation',dTabRes:'Result',dTabWhy:'Why',dTabRef:'Reference',dTabLim:'Limits',
stChecks:'checks applied',stStrong:'strong indicators',stReview:'need review',visTitle:'Visual analysis',vMaps:'Maps',vRegions:'Regions',vGhosts:'Ghosts',vDct:'DCT',vQt:'Quantization',vThumb:'Thumbnail',
toolsTitle:'Manual tools',techTitle:'Technical details',noRegions:'No area is shared by more than one method.',heroSub:{high:'More than one independent method found traces of editing.',medium:'An indicator was found that needs confirmation by another check.',low:'The applicable checks found no clear trace of editing.'},
noHist:'Likely the device original',
evTitle:'Evidence',evSub:'Each button is an independent check. Tap it to see what was found, why it is an indicator, the method and its reference, the matching Amped Authenticate filter, the method limits, and its weight in the opinion.',
rSusp:'strong indicator',rAtt:'needs review',rOk:'consistent',rNa:'not applicable',rInfo:'information',
dFound:'What was found',dWhy:'Why it is an indicator',dMethod:'Method',dAmped:'Matching Amped Authenticate filter',dRef:'Scientific reference',dLimits:'Limits of the method',dMeasure:'Measurements',dWeight:'Weight in the opinion',dMap:'Map',
wText:(r,st,c)=>`Method reliability ${r}%. Strength of this indicator alone ${st}/100; its share of the final suspicion score ${c} points.`,wNone:'Not part of the suspicion score (processing history or documentation).',
opContent:'Content integrity',opHistory:'Processing history',opScore:s=>`Suspicion score ${s} / 100`,
hOrig:'No sign of re-saving or cropping; the file may be the device original.',hEdited:'The file is not the device original:',
hf:{qt:'saved with program or platform tables',double:'saved as JPEG more than once',cropped:'cropped after saving',platform:'passed through a social platform',resized:'resized',container:'carries editing/conversion software tags',gop:'irregular frame structure',vpf:'encoded more than once'},
hNote:'Re-saving or cropping is not necessarily content tampering, but the file is not the original and some checks become weaker.',
opLimited:'Few checks applied to this picture, so the opinion is limited; one check alone cannot raise it.',opHow:'How the opinion is computed',opHowText:(n)=>`Results of ${n} independent checks are combined as independent evidence: each indicator raises the score by its strength and its method's reliability; a check that found nothing does not lower it (it may look for another kind of manipulation). 50 or more with two independent indicators: strong signs; 28–49: needs review.`,
ampedNote:'TruScan does not run Amped software. Filter names are given so any examiner can repeat the same analysis with certified software and verify the result.',
regTitle:'Suspicious regions',regSub:'Crops of the areas highlighted by the fusion map, with the methods that agree on them.',regArea:a=>`about ${a}% of the picture`,regBy:'Found by:',
hashTitle:'File hash',
dctTitle:'DCT plot',dctSub:'Histogram of one DCT coefficient over all blocks. A single save gives a smooth, decaying shape; a double save gives a comb of regularly spaced bars whose spacing reveals the first save quality. Red bars are values that should be nearly empty if the whole picture was saved twice; if they are filled, part of the picture skipped the first save.',
dctCoef:'Coefficient',dctQ2:'Last save step',dctQ1:'Estimated first save step',dctFirst:'Estimated first save quality',dctNone:'no comb',dctAll:n=>`comb in ${n} of 15 coefficients`,
gtTitle:'Ghost map per quality',
tabV:'Video analysis',vTitle:'Video structure analysis',vSub:'Reads the video structure directly from the file: container and encoder data, frame types (I, P, B) and GOP length, and double-encoding detection (VPF) with an estimate of the first GOP. Each check appears as its own piece of evidence.',
vDrop:'Drop a video here or tap to choose',vFrames:'Frame structure',vFramesSub:'Each bar is a frame; its height is its size. Red: I-frame (full), blue: P, grey: B, orange: VPF peaks (P-frames enlarged by an earlier encoding).',
vInfo:'Video properties',vCodec:'Codec',vDur:'Duration',vFps:'Frame rate',vBr:'Bitrate',vRes:'Resolution',
repTitle:'Report',repSub:'A printable report (or PDF) covering every check run in this session: hash, opinion, each piece of evidence with its reason, method, scientific reference and matching Amped Authenticate filter, crops and maps, methodology and limits.',repAr:'Arabic report',repEn:'English report',
scTitle:'Shadows and reflections',scSub:'Manual check: draw lines from shadows to objects, or from objects to their reflections; the tool checks geometrically that they meet at one point. The result is added to the report.',scSh:'Shadow check',scRef:'Reflection check',scOk:'consistent',scBad:'inconsistent',scLines:n=>`${n} lines`,
pVidNote:n=>`The questioned file is a video: its fingerprint was estimated from ${n} frames.`,
pTitle:'Camera sensor fingerprint (PRNU)',
pSub:'Every camera sensor leaves a faint, fixed pattern in each photo. A fingerprint is estimated from confirmed reference photos of a device and compared with the questioned photo to tell whether the same device took it.',
pRefs:'1) Reference photos or videos from the device',
pRefsHint:'10 to 30 original photos from the same device at the same resolution (bright, plain scenes such as sky or walls work best), copied directly from the device — not via WhatsApp or social media.',
pickRefs:'Choose references',pQ:'2) Questioned photo or video',pickQ:'Choose file',pRun:'Start comparison',
files:n=>`${n} photos selected`,
match:'The file was most likely captured by this device',noMatch:'The fingerprint does not match this device',
pceExp:t=>`PCE value: higher means a stronger match. The research threshold for a match is ${t}.`,
sizeErr:(r,q)=>`Cannot compare: the photo size (${q}) differs from the reference size (${r}). The fingerprint does not survive resizing or cropping, which usually happens when sent via WhatsApp or social media.`,
noRefs:'No reference photo was accepted — make sure the references share the same resolution.',
refsUsed:n=>`${n} reference photos used`,
fewRefs:'Few reference photos; at least 10 are recommended for a reliable result.',
noteP:'A match is a strong scientific indicator but this program is not certified evidence. A negative result does not rule out the device if the photo was edited or resized.'}
}[LANG];
document.querySelectorAll('[data-i18n]').forEach(e=>{const v=T[e.dataset.i18n]; if(typeof v==='string') e.textContent=v;});
const $=id=>document.getElementById(id);
const esc=s=>String(s==null?'':s).replace(/[&<>"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]));
const COL={high:'var(--bad)',medium:'var(--warn)',info:'var(--info)'};
function tab(k){[['tJ','pJ'],['tP','pP'],['tV','pV'],['tS','pS']].forEach(([b,p])=>{$(b).classList.toggle('on',b===k);$(p).style.display=b===k?'':'none';});}
$('tJ').onclick=()=>tab('tJ'); $('tP').onclick=()=>tab('tP'); $('tS').onclick=()=>tab('tS'); $('tV').onclick=()=>tab('tV');
// ---------- result evaluation ----------
function feedback(section, predicted, options, details){
const id='fb'+Math.random().toString(36).slice(2,8);
setTimeout(()=>{
const el=document.getElementById(id); if(!el) return;
let choice=null;
const send=(ok,correct)=>{
const note=(el.querySelector('input')||{}).value||'';
fetch('/api/feedback',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify({section,verdict_ok:ok,predicted,correct:ok?predicted:correct,note,details:details||{}})})
.then(r=>{el.innerHTML=r.ok?`<div style="color:var(--ok);font-weight:700;font-size:13px">${T.fbDone}</div>`:`<div style="color:var(--bad)">${T.fbErr}</div>`;})
.catch(()=>{el.innerHTML=`<div style="color:var(--bad)">${T.fbErr}</div>`;});
};
const ask=()=>{
el.innerHTML=`<div style="font-weight:700;font-size:13px;margin-bottom:8px">${T.fbTitle}</div><button class="ok">${T.fbOk}</button><button class="no">${T.fbNo}</button>`;
el.querySelector('.ok').onclick=()=>send(true);
el.querySelector('.no').onclick=wrong;
};
const wrong=()=>{
el.innerHTML=`<div style="font-weight:700;font-size:13px;margin-bottom:8px">${T.fbWhich}</div>`+
options.filter(o=>o.key!==predicted).map(o=>`<button data-k="${o.key}">${o.label}</button>`).join('')+
`<input maxlength="300" placeholder="${T.fbNote}"><button class="send" disabled>${T.fbSend}</button><button class="cancel">${T.fbCancel}</button>`;
el.querySelectorAll('button[data-k]').forEach(b=>b.onclick=()=>{choice=b.dataset.k;el.querySelectorAll('button[data-k]').forEach(x=>x.classList.toggle('sel',x===b));el.querySelector('.send').disabled=false;});
el.querySelector('.send').onclick=()=>choice&&send(false,choice);
el.querySelector('.cancel').onclick=ask;
};
ask();
},0);
return `<div class="card fb" id="${id}"></div>`;
}
// ---------- JPEG ----------
const drop=$('jDrop');
['dragover','dragenter'].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.add('over');}));
['dragleave','drop'].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.remove('over');}));
drop.addEventListener('drop',e=>{const f=e.dataTransfer.files[0]; if(f) runJ(f);});
$('jFile').onchange=e=>{const f=e.target.files[0]; if(f) runJ(f); e.target.value='';};
window.TS_CASE={scene:[]};
function reportCard(){
return `<div class="card"><h2>${T.repTitle}</h2><div class="mut" style="margin-bottom:10px">${T.repSub}</div><div class="row">`+
`<button class="btn" data-rep="ar">${T.repAr}</button><button class="btn sec" data-rep="en">${T.repEn}</button></div></div>`;
}
function bindReport(root){ root.querySelectorAll('[data-rep]').forEach(b=>b.onclick=()=>window.tsReport&&window.tsReport(window.TS_CASE,b.dataset.rep)); }
function sceneCard(){
return `<div class="card"><h2>${T.scTitle}</h2><div class="mut" style="margin-bottom:10px">${T.scSub}</div><div class="row">`+
`<button class="btn sec" data-scene="shadows">${T.scSh}</button><button class="btn sec" data-scene="reflections">${T.scRef}</button></div><div id="sceneList" style="margin-top:10px"></div></div>`;
}
function drawScene(){
const el=$('sceneList'); if(!el) return;
el.innerHTML=TS_CASE.scene.map(r=>`<div class="f"><i style="background:${r.consistent?'var(--ok)':'var(--bad)'}"></i><div><b>${r.mode==='shadows'?T.scSh:T.scRef}</b> — ${r.consistent?T.scOk:T.scBad} (${T.scLines(r.n)})<br><img src="${r.image}" data-z="${r.image}" style="max-width:260px;border-radius:8px;margin-top:6px;cursor:zoom-in"></div></div>`).join('');
el.querySelectorAll('img[data-z]').forEach(i=>i.onclick=()=>window.tsZoom&&window.tsZoom(i.dataset.z));
}
function runJ(file){
const url=URL.createObjectURL(file);
TS_CASE.scene=[]; TS_CASE.tamperName=file.name;
$('jDropCard').style.display='none';
$('jOut').innerHTML=`<div class="card"><span class="spin"></span> ${T.analyzing}</div>`;
const fd=new FormData(); fd.append('file',file);
fetch('/api/jpeg-forensics',{method:'POST',body:fd}).then(r=>r.json()).then(d=>{
if(d.error) throw new Error(d.error);
TS_CASE.tamper={d:d,name:file.name};
renderJ(d,url);
if(d.format==='JPEG') ghostCard(file);
}).catch(e=>{$('jOut').innerHTML=`<div class="card" style="color:var(--bad)">${esc(e.message||e)}</div>${againBtn()}`;bindAgain();});
}
function againBtn(){return `<div class="row"><button class="btn sec" id="jAgain">${T.another}</button></div>`;}
function bindAgain(){const b=$('jAgain'); if(b) b.onclick=()=>{$('jOut').innerHTML='';$('jDropCard').style.display='';};}
const ICP={
scan:'<path d="M3 7V5a2 2 0 0 1 2-2h2M17 3h2a2 2 0 0 1 2 2v2M21 17v2a2 2 0 0 1-2 2h-2M7 21H5a2 2 0 0 1-2-2v-2"/><circle cx="12" cy="12" r="3.2"/><path d="M12 5.5v2M12 16.5v2M5.5 12h2M16.5 12h2"/>',
layers:'<path d="m12 3 9 5-9 5-9-5 9-5Z"/><path d="m3 13 9 5 9-5"/>',
grid:'<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 9h18M3 15h18M9 3v18M15 3v18"/>',
wave:'<path d="M2 12c2.5-5 5-5 7.5 0s5 5 7.5 0 3.5-3 5-2"/><path d="M2 18c2.5-3 5-3 7.5 0s5 3 7.5 0"/>',
image:'<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="9" cy="10" r="1.8"/><path d="m21 16-5-5L5 20"/>',
target:'<circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1.3"/>',
copy:'<rect x="8" y="8" width="13" height="13" rx="2"/><path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3"/>',
scale:'<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>',
table:'<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M9 10v10"/>',
chart:'<path d="M3 20h18"/><rect x="5" y="11" width="3" height="7"/><rect x="10.5" y="6" width="3" height="12"/><rect x="16" y="13" width="3" height="5"/>',
crop:'<path d="M6 2v14a2 2 0 0 0 2 2h14"/><path d="M18 22V8a2 2 0 0 0-2-2H2"/>',
share:'<circle cx="18" cy="5" r="2.5"/><circle cx="6" cy="12" r="2.5"/><circle cx="18" cy="19" r="2.5"/><path d="m8.2 10.8 7.6-4.5M8.2 13.2l7.6 4.5"/>',
hash:'<path d="M5 9h14M5 15h14M10 3 8 21M16 3l-2 18"/>',
film:'<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M7 3v18M17 3v18M3 8h4M3 16h4M17 8h4M17 16h4"/>',
repeat:'<path d="m17 2 4 4-4 4"/><path d="M3 11V9a3 3 0 0 1 3-3h15"/><path d="m7 22-4-4 4-4"/><path d="M21 13v2a3 3 0 0 1-3 3H3"/>',
file:'<path d="M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/><path d="M14 3v6h6"/>',
sun:'<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/>',
mirror:'<path d="M12 3v18"/><path d="M8 7 4 12l4 5"/><path d="m16 7 4 5-4 5"/>',
contrast:'<circle cx="12" cy="12" r="9"/><path d="M12 3v18a9 9 0 0 0 0-18Z" fill="currentColor"/>',
check:'<path d="m5 12 5 5L20 7"/>',alert:'<path d="M12 3 2 20h20L12 3Z"/><path d="M12 10v4M12 17h.01"/>',
chev:'<path d="m6 9 6 6 6-6"/>'};
const ico=k=>`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${ICP[k]||ICP.file}</svg>`;
const EVI={learned:'scan',adjpeg:'layers',dq_local:'layers',nadjpeg:'grid',ghost_local:'wave',thumbnail:'image',fusion:'target',clones:'copy',resampling:'scale',
qt:'table',dct:'chart',grid:'crop',platform:'share',hash:'hash',container:'file',gop:'film',vpf:'repeat'};
const HFI={qt:'table',double:'layers',cropped:'crop',platform:'share',resized:'scale',container:'file',gop:'film',vpf:'repeat'};
const RES={suspicious:['var(--bad)','rSusp'],attention:['var(--warn)','rAtt'],consistent:['var(--ok)','rOk'],na:['var(--mut)','rNa'],info:['var(--info)','rInfo']};
const L=(o,k)=>o[k+(LANG==='en'?'_en':'_ar')];
const LVC={high:'#ef4444',medium:'#f59e0b',low:'#22c55e'};
function gauge(score,level){
const c=LVC[level]||'#60a5fa', a=Math.max(0,Math.min(100,score==null?0:score));
const R=80,cx=100,cy=96, pt=t=>{const ang=Math.PI*(1-t);return [cx+R*Math.cos(ang),cy-R*Math.sin(ang)];};
const arc=(t0,t1)=>{const [x0,y0]=pt(t0),[x1,y1]=pt(t1);return `M${x0.toFixed(1)} ${y0.toFixed(1)} A${R} ${R} 0 0 1 ${x1.toFixed(1)} ${y1.toFixed(1)}`;};
const tick=t=>{const ang=Math.PI*(1-t),x0=cx+(R-14)*Math.cos(ang),y0=cy-(R-14)*Math.sin(ang),x1=cx+(R+6)*Math.cos(ang),y1=cy-(R+6)*Math.sin(ang);return `<line x1="${x0}" y1="${y0}" x2="${x1}" y2="${y1}" stroke="var(--mut)" stroke-width="1.2" opacity=".55"/>`;};
return `<div class="gauge"><svg viewBox="0 0 200 112"><path d="${arc(0,1)}" stroke="color-mix(in srgb,var(--mut) 22%,transparent)" stroke-width="13" fill="none" stroke-linecap="round"/>`+
(a>0?`<path d="${arc(0,Math.max(a,1.5)/100)}" stroke="${c}" stroke-width="13" fill="none" stroke-linecap="round"/>`:'')+tick(.28)+tick(.5)+`</svg>`+
`<div class="num"><b style="color:${c}">${score==null?'—':score}</b><span>${LANG==='en'?'suspicion / 100':'درجة الاشتباه من 100'}</span></div></div>`;
}
function infoBtn(id,text){return `<button class="info" data-info="${id}" aria-label="info">!</button><div class="ipop" id="${id}">${text}</div>`;}
function bindInfo(root){root.querySelectorAll('[data-info]').forEach(b=>b.onclick=()=>$(b.dataset.info).classList.toggle('on'));}
function heroHtml(d,url){
const o=d.opinion, lv=o.content_level, sc=o.content_score==null?null:Math.round(o.content_score*100);
const title=lv==='high'?T.vHigh:lv==='medium'?T.vMed:T.vLow;
const scored=d.evidence.filter(i=>i.contribution!=null);
const strong=d.evidence.filter(i=>i.group==='content'&&i.result==='suspicious').length, review=d.evidence.filter(i=>i.result==='attention').length;
const ev=scored.filter(i=>i.contribution>0).sort((a,b)=>b.contribution-a.contribution);
const cols=['#ef4444','#f59e0b','#a855f7','#3b82f6','#14b8a6','#ec4899'];
const chips=o.history_flags.length?o.history_flags.map(f=>`<span class="chip w">${ico(HFI[f]||'alert')}${esc(T.hf[f]||f)}</span>`).join(''):`<span class="chip g">${ico('check')}${T.noHist}</span>`;
return `<div class="card"><div class="hero">${gauge(sc,lv)}<div>`+
`<div class="mut" style="font-weight:700;letter-spacing:.3px">${T.opContent}</div><h3 style="color:${LVC[lv]}">${title}</h3>`+
`<div class="lead">${T.heroSub[lv]}${(o.overrides||[]).length?' '+esc(LANG==='en'?o.overrides[0][1]:o.overrides[0][0]):''}</div>`+
`<div class="mut" style="font-weight:700;margin-top:12px">${T.opHistory}</div><div class="chips">${chips}</div>`+
`<div class="stats"><div class="stat"><b>${o.checks_used}</b><span>${T.stChecks}</span></div><div class="stat"><b style="color:var(--bad)">${strong}</b><span>${T.stStrong}</span></div><div class="stat"><b style="color:var(--warn)">${review}</b><span>${T.stReview}</span></div></div>`+
`</div><div class="thumb"><img src="${url}" data-z="${url}"></div></div>`+
(ev.length?`<div class="cbar">`+ev.map((i,k)=>`<span title="${esc(L(i,'name'))} ${i.contribution}" style="width:${i.contribution}%;background:${cols[k%cols.length]}"></span>`).join('')+`</div>`+
`<div class="clegend">`+ev.slice(0,5).map((i,k)=>`<span><i style="background:${cols[k%cols.length]}"></i>${esc(L(i,'name'))} · ${i.contribution}</span>`).join('')+`</div>`:'')+
`<div style="display:flex;align-items:center;gap:8px;margin-top:12px"><span class="mut">${T.opHow}</span>${infoBtn('howPop',T.opHowText(o.checks_used)+(o.limited?'<br>'+T.opLimited:'')+'<br>'+T.hNote)}</div></div>`;
}
function tileHtml(i){
const r=RES[i.result]||RES.info, st=i.strength!=null?i.strength:null;
return `<button class="tile" data-ev="${i.key}" style="--c:${r[0]}"><div class="top"><div class="ic">${ico(EVI[i.key])}</div><div class="nm">${esc(L(i,'name'))}</div></div>`+
`<div class="st"><span>${T[r[1]]}</span>${st!=null?`<span style="direction:ltr">${Math.round(st)}</span>`:''}</div>`+
(st!=null?`<div class="meter"><span style="width:${Math.max(2,st)}%"></span></div>`:`<div class="meter"><span style="width:${i.result==='na'?0:100}%;opacity:.35"></span></div>`)+`</button>`;
}
function evidenceHtml(d,sid='j'){
const content=d.evidence.filter(i=>i.group==='content'), other=d.evidence.filter(i=>i.group!=='content');
const ord={suspicious:0,attention:1,consistent:2,info:3,na:4}, srt=a=>[...a].sort((x,y)=>ord[x.result]-ord[y.result]);
return `<div class="card"><div class="sech"><h2>${T.evTitle}</h2>${infoBtn(sid+'EvPop',T.evSub+'<br><br>'+T.ampedNote)}</div>`+
`<div id="${sid}Ev">`+(content.length?`<div class="grp">${T.grpContent}</div><div class="tiles">${srt(content).map(tileHtml).join('')}</div>`:'')+
(other.length?`<div class="grp">${T.grpHistory}</div><div class="tiles">${srt(other).map(tileHtml).join('')}</div>`:'')+
`</div><div id="${sid}EvDetail"></div></div>`;
}
function bindEvidence(d,sid='j'){
const box=$(sid+'EvDetail'), root=$(sid+'Ev'); let cur=null;
bindInfo(root.parentElement);
root.querySelectorAll('[data-ev]').forEach(b=>b.onclick=()=>{
const k=b.dataset.ev; root.querySelectorAll('[data-ev]').forEach(x=>x.classList.toggle('on',x===b&&cur!==k));
if(cur===k){cur=null;box.innerHTML='';return;} cur=k;
const i=d.evidence.find(e=>e.key===k), r=RES[i.result]||RES.info;
const mp=i.map&&(d.maps||[]).find(m=>m.key===i.map);
const meas=(i.measures||[]).map(m=>`<div class="mbox"><span>${esc(LANG==='en'?m[1]:m[0])}</span><b>${esc(m[2])}</b></div>`).join('')+
(i.contribution!=null?`<div class="mbox"><span>${LANG==='en'?'Strength':'قوة الدليل'}</span><b>${Math.round(i.strength)}/100</b></div><div class="mbox"><span>${LANG==='en'?'Share of score':'الحصة من الدرجة'}</span><b>${i.contribution}</b></div>`:'');
const panes={
res:`<div class="${mp?'dsplit':''}"><div><p>${esc(L(i,'found'))}</p>${meas?`<div class="mrow">${meas}</div>`:''}</div>${mp?`<img src="${mp.image}" data-z="${mp.image}">`:''}</div>`,
why:`<p>${esc(L(i,'why'))}</p>`,
ref:`<div class="lbl">${T.dAmped}</div><p>${esc(i.amped)}</p><div class="lbl">${T.dRef}</div><p class="ref">${esc(i.reference)}</p><div class="lbl">${T.dWeight}</div><p>${i.contribution!=null?T.wText(i.share,i.strength,i.contribution):T.wNone}</p>`,
lim:`<p>${esc(L(i,'limits'))}</p>`};
box.innerHTML=`<div class="dpanel" style="--c:${r[0]}"><div class="dhead"><div class="ic">${ico(EVI[i.key])}</div><b>${esc(L(i,'name'))}</b><span class="pill">${T[r[1]]}</span></div>`+
`<div style="padding:12px 14px 0"><div class="seg">`+[['res',T.dTabRes],['why',T.dTabWhy],['ref',T.dTabRef],['lim',T.dTabLim]].map(([k2,t],n)=>`<button data-p="${k2}" class="${n?'':'on'}">${t}</button>`).join('')+`</div></div>`+
`<div class="dbody">${panes.res}</div></div>`;
const body=box.querySelector('.dbody'), zoom=()=>body.querySelectorAll('img[data-z]').forEach(im=>im.onclick=()=>window.tsZoom&&window.tsZoom(im.dataset.z));
box.querySelectorAll('[data-p]').forEach(bt=>bt.onclick=()=>{box.querySelectorAll('[data-p]').forEach(x=>x.classList.toggle('on',x===bt));body.innerHTML=panes[bt.dataset.p];zoom();});
zoom(); box.scrollIntoView({block:'nearest',behavior:'smooth'});
});
}
function visualHtml(d,url){
const q=d.quantization||{}, tabs=[['maps',T.vMaps]];
if(d.regions&&d.regions.length) tabs.push(['regions',T.vRegions]);
if(d.format==='JPEG') tabs.push(['ghosts',T.vGhosts]);
if(d.dct_plot) tabs.push(['dct',T.vDct]);
if(q.all_tables&&q.all_tables.length) tabs.push(['qt',T.vQt]);
if(d.thumbnail) tabs.push(['thumb',T.vThumb]);
const maps=[{key:'original',ar:T.original,en:T.original,image:url,help_ar:'',help_en:''}].concat(d.maps);
const pref=['fusion','learned','adjpeg','nadjpeg','clones','ghost','dq','resampling','reliability','lga'];
maps.sort((a,b)=>(a.key==='original'?-1:b.key==='original'?1:(pref.indexOf(a.key)+99)%99-(pref.indexOf(b.key)+99)%99));
let qt='';
if(q.all_tables) q.all_tables.forEach(t=>{const mx=Math.max(...t.values);
qt+=`<div><div style="font-weight:700;font-size:13px;margin-bottom:6px">${T.qtName(t.index)} <span class="badge">Q≈${t.quality}</span><span class="badge">${t.standard?T.qtStd:T.qtCustom}</span></div><div class="qt">`+
t.values.map(v=>`<span style="background:rgba(37,99,235,${(0.12+0.75*v/mx).toFixed(2)})">${v}</span>`).join('')+`</div></div>`;});
const nm=k=>{const i=d.evidence.find(e=>e.key===k);return i?L(i,'name'):k;};
window._VMAPS=maps;
return `<div class="card"><div class="sech"><h2>${T.visTitle}</h2></div><div class="seg" id="visSeg">`+tabs.map(([k,t],n)=>`<button data-v="${k}" class="${n?'':'on'}">${t}</button>`).join('')+`</div>`+
`<div class="pane" data-pane="maps" style="margin-top:12px"><div class="viewer"><img class="main" id="vMain" src="${maps[0].image}" data-z="${maps[0].image}"><div class="vcap" id="vCap"></div>`+
`<div class="strip" id="vStrip">`+maps.map((m,k)=>`<button data-m="${k}" class="${k?'':'on'}"><img src="${m.image}"><span>${esc(LANG==='en'?m.en:m.ar)}</span></button>`).join('')+`</div></div></div>`+
`<div class="pane" data-pane="regions" style="display:none;margin-top:12px"><div class="mut" style="margin-bottom:10px">${T.regSub}</div><div class="reg">`+
(d.regions||[]).filter(r=>r.crop).map(r=>`<div><img src="${r.crop}" data-z="${r.crop}"><div style="font-size:13px;margin-top:6px"><b>${T.regArea((r.area*100).toFixed(1))}</b></div><div class="mut">${T.regBy} ${r.methods.map(nm).map(esc).join(LANG==='en'?', ':'، ')}</div></div>`).join('')+`</div></div>`+
`<div class="pane" data-pane="ghosts" style="display:none;margin-top:12px"><div id="ghostSlot"></div></div>`+
`<div class="pane" data-pane="dct" style="display:none;margin-top:12px"><div class="card dct" id="dctCard"></div></div>`+
`<div class="pane" data-pane="qt" style="display:none;margin-top:12px"><div class="mut" style="margin-bottom:10px">${T.qtSub}</div><div class="grid">${qt}</div></div>`+
(d.thumbnail?`<div class="pane" data-pane="thumb" style="display:none;margin-top:12px"><div class="grid"><div class="map"><h3>${T.thumb}</h3><img src="${d.thumbnail.image}" data-z="${d.thumbnail.image}"></div><div class="map"><h3>${T.current}</h3><img src="${url}" data-z="${url}"></div></div><div class="kv" style="margin-top:8px"><span>${T.similarity}</span><span>${Math.round(d.thumbnail.similarity*100)}%</span></div></div>`:'')+
`</div>`;
}
function bindVisual(){
const seg=$('visSeg'); if(!seg) return; const card=seg.parentElement;
seg.querySelectorAll('[data-v]').forEach(b=>b.onclick=()=>{seg.querySelectorAll('[data-v]').forEach(x=>x.classList.toggle('on',x===b));
card.querySelectorAll('[data-pane]').forEach(p=>p.style.display=p.dataset.pane===b.dataset.v?'':'none');});
const maps=window._VMAPS, main=$('vMain'), cap=$('vCap');
const show=k=>{const m=maps[k]; main.src=m.image; main.dataset.z=m.image; cap.textContent=(LANG==='en'?m.help_en:m.help_ar)||''; $('vStrip').querySelectorAll('button').forEach((b,n)=>b.classList.toggle('on',n===k));};
$('vStrip').querySelectorAll('[data-m]').forEach(b=>b.onclick=()=>show(+b.dataset.m)); show(0);
}
function toolsHtml(url){
return `<div class="card"><div class="sech"><h2>${T.toolsTitle}</h2>${infoBtn('toolPop',T.scSub)}</div><div class="tools">`+
`<button class="tbtn" data-ela="${url}">${ico('contrast')}${T.elaBtn}</button>`+
`<button class="tbtn" data-scene="shadows">${ico('sun')}${T.scSh}</button><button class="tbtn" data-scene="reflections">${ico('mirror')}${T.scRef}</button></div><div id="sceneList" style="margin-top:10px"></div></div>`;
}
function techHtml(d){
const q=d.quantization||{}, pc=(d.platform||{}).candidates||[], tr=(d.platform||{}).traits||{};
return `<details class="tech"><summary>${T.techTitle}${ico('chev')}</summary><div class="in">`+
`<div class="kv"><span>${T.format}</span><span>${esc(d.format)}</span></div><div class="kv"><span>${T.size}</span><span>${d.size[0]} × ${d.size[1]}</span></div>`+
(q.quality!=null?`<div class="kv"><span>${T.quality}</span><span>${q.quality}</span></div><div class="kv"><span>${T.stdTables}</span><span>${q.standard_tables?T.yes:T.no}</span></div>`:'')+
(d.double_compression_score!=null?`<div class="kv"><span>${T.dqScore}</span><span>${d.double_compression_score}</span></div>`:'')+
(d.hashes?`<div class="kv"><span>MD5</span><span style="font:12px ui-monospace,monospace;word-break:break-all">${d.hashes.md5}</span></div><div class="kv"><span>SHA-256</span><span style="font:12px ui-monospace,monospace;word-break:break-all">${d.hashes.sha256}</span></div>`:'')+
(d.platform?`<div class="kv"><span>${T.platTitle}</span><span>${pc.length?pc.map(c=>esc(LANG==='en'?c.en:c.ar)+' ('+(c.level==='strong'?T.strong:T.possible)+')').join(', '):T.noPlat}</span></div>`+
`<div class="kv"><span>${T.progressive}</span><span>${tr.progressive==null?'—':(tr.progressive?T.yes:T.no)}</span></div><div class="kv"><span>${T.subsampling}</span><span>${tr.subsampling||'—'}</span></div>`+
`<div class="kv"><span>EXIF</span><span>${tr.exif?T.yes:T.no}</span></div><div class="kv"><span>${T.icc}</span><span>${tr.icc?T.yes:T.no}</span></div>`:'')+
`</div></details>`;
}
function renderJ(d,url){
const v=d.status==='high'?['high',T.vHigh]:d.status==='medium'?['medium',T.vMed]:['low',T.vLow];
let h='';
if(d.opinion&&d.evidence){ h+=heroHtml(d,url)+evidenceHtml(d)+visualHtml(d,url)+toolsHtml(url)+techHtml(d); }
else{
h+=`<div class="card"><div class="verdict ${v[0]}"><div><b>${v[1]}</b></div></div></div>`;
h+=`<div class="card"><h2>${T.findings}</h2>`+d.findings.map(f=>`<div class="f"><i style="background:${COL[f.level]}"></i><div>${esc(LANG==='en'?f.en:f.ar)}</div></div>`).join('')+`</div>`;
h+=`<div class="card"><h2>${T.maps}</h2><div class="grid"><div class="map"><h3>${T.original}</h3><img src="${url}" data-z="${url}"></div>`+d.maps.map(m=>`<div class="map"><h3>${esc(LANG==='en'?m.en:m.ar)}</h3><img src="${m.image}" data-z="${m.image}"></div>`).join('')+`</div></div><div id="ghostSlot"></div>`;
}
h+=`<div class="foot">`+reportCard()+feedback('tampering', d.status==='low'?'authentic':'manipulated',
[{key:'authentic',label:T.fbAuth},{key:'manipulated',label:T.fbManip}],
{status:d.status, learned:d.learned&&d.learned.score, dq:d.double_compression_score})+`</div>`;
h+=`<div class="note">${T.noteJ}</div>`+againBtn();
$('jOut').innerHTML=h; bindAgain(); bindReport($('jOut')); bindInfo($('jOut'));
$('jOut').querySelectorAll('[data-scene]').forEach(b=>b.onclick=()=>window.tsScene&&window.tsScene(url,b.dataset.scene,r=>{TS_CASE.scene.push(r);drawScene();}));
$('jOut').querySelectorAll('img[data-z]').forEach(i=>i.onclick=()=>window.tsZoom&&window.tsZoom(i.dataset.z||i.src));
$('jOut').querySelectorAll('[data-ela]').forEach(b=>b.onclick=()=>window.tsEla&&window.tsEla(b.dataset.ela));
if(d.evidence) bindEvidence(d);
bindVisual();
if(d.dct_plot) dctPlot(d.dct_plot);
}
function dctPlot(p){
const c=$('dctCard'); if(!c) return;
const first=p.coefficients.findIndex(x=>x.q1); let idx=first<0?0:first;
c.innerHTML=`<h2>${T.dctTitle}</h2><div class="mut" style="margin-bottom:10px">${T.dctSub}</div>`+
`<div class="row"><label>${T.dctCoef} <select id="dctSel">`+p.coefficients.map((x,k)=>`<option value="${k}">${x.index} (${x.uv[0]},${x.uv[1]})${x.q1?' ●':''}</option>`).join('')+`</select></label>`+
`<span class="badge">${p.double?T.dctAll(p.votes):T.dctNone}</span>${p.first_quality?`<span class="badge">${T.dctFirst}: ${p.first_quality}</span>`:''}</div><div id="dctSvg" style="margin-top:10px"></div>`;
const draw=()=>{
const x=p.coefficients[idx], H=x.hist, W=640, Hh=220, PL=10, PB=24, n=H.length, bw=(W-2*PL)/n, mx=Math.max(...H.filter((v,k)=>k!==40&&k>0&&k<H.length-1))||1;
const pop=new Set((x.populated||[]));
let svg=`<svg viewBox="0 0 ${W} ${Hh}" style="width:100%;direction:ltr">`;
H.forEach((v,k)=>{if(k===0||k===H.length-1) return; const val=k-40, hh=Math.min(1,v/mx)*(Hh-PB-10), clip=v>mx, fb=x.q1&&!pop.has(Math.abs(val))&&val!==0;
svg+=`<rect x="${PL+k*bw}" y="${Hh-PB-hh}" width="${Math.max(1,bw-1)}" height="${hh}" fill="${fb?'#ef4444':'#60a5fa'}"/>`;
if(fb&&hh<3) svg+=`<rect x="${PL+k*bw}" y="${Hh-PB-3}" width="${Math.max(1,bw-1)}" height="3" fill="#ef4444"/>`;
if(val%10===0) svg+=`<text x="${PL+k*bw+bw/2}" y="${Hh-6}" fill="var(--mut)" font-size="11" text-anchor="middle">${val}</text>`;});
svg+=`</svg>`;
$('dctSvg').innerHTML=svg+`<div class="kv"><span>${T.dctQ2}</span><span>${x.q2}</span></div><div class="kv"><span>${T.dctQ1}</span><span>${x.q1||'—'}</span></div>`;
};
$('dctSel').value=idx; $('dctSel').onchange=e=>{idx=+e.target.value;draw();}; draw();
}
// ---------- JPEG ghost plot ----------
function ghostCard(file){
const slot=$('ghostSlot'); if(!slot) return;
slot.innerHTML=`<div class="card"><h2>${T.gTitle}</h2><span class="spin"></span> ${T.analyzing}</div>`;
const fd=new FormData(); fd.append('file',file);
fetch('/api/jpeg-ghosts',{method:'POST',body:fd}).then(r=>r.json()).then(g=>{
if(g.error) throw new Error(g.error);
const Q=g.qualities, [nh,nw]=g.grid, raw=Uint8Array.from(atob(g.cube),c=>c.charCodeAt(0));
const texB=Uint8Array.from(atob(g.texture),c=>c.charCodeAt(0));
const tex=i=>(texB[i>>3]>>(7-(i&7)))&1;
const D=new Float32Array(raw.length); for(let i=0;i<raw.length;i++) D[i]=Math.exp(raw[i]/32)-1;
const N=nh*nw;
// per-block min/max across qualities for the maps
const mn=new Float32Array(N).fill(1e9), mx=new Float32Array(N);
for(let k=0;k<Q.length;k++) for(let i=0;i<N;i++){const v=D[k*N+i]; if(v<mn[i])mn[i]=v; if(v>mx[i])mx[i]=v;}
const curveFor=(sel)=>Q.map((q,k)=>{let s=0,n=0; for(let i=0;i<N;i++){ if(!tex(i)) continue; const y=(i/nw)|0,x=i%nw;
if(sel&&(x<sel[0]||x>sel[2]||y<sel[1]||y>sel[3])) continue; s+=D[k*N+i]; n++; } return n?s/n:0;});
const minima=(c)=>{const out=[]; for(let i=2;i<c.length-2;i++){const tr=(c[i-2]+c[i+2])/2; if(tr<=1e-9) continue; const r=c[i]/tr;
if(r<0.85&&c[i]<=c[i-1]&&c[i]<=c[i+1]) out.push({q:Q[i],depth:1-r});}
out.sort((a,b)=>b.depth-a.depth); if(!out.length) return [];
const last=out[0], prev=[];
for(let i=3;i<c.length-3;i++){ if(Q[i]>=last.q-2) continue;
const tr=((c[i-3]+c[i-2]+c[i-1])/3+(c[i+1]+c[i+2]+c[i+3])/3)/2; if(tr<=1e-9) continue; const r=c[i]/tr;
if(c[i]<=c[i-1]&&c[i]<=c[i+1]&&r<0.85) prev.push({q:Q[i],depth:1-r,role:'previous'}); }
prev.sort((a,b)=>b.depth-a.depth);
return [{...last,role:'last'}].concat(prev.slice(0,1), prev.slice(1,2).filter(m=>m.depth>=0.5));};
let sel=null, roiCurve=null, qIdx=Q.indexOf(g.minima[1]?g.minima[1].quality:70); if(qIdx<0) qIdx=0;
const W=640,H=230,PL=36,PR=10,PT=14,PB=30;
const plot=()=>{
const curves=[{c:g.curve,col:'#60a5fa',lab:T.gWhole,m:minima(g.curve)}]; if(roiCurve) curves.push({c:roiCurve,col:'#f59e0b',lab:T.gRegion,m:minima(roiCurve)});
const X=q=>PL+(q-Q[0])/(Q[Q.length-1]-Q[0])*(W-PL-PR);
let svg=`<svg viewBox="0 0 ${W} ${H}" style="width:100%;direction:ltr">`;
for(let q=50;q<=100;q+=10) svg+=`<line x1="${X(q)}" y1="${PT}" x2="${X(q)}" y2="${H-PB}" stroke="var(--line)"/><text x="${X(q)}" y="${H-PB+16}" fill="var(--mut)" font-size="11" text-anchor="middle">${q}</text>`;
svg+=`<text x="${(W+PL)/2}" y="${H-2}" fill="var(--mut)" font-size="11" text-anchor="middle">${T.gAxisQ}</text>`;
svg+=`<line x1="${X(Q[qIdx])}" y1="${PT}" x2="${X(Q[qIdx])}" y2="${H-PB}" stroke="#ef4444" stroke-dasharray="4 3"/>`;
curves.forEach(o=>{const lo=Math.min(...o.c),hi=Math.max(...o.c)||1,Y=v=>PT+(1-(v-lo)/(hi-lo||1))*(H-PT-PB);
svg+=`<polyline fill="none" stroke="${o.col}" stroke-width="2" points="${o.c.map((v,k)=>X(Q[k])+','+Y(v)).join(' ')}"/>`;
o.m.forEach(m=>{const k=Q.indexOf(m.q),x=X(m.q),y=Y(o.c[k]);
svg+=`<circle cx="${x}" cy="${y}" r="5" fill="${m.role==='last'?'#22c55e':'#ef4444'}" stroke="#fff" stroke-width="1.5"/><text x="${x}" y="${y+18}" font-size="11" font-weight="700" fill="${m.role==='last'?'#22c55e':'#ef4444'}" text-anchor="middle">${m.q}</text>`;});});
svg+=`</svg>`;
const legend=curves.map(o=>`<span style="color:${o.col};font-weight:700">■ ${o.lab}</span>`).join(' &nbsp; ');
const summary=curves.map(o=>{const l=o.m.find(m=>m.role==='last'),p=o.m.filter(m=>m.role==='previous');
return `<div class="f"><i style="background:${o.col}"></i><div><b>${o.lab}:</b> ${l?T.gLast(l.q):T.gNoLast}${p.length?' — '+T.gPrev(p.map(m=>m.q).join('، ')):' — '+T.gNoPrev}</div></div>`;}).join('');
$('gPlot').innerHTML=svg+`<div class="mut" style="margin-top:4px">${legend}</div>`+summary;
};
const draw=()=>{
const cv=$('gCanvas'), img=$('gImg'); if(!cv||!img.naturalWidth) return;
cv.width=nw; cv.height=nh; const ctx=cv.getContext('2d'), id=ctx.createImageData(nw,nh);
for(let i=0;i<N;i++){ if(!tex(i)) continue; const v=D[qIdx*N+i], gh=1-(v-mn[i])/((mx[i]-mn[i])||1);
const a=gh>0.75?Math.min(1,(gh-0.75)*4):0; id.data[i*4]=239;id.data[i*4+1]=68;id.data[i*4+2]=68;id.data[i*4+3]=Math.round(a*170);}
ctx.putImageData(id,0,0); cv.style.imageRendering='pixelated';
$('gQ').textContent=Q[qIdx];
};
slot.innerHTML=`<div class="card"><h2>${T.gTitle}</h2><div class="mut" style="margin-bottom:8px">${T.gHelp}</div><div id="gPlot"></div></div>`+
`<div class="card"><h2>${T.gMapTitle} <span class="badge">Q <span id="gQ"></span></span></h2><div class="mut" style="margin-bottom:8px">${T.gMapHelp}</div>`+
`<input type="range" id="gRange" min="0" max="${Q.length-1}" value="${qIdx}">`+
`<div class="gwrap" id="gWrap" style="margin-top:8px"><img id="gImg" src="${g.preview}"><canvas id="gCanvas"></canvas><div class="gsel" id="gSel"></div></div>`+
`<div class="row" style="margin-top:10px"><button class="btn sec" id="gRegionBtn">${T.gPick}</button><button class="btn sec" id="gClear" style="display:none">${T.gClear}</button></div>`+
`<div class="mut" id="gPickHint" style="display:none;margin-top:6px">${T.gPickHint}</div>`+
`<h3 style="font-size:14px;margin:14px 0 0">${T.gtTitle}</h3><div class="gt" id="gTiles"></div></div>`;
plot(); $('gImg').onload=draw; if($('gImg').complete) draw();
const tiles=$('gTiles');
[60,65,70,75,80,85,90,95].forEach(qq=>{const k=Q.indexOf(qq); if(k<0) return;
const el=document.createElement('div'); el.innerHTML=`<img src="${g.preview}"><canvas></canvas><b>Q ${qq}</b>`; tiles.appendChild(el);
const cv=el.querySelector('canvas'); cv.width=nw; cv.height=nh; const ctx=cv.getContext('2d'), id=ctx.createImageData(nw,nh);
for(let i=0;i<N;i++){ if(!tex(i)) continue; const v=D[k*N+i], gh=1-(v-mn[i])/((mx[i]-mn[i])||1);
const a=gh>0.75?Math.min(1,(gh-0.75)*4):0; id.data[i*4]=239;id.data[i*4+1]=68;id.data[i*4+2]=68;id.data[i*4+3]=Math.round(a*190);}
ctx.putImageData(id,0,0);
el.onclick=()=>{qIdx=k;$('gRange').value=k;draw();plot();$('gWrap').scrollIntoView({block:'center',behavior:'smooth'});};
});
$('gRange').oninput=e=>{qIdx=+e.target.value; draw(); plot();};
let picking=false,start=null;
$('gRegionBtn').onclick=()=>{picking=true;$('gPickHint').style.display='';};
$('gClear').onclick=()=>{sel=null;roiCurve=null;$('gSel').style.display='none';$('gClear').style.display='none';plot();};
const wrap=$('gWrap'), box=$('gSel');
const rel=e=>{const r=wrap.getBoundingClientRect();return [Math.min(1,Math.max(0,(e.clientX-r.left)/r.width)),Math.min(1,Math.max(0,(e.clientY-r.top)/r.height))];};
wrap.onpointerdown=e=>{if(!picking)return;e.preventDefault();try{wrap.setPointerCapture(e.pointerId);}catch(_){}start=rel(e);};
wrap.onpointermove=e=>{if(!picking||!start)return;const p=rel(e),r=wrap.getBoundingClientRect();
const x0=Math.min(start[0],p[0]),y0=Math.min(start[1],p[1]),x1=Math.max(start[0],p[0]),y1=Math.max(start[1],p[1]);
Object.assign(box.style,{display:'block',left:x0*r.width+'px',top:y0*r.height+'px',width:(x1-x0)*r.width+'px',height:(y1-y0)*r.height+'px'});
sel=[Math.floor(x0*nw),Math.floor(y0*nh),Math.min(nw-1,Math.floor(x1*nw)),Math.min(nh-1,Math.floor(y1*nh))];};
wrap.onpointerup=()=>{if(!picking||!start)return;picking=false;start=null;$('gPickHint').style.display='none';
if(sel&&sel[2]>=sel[0]&&sel[3]>=sel[1]){roiCurve=curveFor(sel);$('gClear').style.display='';plot();}};
}).catch(e=>{slot.innerHTML=`<div class="card"><h2>${T.gTitle}</h2><div style="color:var(--bad)">${esc(e.message||e)}</div></div>`;});
}
// ---------- File structure ----------
const sDrop=$('sDrop');
['dragover','dragenter'].forEach(ev=>sDrop.addEventListener(ev,e=>{e.preventDefault();sDrop.classList.add('over');}));
['dragleave','drop'].forEach(ev=>sDrop.addEventListener(ev,e=>{e.preventDefault();sDrop.classList.remove('over');}));
sDrop.addEventListener('drop',e=>{const f=e.dataTransfer.files[0]; if(f) runS(f);});
$('sFile').onchange=e=>{const f=e.target.files[0]; if(f) runS(f); e.target.value='';};
const hexRows=rows=>rows.map(r=>r.offset.toString(16).toUpperCase().padStart(8,'0')+' '+r.hex.padEnd(47,' ')+' '+esc(r.ascii)).join('\n');
function runS(file){
$('sDropCard').style.display='none';
$('sOut').innerHTML=`<div class="card"><span class="spin"></span> ${T.analyzing}</div>`;
const fd=new FormData(); fd.append('file',file);
fetch('/api/file-structure',{method:'POST',body:fd}).then(r=>r.json()).then(d=>{
if(d.error) throw new Error(d.error);
let h=`<div class="card"><h2>${T.findings}</h2>`+(d.findings.length?d.findings.map(f=>`<div class="f"><i style="background:${COL[f.level]}"></i><div>${esc(LANG==='en'?f.en:f.ar)}</div></div>`).join(''):`<div class="mut">${T.sNone}</div>`)+
`<div class="kv" style="margin-top:8px"><span>${T.format}</span><span>${esc(d.kind)}</span></div><div class="kv"><span>${T.sSize}</span><span>${d.size.toLocaleString()} B</span></div></div>`;
h+=`<div class="card"><h2>${T.sSegs}</h2><div class="mut" style="margin-bottom:8px">${T.sSegsSub}</div><div style="overflow:auto;max-height:340px"><table class="tbl"><tr><th>Offset</th><th>${T.sName}</th><th>${T.sLen}</th></tr>`+
d.segments.map(s=>`<tr><td>0x${s.offset.toString(16).toUpperCase()}</td><td>${esc(s.name)}${s.detail?` <span class="mut">(${esc(s.detail)})</span>`:''}</td><td>${s.size.toLocaleString()}</td></tr>`).join('')+`</table></div></div>`;
const fl=d.strings.filter(x=>x.flag), rest=d.strings.filter(x=>!x.flag);
h+=`<div class="card"><h2>${T.sStr}</h2><div class="mut" style="margin-bottom:8px">${T.sStrSub}</div>`+
fl.map(x=>`<div class="str flag">0x${x.offset.toString(16).toUpperCase()} — ${esc(x.text)}</div>`).join('')+
`<details><summary class="mut" style="cursor:pointer;margin-top:8px">${T.sAll(rest.length)}</summary>`+rest.slice(0,300).map(x=>`<div class="str">0x${x.offset.toString(16).toUpperCase()} — ${esc(x.text)}</div>`).join('')+`</details></div>`;
h+=`<div class="card"><h2>${T.sHex}</h2><div class="mut" style="margin-bottom:8px">${T.sHexHead}</div><div class="mono">${hexRows(d.hex_head)}</div>`+
(d.hex_trailing.length?`<div class="mut" style="margin:10px 0 8px;color:var(--bad)">${T.sHexTrail}</div><div class="mono">${hexRows(d.hex_trailing)}</div>`:'')+
(d.hex_tail.length?`<div class="mut" style="margin:10px 0 8px">${T.sHexTail}</div><div class="mono">${hexRows(d.hex_tail)}</div>`:'')+`</div>`;
h+=`<div class="note">${T.sNote}</div><div class="row"><button class="btn sec" id="sAgain">${T.another}</button></div>`;
$('sOut').innerHTML=h; $('sAgain').onclick=()=>{$('sOut').innerHTML='';$('sDropCard').style.display='';};
}).catch(e=>{$('sOut').innerHTML=`<div class="card" style="color:var(--bad)">${esc(e.message||e)}</div>`;$('sDropCard').style.display='';});
}
// ---------- Video ----------
$('vFile').onchange=e=>{const f=e.target.files[0]; if(f) runV(f); e.target.value='';};
function runV(file){
$('vDropCard').style.display='none';
$('vOut').innerHTML=`<div class="card"><span class="spin"></span> ${T.analyzing}</div>`;
const fd=new FormData(); fd.append('file',file);
fetch('/api/video-forensics',{method:'POST',body:fd}).then(r=>r.json()).then(d=>{
if(d.error) throw new Error(d.error);
TS_CASE.video={d:d,name:file.name};
const inf=d.info, o=d.opinion;
const hist=o.history_flags.length?`<b>${T.hEdited}</b><ul style="margin:6px 0 0;padding-inline-start:18px">`+o.history_flags.map(f=>`<li>${T.hf[f]||f}</li>`).join('')+`</ul>`:`<b>${T.hOrig}</b>`;
let h=`<div class="card"><div class="verdict ${o.history_flags.length?'medium':'low'}" style="flex-direction:column;gap:4px;align-items:flex-start"><div class="mut">${T.opHistory}</div><div style="font-size:13.5px;line-height:1.7">${hist}</div><div class="mut">${T.hNote}</div></div></div>`;
h+=evidenceHtml(d,'v');
h+=`<div class="card"><h2>${T.vFrames}</h2><div class="mut" style="margin-bottom:8px">${T.vFramesSub}</div>${framesSvg(d)}</div>`;
h+=`<div class="card"><h2>${T.vInfo}</h2>`+
`<div class="kv"><span>${T.vCodec}</span><span>${esc((inf.codec||'')+' '+(inf.profile||''))}</span></div>`+
`<div class="kv"><span>${T.vRes}</span><span>${inf.width}×${inf.height}</span></div>`+
`<div class="kv"><span>${T.vDur}</span><span>${(inf.duration||0).toFixed(1)}</span></div>`+
`<div class="kv"><span>${T.vFps}</span><span>${esc(inf.fps)}</span></div>`+
`<div class="kv"><span>${T.vBr}</span><span>${Math.round((inf.bitrate||0)/1000)} kbps</span></div>`+
`<div class="kv"><span>SHA-256</span><span style="font:12px ui-monospace,monospace;word-break:break-all">${d.hashes.sha256}</span></div></div>`;
h+=reportCard()+`<div class="row"><button class="btn sec" id="vAgain">${T.another}</button></div>`;
$('vOut').innerHTML=h; bindEvidence(d,'v'); bindReport($('vOut'));
$('vAgain').onclick=()=>{$('vOut').innerHTML='';$('vDropCard').style.display='';};
}).catch(e=>{$('vOut').innerHTML=`<div class="card" style="color:var(--bad)">${esc(e.message||e)}</div>`;$('vDropCard').style.display='';});
}
function framesSvg(v){
const sz=v.frame_sizes||[], ty=v.frame_types||'', n=Math.min(sz.length,1500); if(!n) return '';
const W=1000,H=180,mx=Math.max(...sz.slice(0,n))||1,bw=W/n, sp=new Set((v.vpf||{}).spikes||[]);
let o=`<svg viewBox="0 0 ${W} ${H}" style="width:100%;direction:ltr;background:var(--panel2);border-radius:8px">`;
for(let i=0;i<n;i++){const hh=Math.max(1,sz[i]/mx*(H-8)), c=ty[i]==='I'?'#ef4444':ty[i]==='B'?'#94a3b8':(sp.has(i)?'#f59e0b':'#60a5fa');
o+=`<rect x="${(i*bw).toFixed(2)}" y="${(H-hh).toFixed(1)}" width="${Math.max(.6,bw-.2).toFixed(2)}" height="${hh.toFixed(1)}" fill="${c}"/>`;}
return o+'</svg>';
}
// ---------- PRNU ----------
let refs=[],qf=null;
$('pRefBtn').onclick=()=>$('pRefs').click(); $('pQBtn').onclick=()=>$('pQ').click();
$('pRefs').onchange=e=>{refs=[...e.target.files].slice(0,40);$('pRefList').textContent=refs.length?T.files(refs.length):'';chk();};
$('pQ').onchange=e=>{qf=e.target.files[0]||null;$('pQName').textContent=qf?qf.name:'';chk();};
function chk(){$('pRun').disabled=!(refs.length&&qf);}
$('pRun').onclick=()=>{
const fd=new FormData(); refs.forEach(f=>fd.append('refs',f)); fd.append('file',qf);
$('pRun').disabled=true; $('pOut').innerHTML=`<div class="card"><span class="spin"></span> ${T.analyzing}</div>`;
fetch('/api/prnu',{method:'POST',body:fd}).then(r=>r.json()).then(d=>{
let h='';
if(d.error) throw new Error(d.error);
TS_CASE.prnu={d:d,name:qf.name,refs:refs.length};
if(!d.ok){
h=`<div class="card"><div class="verdict medium"><div>${d.reason==='size'?T.sizeErr(d.ref_size.join('×'),d.q_size.join('×')):T.noRefs}</div></div></div>`;
}else{
h=`<div class="card"><div class="verdict ${d.match?'low':'high'}"><div><b>${d.match?T.match:T.noMatch}</b>`+
`<div class="pce" style="margin-top:6px">PCE ${d.pce}</div><div class="mut">${T.pceExp(d.threshold)}</div>`+
`<div class="mut">${T.refsUsed(d.refs_used)}</div>${d.questioned_video?`<div class="mut">${T.pVidNote(d.frames_used)}</div>`:''}${d.refs_used<10?`<div class="mut" style="color:var(--warn)">${T.fewRefs}</div>`:''}</div></div></div>`;
if(d.tamper_map){
h+=`<div class="card"><h2>${T.ptTitle}</h2><div class="mut" style="margin-bottom:8px">${T.ptSub}</div>`+
`<div class="map"><img src="${d.tamper_map.image}" data-z="${d.tamper_map.image}"></div>`+
`<div class="kv" style="margin-top:8px"><span>${T.ptFrac}</span><span>${Math.round(d.tamper_map.fraction*100)}%</span></div></div>`;
}
}
if(d.ok) h+=feedback('prnu', d.match?'same':'different',[{key:'same',label:T.fbSame},{key:'different',label:T.fbDiff}],{pce:d.pce,refs:d.refs_used});
$('pOut').innerHTML=h+(d.ok?reportCard():'')+`<div class="note">${T.noteP}</div>`; bindReport($('pOut'));
$('pOut').querySelectorAll('img[data-z]').forEach(i=>i.onclick=()=>window.tsZoom&&window.tsZoom(i.dataset.z));
}).catch(e=>{$('pOut').innerHTML=`<div class="card" style="color:var(--bad)">${esc(e.message||e)}</div>`;})
.finally(()=>chk());
};
</script>
</body>
</html>