// Cefalia — 8 logo concepts (exposed on window.CefaliaLogos)
// Each symbol is a React component taking { s } (pixel size).
// Brand idea: Cefalia = cérebro + IA. Motifs: synapse, neural network,
// hemispheres, the app-tile (família), spark, gyri, neuron cell, spectrum.
const C = window.CEF;

// Reusable gradient defs helper — unique id per instance.
let _gid = 0;
function gid(p) { return p + '-' + (++_gid); }

// 1 ─ Synapse C: a "C" arc made of a synapse, terminals are product hues.
function SynapseC({ s = 120 }) {
  const g = gid('sc');
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none" aria-label="Cefalia">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.iris} /><stop offset="1" stopColor={C.teal} />
      </linearGradient></defs>
      <path d="M75 28 A30 30 0 1 0 75 72" stroke={`url(#${g})`} strokeWidth="12" strokeLinecap="round" />
      <circle cx="75" cy="28" r="9.5" fill={C.iris} />
      <circle cx="75" cy="72" r="7.5" fill={C.emerald} />
    </svg>
  );
}

// 2 ─ Neural Hub: a central brain node with product satellites (o ecossistema).
function NeuralHub({ s = 120 }) {
  const g = gid('nh');
  const sat = [
    { x: 50, y: 16, r: 7, c: C.iris },
    { x: 82, y: 40, r: 6, c: C.teal },
    { x: 70, y: 80, r: 6.5, c: C.emerald },
    { x: 26, y: 76, r: 5.5, c: C.amber },
    { x: 17, y: 38, r: 6, c: C.irisLt },
  ];
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.iris} /><stop offset="1" stopColor={C.teal} />
      </linearGradient></defs>
      {sat.map((p, i) => (
        <line key={i} x1="50" y1="50" x2={p.x} y2={p.y} stroke={C.ink3} strokeWidth="2.4" />
      ))}
      {sat.map((p, i) => <circle key={'s' + i} cx={p.x} cy={p.y} r={p.r} fill={p.c} />)}
      <circle cx="50" cy="50" r="13" fill={`url(#${g})`} />
      <circle cx="50" cy="50" r="4.5" fill={C.paper2} />
    </svg>
  );
}

// 3 ─ Hemispheres: two crescent lobes facing each other, synapse gap between.
function Hemispheres({ s = 120 }) {
  const g = gid('hm');
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.emerald} /><stop offset="1" stopColor={C.iris} />
      </linearGradient></defs>
      <path d="M44 16 A34 34 0 1 0 44 84" stroke={C.ink} strokeWidth="13" strokeLinecap="round" />
      <path d="M56 16 A34 34 0 1 1 56 84" stroke={`url(#${g})`} strokeWidth="13" strokeLinecap="round" />
      <circle cx="50" cy="50" r="5.5" fill={C.iris} />
    </svg>
  );
}

// 4 ─ App tile: rounded-square tile (família dos produtos) com glifo C.
function TileMark({ s = 120 }) {
  const g = gid('tl');
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.iris} /><stop offset="0.55" stopColor={C.teal} /><stop offset="1" stopColor={C.emerald} />
      </linearGradient></defs>
      <rect x="6" y="6" width="88" height="88" rx="26" fill={`url(#${g})`} />
      <path d="M70 35 A21 21 0 1 0 70 65" stroke={C.white} strokeWidth="10" strokeLinecap="round" fill="none" />
      <circle cx="70" cy="35" r="5.5" fill={C.white} />
    </svg>
  );
}

// 5 ─ Spark node: 4-point synapse spark (ecoa o ícone do Atende AI).
function SparkMark({ s = 120 }) {
  const g = gid('sp');
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.iris} /><stop offset="1" stopColor={C.teal} />
      </linearGradient></defs>
      <path d="M50 8 C56 36 64 44 92 50 C64 56 56 64 50 92 C44 64 36 56 8 50 C36 44 44 36 50 8 Z" fill={`url(#${g})`} />
      <circle cx="50" cy="50" r="8" fill={C.paper2} />
      <circle cx="50" cy="50" r="3.5" fill={C.iris} />
    </svg>
  );
}

// 6 ─ Gyri: nested brain-fold arcs forming a C.
function GyriMark({ s = 120 }) {
  const g = gid('gy');
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none" strokeLinecap="round">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.iris} /><stop offset="1" stopColor={C.teal} />
      </linearGradient></defs>
      <path d="M72 22 A36 36 0 1 0 72 78" stroke={C.ink} strokeWidth="9" />
      <path d="M68 34 A24 24 0 1 0 68 66" stroke={`url(#${g})`} strokeWidth="9" />
      <path d="M62 46 A12 12 0 1 0 62 54" stroke={C.emerald} strokeWidth="8" />
    </svg>
  );
}

