// Lumynax brand + UI icons.
// All icons are inline SVG so they recolor via currentColor.

// Animated Aurora-Halo logo matching the Flutter onboarding logo:
// - halo breathes (3.6s scale + opacity)
// - star floats (5s up/down)
// - star + glow twinkle (2.4s)
// CSS keyframes are injected once; toggle `animate` per instance.
if (typeof document !== 'undefined' && !document.getElementById('lumynax-logo-keyframes')) {
  const s = document.createElement('style');
  s.id = 'lumynax-logo-keyframes';
  s.textContent = `
    @keyframes lumy-halo-breathe { 0%,100%{transform:scale(1);opacity:.45} 50%{transform:scale(1.1);opacity:.78} }
    @keyframes lumy-star-float   { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-3%)} }
    @keyframes lumy-star-twinkle { 0%,100%{opacity:.82;transform:scale(1)} 50%{opacity:1;transform:scale(1.05)} }
    @keyframes lumy-glow-pulse   { 0%,100%{opacity:.30} 50%{opacity:.60} }
    @keyframes lumy-arc-spin     { to { transform: rotate(360deg) } }
    @keyframes lumy-star-fade-a { 0%,100% { opacity: 0.2; transform: scale(0.85) } 50% { opacity: 1; transform: scale(1.15) } }
    @keyframes lumy-star-fade-b { 0%,100% { opacity: 0.1; transform: scale(0.8)  } 50% { opacity: 0.75; transform: scale(1.1) } }
    @keyframes lumy-star-drift  { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-8px) } }
    .lumy-stars { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
    .lumy-stars .ls { position: absolute; border-radius: 50%; background: white;
      box-shadow: 0 0 6px 1px rgba(255,255,255,0.45); will-change: transform, opacity;
      animation: lumy-star-fade-a var(--dur, 5s) ease-in-out infinite,
                 lumy-star-drift  calc(var(--dur, 5s) * 3) ease-in-out infinite;
      animation-delay: var(--delay, 0s); }
    .lumy-stars .ls.b { background: #C4A8FF;
      box-shadow: 0 0 8px 1.5px rgba(196,168,255,0.6);
      animation: lumy-star-fade-b var(--dur, 4s) ease-in-out infinite,
                 lumy-star-drift  calc(var(--dur, 4s) * 3) ease-in-out infinite; }
    .lumy-stars .ls.lg { box-shadow: 0 0 14px 2px rgba(255,255,255,0.55); }
    .lumy-stars .ls.lg.b { box-shadow: 0 0 16px 2.5px rgba(196,168,255,0.7); }
    @media (prefers-reduced-motion: reduce) {
      .lumy-stars .ls { animation: none; opacity: 0.6; }
    }
    [data-theme="light"] .lumy-stars { display: none; }
    .lumy-svg .halo  { transform-origin: 50% 50%; animation: lumy-halo-breathe 3.6s ease-in-out infinite; }
    .lumy-svg .glow  { transform-origin: 50% 50%; animation: lumy-glow-pulse   2.4s ease-in-out infinite; }
    .lumy-svg .float { transform-origin: 50% 50%; animation: lumy-star-float   5.0s ease-in-out infinite; }
    .lumy-svg .star  { transform-origin: 50% 50%; animation: lumy-star-twinkle 2.4s ease-in-out infinite; }
    .lumy-svg.no-anim .halo, .lumy-svg.no-anim .glow, .lumy-svg.no-anim .float, .lumy-svg.no-anim .star { animation: none; }
    @media (prefers-reduced-motion: reduce) {
      .lumy-svg .halo, .lumy-svg .glow, .lumy-svg .float, .lumy-svg .star { animation: none; }
    }
  `;
  document.head.appendChild(s);
}

