/* ============================================================
 * SECTION: LOYALTY  (lives inside the CRM Engine)
 * Tier engine · No-code builder · Member portal
 * ============================================================ */

const loyaltySlides = [
  {
    k: "tiers",
    channel: "Tier Engine",
    channelColor: "var(--accent)",
    headline: "Tiers sophisticated enough for any group.",
    body: "Unlimited tiers, custom names and colors, multi-criteria qualification rules, points, nights, spend, stays, combined in AND/OR groups. Tier-based earn multipliers. Daily automatic re-evaluation. The same logic the largest hotel groups use, configured visually.",
    illustration: "tiers",
    chips: [
      { k: "Unlimited tiers",    d: "Bronze → Silver → Gold → Platinum → Black, or anything you need." },
      { k: "Multi-criteria rules", d: "(nights ≥ 10 AND spend ≥ €5,000) OR (points ≥ 25,000)." },
      { k: "Auto promote/demote", d: "Daily 3 AM re-evaluation. Immutable history." },
      { k: "Tier multipliers",    d: "1.5× Gold, 2× Platinum, applied on every accrual." },
    ],
  },
  {
    k: "builder",
    channel: "No-Code Builder",
    channelColor: "var(--accent)",
    headline: "Launch a loyalty program in an afternoon.",
    body: "A nine-step builder: basics, earning rules, tiers, benefits, rewards, communications, brand, landing page, launch. Or skip it, answer five questions and the AI quick-start drafts the entire program in seconds, brand-matched to your existing site.",
    illustration: "builder",
    chips: [
      { k: "9-step wizard",      d: "Basics → Earning → Tiers → Benefits → Rewards → Comms → Brand → Page → Launch." },
      { k: "AI quick-start",     d: "5 questions, full program draft. Refine from there." },
      { k: "Website scanner",    d: "Pulls colors, fonts, and tone from your existing site." },
      { k: "Per-hotel branding", d: "Each property can override colors and logo." },
    ],
  },
  {
    k: "portal",
    channel: "Member Portal",
    channelColor: "var(--accent)",
    headline: "A guest portal that looks like the brand.",
    body: "Magic-link auth, points and tier progress, transaction history, rewards catalog, digital membership card with QR. Localized in 23+ languages, brand-themed per hotel, kiosk mode for tablets at the property. Built so the guest never has to download anything.",
    illustration: "portal",
    chips: [
      { k: "23+ languages",       d: "Auto-localized, copy, dates, currencies." },
      { k: "Digital membership card", d: "QR code, Apple/Google Wallet ready." },
      { k: "Kiosk mode",          d: "Tablet experience for in-property enrollment." },
      { k: "Magic-link auth",     d: "No passwords. No friction." },
    ],
  },
];

