/* ============================================================
   VYNDR 2.0 — archetype visual map (Session 42, §Player Intelligence).
   Ported verbatim from the design's ArchetypeBadge.dc.html MAP +
   ArchetypeBlend.dc.html. Plain CommonJS so .tsx imports it AND the
   Jest suite can require it directly (same pattern as vyndrTokens.js).
   Colors/glyphs MUST match src/services/archetypeService.js ARCHETYPES.
   ============================================================ */

/* Glyph SVG inner-markup keyed by name (drawn in a 0 0 16 16 viewBox). */
const GLYPHS = {
  /* Rev 3 — 9 classifier-legacy marks (fallback renders, never user-facing) */
  'brush': '<path fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" d="M5 19 15 9"/><path fill="currentColor" fill-opacity=".2" d="M15 9l4-4 1.6 1.6-4 4z"/><path fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" d="M15 9l4-4M5 19l-1 1M7 20l-2 1"/>',
  'whiff': '<path fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" d="M4 16c5 3 11 3 16-2"/><path fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-dasharray="2.5 3" d="M4 11c5 3 10 3 15-1.5"/><circle cx="18" cy="6" r="2.2" fill="currentColor"/>',
  'connector': '<circle cx="6" cy="7" r="2.4" fill="currentColor"/><circle cx="18" cy="17" r="2.4" fill="currentColor"/><path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" d="M8 8.5C13 11 11 13 16 15.5"/>',
  'distributor': '<circle cx="12" cy="12" r="2.6" fill="currentColor"/><path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M12 9V4M10 6l2-2 2 2M9.5 13.8 5 16.5M7.5 14.2l-2.5 2.3.8 3.2M14.5 13.8 19 16.5M16.5 14.2l2.5 2.3-.8 3.2"/>',
  'fastbreak': '<path fill="currentColor" fill-opacity=".18" d="M10 5l8 7-8 7z"/><path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" d="M10 5l8 7-8 7z"/><path stroke="currentColor" stroke-width="2.2" stroke-linecap="round" d="M5 8h3M4 12h4M5 16h3"/>',
  'flex': '<path fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" d="M8 4C4 8 4 16 8 20M16 4c4 4 4 12 0 16"/><circle cx="12" cy="12" r="2" fill="currentColor"/>',
  'hybrid': '<circle cx="10" cy="12" r="6" fill="none" stroke="currentColor" stroke-width="2"/><path fill="currentColor" fill-opacity=".18" d="M15 6l6 12H9z"/><path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" d="M15 6l6 12H9z"/>',
  'switch': '<path fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round" d="M5 8h11M13 4l4 4-4 4M19 16H8M11 12l-4 4 4 4"/>',
  'switchboard': '<circle cx="6" cy="6" r="1.8" fill="currentColor"/><circle cx="18" cy="6" r="1.8" fill="none" stroke="currentColor" stroke-width="1.8"/><circle cx="6" cy="18" r="1.8" fill="none" stroke="currentColor" stroke-width="1.8"/><circle cx="18" cy="18" r="1.8" fill="currentColor"/><path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" d="M7.5 7.5c4 4 5 4 9 9"/>',

  /* Design 74-mark library — real archetype marks (HANDOFF) */
  'alpha': '<path fill="currentColor" fill-opacity=".16" d="M12 3 4 20h16z"/><path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linejoin="round" d="M12 3 4 20h16zM8.5 14h7"/>',
  'anchor': '<circle cx="12" cy="5" r="2.2" fill="none" stroke="currentColor" stroke-width="2.1"/><path fill="none" stroke="currentColor" stroke-width="2.1" stroke-linecap="round" stroke-linejoin="round" d="M12 7v12M6 13c0 4 3 6 6 6s6-2 6-6M4 13h4M16 13h4"/>',
  'architect': '<path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linejoin="round" d="M12 3 4 19h16z"/><path fill="currentColor" fill-opacity=".18" d="m12 9 4 8H8z"/>',
  'artillery': '<path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" d="M3 20C7 8 14 6 20 6"/><path fill="currentColor" d="M20 6l-4 .3 2 3.4z"/><path stroke="currentColor" stroke-width="1.8" stroke-linecap="round" d="M19 4v-2M22 7h-2"/>',
  'blade': '<path fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" d="M4 20C10 18 16 12 20 4"/><path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" d="M13 5l7-1-1 7"/>',
  'bomber': '<path fill="currentColor" fill-opacity=".18" d="M12 3l7 9h-4v8H9v-8H5z"/><path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" d="M12 3l7 9h-4v8H9v-8H5z"/>',
  'bridge': '<path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" d="M4 18v-8a8 8 0 0 1 16 0v8M4 14h16M9 18v-4M15 18v-4"/>',
  'catalyst': '<path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" d="M3 12h11M10 7l5 5-5 5"/><path fill="currentColor" fill-opacity=".2" d="M16 8h5v8h-5z"/><path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" d="M16 8h5v8h-5z"/>',
  'conductor': '<circle cx="12" cy="16" r="2.6" fill="currentColor"/><path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" d="M12 14 6 5M12 14l6-9M12 14v-4"/>',
  'driver': '<path fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" d="M5 19 17 7"/><circle cx="19" cy="5" r="2.2" fill="currentColor"/><path fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" d="M4 14a10 10 0 0 0 6 6"/>',
  'fortress': '<path fill="currentColor" fill-opacity=".16" d="M5 5h3v2h2V5h4v2h2V5h3v6c0 5-4 7-7 8-3-1-7-3-7-8V5Z"/><path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" d="M5 5h3v2h2V5h4v2h2V5h3v6c0 5-4 7-7 8-3-1-7-3-7-8V5Z"/>',
  'ghost': '<path fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" d="M4 6l6 6-6 6M11 6l6 6-6 6"/>',
  'hammer': '<path fill="currentColor" fill-opacity=".18" d="M6 4h11v5H6z"/><path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" d="M6 4h11v5H6zM11.5 9v11M8 20h7"/>',
  'igniter': '<path fill="currentColor" d="M12 2c.6 4.8 2.4 6.6 7.2 7.2C14.4 9.8 12.6 11.6 12 16.4 11.4 11.6 9.6 9.8 4.8 9.2 9.6 8.6 11.4 6.8 12 2Z"/><path fill="currentColor" d="M18 15c.3 2 1 2.7 3 3-2 .3-2.7 1-3 3-.3-2-1-2.7-3-3 2-.3 2.7-1 3-3Z"/>',
  'lockdown': '<path fill="currentColor" fill-opacity=".16" d="M5 10h14v10H5z"/><path fill="none" stroke="currentColor" stroke-width="2.1" stroke-linejoin="round" d="M5 10h14v10H5zM8 10V7a4 4 0 0 1 8 0v3"/><circle cx="12" cy="15" r="1.6" fill="currentColor"/>',
  'maestro': '<path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" d="M5 19 16 6"/><circle cx="17" cy="5" r="1.9" fill="currentColor"/><path fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" d="M5 9c2-2 5-2 7 0M4 13c2.5-2.5 6-2.5 9 0"/>',
  'mirror': '<path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" d="M9 5 4 12l5 7M15 5l5 7-5 7"/><path stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-dasharray="2 2.6" d="M12 4v16"/>',
  'motor': '<path fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round" d="M6 8a7 7 0 0 1 12 2M18 16a7 7 0 0 1-12-2"/><path fill="currentColor" d="M18 5l1.4 4.2-4.2-1zM6 19l-1.4-4.2 4.2 1z"/>',
  'piston': '<path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" d="M8 4h8v16H8zM12 8v8M9.5 10.5 12 8l2.5 2.5M9.5 13.5 12 16l2.5-2.5"/>',
  'range': '<path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" d="M4 17a8 8 0 0 1 16 0"/><path stroke="currentColor" stroke-width="2.2" stroke-linecap="round" d="M12 17V7"/><path fill="currentColor" d="M12 5l-2.4 4h4.8z"/>',
  'sentinel': '<path fill="currentColor" fill-opacity=".16" d="M12 3 5 6v5c0 5 3.5 7.5 7 9 3.5-1.5 7-4 7-9V6z"/><path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" d="M12 3 5 6v5c0 5 3.5 7.5 7 9 3.5-1.5 7-4 7-9V6z"/><circle cx="12" cy="11" r="2" fill="currentColor"/>',
  'shield': '<path fill="currentColor" fill-opacity=".16" d="M12 3 5 6v5c0 5 3.5 7.5 7 9 3.5-1.5 7-4 7-9V6z"/><path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" d="M12 3 5 6v5c0 5 3.5 7.5 7 9 3.5-1.5 7-4 7-9V6z"/><path stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="m9 11 2 2 4-4"/>',
  'sinker': '<path fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" d="M5 5c6 1 9 5 9 13"/><path fill="currentColor" d="M14 20l-3-4.5 6 .4z"/>',
  'spark': '<circle cx="12" cy="12" r="3" fill="currentColor"/><path fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" d="M12 3v3M12 18v3M4.5 7.5l2.2 2.2M17.3 14.3l2.2 2.2M4.5 16.5l2.2-2.2M17.3 9.7l2.2-2.2"/>',
  'surge': '<path fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" d="M4 18l4-4 3 2 5-6"/><path stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" d="M16 10h4v4"/>',
  'torch': '<path fill="currentColor" fill-opacity=".16" d="M12 2c3.5 4.5 5.5 6 5.5 10a5.5 5.5 0 0 1-11 0C6.5 8 8.5 6.5 12 2Z"/><path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linejoin="round" d="M12 7c2 2.6 3 3.8 3 6a3 3 0 0 1-6 0c0-2.2 1-3.4 3-6Z"/>',
  'tower': '<circle cx="12" cy="6" r="2.6" fill="currentColor"/><path fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" d="M12 9v8M8 20l4-3 4 3M8 13h8"/>',
  'wall': '<path fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" d="M4 5h16v14H4z"/><path stroke="currentColor" stroke-width="1.8" d="M4 9.7h16M4 14.3h16M11 5v4.7M8 9.7v4.6M15 9.7v4.6M11 14.3V19"/>',
  'workhorse': '<path fill="none" stroke="currentColor" stroke-width="2.8" stroke-linecap="round" d="M4 7h16M4 12h16M4 17h16"/>',

  triangle: '<path d="M8 2 L14 14 L2 14 Z" fill="currentColor"/>',
  node: '<circle cx="8" cy="8" r="2.3" fill="currentColor"/><path d="M8 5.7V1.5M5.4 9.3 2.4 13M10.6 9.3 13.6 13" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/>',
  shield: '<path d="M8 1.6 L13.4 4 V8.2 C13.4 11.2 8 14.4 8 14.4 C8 14.4 2.6 11.2 2.6 8.2 V4 Z" fill="currentColor"/>',
  shieldCheck: '<path d="M8 1.6 L13.4 4 V8.2 C13.4 11.2 8 14.4 8 14.4 C8 14.4 2.6 11.2 2.6 8.2 V4 Z" stroke="currentColor" stroke-width="1.5" fill="none"/><path d="M5.6 8 L7.4 9.9 L10.4 6.2" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>',
  target: '<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.5" fill="none"/><circle cx="8" cy="8" r="2.2" fill="currentColor"/>',
  bolt: '<path d="M9 1.6 L4 9 H7.6 L7 14.4 L12 6.6 H8.4 Z" fill="currentColor"/>',
  twin: '<circle cx="6" cy="8" r="3.6" stroke="currentColor" stroke-width="1.6" fill="none"/><circle cx="10" cy="8" r="3.6" stroke="currentColor" stroke-width="1.6" fill="none"/>',
  chain: '<rect x="2.4" y="5.6" width="7" height="4.8" rx="2.4" stroke="currentColor" stroke-width="1.6" fill="none"/><rect x="6.6" y="5.6" width="7" height="4.8" rx="2.4" stroke="currentColor" stroke-width="1.6" fill="none"/>',
  batball: '<path d="M3 13.2 L11 5.2" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/><circle cx="12.4" cy="3.6" r="1.9" fill="currentColor"/>',
  crosshair: '<circle cx="8" cy="8" r="5.6" stroke="currentColor" stroke-width="1.5" fill="none"/><path d="M8 1.4V4.4M8 11.6V14.6M1.4 8H4.4M11.6 8H14.6" stroke="currentColor" stroke-width="1.5"/><circle cx="8" cy="8" r="1.5" fill="currentColor"/>',
  diamond: '<path d="M8 1.6 L14.4 8 L8 14.4 L1.6 8 Z" stroke="currentColor" stroke-width="1.6" fill="none"/><path d="M8 5.4 L10.6 8 L8 10.6 L5.4 8 Z" fill="currentColor"/>',
  diamondLine: '<path d="M8 1.6 L14.4 8 L8 14.4 L1.6 8 Z" stroke="currentColor" stroke-width="1.7" fill="none"/>',
  star: '<path d="M8 1.4 L9.7 6 L14.6 6.3 L10.7 9.3 L12.1 14 L8 11.2 L3.9 14 L5.3 9.3 L1.4 6.3 L6.3 6 Z" fill="currentColor"/>',
  clock: '<circle cx="8" cy="9.2" r="5" stroke="currentColor" stroke-width="1.6" fill="none"/><path d="M8 9.2 V5.6 M6.2 2.2 H9.8" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/>',
  chevrons: '<path d="M2.6 4 L6.6 8 L2.6 12 M7.8 4 L11.8 8 L7.8 12" stroke="currentColor" stroke-width="1.9" fill="none" stroke-linecap="round" stroke-linejoin="round"/>',
  slash: '<path d="M3 13 L13 3 M13 3 H8.6 M13 3 V7.4" stroke="currentColor" stroke-width="1.9" fill="none" stroke-linecap="round" stroke-linejoin="round"/>',
  arc: '<path d="M2 11.5 Q8 1.5 14 11.5" stroke="currentColor" stroke-width="1.7" fill="none" stroke-linecap="round"/><circle cx="13.4" cy="11.2" r="1.6" fill="currentColor"/>',
  plus: '<path d="M8 2.4 V13.6 M2.4 8 H13.6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><circle cx="8" cy="8" r="1.9" fill="currentColor"/>',
  lock: '<rect x="3.6" y="7" width="8.8" height="6.6" rx="1.4" fill="currentColor"/><path d="M5.4 7 V5 a2.6 2.6 0 0 1 5.2 0 V7" stroke="currentColor" stroke-width="1.5" fill="none"/>',
  swap: '<path d="M3 5.6 H11.4 M9.4 3.6 L11.6 5.6 L9.4 7.6 M13 10.4 H4.6 M6.6 8.4 L4.4 10.4 L6.6 12.4" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>',
  half: '<circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.6" fill="none"/><path d="M8 2.2 a5.8 5.8 0 0 1 0 11.6 Z" fill="currentColor"/>',
  uparrow: '<path d="M8 13.4 V3.6 M4.4 7.2 L8 3.6 L11.6 7.2" stroke="currentColor" stroke-width="1.8" fill="none" stroke-linecap="round" stroke-linejoin="round"/>',
  postup: '<rect x="6.4" y="2.6" width="3.2" height="11" rx="1.6" fill="currentColor"/><circle cx="12" cy="5.2" r="1.7" fill="currentColor"/>',
};