const LumynaxMark = ({ size = 28, halo = true, gradient = true, glow = true, animate = true }) => {
  const id = React.useId().replace(/:/g, '');
  return (
    <svg className={`lumy-svg${animate ? '' : ' no-anim'}`} width={size} height={size} viewBox="0 0 64 64" style={{ overflow: 'visible' }} aria-hidden="true">
      <defs>
        <linearGradient id={`g-${id}`} x1="0" y1="0" x2="1" y2="1">
          <stop offset="0%" stopColor="#C4A8FF" />
          <stop offset="100%" stopColor="#FFFFFF" />
        </linearGradient>
        <radialGradient id={`halo-${id}`}>
          <stop offset="0%" stopColor="#C4A8FF" stopOpacity="0.85" />
          <stop offset="65%" stopColor="#C4A8FF" stopOpacity="0" />
        </radialGradient>
        <radialGradient id={`starglow-${id}`}>
          <stop offset="0%" stopColor="#FFFFFF" stopOpacity="0.7" />
          <stop offset="60%" stopColor="#C4A8FF" stopOpacity="0" />
        </radialGradient>
      </defs>

      {/* 1. Halo bloom (breathing) */}
      {halo && (
        <circle className="halo" cx="32" cy="32" r="30" fill={`url(#halo-${id})`} />
      )}

      {/* 2. Inner ring */}
      {halo && (
        <circle cx="32" cy="32" r="19.5" fill="none" stroke="currentColor" strokeOpacity="0.18" strokeWidth="1" />
      )}

      {/* 3. Star + glow — floats, glow + star twinkle */}
      <g className="float">
        {glow && (
          <circle className="glow" cx="32" cy="32" r="15" fill={`url(#starglow-${id})`} />
        )}
        <path
          className="star"
          d="M32 4 L36.5 27.5 L60 32 L36.5 36.5 L32 60 L27.5 36.5 L4 32 L27.5 27.5 Z"
          fill={gradient ? `url(#g-${id})` : 'currentColor'}
        />
      </g>
    </svg>
  );
};

