// ONOGolf — main sections

const { useState: useState2, useEffect: useEffect2 } = React;

// ========== NAV ==========
function OnoWordmark() {
  return (
    <a className="ono-wordmark" href="ONOGolf Landing Page.html" aria-label="ONO Golf">
      <svg viewBox="0 0 100 60" width="68" height="42" aria-hidden="true">
        <text x="0" y="28" fontFamily="Playfair Display, serif" fontWeight="800" fontSize="28" fill="rgb(92,107,58)" letterSpacing="-1">ON</text>
        <circle cx="78" cy="20" r="9" fill="none" stroke="rgb(92,107,58)" strokeWidth="2.4"/>
        <circle cx="76" cy="18" r="1.2" fill="rgb(92,107,58)"/>
        <circle cx="80" cy="18" r="1.2" fill="rgb(92,107,58)"/>
        <circle cx="78" cy="22" r="1.2" fill="rgb(92,107,58)"/>
        <text x="14" y="54" fontFamily="Playfair Display, serif" fontWeight="700" fontSize="20" fill="rgb(92,107,58)" letterSpacing="4">GOLF</text>
      </svg>
    </a>
  );
}

// Nav dropdown groups (Decision 18)
const NAV_FLAT_LEFT = [
  { id: "home",        label: "Home",        href: "ONOGolf Landing Page.html" },
  { id: "globalgolf",  label: "Golf Trend Tracker", href: "ONOGolf Global Golf.html" },
];
const NAV_VIDEO_ROOM = {
  id: "videoroom",
  label: "Video Room",
  children: [
    { id: "lessons",      label: "Lessons",               href: "ONOGolf Lessons.html" },
    { id: "tournament",   label: "Tournament Highlights",  href: "ONOGolf Tournament.html" },
    { id: "influencers",  label: "Influencers",            href: "ONOGolf Influencers.html" },
  ],
};
const NAV_SWING = {
  id: "swing",
  label: "Swing",
  children: [
    { id: "biomechanics", label: "Swing Biomechanics", href: "ONOGolf Swing Analyzer.html" },
    { id: "analysis",     label: "Swing Analysis",     href: "ONOGolf Golf Analyzer.html" },
    { id: "swingvswing",  label: "Swing vs Swing",     href: "ONOGolf Swing Vs Swing.html" },
  ],
};
const NAV_TOURNAMENT_TRACK = {
  id: "tournamenttrack",
  label: "Tournament Track",
  children: [
    { id: "tournaments-map", label: "Tournaments Map", href: "ONOGolf Tournaments Map.html" },
    { id: "protour-map",     label: "Pro Tour Map",    href: "ONOGolf Pro Tour Map.html" },
  ],
};
const NAV_FLAT_RIGHT = [
  { id: "journey",   label: "My Journey", href: "ONOGolf My Journey.html" },
  { id: "coaches",   label: "Coaches",    href: "ONOGolf Coaches.html" },
  { id: "scorecard", label: "Scorecard",  href: "ONOGolf Scorecard.html" },
  { id: "pricing",   label: "Pricing",    href: "ONOGolf Pricing.html" },
];

// All child IDs for active-parent detection
const VIDEO_ROOM_IDS = new Set(NAV_VIDEO_ROOM.children.map(c => c.id));
const SWING_IDS      = new Set(NAV_SWING.children.map(c => c.id));
const TOURNAMENT_IDS = new Set(NAV_TOURNAMENT_TRACK.children.map(c => c.id));

function NavDropdown({ group, page, closeAll }) {
  const [open, setOpen] = useState2(false);
  const ref = React.useRef(null);

  const isActive = group.children.some(c => c.id === page);

  // Close on outside click
  useEffect2(() => {
    if (!open) return;
    function handler(e) {
      if (ref.current && !ref.current.contains(e.target)) setOpen(false);
    }
    document.addEventListener('mousedown', handler);
    return () => document.removeEventListener('mousedown', handler);
  }, [open]);

  // Close when another dropdown opens
  useEffect2(() => {
    if (!open) return;
    function handler(e) {
      if (e.detail && e.detail.id !== group.id) setOpen(false);
    }
    document.addEventListener('ono-nav-open', handler);
    return () => document.removeEventListener('ono-nav-open', handler);
  }, [open, group.id]);

  function toggle() {
    if (!open) {
      document.dispatchEvent(new CustomEvent('ono-nav-open', { detail: { id: group.id } }));
    }
    setOpen(o => !o);
  }

  // Keyboard: close on Escape
  function onKeyDown(e) {
    if (e.key === 'Escape') setOpen(false);
    if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggle(); }
  }

  return (
    <div className={`ono-nav-dropdown${isActive ? ' active' : ''}`} ref={ref} style={{position:'relative'}}>
      <button
        className={`ono-nav-dropdown-btn${isActive ? ' active' : ''}`}
        aria-haspopup="true"
        aria-expanded={open}
        onClick={toggle}
        onKeyDown={onKeyDown}
      >
        {group.label}
        <svg width="11" height="11" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true"
          style={{marginLeft:4, transition:'transform .15s', transform: open ? 'rotate(180deg)' : 'rotate(0deg)'}}>
          <path d="M2 4l4 4 4-4"/>
        </svg>
      </button>
      {open && (
        <div className="ono-nav-dropdown-panel" role="menu">
          {group.children.map(c => (
            <a
              key={c.id}
              href={c.href}
              role="menuitem"
              className={page === c.id ? 'active' : ''}
              aria-current={page === c.id ? 'page' : undefined}
              onClick={() => setOpen(false)}
            >
              {c.label}
            </a>
          ))}
        </div>
      )}
    </div>
  );
}

function Nav({ lang, L, page = "home", signedIn = false }) {
  const [menuOpen, setMenuOpen] = useState2(false);

  // All items flat for mobile menu
  const allMobileItems = [
    ...NAV_FLAT_LEFT,
    ...NAV_VIDEO_ROOM.children,
    ...NAV_SWING.children,
    ...NAV_TOURNAMENT_TRACK.children,
    ...NAV_FLAT_RIGHT,
  ];

  useEffect2(() => {
    document.body.classList.toggle("menu-open", menuOpen);
    return () => document.body.classList.remove("menu-open");
  }, [menuOpen]);

  return (
    <nav className="ono-nav" aria-label="Primary">
      <div className="ono-nav-inner">
        <a className="ono-wordmark" href="ONOGolf Landing Page.html" aria-label="ONO Golf">
          <img src="./assets/ono-golf-logo-blkwht.svg" alt="ONO Golf" style={{height: 40, width: "auto", display: "block"}}/>
        </a>
        <div className="ono-nav-links">
          {/* Flat left: Home */}
          {NAV_FLAT_LEFT.map(l => (
            <a key={l.id} href={l.href} className={page===l.id ? "active" : ""} aria-current={page===l.id ? "page" : undefined}>{l.label}</a>
          ))}
          {/* Video Room dropdown */}
          <NavDropdown group={NAV_VIDEO_ROOM} page={page} />
          {/* Swing dropdown */}
          <NavDropdown group={NAV_SWING} page={page} />
          {/* Tournament Track dropdown */}
          <NavDropdown group={NAV_TOURNAMENT_TRACK} page={page} />
          {/* Flat right: My Journey · Coaches · Scorecard · Pricing */}
          {NAV_FLAT_RIGHT.map(l => (
            <a key={l.id} href={l.href} className={page===l.id ? "active" : ""} aria-current={page===l.id ? "page" : undefined}>{l.label}</a>
          ))}
        </div>
        <div className="ono-nav-right">
          {signedIn ? (
            <>
              <button className="ono-icon-btn" aria-label="Notifications">
                <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" aria-hidden="true"><path d="M6 8a6 6 0 1112 0c0 7 3 9 3 9H3s3-2 3-9z"/><path d="M10 21a2 2 0 004 0"/></svg>
                <span className="ono-dot"></span>
              </button>
              <div className="ono-avatar" aria-label="Profile">A</div>
            </>
          ) : (
            <>
              <span className="ono-lang-toggle">{lang.toUpperCase()}</span>
              <a className="ono-btn-ghost" href="ONOGolf Onboarding.html">Sign In</a>
              <a className="ono-btn-primary" href="ONOGolf Onboarding.html">Get Started <span className="arr">→</span></a>
            </>
          )}
          <button
            className="ono-mobile-toggle"
            aria-label={menuOpen ? "Close menu" : "Open menu"}
            aria-expanded={menuOpen}
            aria-controls="ono-mobile-menu"
            onClick={() => setMenuOpen(o => !o)}
          >
            {menuOpen ? (
              <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>
            ) : (
              <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"/></svg>
            )}
          </button>
        </div>
      </div>
      {/* Mobile menu — flat list of all items with group labels */}
      <div id="ono-mobile-menu" className={`ono-mobile-menu ${menuOpen ? "open" : ""}`} aria-hidden={!menuOpen}>
        {NAV_FLAT_LEFT.map(l => (
          <a key={l.id} href={l.href} className={page===l.id ? "active" : ""} aria-current={page===l.id ? "page" : undefined}>{l.label}</a>
        ))}
        <span className="ono-mobile-group-label">Video Room</span>
        {NAV_VIDEO_ROOM.children.map(l => (
          <a key={l.id} href={l.href} className={page===l.id ? "active" : ""} aria-current={page===l.id ? "page" : undefined}>{l.label}</a>
        ))}
        <span className="ono-mobile-group-label">Swing</span>
        {NAV_SWING.children.map(l => (
          <a key={l.id} href={l.href} className={page===l.id ? "active" : ""} aria-current={page===l.id ? "page" : undefined}>{l.label}</a>
        ))}
        <span className="ono-mobile-group-label">Tournament Track</span>
        {NAV_TOURNAMENT_TRACK.children.map(l => (
          <a key={l.id} href={l.href} className={page===l.id ? "active" : ""} aria-current={page===l.id ? "page" : undefined}>{l.label}</a>
        ))}
        {NAV_FLAT_RIGHT.map(l => (
          <a key={l.id} href={l.href} className={page===l.id ? "active" : ""} aria-current={page===l.id ? "page" : undefined}>{l.label}</a>
        ))}
        {!signedIn && (
          <div className="ono-mobile-menu-cta">
            <a href="ONOGolf Onboarding.html">Sign In</a>
            <a href="ONOGolf Onboarding.html" className="primary">Get Started →</a>
          </div>
        )}
      </div>
    </nav>
  );
}