/* name → { color, glyph, desc, legacy } — VYNDR Originals (Session 44).
   Keys/colors/glyphs MUST match src/services/archetypeService.js ARCHETYPES.
   `legacy` is the old descriptive label, kept for reference (never displayed). */
const ARCHETYPE_MAP = {
  // NBA
  TORCH: { c: '#FF6B4A', d: 'High usage, shot-dependent scorer', g: 'torch', legacy: 'VOLUME SCORER' },
  CONDUCTOR: { c: '#6C8CFF', d: 'Assist-heavy playmaker', g: 'conductor', legacy: 'FLOOR GENERAL' },
  FORTRESS: { c: '#4C6FA5', d: 'Defense, rebounds, blocks', g: 'fortress', legacy: 'TWO-WAY ANCHOR' },
  ARTILLERY: { c: '#C98A5A', d: 'Floor-spacing shooting big', g: 'artillery', legacy: 'STRETCH BIG' },
  SURGE: { c: '#FFA24A', d: 'Usage spikes when stars sit', g: 'surge', legacy: 'USAGE SPONGE' },
  'DUAL THREAT': { c: '#1EA6D8', d: 'Scoring + playmaking hybrid', g: 'twin', legacy: 'COMBO GUARD' },
  CONNECTOR: { c: '#9AB0C4', d: 'Low-usage specialist', g: 'connector', legacy: 'ROLE GLUE' },
  FASTBREAK: { c: '#4AA0E8', d: 'Pace-pushing fast-break threat', g: 'fastbreak', legacy: 'TRANSITION ENGINE' },
  'PAINT BOSS': { c: '#FF5C5C', d: 'Back-to-basket interior scorer', g: 'postup', legacy: 'POST SCORER' },
  LOCKDOWN: { c: '#5A6474', d: 'Perimeter stopper, low usage', g: 'lockdown', legacy: 'DEFENSIVE SPECIALIST' },
  SWITCHBOARD: { c: '#90A0E8', d: 'Oversized primary creator', g: 'switchboard', legacy: 'POINT FORWARD' },
  ARCHITECT: { c: '#B07CFF', d: 'Self-created shot maker, rim-attacking', g: 'architect', legacy: 'SLASHER' },
  PISTON: { c: '#E87B4A', d: 'Lob and putback finisher', g: 'piston', legacy: 'RIM RUNNER' },
  SENTINEL: { c: '#4FA0C4', d: 'Catch-and-shoot plus defense', g: 'sentinel', legacy: '3-AND-D' },
  IGNITER: { c: '#FF8A3D', d: 'Bench scoring spark', g: 'igniter', legacy: 'SIXTH MAN' },
  // WNBA-unique
  DISTRIBUTOR: { c: '#7AB8D8', d: 'Playmaking hub from the post', g: 'distributor', legacy: 'POST FACILITATOR' },
  SHIELD: { c: '#5A8CA8', d: 'Two-way perimeter forward', g: 'shield', legacy: 'TWO-WAY WING' },
  RANGE: { c: '#C77CE0', d: 'Floor-spacing forward', g: 'range', legacy: 'STRETCH FORWARD' },
  SPARK: { c: '#F0A93D', d: 'Downhill scoring guard', g: 'spark', legacy: 'SLASHING GUARD' },
  ANCHOR: { c: '#4C86C4', d: 'Dominant paint defender and rebounder', g: 'anchor', legacy: 'INTERIOR ANCHOR' },
  // MLB
  BOMBER: { c: '#FF9F45', d: 'Middle-of-the-order power producer', g: 'bomber', legacy: 'POWER SLUGGER' },
  BRUSH: { c: '#E0B84A', d: 'High average, low strikeout', g: 'brush', legacy: 'CONTACT' },
  DRIVER: { c: '#5A7D9A', d: 'RBI-dependent, lineup context', g: 'driver', legacy: 'RUN PRODUCER' },
  ALPHA: { c: '#7C5CFF', d: 'High K/9, low WHIP, deep games', g: 'alpha', legacy: 'ACE' },
  WHIFF: { c: '#E86A6A', d: 'Bat-missing arm, high K with traffic', g: 'whiff', legacy: 'STRIKEOUT ARTIST' },
  GHOST: { c: '#3FD8E0', d: 'Stolen bases, speed score', g: 'ghost', legacy: 'SPEED THREAT' },
  HYBRID: { c: '#C88AB0', d: 'Bats and pitches at elite level', g: 'hybrid', legacy: 'TWO-WAY PLAYER' },
  FLEX: { c: '#A08AC8', d: 'Multi-position lineup flex', g: 'flex', legacy: 'UTILITY PLAYER' },
  WORKHORSE: { c: '#C89B5A', d: 'Durable, deep-start arm', g: 'workhorse', legacy: 'INNINGS EATER' },
  CATALYST: { c: '#E88AC0', d: 'On-base leadoff catalyst', g: 'catalyst', legacy: 'TABLE SETTER' },
  MIRROR: { c: '#B0B6C8', d: 'Gap-to-gap line-drive bat', g: 'mirror', legacy: 'GAP HITTER' },
  HAMMER: { c: '#FF4D6D', d: 'Ninth-inning save specialist', g: 'hammer', legacy: 'CLOSER' },
  SINKER: { c: '#5A9AB0', d: 'Groundball spot-starter / long relief', g: 'sinker', legacy: 'SWINGMAN' },
  BRIDGE: { c: '#6C9CB0', d: 'Setup / high-leverage middle relief', g: 'bridge', legacy: 'BULLPEN ARM' },
  SWITCH: { c: '#C0B08A', d: 'Platoon-leveraged, glove-first bat', g: 'switch', legacy: 'DEFENSIVE WIZARD' },
  // Soccer
  FINISHER: { c: '#FF5C5C', d: 'Penalty-box finisher', g: 'crosshair', legacy: 'POACHER' },
  MAESTRO: { c: '#D9A441', d: 'Chance-creating playmaker', g: 'maestro', legacy: 'CREATOR' },
  TOWER: { c: '#6C9CB0', d: 'Hold-up aerial striker', g: 'tower', legacy: 'TARGET MAN' },
  MOTOR: { c: '#E0A03D', d: 'All-action central midfielder', g: 'motor', legacy: 'BOX-TO-BOX' },
  BLADE: { c: '#B36CFF', d: 'Dribbling wide threat', g: 'blade', legacy: 'WING WIZARD' },
  WALL: { c: '#5A7D9A', d: 'Distributing goalkeeper', g: 'wall', legacy: 'SWEEPER KEEPER' },
};