// Inline pure 4-point spark used decoratively
const Spark = ({ size = 14, color = 'currentColor', opacity = 1 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" style={{ opacity }}>
    <path d="M12 2 L13.5 10.5 L22 12 L13.5 13.5 L12 22 L10.5 13.5 L2 12 L10.5 10.5 Z" fill={color} />
  </svg>
);

// Feature / persona icons drawn in a consistent 24px stroked style
const Ic = {
  Memory: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M9.5 3.5a3 3 0 0 0-3 3v1.2A3.5 3.5 0 0 0 4 11.2v1.6a3.5 3.5 0 0 0 2.5 3.4v1.3a3 3 0 0 0 3 3 2.5 2.5 0 0 0 2.5-2.5V6a2.5 2.5 0 0 0-2.5-2.5Z"/>
      <path d="M14.5 3.5a3 3 0 0 1 3 3v1.2A3.5 3.5 0 0 1 20 11.2v1.6a3.5 3.5 0 0 1-2.5 3.4v1.3a3 3 0 0 1-3 3A2.5 2.5 0 0 1 12 18V6a2.5 2.5 0 0 1 2.5-2.5Z"/>
    </svg>
  ),
  Reminder: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M6 8a6 6 0 1 1 12 0c0 5 2 6 2 6H4s2-1 2-6Z"/>
      <path d="M10 19a2 2 0 0 0 4 0"/>
    </svg>
  ),
  Recall: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 12a9 9 0 1 0 3-6.7"/>
      <path d="M3 4v4h4"/>
      <path d="M12 8v5l3 2"/>
    </svg>
  ),
  Mood: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="9"/>
      <path d="M8.5 14c1 1.2 2.2 1.8 3.5 1.8s2.5-.6 3.5-1.8"/>
      <circle cx="9" cy="10" r="0.6" fill="currentColor"/>
      <circle cx="15" cy="10" r="0.6" fill="currentColor"/>
    </svg>
  ),
  Voice: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="9" y="3" width="6" height="12" rx="3"/>
      <path d="M5 11a7 7 0 0 0 14 0"/>
      <path d="M12 18v3"/>
    </svg>
  ),
  Sun: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="4"/>
      <path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5L19 19M5 19l1.5-1.5M17.5 6.5L19 5"/>
    </svg>
  ),
  Moon: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M20 14.5A8.5 8.5 0 0 1 9.5 4 8 8 0 1 0 20 14.5Z"/>
    </svg>
  ),
  Gift: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="8" width="18" height="5" rx="1"/>
      <path d="M4 13v8h16v-8M12 8v13"/>
      <path d="M8 8a2.5 2.5 0 0 1 0-5c1.5 0 3 1.5 4 5-3 0-4 0-4 0Z"/>
      <path d="M16 8a2.5 2.5 0 0 0 0-5c-1.5 0-3 1.5-4 5 3 0 4 0 4 0Z"/>
    </svg>
  ),
  Check: ({ s = 14 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 12.5 10 18 20 6"/>
    </svg>
  ),
  Plus: ({ s = 14 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M12 5v14M5 12h14"/>
    </svg>
  ),
  Apple: ({ s = 20 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <path d="M17.6 12.6c0-2.7 2.2-4 2.3-4-1.3-1.8-3.2-2.1-3.9-2.1-1.7-.2-3.2 1-4.1 1s-2.1-1-3.5-1c-1.8 0-3.5 1.1-4.4 2.7-1.9 3.3-.5 8.1 1.3 10.8.9 1.3 2 2.7 3.4 2.7 1.4-.1 1.9-.9 3.5-.9s2.1.9 3.5.8c1.5 0 2.4-1.3 3.3-2.6.9-1.4 1.3-2.7 1.3-2.7s-2.7-1-2.7-4.1ZM14.7 5c.8-1 1.3-2.3 1.2-3.6-1.1.1-2.5.8-3.3 1.8-.7.9-1.4 2.2-1.2 3.5 1.3.1 2.5-.7 3.3-1.7Z"/>
    </svg>
  ),
  Play: ({ s = 20 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <path d="M3.6 1.8 14.7 12 3.6 22.2c-.5-.3-.8-.9-.8-1.6V3.4c0-.7.3-1.3.8-1.6ZM17 9.4 5.2 1.7c.3-.1.7-.1 1 .1L18.6 8.3 17 9.4Zm0 5.2 1.6 1.1L6.2 22.2c-.3.2-.7.2-1 .1L17 14.6Zm4.4-1.8c.7.5.7 1.5 0 1.9l-2.7 1.6L17 14.6V9.4l1.7-1.1 2.7 1.5Z"/>
    </svg>
  ),
  Globe: ({ s = 16 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round">
      <circle cx="12" cy="12" r="9"/>
      <path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18"/>
    </svg>
  ),
  Sun2: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round">
      <circle cx="12" cy="12" r="4"/>
      <path d="M12 3v1.5M12 19.5V21M3 12h1.5M19.5 12H21M5.5 5.5l1 1M17.5 17.5l-1-1M5.5 18.5l1-1M17.5 6.5l-1 1"/>
    </svg>
  ),
  Moon2: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M20 14.5A8.5 8.5 0 0 1 9.5 4 8 8 0 1 0 20 14.5Z"/>
    </svg>
  ),
  Heart: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 21s-7-4.5-9.4-9C1 8.5 3 4.5 7 4.5c2 0 3.5 1 5 3 1.5-2 3-3 5-3 4 0 6 4 4.4 7.5C19 16.5 12 21 12 21Z"/>
    </svg>
  ),
  Rocket: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M5 14s2.5-7 8-10 8 0 8 0 0 6-3 8.5L13 19l-3-3-5 1Z"/>
      <circle cx="14" cy="9" r="1.5"/>
      <path d="M5 14l-2 5 5-2"/>
    </svg>
  ),
  Sparkle: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 2 L13.5 10.5 L22 12 L13.5 13.5 L12 22 L10.5 13.5 L2 12 L10.5 10.5 Z"/>
    </svg>
  ),
  Book: ({ s = 22 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 4.5A1.5 1.5 0 0 1 5.5 3H11v18H5.5A1.5 1.5 0 0 1 4 19.5Z"/>
      <path d="M20 4.5A1.5 1.5 0 0 0 18.5 3H13v18h5.5a1.5 1.5 0 0 0 1.5-1.5Z"/>
    </svg>
  ),
  Cake: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 14v6h16v-6"/>
      <path d="M3 14a3 3 0 0 0 3-1.5 3 3 0 0 0 6 0 3 3 0 0 0 6 0A3 3 0 0 0 21 14"/>
      <path d="M8 9V6M12 9V5M16 9V6"/>
    </svg>
  ),
  Briefcase: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="2" y="7" width="20" height="13" rx="2"/>
      <path d="M9 7V5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2"/>
      <path d="M2 13h20"/>
    </svg>
  ),
  Tooth: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M12 2c2.5 0 4 1 5.5 1.6 1.4.6 2.5 2 2.5 4 0 2.5-.8 4-.8 6 0 1.5.3 3 .3 5 0 1.5-.5 3-1.5 3s-1.5-1-2-2.5L15 16c-.4-1.4-1.5-1.7-2-1.7H11c-.5 0-1.6.3-2 1.7l-1 3c-.5 1.5-1 2.5-2 2.5s-1.5-1.5-1.5-3c0-2 .3-3.5.3-5 0-2-.8-3.5-.8-6 0-2 1.1-3.4 2.5-4C8 3 9.5 2 12 2Z"/>
    </svg>
  ),
  Slides: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="4" width="18" height="13" rx="1.5"/>
      <path d="M8 21h8M12 17v4"/>
      <path d="M7 11l2.5 2.5L13 9.5l4 4.5"/>
    </svg>
  ),
  Pulse: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 12h4l3-8 4 16 3-8h4"/>
    </svg>
  ),
  Users: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
      <circle cx="8.5" cy="7" r="4"/>
      <path d="M23 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75"/>
    </svg>
  ),
  Dots: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <circle cx="5" cy="12" r="2"/><circle cx="12" cy="12" r="2"/><circle cx="19" cy="12" r="2"/>
    </svg>
  ),
  ChevronDown: ({ s = 18 }) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M6 9l6 6 6-6"/>
    </svg>
  ),
};

