// beats.jsx — narrative data for the Quantum Butterfly Field sequence.
// Nine beats, grouped into three chapters:
//   SCRAMBLING (1–5) · DAMAGE (6) · HEALING (7–9)
// Each beat carries two layers:
//   story   — the main text (hero), shown large in serif italic
//   physics — the scientific text, shown smaller + dimmer beneath
//   attribution — set only when the story is a Faggin quote
//   chapter — which of the three movements this beat belongs to
// `tone` drives a subtle per-beat ambient wash (the I3 "field" light).
// Durations (ms) follow the storyboard's recommended hold times.

const BEATS = [
  {
    num: "01",
    name: "Identity",
    chapter: "INTRO",
    story: "I am a butterfly.|You are a butterfly.",
    attribution: null,
    physics: "A single quantum state holds its own unique identity.",
    duration: 9000,
    tone: { hue: 220, sat: 18, light: 60, strength: 0.05 },
  },
  {
    num: "02",
    name: "Interiority",
    chapter: "SCRAMBLING",
    story: "The interiority of our experience is infinitely rich and infinitely beautiful \u2014 an unknowable, irreducible mystery that only we ourselves can experience.",
    attribution: null,
    physics: "Unlike classical bits, a qubit can never be perfectly copied (no-cloning theorem). To inspect a qubit from from the outside is to change its state forever.",
    duration: 11000,
    tone: { hue: 224, sat: 20, light: 60, strength: 0.055 },
  },
  {
    num: "03",
    name: "Interaction",
    chapter: "SCRAMBLING",
    story: "Yet reality is continually created by the interactions that take place between its \u2018parts\u2019 \u2014 parts that are not, in the end, separable.",
    attribution: "Federico Faggin",
    physics: "When qubits interact through the gates of a quantum circuit, they entangle. Information once held individually is now held jointly across the system.",
    duration: 13000,
    tone: { hue: 286, sat: 42, light: 56, strength: 0.09 },
  },
  {
    num: "04",
    name: "Mutual transformation",
    chapter: "SCRAMBLING",
    story: "Each observation changes both the observer and the observed.",
    attribution: "Federico Faggin",
    physics: "Every gate interaction is mutual \u2014 both qubits are transformed, carrying that change into the next step. Gate after gate, the entanglement compounds.",
    duration: 9000,
    tone: { hue: 300, sat: 52, light: 54, strength: 0.13 },
  },
  {
    num: "05",
    name: "The whole",
    chapter: "SCRAMBLING",
    story: "And together the whole becomes something more than the sum of its parts.",
    attribution: null,
    physics: "Repeated gate operations scramble information holographically across the system of qubits. It now lives in the quantum correlations woven between the qubits \u2014 accessible only through the whole.",
    duration: 8000,
    tone: { hue: 312, sat: 58, light: 54, strength: 0.16 },
  },
  {
    num: "06",
    name: "Rupture",
    chapter: "DAMAGE",
    story: "Separation...",
    attribution: null,
    physics: "A local disturbance severs the correlations between a single qubit and the rest of the field\u2026 the qubit goes dark.",
    duration: 4500,
    tone: { hue: 210, sat: 20, light: 42, strength: 0.08 },
  },
  {
    num: "07",
    name: "Held by the field",
    chapter: "HEALING",
    story: "\u2026 is only at the surface.|Each of us is held within the relational whole.",
    attribution: null,
    physics: "Read individually, the damaged qubit looks like meaningless noise. Yet its information \u2014 distributed across the field\u2019s correlations \u2014 has not been destroyed.",
    duration: 12000,
    tone: { hue: 38, sat: 48, light: 56, strength: 0.11 },
  },
  {
    num: "08",
    name: "Restoration",
    chapter: "HEALING",
    story: "What was lost, can be recovered.",
    attribution: null,
    physics: "Unwinding the same sequence of scrambling interactions backwards, the information of the \u201cdamaged\u201d qubit is recoverable from the deeply entangled correlations of the global system.",
    duration: 10000,
    tone: { hue: 32, sat: 38, light: 54, strength: 0.085 },
  },
  {
    num: "09",
    name: "Self-healing",
    chapter: "HEALING",
    story: "In the quantum world, reality is self-healing.",
    attribution: null,
    physics: "While the interactions leave a small residual error, the qubit is largely restored. This is the opposite of the classical butterfly effect, where tiny disruptions snowball into massive changes. In quantum systems, the whole protects the part.",
    duration: 14000,
    tone: { hue: 30, sat: 28, light: 60, strength: 0.07 },
  },
];

// ---- derive the chapter counter label for each beat ----
// A chapter with a single beat (DAMAGE) shows just its name; multi-beat
// chapters show "NAME NN / TT" (e.g. "SCRAMBLING 01 / 05").
(function deriveChapters(beats) {
  const totals = {};
  beats.forEach((b) => { totals[b.chapter] = (totals[b.chapter] || 0) + 1; });
  const seen = {};
  beats.forEach((b) => {
    seen[b.chapter] = (seen[b.chapter] || 0) + 1;
    b.chapterIndex = seen[b.chapter];
    b.chapterTotal = totals[b.chapter];
    b.phaseLabel = totals[b.chapter] > 1
      ? b.chapter + " " + String(seen[b.chapter]).padStart(2, "0") + " / " + String(totals[b.chapter]).padStart(2, "0")
      : b.chapter;
  });
})(BEATS);

window.BEATS = BEATS;