/* Combat archetype visual map (Wave 6 — MMA/UFC). SEPARATE from ARCHETYPE_MAP:
   FINISHER's combat name/color/glyph differ from the soccer FINISHER, and
   combat FINISHER's green is intentionally close to the pitch-green here. Keys/
   colors/glyph CHARS MUST match src/services/archetypeService.js
   COMBAT_ARCHETYPES — tests/unit/combatArchetypes.test.js asserts it.
   `char` is a unicode glyph (rendered as text, not an SVG glyph key). */
const COMBAT_ARCHETYPE_MAP = {
  STRIKER:  { c: '#E8703A', d: 'Wins on the feet — volume + power at range.',   char: '✦', axis: 'range' },
  GRAPPLER: { c: '#2FA4E7', d: 'Fight hits the mat on his terms — control + subs.', char: '⊗', axis: 'range' },
  PRESSURE: { c: '#E4574C', d: 'Forward, relentless, breaks the pace.',          char: '➤', axis: 'tempo' },
  COUNTER:  { c: '#8E7BE0', d: 'Patient — punishes what you show him.',          char: '◊', axis: 'tempo' },
  FINISHER: { c: '#12B886', d: 'Ends nights — high KO/SUB rate.',                char: '▲', axis: 'outcome' },
  GRINDER:  { c: '#B0883B', d: 'Goes the distance, wins the rounds.',            char: '▦', axis: 'outcome' },
};

