// SVG sigils for the tarot deck.
// Minimal symbolic style: a single glyph per card, gold strokes on dark.
// Stroke uses currentColor so we can theme.

const S = ({ d, vb = "0 0 64 64", strokeWidth = 1.2, fill = "none", children }) => (
  <svg viewBox={vb} xmlns="http://www.w3.org/2000/svg" fill={fill} stroke="currentColor"
       strokeWidth={strokeWidth} strokeLinecap="round" strokeLinejoin="round">
    {d ? <path d={d}/> : children}
  </svg>
);

// ────────────────────────────────────────────────────────────────
// Major Arcana glyphs — each a single mystical icon
// ────────────────────────────────────────────────────────────────
const SIGILS = {

  // 0 — The Fool — infinity / leap
  fool: () => (
    <S>
      <path d="M16 40 C 16 28, 28 28, 32 36 C 36 44, 48 44, 48 32 C 48 20, 36 20, 32 28 C 28 36, 16 36, 16 24" />
      <circle cx="32" cy="14" r="1.5" fill="currentColor"/>
    </S>
  ),

  // I — The Magician — ∞ over hand/staff
  magician: () => (
    <S>
      <path d="M14 24 C 14 18, 22 18, 24 24 C 26 30, 34 30, 36 24 C 38 18, 46 18, 46 24" />
      <path d="M14 24 C 14 30, 22 30, 24 24" />
      <path d="M36 24 C 38 30, 46 30, 46 24" />
      <line x1="30" y1="34" x2="30" y2="54"/>
      <line x1="34" y1="34" x2="34" y2="54"/>
      <circle cx="32" cy="32" r="1.5" fill="currentColor"/>
    </S>
  ),

  // II — High Priestess — crescent
  priestess: () => (
    <S>
      <path d="M44 12 A 22 22 0 1 0 44 52 A 16 16 0 1 1 44 12 Z"/>
      <circle cx="32" cy="32" r="2" fill="currentColor"/>
    </S>
  ),

  // III — Empress — Venus
  empress: () => (
    <S>
      <circle cx="32" cy="22" r="11"/>
      <line x1="32" y1="33" x2="32" y2="54"/>
      <line x1="24" y1="46" x2="40" y2="46"/>
      <circle cx="32" cy="22" r="3" fill="currentColor"/>
    </S>
  ),

  // IV — Emperor — square with crown
  emperor: () => (
    <S>
      <rect x="16" y="22" width="32" height="28"/>
      <path d="M14 22 L 22 14 L 26 18 L 32 12 L 38 18 L 42 14 L 50 22"/>
      <circle cx="22" cy="14" r="1.5" fill="currentColor"/>
      <circle cx="32" cy="12" r="1.5" fill="currentColor"/>
      <circle cx="42" cy="14" r="1.5" fill="currentColor"/>
    </S>
  ),

  // V — Hierophant — triple cross
  hierophant: () => (
    <S>
      <line x1="32" y1="10" x2="32" y2="56"/>
      <line x1="22" y1="20" x2="42" y2="20"/>
      <line x1="20" y1="30" x2="44" y2="30"/>
      <line x1="18" y1="40" x2="46" y2="40"/>
      <circle cx="32" cy="10" r="1.5" fill="currentColor"/>
    </S>
  ),

  // VI — Lovers — interlocking circles
  lovers: () => (
    <S>
      <circle cx="24" cy="32" r="14"/>
      <circle cx="40" cy="32" r="14"/>
      <path d="M32 18 L 32 46" strokeDasharray="2 3"/>
    </S>
  ),

  // VII — Chariot — wheel/star
  chariot: () => (
    <S>
      <circle cx="32" cy="32" r="18"/>
      <line x1="32" y1="14" x2="32" y2="50"/>
      <line x1="14" y1="32" x2="50" y2="32"/>
      <line x1="19" y1="19" x2="45" y2="45"/>
      <line x1="45" y1="19" x2="19" y2="45"/>
      <circle cx="32" cy="32" r="3" fill="currentColor"/>
    </S>
  ),

  // VIII — Strength — infinity & flower
  strength: () => (
    <S>
      <path d="M14 32 C 14 24, 22 24, 24 32 C 26 40, 34 40, 36 32 C 38 24, 46 24, 50 32 C 46 40, 38 40, 36 32 C 34 24, 26 24, 24 32 C 22 40, 14 40, 14 32 Z"/>
      <circle cx="32" cy="48" r="3"/>
      <path d="M32 45 L 32 41 M28 47 L 25 45 M36 47 L 39 45"/>
    </S>
  ),

  // IX — Hermit — lantern / star inside
  hermit: () => (
    <S>
      <path d="M22 16 L 42 16 L 42 50 L 22 50 Z"/>
      <line x1="20" y1="16" x2="44" y2="16"/>
      <line x1="32" y1="10" x2="32" y2="16"/>
      <polygon points="32,24 35,30 41,30 36,34 38,40 32,37 26,40 28,34 23,30 29,30"/>
    </S>
  ),

  // X — Wheel — circle with cross + symbols
  wheel: () => (
    <S>
      <circle cx="32" cy="32" r="20"/>
      <circle cx="32" cy="32" r="12"/>
      <line x1="12" y1="32" x2="52" y2="32"/>
      <line x1="32" y1="12" x2="32" y2="52"/>
      <line x1="18" y1="18" x2="46" y2="46"/>
      <line x1="46" y1="18" x2="18" y2="46"/>
    </S>
  ),

  // XI — Justice — scales
  justice: () => (
    <S>
      <line x1="32" y1="12" x2="32" y2="50"/>
      <line x1="16" y1="20" x2="48" y2="20"/>
      <path d="M16 20 L 10 36 L 22 36 Z"/>
      <path d="M48 20 L 42 36 L 54 36 Z"/>
      <line x1="26" y1="50" x2="38" y2="50"/>
    </S>
  ),

  // XII — Hanged Man — inverted triangle on cross
  hanged: () => (
    <S>
      <line x1="16" y1="14" x2="48" y2="14"/>
      <line x1="32" y1="14" x2="32" y2="24"/>
      <polygon points="32,24 18,46 46,46"/>
      <circle cx="32" cy="38" r="2.5" fill="currentColor"/>
    </S>
  ),

  // XIII — Death — scythe / skull
  death: () => (
    <S>
      <path d="M14 50 L 36 14"/>
      <path d="M14 18 C 18 14, 28 14, 32 22 C 28 22, 22 24, 18 26 Z"/>
      <circle cx="44" cy="44" r="8"/>
      <circle cx="41" cy="43" r="1.2" fill="currentColor"/>
      <circle cx="47" cy="43" r="1.2" fill="currentColor"/>
      <path d="M40 50 L 48 50"/>
    </S>
  ),

  // XIV — Temperance — two triangles overlapping
  temperance: () => (
    <S>
      <polygon points="32,12 14,42 50,42"/>
      <polygon points="32,52 14,22 50,22"/>
    </S>
  ),

  // XV — Devil — inverted pentagram
  devil: () => (
    <S>
      <circle cx="32" cy="32" r="20"/>
      <polygon points="32,52 14,22 50,40 14,40 50,22"/>
    </S>
  ),

  // XVI — Tower — tower with lightning
  tower: () => (
    <S>
      <rect x="22" y="22" width="20" height="32"/>
      <polygon points="20,22 32,12 44,22"/>
      <path d="M44 14 L 36 28 L 42 28 L 34 44" />
    </S>
  ),

  // XVII — Star — 7-pointed star
  star: () => (
    <S>
      <polygon points="32,10 38,24 52,26 42,36 46,52 32,44 18,52 22,36 12,26 26,24"/>
      <circle cx="32" cy="32" r="2" fill="currentColor"/>
    </S>
  ),

  // XVIII — Moon — crescent with two towers below
  moon: () => (
    <S>
      <path d="M40 14 A 16 16 0 1 0 40 46 A 12 12 0 1 1 40 14 Z"/>
      <line x1="18" y1="38" x2="18" y2="54"/>
      <line x1="46" y1="38" x2="46" y2="54"/>
      <line x1="14" y1="54" x2="50" y2="54"/>
    </S>
  ),

  // XIX — Sun — sun with rays
  sun: () => (
    <S>
      <circle cx="32" cy="32" r="10"/>
      <line x1="32" y1="10" x2="32" y2="16"/>
      <line x1="32" y1="48" x2="32" y2="54"/>
      <line x1="10" y1="32" x2="16" y2="32"/>
      <line x1="48" y1="32" x2="54" y2="32"/>
      <line x1="17" y1="17" x2="21" y2="21"/>
      <line x1="43" y1="43" x2="47" y2="47"/>
      <line x1="47" y1="17" x2="43" y2="21"/>
      <line x1="17" y1="47" x2="21" y2="43"/>
    </S>
  ),

  // XX — Judgement — trumpet / flame
  judgement: () => (
    <S>
      <path d="M14 32 L 36 22 L 36 42 Z"/>
      <line x1="36" y1="32" x2="50" y2="32"/>
      <path d="M44 22 C 48 26, 48 38, 44 42"/>
      <path d="M30 12 C 32 14, 32 18, 30 20 C 28 22, 28 26, 32 28"/>
    </S>
  ),

  // XXI — World — wreath / ouroboros
  world: () => (
    <S>
      <ellipse cx="32" cy="32" rx="18" ry="22"/>
      <circle cx="20" cy="20" r="2"/>
      <circle cx="44" cy="20" r="2"/>
      <circle cx="20" cy="44" r="2"/>
      <circle cx="44" cy="44" r="2"/>
      <circle cx="32" cy="32" r="4"/>
    </S>
  ),

  // ────────────────────────────────────────────────────────────────
  // Suit sigils
  // ────────────────────────────────────────────────────────────────

  // Wands — flaming rod
  'suit-wands': () => (
    <S>
      <line x1="32" y1="12" x2="32" y2="52" strokeWidth="1.8"/>
      <path d="M28 10 C 30 14, 30 16, 28 20 M36 10 C 34 14, 34 16, 36 20" strokeWidth="1.4"/>
      <path d="M22 18 L 26 18 M38 18 L 42 18"/>
      <path d="M22 50 L 42 50"/>
    </S>
  ),

  // Cups — chalice
  'suit-cups': () => (
    <S>
      <path d="M18 18 L 46 18 L 42 36 C 42 42, 36 46, 32 46 C 28 46, 22 42, 22 36 Z"/>
      <line x1="32" y1="46" x2="32" y2="54"/>
      <line x1="24" y1="54" x2="40" y2="54"/>
      <path d="M26 22 L 38 22"/>
    </S>
  ),

  // Swords — sword
  'suit-swords': () => (
    <S>
      <line x1="32" y1="10" x2="32" y2="46" strokeWidth="1.8"/>
      <line x1="22" y1="40" x2="42" y2="40"/>
      <line x1="32" y1="46" x2="32" y2="54"/>
      <circle cx="32" cy="54" r="2" fill="currentColor"/>
      <line x1="28" y1="14" x2="32" y2="10" />
      <line x1="36" y1="14" x2="32" y2="10" />
    </S>
  ),

  // Pentacles — pentacle / star in circle
  'suit-pentacles': () => (
    <S>
      <circle cx="32" cy="32" r="20"/>
      <polygon points="32,16 37,28 50,28 39,36 44,48 32,40 20,48 25,36 14,28 27,28"/>
    </S>
  ),

  // ────────────────────────────────────────────────────────────────
  // Misc decorative + voice glyphs
  // ────────────────────────────────────────────────────────────────

  'mark': () => (
    <S>
      <path d="M32 8 L 36 28 L 56 32 L 36 36 L 32 56 L 28 36 L 8 32 L 28 28 Z"/>
    </S>
  ),

  'sigil-mark': () => (
    <S>
      <path d="M32 10 L 34 24 L 48 22 L 38 32 L 48 42 L 34 40 L 32 54 L 30 40 L 16 42 L 26 32 L 16 22 L 30 24 Z"/>
      <circle cx="32" cy="32" r="3"/>
    </S>
  ),

  'voice-moon': () => (
    <S>
      <path d="M42 12 A 20 20 0 1 0 42 52 A 14 14 0 1 1 42 12 Z"/>
    </S>
  ),
  'voice-lantern': () => (
    <S>
      <rect x="20" y="18" width="24" height="32"/>
      <line x1="32" y1="10" x2="32" y2="18"/>
      <polygon points="32,28 35,34 41,34 36,38 38,44 32,41 26,44 28,38 23,34 29,34"/>
    </S>
  ),
  'voice-star': () => (
    <S>
      <polygon points="32,10 38,26 54,26 42,36 46,52 32,42 18,52 22,36 10,26 26,26"/>
    </S>
  ),
  'voice-wing': () => (
    <S>
      <path d="M12 40 C 20 28, 32 22, 52 22 C 44 30, 32 38, 12 40 Z"/>
      <path d="M22 38 C 26 32, 32 30, 40 28"/>
    </S>
  ),
  'voice-flame': () => (
    <S>
      <path d="M32 10 C 28 18, 20 22, 22 32 C 24 42, 30 44, 32 54 C 34 44, 40 42, 42 32 C 44 22, 36 18, 32 10 Z"/>
    </S>
  ),
  'voice-cross': () => (
    <S>
      <line x1="32" y1="12" x2="32" y2="52"/>
      <line x1="20" y1="24" x2="44" y2="24"/>
      <circle cx="32" cy="38" r="6"/>
    </S>
  ),

  // play/pause/etc
  'play': () => <S vb="0 0 24 24" fill="currentColor" strokeWidth="0"><polygon points="6,4 20,12 6,20"/></S>,
  'pause': () => <S vb="0 0 24 24" fill="currentColor" strokeWidth="0"><rect x="5" y="4" width="5" height="16"/><rect x="14" y="4" width="5" height="16"/></S>,
  'volume': () => (
    <S vb="0 0 24 24">
      <path d="M3 9 L 3 15 L 8 15 L 13 19 L 13 5 L 8 9 Z" fill="currentColor" strokeWidth="0"/>
      <path d="M17 8 C 19 10, 19 14, 17 16"/>
      <path d="M20 5 C 24 9, 24 15, 20 19"/>
    </S>
  ),
  'volume-off': () => (
    <S vb="0 0 24 24">
      <path d="M3 9 L 3 15 L 8 15 L 13 19 L 13 5 L 8 9 Z" fill="currentColor" strokeWidth="0"/>
      <line x1="16" y1="8" x2="22" y2="14"/>
      <line x1="22" y1="8" x2="16" y2="14"/>
    </S>
  ),
  'chevron-right': () => <S vb="0 0 24 24"><polyline points="8,4 16,12 8,20"/></S>,
  'chevron-left': () => <S vb="0 0 24 24"><polyline points="16,4 8,12 16,20"/></S>,
  'check': () => <S vb="0 0 24 24"><polyline points="4,12 10,18 20,6"/></S>,
  'shuffle-icon': () => (
    <S vb="0 0 24 24">
      <path d="M3 7 L 8 7 L 12 17 L 16 17 L 21 17"/>
      <path d="M3 17 L 8 17 L 12 7 L 16 7 L 21 7"/>
      <polyline points="18,4 21,7 18,10"/>
      <polyline points="18,14 21,17 18,20"/>
    </S>
  ),
  'scissors': () => (
    <S vb="0 0 24 24">
      <circle cx="6" cy="6" r="3"/>
      <circle cx="6" cy="18" r="3"/>
      <line x1="8" y1="8" x2="20" y2="20"/>
      <line x1="8" y1="16" x2="20" y2="4"/>
    </S>
  ),
};

