// palette-qp.jsx — The Quantum Palette
// Verbatim from the Oscillian Studio brand system. Single source of truth.
// Every Council component reads from this module.

const QP = {
  // 14 atomic colors — each carries a role, quantifiable advantage, and multiplier.
  atomic: [
    { idx:  0, name: 'Oscillation Crimson', hex: '#e72020', role: 'pillar',    advantage: 'Compression',          multiplier: 122.99, mLabel: '122.99×', description: 'PHI^10 = 122.99x — 1000 oscillations compressed to 9 gate layers' },
    { idx:  1, name: 'Velocity Teal',       hex: '#42f977', role: 'pillar',    advantage: 'Speed',                multiplier: 2175,   mLabel: '2,175×', description: '2,175x GPU acceleration at 28 qubits via cuStateVec' },
    { idx:  2, name: 'Swarm Violet',        hex: '#a334f3', role: 'pillar',    advantage: 'Scale',                multiplier: 713.2,  mLabel: '713×',   description: '713x swarm scaling — circuit knitting to 400+ effective qubits' },
    { idx:  3, name: 'Yield Gold',          hex: '#a59523', role: 'pillar',    advantage: 'Economic',             multiplier: 3.33,   mLabel: '3.33×',  description: '3.33x cost reduction — $3.91 blended vs $13.04 single Heron' },
    { idx:  4, name: 'Calibration Cyan',    hex: '#23c8e9', role: 'qes',       advantage: 'Qubit Subgraph',       multiplier: 156,    mLabel: '156',    description: 'Best N qubits from 156 via T2/ECR/RO calibration scoring' },
    { idx:  5, name: 'Session Magenta',     hex: '#c6207a', role: 'qes',       advantage: 'Runtime Sessions',     multiplier: 17.7,   mLabel: '17.7×',  description: 'Eliminates 94.5% queue wait — 559 min queue to 32 min QPU' },
    { idx:  6, name: 'Fidelity Lime',       hex: '#42a023', role: 'qes',       advantage: 'Error Budget',         multiplier: 2.5,    mLabel: '2.5×',   description: 'Estimate fidelity before paying — route low-fidelity to GPU ($0)' },
    { idx:  7, name: 'Coherence Indigo',    hex: '#28239b', role: 'qes',       advantage: 'Dynamic Decoupling',   multiplier: 2,      mLabel: '2×',     description: 'Extends T2 coherence 1.5-2x on idle qubits via XY4 pulses' },
    { idx:  8, name: 'Consensus Orange',    hex: '#b05222', role: 'qes',       advantage: 'Ensemble Voting',      multiplier: 6,      mLabel: '6×',     description: 'Multi-backend weighted result fusion across 6 Heron backends' },
    { idx:  9, name: 'Budget Seafoam',      hex: '#24956b', role: 'qes',       advantage: 'Adaptive Budgeting',   multiplier: 1.4,    mLabel: '1.4×',   description: '20-40% cost savings via complexity-scaled shot allocation' },
    { idx: 10, name: 'Seed Pulse',          hex: '#a921b5', role: 'frequency', advantage: 'Seed Layer',           multiplier: 7777.77, mLabel: '7777.77 Hz', description: 'Foundation frequency — quantum_loop_trinity genesis sync' },
    { idx: 11, name: 'Trunk Wave',          hex: '#98b821', role: 'frequency', advantage: 'Trunk Layer',          multiplier: 8888.88, mLabel: '8888.88 Hz', description: 'Primary relay — epochGphi CloudMedusa backbone' },
    { idx: 12, name: 'Crown Resonance',     hex: '#216dba', role: 'frequency', advantage: 'Crown Layer',          multiplier: 9999.99, mLabel: '9999.99 Hz', description: 'Peak coherence — terminal_sanitation verification' },
    { idx: 13, name: 'Shield Barrier',      hex: '#ba2141', role: 'frequency', advantage: 'Shield Layer',         multiplier: 10101.01, mLabel: '10101.01 Hz', description: 'Defense perimeter — T6 SHIELD integrity barrier' },
  ],

  // Named duotones — used as constellation field gradients per agent.
  duotones: {
    'entanglement-gate':     ['#42f977', '#28239b'],
    'error-correction-spark':['#e72020', '#23c8e9'],
    'aureate-singularity':   ['#a334f3', '#a59523'],
    'chromatic-qubit':       ['#c6207a', '#23c8e9'],
    'protocol-horizon':      ['#b05222', '#28239b'],
    'mesh-lattice':          ['#24956b', '#a334f3'],
    'goldfield-calibration': ['#a59523', '#23c8e9'],
    'greenroom-drift':       ['#42f977', '#24956b'],
    'deep-coherence':        ['#a334f3', '#28239b'],
    'runtime-bloom':         ['#c6207a', '#a334f3'],
    'market-furnace':        ['#b05222', '#a59523'],
    'preflight-clarity':     ['#42a023', '#23c8e9'],
    'crown-dawn':            ['#e2c24a', '#ffb347'],
    'phase-shift':           ['#37e6b0', '#b03bff'],
    'spectral-tunnel':       ['#27d7e8', '#7b4dff'],
    'open-world-current':    ['#42a3ff', '#5fe07f'],
    'indigo-harvest':        ['#5f6cff', '#c9d06a'],
  },

  // Triads — section/mood palettes.
  triads: {
    'instrument-panel':    ['#28239b', '#23c8e9', '#a59523'],
    'neon-control-loop':   ['#a334f3', '#42f977', '#c6207a'],
    'operational-clarity': ['#24956b', '#42a023', '#23c8e9'],
    'collapse-cascade':    ['#e72020', '#a334f3', '#28239b'],
    'aureate-furnace':     ['#a59523', '#b05222', '#ffb347'],
    'epoch-arc':           ['#e2c24a', '#27d7e8', '#b03bff'],
    'open-world-gradient': ['#9ed66a', '#42a3ff', '#7b4dff'],
    'coastal-acceleration':['#5fe07f', '#37e6b0', '#27d7e8'],
  },

  // Signature gradients — atmosphere backdrops.
  gradients: {
    'singularity-rail':  'linear-gradient(135deg, #28239b, #a334f3, #23c8e9)',
    'velocity-pulse':    'linear-gradient(135deg, #0a0a0a, #24956b, #42f977)',
    'runtime-aurora':    'linear-gradient(135deg, #28239b, #c6207a, #a334f3)',
    'yield-spectrum':    'linear-gradient(135deg, #0a0a0a, #a59523, #ffb347)',
    'protocol-flame':    'linear-gradient(135deg, #28239b, #b05222, #e72020)',
    'season-drift':      'linear-gradient(90deg, #e2c24a, #5fe07f, #27d7e8, #5f6cff, #b03bff, #ffb347)',
    'mid-arc':           'linear-gradient(90deg, #5fe07f, #37e6b0, #27d7e8, #42a3ff, #5f6cff)',
    'indigo-glass':      'linear-gradient(180deg, #141414, #0f0f0f 60%, #0a0a0a)',
    'cyan-fog':          'linear-gradient(180deg, rgba(35,200,233,0.18), rgba(10,10,10,0) 55%)',
    'violet-bloom':      'radial-gradient(circle at 20% 15%, rgba(163,52,243,0.25), rgba(10,10,10,0) 55%)',
  },

  // Dataviz palettes — for charts, heatmaps, distributions.
  dataviz: {
    'execution-spectrum': ['#e72020', '#b05222', '#a59523', '#24956b', '#23c8e9', '#28239b'],
    'qubit-ensemble':     ['#e72020', '#c6207a', '#a334f3', '#28239b', '#23c8e9', '#24956b', '#42f977', '#a59523'],
    'epoch-drift-map':    ['#e2c24a', '#c9d06a', '#8ed85a', '#37e6b0', '#27d7e8', '#3ab8f5', '#5f6cff', '#7b4dff', '#b03bff', '#ffb347'],
  },

  // Push/pull dualities — the 6-axis personality radar.
  pushpull: [
    { axis: 'Compression vs Speed',     push: '#e72020', pull: '#42f977', pushLabel: 'Compression', pullLabel: 'Speed' },
    { axis: 'Runtime vs Reserve',       push: '#c6207a', pull: '#24956b', pushLabel: 'Runtime',     pullLabel: 'Reserve' },
    { axis: 'Swarm vs Yield',           push: '#a334f3', pull: '#a59523', pushLabel: 'Swarm',       pullLabel: 'Yield' },
    { axis: 'Signal vs Noise',          push: '#b05222', pull: '#23c8e9', pushLabel: 'Signal',      pullLabel: 'Noise' },
    { axis: 'Singularity vs Growth',    push: '#b03bff', pull: '#9ed66a', pushLabel: 'Singularity', pullLabel: 'Growth' },
    { axis: 'Deepfield vs Crownflare',  push: '#7b4dff', pull: '#ffb347', pushLabel: 'Deepfield',   pullLabel: 'Crownflare' },
  ],

  // Glow/ring focus states — live-vote semantic colors.
  glowring: {
    'precision':  { name: 'Precision Focus',  ring: '#23c8e9', glow: '#28239b' },  // checking
    'velocity':   { name: 'Velocity Focus',   ring: '#42f977', glow: '#24956b' },  // cleared
    'sovereign':  { name: 'Sovereign Focus',  ring: '#a59523', glow: '#ffb347' },  // featured / top of class
    'runtime':    { name: 'Runtime Focus',    ring: '#c6207a', glow: '#a334f3' },  // routing
    'critical':   { name: 'Critical Focus',   ring: '#e72020', glow: '#b05222' },  // refused
  },

  // Surface colors — the dark substrate everything sits on.
  surface: {
    background:    '#0a0a0a',
    surface:       '#141414',
    surfaceRaised: '#1e1e1e',
    border:        '#2a2a2a',
    borderActive:  '#42f977',
    textPrimary:   '#e0e0e0',
    textSecondary: '#888888',
  },
};