// ========== HERO (full-bleed photo header) ==========
function Hero({ lang, L }) {
  return (
    <section className="hero-full" id="top">
      <div className="hero-full-photo"/>
      <div className="hero-full-grade"/>

      {/* Top editorial strip */}
      <div className="hero-full-topstrip wrap wrap-wide">
        <div className="label-mono" style={{color:"rgba(255,255,255,0.8)"}}>Est. 2026 · Plate 01</div>
        <div className="label-mono" style={{color:"rgba(255,255,255,0.8)"}}>The Green-to-Gold Roadmap</div>
        <div className="label-mono" style={{color:"rgba(255,255,255,0.8)"}}>N° I / VIII</div>
      </div>

      {/* Center caption */}
      <div className="hero-full-inner wrap wrap-wide">
        <img src="./assets/ono-logo2.png" alt="ONOGolf" className="hero-full-logo"/>
        <div className="eyebrow" style={{color:"rgb(var(--gold))"}}>{L.heroEyebrow}</div>
        <h1 className="hero-full-title">
          {lang === "en" ? (
            <>From the <span className="italic-ink-white">first</span> swing<br/>to the <span className="word-gold">summit</span>.</>
          ) : (
            <>Del <span className="italic-ink-white">primer</span> swing<br/>a la <span className="word-gold">cumbre</span>.</>
          )}
        </h1>
        <p className="hero-full-lede">{L.heroLead}</p>
        <div style={{display:"flex", gap: 12, marginTop: 40, flexWrap: "wrap", justifyContent:"flex-start"}}>
          <a className="btn btn-xl" href="ONOGolf Onboarding.html" style={{background:"rgb(var(--gold))", color:"rgb(var(--olive-deep))", borderColor:"rgb(var(--gold))"}}>{L.startCta} <Icon.arrow className="arrow"/></a>
          <a className="btn btn-xl" href="ONOGolf Swing Analyzer.html" style={{background:"rgba(255,255,255,0.08)", color:"white", borderColor:"rgba(255,255,255,0.35)", backdropFilter:"blur(8px)"}}>▸ {L.watchCta}</a>
        </div>
      </div>

      {/* Bottom metric band */}
      <div className="hero-full-bottom wrap wrap-wide">
        <div>
          <div className="hero-full-num">84<span style={{color:"rgb(var(--gold))"}}>K</span></div>
          <div className="hero-full-label">{L.heroMetric1}</div>
        </div>
        <div>
          <div className="hero-full-num">312</div>
          <div className="hero-full-label">{L.heroMetric2}</div>
        </div>
        <div>
          <div className="hero-full-num">47</div>
          <div className="hero-full-label">{L.heroMetric3}</div>
        </div>
      </div>

      {/* Corners */}
      <div className="hero-full-corner tl"/>
      <div className="hero-full-corner tr"/>
      <div className="hero-full-corner bl"/>
      <div className="hero-full-corner br"/>
    </section>
  );
}

// ========== TICKER ==========
function Ticker({ L }) {
  const items = [
    { dot: true, text: "AJGA Fall Classic · Austin", tag: "Phase V" },
    { dot: true, text: "Drive, Chip & Putt Regionals", tag: "Phase I–II" },
    { dot: true, text: "Korn Ferry · Knoxville Open", tag: "Phase VII" },
    { dot: true, text: "U.S. Kids World Championship", tag: "Phase II–III" },
    { dot: true, text: "PGA Tour · Genesis Invitational", tag: "Phase VIII" },
    { dot: true, text: "US Am Tour · Flight B Playoff", tag: "Phase IV" },
    { dot: true, text: "Society of Seniors · Pinehurst", tag: "55+" },
    { dot: true, text: "LIV Miami · Team Standings", tag: "Phase VIII" },
  ];
  const track = [...items, ...items];
  return (
    <div className="marquee-row">
      <div className="marquee-track">
        {track.map((it, i) => (
          <span key={i} className="marquee-item">
            <span className="dot"></span>
            {it.text}
            <span className="tag">{it.tag}</span>
          </span>
        ))}
      </div>
    </div>
  );
}

// ========== INSTRUCTORS — "Learn From the Best" ==========
function Instructors({ lang, L }) {
  const list = [
    { name: "Me & My Golf",     subs: "890K", hue: "olive",  initials: "MM" },
    { name: "Peter Finch",       subs: "765K", hue: "orange", initials: "PF" },
    { name: "Athletic Motion",   subs: "445K", hue: "sea",    initials: "AM" },
    { name: "Rick Shiels",       subs: "2.1M", hue: "gold",   initials: "RS" },
    { name: "Clay Ballard",      subs: "580K", hue: "wine",   initials: "CB" },
    { name: "Rotary Swing",      subs: "320K", hue: "navy",   initials: "RS" },
    { name: "Mark Crossfield",   subs: "710K", hue: "olive",  initials: "MC" },
    { name: "Scratch Golf",      subs: "1.2M", hue: "orange", initials: "SG" },
  ];
  const hues = {
    olive:  "rgb(92,107,58)",
    orange: "rgb(196,112,58)",
    sea:    "rgb(58,107,122)",
    gold:   "rgb(191,154,56)",
    wine:   "rgb(160,64,64)",
    navy:   "rgb(74,94,138)",
  };
  return (
    <section className="section section-tight" style={{background:"rgb(var(--bg-2))"}}>
      <div className="wrap wrap-wide">
        <div style={{textAlign:"center", maxWidth: 640, margin: "0 auto 48px"}}>
          <div className="eyebrow" style={{justifyContent:"center", display:"inline-flex"}}>
            {lang === "en" ? "Curated Creator Network" : "Red de Creadores Curados"}
          </div>
          <h2 className="display display-md" style={{marginTop: 18, marginBottom: 14}}>
            {lang === "en"
              ? <>Learn from the <span className="italic-ink">best</span>.</>
              : <>Aprende de los <span className="italic-ink">mejores</span>.</>}
          </h2>
          <p className="lede" style={{margin: "0 auto"}}>
            {lang === "en"
              ? "Over 400 hours of instruction from the world's top golf creators — indexed by phase, technique, and archetype."
              : "Más de 400 horas de instrucción de los mejores creadores de golf del mundo — indexadas por fase, técnica y arquetipo."}
          </p>
        </div>
        <div style={{display:"grid", gridTemplateColumns:"repeat(8, 1fr)", gap: 16}}>
          {list.map(i => (
            <div key={i.name} style={{display:"flex", flexDirection:"column", alignItems:"center", gap: 8, padding: "12px 4px", borderRadius: 12, cursor:"pointer", transition:"background 0.15s"}}
                 onMouseEnter={e=>e.currentTarget.style.background="rgb(var(--bg-3))"}
                 onMouseLeave={e=>e.currentTarget.style.background="transparent"}>
              <div style={{width: 64, height: 64, borderRadius: 999, background: hues[i.hue], display:"grid", placeItems:"center", color:"white", fontFamily:"Playfair Display", fontWeight:700, fontSize: 20, letterSpacing:"-0.02em", boxShadow:"inset 0 -10px 18px rgba(0,0,0,0.2)", border:"1px solid rgba(0,0,0,0.08)"}}>
                {i.initials}
              </div>
              <div style={{fontFamily:"Inter", fontSize: 12, color:"rgb(var(--fg))", fontWeight: 500, textAlign:"center", lineHeight: 1.2}}>{i.name}</div>
              <div style={{fontFamily:"JetBrains Mono", fontSize: 10, color:"rgb(var(--fg-muted))", letterSpacing:"0.04em"}}>{i.subs} subs</div>
            </div>
          ))}
        </div>
        <div style={{display:"flex", justifyContent:"center", marginTop: 40}}>
          <a className="btn btn-ghost" href="ONOGolf Lessons.html">
            {lang === "en" ? "Browse 400+ hours" : "Explorar 400+ horas"} <Icon.arrow className="arrow"/>
          </a>
        </div>
      </div>
    </section>
  );
}


// ========== TUTORIAL LIBRARY (DB-backed, with filters + ratings + embed) ==========

// Hardcoded seed/fallback array — shown when DB is empty
// Fallback cards use video_id:"" — a neutral non-playing value.
// The embed guard checks (t.video_id && ...) so "" is safely treated as no-embed.
const TUTORIAL_FALLBACK = [
  { video_id:"", title: "Perfect Iron Swing: 5 Steps to Solid Contact", channel_title: "Scratch Golf Academy", view_count: 284000, duration_seconds: 840, audience: "adults", video_type: "lesson", avg_rating: null, rating_count: 0, skills: [{category:"iron",slug:"ball_position",label:"Ball Position"}], thumbnail_url: null, channel_yt_id: null, channel_custom_url: null },
  { video_id:"", title: "Driver Swing Fundamentals for Distance",       channel_title: "Me & My Golf",         view_count: 412000, duration_seconds: 1080, audience: "adults", video_type: "lesson", avg_rating: null, rating_count: 0, skills: [{category:"driver",slug:"driver_tempo",label:"Driver Tempo"}], thumbnail_url: null, channel_yt_id: null, channel_custom_url: null },
  { video_id:"", title: "The Overlap Grip — Step by Step Guide",        channel_title: "Peter Finch Golf",     view_count: 156000, duration_seconds: 540, audience: "both",   video_type: "lesson", avg_rating: null, rating_count: 0, skills: [{category:"grip",slug:"grip",label:"Grip"}], thumbnail_url: null, channel_yt_id: null, channel_custom_url: null },
  { video_id:"", title: "One Plane vs Two Plane Swing Analysis",        channel_title: "Athletic Motion Golf", view_count: 98000, duration_seconds: 1320, audience: "adults", video_type: "lesson", avg_rating: null, rating_count: 0, skills: [{category:"swing_types",slug:"one_plane",label:"One-Plane Swing"}], thumbnail_url: null, channel_yt_id: null, channel_custom_url: null },
];

function fmtViews(n) {
  if (!n) return "0";
  if (n >= 1000000) return (n/1000000).toFixed(1) + "M";
  if (n >= 1000) return Math.round(n/1000) + "K";
  return String(n);
}

function fmtDur(secs) {
  if (!secs) return "";
  const m = Math.floor(secs / 60);
  const s = secs % 60;
  return m + ":" + String(s).padStart(2, "0");
}

function StarRating({ avg, count, videoId, onRated }) {
  const [hovered, setHovered] = useState2(0);
  const [submitting, setSubmitting] = useState2(false);
  const display = hovered || Math.round(avg || 0);

  const rate = async (stars) => {
    if (submitting) return;
    setSubmitting(true);
    try {
      const r = await fetch("/api/videos/" + videoId + "/rate", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ stars }),
      });
      const d = await r.json();
      if (d.ok && onRated) onRated(d.avg_rating, d.rating_count);
    } catch(_) {}
    setSubmitting(false);
  };

  return (
    <div style={{display:"flex", alignItems:"center", gap: 4}}>
      {[1,2,3,4,5].map(n => (
        <span key={n}
          onMouseEnter={()=>setHovered(n)}
          onMouseLeave={()=>setHovered(0)}
          onClick={()=>rate(n)}
          style={{
            cursor:"pointer", fontSize: 14,
            color: n <= display ? "rgb(191,154,56)" : "rgb(var(--border-2,214,212,202))",
            lineHeight: 1,
          }}>★</span>
      ))}
      {count > 0 && (
        <span style={{fontFamily:"Inter", fontSize: 10, color:"rgb(var(--fg-muted))", marginLeft: 2}}>
          {avg ? avg.toFixed(1) : "—"} ({count})
        </span>
      )}
    </div>
  );
}

