/* ============================================================
   ICONS — simple monoline glyphs (currentColor)
   ============================================================ */
function Icon({name, size=20, sw=1.6, style}){
  const common = { width:size, height:size, viewBox:'0 0 24 24', fill:'none',
    stroke:'currentColor', strokeWidth:sw, strokeLinecap:'round', strokeLinejoin:'round', style };
  const P = {
    coin: <><circle cx="12" cy="12" r="8"/><circle cx="12" cy="12" r="4.2"/></>,
    sword: <><path d="M14.5 4 20 4 20 9.5 9 20.5 6.5 20.5 6.5 18 14.5 10"/><path d="M5 17l2 2"/><path d="M14.5 4 14.5 10"/></>,
    dagger: <><path d="M12 3v11"/><path d="M9 14h6l-3 6z"/><path d="M8 14h8"/></>,
    axe: <><path d="M7 21 16 12"/><path d="M14 5a6 6 0 0 1 5 7c-3 1-5-1-5-1l-3 3-2-2 3-3s-2-2-1-5z"/></>,
    bow: <><path d="M6 3c7 3 7 15 0 18"/><path d="M6 3 18 21"/><path d="M5 4 7 3 6 5"/></>,
    staff: <><path d="M12 4v16"/><circle cx="12" cy="4" r="2.2"/><path d="M12 4l3-2M12 4 9 2"/></>,
    mace: <><path d="M6 21 13 14"/><circle cx="16" cy="8" r="4"/><path d="M16 3v2M16 11v2M11 8h2M19 8h2"/></>,
    shield: <><path d="M12 3 5 6v6c0 4 3 6.5 7 9 4-2.5 7-5 7-9V6z"/></>,
    potion: <><path d="M9 3h6"/><path d="M10 3v4l-3.5 9a3 3 0 0 0 2.8 4h5.4a3 3 0 0 0 2.8-4L14 7V3"/><path d="M7.5 14h9"/></>,
    scroll: <><path d="M7 4h10v13a3 3 0 0 1-3 3H7a3 3 0 0 0 3-3V4z"/><path d="M5 17a2 2 0 0 0 2 2"/><path d="M10 8h4M10 11h4"/></>,
    book: <><path d="M5 4h11a2 2 0 0 1 2 2v14H7a2 2 0 0 1-2-2z"/><path d="M18 16H7a2 2 0 0 0-2 2"/></>,
    key: <><circle cx="8" cy="8" r="4"/><path d="M11 11l8 8M16 16l2-2M18 18l2-2"/></>,
    rope: <><path d="M6 4c4 2 4 5 0 7s-4 5 0 7 4 2 0 0"/><circle cx="6" cy="20" r="1"/></>,
    torch: <><path d="M12 3c2 2 3 4 0 7-3-3-2-5 0-7z"/><path d="M10 10l-2 11M14 10l2 11M9 21h6"/></>,
    bread: <><path d="M5 11a3 3 0 0 1 3-3h8a3 3 0 0 1 0 9H8a3 3 0 0 1-3-3z"/><path d="M9 11v4M12 11v4M15 11v4"/></>,
    ring: <><circle cx="12" cy="14" r="6"/><path d="M9 7l3-3 3 3-1.5 2h-3z"/></>,
    item: <><rect x="5" y="7" width="14" height="13" rx="2"/><path d="M9 7V5a3 3 0 0 1 6 0v2"/></>,
    eye: <><path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/></>,
    moon: <><path d="M20 13a8 8 0 1 1-9-9 6.5 6.5 0 0 0 9 9z"/></>,
    give: <><path d="M4 12h13"/><path d="M13 7l5 5-5 5"/><circle cx="20" cy="12" r="0"/></>,
    buy: <><circle cx="9" cy="20" r="1.4"/><circle cx="17" cy="20" r="1.4"/><path d="M3 4h2l2.5 12h10l2-8H6.5"/></>,
    use: <><path d="M12 3v7"/><path d="M8 6l4-3 4 3"/><circle cx="12" cy="16" r="5"/></>,
    skull: <><path d="M5 11a7 7 0 0 1 14 0v3l-1 2h-1v3h-3v-2h-4v2H7v-3H6l-1-2z"/><circle cx="9" cy="11" r="1.3"/><circle cx="15" cy="11" r="1.3"/></>,
    spark: <><path d="M12 3v6M12 15v6M3 12h6M15 12h6"/><path d="M6 6l3 3M15 15l3 3M18 6l-3 3M9 15l-3 3"/></>,
    music: <><path d="M9 18V5l10-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="16" cy="16" r="3"/></>,
    cards: <><rect x="4" y="6" width="11" height="14" rx="1.5"/><path d="M9 4h9a1.5 1.5 0 0 1 1.5 1.5V18"/></>,
    arrowUp: <><path d="M12 19V5M6 11l6-6 6 6"/></>,
    arrowDown: <><path d="M12 5v14M6 13l6 6 6-6"/></>,
    armor: <><path d="M12 3 5 6c0 6 1 9 7 12 6-3 7-6 7-12z"/><path d="M12 3v18"/></>,
    helm: <><path d="M5 11a7 7 0 0 1 14 0v4a2 2 0 0 1-2 2h-2v-3h-2v3h-2v-3H9v3H7a2 2 0 0 1-2-2z"/><path d="M12 11v3"/></>,
    cloak: <><path d="M12 3c3 0 4 2 4 2l3 16H5l3-16s1-2 4-2z"/><path d="M12 3v18"/></>,
    boots: <><path d="M7 3h4v10l5 2a2 2 0 0 1 1 2v2H7z"/><path d="M7 17h11"/></>,
    gem: <><path d="M6 3h12l3 6-9 12L3 9z"/><path d="M3 9h18M9 3 6 9l6 12 6-12-3-6"/></>,
    star: <><path d="M12 3l2.6 5.6L20 9.3l-4 4 1 6-5-2.8L7 19.3l1-6-4-4 5.4-.7z"/></>,
    cart: <><circle cx="9" cy="20" r="1.4"/><circle cx="17" cy="20" r="1.4"/><path d="M3 4h2l2.5 12h10l2-8H6.5"/></>,
    bag: <><path d="M7 8h10l1 11a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2z"/><path d="M9 8a3 3 0 0 1 6 0"/></>,
    heart: <><path d="M12 20s-7-4.5-9-9a4.5 4.5 0 0 1 9-2 4.5 4.5 0 0 1 9 2c-2 4.5-9 9-9 9z"/></>,
  };
  return <svg {...common}>{P[name] || P.item}</svg>;
}

