/* bostrom.network — the bootloader, reborn · the deck
   seven chapters, each a page: / · /rebirth · /balance · /story · /bootloader · /graph · /next
   no date on the page: the launch is a milestone — code that passes its gate
   marks: ● measured · ○ target · ◌ mock. every number carries one. */
(() => {
const $ = (s, r = document) => r.querySelector(s);
const el = (h) => { const t = document.createElement('template'); t.innerHTML = h.trim(); return t.content.firstChild; };
const esc = (t) => String(t).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
const M = (k) => `<i class="mk ${k}"></i>`;
const COLS = ['#00ff41', '#00b8ff', '#ffc400', '#ff1a00', '#ff7a00', '#1e00ff', '#7a00ff'];

const sfx = (() => {
  let ac = null, master = null, on = localStorage.getItem('cyber.sound') !== 'off', amb = null;
  const ensure = () => { if (ac) return true; try { ac = new (window.AudioContext || window.webkitAudioContext)(); master = ac.createGain(); master.gain.value = .22; master.connect(ac.destination); } catch { return false; } return true; };
  const resume = () => { if (ac && ac.state === 'suspended') ac.resume(); };
  const tone = (f0, f1, dur, type = 'sine', g = .5, at = 0) => { if (!on || !ensure()) return; resume(); const t = ac.currentTime + at; const o = ac.createOscillator(), v = ac.createGain(); o.type = type; o.frequency.setValueAtTime(f0, t); if (f1) o.frequency.exponentialRampToValueAtTime(f1, t + dur); v.gain.setValueAtTime(0, t); v.gain.linearRampToValueAtTime(g, t + .006); v.gain.exponentialRampToValueAtTime(.0005, t + dur); o.connect(v); v.connect(master); o.start(t); o.stop(t + dur + .02); };
  const noise = (dur, g = .3, hp = 2000) => { if (!on || !ensure()) return; resume(); const t = ac.currentTime; const n = ac.sampleRate * dur | 0, b = ac.createBuffer(1, n, ac.sampleRate), d = b.getChannelData(0); for (let i = 0; i < n; i++) d[i] = (Math.random() * 2 - 1) * (1 - i / n); const src = ac.createBufferSource(); src.buffer = b; const f = ac.createBiquadFilter(); f.type = 'highpass'; f.frequency.value = hp; const v = ac.createGain(); v.gain.value = g; src.connect(f); f.connect(v); v.connect(master); src.start(t); };
  const ambient = (start) => { if (!ensure()) return; if (start && !amb && on) { const v = ac.createGain(); v.gain.value = 0; v.connect(master); const f = ac.createBiquadFilter(); f.type = 'lowpass'; f.frequency.value = 220; f.connect(v); const os = [55, 55.4, 82.5].map((fr) => { const o = ac.createOscillator(); o.type = 'triangle'; o.frequency.value = fr; o.connect(f); o.start(); return o; }); v.gain.linearRampToValueAtTime(.06, ac.currentTime + 4); amb = { v, os }; } if (!start && amb) { amb.v.gain.linearRampToValueAtTime(0, ac.currentTime + 1); const a = amb; amb = null; setTimeout(() => a.os.forEach((o) => o.stop()), 1200); } };
  const NOTES = [220, 246.9, 277.2, 329.6, 370, 440, 493.9];
  return {
    get on() { return on; },
    toggle() { on = !on; localStorage.setItem('cyber.sound', on ? 'on' : 'off'); if (on) { ensure(); resume(); ambient(true); tone(660, 990, .12, 'sine', .4); } else ambient(false); return on; },
    wake() { if (on && ensure()) { resume(); ambient(true); } },
    tick() { noise(.02, .25, 3000); tone(1800, 1200, .03, 'square', .08); },
    move(dir, ch) { noise(.03, .2, 1500); tone(dir > 0 ? 440 : 520, dir > 0 ? 560 : 400, .08, 'sine', .25); if (ch != null) { const r = NOTES[ch]; tone(r, null, .5, 'sine', .18, .04); tone(r * 1.5, null, .45, 'sine', .1, .08); } },
    link() { tone(880, 1320, .16, 'sine', .35); tone(1320, 1760, .22, 'triangle', .18, .1); },
    hash() { noise(.012, .12, 4000); },
    ticket() { tone(1760, 1750, .35, 'sine', .3); tone(2640, 2630, .25, 'sine', .12, .02); },
    converge(d) { const f = 220 + 1200 * Math.min(1, Math.max(0, (-Math.log10(Math.max(d, 1e-9)) - 1) / 7)); tone(f, f * 1.02, .07, 'triangle', .22); },
    stake(v) { tone(v ? 160 : 110, 60, .25, 'sine', .45); noise(.05, .15, 800); },
    mentor() { [0, 2, 4, 6].forEach((k, i) => tone(NOTES[k] * 2, null, .3, 'sine', .22, i * .09)); },
    chord(ch) { const r = NOTES[ch]; [1, 1.25, 1.5, 2].forEach((m, i) => tone(r * m, null, .9, 'sine', .14, i * .05)); },
  };
})();


/* ------------------------------------------------------------------ chapters = pages */
const CH = [
  { id: '', path: '/', name: 'bostrom', c: COLS[0] },
  { id: 'rebirth', path: '/rebirth', name: 'rebirth', c: COLS[1] },
  { id: 'balance', path: '/balance', name: 'balance', c: COLS[2] },
  { id: 'story', path: '/story', name: 'the story', c: COLS[3] },
  { id: 'bootloader', path: '/bootloader', name: 'the bootloader', c: COLS[4] },
  { id: 'graph', path: '/graph', name: 'the graph', c: COLS[5] },
  { id: 'next', path: '/next', name: 'what next', c: COLS[6] },
];
const S = []; const push = (ch, html, cls = '', extra = {}) => S.push({ ch, cls, html, ...extra });

/* 1 · cover */
push(0, `<div><p class="kick">the bootloader of superintelligence · block 1 → halt → ∞</p><p class="hero-word boot">BOSTROM</p><p class="sub">halted · laid to rest · reborn</p><p class="lead">almost five years, 3.1M particles, 2.9M cyberlinks. halted at height <b>25,120,712</b>. it returns in a new body on soft3 when the code is ready — with $BOOT, every balance and the whole graph.</p><p class="kbd">→ or space · swipe · every arrow is one step · <span id="nslides"></span> pages</p></div>`, 'one');

/* 2 · rebirth */
push(1, `<div><p class="kick">rebirth · when the code is ready</p><h2>no date.<br><em>a gate.</em></h2><p class="lead">bostrom returns as a root chain on soft3 on the day its code passes every gate: the genesis built from the burial and matched bit-exact, the rehearsal network holding under real use, the red team finding nothing critical. not a day earlier.</p><p class="mute">space-pussy, the canary, goes through every rehearsal first. the launch page tracks the gates as they turn green.</p></div><div class="nums"><div class="n"><big>no date</big><small>a milestone is code that passes its gate ${M('m')}
genesisbuilt from the burial, matched bit-exact, its particle the chain id ${M('m')}</small></div><div class="n"><big>rehearsal</big><small>the canary chain under real use before the bootloader moves ${M('t')}
the launch pagecyber.page/launch — the gates, as they turn green ${M('t')}</small></div></div>`, '', { bridge: 'what returns, and what changes' }); push(1, `<div><p class="kick">rebirth · what returns</p><h2>everything you had.<br><em>nothing you must do.</em></h2><p class="lead">the genesis is built from the burial snapshot by a deterministic pipeline: two independent builds give the same bytes, and the particle of that file is the chain id.</p><div class="tiles"><span class="tile"><b>$BOOTevery balance, liquid againthe graph2,949,732 links, bit-exactyour keysthe same secp256k1 key signs47,837 namesevery passport, a link at height 0