// Category slug → display label map (mirrors seed taxonomy categories)
const CATEGORY_LABELS = {
  all:        "All",
  full_swing: "Full Swing",
  iron:       "Iron Swing",
  driver:     "Driver",
  grip:       "Grip",
  swing_types:"Swing Types",
  putting:    "Putting",
  short_game: "Short Game",
};

// Phase 1.5 — 5 video types matching server VALID_VIDEO_TYPES
const VIDEO_TYPE_LABELS = {
  all:        "All Types",
  lesson:     "Lesson",
  highlight:  "Highlight",
  round_play: "Round Play",
  tournament: "Tournament",
  drill:      "Drill",
};

function TutorialLibrary({ lang, L }) {
  const [videos, setVideos]       = useState2(null); // null = loading
  const [audience, setAudience]   = useState2("all");
  const [category, setCategory]   = useState2("all");
  const [vtype, setVtype]         = useState2("all");
  const [activeEmbed, setActiveEmbed] = useState2(null); // video_id being played
  const [ratings, setRatings]     = useState2({}); // { [id]: {avg, count} }
  const [catList, setCatList]     = useState2([]); // skill-tag categories (dynamic pills)

  // Load the live category list once — any category added in admin Skill Tags shows up here.
  useEffect2(() => {
    fetch("/api/skill-categories")
      .then(r => r.json())
      .then(d => { if (d.ok) setCatList(d.categories || []); })
      .catch(() => {});
  }, []);

  useEffect2(() => {
    const params = new URLSearchParams();
    if (audience !== "all") params.set("audience", audience);
    if (category === "coaches") params.set("source", "coaches");   // videos from coach channels
    else if (category !== "all") params.set("category", category);
    if (vtype    !== "all") params.set("type", vtype);
    fetch("/api/library?" + params.toString())
      .then(r => r.json())
      .then(d => {
        if (d.ok) {
          // Always set the real array — never collapse [] into null.
          // null is reserved for "loading / error" only.
          setVideos(d.videos);
        }
      })
      .catch(() => setVideos(null));
  }, [audience, category, vtype]);

  // Three distinct display states:
  //   videos === null  → still loading or fetch error  → show fallback + "loading" label
  //   videos.length === 0 → loaded, zero results for filter → show empty-state message
  //   videos.length > 0   → real data
  const isFallback    = videos === null;
  const isEmpty       = videos !== null && videos.length === 0;
  const displayVideos = isFallback ? TUTORIAL_FALLBACK : (isEmpty ? [] : videos);

  const handleRated = (id, avg, count) => {
    setRatings(r => ({ ...r, [id]: { avg, count } }));
  };

  // Pills built from the live taxonomy: "All" + every category in use (known ones get a
  // friendly label, custom ones are title-cased). Falls back to the known 7 before load.
  const labelForCat = (c) => CATEGORY_LABELS[c] || c.replace(/_/g, " ").replace(/\b\w/g, m => m.toUpperCase());
  const categoryKeys = ["all", "coaches", ...(catList.length ? catList : ["full_swing","iron","driver","grip","swing_types","putting","short_game"])];
  const vtypeKeys    = Object.keys(VIDEO_TYPE_LABELS);

  return (
    <section className="section section-tight" id="tutorials" style={{background:"rgb(var(--bg-2))"}}>
      <div className="wrap wrap-wide">

        {/* Header row */}
        <div style={{display:"flex", justifyContent:"space-between", alignItems:"flex-end", marginBottom: 24, flexWrap:"wrap", gap: 20}}>
          <div>
            <h2 className="display display-md" style={{margin: 0}}>
              {lang === "en" ? "Golf TV — Lessons & More" : "Golf TV — Lecciones y Más"}
            </h2>
            <div className="label-mono" style={{marginTop: 6, fontSize: 11, textTransform:"none", letterSpacing:"0.02em"}}>
              {isFallback
                ? (lang==="en" ? "Loading Golf TV library…" : "Cargando biblioteca de Golf TV…")
                : isEmpty
                  ? (lang==="en" ? "No videos match these filters yet" : "Ningún video coincide con estos filtros aún")
                  : displayVideos.length + " " + (lang==="en" ? "videos available" : "videos disponibles")}
            </div>
          </div>
        </div>

        {/* Audience toggle */}
        <div style={{display:"flex", gap: 8, marginBottom: 12, flexWrap:"wrap", alignItems:"center"}}>
          <span style={{fontFamily:"Inter", fontSize: 11, color:"rgb(var(--fg-muted))", fontWeight: 500, marginRight: 4}}>
            {lang==="en" ? "Audience:" : "Audiencia:"}
          </span>
          {["all","adults","juniors"].map(a => (
            <button key={a}
              onClick={()=>setAudience(a)}
              style={{
                padding: "6px 14px", borderRadius: 999,
                border: "1px solid " + (audience===a ? "rgb(var(--accent,92,107,58))" : "rgb(var(--border))"),
                background: audience===a ? "rgb(var(--accent,92,107,58))" : "rgb(var(--bg-3))",
                color: audience===a ? "white" : "rgb(var(--fg))",
                fontFamily:"Inter", fontSize: 12, fontWeight: 500,
                cursor:"pointer", transition:"all 0.15s",
              }}>
              {a === "all" ? (lang==="en"?"All":"Todos") : a === "adults" ? (lang==="en"?"Adults":"Adultos") : (lang==="en"?"Juniors":"Juniors")}
            </button>
          ))}
        </div>

        {/* Video type pills */}
        <div style={{display:"flex", gap: 8, marginBottom: 12, flexWrap:"wrap", alignItems:"center"}}>
          <span style={{fontFamily:"Inter", fontSize: 11, color:"rgb(var(--fg-muted))", fontWeight: 500, marginRight: 4}}>
            {lang==="en" ? "Type:" : "Tipo:"}
          </span>
          {vtypeKeys.map(k => (
            <button key={k}
              onClick={()=>setVtype(k)}
              style={{
                padding: "6px 14px", borderRadius: 999,
                border: "1px solid " + (vtype===k ? "rgb(191,154,56)" : "rgb(var(--border))"),
                background: vtype===k ? "rgb(191,154,56)" : "rgb(var(--bg-3))",
                color: vtype===k ? "white" : "rgb(var(--fg))",
                fontFamily:"Inter", fontSize: 12, fontWeight: 500,
                cursor:"pointer", transition:"all 0.15s",
              }}>{VIDEO_TYPE_LABELS[k]}</button>
          ))}
        </div>

        {/* Category (skill) filter pills */}
        <div style={{display:"flex", gap: 8, marginBottom: 32, flexWrap:"wrap"}}>
          {categoryKeys.map(k => (
            <button key={k} onClick={()=>setCategory(k)}
              style={{
                padding: "7px 16px", borderRadius: 999,
                border: "1px solid " + (category===k ? "rgb(var(--accent,92,107,58))" : "rgb(var(--border))"),
                background: category===k ? "rgb(var(--accent,92,107,58))" : "rgb(var(--bg-3))",
                color: category===k ? "white" : "rgb(var(--fg))",
                fontFamily:"Inter", fontSize: 12, fontWeight: 500,
                cursor:"pointer", transition:"all 0.15s",
              }}>{labelForCat(k)}</button>
          ))}
        </div>

        {/* Tutorial grid — empty state */}
        {isEmpty && (
          <div style={{gridColumn:"1/-1", textAlign:"center", padding:"60px 0", color:"rgb(var(--fg-muted))", fontFamily:"Inter", fontSize:14}}>
            {lang==="en" ? "No tutorials match these filters yet." : "Ningún tutorial coincide con estos filtros aún."}
          </div>
        )}

        {/* Tutorial grid */}
        {!isEmpty && (
        <div style={{display:"grid", gridTemplateColumns:"repeat(4, 1fr)", gap: 20}}>
          {displayVideos.map((t, i) => {
            // Use video_id as the stable React/state key (always unique); fall back to index only for fallback items.
            const stateKey = t.video_id || i;
            // DB PK (t.id) is used only for the rate API URL.
            const ratePk   = t.id;
            const r = ratings[stateKey] || { avg: t.avg_rating, count: t.rating_count || 0 };
            const thumbUrl = t.thumbnail_url || (t.video_id && t.video_id !== "dQw4w9WgXcQ"
              ? "https://i.ytimg.com/vi/" + t.video_id + "/hqdefault.jpg"
              : null);
            const isPlaying = activeEmbed === t.video_id && t.video_id !== "dQw4w9WgXcQ";
            const ytUrl = t.channel_custom_url
              ? "https://youtube.com/" + t.channel_custom_url
              : t.channel_yt_id
                ? "https://youtube.com/channel/" + t.channel_yt_id
                : null;

            return (
              <div key={stateKey} className="tut-card" style={{cursor:"default"}}>
                {/* Thumbnail / embed */}
                <div className="tut-thumb" style={{background:"#0f0f0f", cursor: "pointer"}}
                  onClick={()=>{
                    if (t.video_id && t.video_id !== "dQw4w9WgXcQ") {
                      setActiveEmbed(isPlaying ? null : t.video_id);
                    }
                  }}>
                  {isPlaying ? (
                    <iframe
                      src={"https://www.youtube.com/embed/" + t.video_id + "?autoplay=1&rel=0"}
                      frameBorder="0"
                      allow="autoplay; encrypted-media; fullscreen"
                      style={{position:"absolute", inset:0, width:"100%", height:"100%"}}
                      title={t.title}
                    />
                  ) : thumbUrl ? (
                    <>
                      <img src={thumbUrl} alt={t.title}
                        style={{position:"absolute", inset:0, width:"100%", height:"100%", objectFit:"cover"}}/>
                      {/* Play overlay */}
                      <div style={{position:"absolute", inset:0, display:"grid", placeItems:"center", background:"rgba(0,0,0,0.2)"}}>
                        <div style={{width:62, height:44, background:"rgba(0,0,0,0.7)", border:"1px solid rgba(255,255,255,0.2)", borderRadius:12, display:"grid", placeItems:"center"}}>
                          <svg width="22" height="22" viewBox="0 0 24 24" fill="white"><path d="M8 5v14l11-7z"/></svg>
                        </div>
                      </div>
                    </>
                  ) : (
                    <YouTubeThumb title={t.title} channel={t.channel_title || ""} hue="rgb(92,107,58)"/>
                  )}
                  {t.duration_seconds > 0 && (
                    <div className="tut-dur">{fmtDur(t.duration_seconds)}</div>
                  )}
                </div>

                {/* Card body */}
                <div className="tut-body">
                  {/* Video type badge + views */}
                  <div style={{display:"flex", justifyContent:"space-between", alignItems:"center", marginBottom: 8}}>
                    {t.video_type && (() => {
                      // Color map for 5 video types
                      const VT_BG = {
                        lesson:     "rgb(238,241,232)", // olive tint
                        highlight:  "rgb(255,245,220)", // amber tint
                        round_play: "rgb(228,235,248)", // blue tint
                        tournament: "rgb(250,228,228)", // red tint
                        drill:      "rgb(235,228,250)", // purple tint
                      };
                      const VT_FG = {
                        lesson:     "rgb(92,107,58)",
                        highlight:  "rgb(160,100,0)",
                        round_play: "rgb(40,80,160)",
                        tournament: "rgb(160,40,40)",
                        drill:      "rgb(80,40,160)",
                      };
                      return (
                        <span className="tut-level" style={{
                          background: VT_BG[t.video_type] || "rgb(238,241,232)",
                          color:      VT_FG[t.video_type] || "rgb(92,107,58)",
                          textTransform:"uppercase", fontSize: 9,
                        }}>
                          {VIDEO_TYPE_LABELS[t.video_type] || t.video_type}
                        </span>
                      );
                    })()}
                    <span style={{fontFamily:"Inter", fontSize: 11, color: "rgb(var(--fg-muted))"}}>{fmtViews(t.view_count)} {lang==="en"?"views":"vistas"}</span>
                  </div>

                  {/* Title */}
                  <div style={{fontFamily: "Inter", fontWeight: 600, fontSize: 14, lineHeight: 1.35, color:"rgb(var(--fg))", marginBottom: 8, minHeight: 38, display:"-webkit-box", WebkitLineClamp:2, WebkitBoxOrient:"vertical", overflow:"hidden"}}>
                    {t.title}
                  </div>

                  {/* Skill tags */}
                  {t.skills && t.skills.length > 0 && (
                    <div style={{display:"flex", gap: 4, flexWrap:"wrap", marginBottom: 8}}>
                      {t.skills.slice(0, 3).map(sk => (
                        <span key={sk.slug} style={{
                          display:"inline-block", padding:"2px 7px", borderRadius: 999, fontSize: 9,
                          fontFamily:"Inter", fontWeight: 500,
                          background:"rgba(92,107,58,0.08)", border:"1px solid rgba(92,107,58,0.18)",
                          color:"rgb(92,107,58)",
                        }}>{sk.label}</span>
                      ))}
                    </div>
                  )}

                  {/* Star rating — videoId is the DB PK for /api/videos/:id/rate;
                       onRated updates the ratings map keyed by stateKey (video_id) */}
                  {!isFallback && (
                    <div style={{marginBottom: 8}}>
                      <StarRating
                        avg={r.avg}
                        count={r.count}
                        videoId={ratePk}
                        onRated={(avg, count) => handleRated(stateKey, avg, count)}
                      />
                    </div>
                  )}

                  {/* Channel info + follow */}
                  <div style={{display:"flex", alignItems:"center", gap: 8, paddingTop: 8, borderTop: "1px solid rgb(var(--border))", justifyContent:"space-between"}}>
                    <div style={{display:"flex", alignItems:"center", gap: 6, minWidth:0}}>
                      {t.channel_avatar ? (
                        <img src={t.channel_avatar} alt="" style={{width:20, height:20, borderRadius:999, objectFit:"cover", flexShrink:0}}/>
                      ) : (
                        <span style={{width:20, height:20, borderRadius:999, background:"rgb(92,107,58)", color:"white", display:"grid", placeItems:"center", fontSize:8, fontWeight:700, fontFamily:"Inter", flexShrink:0}}>
                          {(t.channel_title||"?").slice(0,2).toUpperCase()}
                        </span>
                      )}
                      <span style={{fontFamily:"Inter", fontSize: 11, color:"rgb(var(--fg-muted))", overflow:"hidden", textOverflow:"ellipsis", whiteSpace:"nowrap"}}>
                        {t.channel_title || "Unknown"}
                      </span>
                    </div>
                    {ytUrl && (
                      <a href={ytUrl} target="_blank" rel="noopener noreferrer"
                        onClick={e=>e.stopPropagation()}
                        style={{
                          display:"inline-flex", alignItems:"center", gap:4,
                          padding:"3px 8px", borderRadius:999, fontSize:9,
                          fontFamily:"Inter", fontWeight:600,
                          background:"rgba(255,0,0,0.08)", border:"1px solid rgba(255,0,0,0.2)",
                          color:"#c00", textDecoration:"none", flexShrink:0,
                        }}>
                        <svg width="10" height="10" viewBox="0 0 24 24" fill="#c00"><path d="M23.5 6.2A3 3 0 0 0 21.4 4C19.5 3.5 12 3.5 12 3.5s-7.5 0-9.4.5A3 3 0 0 0 .5 6.2C0 8.1 0 12 0 12s0 3.9.5 5.8A3 3 0 0 0 2.6 20C4.5 20.5 12 20.5 12 20.5s7.5 0 9.4-.5a3 3 0 0 0 2.1-2.2c.5-1.9.5-5.8.5-5.8s0-3.9-.5-5.8z"/><path d="M9.8 15.5V8.5l6.2 3.5-6.2 3.5z" fill="white"/></svg>
                        {lang==="en"?"Follow":"Seguir"}
                      </a>
                    )}
                  </div>
                </div>
              </div>
            );
          })}
        </div>
        )}
      </div>
    </section>
  );
}

