// ONOGolf — reusable bits (archetype sigils, icons, topo visual)

const { useState, useEffect, useRef } = React;

// ------------ Brand mark ------------
function BrandMark() {
  return (
    <a className="brand" href="#">
      <span className="brand-mark">O</span>
      <span>ONOGolf</span>
    </a>
  );
}

// ------------ Small icon set (stroke only, no detail sloppiness) ------------
const Icon = {
  arrow: (props) => (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none" {...props}>
      <path d="M3 8h10M9 4l4 4-4 4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  flag: (props) => (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none" {...props}>
      <path d="M4 14V2M4 3h7l-1.5 2L11 7H4" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  dollar: (props) => (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none" {...props}>
      <path d="M8 2v12M11 5H6.5a2 2 0 0 0 0 4H10a2 2 0 0 1 0 4H4" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/>
    </svg>
  ),
  globe: (props) => (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none" {...props}>
      <circle cx="8" cy="8" r="6" stroke="currentColor" strokeWidth="1.3"/>
      <path d="M2 8h12M8 2c2 2 2 10 0 12M8 2c-2 2-2 10 0 12" stroke="currentColor" strokeWidth="1.3"/>
    </svg>
  ),
  trophy: (props) => (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none" {...props}>
      <path d="M4 2h8v4a4 4 0 0 1-8 0V2zM4 4H2v1a2 2 0 0 0 2 2M12 4h2v1a2 2 0 0 1-2 2M6 14h4M8 10v4" stroke="currentColor" strokeWidth="1.3" strokeLinejoin="round"/>
    </svg>
  ),
};

// ------------ Hero visual: real course photograph + editorial overlay ------------
function HeroVisual() {
  return (
    <div className="hero-visual">
      {/* Background photo with subtle tonal grade */}
      <div className="hero-photo"/>
      <div className="hero-photo-grade"/>

      {/* Editorial caption corner */}
      <div className="hero-photo-caption">
        <div className="label-mono" style={{fontSize: 10, color: "rgba(255,255,255,0.75)"}}>Est. 2026 · Plate 01</div>
        <div style={{fontFamily:"Playfair Display", fontStyle:"italic", fontWeight: 400, fontSize: 15, color:"white", lineHeight: 1.3, marginTop: 4, maxWidth: 200}}>
          "The fairway, photographed <br/>somewhere in October."
        </div>
      </div>

      {/* Floating: current phase card */}
      <div className="hero-float hero-float-tr">
        <div className="label-mono" style={{fontSize: 10}}>Currently charted</div>
        <div style={{fontFamily: "Playfair Display", fontWeight: 700, fontSize: 30, lineHeight: 1, marginTop: 6, letterSpacing: "-0.02em"}}>
          Phase <span style={{color: "rgb(var(--accent))"}}>IV</span>
        </div>
        <div style={{fontSize: 11, color: "rgb(var(--fg-muted))", marginTop: 6}}>
          The Grind · GHIN 14.2
        </div>
        <div style={{display:"flex", gap: 2, marginTop: 10}}>
          {[1,2,3,4,5,6,7,8].map(i => (
            <div key={i} style={{flex: 1, height: 4, borderRadius: 2, background: i<=4 ? "rgb(var(--accent))" : "rgb(var(--border))"}}/>
          ))}
        </div>
      </div>

      {/* Floating: archetype card */}
      <div className="hero-float hero-float-bl">
        <div style={{display:"flex", gap: 10, alignItems:"center"}}>
          <div style={{width: 34, height: 34, borderRadius: 999, background: "rgb(var(--accent))", display:"grid", placeItems:"center", color: "white", fontFamily: "Playfair Display", fontSize: 15, fontWeight: 700}}>M</div>
          <div>
            <div style={{fontSize: 10, color: "rgb(var(--fg-muted))", letterSpacing:"0.08em", textTransform:"uppercase"}}>Your archetype</div>
            <div style={{fontFamily:"Playfair Display", fontWeight: 700, fontSize: 16, lineHeight: 1.1, letterSpacing:"-0.01em"}}>The Metronome</div>
          </div>
        </div>
        <div style={{display:"grid", gridTemplateColumns:"repeat(3, 1fr)", gap: 10, marginTop: 12, paddingTop: 10, borderTop: "1px solid rgb(var(--border))"}}>
          <div>
            <div style={{fontSize: 9, color: "rgb(var(--fg-muted))", letterSpacing:"0.08em", textTransform:"uppercase"}}>Tempo</div>
            <div style={{fontFamily:"JetBrains Mono", fontSize: 11, fontWeight: 600, marginTop: 2}}>3:1 even</div>
          </div>
          <div>
            <div style={{fontSize: 9, color: "rgb(var(--fg-muted))", letterSpacing:"0.08em", textTransform:"uppercase"}}>AoA</div>
            <div style={{fontFamily:"JetBrains Mono", fontSize: 11, fontWeight: 600, marginTop: 2}}>−2.1°</div>
          </div>
          <div>
            <div style={{fontSize: 9, color: "rgb(var(--fg-muted))", letterSpacing:"0.08em", textTransform:"uppercase"}}>Shape</div>
            <div style={{fontFamily:"JetBrains Mono", fontSize: 11, fontWeight: 600, marginTop: 2}}>Straight</div>
          </div>
        </div>
      </div>

      {/* Corner ornaments */}
      <div className="hero-corner hero-corner-tl"/>
      <div className="hero-corner hero-corner-br"/>
    </div>
  );
}

// ------------ Archetype sigils: abstract swing-arc glyphs ------------
function Sigil({ kind = "young" }) {
  // Each sigil is a stylized swing arc + a secondary motif, drawn in brand colors
  const sigils = {
    young: (
      <>
        <circle cx="60" cy="60" r="54" fill="none" stroke="rgb(196,112,58)" strokeWidth="0.8" opacity="0.3"/>
        <path d="M 20 90 Q 40 30, 100 70" fill="none" stroke="rgb(196,112,58)" strokeWidth="3" strokeLinecap="round"/>
        <circle cx="100" cy="70" r="4" fill="rgb(26,26,24)"/>
        <path d="M 20 90 L 16 95 L 24 95 Z" fill="rgb(196,112,58)"/>
        <text x="60" y="112" fontFamily="JetBrains Mono" fontSize="7" textAnchor="middle" fill="rgb(107,107,100)" letterSpacing="1.5">AGG · STEEP</text>
      </>
    ),
    metronome: (
      <>
        <circle cx="60" cy="60" r="54" fill="none" stroke="rgb(92,107,58)" strokeWidth="0.8" opacity="0.3"/>
        <path d="M 30 100 L 60 20 L 90 100" fill="none" stroke="rgb(92,107,58)" strokeWidth="2.5" strokeLinecap="round"/>
        <circle cx="60" cy="60" r="3" fill="rgb(92,107,58)"/>
        <line x1="60" y1="20" x2="60" y2="100" stroke="rgb(92,107,58)" strokeWidth="0.6" strokeDasharray="2 3" opacity="0.5"/>
        <text x="60" y="112" fontFamily="JetBrains Mono" fontSize="7" textAnchor="middle" fill="rgb(107,107,100)" letterSpacing="1.5">TEMPO · 3:1</text>
      </>
    ),
    fader: (
      <>
        <circle cx="60" cy="60" r="54" fill="none" stroke="rgb(191,154,56)" strokeWidth="0.8" opacity="0.3"/>
        <path d="M 25 85 Q 55 95, 75 60 T 100 30" fill="none" stroke="rgb(191,154,56)" strokeWidth="2.5" strokeLinecap="round"/>
        <circle cx="100" cy="30" r="3" fill="rgb(26,26,24)"/>
        <path d="M 25 85 L 21 82 L 25 80 Z M 25 85 L 29 82 L 25 80 Z" fill="rgb(191,154,56)"/>
        <text x="60" y="112" fontFamily="JetBrains Mono" fontSize="7" textAnchor="middle" fill="rgb(107,107,100)" letterSpacing="1.5">POWER · FADE</text>
      </>
    ),
    antihook: (
      <>
        <circle cx="60" cy="60" r="54" fill="none" stroke="rgb(160,64,64)" strokeWidth="0.8" opacity="0.3"/>
        <rect x="52" y="18" width="16" height="84" fill="none" stroke="rgb(160,64,64)" strokeWidth="1" strokeDasharray="3 3"/>
        <path d="M 40 90 Q 60 50, 92 40" fill="none" stroke="rgb(160,64,64)" strokeWidth="2.5" strokeLinecap="round"/>
        <circle cx="92" cy="40" r="3" fill="rgb(26,26,24)"/>
        <text x="60" y="112" fontFamily="JetBrains Mono" fontSize="7" textAnchor="middle" fill="rgb(107,107,100)" letterSpacing="1.5">SQUARE · CAGED</text>
      </>
    ),
    rising: (
      <>
        <circle cx="60" cy="60" r="54" fill="none" stroke="rgb(58,107,122)" strokeWidth="0.8" opacity="0.3"/>
        <path d="M 25 90 Q 50 40, 95 45" fill="none" stroke="rgb(58,107,122)" strokeWidth="2" strokeLinecap="round" opacity="0.6"/>
        <path d="M 25 90 Q 60 30, 95 45" fill="none" stroke="rgb(58,107,122)" strokeWidth="2.5" strokeLinecap="round"/>
        <circle cx="95" cy="45" r="3" fill="rgb(26,26,24)"/>
        {/* Rising stars */}
        <path d="M 30 30 L 31 33 L 34 33 L 32 35 L 33 38 L 30 36 L 27 38 L 28 35 L 26 33 L 29 33 Z" fill="rgb(58,107,122)" opacity="0.5"/>
        <text x="60" y="112" fontFamily="JetBrains Mono" fontSize="7" textAnchor="middle" fill="rgb(107,107,100)" letterSpacing="1.5">TWO-WAY · COACHED</text>
      </>
    ),
  };
  return (
    <svg viewBox="0 0 120 120" width="100%" height="100%" style={{maxHeight: 160}}>
      {sigils[kind]}
    </svg>
  );
}

Object.assign(window, { BrandMark, Icon, HeroVisual, Sigil });