/* === Custom illustrations, hand-built SVG, not screenshots === */
const LoyaltyIllustration = ({ kind }) => {
  if (kind === "tiers") return (
    <svg viewBox="0 0 800 460" preserveAspectRatio="xMidYMid meet" className="li-svg">
      <defs>
        <linearGradient id="li-tiers-bg" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%"  stopColor="var(--bg-elev-1)"/>
          <stop offset="100%" stopColor="var(--bg)"/>
        </linearGradient>
        <linearGradient id="li-bar-platinum" x1="0" y1="0" x2="1" y2="0">
          <stop offset="0%"  stopColor="var(--accent)" stopOpacity="0.3"/>
          <stop offset="100%" stopColor="var(--accent)"/>
        </linearGradient>
      </defs>

      {/* Background */}
      <rect width="800" height="460" fill="url(#li-tiers-bg)"/>

      {/* === LEFT: Rule builder === */}
      <g transform="translate(40, 40)">
        <text x="0" y="0" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink-3)" letterSpacing="1.2">QUALIFICATION RULE · GOLD TIER</text>

        {/* AND group */}
        <g transform="translate(0, 24)">
          <rect width="320" height="100" rx="8" fill="var(--bg)" stroke="var(--hairline-strong)" strokeWidth="1"/>
          <rect x="0" y="0" width="48" height="20" rx="4" fill="var(--accent)"/>
          <text x="24" y="14" fontFamily="var(--f-mono)" fontSize="10" fontWeight="700" fill="var(--accent-ink)" textAnchor="middle">AND</text>

          {/* Condition rows */}
          <g transform="translate(16, 32)">
            <rect width="288" height="24" rx="4" fill="var(--bg-elev-2)" stroke="var(--hairline)"/>
            <text x="12" y="16" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink-2)">nights</text>
            <rect x="68" y="6" width="22" height="12" rx="2" fill="var(--accent)" opacity="0.18"/>
            <text x="79" y="15" fontFamily="var(--f-mono)" fontSize="10" fill="var(--accent)" textAnchor="middle" fontWeight="600">≥</text>
            <text x="100" y="16" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink)" fontWeight="600">10</text>
          </g>
          <g transform="translate(16, 64)">
            <rect width="288" height="24" rx="4" fill="var(--bg-elev-2)" stroke="var(--hairline)"/>
            <text x="12" y="16" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink-2)">spend</text>
            <rect x="68" y="6" width="22" height="12" rx="2" fill="var(--accent)" opacity="0.18"/>
            <text x="79" y="15" fontFamily="var(--f-mono)" fontSize="10" fill="var(--accent)" textAnchor="middle" fontWeight="600">≥</text>
            <text x="100" y="16" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink)" fontWeight="600">€5,000</text>
          </g>
        </g>

        {/* OR connector */}
        <g transform="translate(140, 138)">
          <line x1="20" y1="0" x2="20" y2="14" stroke="var(--ink-3)" strokeWidth="1" strokeDasharray="2 2"/>
          <rect x="0" y="14" width="40" height="18" rx="4" fill="var(--ink-3)"/>
          <text x="20" y="27" fontFamily="var(--f-mono)" fontSize="10" fontWeight="700" fill="var(--bg)" textAnchor="middle">OR</text>
          <line x1="20" y1="32" x2="20" y2="46" stroke="var(--ink-3)" strokeWidth="1" strokeDasharray="2 2"/>
        </g>

        {/* Single-condition group */}
        <g transform="translate(0, 200)">
          <rect width="320" height="60" rx="8" fill="var(--bg)" stroke="var(--hairline-strong)" strokeWidth="1"/>
          <g transform="translate(16, 18)">
            <rect width="288" height="24" rx="4" fill="var(--bg-elev-2)" stroke="var(--hairline)"/>
            <text x="12" y="16" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink-2)">points</text>
            <rect x="68" y="6" width="22" height="12" rx="2" fill="var(--accent)" opacity="0.18"/>
            <text x="79" y="15" fontFamily="var(--f-mono)" fontSize="10" fill="var(--accent)" textAnchor="middle" fontWeight="600">≥</text>
            <text x="100" y="16" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink)" fontWeight="600">25,000</text>
          </g>
        </g>

        {/* Result arrow */}
        <g transform="translate(0, 290)">
          <line x1="160" y1="0" x2="160" y2="20" stroke="var(--accent)" strokeWidth="1.5"/>
          <polygon points="156,18 164,18 160,26" fill="var(--accent)"/>
          <text x="160" y="44" fontFamily="var(--f-mono)" fontSize="10" fill="var(--accent)" textAnchor="middle" letterSpacing="1.2">→ QUALIFIES FOR GOLD</text>
        </g>
      </g>

      {/* === RIGHT: Tier ladder === */}
      <g transform="translate(420, 50)">
        <text x="0" y="0" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink-3)" letterSpacing="1.2">TIER LADDER · GUEST PROGRESSION</text>

        {[
          { y: 24,  w: 70,  label: "BRONZE",   mult: "1.0×", on: false },
          { y: 64,  w: 130, label: "SILVER",   mult: "1.2×", on: false },
          { y: 104, w: 200, label: "GOLD",     mult: "1.5×", on: true  },
          { y: 144, w: 270, label: "PLATINUM", mult: "2.0×", on: false },
          { y: 184, w: 340, label: "BLACK",    mult: "3.0×", on: false },
        ].map((t, i) => (
          <g key={i}>
            {/* Track */}
            <rect x="0" y={t.y} width="340" height="22" rx="4" fill="var(--bg-elev-2)" stroke="var(--hairline)"/>
            {/* Fill */}
            <rect x="0" y={t.y} width={t.w} height="22" rx="4"
                  fill={t.on ? "url(#li-bar-platinum)" : "var(--ink-4)"}
                  opacity={t.on ? 1 : 0.35}/>
            {/* Label */}
            <text x="12" y={t.y + 14.5} fontFamily="var(--f-mono)" fontSize="10" fontWeight="700"
                  fill={t.on ? "var(--accent-ink)" : "var(--ink-2)"} letterSpacing="1.4">{t.label}</text>
            {/* Multiplier */}
            <text x="356" y={t.y + 14.5} fontFamily="var(--f-mono)" fontSize="10" fill={t.on ? "var(--accent)" : "var(--ink-3)"} fontWeight={t.on ? 700 : 400}>{t.mult}</text>
            {/* Active indicator */}
            {t.on && (
              <g transform={`translate(${t.w + 6}, ${t.y + 11})`}>
                <circle r="3" fill="var(--accent)">
                  <animate attributeName="r" values="3;5;3" dur="2.4s" repeatCount="indefinite"/>
                  <animate attributeName="opacity" values="1;0;1" dur="2.4s" repeatCount="indefinite"/>
                </circle>
                <circle r="3" fill="var(--accent)"/>
              </g>
            )}
          </g>
        ))}

        {/* Benefits column */}
        <g transform="translate(0, 240)">
          <text x="0" y="0" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink-3)" letterSpacing="1.2">12 BENEFIT CATEGORIES · GOLD</text>
          <g transform="translate(0, 16)">
            {[
              "Lounge access", "Room upgrades", "Priority services",
              "Exclusive dining", "Room perks", "Travel perks",
              "Recognition", "Special events", "Communications",
            ].map((b, i) => {
              const col = i % 3;
              const row = Math.floor(i / 3);
              return (
                <g key={i} transform={`translate(${col * 130}, ${row * 28})`}>
                  <circle cx="6" cy="9" r="2.5" fill="var(--accent)"/>
                  <text x="14" y="12" fontFamily="var(--f-body)" fontSize="11" fill="var(--ink-2)">{b}</text>
                </g>
              );
            })}
          </g>
        </g>
      </g>
    </svg>
  );

  if (kind === "builder") return (
    <svg viewBox="0 0 800 460" preserveAspectRatio="xMidYMid meet" className="li-svg">
      <defs>
        <linearGradient id="li-builder-bg" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%"  stopColor="var(--bg-elev-1)"/>
          <stop offset="100%" stopColor="var(--bg)"/>
        </linearGradient>
      </defs>
      <rect width="800" height="460" fill="url(#li-builder-bg)"/>

      {/* AI quick-start card */}
      <g transform="translate(40, 40)">
        <rect width="300" height="200" rx="12" fill="var(--bg)" stroke="var(--accent)" strokeWidth="1.4"/>
        <text x="20" y="32" fontFamily="var(--f-mono)" fontSize="10" fill="var(--accent)" letterSpacing="1.4">⚡ AI QUICK-START</text>
        <text x="20" y="62" fontFamily="var(--f-display)" fontSize="22" fill="var(--ink)" fontWeight="600">5 questions.</text>
        <text x="20" y="86" fontFamily="var(--f-display)" fontSize="22" fill="var(--accent)" fontStyle="italic">A full program.</text>

        {/* Question chips */}
        {[
          "What kind of property?",
          "What does \"loyal\" look like?",
          "Free perks or paid points?",
          "Multi-property or single?",
          "Brand colors and tone?",
        ].map((q, i) => (
          <g key={i} transform={`translate(20, ${108 + i * 17})`}>
            <circle cx="6" cy="6" r="6" fill={i === 4 ? "var(--accent)" : "var(--bg-elev-2)"} stroke={i === 4 ? "var(--accent)" : "var(--hairline-strong)"}/>
            <text x="6" y="9" fontFamily="var(--f-mono)" fontSize="8" textAnchor="middle" fontWeight="700"
                  fill={i === 4 ? "var(--accent-ink)" : "var(--ink-3)"}>{i + 1}</text>
            <text x="20" y="9" fontFamily="var(--f-body)" fontSize="11" fill="var(--ink-2)">{q}</text>
          </g>
        ))}
      </g>

      {/* Connector */}
      <g transform="translate(340, 130)">
        <line x1="0" y1="10" x2="40" y2="10" stroke="var(--accent)" strokeWidth="1.4" strokeDasharray="3 3"/>
        <polygon points="40,5 50,10 40,15" fill="var(--accent)"/>
      </g>

      {/* 9-step builder path */}
      <g transform="translate(400, 40)">
        <text x="0" y="0" fontFamily="var(--f-mono)" fontSize="10" fill="var(--ink-3)" letterSpacing="1.4">9-STEP BUILDER</text>

        {[
          "Basics", "Earning", "Tiers",
          "Benefits", "Rewards", "Comms",
          "Brand", "Page", "Launch",
        ].map((step, i) => {
          const col = i % 3;
          const row = Math.floor(i / 3);
          const x = col * 116;
          const y = 24 + row * 70;
          const isLast = i === 8;
          return (
            <g key={i} transform={`translate(${x}, ${y})`}>
              <rect width="100" height="56" rx="8" fill={isLast ? "var(--accent)" : "var(--bg)"}
                    stroke={isLast ? "var(--accent)" : "var(--hairline-strong)"}/>
              <text x="12" y="20" fontFamily="var(--f-mono)" fontSize="9" letterSpacing="1.2"
                    fill={isLast ? "var(--accent-ink)" : "var(--ink-3)"} opacity={isLast ? 0.7 : 1}>{`STEP ${i + 1}`}</text>
              <text x="12" y="40" fontFamily="var(--f-display)" fontSize="14" fontWeight="600"
                    fill={isLast ? "var(--accent-ink)" : "var(--ink)"}>{step}</text>
              {isLast && (
                <g transform="translate(82, 40)">
                  <path d="M 0 0 L 4 4 L 10 -4" fill="none" stroke="var(--accent-ink)" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
                </g>
              )}
            </g>
          );
        })}
      </g>

      {/* Bottom: scanner / brand-aware */}
      <g transform="translate(40, 264)">
        <rect width="720" height="156" rx="12" fill="var(--bg)" stroke="var(--hairline)"/>
        <text x="20" y="30" fontFamily="var(--f-mono)" fontSize="10" fill="var(--ink-3)" letterSpacing="1.4">WEBSITE SCANNER · BRAND-AWARE OUTPUT</text>

        {/* Input URL */}
        <g transform="translate(20, 46)">
          <rect width="200" height="26" rx="4" fill="var(--bg-elev-2)" stroke="var(--hairline)"/>
          <text x="10" y="17" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink-2)">sunsetbeachresort.com</text>
        </g>

        {/* Arrow */}
        <g transform="translate(232, 56)">
          <line x1="0" y1="0" x2="40" y2="0" stroke="var(--accent)" strokeWidth="1.4" strokeDasharray="3 3"/>
          <polygon points="40,-5 50,0 40,5" fill="var(--accent)"/>
        </g>

        {/* Extracted swatches */}
        <g transform="translate(296, 42)">
          <text x="0" y="6" fontFamily="var(--f-mono)" fontSize="9" fill="var(--ink-4)" letterSpacing="1.4">COLORS</text>
          {[
            { c: "#1a3a52", x: 0  },
            { c: "#d4a574", x: 22 },
            { c: "#f5e6d3", x: 44 },
            { c: "#0a1f2e", x: 66 },
          ].map((s, i) => (
            <rect key={i} x={s.x} y="14" width="18" height="18" rx="3" fill={s.c} stroke="var(--hairline)"/>
          ))}
        </g>

        <g transform="translate(420, 42)">
          <text x="0" y="6" fontFamily="var(--f-mono)" fontSize="9" fill="var(--ink-4)" letterSpacing="1.4">FONTS</text>
          <text x="0" y="26" fontFamily="serif" fontSize="14" fill="var(--ink)" fontWeight="600">Playfair</text>
          <text x="0" y="42" fontFamily="sans-serif" fontSize="10" fill="var(--ink-2)">Inter</text>
        </g>

        <g transform="translate(520, 42)">
          <text x="0" y="6" fontFamily="var(--f-mono)" fontSize="9" fill="var(--ink-4)" letterSpacing="1.4">TONE</text>
          <text x="0" y="22" fontFamily="var(--f-body)" fontSize="11" fill="var(--ink)" fontStyle="italic">"Coastal · Refined"</text>
          <text x="0" y="38" fontFamily="var(--f-body)" fontSize="11" fill="var(--ink-2)" fontStyle="italic">"Effortless luxury"</text>
        </g>

        {/* Output mock */}
        <g transform="translate(20, 96)">
          <rect width="680" height="44" rx="8" fill="var(--bg-elev-2)" stroke="var(--hairline)"/>
          <rect x="0" y="0" width="3" height="44" fill="var(--accent)"/>
          <text x="20" y="18" fontFamily="var(--f-mono)" fontSize="9" fill="var(--accent)" letterSpacing="1.4">→ DRAFT PROGRAM GENERATED</text>
          <text x="20" y="34" fontFamily="var(--f-body)" fontSize="11" fill="var(--ink-2)">Sunset Society · 4 tiers · 6 benefits per tier · 12 rewards · brand-matched landing page · 23 languages</text>
        </g>
      </g>
    </svg>
  );

  if (kind === "portal") return (
    <svg viewBox="0 0 800 460" preserveAspectRatio="xMidYMid meet" className="li-svg">
      <defs>
        <linearGradient id="li-portal-bg" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%"  stopColor="var(--bg-elev-1)"/>
          <stop offset="100%" stopColor="var(--bg)"/>
        </linearGradient>
        <linearGradient id="li-card" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0%"  stopColor="#1a1a1a"/>
          <stop offset="100%" stopColor="#3a2820"/>
        </linearGradient>
        <linearGradient id="li-card-shimmer" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0%"  stopColor="var(--accent)" stopOpacity="0.0"/>
          <stop offset="50%" stopColor="var(--accent)" stopOpacity="0.4"/>
          <stop offset="100%" stopColor="var(--accent)" stopOpacity="0.0"/>
        </linearGradient>
      </defs>
      <rect width="800" height="460" fill="url(#li-portal-bg)"/>

      {/* === Phone === */}
      <g transform="translate(70, 30)">
        <rect width="220" height="400" rx="32" fill="#0a0a0a" stroke="#1f1f1f" strokeWidth="2"/>
        <rect x="6" y="6" width="208" height="388" rx="26" fill="var(--bg)"/>

        {/* Notch */}
        <rect x="92" y="14" width="36" height="6" rx="3" fill="#000"/>

        {/* Status bar */}
        <text x="20" y="30" fontFamily="var(--f-mono)" fontSize="9" fill="var(--ink-2)" fontWeight="600">9:41</text>
        <g transform="translate(180, 24)">
          <rect width="3" height="6" fill="var(--ink-2)"/>
          <rect x="5" width="3" height="6" fill="var(--ink-2)"/>
          <rect x="10" width="3" height="6" fill="var(--ink-2)"/>
          <rect x="15" width="3" height="6" fill="var(--ink-2)" opacity="0.4"/>
        </g>

        {/* Brand bar */}
        <text x="20" y="60" fontFamily="serif" fontSize="14" fontWeight="700" fill="var(--ink)">Sunset Society</text>
        <text x="200" y="60" fontFamily="var(--f-mono)" fontSize="9" fill="var(--ink-3)" textAnchor="end">EN</text>

        {/* Membership card */}
        <g transform="translate(20, 76)">
          <rect width="180" height="100" rx="10" fill="url(#li-card)"/>
          <rect width="180" height="100" rx="10" fill="url(#li-card-shimmer)"/>
          <text x="14" y="22" fontFamily="var(--f-mono)" fontSize="8" fill="rgba(255,255,255,0.5)" letterSpacing="1.4">SUNSET SOCIETY</text>
          <text x="14" y="46" fontFamily="serif" fontSize="14" fill="white" fontWeight="600">David Richter</text>
          <text x="14" y="62" fontFamily="var(--f-mono)" fontSize="8" fill="rgba(255,255,255,0.6)">MEMBER · GOLD</text>

          {/* QR */}
          <g transform="translate(132, 54)">
            <rect width="38" height="38" rx="3" fill="white"/>
            {/* Pseudo QR */}
            {Array.from({ length: 36 }).map((_, i) => {
              const r = Math.floor(i / 6);
              const c = i % 6;
              const fill = (i * 7 + r * 3 + c) % 3 !== 0;
              return fill ? <rect key={i} x={4 + c * 5} y={4 + r * 5} width="4" height="4" fill="#000"/> : null;
            })}
          </g>

          <text x="14" y="88" fontFamily="var(--f-mono)" fontSize="8" fill="rgba(255,255,255,0.5)" letterSpacing="1.4">8,420 PTS · 1,580 TO PLATINUM</text>
        </g>

        {/* Tier progress */}
        <g transform="translate(20, 192)">
          <text x="0" y="0" fontFamily="var(--f-mono)" fontSize="8" fill="var(--ink-3)" letterSpacing="1.4">TIER PROGRESS</text>
          <rect x="0" y="8" width="180" height="6" rx="3" fill="var(--bg-elev-2)"/>
          <rect x="0" y="8" width="142" height="6" rx="3" fill="var(--accent)"/>
          <text x="0" y="28" fontFamily="var(--f-body)" fontSize="9" fill="var(--ink-2)">Gold</text>
          <text x="180" y="28" fontFamily="var(--f-body)" fontSize="9" fill="var(--ink-3)" textAnchor="end">Platinum</text>
        </g>

        {/* Recent activity */}
        <g transform="translate(20, 232)">
          <text x="0" y="0" fontFamily="var(--f-mono)" fontSize="8" fill="var(--ink-3)" letterSpacing="1.4">RECENT</text>
          {[
            { t: "Stay · Sunset Beach", p: "+1,200" },
            { t: "Spa credit redeemed",  p: "−800"  },
            { t: "Birthday bonus",       p: "+500"  },
          ].map((row, i) => (
            <g key={i} transform={`translate(0, ${10 + i * 22})`}>
              <rect width="180" height="20" rx="4" fill="var(--bg-elev-2)"/>
              <text x="8" y="14" fontFamily="var(--f-body)" fontSize="9" fill="var(--ink-2)">{row.t}</text>
              <text x="172" y="14" fontFamily="var(--f-mono)" fontSize="9" fill={row.p.startsWith("+") ? "var(--c-whatsapp)" : "var(--ink-3)"} textAnchor="end" fontWeight="600">{row.p}</text>
            </g>
          ))}
        </g>

        {/* Bottom CTA */}
        <g transform="translate(20, 354)">
          <rect width="180" height="28" rx="6" fill="var(--accent)"/>
          <text x="90" y="18" fontFamily="var(--f-mono)" fontSize="9" fontWeight="700" fill="var(--accent-ink)" textAnchor="middle" letterSpacing="1.2">REDEEM REWARDS</text>
        </g>
      </g>

      {/* === Right side: language strip + features === */}
      <g transform="translate(340, 50)">
        <text x="0" y="0" fontFamily="var(--f-mono)" fontSize="11" fill="var(--ink-3)" letterSpacing="1.4">LOCALIZED · 23+ LANGUAGES</text>

        {/* Language tiles */}
        <g transform="translate(0, 18)">
          {[
            "EN", "ES", "DE", "FR", "IT", "PT",
            "NL", "PL", "RU", "TR", "AR", "ZH",
            "JA", "KO", "TH", "VI", "EL", "HE",
          ].map((lang, i) => {
            const col = i % 6;
            const row = Math.floor(i / 6);
            const active = i === 0;
            return (
              <g key={i} transform={`translate(${col * 64}, ${row * 36})`}>
                <rect width="56" height="28" rx="6" fill={active ? "var(--accent)" : "var(--bg)"} stroke={active ? "var(--accent)" : "var(--hairline-strong)"}/>
                <text x="28" y="18" fontFamily="var(--f-mono)" fontSize="11" fontWeight="700" textAnchor="middle"
                      fill={active ? "var(--accent-ink)" : "var(--ink-2)"}>{lang}</text>
              </g>
            );
          })}
        </g>

        {/* Feature pills */}
        <g transform="translate(0, 156)">
          {[
            { label: "Magic-link auth",     d: "No password. Tap a link." },
            { label: "Apple / Google Wallet",d: "Add the card to wallet." },
            { label: "Per-hotel branding",  d: "Each property, its own skin." },
            { label: "Kiosk mode",          d: "Tablet enrollment in-property." },
          ].map((f, i) => (
            <g key={i} transform={`translate(0, ${i * 56})`}>
              <rect width="380" height="44" rx="8" fill="var(--bg)" stroke="var(--hairline-strong)"/>
              <rect width="3" height="44" fill="var(--accent)"/>
              <text x="20" y="20" fontFamily="var(--f-mono)" fontSize="10" fill="var(--ink)" fontWeight="700" letterSpacing="0.6">{f.label}</text>
              <text x="20" y="34" fontFamily="var(--f-body)" fontSize="11" fill="var(--ink-3)">{f.d}</text>
            </g>
          ))}
        </g>
      </g>
    </svg>
  );

  return null;
};