// YouTube-style thumbnail placeholder — looks like an unloaded YT embed
function YouTubeThumb({ title, channel, hue }) {
  return (
    <div style={{position:"absolute", inset:0, background:"#0f0f0f", overflow:"hidden"}}>
      {/* soft tint gradient based on instructor color */}
      <div style={{position:"absolute", inset:0, background:`radial-gradient(circle at 30% 35%, ${hue}22 0%, transparent 60%), radial-gradient(circle at 75% 70%, ${hue}33 0%, transparent 55%)`}}/>
      {/* faint grid / film grain */}
      <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{position:"absolute", inset:0, opacity:0.18}}>
        <defs>
          <pattern id={`gr-${hue.replace(/[^a-z0-9]/gi,"")}`} width="20" height="20" patternUnits="userSpaceOnUse">
            <path d="M 20 0 L 0 0 0 20" fill="none" stroke="white" strokeWidth="0.3"/>
          </pattern>
        </defs>
        <rect width="200" height="120" fill={`url(#gr-${hue.replace(/[^a-z0-9]/gi,"")})`}/>
      </svg>
      {/* Centered play button — YouTube red */}
      <div style={{position:"absolute", inset:0, display:"grid", placeItems:"center"}}>
        <div style={{width:62, height:44, background:"rgba(0,0,0,0.55)", border:"1px solid rgba(255,255,255,0.12)", borderRadius:12, display:"grid", placeItems:"center", boxShadow:"0 6px 20px rgba(0,0,0,0.5)"}}>
          <svg width="22" height="22" viewBox="0 0 24 24" fill="white"><path d="M8 5v14l11-7z"/></svg>
        </div>
      </div>
      {/* Bottom title strip — mimics YT title overlay */}
      <div style={{position:"absolute", left:10, right:50, bottom:8, color:"rgba(255,255,255,0.92)", fontFamily:"Inter", fontSize:11, lineHeight:1.25, fontWeight:500, textShadow:"0 1px 3px rgba(0,0,0,0.8)", display:"-webkit-box", WebkitLineClamp:2, WebkitBoxOrient:"vertical", overflow:"hidden"}}>{title}</div>
      {/* Top-left "YouTube" tiny mark */}
      <div style={{position:"absolute", top:8, left:10, display:"flex", alignItems:"center", gap:5, color:"rgba(255,255,255,0.85)", fontFamily:"Inter", fontSize:9, fontWeight:700, letterSpacing:"0.05em"}}>
        <span style={{display:"inline-flex", width:18, height:13, background:"#FF0000", borderRadius:3, alignItems:"center", justifyContent:"center"}}>
          <svg width="8" height="8" viewBox="0 0 24 24" fill="white"><path d="M8 5v14l11-7z"/></svg>
        </span>
        <span style={{textTransform:"uppercase"}}>YouTube</span>
      </div>
    </div>
  );
}

// Abstract golf-scene illustration (legacy, unused — kept for future)
function TutorialIllustration_unused({ kind }) {
  if (kind === "iron" || kind === "driver") {
    return (
      <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{position:"absolute", inset:0}}>
        <defs>
          <linearGradient id={`sky${kind}`} x1="0" x2="0" y1="0" y2="1">
            <stop offset="0" stopColor="rgba(255,255,255,0.25)"/>
            <stop offset="1" stopColor="rgba(255,255,255,0)"/>
          </linearGradient>
        </defs>
        <rect width="200" height="120" fill={`url(#sky${kind})`}/>
        {/* horizon */}
        <path d="M 0 85 Q 100 70, 200 85 L 200 120 L 0 120 Z" fill="rgba(0,0,0,0.25)"/>
        <path d="M 0 92 Q 100 80, 200 92 L 200 120 L 0 120 Z" fill="rgba(0,0,0,0.15)"/>
        {/* silhouetted golfer */}
        <g transform="translate(140, 55)" fill="rgba(20,20,18,0.85)">
          <ellipse cx="0" cy="5" rx="3.5" ry="3.5"/>
          <rect x="-2" y="7" width="4" height="12" rx="1"/>
          <path d="M -5 20 L -2 32 L -4 40 L -2 40 L 1 32 L 2 40 L 4 40 L 2 32 L 5 20 Z"/>
          <line x1="1" y1="10" x2="22" y2="-5" stroke="rgba(20,20,18,0.85)" strokeWidth="1.2"/>
          <circle cx="22" cy="-5" r="1.5" fill="rgba(220,220,210,0.9)"/>
        </g>
        <circle cx="60" cy="90" r="2" fill="rgba(255,255,255,0.9)"/>
        {/* distant trees */}
        <path d="M 20 82 L 24 74 L 28 82 Z M 30 85 L 36 72 L 42 85 Z M 180 86 L 186 76 L 192 86 Z" fill="rgba(0,0,0,0.3)"/>
      </svg>
    );
  }
  if (kind === "grip") {
    return (
      <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{position:"absolute", inset:0}}>
        <rect width="200" height="120" fill="rgba(255,255,255,0.05)"/>
        <g transform="translate(100, 60)">
          <ellipse cx="0" cy="0" rx="30" ry="40" fill="rgba(245,235,210,0.7)" transform="rotate(-20)"/>
          <ellipse cx="-8" cy="5" rx="26" ry="36" fill="rgba(235,220,185,0.8)" transform="rotate(-15)"/>
          <line x1="0" y1="-50" x2="-4" y2="50" stroke="rgba(60,45,30,0.7)" strokeWidth="3"/>
          <rect x="-5" y="-55" width="10" height="8" rx="1" fill="rgba(40,30,20,0.85)"/>
        </g>
      </svg>
    );
  }
  if (kind === "putt" || kind === "short") {
    return (
      <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{position:"absolute", inset:0}}>
        <path d="M 0 60 Q 100 40, 200 60 L 200 120 L 0 120 Z" fill="rgba(0,0,0,0.2)"/>
        <path d="M 0 72 Q 100 55, 200 72 L 200 120 L 0 120 Z" fill="rgba(0,0,0,0.12)"/>
        {/* bucket of balls OR green with flag */}
        <g transform="translate(100, 75)">
          <path d="M -30 0 L -26 28 L 26 28 L 30 0 Z" fill="rgba(200,170,120,0.7)"/>
          <ellipse cx="0" cy="0" rx="30" ry="6" fill="rgba(220,200,160,0.8)"/>
          {[[-12,-3],[-5,-6],[6,-4],[14,-3],[0,-2],[-18,0],[18,0],[-7,2]].map(([x,y],i)=>(
            <circle key={i} cx={x} cy={y} r="3.5" fill="rgba(255,250,235,0.9)"/>
          ))}
        </g>
      </svg>
    );
  }
  return (
    <svg viewBox="0 0 200 120" width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{position:"absolute", inset:0}}>
      <path d="M 0 80 Q 100 65, 200 80 L 200 120 L 0 120 Z" fill="rgba(0,0,0,0.22)"/>
      <g transform="translate(80, 50)" fill="rgba(20,20,18,0.85)">
        <ellipse cx="0" cy="5" rx="3.5" ry="3.5"/>
        <rect x="-2" y="7" width="4" height="12" rx="1"/>
        <path d="M -5 20 L -2 32 L -4 40 L -2 40 L 1 32 L 2 40 L 4 40 L 2 32 L 5 20 Z"/>
        <line x1="1" y1="10" x2="25" y2="-10" stroke="rgba(20,20,18,0.85)" strokeWidth="1.2"/>
      </g>
    </svg>
  );
}