// ────────────────────────────────────────────────────────────────
// Ornament library — corner filigree, back pattern, fleurons
// ────────────────────────────────────────────────────────────────
const ORNAMENTS = {
  // Corner filigree — placed in each card-front corner
  'corner-filigree': () => (
    <svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" strokeWidth="0.9" strokeLinecap="round" strokeLinejoin="round">
      <path d="M2 2 L 14 2"/>
      <path d="M2 2 L 2 14"/>
      <path d="M2 8 C 6 8, 8 6, 8 2"/>
      <path d="M5 5 C 8 5, 10 7, 10 10" />
      <circle cx="2" cy="2" r="1.2" fill="currentColor" stroke="none"/>
      <circle cx="8" cy="8" r="0.8" fill="currentColor" stroke="none"/>
    </svg>
  ),

  // Fleuron — small decorative leaf used between elements
  'fleuron': () => (
    <svg viewBox="0 0 40 16" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" strokeWidth="0.9" strokeLinecap="round" strokeLinejoin="round">
      <line x1="2" y1="8" x2="14" y2="8"/>
      <path d="M14 8 C 17 4, 20 4, 20 8 C 20 12, 23 12, 26 8"/>
      <path d="M26 8 L 38 8"/>
      <circle cx="20" cy="8" r="1.4" fill="currentColor" stroke="none"/>
      <path d="M16 8 C 18 6, 18 10, 20 8"/>
      <path d="M24 8 C 22 6, 22 10, 20 8"/>
    </svg>
  ),

  // Mandala backdrop — radial decoration behind sigil
  'mandala': () => (
    <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" strokeWidth="0.5" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="50" cy="50" r="46"/>
      <circle cx="50" cy="50" r="38"/>
      {Array.from({length: 12}).map((_, i) => {
        const a = (i * 30) * Math.PI / 180;
        const x1 = 50 + Math.cos(a) * 38;
        const y1 = 50 + Math.sin(a) * 38;
        const x2 = 50 + Math.cos(a) * 46;
        const y2 = 50 + Math.sin(a) * 46;
        return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2}/>;
      })}
      {Array.from({length: 24}).map((_, i) => {
        const a = (i * 15 + 7.5) * Math.PI / 180;
        const x = 50 + Math.cos(a) * 42;
        const y = 50 + Math.sin(a) * 42;
        return <circle key={i} cx={x} cy={y} r="0.6" fill="currentColor" stroke="none"/>;
      })}
    </svg>
  ),

  // Back pattern — ornate filigree center for card backs
  'back-ornament': () => (
    <svg viewBox="0 0 100 140" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" strokeWidth="0.7" strokeLinecap="round" strokeLinejoin="round">
      {/* outer frame within */}
      <rect x="6" y="6" width="88" height="128"/>
      <rect x="10" y="10" width="80" height="120"/>
      {/* corner flourishes */}
      <path d="M10 22 C 14 18, 18 14, 22 10"/>
      <path d="M90 22 C 86 18, 82 14, 78 10"/>
      <path d="M10 118 C 14 122, 18 126, 22 130"/>
      <path d="M90 118 C 86 122, 82 126, 78 130"/>
      <circle cx="22" cy="22" r="1.5" fill="currentColor" stroke="none"/>
      <circle cx="78" cy="22" r="1.5" fill="currentColor" stroke="none"/>
      <circle cx="22" cy="118" r="1.5" fill="currentColor" stroke="none"/>
      <circle cx="78" cy="118" r="1.5" fill="currentColor" stroke="none"/>
      {/* central star sigil */}
      <circle cx="50" cy="70" r="22"/>
      <circle cx="50" cy="70" r="16"/>
      <path d="M50 48 L 53 64 L 69 67 L 56 76 L 60 92 L 50 82 L 40 92 L 44 76 L 31 67 L 47 64 Z"/>
      <circle cx="50" cy="70" r="2.5" fill="currentColor" stroke="none"/>
      {/* top and bottom flourishes */}
      <path d="M50 16 L 50 24"/>
      <circle cx="50" cy="14" r="1" fill="currentColor" stroke="none"/>
      <path d="M44 20 C 47 18, 53 18, 56 20" />
      <path d="M50 124 L 50 116"/>
      <circle cx="50" cy="126" r="1" fill="currentColor" stroke="none"/>
      <path d="M44 120 C 47 122, 53 122, 56 120" />
      {/* side flourishes */}
      <path d="M14 70 L 22 70"/>
      <path d="M86 70 L 78 70"/>
      <circle cx="14" cy="70" r="1" fill="currentColor" stroke="none"/>
      <circle cx="86" cy="70" r="1" fill="currentColor" stroke="none"/>
    </svg>
  ),

  // Crown — ornate top decoration above name
  'crown-divider': () => (
    <svg viewBox="0 0 60 12" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" strokeWidth="0.8" strokeLinecap="round" strokeLinejoin="round">
      <line x1="4" y1="6" x2="24" y2="6"/>
      <line x1="36" y1="6" x2="56" y2="6"/>
      <path d="M24 6 L 27 2 L 30 6 L 33 2 L 36 6"/>
      <circle cx="30" cy="6" r="1.5" fill="currentColor" stroke="none"/>
      <circle cx="4" cy="6" r="0.8" fill="currentColor" stroke="none"/>
      <circle cx="56" cy="6" r="0.8" fill="currentColor" stroke="none"/>
    </svg>
  ),

  // Suit pip — small icon shown at top corners of minor arcana
  'pip-wands': () => (
    <svg viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
      <path d="M6 1 L 7 4 L 10 5 L 7 6 L 6 11 L 5 6 L 2 5 L 5 4 Z"/>
    </svg>
  ),
  'pip-cups': () => (
    <svg viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" strokeWidth="0.9" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 3 L 9 3 L 8 7 C 8 8.5, 7 9, 6 9 C 5 9, 4 8.5, 4 7 Z"/>
      <line x1="6" y1="9" x2="6" y2="11"/>
    </svg>
  ),
  'pip-swords': () => (
    <svg viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" strokeWidth="0.9" strokeLinecap="round" strokeLinejoin="round">
      <line x1="6" y1="1" x2="6" y2="9"/>
      <line x1="4" y1="8" x2="8" y2="8"/>
      <line x1="6" y1="9" x2="6" y2="11"/>
    </svg>
  ),
  'pip-pentacles': () => (
    <svg viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" strokeWidth="0.7" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="6" cy="6" r="4.5"/>
      <path d="M6 2 L 7 5 L 10 5 L 7.5 7 L 8.5 10 L 6 8 L 3.5 10 L 4.5 7 L 2 5 L 5 5 Z" fill="currentColor" stroke="none"/>
    </svg>
  ),
};

function Ornament({ name, ...props }) {
  const C = ORNAMENTS[name];
  return C ? <C {...props}/> : null;
}

window.Ornament = Ornament;
window.ORNAMENTS = ORNAMENTS;

function Sigil({ name, ...props }) {
  const C = SIGILS[name] || SIGILS['mark'];
  return <C {...props} />;
}

window.Sigil = Sigil;
window.SIGILS = SIGILS;
