// Slot symbols — flat, designed SVGs with gold outlines.
// All accept { size } and render a square symbol that fills its container.

const GoldDefs = ({ id }) => (
  <defs>
    <linearGradient id={`gold-${id}`} x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stopColor="#fff3a8"/>
      <stop offset="30%" stopColor="#f7c84a"/>
      <stop offset="60%" stopColor="#d18a17"/>
      <stop offset="100%" stopColor="#8a560c"/>
    </linearGradient>
    <linearGradient id={`gold-rim-${id}`} x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stopColor="#ffe78a"/>
      <stop offset="100%" stopColor="#a36b14"/>
    </linearGradient>
    <linearGradient id={`gold-shine-${id}`} x1="0" y1="0" x2="0" y2="1">
      <stop offset="0%" stopColor="rgba(255,255,255,0.85)" stopOpacity="0.9"/>
      <stop offset="40%" stopColor="rgba(255,255,255,0.1)" stopOpacity="0"/>
    </linearGradient>
  </defs>
);

// A tiny crown that sits on top of a letter / 7.
function Crown({ cx = 50, cy = 12, w = 28, idSuffix = '' }) {
  const id = `crown-${idSuffix}-${Math.random().toString(36).slice(2,7)}`;
  const h = w * 0.55;
  const x = cx - w / 2;
  const y = cy - h / 2;
  return (
    <g>
      <defs>
        <linearGradient id={id} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#fff4b0"/>
          <stop offset="55%" stopColor="#e9b53a"/>
          <stop offset="100%" stopColor="#8c5c0e"/>
        </linearGradient>
      </defs>
      <path
        d={`M ${x} ${y + h}
            L ${x} ${y + h * 0.4}
            L ${x + w * 0.18} ${y + h * 0.7}
            L ${x + w * 0.32} ${y + h * 0.15}
            L ${x + w * 0.5} ${y + h * 0.55}
            L ${x + w * 0.68} ${y + h * 0.15}
            L ${x + w * 0.82} ${y + h * 0.7}
            L ${x + w} ${y + h * 0.4}
            L ${x + w} ${y + h}
            Z`}
        fill={`url(#${id})`}
        stroke="#5a3a0a"
        strokeWidth="1.4"
        strokeLinejoin="round"
      />
      <rect x={x + 1.5} y={y + h - 4} width={w - 3} height="2.2" fill="#5a3a0a"/>
      <circle cx={x + w * 0.18} cy={y + h * 0.32} r="2.2" fill="#ff3b3b" stroke="#5a0a0a" strokeWidth="0.6"/>
      <circle cx={x + w * 0.5} cy={y + h * 0.1} r="2.2" fill="#3bb6ff" stroke="#0a3a5a" strokeWidth="0.6"/>
      <circle cx={x + w * 0.82} cy={y + h * 0.32} r="2.2" fill="#5dd66d" stroke="#0a5a1a" strokeWidth="0.6"/>
    </g>
  );
}