// ========== TAKE YOUR GAME ANYWHERE ==========
function TakeAnywhere({ lang, L }) {
  return (
    <section className="section" style={{background:"rgb(var(--olive-deep))", color:"white", overflow:"hidden", position:"relative"}}>
      {/* Subtle topo lines */}
      <svg viewBox="0 0 1440 600" width="100%" height="100%" preserveAspectRatio="none" style={{position:"absolute", inset: 0, opacity: 0.08}}>
        {Array.from({length: 14}).map((_, i) => (
          <path key={i} d={`M 0 ${100 + i*35} Q 400 ${80 + i*35}, 720 ${130 + i*35} T 1440 ${110 + i*35}`} fill="none" stroke="rgb(191,154,56)" strokeWidth="0.8"/>
        ))}
      </svg>
      <div className="wrap wrap-wide" style={{position:"relative"}}>
        <div style={{display:"grid", gridTemplateColumns:"1.3fr 1fr", gap: 80, alignItems:"center"}}>
          <div>
            <div style={{display:"inline-flex", alignItems:"center", gap: 8, padding:"4px 12px", borderRadius: 999, background:"rgba(191,154,56,0.15)", border:"1px solid rgba(191,154,56,0.4)", fontFamily:"Inter", fontSize:10, letterSpacing:"0.12em", textTransform:"uppercase", color:"rgb(var(--gold))", marginBottom: 28}}>
              {lang==="en" ? "Free to download" : "Descarga gratuita"}
            </div>
            <h2 style={{fontFamily:"Playfair Display", fontWeight: 700, fontSize: "clamp(40px, 5vw, 68px)", letterSpacing:"-0.02em", lineHeight: 1.02, margin: 0, marginBottom: 24}}>
              {lang==="en"
                ? <>Take your game <span style={{fontStyle:"italic", fontWeight: 400, color:"rgb(var(--gold))"}}>anywhere</span>.</>
                : <>Lleva tu juego <span style={{fontStyle:"italic", fontWeight: 400, color:"rgb(var(--gold))"}}>a cualquier parte</span>.</>}
            </h2>
            <p style={{fontSize: 17, lineHeight: 1.6, color:"rgba(255,255,255,0.7)", maxWidth: "50ch", margin: "0 0 40px"}}>
              {lang==="en"
                ? "Analyze swings, track progress, and access your lessons on the go with the One N Only Golf app. iOS + Android, offline-capable, synced to your coach."
                : "Analiza swings, rastrea tu progreso y accede a tus lecciones en cualquier lugar con la app One N Only Golf."}
            </p>
            <div style={{display:"flex", gap: 14, flexWrap:"wrap"}}>
              <a className="app-btn" href="ONOGolf Onboarding.html" style={{background:"white", color:"rgb(var(--olive-deep))"}}>
                <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor"><path d="M17.05 20.28c-.98.95-2.05.8-3.08.35-1.09-.46-2.09-.48-3.24 0-1.44.62-2.2.44-3.06-.35C2.79 15.25 3.51 7.59 9.05 7.31c1.35.07 2.29.74 3.08.8 1.18-.24 2.31-.93 3.57-.84 1.51.12 2.65.72 3.4 1.8-3.12 1.87-2.38 5.98.48 7.13-.57 1.5-1.31 2.99-2.54 4.09zM12 7.25c-.15-2.23 1.66-4.07 3.74-4.25.29 2.58-2.34 4.5-3.74 4.25z"/></svg>
                <div style={{textAlign:"left"}}>
                  <div style={{fontSize: 9, letterSpacing:"0.08em", textTransform:"uppercase", opacity: 0.7}}>Download on the</div>
                  <div style={{fontFamily:"Playfair Display", fontWeight: 700, fontSize: 18, lineHeight: 1}}>App Store</div>
                </div>
              </a>
              <a className="app-btn" href="ONOGolf Onboarding.html" style={{background:"rgb(var(--gold))", color:"rgb(var(--olive-deep))"}}>
                <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor"><path d="M3.609 1.814 13.792 12 3.61 22.186a.996.996 0 0 1-.61-.92V2.734a1 1 0 0 1 .609-.92zM14.5 12.707 5.5 21.707l10.805-6.21zm1.415-1.414 3.894-2.238a.75.75 0 0 1 0 1.299l-3.894 2.237L13.207 12zM5.5 2.293l9 9-3.695 3.695-7.11 4.087L5.5 2.293z"/></svg>
                <div style={{textAlign:"left"}}>
                  <div style={{fontSize: 9, letterSpacing:"0.08em", textTransform:"uppercase", opacity: 0.7}}>Get it on</div>
                  <div style={{fontFamily:"Playfair Display", fontWeight: 700, fontSize: 18, lineHeight: 1}}>Google Play</div>
                </div>
              </a>
            </div>

            <div style={{display:"flex", gap: 32, marginTop: 48, paddingTop: 28, borderTop:"1px solid rgba(255,255,255,0.15)"}}>
              {[
                { v:"4.9", k: lang==="en"?"App Store":"App Store" },
                { v:"4.8", k: lang==="en"?"Play Store":"Play Store" },
                { v:"84K+", k: lang==="en"?"Active golfers":"Golfistas activos" },
              ].map(m => (
                <div key={m.k}>
                  <div style={{fontFamily:"Playfair Display", fontWeight: 700, fontSize: 28, letterSpacing:"-0.02em"}}>{m.v}</div>
                  <div style={{fontSize: 11, letterSpacing:"0.1em", textTransform:"uppercase", color:"rgba(255,255,255,0.6)", marginTop: 4}}>{m.k}</div>
                </div>
              ))}
            </div>
          </div>

          {/* Phone mockup */}
          <div style={{display:"flex", justifyContent:"center"}}>
            <div style={{width: 290, borderRadius: 36, background: "white", color:"rgb(var(--ink))", padding: 20, boxShadow:"0 40px 80px rgba(0,0,0,0.4), 0 0 0 10px rgba(255,255,255,0.04)", border:"1px solid rgba(255,255,255,0.1)"}}>
              <div style={{fontFamily:"Inter", fontSize: 13, fontWeight: 600, color:"rgb(var(--ink))", marginBottom: 4, display:"flex", alignItems:"center", gap: 6}}>
                <svg width="14" height="14" viewBox="0 0 16 16" fill="none"><rect x="2" y="3" width="12" height="9" rx="1.5" stroke="currentColor" strokeWidth="1.4"/><circle cx="5" cy="7.5" r="1.2" fill="currentColor"/><path d="m2 11 3-3 3 3 3-3 3 3" stroke="currentColor" strokeWidth="1.4" fill="none"/></svg>
                Upload Your Swing
              </div>
              <div style={{fontSize: 11, color:"rgb(var(--fg-muted))", marginBottom: 14}}>Upload 1–5 videos of your swing for personalized analysis</div>
              <div style={{border:"1.5px dashed rgb(var(--border))", borderRadius: 12, padding: "22px 16px", textAlign:"center", marginBottom: 14}}>
                <svg width="20" height="20" viewBox="0 0 20 20" fill="none" style={{margin:"0 auto 6px", display:"block"}}><path d="M10 3v10m-5-5 5-5 5 5M3 17h14" stroke="rgb(92,107,58)" strokeWidth="1.5" strokeLinecap="round"/></svg>
                <div style={{fontFamily:"Inter", fontWeight: 600, fontSize: 13}}>Select Videos</div>
                <div style={{fontSize: 10, color:"rgb(var(--fg-muted))", marginTop: 3}}>or drag & drop here</div>
                <div style={{fontSize: 9, color:"rgb(var(--fg-faint))", marginTop: 8, fontFamily:"JetBrains Mono"}}>MP4, MOV, AVI — max 100MB per video</div>
              </div>
              <div style={{fontSize: 9, letterSpacing:"0.12em", textTransform:"uppercase", color:"rgb(var(--fg-muted))", fontFamily:"Inter", fontWeight: 600, marginBottom: 8}}>Uploaded videos</div>
              {[
                { n: "driver_swing_front.mp4", s: "24 MB", status: "ANALYZED",  fg:"rgb(92,107,58)" },
                { n: "iron_7_dtl.mp4",         s: "18 MB", status: "ANALYZED",  fg:"rgb(92,107,58)" },
                { n: "putting_stance.mp4",      s: "12 MB", status: "PROCESSING", fg:"rgb(196,112,58)" },
              ].map(v => (
                <div key={v.n} style={{display:"flex", alignItems:"center", gap: 8, padding: "8px 10px", background:"rgb(var(--bg-2))", borderRadius: 8, marginBottom: 6}}>
                  <svg width="12" height="12" viewBox="0 0 16 16" fill="none" style={{color:"rgb(var(--fg-muted))"}}><rect x="2" y="3" width="12" height="9" rx="1" stroke="currentColor" strokeWidth="1.3"/><path d="m7 6 3 2-3 2V6z" fill="currentColor"/></svg>
                  <div style={{flex: 1, minWidth: 0}}>
                    <div style={{fontSize: 11, fontWeight: 500, whiteSpace:"nowrap", overflow:"hidden", textOverflow:"ellipsis"}}>{v.n}</div>
                    <div style={{fontSize: 9, color:"rgb(var(--fg-muted))", fontFamily:"JetBrains Mono"}}>{v.s}</div>
                  </div>
                  <span style={{fontSize: 9, fontWeight: 600, color: v.fg, letterSpacing:"0.08em"}}>{v.status}</span>
                </div>
              ))}
              <button style={{width:"100%", marginTop: 12, padding: "12px", borderRadius: 10, background:"rgb(92,107,58)", color:"white", border:"none", fontFamily:"Inter", fontWeight: 600, fontSize: 13, cursor:"pointer", display:"flex", alignItems:"center", justifyContent:"center", gap: 6}}>
                <svg width="14" height="14" viewBox="0 0 16 16" fill="none"><circle cx="8" cy="8" r="6" stroke="currentColor" strokeWidth="1.4"/><path d="M8 4v4l2.5 1.5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/></svg>
                Analyze My Swing
              </button>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

function Journey({ lang, L, phase, setPhase }) {
  const active = PHASES[phase - 1];
  return (
    <section className="section journey" id="journey">
      <div className="wrap wrap-wide">
        <div style={{display:"grid", gridTemplateColumns: "1fr auto", gap: 40, alignItems: "end"}}>
          <div>
            <div className="eyebrow">{L.journeyEyebrow}</div>
            <h2 className="display display-lg" style={{marginTop: 20, marginBottom: 20, maxWidth: "16ch"}}>
              {lang === "en"
                ? <>Eight phases. <span className="italic-ink">One</span> route.</>
                : <>Ocho fases. <span className="italic-ink">Una</span> ruta.</>}
            </h2>
            <p className="lede">{L.journeyLede}</p>
          </div>
          <div className="label-mono">Phase 01 → 08 · press any phase</div>
        </div>

        <div className="phase-path" role="tablist" aria-label="Journey phases">
          {PHASES.map(p => (
            <button
              type="button"
              key={p.n}
              role="tab"
              aria-selected={p.n === phase}
              aria-label={`Phase ${p.roman} — ${p.name[lang]}`}
              className={`phase-col ${p.n === phase ? "current" : ""} ${p.n < phase ? "done" : ""}`}
              onClick={() => setPhase(p.n)}
              style={{font: "inherit", color: "inherit", appearance: "none"}}
            >
              <div
                className="phase-img"
                aria-hidden="true"
                style={{backgroundImage: `url('./assets/phase-${String(p.n).padStart(2,"0")}.jpg')`}}
              />
              <div className="phase-meta">
                <div className="phase-roman">{p.roman}</div>
                <div className="phase-name">{p.name[lang]}</div>
                <div className="phase-goal">{p.goal[lang]}</div>
              </div>
            </button>
          ))}
        </div>

        <div className="phase-detail">
          <div>
            <div className="label-mono">Phase {String(active.n).padStart(2,"0")} · {active.roman}</div>
            <div className="phase-detail-num">{active.roman}</div>
            <h3 className="display display-md" style={{marginTop: 0, marginBottom: 8}}>{active.name[lang]}</h3>
            <div className="chip chip-neutral" style={{marginBottom: 20}}>
              <span className="chip-dot"></span>{active.goal[lang]} · {active.hcp}
            </div>
            <p className="serif-quote" style={{fontSize: 18, lineHeight: 1.4, color: "rgb(var(--fg-muted))", margin: 0, maxWidth: "28ch"}}>
              "{active.quote[lang]}"
            </p>
          </div>
          <div>
            <div style={{display: "grid", gridTemplateColumns: "1fr 1fr", gap: 32, marginBottom: 28}}>
              <div>
                <div className="label-mono">{L.currentPhase}</div>
                <div className="display display-sm" style={{marginTop: 6}}>{active.milestone[lang]}</div>
              </div>
              <div>
                <div className="label-mono">{L.focusNow}</div>
                <div className="display display-sm" style={{marginTop: 6}}>{active.focus[lang]}</div>
              </div>
            </div>
            <div className="label-mono" style={{marginBottom: 8}}>{L.milestones}</div>
            {active.gates.map(g => (
              <div key={g.mk} className="phase-gate">
                <div className="marker">{g.mk}</div>
                <div style={{flex: 1}}>
                  <div className="g-title">{g.t[lang]}</div>
                  <div className="g-desc">{g.d[lang]}</div>
                </div>
                <Icon.arrow style={{color: "rgb(var(--fg-faint))"}}/>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

// ========== ARCHETYPES ==========
function Archetypes({ lang, L }) {
  const kinds = ["young", "metronome", "fader", "antihook", "rising"];
  return (
    <section className="section" id="archetypes">
      <div className="wrap wrap-wide" style={{marginBottom: 56}}>
        <div style={{display:"grid", gridTemplateColumns: "1.2fr 1fr", gap: 40, alignItems: "end"}}>
          <div>
            <div className="eyebrow">{L.archEyebrow}</div>
            <h2 className="display display-lg" style={{marginTop: 20, marginBottom: 20, maxWidth: "14ch"}}>
              {lang === "en"
                ? <>Your swing is <span className="italic-ink">one</span> of five.</>
                : <>Tu swing es <span className="italic-ink">uno</span> de cinco.</>}
            </h2>
            <p className="lede">{L.archLede}</p>
          </div>
          <p className="label-mono" style={{maxWidth: 260, lineHeight: 1.5, textTransform: "none", letterSpacing: "0.02em", fontSize: 12}}>
            ✽ {L.archNote}
          </p>
        </div>
      </div>

      <div className="archetypes">
        {ARCHETYPES.map((a, i) => (
          <div key={a.num} className="archetype">
            <div style={{display:"flex", justifyContent:"space-between", alignItems:"center"}}>
              <div className="archetype-num">{a.num} / 05</div>
              <Icon.arrow style={{color: "rgb(var(--fg-faint))"}}/>
            </div>
            <div className="archetype-sigil">
              <Sigil kind={kinds[i]}/>
            </div>
            <div>
              <div className="archetype-kind">{a.kind[lang]}</div>
              <div className="archetype-name">{a.name[lang]}</div>
            </div>
            <div className="archetype-desc">{a.desc[lang]}</div>
            <div className="archetype-stats">
              <div><div className="k">Tempo</div><div className="v">{a.stats.tempo}</div></div>
              <div><div className="k">Angle</div><div className="v">{a.stats.angle}</div></div>
              <div><div className="k">Shape</div><div className="v">{a.stats.shape}</div></div>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ========== TOURNAMENTS ==========
function Tournaments({ lang, L }) {
  return (
    <section className="section" id="tournaments" style={{background: "rgb(var(--bg-2))"}}>
      <div className="wrap wrap-wide">
        <div style={{display:"grid", gridTemplateColumns: "1.2fr 1fr", gap: 40, alignItems:"end", marginBottom: 56}}>
          <div>
            <div className="eyebrow">{L.tourEyebrow}</div>
            <h2 className="display display-lg" style={{marginTop: 20, marginBottom: 20, maxWidth: "16ch"}}>
              {lang === "en"
                ? <>The tournament map, <span className="italic-ink">finally</span> legible.</>
                : <>El mapa de torneos, <span className="italic-ink">por fin</span> legible.</>}
            </h2>
            <p className="lede">{L.tourLede}</p>
          </div>
          <div className="label-mono" style={{fontSize: 11}}>
            <div>Updated weekly · 47 feeds</div>
            <div style={{marginTop: 4}}>Real-time OWGR sync</div>
          </div>
        </div>

        <div className="tourney-grid">
          {["junior", "adult"].map(k => {
            const t = TOURNAMENTS[k];
            return (
              <div key={k} className="track-card">
                <div className="track-head">
                  <div>
                    <div className="track-title">{t.title[lang]}</div>
                    <div className="track-sub">{t.age[lang]}</div>
                  </div>
                  <Icon.flag style={{color: "rgb(var(--accent))"}}/>
                </div>
                <div className="track-body">
                  {t.rows.map(r => (
                    <div key={r.name} className="tour-row">
                      <div>
                        <div className="tour-name">{r.name}</div>
                        <div className="tour-meta">
                          <span>{r.lvl}</span>
                          <span style={{color: "rgb(var(--fg-faint))"}}>·</span>
                          <span>{r.sub}</span>
                        </div>
                      </div>
                      <Icon.arrow style={{color: "rgb(var(--fg-faint))"}}/>
                    </div>
                  ))}
                </div>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}

// ========== MONEY HUB ==========
function MoneyHub({ lang, L }) {
  return (
    <section className="section" id="money">
      <div className="wrap wrap-wide">
        <div className="money">
          <div className="eyebrow" style={{color: "rgb(var(--gold))"}}>{L.moneyEyebrow}</div>
          <h2 className="money-title" style={{marginTop: 20, maxWidth: "18ch"}}>
            {L.moneyTitleA}<br/>
            <span className="frac">{L.moneyTitleFrac}</span>
          </h2>
          <p style={{fontSize: 17, lineHeight: 1.55, color: "rgba(255,255,255,0.7)", maxWidth: "52ch", marginTop: 28}}>
            {L.moneyLede}
          </p>

          <div className="money-grid">
            <div>
              <div style={{fontFamily: "Inter", fontSize: 11, letterSpacing: "0.14em", textTransform:"uppercase", color: "rgba(255,255,255,0.6)", marginBottom: 16}}>Annual ledger · sample junior</div>
              <div className="ledger">
                <div className="ledger-row"><span className="k">Equipment & clubs</span><span className="v">$1,200</span></div>
                <div className="ledger-row"><span className="k">Lessons & coaching</span><span className="v">$1,800</span></div>
                <div className="ledger-row"><span className="k">Tournament entries</span><span className="v">$2,150</span></div>
                <div className="ledger-row"><span className="k">Travel & lodging</span><span className="v">$4,900</span></div>
                <div className="ledger-row"><span className="k">Green fees</span><span className="v">$960</span></div>
                <div className="ledger-row"><span className="k">Apparel & accessories</span><span className="v">$290</span></div>
                <div className="ledger-row total"><span className="k">Year 1 · out</span><span className="v">$11,300</span></div>
              </div>
              <div style={{fontSize: 12, color: "rgba(255,255,255,0.6)", marginTop: 14, lineHeight: 1.5}}>
                Extrapolated across 5 years of junior development · pre-college.
              </div>
            </div>

            <div>
              <div style={{fontFamily:"Inter", fontSize: 11, letterSpacing: "0.14em", textTransform:"uppercase", color: "rgba(255,255,255,0.6)", marginBottom: 16}}>Potential return</div>
              <div className="roi-num">
                4.2<span className="x">×</span>
              </div>
              <div style={{fontSize: 14, color: "rgba(255,255,255,0.8)", marginTop: 8}}>
                Scholarship yield + career networking + lifetime health.
              </div>
              <div className="ledger-meter">
                <div style={{display:"flex", justifyContent:"space-between", marginBottom: 10, fontSize: 12, color: "rgba(255,255,255,0.7)"}}>
                  <span>Invested · $50K</span>
                  <span style={{color: "rgb(var(--gold))"}}>Returned · $160K+</span>
                </div>
                <div className="bar">
                  <div className="fill-gold"></div>
                </div>
                <div style={{display:"grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 14, marginTop: 28}}>
                  {[
                    {k:"Schol. avg", v:"$18K+"},
                    {k:"D1 placement", v:"32%"},
                    {k:"Break-even yr", v:"Y4"},
                    {k:"Tax writeoff", v:"partial"},
                  ].map(m => (
                    <div key={m.k}>
                      <div style={{fontSize: 10, letterSpacing: "0.1em", textTransform:"uppercase", color: "rgba(255,255,255,0.6)"}}>{m.k}</div>
                      <div style={{fontFamily:"JetBrains Mono", color: "rgb(var(--gold))", fontWeight: 500, fontSize: 14, marginTop: 4}}>{m.v}</div>
                    </div>
                  ))}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ========== MOBSYNC / SPANISH ==========
function MobSync({ lang, L }) {
  return (
    <section className="section">
      <div className="wrap wrap-wide">
        <div className="mobsync">
          <div className="mobsync-side">
            <div className="eyebrow">{L.mobsyncEyebrow}</div>
            <h3>{L.mobsyncTitle}</h3>
            <p>{L.mobsyncLede}</p>
            <div className="transcript transcript-en">
              <div style={{fontSize: 10, letterSpacing: "0.1em", textTransform:"uppercase", color: "rgb(var(--fg-muted))", marginBottom: 8}}>SOURCE · EN</div>
              <div className="en">"Keep the trail arm long through impact, and let the face <em>follow</em> the ball rather than chase it."</div>
            </div>
          </div>
          <div className="mobsync-side" style={{background: "rgb(var(--bg-2))"}}>
            <div style={{display:"inline-flex", alignItems:"center", gap:8, padding: "4px 10px", background:"rgb(var(--bg-3))", border:"1px solid rgb(var(--border))", borderRadius: 999, fontSize: 10, letterSpacing:"0.12em", textTransform:"uppercase", color:"rgb(var(--fg-muted))"}}>
              <span style={{width: 6, height: 6, borderRadius: 999, background: "rgb(var(--orange))", animation:"pulse 2s infinite"}}></span>
              Auto-dubbed · 3.1s
            </div>
            <h3>"The same lesson, in both languages."</h3>
            <p>The fastest-growing demographic in golf is Spanish-speaking. Most instruction is not. We close the gap at the infrastructure layer.</p>
            <div className="transcript transcript-es">
              <div style={{fontSize: 10, letterSpacing: "0.1em", textTransform:"uppercase", color: "rgb(var(--fg-muted))", marginBottom: 8}}>OUTPUT · ES</div>
              <div className="es">"Mantén el brazo del rastro largo durante el impacto, y deja que la cara <em>siga</em> la bola en lugar de perseguirla."</div>
            </div>
            <div style={{display:"flex", gap: 14, marginTop: 16, fontSize: 11, color: "rgb(var(--fg-muted))"}}>
              <span>▸ Voice-matched</span>
              <span>▸ Term-aware</span>
              <span>▸ 100% coverage</span>
            </div>
          </div>
        </div>

        <div style={{display:"grid", gridTemplateColumns:"repeat(4, 1fr)", gap: 24, marginTop: 56}}>
          {[
            {k:"Hours dubbed", v:"12,400"},
            {k:"Instructors covered", v:"187"},
            {k:"LATAM markets", v:"19"},
            {k:"Competitive players", v:"zero"},
          ].map(m => (
            <div key={m.k} style={{borderTop: "1px solid rgb(var(--border))", paddingTop: 16}}>
              <div style={{fontFamily:"Playfair Display", fontWeight: 700, fontSize: 36, letterSpacing:"-0.02em", lineHeight: 1}}>{m.v}</div>
              <div style={{fontSize: 11, letterSpacing:"0.12em", textTransform:"uppercase", color: "rgb(var(--fg-muted))", marginTop: 10}}>{m.k}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ========== CTA + FOOTER ==========
function Cta({ lang, L }) {
  return (
    <section className="cta-big">
      <div className="wrap wrap-wide">
        <div className="eyebrow" style={{justifyContent:"center", display:"inline-flex"}}>{L.ctaEyebrow}</div>
        <h2 className="display display-xl" style={{marginTop: 24, marginBottom: 28}}>
          {L.ctaTitleA} <span className="italic-ink">{L.ctaTitleItalic}</span>
        </h2>
        <p className="lede" style={{margin: "0 auto 36px"}}>{L.ctaLede}</p>
        <div style={{display:"flex", gap: 12, justifyContent:"center", flexWrap:"wrap"}}>
          <a className="btn btn-dark btn-xl" href="ONOGolf Onboarding.html">{L.startCta} <Icon.arrow className="arrow"/></a>
          <a className="btn btn-ghost btn-xl" href="ONOGolf Swing Analyzer.html">▸ {L.watchCta}</a>
        </div>
      </div>
    </section>
  );
}

function Footer({ lang, L }) {
  // Shared "Share a Golf Idea" modal (/idea-form.js) — same form as the gate + ver2 nav.
  React.useEffect(() => {
    if (window.OnoIdea || document.getElementById('oif-script')) return;
    const s = document.createElement('script'); s.id = 'oif-script'; s.src = '/idea-form.js';
    document.head.appendChild(s);
  }, []);
  return (
    <footer className="ono-footer">
      <div className="ono-footer-inner">
        <div className="ono-footer-grid">
          <div className="ono-footer-brand">
            <a className="ono-wordmark" href="ONOGolf Landing Page.html" aria-label="ONO Golf">
              <img src="./assets/ono-golf-logo-blkwht.svg" alt="ONO Golf" style={{height: 56, width: "auto", display: "block"}}/>
            </a>
            <p>Your personal AI golf coach,<br/>available 24/7.</p>
            <div className="ono-footer-follow">
              <div className="ono-footer-eyebrow">FOLLOW US</div>
              <div className="ono-social-row">
                <a aria-label="Instagram"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6"><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="1" fill="currentColor"/></svg></a>
                <a aria-label="YouTube"><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M21.6 7.2a2.6 2.6 0 00-1.83-1.84C18.2 5 12 5 12 5s-6.2 0-7.77.36A2.6 2.6 0 002.4 7.2 27 27 0 002 12a27 27 0 00.4 4.8 2.6 2.6 0 001.83 1.84C5.8 19 12 19 12 19s6.2 0 7.77-.36a2.6 2.6 0 001.83-1.84A27 27 0 0022 12a27 27 0 00-.4-4.8zM10 15V9l5.2 3z"/></svg></a>
                <a aria-label="Twitter"><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M22 5.8a8.5 8.5 0 01-2.36.65 4.1 4.1 0 001.8-2.27 8.2 8.2 0 01-2.6 1 4.1 4.1 0 00-7 3.74A11.6 11.6 0 013 4.8a4.1 4.1 0 001.27 5.48 4 4 0 01-1.86-.5v.05a4.1 4.1 0 003.3 4 4.1 4.1 0 01-1.85.07 4.1 4.1 0 003.83 2.85A8.2 8.2 0 012 18.4a11.6 11.6 0 006.3 1.85c7.55 0 11.69-6.26 11.69-11.69v-.53A8.3 8.3 0 0022 5.8z"/></svg></a>
                <a aria-label="Facebook"><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M22 12a10 10 0 10-11.56 9.88v-7H7.9V12h2.54V9.8c0-2.5 1.49-3.9 3.78-3.9 1.1 0 2.24.2 2.24.2v2.47h-1.26c-1.24 0-1.63.77-1.63 1.56V12h2.77l-.44 2.88h-2.33v7A10 10 0 0022 12z"/></svg></a>
              </div>
            </div>
            <div className="ono-footer-apps">
              <div className="ono-footer-eyebrow">DOWNLOAD THE APP</div>
              <a className="ono-app-pill">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M17 12.5a4 4 0 012-3.4 4.2 4.2 0 00-3.3-1.8c-1.4-.1-2.7.8-3.4.8-.7 0-1.8-.8-3-.8a4.4 4.4 0 00-3.7 2.3c-1.6 2.8-.4 6.9 1.1 9.1.8 1.1 1.7 2.3 2.9 2.3 1.2 0 1.6-.7 3-.7 1.4 0 1.8.7 3 .7 1.2 0 2-1.1 2.8-2.2a9.7 9.7 0 001.3-2.6 4 4 0 01-2.7-3.7zM14.8 5.5a4 4 0 001-3 4 4 0 00-2.5 1.3 3.7 3.7 0 00-1 2.9 3.4 3.4 0 002.5-1.2z"/></svg>
                App Store
              </a>
              <a className="ono-app-pill">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M5 3v18l13-9z"/></svg>
                Google Play
              </a>
            </div>
          </div>

          <div>
            <h4>PLATFORM</h4>
            <a href="ONOGolf Analysis.html">Analysis Dashboard</a>
            <a href="ONOGolf Progress.html">Progress Tracker</a>
            <a href="ONOGolf Dashboard.html">Dashboard</a>
            <a href="ONOGolf Tournament.html">Tournaments</a>
            <a href="ONOGolf Scorecard.html">Scorecard</a>
            <a href="ONOGolf Pricing.html">Pricing</a>
          </div>

          <div>
            <h4>RESOURCES</h4>
            <a href="ONOGolf Coaches.html">Find Instructors</a>
            <a href="ONOGolf Lessons.html">Lessons Library</a>
            <a href="ONOGolf Player Profile.html">Your Profile</a>
            <a href="ONOGolf Onboarding.html">Get Started</a>
            <a>Golf Blog</a>
            <a>Equipment Guide</a>
            <a>FAQ</a>
          </div>

          <div>
            <h4>COMPANY</h4>
            <a>About Us</a>
            <a>Careers</a>
            <a>Press</a>
            <a>Contact Us</a>
          </div>

          <div>
            <h4>LEGAL</h4>
            <a href="/privacy.html">Privacy Policy</a>
            <a href="/idea-terms.html">Idea Submission Terms</a>
            <a href="#" data-ono-idea="">Share a Golf Idea</a>
            <a>Terms of Service</a>
            <a>Cookie Policy</a>
            <a>Accessibility</a>
          </div>
        </div>

        <div className="ono-footer-admin">
          <span className="ono-footer-admin-label">◆ Operator Access</span>
          <a href="ONOGolf Admin.html">Site Admin</a>
          <span className="ono-footer-admin-sep">·</span>
          <a href="ONOGolf Coach Portal.html">Coach Portal</a>
          <span className="ono-footer-admin-sep">·</span>
          <a href="ONOGolf Dashboard.html">Player Dashboard</a>
        </div>

        <div className="ono-footer-bottom">
          <span>© 2026 One N Only Golf, Inc. All rights reserved. · <a href="/privacy.html">Privacy Policy</a> · <a href="/idea-terms.html">Idea Submission Terms</a></span>
          <span>Made with care in the USA 🇺🇸</span>
        </div>
      </div>
    </footer>
  );
}

// ========== SCORECARD HOMEPAGE FEATURE ==========
function ScorecardFeature({ lang, L }) {
  return (
    <section className="sc-feature">
      <div className="sc-feature-inner">
        <div className="sc-feature-copy">
          <div className="eyebrow" style={{color:"rgb(var(--gold))"}}>★ NEW · INCLUDED FREE</div>
          <h2 className="display display-xl" style={{marginTop: 18, marginBottom: 22}}>
            Never lose <span className="italic-ink">the pencil</span> again.
          </h2>
          <p className="lede" style={{marginBottom: 28}}>
            A generic digital scorecard for every round you play. Track up to a foursome, log strokes, putts, fairways and GIR — works offline, syncs to your journey, and emails non-member playing partners their card with a sign-up invite.
          </p>
          <ul className="sc-feature-bullets">
            <li><span className="sc-check">✓</span> <strong>Group-aware</strong> — score your whole foursome on one card</li>
            <li><span className="sc-check">✓</span> <strong>Offline-first</strong> — no signal on the back nine? No problem</li>
            <li><span className="sc-check">✓</span> <strong>Auto-course-detect</strong> — pulls par from 38K+ courses</li>
            <li><span className="sc-check">✓</span> <strong>Feeds your AI coach</strong> — every round refines your analysis</li>
            <li><span className="sc-check">✓</span> <strong>Invite playing partners</strong> — send their card + sign-up link</li>
          </ul>
          <div style={{display:"flex", gap: 12, marginTop: 32, flexWrap:"wrap"}}>
            <a className="btn btn-dark btn-xl" href="ONOGolf Scorecard.html">Open scorecard <Icon.arrow className="arrow"/></a>
            <a className="btn btn-ghost btn-xl" href="ONOGolf Onboarding.html">Try the demo round</a>
          </div>
        </div>

        <div className="sc-feature-mock">
          <div className="sc-mock-phone">
            <div className="sc-mock-head">
              <div>
                <div className="sc-mock-eyebrow">ROUND · IN PROGRESS</div>
                <div className="sc-mock-course">Pebble Beach G.L.</div>
              </div>
              <div className="sc-mock-pill">Hole 7 / 18</div>
            </div>
            <div className="sc-mock-players">
              {[
                {n:"YOU",   s:"+3", c:"olive"},
                {n:"M.J.",  s:"+5", c:"gold"},
                {n:"K.R.",  s:"+1", c:"orange"},
                {n:"D.W.",  s:"+7", c:"deep"},
              ].map(p => (
                <div key={p.n} className={`sc-mock-player sc-${p.c}`}>
                  <span className="sc-mock-name">{p.n}</span>
                  <span className="sc-mock-score">{p.s}</span>
                </div>
              ))}
            </div>
            <div className="sc-mock-grid">
              <div className="sc-mock-grid-head"><span>H</span><span>P</span><span>YOU</span><span>M.J.</span><span>K.R.</span><span>D.W.</span></div>
              {[
                {h:1, p:4, s:["4","5","4","6"]},
                {h:2, p:5, s:["6","6","5","7"]},
                {h:3, p:3, s:["3","4","3","4"]},
                {h:4, p:4, s:["5","5","4","6"]},
                {h:5, p:4, s:["4","6","4","5"]},
                {h:6, p:5, s:["5","6","5","7"]},
                {h:7, p:3, s:["—","—","—","—"]},
              ].map(r => (
                <div key={r.h} className={`sc-mock-row ${r.h===7?"active":""}`}>
                  <span className="sc-mock-h">{r.h}</span>
                  <span className="sc-mock-par">{r.p}</span>
                  {r.s.map((v,i) => <span key={i} className="sc-mock-stroke">{v}</span>)}
                </div>
              ))}
            </div>
            <div className="sc-mock-actions">
              <button className="sc-mock-btn sc-mock-btn-ghost">− Stroke</button>
              <button className="sc-mock-btn sc-mock-btn-primary">+ Stroke</button>
            </div>
          </div>
          <div className="sc-feature-badge">
            <div className="sc-feature-badge-num">38K+</div>
            <div className="sc-feature-badge-label">Courses pre-loaded</div>
          </div>
          <div className="sc-feature-badge sc-feature-badge-2">
            <div className="sc-feature-badge-num">⚡</div>
            <div className="sc-feature-badge-label">Offline-first</div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ========== SWING SHOWCASE — Feature card linking to Swing Analyzer ==========
function SwingShowcase({ lang, L }) {
  return (
    <section className="section" style={{background:"rgb(var(--bg))", borderTop:"1px solid rgb(var(--border))", borderBottom:"1px solid rgb(var(--border))"}}>
      <div className="wrap wrap-wide">
        <div style={{display:"grid", gridTemplateColumns:"1fr 1.1fr", gap: 64, alignItems:"center"}}>
          <div>
            <div className="eyebrow">
              {lang === "en" ? "NEW · Biomechanics Engine" : "NUEVO · Motor de Biomecánica"}
            </div>
            <h2 className="display display-lg" style={{marginTop: 20, marginBottom: 20, maxWidth: "16ch"}}>
              {lang === "en"
                ? <>See your swing, <span className="italic-ink">frame by frame</span>.</>
                : <>Mira tu swing, <span className="italic-ink">cuadro por cuadro</span>.</>}
            </h2>
            <p className="lede" style={{marginBottom: 28}}>
              {lang === "en"
                ? "P1 to P10 — the ten checkpoints elite coaches use to diagnose every swing. Hip turn, shaft plane, wrist hinge, weight transfer. Interactive 3D animation, in your browser."
                : "P1 a P10 — los diez puntos de control que los entrenadores de élite usan para diagnosticar cada swing. Animación 3D interactiva, en tu navegador."}
            </p>
            <div style={{display:"flex", gap: 12, flexWrap:"wrap"}}>
              <a className="btn btn-xl" href="ONOGolf Swing Analyzer.html" style={{background:"rgb(var(--olive-deep))", color:"white", borderColor:"rgb(var(--olive-deep))"}}>
                {lang === "en" ? "Open the analyzer" : "Abrir el analizador"} <Icon.arrow className="arrow"/>
              </a>
              <a className="btn btn-ghost btn-xl" href="ONOGolf Analysis.html">
                {lang === "en" ? "▸ Sample analysis" : "▸ Análisis de muestra"}
              </a>
            </div>
            <div style={{display:"flex", gap: 32, marginTop: 40, paddingTop: 24, borderTop:"1px solid rgb(var(--border))"}}>
              {[
                { v: "P1–P10", k: lang==="en"?"Checkpoints":"Puntos" },
                { v: "3D", k: lang==="en"?"Interactive":"Interactivo" },
                { v: "60fps", k: lang==="en"?"Real-time":"Tiempo real" },
              ].map(m => (
                <div key={m.k}>
                  <div style={{fontFamily:"Playfair Display", fontWeight: 700, fontSize: 26, letterSpacing:"-0.02em", lineHeight: 1, color:"rgb(var(--fg))"}}>{m.v}</div>
                  <div style={{fontSize: 10, letterSpacing:"0.12em", textTransform:"uppercase", color:"rgb(var(--fg-muted))", marginTop: 8}}>{m.k}</div>
                </div>
              ))}
            </div>
          </div>

          {/* Visual: stylized P1-P10 frame strip */}
          <a href="ONOGolf Swing Analyzer.html" style={{display:"block", textDecoration:"none", color:"inherit"}}>
            <div style={{position:"relative", borderRadius: 16, overflow:"hidden", background:"linear-gradient(135deg, rgb(var(--olive-deep)) 0%, rgb(38,46,28) 100%)", padding: 28, boxShadow:"0 30px 60px rgba(0,0,0,0.25)", border:"1px solid rgba(191,154,56,0.25)"}}>
              <div style={{position:"absolute", top: 14, right: 18, display:"inline-flex", alignItems:"center", gap: 6, padding:"4px 10px", background:"rgba(191,154,56,0.18)", border:"1px solid rgba(191,154,56,0.5)", borderRadius: 999, fontFamily:"JetBrains Mono", fontSize: 9, letterSpacing:"0.12em", textTransform:"uppercase", color:"rgb(var(--gold))"}}>
                <span style={{width: 6, height: 6, borderRadius: 999, background:"rgb(var(--gold))", animation:"pulse 2s infinite"}}></span>
                LIVE PREVIEW
              </div>
              <div style={{display:"grid", gridTemplateColumns:"repeat(5, 1fr)", gap: 10, marginBottom: 18}}>
                {["P1","P2","P3","P4","P5","P6","P7","P8","P9","P10"].map((p,i) => (
                  <div key={p} style={{
                    aspectRatio:"3/4",
                    background:`linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(0,0,0,0.25) 100%)`,
                    border: i===4 ? "1.5px solid rgb(var(--gold))" : "1px solid rgba(255,255,255,0.08)",
                    borderRadius: 6,
                    display:"grid",
                    placeItems:"center",
                    fontFamily:"JetBrains Mono", fontSize: 11, fontWeight: 500,
                    color: i===4 ? "rgb(var(--gold))" : "rgba(255,255,255,0.6)",
                    boxShadow: i===4 ? "0 0 20px rgba(191,154,56,0.4)" : "none",
                    position:"relative",
                  }}>
                    <svg viewBox="0 0 24 32" width="60%" height="60%" style={{position:"absolute", inset:0, margin:"auto", opacity: i===4 ? 0.9 : 0.45}}>
                      <circle cx="12" cy="6" r="2.5" fill="currentColor"/>
                      <line x1="12" y1="8.5" x2="12" y2="18" stroke="currentColor" strokeWidth="1.5"/>
                      <line x1="12" y1="18" x2="9" y2="26" stroke="currentColor" strokeWidth="1.5"/>
                      <line x1="12" y1="18" x2="15" y2="26" stroke="currentColor" strokeWidth="1.5"/>
                      <line x1="12" y1="12" x2={4 + i*1.2} y2={10 - i*0.4} stroke="currentColor" strokeWidth="1.5"/>
                      <line x1="12" y1="12" x2={20 - i*0.5} y2={14 - i*0.5} stroke="currentColor" strokeWidth="1.5"/>
                    </svg>
                    <span style={{position:"absolute", bottom: 4, left: 6, fontSize: 8, opacity: 0.7}}>{p}</span>
                  </div>
                ))}
              </div>
              <div style={{display:"flex", justifyContent:"space-between", alignItems:"center", paddingTop: 16, borderTop:"1px solid rgba(255,255,255,0.08)"}}>
                <div>
                  <div style={{fontFamily:"Playfair Display", fontWeight: 600, fontSize: 16, color:"white"}}>
                    {lang === "en" ? "Top of Backswing" : "Cima del Backswing"}
                  </div>
                  <div style={{fontFamily:"JetBrains Mono", fontSize: 10, color:"rgba(255,255,255,0.55)", marginTop: 4, letterSpacing:"0.05em"}}>
                    P5 · 0.74s · shaft plane 62°
                  </div>
                </div>
                <div style={{padding:"8px 16px", background:"rgba(191,154,56,0.15)", border:"1px solid rgba(191,154,56,0.5)", borderRadius: 999, fontFamily:"Inter", fontSize: 11, fontWeight: 600, color:"rgb(var(--gold))"}}>
                  {lang === "en" ? "Launch →" : "Abrir →"}
                </div>
              </div>
            </div>
          </a>
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { Nav, Hero, Ticker, Instructors, TutorialLibrary, TakeAnywhere, Journey, Archetypes, Tournaments, MoneyHub, MobSync, Cta, Footer, ScorecardFeature, OnoWordmark, SwingShowcase });