// map an item/weapon name to an icon glyph
function iconFor(name){
  const n = (name||'').toLowerCase();
  if(/coin|gold/.test(n)) return 'coin';
  if(/hammer|mace|club/.test(n)) return 'mace';
  if(/dagger|knife|lockpick/.test(n)) return 'dagger';
  if(/axe/.test(n)) return 'axe';
  if(/bow/.test(n)) return 'bow';
  if(/staff|wand|ember|orb/.test(n)) return 'staff';
  if(/sword|blade|rapier|tongue/.test(n)) return 'sword';
  if(/spear|halberd|glaive|pike/.test(n)) return 'sword';
  if(/shield/.test(n)) return 'shield';
  if(/plate|chain|mail|armor|armour/.test(n)) return 'armor';
  if(/helm|helmet|cap/.test(n)) return 'helm';
  if(/cloak/.test(n)) return 'cloak';
  if(/boot|greave/.test(n)) return 'boots';
  if(/draught|potion|vial|mana|elixir|philter/.test(n)) return 'potion';
  if(/scroll/.test(n)) return 'scroll';
  if(/book|spellbook|tome/.test(n)) return 'book';
  if(/key/.test(n)) return 'key';
  if(/rope/.test(n)) return 'rope';
  if(/torch|lantern|light/.test(n)) return 'torch';
  if(/bread|food|ration|meat|cheese/.test(n)) return 'bread';
  if(/ring|amulet|symbol|holy|pendant/.test(n)) return 'ring';
  if(/gem|crystal|jewel|stone of/.test(n)) return 'gem';
  if(/bag|sack|pouch|gauntlet/.test(n)) return 'bag';
  if(/horn/.test(n)) return 'mace';
  if(/smoke|bandage|wood|tent|tinder|grapp/.test(n)) return 'item';
  return 'item';
}

window.Icon = Icon;
window.iconFor = iconFor;