// Letter symbol: bold serif letter with gold rim and crown.
function LetterSymbol({ letter, fill, fillDark, idSuffix }) {
  const id = idSuffix || letter;
  return (
    <svg viewBox="0 0 100 100" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
      <defs>
        <linearGradient id={`letterFill-${id}`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor={fill}/>
          <stop offset="65%" stopColor={fill}/>
          <stop offset="100%" stopColor={fillDark}/>
        </linearGradient>
        <linearGradient id={`letterShine-${id}`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="rgba(255,255,255,0.7)"/>
          <stop offset="40%" stopColor="rgba(255,255,255,0)"/>
        </linearGradient>
      </defs>
      <Crown cx={50} cy={16} w={28} idSuffix={`L${id}`}/>
      <text
        x="50" y="84"
        textAnchor="middle"
        fontFamily="Cinzel, 'Times New Roman', serif"
        fontSize="76"
        fontWeight="900"
        fill="#5a3a0a"
        style={{ paintOrder: 'stroke' }}
        stroke="#5a3a0a"
        strokeWidth="6"
        strokeLinejoin="round"
      >{letter}</text>
      <text
        x="50" y="84"
        textAnchor="middle"
        fontFamily="Cinzel, 'Times New Roman', serif"
        fontSize="76"
        fontWeight="900"
        fill={`url(#letterFill-${id})`}
      >{letter}</text>
      <text
        x="50" y="84"
        textAnchor="middle"
        fontFamily="Cinzel, 'Times New Roman', serif"
        fontSize="76"
        fontWeight="900"
        fill={`url(#letterShine-${id})`}
        opacity="0.6"
      >{letter}</text>
    </svg>
  );
}

const A = () => <LetterSymbol letter="A" fill="#e21f2c" fillDark="#7a0a14" idSuffix="A"/>;
const K = () => <LetterSymbol letter="K" fill="#2cb04b" fillDark="#0d5022" idSuffix="K"/>;
const Q = () => <LetterSymbol letter="Q" fill="#9b3fd6" fillDark="#4a1370" idSuffix="Q"/>;
const J = () => <LetterSymbol letter="J" fill="#3aa6e8" fillDark="#0d4a78" idSuffix="J"/>;

// 7 symbol with gold flame on top.
function Seven({ color, dark, idSuffix }) {
  const id = idSuffix;
  return (
    <svg viewBox="0 0 100 100" width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
      <defs>
        <linearGradient id={`sevenFill-${id}`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor={color}/>
          <stop offset="80%" stopColor={color}/>
          <stop offset="100%" stopColor={dark}/>
        </linearGradient>
        <linearGradient id={`flameFill-${id}`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#fff7c0"/>
          <stop offset="50%" stopColor="#f0c040"/>
          <stop offset="100%" stopColor="#a06010"/>
        </linearGradient>
      </defs>
      {/* gold flame swoosh */}
      <path
        d="M 18 18 Q 30 6 60 12 Q 78 16 86 8 Q 80 22 70 26 Q 50 32 32 26 Q 24 24 18 18 Z"
        fill={`url(#flameFill-${id})`}
        stroke="#5a3a0a"
        strokeWidth="1.6"
        strokeLinejoin="round"
      />
      {/* 7 shape: outer stroke + fill */}
      <text x="50" y="88" textAnchor="middle"
        fontFamily="'Bowlby One', 'Arial Black', sans-serif"
        fontSize="86" fontWeight="900"
        fill="#5a3a0a"
        stroke="#5a3a0a" strokeWidth="7" strokeLinejoin="round"
        style={{ paintOrder: 'stroke' }}>7</text>
      <text x="50" y="88" textAnchor="middle"
        fontFamily="'Bowlby One', 'Arial Black', sans-serif"
        fontSize="86" fontWeight="900"
        fill={`url(#sevenFill-${id})`}>7</text>
      {/* tiny crown on bottom of 7 */}
      <g transform="translate(0, 70)">
        <Crown cx={50} cy={20} w={20} idSuffix={`s${id}`}/>
      </g>
    </svg>
  );
}

const Seven7Red = () => <Seven color="#ff2d3a" dark="#7a0a14" idSuffix="r"/>;
const Seven7Green = () => <Seven color="#2cd455" dark="#0d5022" idSuffix="g"/>;
const Seven7Blue = () => <Seven color="#3ab0ff" dark="#0a4a7a" idSuffix="b"/>;

function Cherry() {
  return (
    <svg viewBox="0 0 100 100" width="100%" height="100%">
      <defs>
        <radialGradient id="cherry-r" cx="0.35" cy="0.3" r="0.7">
          <stop offset="0%" stopColor="#ff8a8a"/>
          <stop offset="50%" stopColor="#e8232f"/>
          <stop offset="100%" stopColor="#7a0a14"/>
        </radialGradient>
      </defs>
      {/* stems */}
      <path d="M 38 60 Q 30 30 50 18 Q 70 30 64 60" fill="none" stroke="#7a4a16" strokeWidth="3.5" strokeLinecap="round"/>
      {/* leaf */}
      <path d="M 50 22 Q 70 12 78 26 Q 70 36 56 30 Q 50 28 50 22 Z" fill="#2cb04b" stroke="#0d5022" strokeWidth="1.6"/>
      <path d="M 56 26 Q 66 22 74 27" stroke="#0d5022" strokeWidth="1" fill="none"/>
      {/* berries */}
      <circle cx="36" cy="68" r="18" fill="url(#cherry-r)" stroke="#5a0a14" strokeWidth="2"/>
      <circle cx="66" cy="72" r="18" fill="url(#cherry-r)" stroke="#5a0a14" strokeWidth="2"/>
      <ellipse cx="30" cy="62" rx="6" ry="3" fill="#ffd1d1" opacity="0.7"/>
      <ellipse cx="60" cy="66" rx="6" ry="3" fill="#ffd1d1" opacity="0.7"/>
    </svg>
  );
}

function Lemon() {
  return (
    <svg viewBox="0 0 100 100" width="100%" height="100%">
      <defs>
        <radialGradient id="lemon-r" cx="0.4" cy="0.3" r="0.8">
          <stop offset="0%" stopColor="#fff8a8"/>
          <stop offset="60%" stopColor="#f5c726"/>
          <stop offset="100%" stopColor="#a06f10"/>
        </radialGradient>
        <radialGradient id="slice-r" cx="0.5" cy="0.5" r="0.5">
          <stop offset="0%" stopColor="#fff2a0"/>
          <stop offset="100%" stopColor="#f0aa28"/>
        </radialGradient>
      </defs>
      {/* whole lemon */}
      <ellipse cx="38" cy="58" rx="26" ry="22" fill="url(#lemon-r)" stroke="#7a4a0a" strokeWidth="2"/>
      {/* small leaf */}
      <path d="M 28 36 Q 18 26 30 22 Q 40 26 36 38 Z" fill="#2cb04b" stroke="#0d5022" strokeWidth="1.4"/>
      {/* slice */}
      <circle cx="68" cy="62" r="20" fill="url(#slice-r)" stroke="#7a4a0a" strokeWidth="2"/>
      <circle cx="68" cy="62" r="14" fill="#fff4b0" opacity="0.55"/>
      {[0, 60, 120, 180, 240, 300].map(a => {
        const r = (a * Math.PI) / 180;
        const x1 = 68 + Math.cos(r) * 4;
        const y1 = 62 + Math.sin(r) * 4;
        const x2 = 68 + Math.cos(r) * 14;
        const y2 = 62 + Math.sin(r) * 14;
        return <line key={a} x1={x1} y1={y1} x2={x2} y2={y2} stroke="#d89a18" strokeWidth="1.5" strokeLinecap="round"/>;
      })}
      <circle cx="68" cy="62" r="3" fill="#f5c726" stroke="#7a4a0a" strokeWidth="1"/>
    </svg>
  );
}

function Wild() {
  return (
    <svg viewBox="0 0 100 100" width="100%" height="100%">
      <defs>
        <linearGradient id="wild-fill" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#fff4a8"/>
          <stop offset="50%" stopColor="#f0c040"/>
          <stop offset="100%" stopColor="#8a560c"/>
        </linearGradient>
        <linearGradient id="wild-disc" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#3a3a4a"/>
          <stop offset="100%" stopColor="#0a0a14"/>
        </linearGradient>
      </defs>
      {/* dark backing disc */}
      <ellipse cx="50" cy="55" rx="46" ry="36" fill="url(#wild-disc)" stroke="#f0c040" strokeWidth="2.5"/>
      <ellipse cx="50" cy="55" rx="42" ry="32" fill="none" stroke="#8a560c" strokeWidth="1"/>
      <Crown cx={50} cy={22} w={26} idSuffix="wild"/>
      <text x="50" y="68"
        textAnchor="middle"
        fontFamily="'Bowlby One', 'Arial Black', sans-serif"
        fontSize="22" fontStyle="italic" fontWeight="900"
        fill="#5a3a0a"
        stroke="#5a3a0a" strokeWidth="3.5" strokeLinejoin="round"
        style={{ paintOrder: 'stroke' }}>WILD</text>
      <text x="50" y="68"
        textAnchor="middle"
        fontFamily="'Bowlby One', 'Arial Black', sans-serif"
        fontSize="22" fontStyle="italic" fontWeight="900"
        fill="url(#wild-fill)">WILD</text>
    </svg>
  );
}

function FreeSpinsScatter() {
  return (
    <svg viewBox="0 0 100 100" width="100%" height="100%">
      <defs>
        <linearGradient id="fs-fill" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#fff4a8"/>
          <stop offset="50%" stopColor="#f0c040"/>
          <stop offset="100%" stopColor="#8a560c"/>
        </linearGradient>
        <linearGradient id="fs-flag" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#ffe478"/>
          <stop offset="100%" stopColor="#c98a1a"/>
        </linearGradient>
      </defs>
      {/* swooping flag/banner */}
      <path
        d="M 10 28 Q 50 8 92 22 L 90 60 Q 50 78 12 62 Z"
        fill="url(#fs-flag)"
        stroke="#5a3a0a"
        strokeWidth="2"
        strokeLinejoin="round"
      />
      {/* free text */}
      <text x="50" y="42"
        textAnchor="middle"
        fontFamily="Cinzel, serif"
        fontSize="17" fontWeight="900" fontStyle="italic"
        fill="#5a3a0a"
        stroke="#5a3a0a" strokeWidth="2.5"
        style={{ paintOrder: 'stroke' }}>FREE</text>
      <text x="50" y="42"
        textAnchor="middle"
        fontFamily="Cinzel, serif"
        fontSize="17" fontWeight="900" fontStyle="italic"
        fill="url(#fs-fill)">FREE</text>
      <text x="50" y="62"
        textAnchor="middle"
        fontFamily="Cinzel, serif"
        fontSize="17" fontWeight="900" fontStyle="italic"
        fill="#5a3a0a"
        stroke="#5a3a0a" strokeWidth="2.5"
        style={{ paintOrder: 'stroke' }}>SPINS</text>
      <text x="50" y="62"
        textAnchor="middle"
        fontFamily="Cinzel, serif"
        fontSize="17" fontWeight="900" fontStyle="italic"
        fill="url(#fs-fill)">SPINS</text>
      {/* little gold 7 in corner */}
      <text x="20" y="22"
        textAnchor="middle"
        fontFamily="'Bowlby One', sans-serif"
        fontSize="20" fontWeight="900"
        fill="url(#fs-fill)"
        stroke="#5a3a0a" strokeWidth="1.5"
        style={{ paintOrder: 'stroke' }}>7</text>
    </svg>
  );
}

// Win Spins scatter — banner says "WIN / SPINS" in red/gold.
function WinSpinsScatter() {
  return (
    <svg viewBox="0 0 100 100" width="100%" height="100%">
      <defs>
        <linearGradient id="win-fill" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#ffd680"/>
          <stop offset="50%" stopColor="#f04030"/>
          <stop offset="100%" stopColor="#7a0a14"/>
        </linearGradient>
        <linearGradient id="win-flag" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#ff8a4a"/>
          <stop offset="100%" stopColor="#9a1f2c"/>
        </linearGradient>
      </defs>
      <path d="M 10 28 Q 50 8 92 22 L 90 60 Q 50 78 12 62 Z" fill="url(#win-flag)" stroke="#3a0610" strokeWidth="2" strokeLinejoin="round"/>
      <text x="50" y="42" textAnchor="middle" fontFamily="Cinzel, serif" fontSize="17" fontWeight="900" fontStyle="italic" fill="#3a0610" stroke="#3a0610" strokeWidth="2.5" style={{ paintOrder: 'stroke' }}>WIN</text>
      <text x="50" y="42" textAnchor="middle" fontFamily="Cinzel, serif" fontSize="17" fontWeight="900" fontStyle="italic" fill="url(#win-fill)">WIN</text>
      <text x="50" y="62" textAnchor="middle" fontFamily="Cinzel, serif" fontSize="17" fontWeight="900" fontStyle="italic" fill="#3a0610" stroke="#3a0610" strokeWidth="2.5" style={{ paintOrder: 'stroke' }}>SPINS</text>
      <text x="50" y="62" textAnchor="middle" fontFamily="Cinzel, serif" fontSize="17" fontWeight="900" fontStyle="italic" fill="url(#win-fill)">SPINS</text>
    </svg>
  );
}

// Wild Spins scatter — banner says "WILD / SPINS" in purple/silver.
function WildSpinsScatter() {
  return (
    <svg viewBox="0 0 100 100" width="100%" height="100%">
      <defs>
        <linearGradient id="ws-fill" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#e0d0ff"/>
          <stop offset="50%" stopColor="#9a4ad6"/>
          <stop offset="100%" stopColor="#3a0a6a"/>
        </linearGradient>
        <linearGradient id="ws-flag" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#b48aff"/>
          <stop offset="100%" stopColor="#4a1a8a"/>
        </linearGradient>
      </defs>
      <path d="M 10 28 Q 50 8 92 22 L 90 60 Q 50 78 12 62 Z" fill="url(#ws-flag)" stroke="#1a0640" strokeWidth="2" strokeLinejoin="round"/>
      <text x="50" y="42" textAnchor="middle" fontFamily="Cinzel, serif" fontSize="17" fontWeight="900" fontStyle="italic" fill="#1a0640" stroke="#1a0640" strokeWidth="2.5" style={{ paintOrder: 'stroke' }}>WILD</text>
      <text x="50" y="42" textAnchor="middle" fontFamily="Cinzel, serif" fontSize="17" fontWeight="900" fontStyle="italic" fill="url(#ws-fill)">WILD</text>
      <text x="50" y="62" textAnchor="middle" fontFamily="Cinzel, serif" fontSize="17" fontWeight="900" fontStyle="italic" fill="#1a0640" stroke="#1a0640" strokeWidth="2.5" style={{ paintOrder: 'stroke' }}>SPINS</text>
      <text x="50" y="62" textAnchor="middle" fontFamily="Cinzel, serif" fontSize="17" fontWeight="900" fontStyle="italic" fill="url(#ws-fill)">SPINS</text>
    </svg>
  );
}

// 777 Strike logo (top-left header art)
function LogoBadge() {
  return (
    <svg viewBox="0 0 200 120" width="100%" height="100%">
      <defs>
        <radialGradient id="logo-disc" cx="0.5" cy="0.4" r="0.6">
          <stop offset="0%" stopColor="#1a2a4a"/>
          <stop offset="100%" stopColor="#000010"/>
        </radialGradient>
        <linearGradient id="logo-gold" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#fff3a8"/>
          <stop offset="40%" stopColor="#f0c040"/>
          <stop offset="80%" stopColor="#a06010"/>
          <stop offset="100%" stopColor="#5a3a0a"/>
        </linearGradient>
      </defs>
      <ellipse cx="100" cy="60" rx="95" ry="55" fill="url(#logo-disc)" stroke="url(#logo-gold)" strokeWidth="4"/>
      <ellipse cx="100" cy="60" rx="88" ry="48" fill="none" stroke="#8a560c" strokeWidth="1"/>
      <text x="100" y="55"
        textAnchor="middle"
        fontFamily="'Bowlby One', sans-serif"
        fontSize="42" fontWeight="900" fontStyle="italic"
        fill="#5a3a0a"
        stroke="#5a3a0a" strokeWidth="3"
        style={{ paintOrder: 'stroke' }}>777</text>
      <text x="100" y="55"
        textAnchor="middle"
        fontFamily="'Bowlby One', sans-serif"
        fontSize="42" fontWeight="900" fontStyle="italic"
        fill="url(#logo-gold)">777</text>
      <text x="100" y="92"
        textAnchor="middle"
        fontFamily="Cinzel, serif"
        fontSize="26" fontWeight="900" fontStyle="italic"
        fill="#5a3a0a"
        stroke="#5a3a0a" strokeWidth="2.5"
        style={{ paintOrder: 'stroke' }}>Strike</text>
      <text x="100" y="92"
        textAnchor="middle"
        fontFamily="Cinzel, serif"
        fontSize="26" fontWeight="900" fontStyle="italic"
        fill="url(#logo-gold)">Strike</text>
    </svg>
  );
}

// Symbol registry: id -> { id, render, payouts (5/4/3), kind }
const SYMBOLS = {
  WILD:  { id: 'WILD',  render: Wild,            kind: 'wild',     payouts: [77, 0, 0] },
  S7R:   { id: 'S7R',   render: Seven7Red,       kind: 'high',     payouts: [77, 21, 10] },
  S7G:   { id: 'S7G',   render: Seven7Green,     kind: 'high',     payouts: [47, 15, 7] },
  S7B:   { id: 'S7B',   render: Seven7Blue,      kind: 'high',     payouts: [35, 11, 5] },
  LEMON: { id: 'LEMON', render: Lemon,           kind: 'high',     payouts: [23, 7, 3] },
  CHRY:  { id: 'CHRY',  render: Cherry,          kind: 'med',      payouts: [9.2, 4.6, 2.3] },
  A:     { id: 'A',     render: A,               kind: 'med',      payouts: [5.2, 2.6, 1.3] },
  K:     { id: 'K',     render: K,               kind: 'low',      payouts: [3.6, 1.8, 0.9] },
  Q:     { id: 'Q',     render: Q,               kind: 'low',      payouts: [2.8, 1.4, 0.7] },
  J:     { id: 'J',     render: J,               kind: 'low',      payouts: [2.4, 1.2, 0.6] },
  FS:    { id: 'FS',    render: FreeSpinsScatter,kind: 'scatter',  payouts: [0, 0, 0] },
  WIN:   { id: 'WIN',   render: WinSpinsScatter, kind: 'scatter',  payouts: [0, 0, 0] },
  WS:    { id: 'WS',    render: WildSpinsScatter,kind: 'scatter',  payouts: [0, 0, 0] },
};

Object.assign(window, {
  SYMBOLS, LogoBadge,
  A, K, Q, J, Seven7Red, Seven7Green, Seven7Blue, Cherry, Lemon, Wild,
  FreeSpinsScatter, WinSpinsScatter, WildSpinsScatter, Crown,
});
