// Lumyna design primitives — shared across every screen.
// All styles are object literals to avoid global name collisions.

// Gradient artwork — deterministic from seed. Replaces placeholder colors.
function GradientArt({ seed = 0, size = 38, radius }) {
  const palette = [
    ['#F6C75C','#C74F6F','#5AA8C7'],    // warm
    ['#7C4DBC','#D14B78','#4A93C5'],    // magenta
    ['#3D6FC7','#7742B5','#D14B7A'],    // royal
    ['#5FC78B','#3596C7','#A340C7'],    // ocean
    ['#E38A3B','#C7445E','#6554C7'],    // sunset
    ['#8CC75F','#45B29D','#346C9C'],    // moss
    ['#C77A3B','#89346C','#364B8C'],    // amber-purple
    ['#4FB06B','#C7A63B','#B04F4F'],    // field
    ['#9C4FBC','#3B7DC7','#4FBC88'],    // prism
    ['#C73B70','#7B3BC7','#3BC7AB'],    // vivid
  ];
  const colors = palette[seed % palette.length];
  const r = radius ?? Math.max(6, size * 0.16);
  return (
    <div style={{
      width: size, height: size, borderRadius: r,
      position: 'relative', overflow: 'hidden', flexShrink: 0,
      background: `
        radial-gradient(circle at 20% 30%, ${colors[0]} 0%, transparent 55%),
        radial-gradient(circle at 70% 40%, ${colors[1]} 0%, transparent 60%),
        radial-gradient(circle at 50% 80%, ${colors[2]} 0%, transparent 60%),
        linear-gradient(135deg, ${colors[0]}40, ${colors[2]}40)
      `,
      boxShadow: 'inset 0 0 0 0.5px rgba(255,255,255,0.12), 0 1px 2px rgba(0,0,0,0.3)',
    }} />
  );
}