// Cosmic starfield used as a subtle hero background.
// 28 white primary stars + 18 lavender secondary, each is a small glowing
// dot (CSS box-shadow) that twinkles + drifts. Hidden on light theme.
const Starfield = () => {
  // [xPercent, yPercent, sizePx, durSec, delaySec]
  const primary = [
    [4, 18, 2.5, 5.2, 0.0], [8, 62, 1.6, 6.0, 1.4], [12, 12, 3.0, 4.8, 0.6],
    [15, 45, 1.8, 6.2, 2.1], [19, 78, 2.4, 5.6, 0.3], [23, 28, 2.0, 5.0, 1.8],
    [27, 8,  1.6, 4.6, 0.9], [31, 55, 2.8, 5.4, 2.5], [35, 35, 1.7, 6.4, 1.2],
    [38, 72, 2.2, 5.8, 0.5], [42, 18, 3.1, 5.0, 1.7], [46, 50, 1.5, 6.2, 2.8],
    [50, 85, 2.0, 4.8, 0.2], [54, 22, 1.8, 5.6, 1.5], [58, 65, 2.6, 5.2, 2.2],
    [62, 38, 1.6, 6.0, 0.8], [66, 12, 2.4, 4.6, 1.9], [70, 78, 3.0, 5.4, 0.4],
    [73, 28, 1.7, 6.2, 1.1], [77, 58, 2.2, 4.8, 2.4], [81, 14, 2.8, 5.8, 0.7],
    [85, 42, 1.9, 6.0, 1.6], [88, 70, 1.6, 5.0, 2.0], [92, 30, 2.4, 5.4, 0.3],
    [95, 55, 1.8, 4.6, 1.3], [97, 18, 2.0, 6.2, 2.6], [6,  88, 2.6, 5.0, 0.5],
    [11, 35, 1.7, 5.6, 1.8],
  ];
  const secondary = [
    [10, 25, 1.4, 4.0, 0.1], [17, 88, 2.0, 4.4, 1.6], [25, 60, 1.6, 4.2, 0.7],
    [33, 18, 2.4, 3.8, 2.0], [40, 90, 1.5, 4.6, 1.0], [48, 30, 1.8, 4.0, 0.4],
    [56, 72, 2.2, 4.4, 1.9], [64, 50, 1.4, 4.2, 0.6], [71, 14, 2.0, 4.6, 1.4],
    [79, 84, 1.6, 3.8, 0.2], [87, 30, 2.4, 4.0, 1.7], [94, 75, 1.5, 4.4, 0.8],
    [3,  50, 1.8, 4.2, 2.1], [19, 8,  2.0, 3.8, 0.9], [44, 65, 1.6, 4.6, 1.3],
    [60, 8,  2.2, 4.0, 0.5], [76, 42, 1.5, 4.4, 1.8], [90, 92, 1.8, 4.2, 0.3],
  ];
  return (
    <div className="lumy-stars" aria-hidden="true">
      {primary.map(([x, y, s, d, dl], i) => (
        <span key={'p' + i} className={`ls${s > 2.5 ? ' lg' : ''}`} style={{
          left: x + '%', top: y + '%',
          width: s + 'px', height: s + 'px',
          ['--dur']: d + 's', ['--delay']: dl + 's',
        }}/>
      ))}
      {secondary.map(([x, y, s, d, dl], i) => (
        <span key={'s' + i} className={`ls b${s > 2 ? ' lg' : ''}`} style={{
          left: x + '%', top: y + '%',
          width: s + 'px', height: s + 'px',
          ['--dur']: d + 's', ['--delay']: dl + 's',
        }}/>
      ))}
    </div>
  );
};

Object.assign(window, { LumynaxMark, Spark, Ic, Starfield });