// 7 ─ Neuron cell: hexagonal soma with dendrite nodes.
function NeuronMark({ s = 120 }) {
  const g = gid('nu');
  const pts = '50,12 83,31 83,69 50,88 17,69 17,31';
  const v = [[50,12],[83,31],[83,69],[50,88],[17,69],[17,31]];
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.iris} /><stop offset="1" stopColor={C.teal} />
      </linearGradient></defs>
      {v.map((p, i) => <line key={i} x1="50" y1="50" x2={p[0]} y2={p[1]} stroke={C.ink3} strokeWidth="2.2" />)}
      <polygon points={pts} stroke={`url(#${g})`} strokeWidth="6" strokeLinejoin="round" />
      {v.map((p, i) => <circle key={'c'+i} cx={p[0]} cy={p[1]} r="4" fill={i===0?C.iris:i===2?C.emerald:i===4?C.amber:C.teal} />)}
      <circle cx="50" cy="50" r="9" fill={`url(#${g})`} />
    </svg>
  );
}

// 8 ─ Spectrum ring: open ring (a C) carrying the full neural spectrum.
function SpectrumRing({ s = 120 }) {
  const g = gid('sr');
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs><linearGradient id={g} x1="0.1" y1="0" x2="0.9" y2="1">
        <stop offset="0" stopColor={C.emerald} /><stop offset="0.5" stopColor={C.teal} /><stop offset="1" stopColor={C.iris} />
      </linearGradient></defs>
      <path d="M78 30 A32 32 0 1 0 80 64" stroke={`url(#${g})`} strokeWidth="13" strokeLinecap="round" />
      <circle cx="50" cy="50" r="8" fill={C.ink} />
    </svg>
  );
}

// Wordmark — lowercase, tight grotesk. Optional iris accent on the leading c.
function Wordmark({ size = 36, color, accent }) {
  color = color || C.ink;
  return (
    <span style={{ fontFamily: C.display, fontWeight: 700, fontSize: size, letterSpacing: '-0.03em', color, lineHeight: 1, whiteSpace: 'nowrap' }}>
      {accent ? <span style={{ color: C.iris }}>c</span> : 'c'}efalia
    </span>
  );
}

// ── BRAIN-FORWARD MARKS ─────────────────────────────────────────
// Smooth lumpy "cortex" blob, generated so it's perfectly symmetric.
function lobePath(cx, cy, bumps, rOut, rIn) {
  const total = bumps * 2, pts = [];
  for (let i = 0; i < total; i++) {
    const a = (i / total) * Math.PI * 2 - Math.PI / 2;
    const r = i % 2 === 0 ? rOut : rIn;
    pts.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r]);
  }
  const m0 = [(pts[0][0] + pts[total - 1][0]) / 2, (pts[0][1] + pts[total - 1][1]) / 2];
  let d = `M ${m0[0].toFixed(1)} ${m0[1].toFixed(1)} `;
  for (let i = 0; i < total; i++) {
    const cur = pts[i], nxt = pts[(i + 1) % total];
    const mid = [(cur[0] + nxt[0]) / 2, (cur[1] + nxt[1]) / 2];
    d += `Q ${cur[0].toFixed(1)} ${cur[1].toFixed(1)} ${mid[0].toFixed(1)} ${mid[1].toFixed(1)} `;
  }
  return d + 'Z';
}

// 9 ─ Cortex: top-down brain, lumpy outline + fissure + gyri.
function CortexMark({ s = 120 }) {
  const g = gid('cx');
  const blob = lobePath(50, 50, 7, 39, 32);
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.iris} /><stop offset="0.5" stopColor={C.teal} /><stop offset="1" stopColor={C.emerald} />
      </linearGradient></defs>
      <path d={blob} stroke={`url(#${g})`} strokeWidth="6" strokeLinejoin="round" />
      <path d="M50 19 V81" stroke={C.ink} strokeWidth="4.5" strokeLinecap="round" />
      <path d="M50 33 Q36 36 38 50 Q40 64 50 67" stroke={C.ink} strokeWidth="3.4" strokeLinecap="round" opacity="0.55" />
      <path d="M50 33 Q64 36 62 50 Q60 64 50 67" stroke={C.ink} strokeWidth="3.4" strokeLinecap="round" opacity="0.55" />
    </svg>
  );
}

// 10 ─ Brain Circuit: half folds / half circuit (o lado IA do cérebro).
function BrainCircuitMark({ s = 120 }) {
  const g = gid('bc');
  const blob = lobePath(50, 50, 7, 39, 32);
  const nodes = [[64, 32], [74, 48], [66, 64], [54, 56], [58, 40]];
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs>
        <linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
          <stop offset="0" stopColor={C.iris} /><stop offset="1" stopColor={C.teal} />
        </linearGradient>
        <clipPath id={g + 'L'}><rect x="0" y="0" width="50" height="100" /></clipPath>
        <clipPath id={g + 'R'}><rect x="50" y="0" width="50" height="100" /></clipPath>
      </defs>
      <path d={blob} stroke={C.ink} strokeWidth="6" strokeLinejoin="round" />
      {/* left: organic folds */}
      <g clipPath={`url(#${g}L)`}>
        <path d="M44 30 Q30 34 32 50 Q34 66 44 70" stroke={`url(#${g})`} strokeWidth="3.6" strokeLinecap="round" />
        <path d="M40 42 Q34 46 40 56" stroke={`url(#${g})`} strokeWidth="3.6" strokeLinecap="round" />
      </g>
      {/* right: circuit */}
      <g clipPath={`url(#${g}R)`}>
        <path d="M54 50 L64 32 M64 32 L74 48 M74 48 L66 64 M66 64 L54 56 M54 56 L58 40" stroke={C.teal} strokeWidth="2.6" strokeLinecap="round" strokeLinejoin="round" />
        {nodes.map((n, i) => <circle key={i} cx={n[0]} cy={n[1]} r="3.4" fill={i % 2 ? C.iris : C.teal} />)}
      </g>
      <path d="M50 20 V80" stroke={C.ink} strokeWidth="3" strokeLinecap="round" opacity="0.35" />
    </svg>
  );
}

