HirModel's picture
Upload 4 files
6095f0a verified
Raw
History Blame Contribute Delete
50.1 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Three-run 105-qubit pressure instrument with Run C dynamical exports." />
<title>Stabilizing Beyond 105 Qubits Instrument v0.3</title>
<style>
:root{
--bg:#070912; --bg2:#0b0f1a; --panel:#0e1422; --panel2:#111a2c; --panel3:#0a0f19;
--line:#233047; --line2:#31415c; --ink:#e9edf5; --muted:#a6b0c3; --faint:#68738a;
--blue:#62a8ff; --cyan:#4ed9ff; --indigo:#8b7bff; --green:#7ee08a; --amber:#e0a64a;
--orange:#f08d49; --red:#ee6b5f; --violet:#bf8cff; --shadow:rgba(0,0,0,.42);
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
--sans: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}
*{box-sizing:border-box}
html,body{margin:0;min-height:100%;background:
radial-gradient(900px 460px at 80% -10%, rgba(98,168,255,.16), transparent 60%),
radial-gradient(680px 360px at 12% 0%, rgba(139,123,255,.14), transparent 58%),
radial-gradient(820px 420px at 60% 110%, rgba(126,224,138,.08), transparent 60%),
var(--bg); color:var(--ink); font-family:var(--sans); line-height:1.48;}
body:before{content:"";position:fixed;inset:0;pointer-events:none;background-image:linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.014) 1px, transparent 1px);background-size:38px 38px;mask-image:linear-gradient(to bottom,rgba(0,0,0,.85),rgba(0,0,0,.22));}
a{color:var(--cyan)} .wrap{width:min(1560px,calc(100% - 28px));margin:0 auto;padding:22px 0 70px;position:relative;z-index:1}
.top{border:1px solid var(--line);border-radius:18px;background:linear-gradient(135deg,rgba(17,26,44,.96),rgba(8,11,20,.96));box-shadow:0 22px 70px var(--shadow);padding:24px;overflow:hidden;position:relative}.top:after{content:"";position:absolute;inset:-40% -20%;background:conic-gradient(from 40deg,transparent,rgba(78,217,255,.07),transparent,rgba(126,224,138,.05),transparent);animation:spin 22s linear infinite;pointer-events:none}@keyframes spin{to{transform:rotate(360deg)}}.top>*{position:relative;z-index:1}.kicker{font:800 11px/1.2 var(--mono);letter-spacing:.22em;text-transform:uppercase;color:var(--green);display:flex;gap:10px;align-items:center}.pulse{width:8px;height:8px;border-radius:50%;background:var(--green);box-shadow:0 0 18px var(--green)}h1{font-family:var(--mono);font-size:clamp(26px,4vw,46px);line-height:1.04;margin:10px 0 5px;letter-spacing:-.04em}.subtitle{color:var(--muted);font:600 14px/1.45 var(--mono);max-width:1180px}.attrib{margin-top:13px;border-top:1px dashed var(--line);padding-top:10px;color:var(--faint);font-size:12px}.attrib b{color:var(--muted)}
.boundary{margin-top:16px;border:1px solid rgba(224,166,74,.45);border-left:5px solid var(--amber);border-radius:12px;background:linear-gradient(90deg,rgba(224,166,74,.10),rgba(224,166,74,.025));padding:13px 15px;color:#f2d9aa;font:600 12px/1.55 var(--mono)}.boundary strong{color:var(--amber);text-transform:uppercase;letter-spacing:.12em}
.dashboard{display:grid;grid-template-columns:340px minmax(0,1fr) 480px;gap:14px;margin-top:14px}@media(max-width:1240px){.dashboard{grid-template-columns:330px 1fr}.rightCol{grid-column:1/-1}}@media(max-width:940px){.dashboard{grid-template-columns:1fr}}
.card{border:1px solid var(--line);border-radius:16px;background:linear-gradient(180deg,rgba(17,26,44,.92),rgba(9,14,24,.95));padding:15px;box-shadow:0 14px 44px rgba(0,0,0,.22)}.card h2{font:900 12px/1.2 var(--mono);letter-spacing:.14em;text-transform:uppercase;color:var(--muted);margin:0 0 13px;display:flex;align-items:center;gap:8px}.card h2:before{content:"";width:8px;height:8px;border-radius:3px;background:var(--cyan);box-shadow:0 0 10px var(--cyan)}.card h3{font:900 13px/1.2 var(--mono);color:var(--ink);margin:0 0 8px}.fine{font:500 12px/1.55 var(--mono);color:var(--muted)}
.ctl{margin:0 0 10px}.ctl label{display:flex;justify-content:space-between;gap:10px;align-items:baseline;color:var(--muted);font:700 11.5px var(--mono)}.ctl .val{color:var(--ink);border:1px solid var(--line);border-radius:6px;background:#060914;padding:1px 6px;min-width:44px;text-align:right}.ctl .hint{display:block;margin-top:2px;color:var(--faint);font:600 9.5px var(--mono);letter-spacing:.05em;text-transform:uppercase}input[type=range]{appearance:none;width:100%;height:5px;border-radius:999px;background:linear-gradient(90deg,#20283a,#3b4b67);outline:none}input[type=range]::-webkit-slider-thumb{appearance:none;width:16px;height:16px;border-radius:50%;background:var(--ink);border:2px solid var(--cyan);box-shadow:0 0 12px rgba(78,217,255,.55);cursor:pointer}select{width:100%;border:1px solid var(--line);background:#07101c;color:var(--ink);border-radius:9px;padding:9px 10px;font:700 12px var(--mono)}
.controlsTabs{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:12px}.tab{border:1px solid var(--line);background:#0a101c;color:var(--muted);border-radius:999px;padding:7px 10px;font:800 11px var(--mono);cursor:pointer}.tab.active{border-color:var(--cyan);color:var(--ink);background:rgba(78,217,255,.10)}.controlGroup{display:none}.controlGroup.active{display:block}.actions{display:flex;flex-wrap:wrap;gap:9px;margin-top:12px}button{border:1px solid var(--line2);background:linear-gradient(180deg,rgba(78,217,255,.15),rgba(78,217,255,.06));color:var(--ink);border-radius:10px;padding:10px 12px;font:900 12px var(--mono);cursor:pointer}button:hover{filter:brightness(1.12);border-color:var(--cyan)}button.green{background:linear-gradient(180deg,rgba(126,224,138,.15),rgba(126,224,138,.055));border-color:rgba(126,224,138,.34)}button.amber{background:linear-gradient(180deg,rgba(224,166,74,.15),rgba(224,166,74,.055));border-color:rgba(224,166,74,.38)}
.visualHead{display:grid;grid-template-columns:1fr auto;gap:12px;align-items:start;margin-bottom:10px}.scenarioBadge{font:900 11px var(--mono);padding:6px 9px;border-radius:999px;border:1px solid var(--line);color:var(--muted)}.scenarioBadge.high{color:var(--amber);border-color:rgba(224,166,74,.5)}.scenarioBadge.fail{color:var(--red);border-color:rgba(238,107,95,.5)}.scenarioBadge.good{color:var(--green);border-color:rgba(126,224,138,.5)}
.fieldWrap{position:relative;border:1px solid var(--line);border-radius:16px;background:radial-gradient(circle at center,rgba(78,217,255,.07),transparent 58%),#070b13;padding:8px;overflow:hidden}.fieldWrap canvas{display:block;width:100%;height:470px;border-radius:12px}.legend{display:grid;grid-template-columns:repeat(5,1fr);gap:7px;margin-top:9px}@media(max-width:780px){.legend{grid-template-columns:1fr 1fr}}.legend span{font:800 10px var(--mono);color:var(--muted);border:1px solid var(--line);border-radius:8px;padding:6px 7px;background:rgba(255,255,255,.025)}.dotKey{display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:5px;background:var(--cyan)}.dotKey.good{background:var(--green)}.dotKey.warn{background:var(--amber)}.dotKey.bad{background:var(--red)}.dotKey.c{background:var(--violet)}
.runGrid{display:grid;grid-template-columns:1fr;gap:10px}.runCard{border:1px solid var(--line);border-radius:15px;background:rgba(6,10,18,.72);padding:12px;position:relative;overflow:hidden}.runCard:before{content:"";position:absolute;left:0;top:0;bottom:0;width:4px}.runCard.a:before{background:var(--amber)}.runCard.b:before{background:var(--cyan)}.runCard.c:before{background:var(--green)}.runTitle{display:flex;justify-content:space-between;gap:10px;align-items:center;margin-bottom:8px;font:900 12px var(--mono)}.runTitle small{color:var(--muted);font-weight:700}.state{border-radius:999px;padding:4px 8px;font:900 10px var(--mono);border:1px solid var(--line);color:var(--muted)}.state.good{color:var(--green);border-color:rgba(126,224,138,.38)}.state.warn{color:var(--amber);border-color:rgba(224,166,74,.46)}.state.bad{color:var(--red);border-color:rgba(238,107,95,.44)}.metrics{display:grid;grid-template-columns:repeat(2,1fr);gap:7px}.metric{border:1px solid rgba(255,255,255,.08);border-radius:10px;background:rgba(255,255,255,.025);padding:8px}.metric .mName{font:800 9.5px var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--faint)}.metric .mVal{font:950 18px var(--mono);margin-top:2px}.metric .mVal.good{color:var(--green)}.metric .mVal.mid{color:var(--amber)}.metric .mVal.bad{color:var(--red)}.metric.wide{grid-column:1/-1}.monoList{font:700 11px/1.6 var(--mono);color:var(--muted);margin-top:8px}.monoList b{color:var(--ink)}
.curves{display:grid;grid-template-columns:repeat(2,1fr);gap:14px;margin-top:14px}@media(max-width:980px){.curves{grid-template-columns:1fr}}.curveCard{border:1px solid var(--line);border-radius:16px;background:rgba(8,12,20,.72);padding:12px}.curveCard canvas{width:100%;height:220px;display:block;background:linear-gradient(180deg,rgba(255,255,255,.025),rgba(255,255,255,.005));border-radius:12px}.curveTitle{font:900 11px var(--mono);letter-spacing:.12em;text-transform:uppercase;color:var(--muted);margin-bottom:7px}.timeline{margin-top:14px;display:grid;grid-template-columns:1fr 1fr;gap:14px}@media(max-width:980px){.timeline{grid-template-columns:1fr}}.eventBox{border:1px solid var(--line);border-radius:16px;background:rgba(8,12,20,.72);padding:12px}.eventList{max-height:230px;overflow:auto}.event{display:grid;grid-template-columns:54px 1fr;gap:9px;border-bottom:1px dashed rgba(255,255,255,.08);padding:7px 0;font:650 11px/1.45 var(--mono);color:var(--muted)}.event:last-child{border-bottom:0}.event .t{color:var(--cyan)}.event.fail .t,.event.fail b{color:var(--red)}.event.warn .t,.event.warn b{color:var(--amber)}.event.good .t,.event.good b{color:var(--green)}
.sections{margin-top:18px;display:grid;gap:14px}.section{border:1px solid var(--line);border-radius:16px;background:linear-gradient(180deg,rgba(17,26,44,.72),rgba(9,14,24,.78));padding:18px}.section h2{font-family:var(--mono);font-size:16px;margin:0 0 9px;color:var(--ink)}.section p,.section li{color:var(--muted);font-size:13px}.section ul{margin:8px 0 0;padding-left:20px}.eq{border:1px solid rgba(78,217,255,.25);background:rgba(78,217,255,.055);border-radius:10px;padding:10px;margin:9px 0;color:#cbf6ff;font:750 12px/1.6 var(--mono);overflow:auto}.threeCols{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}@media(max-width:980px){.threeCols{grid-template-columns:1fr}}.miniBox{border:1px solid var(--line);border-radius:12px;padding:12px;background:rgba(255,255,255,.02)}.miniBox h3{font:900 12px var(--mono);color:var(--ink);margin:0 0 7px}.foot{margin-top:18px;color:var(--faint);font:650 11px var(--mono);text-align:center}
.copyToast{position:fixed;right:16px;bottom:16px;border:1px solid rgba(126,224,138,.45);background:#07180f;color:var(--green);border-radius:12px;padding:10px 13px;font:900 12px var(--mono);opacity:0;transform:translateY(10px);transition:.2s;z-index:10}.copyToast.show{opacity:1;transform:translateY(0)}
</style>
</head>
<body>
<div class="wrap">
<header class="top">
<div class="kicker"><span class="pulse"></span> Primordial Calculus / HIR-OAM · Public structural instrument · v0.3</div>
<h1>Stabilizing Beyond 105 Qubits Instrument v0.3</h1>
<div class="subtitle">Dynamical Run C Patch: explicit hexshell / diamond-gate pressure modulation, ECS curves, P_unknown reduction traces, flag triggers, and fail-closed transitions.</div>
<div class="attrib"><b>Created and Developed by Collin D. Weber</b> · Creator and Developer of Primordial Calculus / HIR-OAM · Systems Architect / Systems Integrity Steward</div>
<div class="boundary"><strong>Boundary:</strong> Public-review structural instrument only. Not quantum hardware control. Not direct qubit measurement. Not QEC replacement. Not a Google / Willow product claim. Run C is a theoretical HIR architecture model with model-internal qubit-equivalent ceilings, not hardware validation.</div>
</header>
<div class="dashboard">
<aside class="card">
<h2>Pressure Field Controls</h2>
<div class="controlsTabs">
<button class="tab active" data-tab="shared">Shared</button>
<button class="tab" data-tab="runc">Run C</button>
<button class="tab" data-tab="case">Case</button>
</div>
<div id="tab-shared" class="controlGroup active"></div>
<div id="tab-runc" class="controlGroup"></div>
<div id="tab-case" class="controlGroup">
<div class="ctl"><label>Defined scenario</label><select id="scenarioSelect"></select><span class="hint">High-correlation cases set linked controls for reproducible review.</span></div>
<div class="ctl"><label>Operation type</label><select id="operationType">
<option>Diagnostic review</option><option>Calibration review</option><option>Current branch operation</option><option>Final logical operation</option><option>Public claim / benchmark interpretation</option><option>Safety-critical downstream use</option>
</select><span class="hint">Scope threshold and hard-invariant sensitivity derive from declared operation.</span></div>
</div>
<div class="actions">
<button id="applyCase" class="amber">Apply Case</button>
<button id="copyJson" class="green">Copy JSON Review Packet</button>
<button id="downloadJson">Download JSON</button>
<button id="downloadCsv">Download CSV Curves</button>
</div>
</aside>
<main class="card">
<div class="visualHead"><div><h2>105-Qubit-Scale Pressure Field + Run C Hexshell</h2><div class="fine">Same public pressure field across Run A, Run B, and Run C. Run C overlays dynamic shell/gate modulation, learning, immune capture, encapsulation, and resource-truth pressure.</div></div><span id="scenarioBadge" class="scenarioBadge high">High correlation case</span></div>
<div class="fieldWrap"><canvas id="fieldCanvas" width="960" height="600"></canvas></div>
<div class="legend"><span><i class="dotKey good"></i>Coherent node</span><span><i class="dotKey warn"></i>Strained node</span><span><i class="dotKey bad"></i>Correlated cluster</span><span><i class="dotKey c"></i>Diamond gate</span><span><i class="dotKey"></i>Routed handoff</span></div>
<div class="curves">
<div class="curveCard"><div class="curveTitle">ECS curve under defined case</div><canvas id="ecsChart" width="720" height="260"></canvas></div>
<div class="curveCard"><div class="curveTitle">P_unknown reduction trace</div><canvas id="pChart" width="720" height="260"></canvas></div>
<div class="curveCard"><div class="curveTitle">Pressure-term modulation</div><canvas id="modChart" width="720" height="260"></canvas></div>
<div class="curveCard"><div class="curveTitle">Model-internal ceiling trend</div><canvas id="ceilChart" width="720" height="260"></canvas></div>
</div>
<div class="timeline">
<div class="eventBox"><h3>Flag trigger timeline</h3><div id="flagList" class="eventList"></div></div>
<div class="eventBox"><h3>Fail-closed / reroute transitions</h3><div id="transitionList" class="eventList"></div></div>
</div>
</main>
<aside class="rightCol card">
<h2>Three Run Readouts</h2>
<div class="runGrid">
<div class="runCard a"><div class="runTitle">Run A <small>Public Constraint Backtrace</small><span id="stateA" class="state"></span></div><div id="metricsA" class="metrics"></div><div id="notesA" class="monoList"></div></div>
<div class="runCard b"><div class="runTitle">Run B <small>HIR/OAM Encapsulated Settlement</small><span id="stateB" class="state"></span></div><div id="metricsB" class="metrics"></div><div id="notesB" class="monoList"></div></div>
<div class="runCard c"><div class="runTitle">Run C <small>Diamond-Gate Hexshell Dynamics</small><span id="stateC" class="state"></span></div><div id="metricsC" class="metrics"></div><div id="notesC" class="monoList"></div></div>
</div>
</aside>
</div>
<section class="sections">
<div class="section">
<h2>What v0.3 Adds</h2>
<p>v0.3 moves Run C from structural comparison into exportable dynamics. The model now exposes explicit pressure-term modulation, ECS curves, P_unknown reduction traces, flag triggers, and fail-closed transitions under defined high-correlation / high-P_unknown review cases.</p>
<div class="eq">Run C modulation map:<br>shell count + gate density + instantaneous alignment + RAM learning + immune capture + cryptobiotic encapsulation + UWC resource truth → lattice / correlation / decoder / runtime / unknown pressure shifts.</div>
</div>
<div class="section">
<h2>Core Equations</h2>
<div class="eq">S_field = T × Q × R × G − P_system</div>
<div class="eq">P_system = P_lattice + P_correlation + P_decoder + P_control + P_runtime + P_resource + P_provenance + P_security + P_public + P_unknown</div>
<div class="eq">ECS = Provenance + Independence + Scope Match + Pressure Match + Temporal Validity + Repeat Stability − Correlation Penalty − Self-Certification Penalty − Boundary Violation Penalty</div>
<div class="eq">S_full = T × Q × R × G × DG × RAM × IM × DM × UWC − P_total</div>
<div class="eq">Q_ceiling = Q_base × (1 + S_full × ShellMultiplier × GateDensity × AlignmentFactor × RecoveryFactor)</div>
</div>
<div class="section threeCols">
<div class="miniBox"><h3>Run A</h3><p>Backtrace correction mode. It asks whether correction produced a usable output. Residual pressure may be compressed into confidence if downstream gates do not force settlement review.</p></div>
<div class="miniBox"><h3>Run B</h3><p>Trace-capsule settlement mode. It asks whether the pressure-bearing trace can settle for the declared scope using ECS, hard invariants, residual P_unknown, and settlement authority.</p></div>
<div class="miniBox"><h3>Run C</h3><p>Diamond-gate hexshell dynamics. It asks whether pressure can be intercepted, aligned, routed, learned, quarantined, encapsulated, and audited before unresolved error accumulates.</p></div>
</div>
<div class="section">
<h2>Run C Dynamical Mapping</h2>
<p>Run C computes gate capacity, shell handoff capacity, RAM recovery, immune capture, cryptobiotic encapsulation, Digital Mycelium repair propagation, and UWC resource truth. These factors reduce effective lattice, correlation, decoder, runtime, and unknown pressure only when provenance, evidence, and resource-truth conditions remain visible.</p>
<ul>
<li><b>Shell multiplier:</b> more shells increase bounded handoff depth, but also add overhead when resource pressure is high.</li>
<li><b>Gate density:</b> increases handoff paths and reduces bottleneck pressure until gate saturation appears.</li>
<li><b>Instantaneous alignment:</b> reduces drift at layer transition and improves ECS when evidence is not self-certified.</li>
<li><b>RAM learning:</b> reduces repeat P_unknown over simulation steps by storing pressure signatures and successful routing hints.</li>
<li><b>Immune capture:</b> routes malformed/capture pressure into quarantine before it can train memory directly.</li>
<li><b>Cryptobiotic encapsulation:</b> pauses interpretation when pressure exceeds safe handling, preserving trace state without forced closure.</li>
<li><b>UWC resource truth:</b> penalizes any apparent stabilization that hides heat, compute friction, audit overhead, or cooling burden.</li>
</ul>
</div>
<div class="section">
<h2>What This Does Not Claim</h2>
<p>This artifact does not simulate Google Willow internals, claim Google endorsement, claim QEC replacement, claim direct qubit-state measurement, claim hardware control, or claim that model-internal qubit-equivalent ceilings correspond to physically stabilized qubits. It is a deterministic structural pressure instrument for public review, not a validated quantum hardware model.</p>
<p><b>Final core line:</b> A stable system is not a system without error. A stable system is one where error has a bounded address, agency remains attached, and closure is earned.</p>
</div>
</section>
<div class="foot">Stabilizing Beyond 105 Qubits Instrument v0.3 · Static SDK · No external JS frameworks · CC BY-NC-SA 4.0</div>
</div>
<div id="toast" class="copyToast">Copied JSON review packet</div>
<script>
'use strict';
const clamp=(x,a=0,b=1)=>Math.max(a,Math.min(b,x));
const $=id=>document.getElementById(id);
const fmt=(x,d=3)=>Number.isFinite(x)?x.toFixed(d):String(x);
const pct=x=>fmt(x*100,1)+'%';
const Q_BASE=105;
const controls={
localTrace:{label:'local trace stability',value:.72,min:0,max:1,tab:'shared',hint:'higher = cleaner input/output trace'},
lattice:{label:'lattice pressure',value:.74,min:0,max:1,tab:'shared',hint:'multi-node strain / topology pressure'},
correlation:{label:'correlation level',value:.82,min:0,max:1,tab:'shared',hint:'cross-linked or repeated error pressure'},
decoder:{label:'decoder strain',value:.68,min:0,max:1,tab:'shared',hint:'syndrome/decoder correction burden'},
control:{label:'control drift',value:.54,min:0,max:1,tab:'shared',hint:'timing, readout, calibration drift'},
runtime:{label:'runtime scheduler pressure',value:.62,min:0,max:1,tab:'shared',hint:'operation ordering / throughput burden'},
resource:{label:'resource pressure',value:.58,min:0,max:1,tab:'shared',hint:'compute/thermal/cooling/audit overhead'},
provenance:{label:'provenance continuity',value:.70,min:0,max:1,tab:'shared',hint:'trace chain continuity'},
security:{label:'security risk',value:.38,min:0,max:1,tab:'shared',hint:'injection, spoofing, poisoned sidecars'},
publicClaim:{label:'public claim pressure',value:.56,min:0,max:1,tab:'shared',hint:'benchmark/practical-use overclaim pressure'},
pUnknown:{label:'P_unknown / residual uncertainty',value:.78,min:0,max:1,tab:'shared',hint:'honesty reservoir / unresolved pressure'},
evidence:{label:'evidence quality',value:.62,min:0,max:1,tab:'shared',hint:'independent, scoped, time-valid evidence'},
shells:{label:'shell count',value:.68,min:0,max:1,tab:'runc',hint:'maps 1–9 concentric hexshells'},
gateDensity:{label:'diamond gate density',value:.72,min:0,max:1,tab:'runc',hint:'maps low-to-high gate availability'},
gateEfficiency:{label:'gate handoff efficiency',value:.70,min:0,max:1,tab:'runc',hint:'handoff coprocessor capacity'},
alignment:{label:'instantaneous alignment strength',value:.76,min:0,max:1,tab:'runc',hint:'alignment under pressure at boundary'},
routing:{label:'omnidirectional routing efficiency',value:.74,min:0,max:1,tab:'runc',hint:'constraint relief across shell field'},
ramLearning:{label:'RAM learning rate',value:.66,min:0,max:1,tab:'runc',hint:'pressure signature learning speed'},
immuneRetention:{label:'immune memory retention',value:.64,min:0,max:1,tab:'runc',hint:'recurrence recognition across runs'},
redSensitivity:{label:'authorized red-team capture sensitivity',value:.68,min:0,max:1,tab:'runc',hint:'white-blood-cell capture detection'},
redFalsePositive:{label:'red-team false-positive pressure',value:.18,min:0,max:1,tab:'runc',hint:'over-quarantine burden'},
redFalseNegative:{label:'red-team false-negative pressure',value:.24,min:0,max:1,tab:'runc',hint:'missed capture burden'},
cryptoThreshold:{label:'cryptobiotic encapsulation threshold',value:.62,min:0,max:1,tab:'runc',hint:'when to pause interpretation'},
malformed:{label:'malformed data pressure',value:.58,min:0,max:1,tab:'runc',hint:'bad payload / poisoned trace pressure'},
counterfeit:{label:'counterfeit resonance pressure',value:.52,min:0,max:1,tab:'runc',hint:'looks coherent but fails HIR/OAM'},
mycelium:{label:'Digital Mycelium repair propagation',value:.64,min:0,max:1,tab:'runc',hint:'distributed repair/warning propagation'},
hirInternal:{label:'HIR internalization',value:.72,min:0,max:1,tab:'runc',hint:'internalized HIR runtime density'},
grit:{label:'grit density',value:.58,min:0,max:1,tab:'runc',hint:'earned pressure-history inertia'},
uwc:{label:'UWC resource-truth visibility',value:.66,min:0,max:1,tab:'runc',hint:'visible thermodynamic/resource burden'}
};
const scenarios={
highCorrelation:{label:'High correlation / high P_unknown',badge:'High correlation case',values:{correlation:.86,pUnknown:.82,decoder:.70,lattice:.76,evidence:.60,gateDensity:.72,alignment:.76,ramLearning:.66,redSensitivity:.68,resource:.58,provenance:.70}},
decoderStress:{label:'Decoder stress / moderate evidence',badge:'Decoder strain case',values:{correlation:.70,pUnknown:.70,decoder:.88,lattice:.66,evidence:.55,runtime:.72,gateDensity:.68,alignment:.72,ramLearning:.62,resource:.65}},
malformedCapture:{label:'Malformed data / counterfeit resonance',badge:'Immune capture case',values:{malformed:.84,counterfeit:.78,security:.62,pUnknown:.76,correlation:.74,redSensitivity:.76,redFalseNegative:.18,ramLearning:.64,cryptoThreshold:.60}},
resourceBurden:{label:'High resource pressure / UWC audit',badge:'Resource-truth case',values:{resource:.86,uwc:.52,runtime:.78,decoder:.66,pUnknown:.70,evidence:.58,gateEfficiency:.62,routing:.64,mycelium:.54}},
nominal:{label:'Nominal review / stable evidence',badge:'Nominal case',values:{localTrace:.80,lattice:.44,correlation:.38,decoder:.36,control:.30,runtime:.34,resource:.30,provenance:.86,security:.12,publicClaim:.20,pUnknown:.34,evidence:.84,shells:.62,gateDensity:.70,gateEfficiency:.76,alignment:.80,routing:.75,ramLearning:.70,immuneRetention:.72,redSensitivity:.66,redFalsePositive:.12,redFalseNegative:.14,cryptoThreshold:.70,malformed:.22,counterfeit:.18,mycelium:.72,hirInternal:.82,grit:.64,uwc:.82}}
};
let lastResult=null;
function buildControls(){
for(const key in scenarios){const o=document.createElement('option');o.value=key;o.textContent=scenarios[key].label;$('scenarioSelect').appendChild(o);} $('scenarioSelect').value='highCorrelation';
for(const [key,c] of Object.entries(controls)){
const div=document.createElement('div');div.className='ctl';
div.innerHTML=`<label for="${key}"><span>${c.label}</span><span class="val" id="${key}Val">${fmt(c.value,2)}</span></label><input id="${key}" type="range" min="0" max="1" step="0.01" value="${c.value}"><span class="hint">${c.hint}</span>`;
$('tab-'+c.tab).appendChild(div);
$(key).addEventListener('input',()=>{controls[key].value=parseFloat($(key).value);$(key+'Val').textContent=fmt(controls[key].value,2);computeAndRender();});
}
}
function vals(){const o={}; for(const [k,c] of Object.entries(controls)) o[k]=c.value; o.operationType=$('operationType').value; o.scenario=$('scenarioSelect').value; return o;}
function setVals(obj){for(const [k,v] of Object.entries(obj)){if(controls[k]){controls[k].value=v;$(k).value=v;$(k+'Val').textContent=fmt(v,2);}}}
function opThreshold(op){return {'Diagnostic review':.52,'Calibration review':.48,'Current branch operation':.42,'Final logical operation':.32,'Public claim / benchmark interpretation':.25,'Safety-critical downstream use':.18}[op]||.42;}
function pressureProfile(v){
const P_lattice=v.lattice;
const P_correlation=v.correlation;
const P_decoder=v.decoder;
const P_control=v.control;
const P_runtime=v.runtime;
const P_resource=v.resource;
const P_provenance=1-v.provenance;
const P_security=v.security;
const P_public=v.publicClaim;
const P_unknown=v.pUnknown;
const P_malformed=(v.malformed+v.counterfeit)/2;
const P_constraint=clamp((P_runtime+P_decoder+P_resource+P_correlation)/4);
const base=[P_lattice,P_correlation,P_decoder,P_control,P_runtime,P_resource,P_provenance,P_security,P_public,P_unknown].reduce((a,b)=>a+b,0)/10;
const total=clamp((P_lattice+P_correlation+P_decoder+P_control+P_runtime+P_resource+P_provenance+P_security+P_public+P_unknown+P_malformed+P_constraint)/12,0,1.4);
return {P_lattice,P_correlation,P_decoder,P_control,P_runtime,P_resource,P_provenance,P_security,P_public,P_unknown,P_malformed,P_constraint,base,total};
}
function ecs(v,p,variant){
const provenance=v.provenance;
const independence=variant==='A'?clamp(v.evidence*.62):clamp(v.evidence*(variant==='C'?(.72+.20*v.immuneRetention):.82));
const scopeMatch=clamp(1-v.publicClaim*.62);
const pressureMatch=clamp(v.evidence*(1-p.P_unknown*.42)*(variant==='C'?(1+.18*v.alignment):1));
const temporal=variant==='C'?clamp(.54+.28*v.ramLearning+.14*v.immuneRetention-.12*v.redFalsePositive):clamp(.62+.18*v.evidence-.12*p.P_unknown);
const repeatStability=variant==='C'?clamp(.34+.24*v.ramLearning+.16*v.mycelium+.14*v.grit-.20*p.P_correlation):clamp(.45+.18*v.evidence-.28*p.P_correlation);
const corrPenalty=p.P_correlation*(variant==='C'?.24:.48);
const selfCertPenalty=variant==='A'?clamp(.22+.30*v.decoder*(1-v.evidence)):clamp(.12+.15*v.decoder*(1-v.evidence));
const boundaryPenalty=clamp(p.P_public*.42+p.P_security*.24+p.P_provenance*.32);
return clamp((provenance+independence+scopeMatch+pressureMatch+temporal+repeatStability)/6 - corrPenalty - selfCertPenalty - boundaryPenalty,0,1);
}
function hardFlags(v,p,variant){
const flags=[];
if(p.P_lattice>.74 && v.provenance<.55) flags.push('boundary leakage not propagated');
if(v.publicClaim>.70 && v.evidence<.72) flags.push('public claim exceeding technical settlement state');
if(v.decoder>.82 && v.evidence<.58) flags.push('decoder self-certification used as proof');
if(v.correlation>.78 && variant!=='C') flags.push('recurring correlated pressure without field recheck');
if(v.provenance<.45) flags.push('missing provenance chain');
if(v.security>.66) flags.push('security risk elevated without review');
if(variant==='C' && v.redFalseNegative>.62 && p.P_malformed>.55) flags.push('immune false-negative pressure elevated');
if(variant==='C' && v.resource>.82 && v.uwc<.55) flags.push('resource burden hidden from settlement');
return flags;
}
function runA(v,p){
const stability=clamp(v.localTrace*.42+(1-p.base)*.30+v.evidence*.18+(1-v.decoder)*.10);
const e=ecs(v,p,'A'), flags=hardFlags(v,p,'A');
const residual=clamp(p.P_unknown*.74+p.P_correlation*.26-v.evidence*.16);
let state='CORRECTED FOR LIMITED SCOPE', cls='good';
if(v.decoder>.75) {state='DECODER STRAIN';cls='warn';}
if(v.correlation>.78) {state='CORRELATED PRESSURE RISK';cls='warn';}
if(v.publicClaim>.68) {state='BENCHMARK SCOPE ONLY';cls='warn';}
if(residual>.68) {state='UNRESOLVED PRESSURE COMPRESSED';cls='bad';}
if(flags.length>2){state='RECHECK RECOMMENDED';cls='bad';}
const ceiling=Math.round(Q_BASE*(.78+stability*.58-(p.P_correlation+p.P_unknown)*.12));
return {stability,ecs:e,residual,flags,state,cls,ceiling:Math.max(50,ceiling),correctionStatus:stability>.52?'usable output':'limited output',decoderStrain:v.decoder,correlationRisk:v.correlation,publicBoundary:v.publicClaim>opThreshold(v.operationType)?'scope warning':'within declared scope'};
}
function runB(v,p){
const T=v.localTrace, Q=clamp(1-(p.P_lattice*.62+p.P_correlation*.36)), R=clamp(1-(p.P_decoder*.38+p.P_runtime*.28+p.P_control*.22)), G=clamp((v.provenance+v.evidence+(1-v.publicClaim)+(1-v.security))/4);
const S=clamp(T*Q*R*G - p.base*.25 + .18,0,1);
const e=ecs(v,p,'B'), flags=hardFlags(v,p,'B');
const threshold=opThreshold(v.operationType);
const residual=clamp(p.P_unknown*(1-v.evidence*.22));
let state='ERROR ADDRESSED, NOT CLOSED', cls='warn', action='keep trace open';
if(flags.length){state='FAIL CLOSED FOR AFFECTED PATH';cls='bad';action='fail closed / review flags';}
else if(residual>threshold*1.75){state='MUST RECHECK FIELD';cls='bad';action='field recheck required';}
else if(e>.64 && residual<threshold){state='FIELD HELD FOR CURRENT SCOPE';cls='good';action='settle for declared scope';}
else if(e>.48){state='PARTIAL SETTLEMENT ONLY';cls='warn';action='partial settlement';}
else if(p.P_lattice>.66 && p.P_correlation<.45){state='LOCAL STRAIN ONLY';cls='warn';action='local repair';}
if(v.publicClaim>0.64 && v.operationType.includes('Public')){state='PUBLIC CLAIM BOUNDARY REQUIRED';cls='warn';action='claim boundary review';}
const ceiling=Math.round(Q_BASE*(1+S*.80+e*.42-p.P_unknown*.18));
return {T,Q,R,G,S,ecs:e,residual,flags,state,cls,action,ceiling:Math.max(70,ceiling),pSystem:p.base};
}
function runC(v,p){
const shells=1+Math.round(v.shells*8);
const ShellMultiplier=1+shells*.075;
const GateDensity=.35+.85*v.gateDensity;
const AlignmentFactor=.42+.72*v.alignment;
const GateCapacity=clamp(v.gateDensity*v.gateEfficiency*v.alignment*v.routing*ShellMultiplier/(1+.28*v.resource));
const RAMRecovery=clamp(v.ramLearning*v.immuneRetention*(.55+.45*v.mycelium)*(1-.22*v.redFalsePositive));
const ImmuneCapture=clamp(v.redSensitivity*v.immuneRetention*(1-v.redFalseNegative)*(1-.18*v.redFalsePositive));
const Crypto=clamp(v.cryptoThreshold*(.45+.55*v.provenance)*(1-.28*v.publicClaim));
const DM=clamp(v.mycelium*(.55+.25*v.hirInternal+.20*v.grit));
const UWC=clamp(v.uwc*(1-.40*v.resource)+.12);
const malformedShield=clamp(ImmuneCapture*(.4+.6*v.redSensitivity) - v.redFalseNegative*.22);
const shellShield=clamp((shells/9)*v.routing*v.gateEfficiency);
const learnShield=clamp(RAMRecovery*(.35+.65*v.ramLearning));
const alignShield=clamp(v.alignment*v.gateEfficiency);
const resourcePenalty=clamp(v.resource*(1-v.uwc)*.42 + v.redFalsePositive*.12);
const effective={
lattice:clamp(p.P_lattice*(1-.30*shellShield-.22*alignShield)+resourcePenalty*.05),
correlation:clamp(p.P_correlation*(1-.34*GateCapacity-.22*learnShield-.10*DM)+v.redFalseNegative*.08),
decoder:clamp(p.P_decoder*(1-.28*GateCapacity-.24*alignShield-.18*learnShield)+resourcePenalty*.10),
control:clamp(p.P_control*(1-.16*alignShield-.10*shellShield)+resourcePenalty*.05),
runtime:clamp(p.P_runtime*(1-.30*v.routing*GateCapacity-.16*DM)+resourcePenalty*.12),
resource:clamp(p.P_resource*(1-.24*UWC)+(.06*shells/9)+v.redFalsePositive*.04),
provenance:clamp(p.P_provenance*(1-.20*v.provenance-.14*Crypto)),
security:clamp(p.P_security*(1-.32*ImmuneCapture)+v.redFalseNegative*.06),
public:clamp(p.P_public*(1-.18*v.provenance-.18*UWC)),
unknown:clamp(p.P_unknown*(1-.34*learnShield-.24*GateCapacity-.16*Crypto-.10*DM)+v.redFalseNegative*.07),
malformed:clamp(p.P_malformed*(1-.46*malformedShield)+v.redFalseNegative*.10)
};
const effTotal=clamp(Object.values(effective).reduce((a,b)=>a+b,0)/Object.keys(effective).length);
const T=v.localTrace, Q=clamp(1-(effective.lattice*.42+effective.correlation*.30)), R=clamp(1-(effective.decoder*.32+effective.runtime*.22+effective.control*.18)), G=clamp((v.provenance+v.evidence+v.hirInternal+v.uwc+(1-v.publicClaim)+(1-v.security))/6);
const DG=GateCapacity, RAM=clamp(.35+.65*RAMRecovery), IM=clamp(.35+.65*ImmuneCapture);
const S_full=clamp(T*Q*R*G*DG*RAM*IM*DM*UWC - effTotal*.24 + .22,0,1.4);
const e=ecs({...v,pUnknown:effective.unknown}, {...p,P_unknown:effective.unknown,P_correlation:effective.correlation,P_decoder:effective.decoder,P_lattice:effective.lattice,P_public:effective.public,P_security:effective.security,P_provenance:effective.provenance}, 'C');
const flags=hardFlags(v,{...p,P_unknown:effective.unknown,P_correlation:effective.correlation,P_decoder:effective.decoder,P_lattice:effective.lattice,P_public:effective.public,P_security:effective.security,P_provenance:effective.provenance,P_malformed:effective.malformed},'C');
const threshold=opThreshold(v.operationType);
const gateSaturation=clamp((p.total - (GateCapacity+RAMRecovery+ImmuneCapture+DM+UWC)/5)*1.35);
const RecoveryFactor=clamp(.55+.45*(RAMRecovery+ImmuneCapture+DM)/3 - resourcePenalty*.20);
const ceiling=Math.round(Q_BASE*(1+S_full*ShellMultiplier*GateDensity*AlignmentFactor*RecoveryFactor));
let state='GATE-ALIGNED FIELD HELD', cls='good', action='continue with pressure ledger attached';
if(effective.malformed>.45 && ImmuneCapture>.48){state='MALFORMED TRACE QUARANTINED';cls='warn';action='quarantine and extract clean learning';}
if(effective.unknown>threshold*1.65 && Crypto>.42){state='CRYPTOBIOTIC ENCAPSULATION ACTIVE';cls='warn';action='pause interpretation / preserve trace';}
if(GateCapacity>.55 && v.routing>.60 && p.P_constraint>.55){state='OMNIDIRECTIONAL RELIEF ACTIVE';cls='good';action='distributed handoff active';}
if(RAMRecovery>.58 && effective.unknown<p.P_unknown*.72){state='PRESSURE LEARNED INTO RAM';cls='good';action='store pressure signature';}
if(ImmuneCapture>.60 && p.P_malformed>.55){state='IMMUNE CAPTURE EVENT';cls='warn';action='capture signature / quarantine';}
if(v.resource>.75 && UWC<.48){state='RESOURCE BURDEN VISIBLE';cls='warn';action='resource-truth review';}
if(gateSaturation>.62){state='GATE NETWORK SATURATED';cls='bad';action='increase shell/gate capacity or fail closed';}
if(flags.length>1 || (effective.unknown>threshold*2.2 && gateSaturation>.45)){state='FAIL CLOSED AT SHELL BOUNDARY';cls='bad';action='fail closed / preserve trace capsule';}
return {shells,ShellMultiplier,GateDensity,AlignmentFactor,GateCapacity,RAMRecovery,ImmuneCapture,Crypto,DM,UWC,effective,effTotal,T,Q,R,G,DG,RAM,IM,S_full,ecs:e,residual:effective.unknown,flags,state,cls,action,ceiling:Math.max(Q_BASE,ceiling),gateSaturation,resourcePenalty};
}
function simulateCurves(v,p,a,b,c){
const rows=[]; let pU=p.P_unknown, ecsV=Math.max(.08,b.ecs*.55), gateHeat=c.gateSaturation, learned=0, failClosed=false;
for(let t=0;t<=36;t++){
const step=t/36;
const learnGain=c.RAMRecovery*(.025+.020*v.ramLearning)*(1+.5*step);
const gateGain=c.GateCapacity*(.012+.014*v.alignment);
const immuneGain=c.ImmuneCapture*(p.P_malformed>.45?.018:.008)*(1-v.redFalsePositive*.25);
const cryptoHold=(pU>opThreshold(v.operationType)*1.55 && c.Crypto>.42)?.012:0;
const newUnknown=clamp(pU - learnGain - gateGain - immuneGain - cryptoHold + v.redFalseNegative*.006 + c.resourcePenalty*.004);
learned=clamp(learned + (pU-newUnknown)*(.8+.2*v.immuneRetention));
pU=newUnknown;
const ecsTarget=clamp(c.ecs + learned*.55 - c.gateSaturation*.12 - c.resourcePenalty*.12);
ecsV=clamp(ecsV + (ecsTarget-ecsV)*.18);
const latticeEff=clamp(p.P_lattice*(1-.30*c.ShellMultiplier*step*.35-.20*c.GateCapacity*step)+c.resourcePenalty*.04);
const corrEff=clamp(p.P_correlation*(1-.38*c.GateCapacity*step-.28*c.RAMRecovery*step-.13*c.DM*step)+v.redFalseNegative*.06);
const decoderEff=clamp(p.P_decoder*(1-.28*c.GateCapacity*step-.24*v.alignment*step-.22*c.RAMRecovery*step)+c.resourcePenalty*.08);
gateHeat=clamp(gateHeat + ((p.total-(c.GateCapacity+c.RAMRecovery+c.ImmuneCapture+c.DM)/4)-gateHeat)*.10);
let event='';
if(t===0) event='case initialized';
if(t===4 && p.P_correlation>.75) event='correlation cluster detected';
if(t===7 && c.ImmuneCapture>.55 && p.P_malformed>.45) event='authorized red-team capture activated';
if(t===10 && pU< p.P_unknown*.82) event='P_unknown reduction observed';
if(t===14 && c.Crypto>.48 && pU>opThreshold(v.operationType)*1.35) event='cryptobiotic encapsulation gate held';
if(t===20 && ecsV>.58) event='ECS crossed review threshold';
if(t===28 && c.GateCapacity>.56) event='shell reroute stabilized';
if(gateHeat>.70 && !failClosed){event='gate saturation warning';}
if((pU>opThreshold(v.operationType)*2.2 && gateHeat>.52) || (c.flags && c.flags.length>2)){failClosed=true;}
rows.push({t,ECS:ecsV,P_unknown:pU,lattice:latticeEff,correlation:corrEff,decoder:decoderEff,ceiling:Math.round(Q_BASE*(1+c.S_full*c.ShellMultiplier*c.GateDensity*c.AlignmentFactor*(.35+.65*step))),gateSaturation:gateHeat,event,failClosed});
}
return rows;
}
function compute(){
const v=vals(), p=pressureProfile(v), A=runA(v,p), B=runB(v,p), C=runC(v,p), curves=simulateCurves(v,p,A,B,C);
return {artifact_name:'Stabilizing Beyond 105 Qubits Instrument',version:'0.3',boundary_statement:'Public-review structural instrument only. Not quantum hardware control. Not direct qubit measurement. Not QEC replacement. Not a Google / Willow product claim. Run C is a theoretical HIR architecture model, not hardware validation.',timestamp:new Date().toISOString(),input_controls:v,shared_pressure_field:p,run_a_public_constraint_backtrace:A,run_b_hir_oam_encapsulated:B,run_c_full_hir_architecture:C,curves,public_claim_boundary:B.publicBoundary||A.publicBoundary,claims_not_made:['Google endorsement','Willow integration','private hardware access','hardware control','direct qubit-state measurement','QEC replacement','production readiness','validated physical qubit stabilization']};
}
function metricHTML(rows){return rows.map(([name,val,cls])=>`<div class="metric"><div class="mName">${name}</div><div class="mVal ${cls||''}">${val}</div></div>`).join('');}
function setRun(id,res,type){
$('state'+id).textContent=res.state; $('state'+id).className='state '+res.cls;
if(id==='A') $('metricsA').innerHTML=metricHTML([['Stability',fmt(res.stability,2),res.stability>.55?'good':res.stability>.38?'mid':'bad'],['ECS',fmt(res.ecs,2),res.ecs>.55?'good':res.ecs>.35?'mid':'bad'],['Residual',fmt(res.residual,2),res.residual>.62?'bad':'mid'],['Ceiling',res.ceiling,'mid'],['Decoder',fmt(res.decoderStrain,2),'mid'],['Correlation',fmt(res.correlationRisk,2),'mid']]);
if(id==='B') $('metricsB').innerHTML=metricHTML([['S_field',fmt(res.S,2),res.S>.55?'good':res.S>.35?'mid':'bad'],['ECS',fmt(res.ecs,2),res.ecs>.55?'good':res.ecs>.35?'mid':'bad'],['P_unknown',fmt(res.residual,2),res.residual>.62?'bad':'mid'],['Ceiling',res.ceiling,'mid'],['Flags',res.flags.length,res.flags.length?'bad':'good'],['Action',res.action,'mid']]);
if(id==='C') $('metricsC').innerHTML=metricHTML([['S_full',fmt(res.S_full,2),res.S_full>.50?'good':res.S_full>.30?'mid':'bad'],['ECS',fmt(res.ecs,2),res.ecs>.55?'good':res.ecs>.35?'mid':'bad'],['P_unknown',fmt(res.residual,2),res.residual>.62?'bad':'mid'],['Ceiling',res.ceiling,'good'],['Gate cap',fmt(res.GateCapacity,2),'mid'],['Shells',res.shells,'mid'],['RAM',fmt(res.RAMRecovery,2),'mid'],['Immune',fmt(res.ImmuneCapture,2),'mid']]);
$('notes'+id).innerHTML='<b>Flags:</b> '+(res.flags&&res.flags.length?res.flags.join('; '):'none')+'<br><b>Recommended:</b> '+(res.action||res.publicBoundary||'review output');
}
function drawField(result){
const c=$('fieldCanvas'), ctx=c.getContext('2d'), w=c.width,h=c.height; ctx.clearRect(0,0,w,h);
ctx.fillStyle='#060912'; ctx.fillRect(0,0,w,h);
for(let i=0;i<120;i++){ctx.fillStyle='rgba(255,255,255,'+(0.02+0.05*((i*17)%7)/7)+')';ctx.fillRect((i*73)%w,(i*119)%h,1,1)}
const cx=w/2, cy=h/2+10; const C=result.run_c_full_hir_architecture; const p=result.shared_pressure_field;
// flat lattice ghost
const cols=15, rows=7, spacing=42, startX=cx-cols*spacing/2+spacing/2, startY=cy-rows*spacing/2;
for(let y=0;y<rows;y++) for(let x=0;x<cols;x++){
const px=startX+x*spacing, py=startY+y*spacing;
ctx.strokeStyle='rgba(98,168,255,.10)'; ctx.lineWidth=1; if(x<cols-1){ctx.beginPath();ctx.moveTo(px,py);ctx.lineTo(px+spacing,py);ctx.stroke()} if(y<rows-1){ctx.beginPath();ctx.moveTo(px,py);ctx.lineTo(px,py+spacing);ctx.stroke()}
const strain=(p.P_lattice*.3+p.P_correlation*.45+p.P_unknown*.25); const cluster=((x-7)**2+(y-3)**2)<(3+p.P_correlation*5);
ctx.fillStyle=cluster?`rgba(238,107,95,${0.25+0.55*p.P_correlation})`:strain>.62?'rgba(224,166,74,.75)':'rgba(126,224,138,.72)';
ctx.beginPath();ctx.arc(px,py,cluster?4.3:3.2,0,Math.PI*2);ctx.fill();
}
// hexshells
function hexPoints(r){let pts=[]; for(let i=0;i<6;i++){const a=Math.PI/6+i*Math.PI/3;pts.push([cx+Math.cos(a)*r,cy+Math.sin(a)*r]);}return pts}
const shellN=C.shells; const maxR=260, minR=74; ctx.lineWidth=2;
for(let s=0;s<shellN;s++){const r=minR+(maxR-minR)*s/Math.max(1,shellN-1); const pts=hexPoints(r); ctx.beginPath();pts.forEach((pt,i)=>i?ctx.lineTo(pt[0],pt[1]):ctx.moveTo(pt[0],pt[1]));ctx.closePath(); ctx.strokeStyle=`rgba(126,224,138,${0.20+0.55*(s+1)/shellN})`;ctx.stroke();
// diamond gates
pts.forEach((pt,i)=>{const [x,y]=pt; const active=(i+s)%2===0 || C.GateCapacity>.55; ctx.save();ctx.translate(x,y);ctx.rotate(Math.PI/4);ctx.fillStyle=active?'rgba(191,140,255,.82)':'rgba(104,115,138,.42)';ctx.strokeStyle='rgba(255,255,255,.35)';ctx.lineWidth=1;ctx.fillRect(-5,-5,10,10);ctx.strokeRect(-5,-5,10,10);ctx.restore();});
}
// routing lines
for(let i=0;i<16;i++){const a=Math.PI*2*i/16 + .2; const r1=60, r2=250; ctx.strokeStyle=i%3===0?'rgba(78,217,255,.55)':i%3===1?'rgba(126,224,138,.45)':'rgba(224,166,74,.35)'; ctx.lineWidth=i%4===0?2.4:1.2; ctx.beginPath();ctx.moveTo(cx+Math.cos(a)*r1,cy+Math.sin(a)*r1);ctx.quadraticCurveTo(cx+Math.cos(a+.35)*150,cy+Math.sin(a+.35)*150,cx+Math.cos(a)*r2,cy+Math.sin(a)*r2);ctx.stroke();}
ctx.fillStyle='rgba(78,217,255,.22)';ctx.beginPath();ctx.arc(cx,cy,48,0,Math.PI*2);ctx.fill();ctx.strokeStyle='rgba(78,217,255,.7)';ctx.lineWidth=2;ctx.stroke();
ctx.fillStyle='#e9edf5';ctx.font='900 14px ui-monospace,monospace';ctx.textAlign='center';ctx.fillText('TRACE CORE',cx,cy+5);
ctx.textAlign='left';ctx.font='800 12px ui-monospace,monospace';ctx.fillStyle='#a6b0c3';ctx.fillText('Run C hexshell overlay: '+shellN+' shells · gate capacity '+fmt(C.GateCapacity,2)+' · ceiling '+C.ceiling+' QE units',22,30);
}
function drawChart(id, rows, series, opts={}){const c=$(id),ctx=c.getContext('2d'),w=c.width,h=c.height;ctx.clearRect(0,0,w,h);ctx.fillStyle='#070b13';ctx.fillRect(0,0,w,h);const pad=34, pw=w-pad*2, ph=h-pad*2;ctx.strokeStyle='rgba(255,255,255,.10)';for(let i=0;i<=4;i++){let y=pad+ph*i/4;ctx.beginPath();ctx.moveTo(pad,y);ctx.lineTo(w-pad,y);ctx.stroke()}let maxY=opts.maxY??Math.max(...rows.flatMap(r=>series.map(s=>r[s.key]||0)),1);let minY=opts.minY??0;const cols=['#4ed9ff','#7ee08a','#e0a64a','#ee6b5f','#bf8cff'];series.forEach((s,si)=>{ctx.strokeStyle=cols[si%cols.length];ctx.lineWidth=2.5;ctx.beginPath();rows.forEach((r,i)=>{const x=pad+pw*i/(rows.length-1);const v=(r[s.key]-minY)/(maxY-minY);const y=pad+ph*(1-clamp(v));if(i===0)ctx.moveTo(x,y);else ctx.lineTo(x,y);});ctx.stroke();ctx.fillStyle=cols[si%cols.length];ctx.font='800 11px ui-monospace,monospace';ctx.fillText(s.label,pad+si*150,18);});ctx.fillStyle='rgba(166,176,195,.8)';ctx.font='700 10px ui-monospace,monospace';ctx.fillText(String(maxY.toFixed?maxY.toFixed(1):maxY),4,pad);ctx.fillText(String(minY),4,h-pad+4);}
function renderEvents(result){const rows=result.curves;let flags=[];let trans=[];rows.forEach(r=>{if(r.event){let type=r.event.includes('warning')?'warn':r.event.includes('reduction')||r.event.includes('stabilized')||r.event.includes('crossed')?'good':'warn';flags.push(`<div class="event ${type}"><div class="t">t=${r.t}</div><div><b>${r.event}</b><br>ECS ${fmt(r.ECS,2)} · P_unknown ${fmt(r.P_unknown,2)}</div></div>`);}if(r.failClosed){trans.push(`<div class="event fail"><div class="t">t=${r.t}</div><div><b>fail-closed condition reachable</b><br>Gate saturation ${fmt(r.gateSaturation,2)} · P_unknown ${fmt(r.P_unknown,2)}</div></div>`);}}); if(!trans.length){trans.push(`<div class="event good"><div class="t">t=36</div><div><b>no fail-closed transition in this run</b><br>Trace remains routed/held under defined scope.</div></div>`)}$('flagList').innerHTML=flags.join('')||'<div class="fine">No flags emitted.</div>';$('transitionList').innerHTML=trans.join('');}
function computeAndRender(){const r=compute();lastResult=r;const scen=scenarios[r.input_controls.scenario];$('scenarioBadge').textContent=scen.badge;$('scenarioBadge').className='scenarioBadge '+(r.run_c_full_hir_architecture.cls||'high'); setRun('A',r.run_a_public_constraint_backtrace);setRun('B',r.run_b_hir_oam_encapsulated);setRun('C',r.run_c_full_hir_architecture);drawField(r);drawChart('ecsChart',r.curves,[{key:'ECS',label:'Run C ECS'}],{minY:0,maxY:1});drawChart('pChart',r.curves,[{key:'P_unknown',label:'P_unknown'}],{minY:0,maxY:1});drawChart('modChart',r.curves,[{key:'lattice',label:'Lattice'},{key:'correlation',label:'Correlation'},{key:'decoder',label:'Decoder'}],{minY:0,maxY:1});drawChart('ceilChart',r.curves,[{key:'ceiling',label:'Qubit-equivalent ceiling'}],{minY:Q_BASE,maxY:Math.max(Q_BASE+20,...r.curves.map(x=>x.ceiling))*1.05});renderEvents(r);}
function packet(){return JSON.stringify(lastResult||compute(),null,2);}
function csv(){const rows=(lastResult||compute()).curves;const keys=Object.keys(rows[0]);return keys.join(',')+'\n'+rows.map(r=>keys.map(k=>JSON.stringify(r[k]??'')).join(',')).join('\n');}
function download(name,text,type){const blob=new Blob([text],{type});const url=URL.createObjectURL(blob);const a=document.createElement('a');a.href=url;a.download=name;document.body.appendChild(a);a.click();a.remove();URL.revokeObjectURL(url);}
function showToast(){const t=$('toast');t.classList.add('show');setTimeout(()=>t.classList.remove('show'),1600)}
document.querySelectorAll('.tab').forEach(b=>b.addEventListener('click',()=>{document.querySelectorAll('.tab').forEach(x=>x.classList.remove('active'));b.classList.add('active');document.querySelectorAll('.controlGroup').forEach(x=>x.classList.remove('active'));$('tab-'+b.dataset.tab).classList.add('active');}));
$('applyCase').addEventListener('click',()=>{setVals(scenarios[$('scenarioSelect').value].values);computeAndRender();});
$('operationType').addEventListener('change',computeAndRender);$('scenarioSelect').addEventListener('change',()=>{$('applyCase').click();});
$('copyJson').addEventListener('click',async()=>{try{await navigator.clipboard.writeText(packet());showToast();}catch(e){download('Stabilizing_Beyond_105_Qubits_v0_3_review_packet.json',packet(),'application/json');}});
$('downloadJson').addEventListener('click',()=>download('Stabilizing_Beyond_105_Qubits_v0_3_review_packet.json',packet(),'application/json'));
$('downloadCsv').addEventListener('click',()=>download('Stabilizing_Beyond_105_Qubits_v0_3_curves.csv',csv(),'text/csv'));
buildControls(); computeAndRender();
</script>
</body>
</html>