const FALLBACK = { c: '#9499A8', d: '', g: '' };

// Reverse index so an old legacy name (e.g. "POWER SLUGGER") still resolves to
// its VYNDR Original (BOMBER) — defends any stale cached data post-rename.
const LEGACY_INDEX = {};
for (const [k, v] of Object.entries(ARCHETYPE_MAP)) {
  if (v.legacy) LEGACY_INDEX[v.legacy.toUpperCase()] = k;
}

function archetypeInfo(name, sport) {
  const key = (name == null ? '' : String(name)).toUpperCase();
  // Combat archetypes live in their own namespace (FINISHER collides with the
  // soccer archetype) — resolve them ONLY when the sport is MMA.
  if (String(sport || '').toLowerCase() === 'mma' && COMBAT_ARCHETYPE_MAP[key]) {
    return COMBAT_ARCHETYPE_MAP[key];
  }
  if (ARCHETYPE_MAP[key]) return ARCHETYPE_MAP[key];
  if (LEGACY_INDEX[key]) return ARCHETYPE_MAP[LEGACY_INDEX[key]];
  return FALLBACK;
}

function archetypeColor(name, sport) {
  return archetypeInfo(name, sport).c;
}

/** Combat-only color lookup (unambiguous — no soccer FINISHER collision). */
function combatArchetypeColor(name) {
  const key = (name == null ? '' : String(name)).toUpperCase();
  return (COMBAT_ARCHETYPE_MAP[key] || FALLBACK).c;
}