// 11 ─ Brain Constellation: cortex outline filled with a neural network.
function BrainNetMark({ s = 120 }) {
  const g = gid('bn');
  const blob = lobePath(50, 50, 7, 39, 32);
  const n = [[50, 28, C.iris], [33, 42, C.teal], [40, 60, C.emerald], [58, 64, C.amber], [68, 46, C.teal], [56, 42, C.irisLt]];
  const edges = [[0, 1], [0, 5], [1, 2], [2, 3], [3, 4], [4, 5], [5, 2], [1, 5]];
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.iris} /><stop offset="1" stopColor={C.emerald} />
      </linearGradient></defs>
      <path d={blob} stroke={`url(#${g})`} strokeWidth="5" strokeLinejoin="round" opacity="0.9" />
      {edges.map((e, i) => (
        <line key={i} x1={n[e[0]][0]} y1={n[e[0]][1]} x2={n[e[1]][0]} y2={n[e[1]][1]} stroke={C.ink} strokeWidth="1.8" opacity="0.4" />
      ))}
      {n.map((p, i) => <circle key={i} cx={p[0]} cy={p[1]} r={i === 0 ? 4.6 : 3.4} fill={p[2]} />)}
    </svg>
  );
}

// 12 ─ Mind Tile: app-tile da família com um cérebro em negativo.
function BrainTileMark({ s = 120 }) {
  const g = gid('bt');
  const blob = lobePath(50, 52, 7, 26, 21);
  return (
    <svg width={s} height={s} viewBox="0 0 100 100" fill="none">
      <defs><linearGradient id={g} x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={C.iris} /><stop offset="0.55" stopColor={C.teal} /><stop offset="1" stopColor={C.emerald} />
      </linearGradient></defs>
      <rect x="6" y="6" width="88" height="88" rx="26" fill={`url(#${g})`} />
      <path d={blob} stroke={C.white} strokeWidth="4.5" strokeLinejoin="round" />
      <path d="M50 35 V69" stroke={C.white} strokeWidth="3.2" strokeLinecap="round" />
      <path d="M50 44 Q41 46 43 54" stroke={C.white} strokeWidth="2.6" strokeLinecap="round" opacity="0.8" />
      <path d="M50 44 Q59 46 57 54" stroke={C.white} strokeWidth="2.6" strokeLinecap="round" opacity="0.8" />
    </svg>
  );
}

window.CefaliaLogos = {
  list: [
    { key: 'cortex',   name: 'Cortex',        Comp: CortexMark,      desc: 'Cérebro em vista superior — sulcos + fissura central.' },
    { key: 'braincir', name: 'Brain Circuit', Comp: BrainCircuitMark,desc: 'Metade dobras, metade circuito: o lado IA do cérebro.' },
    { key: 'brainnet', name: 'Brain Network', Comp: BrainNetMark,    desc: 'Cérebro preenchido por uma rede neural de nós.' },
    { key: 'braintile',name: 'Mind Tile',     Comp: BrainTileMark,   desc: 'Tile da família com cérebro em negativo.' },
    { key: 'synapse',  name: 'Synapse C',     Comp: SynapseC,     desc: 'Monograma + sinapse. Terminais nas cores dos produtos.' },
    { key: 'hub',      name: 'Neural Hub',    Comp: NeuralHub,    desc: 'Cérebro central + satélites = o ecossistema.' },
    { key: 'hemi',     name: 'Hemisférios',   Comp: Hemispheres,  desc: 'Dois lóbulos, uma sinapse no centro.' },
    { key: 'tile',     name: 'App Tile',      Comp: TileMark,     desc: 'Tile da família — pareia com iEntrega/Atende.' },
    { key: 'spark',    name: 'Spark',         Comp: SparkMark,    desc: 'A faísca neural. Ecoa o ícone do Atende AI.' },
    { key: 'gyri',     name: 'Gyri',          Comp: GyriMark,     desc: 'Dobras do córtex aninhadas formando um C.' },
    { key: 'neuron',   name: 'Neurônio',      Comp: NeuronMark,   desc: 'Soma hexagonal com dendritos conectados.' },
    { key: 'spectrum', name: 'Spectrum Ring', Comp: SpectrumRing, desc: 'Anel aberto com o espectro neural completo.' },
  ],
  Wordmark,
};