/* === Loyalty section component === */
const SectionLoyalty = () => {
  const [idx, setIdx] = React.useState(0);
  const trackRef = React.useRef(null);

  React.useEffect(() => {
    const track = trackRef.current;
    if (!track) return;
    let raf;
    const onScroll = () => {
      cancelAnimationFrame(raf);
      raf = requestAnimationFrame(() => {
        const w = track.clientWidth;
        if (!w) return;
        const next = Math.round(track.scrollLeft / w);
        if (next !== idx) setIdx(next);
      });
    };
    track.addEventListener("scroll", onScroll, { passive: true });
    return () => { track.removeEventListener("scroll", onScroll); cancelAnimationFrame(raf); };
  }, [idx]);

  const goTo = (i) => {
    const track = trackRef.current;
    if (!track) return;
    track.scrollTo({ left: i * track.clientWidth, behavior: "smooth" });
    setIdx(i);
  };

  // Engineered-for grid items
  const grid = [
    { k: "API-first",        d: "REST API + JS SDK. Plug into Mews, Cloudbeds, Roiback, Mirai, Hotetec, WitBooking, or your own." },
    { k: "Multi-tenant",     d: "One program per group, inherited by every property. Per-hotel brand override." },
    { k: "AI-powered ops",   d: "6 agents, research, refinement, landing pages, weekly insights, churn risk, design." },
    { k: "Automated crons",  d: "Tier recalc daily · point expiry · birthday bonuses · weekly insights." },
    { k: "Audit trail",      d: "Every config change logged, every transaction immutable. Compliance-grade." },
    { k: "Transactional emails", d: "Welcome · tier upgrade · expiry warning · birthday · points notification." },
  ];

  return (
    <Reveal>
      <div className="engine-feature loyalty-feature">
        <div className="ef-head">
          <div className="eyebrow" style={{ justifyContent: "flex-start" }}>Loyalty</div>
          <h3 className="h-2" style={{ marginTop: 16, fontSize: "clamp(28px, 3vw, 40px)" }}>
            A loyalty program your group <span className="italic-accent">can actually launch.</span>
          </h3>
          <p className="body" style={{ marginTop: 16, maxWidth: 720, color: "var(--ink-2)" }}>
            Most hotel loyalty programs die in committee. Ours ships in an afternoon, sophisticated tier rules, a beautiful guest portal, an API that plugs into any PMS, and an AI builder that drafts the entire program from your existing brand.
          </p>
        </div>

        {/* === Carousel with custom illustrations === */}
        <div className="cc">
          <div className="cc-track" ref={trackRef}>
            {loyaltySlides.map((s, i) => (
              <div className="cc-slide" key={s.k} aria-hidden={i !== idx}>
                <div className="cc-channel-row">
                  <span className="cc-channel-dot" style={{ background: s.channelColor }} />
                  <span className="cc-channel-label" style={{ color: s.channelColor }}>{s.channel}</span>
                </div>
                <h4 className="cc-headline">{s.headline}</h4>
                <p className="cc-body">{s.body}</p>

                <div className="loyalty-illust-frame">
                  <LoyaltyIllustration kind={s.illustration} />
                </div>

                <div className="ej-chips">
                  {s.chips.map((c, j) => (
                    <div key={j} className="ej-chip" style={{ borderLeftColor: s.channelColor }}>
                      <div className="ej-chip-k">{c.k}</div>
                      <div className="ej-chip-d">{c.d}</div>
                    </div>
                  ))}
                </div>
              </div>
            ))}
          </div>

          <div className="cc-pager" role="tablist" aria-label="Loyalty">
            {loyaltySlides.map((s, i) => (
              <button
                key={s.k}
                type="button"
                role="tab"
                aria-selected={i === idx}
                aria-label={s.channel}
                className={`cc-dot ${i === idx ? "is-active" : ""}`}
                onClick={() => goTo(i)}
              >
                <span className="cc-dot-label">{s.channel}</span>
              </button>
            ))}
          </div>
        </div>

        {/* === Engineered-for-hotel-groups grid === */}
        <div className="loyalty-grid">
          <div className="lg-label">Engineered for hotel groups</div>
          <div className="lg-rows">
            {grid.map((row, i) => (
              <div key={i} className="lg-row">
                <span className="lg-num">0{i + 1}</span>
                <span className="lg-k">{row.k}</span>
                <span className="lg-d">{row.d}</span>
              </div>
            ))}
          </div>
        </div>
      </div>

      <style>{`
        .loyalty-feature .loyalty-illust-frame {
          margin-top: 24px;
          border-radius: 16px;
          overflow: hidden;
          background: var(--bg-elev-1);
          border: 1px solid var(--hairline);
          box-shadow:
            0 60px 120px -40px rgba(0,0,0,.6),
            0 0 0 1px var(--hairline);
        }
        .loyalty-feature .li-svg {
          width: 100%; height: auto; display: block;
        }

        .loyalty-grid {
          margin-top: 64px;
          padding: 28px;
          background: var(--bg-elev-1);
          border: 1px solid var(--hairline);
          border-radius: 16px;
        }
        .lg-label {
          font-family: var(--f-mono);
          font-size: 11px;
          letter-spacing: 0.12em;
          text-transform: uppercase;
          color: var(--ink-3);
          margin-bottom: 18px;
        }
        .lg-rows {
          display: grid;
          grid-template-columns: 1fr 1fr;
          gap: 12px;
        }
        @media (max-width: 720px) { .lg-rows { grid-template-columns: 1fr; } }
        .lg-row {
          display: grid;
          grid-template-columns: 28px 150px 1fr;
          align-items: center;
          gap: 14px;
          padding: 16px 18px;
          background: var(--bg);
          border-radius: 10px;
          border: 1px solid var(--hairline);
          font-size: 13px;
        }
        @media (max-width: 720px) {
          .lg-row {
            grid-template-columns: 28px 1fr;
            gap: 8px 12px;
          }
          .lg-d { grid-column: 2; }
        }
        .lg-num {
          font-family: var(--f-mono);
          font-size: 10px;
          color: var(--accent);
          letter-spacing: 0.1em;
        }
        .lg-k {
          font-family: var(--f-mono);
          font-size: 11px;
          letter-spacing: 0.06em;
          font-weight: 600;
          color: var(--ink);
        }
        .lg-d {
          color: var(--ink-2);
          font-size: 13px;
          line-height: 1.5;
        }
      `}</style>
    </Reveal>
  );
};

window.SectionLoyalty = SectionLoyalty;
