// Shared brand primitives — Qubikos marketing surfaces.
// Neon pictograms inspired by hero-cube reference image.

const QB_SPORTS = [
  // --- FRONT FACE (cyan): action sports ---
  { key:'swim', label:'Swimming',
    paths:(<g>
      {/* Horizontal freestyle swimmer */}
      <circle cx="18" cy="30" r="5"/>
      <path d="M14 30 L 28 28 L 42 30 L 52 26 C 55 24 57 28 54 30 L 44 35 L 32 35 L 22 35 C 18 35 14 33 14 30 Z"/>
      <path d="M46 26 L 56 20 C 58 19 60 22 58 24 L 50 30" strokeWidth="4" stroke="currentColor" fill="none" strokeLinecap="round"/>
      <path d="M6 44 Q 14 40 22 44 T 38 44 T 54 44 T 62 44" stroke="currentColor" strokeWidth="2.5" fill="none" strokeLinecap="round"/>
      <path d="M6 52 Q 14 48 22 52 T 38 52 T 54 52 T 62 52" stroke="currentColor" strokeWidth="2.5" fill="none" strokeLinecap="round"/>
    </g>) },
  { key:'run', label:'Running',
    paths:(<g>
      {/* Sprinter — stick figure like reference */}
      <circle cx="38" cy="12" r="5"/>
      <path d="M36 18 L 34 30 L 22 32" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <path d="M34 30 L 44 34 L 46 24" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <path d="M34 30 L 28 42 L 18 46" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <path d="M34 30 L 42 44 L 52 48" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
    </g>) },
  { key:'hoops', label:'Basketball',
    paths:(<g>
      <circle cx="32" cy="32" r="22"/>
      <path d="M32 10 L 32 54 M10 32 L 54 32 M16 16 C 22 24 22 40 16 48 M48 16 C 42 24 42 40 48 48"
        stroke="#0a1338" strokeWidth="2.5" fill="none" strokeLinecap="round"/>
    </g>) },
  { key:'cycle', label:'Cycling',
    paths:(<g>
      <circle cx="14" cy="46" r="9" fill="none" stroke="currentColor" strokeWidth="3"/>
      <circle cx="50" cy="46" r="9" fill="none" stroke="currentColor" strokeWidth="3"/>
      <path d="M14 46 L 26 30 L 42 30 L 50 46 M32 30 L 38 22 L 46 22" stroke="currentColor" strokeWidth="3" fill="none" strokeLinecap="round" strokeLinejoin="round"/>
      <circle cx="40" cy="14" r="4"/>
    </g>) },
  { key:'yoga', label:'Yoga',
    paths:(<g>
      {/* Seated meditation — simple silhouette */}
      <circle cx="32" cy="14" r="5"/>
      <path d="M32 20 C 28 21 26 25 26 30 L 26 38 C 18 38 12 42 10 48 L 6 54 L 14 54 L 22 48 L 42 48 L 50 54 L 58 54 L 54 48 C 52 42 46 38 38 38 L 38 30 C 38 25 36 21 32 20 Z"/>
    </g>) },
  { key:'karate', label:'Karate',
    paths:(<g>
      {/* High side-kick */}
      <circle cx="24" cy="14" r="5"/>
      <path d="M22 20 L 20 30 L 14 40" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <path d="M20 30 L 30 30 L 38 22" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <path d="M20 30 L 28 42 L 22 54" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <path d="M28 42 L 46 42 L 58 36" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
    </g>) },
  { key:'box', label:'Boxing',
    paths:(<g>
      {/* Boxer with gloves */}
      <circle cx="26" cy="14" r="5"/>
      <path d="M24 20 L 22 34 L 26 34 L 26 48 L 20 56" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <path d="M26 48 L 34 48 L 36 56" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <path d="M22 28 L 12 32" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <circle cx="10" cy="34" r="6"/>
      <path d="M26 28 L 42 26" stroke="currentColor" strokeWidth="5" fill="none" strokeLinecap="round"/>
      <circle cx="46" cy="24" r="6"/>
    </g>) },
  { key:'gymnast', label:'Gymnastics',
    paths:(<g>
      {/* Gymnast leap — arms up, split */}
      <circle cx="32" cy="10" r="4.5"/>
      <path d="M32 15 L 32 32" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M32 18 L 20 8" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M32 18 L 44 8" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M32 32 L 14 46" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M32 32 L 52 46" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
    </g>) },
  { key:'soccer', label:'Soccer',
    paths:(<g>
      {/* Just the ball, like reference */}
      <circle cx="32" cy="32" r="22"/>
      <path d="M32 18 L 42 25 L 38 37 L 26 37 L 22 25 Z" fill="#0a1338"/>
      <path d="M32 10 L 32 18 M32 46 L 32 56 M10 32 L 22 32 M42 32 L 54 32 M16 16 L 22 25 M48 16 L 42 25 M16 48 L 26 37 M48 48 L 38 37"
        stroke="#0a1338" strokeWidth="2" fill="none" strokeLinecap="round"/>
    </g>) },

  // --- RIGHT FACE (purple/magenta): artistic & equipment sports ---
  { key:'rings', label:'Rings',
    paths:(<g>
      {/* Two hanging rings */}
      <path d="M20 6 L 20 28 M44 6 L 44 28" stroke="currentColor" strokeWidth="3" fill="none" strokeLinecap="round"/>
      <circle cx="20" cy="38" r="10" fill="none" stroke="currentColor" strokeWidth="4.5"/>
      <circle cx="44" cy="38" r="10" fill="none" stroke="currentColor" strokeWidth="4.5"/>
    </g>) },
  { key:'ballet', label:'Ballet',
    paths:(<g>
      {/* Ballerina on pointe — one leg extended */}
      <circle cx="28" cy="10" r="4.5"/>
      <path d="M28 15 L 26 24 L 28 34" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M26 20 L 14 14" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M26 20 L 42 26" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M28 34 L 24 52" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M28 34 L 48 46" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M18 38 L 10 40 L 18 42 L 8 46 L 46 46 L 38 42 L 46 40 L 38 38 Z" opacity="0.6"/>
    </g>) },
  { key:'pommel', label:'Pommel horse',
    paths:(<g>
      {/* Pommel horse */}
      <rect x="8" y="28" width="48" height="14" rx="6"/>
      <path d="M22 22 L 22 32 M22 22 Q 22 18 24 18 Q 26 18 26 22 L 26 32" stroke="currentColor" strokeWidth="3" fill="none" strokeLinecap="round"/>
      <path d="M38 22 L 38 32 M38 22 Q 38 18 40 18 Q 42 18 42 22 L 42 32" stroke="currentColor" strokeWidth="3" fill="none" strokeLinecap="round"/>
      <path d="M14 42 L 14 56 M50 42 L 50 56" stroke="currentColor" strokeWidth="3.5" strokeLinecap="round" fill="none"/>
    </g>) },
  { key:'jump', label:'Jump rope',
    paths:(<g>
      {/* Jumping rope */}
      <circle cx="32" cy="14" r="4.5"/>
      <path d="M32 19 L 32 38" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M32 24 L 22 22" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M32 24 L 42 22" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M32 38 L 26 52" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M32 38 L 38 52" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M22 22 C 8 32 8 50 22 54" stroke="currentColor" strokeWidth="2.5" fill="none" strokeLinecap="round"/>
      <path d="M42 22 C 56 32 56 50 42 54" stroke="currentColor" strokeWidth="2.5" fill="none" strokeLinecap="round"/>
    </g>) },
  { key:'dance', label:'Dance',
    paths:(<g>
      {/* Dancer arm up */}
      <circle cx="32" cy="10" r="4.5"/>
      <path d="M32 15 L 28 30 L 34 44" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M30 20 L 48 8" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M30 24 L 14 30" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M34 44 L 20 56" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M34 44 L 48 54" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
    </g>) },
  { key:'gym', label:'Gym',
    paths:(<g>
      {/* Building with "GYM" like reference */}
      <path d="M8 22 L 32 10 L 56 22 L 56 56 L 8 56 Z" fill="none" stroke="currentColor" strokeWidth="3.5" strokeLinejoin="round"/>
      <rect x="20" y="34" width="24" height="22" fill="none" stroke="currentColor" strokeWidth="2.5"/>
      <text x="32" y="30" textAnchor="middle" fontSize="10" fontWeight="700" fill="currentColor" fontFamily="var(--font-display)">GYM</text>
    </g>) },
  { key:'dancers', label:'Dancers',
    paths:(<g>
      {/* Two figures holding hands */}
      <circle cx="22" cy="14" r="4.5"/>
      <path d="M22 19 L 20 32 L 16 52" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M20 32 L 28 52" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M20 24 L 10 30" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M22 24 L 42 24" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <circle cx="44" cy="14" r="4.5"/>
      <path d="M44 19 L 44 32 L 40 52" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M44 32 L 50 52" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
      <path d="M44 24 L 56 30" stroke="currentColor" strokeWidth="4.5" fill="none" strokeLinecap="round"/>
    </g>) },
  { key:'music', label:'Music',
    paths:(<g>
      {/* Music notes */}
      <path d="M18 42 L 18 14 L 46 10 L 46 38" stroke="currentColor" strokeWidth="4" fill="none" strokeLinecap="round" strokeLinejoin="round"/>
      <ellipse cx="14" cy="44" rx="8" ry="6"/>
      <ellipse cx="42" cy="40" rx="8" ry="6"/>
    </g>) },
];