// Simplified SF Symbol icons
const Icons = {
  chevronLeft: (s = 16, c = 'currentColor') => (
    <svg width={s} height={s*1.5} viewBox="0 0 8 12" fill="none">
      <path d="M6.5 1L1.5 6l5 5" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  chevronRight: (s = 12, c = 'currentColor') => (
    <svg width={s} height={s*1.5} viewBox="0 0 8 12" fill="none">
      <path d="M1.5 1L6.5 6l-5 5" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  chevronDown: (s = 14, c = 'currentColor') => (
    <svg width={s} height={s*0.66} viewBox="0 0 12 8" fill="none">
      <path d="M1 1l5 5 5-5" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  plus: (s = 18, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 18 18" fill="none">
      <path d="M9 3v12M3 9h12" stroke={c} strokeWidth="2" strokeLinecap="round"/>
    </svg>
  ),
  ellipsis: (s = 20, c = 'currentColor') => (
    <svg width={s} height={s*0.24} viewBox="0 0 20 5" fill={c}>
      <circle cx="2.5" cy="2.5" r="2"/>
      <circle cx="10" cy="2.5" r="2"/>
      <circle cx="17.5" cy="2.5" r="2"/>
    </svg>
  ),
  play: (s = 14, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 14 14" fill={c}>
      <path d="M3 1.8v10.4c0 .7.8 1.1 1.3.7l8.4-5.2a.8.8 0 000-1.4L4.3 1.1C3.8.7 3 1.1 3 1.8z"/>
    </svg>
  ),
  pause: (s = 18, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 18 18" fill={c}>
      <rect x="3" y="2" width="4" height="14" rx="1.2"/>
      <rect x="11" y="2" width="4" height="14" rx="1.2"/>
    </svg>
  ),
  skipBack: (s = 22, c = 'currentColor') => (
    <svg width={s} height={s*0.68} viewBox="0 0 22 15" fill={c}>
      <path d="M10 1.5L2 7v1L10 13.5a.5.5 0 00.8-.4V2a.5.5 0 00-.8-.5z"/>
      <path d="M20 1.5L12 7v1L20 13.5a.5.5 0 00.8-.4V2a.5.5 0 00-.8-.5z"/>
    </svg>
  ),
  skipFwd: (s = 22, c = 'currentColor') => (
    <svg width={s} height={s*0.68} viewBox="0 0 22 15" fill={c}>
      <path d="M12 1.5L20 7v1L12 13.5a.5.5 0 01-.8-.4V2a.5.5 0 01.8-.5z"/>
      <path d="M2 1.5L10 7v1L2 13.5a.5.5 0 01-.8-.4V2a.5.5 0 01.8-.5z"/>
    </svg>
  ),
  shuffle: (s = 17, c = 'currentColor') => (
    <svg width={s} height={s*0.85} viewBox="0 0 17 14" fill="none">
      <path d="M1 2h3l8 10h3M13 2h3M13 12h3M15 0l2 2-2 2M15 10l2 2-2 2M1 12h3l2-2.5" stroke={c} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  repeat: (s = 17, c = 'currentColor') => (
    <svg width={s} height={s*0.85} viewBox="0 0 17 14" fill="none">
      <path d="M2 5V4a2 2 0 012-2h9M2 5l-1-1m1 1l-1 1M15 9v1a2 2 0 01-2 2H4m11-3l1 1m-1-1l1-1" stroke={c} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  star: (s = 18, c = 'currentColor', filled = false) => (
    <svg width={s} height={s} viewBox="0 0 18 18" fill={filled ? c : 'none'} stroke={c} strokeWidth={filled ? 0 : 1.5}>
      <path d="M9 1.5l2.3 4.8 5.2.5-3.9 3.5 1.1 5.2L9 12.8l-4.7 2.7 1.1-5.2L1.5 6.8l5.2-.5L9 1.5z" strokeLinejoin="round"/>
    </svg>
  ),
  info: (s = 18, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 18 18" fill="none" stroke={c} strokeWidth="1.5">
      <circle cx="9" cy="9" r="7.25"/>
      <path d="M9 7.5v5" strokeLinecap="round"/>
      <circle cx="9" cy="5" r="0.9" fill={c} stroke="none"/>
    </svg>
  ),
  checkmark: (s = 14, c = 'currentColor') => (
    <svg width={s} height={s*0.75} viewBox="0 0 14 10" fill="none">
      <path d="M1 5l4 4L13 1" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  airplay: (s = 18, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 18 18" fill="none" stroke={c} strokeWidth="1.5">
      <path d="M3 12H2a1 1 0 01-1-1V3a1 1 0 011-1h14a1 1 0 011 1v8a1 1 0 01-1 1h-1M6 16l3-3 3 3z" strokeLinejoin="round" fill={c} fillOpacity="0.0"/>
      <path d="M6 16l3-3 3 3H6z" fill={c}/>
    </svg>
  ),
  queue: (s = 18, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 18 18" fill="none" stroke={c} strokeWidth="1.6" strokeLinecap="round">
      <path d="M3 5h12M3 9h12M3 13h8M14 13l2 2-2 2v-4z" fill={c} strokeWidth="0"/>
      <path d="M3 5h12M3 9h12M3 13h8"/>
    </svg>
  ),
  search: (s = 17, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 17 17" fill="none" stroke={c} strokeWidth="1.6">
      <circle cx="7.5" cy="7.5" r="5.25"/>
      <path d="M11.5 11.5l3 3" strokeLinecap="round"/>
    </svg>
  ),
  cog: (s = 17, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 17 17" fill="none" stroke={c} strokeWidth="1.4">
      <circle cx="8.5" cy="8.5" r="2.4"/>
      <path d="M8.5 1.5v2M8.5 13.5v2M15.5 8.5h-2M3.5 8.5h-2M13.5 3.5l-1.4 1.4M4.9 12.1L3.5 13.5M13.5 13.5l-1.4-1.4M4.9 4.9L3.5 3.5"/>
    </svg>
  ),
  note: (s = 16, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill={c}>
      <path d="M13 1.5L6 3v8.2A2.8 2.8 0 104.5 8.3c.35 0 .68.06 1 .18V3.8L12 2.6v6.4a2.8 2.8 0 10-1.5 2.9V1.5h2.5z"/>
    </svg>
  ),
  person2: (s = 18, c = 'currentColor') => (
    <svg width={s} height={s*0.88} viewBox="0 0 18 16" fill={c}>
      <circle cx="6" cy="4" r="2.5"/>
      <circle cx="13" cy="5" r="2"/>
      <path d="M1 13c0-2.5 2.2-4.5 5-4.5s5 2 5 4.5v1H1v-1z"/>
      <path d="M12 9.5c2.3 0 4 1.6 4 4v1h-3.5v-1c0-1.4-.5-2.6-1.3-3.5.3-.3.5-.5.8-.5z"/>
    </svg>
  ),
  disc: (s = 18, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 18 18" fill="none" stroke={c} strokeWidth="1.5">
      <circle cx="9" cy="9" r="7.25"/>
      <circle cx="9" cy="9" r="2.2"/>
      <circle cx="9" cy="9" r="0.7" fill={c} stroke="none"/>
    </svg>
  ),
  listBullet: (s = 18, c = 'currentColor') => (
    <svg width={s} height={s*0.77} viewBox="0 0 18 14" fill="none" stroke={c} strokeWidth="1.6" strokeLinecap="round">
      <path d="M6 2h11M6 7h11M6 12h11"/>
      <circle cx="2" cy="2" r="1" fill={c}/>
      <circle cx="2" cy="7" r="1" fill={c}/>
      <circle cx="2" cy="12" r="1" fill={c}/>
    </svg>
  ),
  heart: (s = 18, c = 'currentColor', filled = false) => (
    <svg width={s} height={s} viewBox="0 0 18 18" fill={filled ? c : 'none'} stroke={c} strokeWidth={filled ? 0 : 1.5}>
      <path d="M9 15.5s-6-3.8-6-8.3C3 4.8 4.8 3 7 3c1.2 0 2.3.6 3 1.6C10.7 3.6 11.8 3 13 3c2.2 0 4 1.8 4 4.2 0 4.5-6 8.3-6 8.3z" strokeLinejoin="round"/>
    </svg>
  ),
  trash: (s = 17, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 17 17" fill="none" stroke={c} strokeWidth="1.5">
      <path d="M3 4.5h11M7 1.5h3a1 1 0 011 1v2H6v-2a1 1 0 011-1zM4.5 4.5l.8 10.1a1 1 0 001 .9h5.4a1 1 0 001-.9l.8-10.1" strokeLinejoin="round"/>
    </svg>
  ),
  pencil: (s = 16, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill="none" stroke={c} strokeWidth="1.5" strokeLinejoin="round">
      <path d="M11 2.5l2.5 2.5M10 3.5l2.5 2.5-8 8H2v-2.5l8-8z"/>
    </svg>
  ),
  sort: (s = 17, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 17 17" fill="none" stroke={c} strokeWidth="1.5" strokeLinecap="round">
      <path d="M5 3v10M5 13l-2-2M5 13l2-2M12 14V4M12 4l-2 2M12 4l2 2"/>
    </svg>
  ),
  equalizer: (s = 16, c = 'currentColor') => (
    <svg width={s} height={s} viewBox="0 0 16 16" fill={c}>
      <rect x="1.5" y="9" width="2.2" height="5" rx="1"/>
      <rect x="5.5" y="4" width="2.2" height="10" rx="1"/>
      <rect x="9.5" y="7" width="2.2" height="7" rx="1"/>
      <rect x="13.5" y="5.5" width="2.2" height="8.5" rx="1"/>
    </svg>
  ),
};

// Annotation marker — dashed outline + label.
// Only rendered when the global annotations toggle is on.
function Annot({ children, label, rule, color = '#D58E90', style = {}, placement = 'right' }) {
  const pl = {
    position: 'relative',
    display: 'contents',
    ...style,
  };
  return (
    <div style={pl}>
      {children}
      <div data-annot style={{
        position: 'absolute', inset: -4,
        border: `1px dashed ${color}`,
        borderRadius: 10, pointerEvents: 'none',
        boxShadow: `0 0 0 2px rgba(0,0,0,0.25)`,
      }} />
      <div data-annot style={{
        position: 'absolute', top: -10, left: placement === 'right' ? '100%' : 'auto', right: placement === 'left' ? '100%' : 'auto',
        marginLeft: placement === 'right' ? 12 : 0,
        marginRight: placement === 'left' ? 12 : 0,
        padding: '6px 10px', borderRadius: 8,
        background: '#1A1C20', border: `1px solid ${color}`,
        fontFamily: '"JetBrains Mono", ui-monospace, monospace',
        fontSize: 10, letterSpacing: 0.02,
        color: '#EDEEF0',
        maxWidth: 220, whiteSpace: 'normal', lineHeight: 1.4,
        zIndex: 999,
      }}>
        <div style={{ color, fontWeight: 600, marginBottom: 2 }}>{label}</div>
        <div style={{ color: 'rgba(235,236,240,0.75)' }}>{rule}</div>
      </div>
    </div>
  );
}

// A simple block-level annotation: a dashed frame around children with a label pill.
function AnnotBox({ children, label, rule, color = '#D58E90', enabled, placement = 'top-right' }) {
  if (!enabled) return children;
  const pos = {
    'top-right': { top: -12, right: 8 },
    'top-left': { top: -12, left: 8 },
    'bottom-right': { bottom: -12, right: 8 },
    'bottom-left': { bottom: -12, left: 8 },
  }[placement];
  return (
    <div style={{ position: 'relative' }}>
      <div style={{
        position: 'absolute', inset: -3,
        border: `1px dashed ${color}`,
        borderRadius: 8, pointerEvents: 'none',
      }} />
      <div style={{
        position: 'absolute', ...pos,
        padding: '4px 8px', borderRadius: 6,
        background: '#17191D', border: `1px solid ${color}`,
        fontFamily: '"JetBrains Mono", ui-monospace, monospace',
        fontSize: 9.5, letterSpacing: 0.02,
        color: '#F1F1F4', fontWeight: 500,
        zIndex: 40, whiteSpace: 'nowrap',
        boxShadow: '0 4px 10px rgba(0,0,0,0.5)',
      }}>
        <span style={{ color }}>●</span> {label}
      </div>
      {children}
    </div>
  );
}

// Shared glass surface recipe — for the mini player, tab bar, sheets.
function GlassSurface({ children, style = {}, dark = true, strength = 'default', radius = 24 }) {
  const tint = strength === 'strong' ? 0.14 : 0.07;
  const s = {
    position: 'relative',
    borderRadius: radius,
    overflow: 'hidden',
    background: dark ? `rgba(22,24,28,${0.55 + tint})` : `rgba(255,255,255,${0.6 + tint})`,
    backdropFilter: 'blur(24px) saturate(180%)',
    WebkitBackdropFilter: 'blur(24px) saturate(180%)',
    boxShadow: dark
      ? `inset 0 0.5px 0 rgba(255,255,255,0.10), inset 0 0 0 0.5px rgba(255,255,255,0.06), 0 20px 50px rgba(0,0,0,0.45)`
      : `inset 0 0.5px 0 rgba(255,255,255,0.9), inset 0 0 0 0.5px rgba(0,0,0,0.06), 0 10px 30px rgba(0,0,0,0.12)`,
    ...style,
  };
  return <div style={s}>{children}</div>;
}

// Rose-tinted "now playing" equalizer ticks.
function EqTicks({ active = true, color }) {
  const [t, setT] = React.useState(0);
  React.useEffect(() => {
    if (!active) return;
    const i = setInterval(() => setT(v => v + 1), 140);
    return () => clearInterval(i);
  }, [active]);
  const heights = [
    [5, 9, 4, 7], [8, 4, 9, 5], [4, 8, 6, 9], [7, 5, 8, 4],
  ][t % 4];
  return (
    <div style={{ display: 'flex', gap: 2, alignItems: 'flex-end', height: 10 }}>
      {heights.map((h, i) => (
        <div key={i} style={{
          width: 2, height: h, background: color || 'var(--accent)',
          borderRadius: 1, transition: 'height 140ms ease-out',
          opacity: active ? 1 : 0.35,
        }} />
      ))}
    </div>
  );
}

Object.assign(window, { GradientArt, Icons, Annot, AnnotBox, GlassSurface, EqTicks });