function glyphSvg(glyphKey) {
  const inner = GLYPHS[glyphKey] || '';
  return `<svg viewBox="0 0 16 16" width="100%" height="100%" style="display:block">${inner}</svg>`;
}

/**
 * Resolve the full style bundle for a badge — mirrors the design's renderVals.
 * variant: 'full' (solid) | 'ghost' (outline) | 'tint' (default).
 * size: 'sm' | 'md'.
 */
function badgeStyle(name, variant = 'tint', size = 'sm', sport) {
  const info = archetypeInfo(name, sport);
  const sm = size === 'sm';
  let textColor, bg, borderColor, glyphColor, textShadow = 'none';
  if (variant === 'full' || variant === 'solid') {
    textColor = '#FFFFFF'; bg = info.c; borderColor = info.c; glyphColor = '#FFFFFF';
    textShadow = '0 1px 2px rgba(0,0,0,0.38)';
  } else if (variant === 'ghost' || variant === 'outline') {
    textColor = info.c; bg = 'transparent'; borderColor = info.c + 'CC'; glyphColor = info.c;
  } else {
    textColor = info.c; bg = info.c + '1F'; borderColor = info.c + '52'; glyphColor = info.c;
  }
  // Display the canonical VYNDR name even if a legacy name was passed.
  const upper = (name == null ? '' : String(name)).toUpperCase();
  const isCombat = String(sport || '').toLowerCase() === 'mma' && COMBAT_ARCHETYPE_MAP[upper];
  const canonical = isCombat ? upper : ARCHETYPE_MAP[upper] ? upper : LEGACY_INDEX[upper] || upper;
  return {
    name: canonical,
    desc: info.d,
    glyph: info.g,
    // Combat glyphs are unicode chars rendered as TEXT (not SVG glyph keys).
    glyphChar: isCombat ? info.char : null,
    color: info.c,
    textColor, bg, borderColor, glyphColor, textShadow,
    fontSize: sm ? '9.5px' : '12px',
    padding: sm ? '3px 7px 3px 6px' : '5px 11px 5px 9px',
    radius: sm ? '4px' : '6px',
    glyphSize: sm ? '11px' : '14px',
    descSize: sm ? '11px' : '13px',
  };
}

module.exports = {
  GLYPHS,
  ARCHETYPE_MAP,
  COMBAT_ARCHETYPE_MAP,
  archetypeInfo,
  archetypeColor,
  combatArchetypeColor,
  glyphSvg,
  badgeStyle,
};