function SportIcon({ paths, d, size = 22, className = '' }) {
  return (
    <svg viewBox="0 0 64 64" width={size} height={size} fill="currentColor"
      stroke="none" className={className} aria-hidden="true">
      {paths ?? (d ? <path d={d}/> : null)}
    </svg>
  );
}

function Wordmark({ className = '', style = {} }) {
  return (
    <span className={`wordmark ${className}`} style={style}>
      qubikos<span style={{ color: 'var(--blue-500)' }}>.</span>
    </span>
  );
}

function Pill({ children, tone = 'neutral', style }) {
  const tones = {
    neutral: { bg: 'rgba(255,255,255,0.06)', fg: 'var(--fg-1)', dot: 'var(--ink-400)' },
    blue:    { bg: 'rgba(57,104,255,0.12)',  fg: 'var(--blue-300)', dot: 'var(--blue-400)' },
    ok:      { bg: 'rgba(16,185,129,0.12)',  fg: '#34d399',        dot: '#10b981' },
  }[tone];
  return (
    <span style={{
      display:'inline-flex', alignItems:'center', gap:8,
      padding:'6px 12px', borderRadius: 999,
      background: tones.bg, color: tones.fg,
      border:'1px solid var(--border)',
      fontSize: 13, fontWeight: 500, letterSpacing:'-0.005em',
      ...style,
    }}>
      <span style={{ width:6, height:6, borderRadius:999, background: tones.dot }}/>
      {children}
    </span>
  );
}