// ── Lookup helpers ───────────────────────────────────────────
function qpByName(name)  { return QP.atomic.find(c => c.name === name); }
function qpByHex(hex)    { return QP.atomic.find(c => c.hex.toLowerCase() === (hex || '').toLowerCase()); }
function qpByRole(role)  { return QP.atomic.filter(c => c.role === role); }
function qpDuotone(key)  { return QP.duotones[key]; }
function qpGradient(key) { return QP.gradients[key]; }
function qpTriad(key)    { return QP.triads[key]; }
function qpFocus(state)  { return QP.glowring[state] || QP.glowring.precision; }

// Pair an atomic color with its semantically-best duotone partner for
// constellation rendering. Used as a deterministic default.
function qpFieldFor(color) {
  // Hard-mapped associations so each pillar color has a known constellation feel
  const map = {
    'Oscillation Crimson': 'error-correction-spark',
    'Velocity Teal':       'greenroom-drift',
    'Swarm Violet':        'deep-coherence',
    'Yield Gold':          'aureate-singularity',
    'Calibration Cyan':    'goldfield-calibration',
    'Session Magenta':     'chromatic-qubit',
    'Fidelity Lime':       'preflight-clarity',
    'Coherence Indigo':    'protocol-horizon',
    'Consensus Orange':    'market-furnace',
    'Budget Seafoam':      'mesh-lattice',
    'Seed Pulse':          'runtime-bloom',
    'Trunk Wave':          'greenroom-drift',
    'Crown Resonance':     'crown-dawn',
    'Shield Barrier':      'error-correction-spark',
  };
  return map[color.name] || 'mesh-lattice';
}

Object.assign(window, {
  QP,
  qpByName, qpByHex, qpByRole, qpDuotone, qpGradient, qpTriad, qpFocus, qpFieldFor,
});