function QBButton({ children, variant = 'primary', size = 'md', icon, style = {}, ...rest }) {
  const sizes = {
    sm: { h: 34, px: 14, fs: 13 },
    md: { h: 44, px: 20, fs: 14 },
    lg: { h: 52, px: 24, fs: 15 },
  }[size];
  const variants = {
    primary: {
      background: 'linear-gradient(180deg, #4d7dff 0%, #2950e6 100%)',
      color: '#fff', border: '1px solid rgba(255,255,255,0.18)',
      boxShadow: '0 1px 0 rgba(255,255,255,0.25) inset, 0 8px 24px rgba(41,80,230,0.35)',
    },
    ghost: {
      background: 'rgba(255,255,255,0.10)', color: '#fff',
      border: '1px solid rgba(255,255,255,0.22)', boxShadow: 'none',
    },
    light: {
      background: '#fff', color: 'var(--ink-900)',
      border: '1px solid var(--ink-200)', boxShadow: 'var(--shadow-sm)',
    },
  }[variant];
  return (
    <button {...rest} style={{
      display:'inline-flex', alignItems:'center', justifyContent:'center', gap:8,
      height: sizes.h, padding: `0 ${sizes.px}px`, borderRadius: 999,
      fontFamily: 'var(--font-sans)', fontSize: sizes.fs, fontWeight: 600,
      letterSpacing: '-0.01em', cursor: 'pointer',
      transition: 'transform .14s var(--ease-out), box-shadow .14s var(--ease-out), opacity .14s',
      ...variants, ...style,
    }}
    onMouseDown={e => e.currentTarget.style.transform = 'scale(0.98)'}
    onMouseUp={e => e.currentTarget.style.transform = ''}
    onMouseLeave={e => e.currentTarget.style.transform = ''}>
      {icon}{children}
    </button>
  );
}

// 3D cube with neon pictograms — cyan front, magenta right, purple top.
function QubeHero({ size = 460 }) {
  const front = QB_SPORTS.slice(0, 9);   // cyan
  const right = QB_SPORTS.slice(9, 18);  // magenta
  const top   = [...QB_SPORTS.slice(0, 3), ...QB_SPORTS.slice(9, 12), ...QB_SPORTS.slice(3, 6)]; // mix
  const tile = (size - 24) / 3;
  const iconSize = Math.round(tile * 0.64);

  function Face({ transform, icons, accent, shade }) {
    return (
      <div style={{
        position:'absolute', inset:0, width: size, height: size,
        display:'grid', gridTemplateColumns:'1fr 1fr 1fr', gridTemplateRows:'1fr 1fr 1fr',
        gap: 8, padding: 10,
        borderRadius: 22, overflow: 'hidden',
        background: shade,
        boxShadow: 'inset 0 0 120px rgba(124,92,255,0.18), inset 0 0 0 1.5px rgba(255,255,255,0.08)',
        transform,
      }}>
        {icons.map((s, i) => (
          <div key={i} style={{
            background: 'radial-gradient(80% 80% at 50% 40%, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.015) 100%)',
            border: '1px solid rgba(255,255,255,0.10)',
            borderRadius: 14, display:'grid', placeItems:'center',
            color: accent,
            filter: `drop-shadow(0 0 8px ${accent}66)`,
            boxShadow: 'inset 0 1px 0 rgba(255,255,255,0.10), inset 0 -1px 0 rgba(0,0,0,0.25)',
          }}>
            <SportIcon paths={s.paths} size={iconSize}/>
          </div>
        ))}
      </div>
    );
  }

  return (
    <div style={{
      width: size, height: size, perspective: 1400,
      position:'relative',
      filter: 'drop-shadow(0 40px 80px rgba(57,104,255,0.50)) drop-shadow(0 0 140px rgba(124,92,255,0.45))',
    }}>
      <div style={{
        width: size, height: size, position:'relative',
        transformStyle: 'preserve-3d',
        transform: 'rotateX(-18deg) rotateY(28deg)',
        animation: 'qube-spin 36s ease-in-out infinite',
      }}>
        <Face transform={`translateZ(${size/2}px)`}
          icons={front} accent="#4dd4ff"
          shade="linear-gradient(155deg, #0e1742 0%, #050a22 100%)"/>
        <Face transform={`rotateY(-90deg) translateZ(${size/2}px)`}
          icons={right} accent="#c770ff"
          shade="linear-gradient(155deg, #1a1540 0%, #06051a 100%)"/>
        <Face transform={`rotateX(90deg) translateZ(${size/2}px)`}
          icons={top} accent="#8cb0ff"
          shade="linear-gradient(155deg, #101a4a 0%, #07091e 100%)"/>
      </div>
      <style>{`
        @keyframes qube-spin {
          0%   { transform: rotateX(-18deg) rotateY(22deg); }
          50%  { transform: rotateX(-22deg) rotateY(38deg); }
          100% { transform: rotateX(-18deg) rotateY(22deg); }
        }
      `}</style>
    </div>
  );
}

Object.assign(window, { QB_SPORTS, SportIcon, Wordmark, Pill, QBButton, QubeHero });
