/* global React */
const { useState, useEffect, useRef } = React;

/* ============ Icons ============ */
const Ic = {
  play: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M8 5v14l11-7z"/></svg>,
  pause: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M6 5h4v14H6zM14 5h4v14h-4z"/></svg>,
  prev: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M6 6h2v12H6zM9.5 12l8.5 6V6z"/></svg>,
  next: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M16 6h2v12h-2zM6 18l8.5-6L6 6z"/></svg>,
  shuffle: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><polyline points="16 3 21 3 21 8"/><line x1="4" y1="20" x2="21" y2="3"/><polyline points="21 16 21 21 16 21"/><line x1="15" y1="15" x2="21" y2="21"/><line x1="4" y1="4" x2="9" y2="9"/></svg>,
  repeat: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>,
  heart: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M12 21s-7-4.5-9.5-9A5.5 5.5 0 0 1 12 6a5.5 5.5 0 0 1 9.5 6c-2.5 4.5-9.5 9-9.5 9z"/></svg>,
  music: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>,
  list: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...p}><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><circle cx="4" cy="6" r="1"/><circle cx="4" cy="12" r="1"/><circle cx="4" cy="18" r="1"/></svg>,
  check: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" {...p}><polyline points="20 6 9 17 4 12"/></svg>,
  x: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...p}><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>,
  plus: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...p}><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>,
  arrow: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg>,
  spark: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M12 2l1.5 6.5L20 10l-6.5 1.5L12 18l-1.5-6.5L4 10l6.5-1.5z"/></svg>,
  bolt: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M13 2L4 14h7l-1 8 9-12h-7z"/></svg>,
  shield: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinejoin="round" {...p}><path d="M12 2L4 5v6c0 5 3.5 9.5 8 11 4.5-1.5 8-6 8-11V5l-8-3z"/></svg>,
  lock: (p) => <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>,
  key: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="7.5" cy="15.5" r="4.5"/><path d="M11 12l9-9M14 5l3 3M19 3l3 3"/></svg>,
  panel: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinejoin="round" {...p}><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="9" y1="3" x2="9" y2="21"/></svg>,
  chart: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...p}><line x1="18" y1="20" x2="18" y2="10"/><line x1="12" y1="20" x2="12" y2="4"/><line x1="6" y1="20" x2="6" y2="14"/></svg>,
  term: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>,
  tune: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...p}><line x1="4" y1="21" x2="4" y2="14"/><line x1="4" y1="10" x2="4" y2="3"/><line x1="12" y1="21" x2="12" y2="12"/><line x1="12" y1="8" x2="12" y2="3"/><line x1="20" y1="21" x2="20" y2="16"/><line x1="20" y1="12" x2="20" y2="3"/><line x1="1" y1="14" x2="7" y2="14"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="17" y1="16" x2="23" y2="16"/></svg>,
  spotify: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M12 0C5.4 0 0 5.4 0 12s5.4 12 12 12 12-5.4 12-12S18.66 0 12 0zm5.521 17.34c-.24.359-.66.48-1.021.24-2.82-1.74-6.36-2.101-10.561-1.141-.418.122-.84-.179-.94-.6-.12-.421.18-.841.6-.94 4.56-1.021 8.52-.6 11.64 1.32.42.18.479.659.282 1.121zm1.44-3.3c-.301.42-.841.6-1.262.3-3.239-1.98-8.159-2.58-11.939-1.38-.479.12-1.02-.12-1.14-.6-.12-.48.12-1.021.6-1.141C9.6 9.9 15 10.561 18.72 12.84c.361.181.54.78.241 1.2zm.12-3.36C15.24 8.4 8.82 8.16 5.16 9.301c-.6.179-1.2-.181-1.38-.721-.18-.601.18-1.2.72-1.381 4.26-1.26 11.28-1.02 15.721 1.621.539.3.719 1.02.42 1.56-.301.421-1.02.599-1.56.3z"/></svg>,
  youtube: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/></svg>,
  rocket: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinejoin="round" strokeLinecap="round" {...p}><path d="M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"/><path d="M12 15l-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"/><path d="M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"/></svg>,
  premium: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M5 16L3 5l5.5 5L12 4l3.5 6L21 5l-2 11H5zm14 3v-1H5v1c0 .55.45 1 1 1h12c.55 0 1-.45 1-1z"/></svg>,
  globe: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>,
  external: (p) => <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>,
  sun: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"/></svg>,
  moon: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>,
};

/* ============ Brand Mark ============ */
const Brand = ({ small }) => (
  <a href="#hero" className="nav-brand">
    <span className="mark mark-logo">
      <img src="assets/wsguardian-logo.png" alt="WSG" width="28" height="28" />
    </span>
    <b>Winners Side Guardian</b>
    {!small && <small>· WSG</small>}
  </a>
);

/* ============ Nav ============ */
const LANGS = [
  { code: "tr", label: "Türkçe" },
  { code: "en", label: "English" },
  { code: "es", label: "Español" },
  { code: "pt", label: "Português" },
];

const LangPicker = ({ lang, onLang, t }) => {
  const [open, setOpen] = useState(false);
  const ref = useRef(null);
  const cur = LANGS.find(l => l.code === lang) || LANGS[0];
  useEffect(() => {
    if (!open) return;
    const onDoc = (e) => { if (ref.current && !ref.current.contains(e.target)) setOpen(false); };
    document.addEventListener("mousedown", onDoc);
    return () => document.removeEventListener("mousedown", onDoc);
  }, [open]);
  return (
    <div className="lang-picker" ref={ref}>
      <button className="theme-tog lang-btn" onClick={() => setOpen(!open)} aria-label={t.nav.langSelect}>
        <Ic.globe />
        <span style={{fontSize:11, fontFamily:"var(--font-mono)", textTransform:"uppercase", letterSpacing:"0.06em"}}>{cur.code}</span>
      </button>
      {open && (
        <div className="lang-menu">
          {LANGS.map(l => (
            <button key={l.code} className={"lang-item" + (l.code === lang ? " on" : "")} onClick={() => { onLang(l.code); setOpen(false); }}>
              <span style={{fontFamily:"var(--font-mono)", fontSize:11, color:"var(--ink-3)", letterSpacing:"0.06em"}}>{l.code.toUpperCase()}</span>
              {l.label}
              {l.code === lang && <Ic.check />}
            </button>
          ))}
        </div>
      )}
    </div>
  );
};

const Nav = ({ theme, onTheme, lang, onLang, t }) => (
  <nav className="nav">
    <div className="shell nav-inner">
      <Brand />
      <div className="nav-links">
        <a href="#features"><span className="dot" />{t.nav.features}</a>
        <a href="#modules"><span className="dot" />{t.nav.modules}</a>
        <a href="#pricing"><span className="dot" />{t.nav.pricing}</a>
        <a href="#panel"><span className="dot" />{t.nav.panel}</a>
        <a href="#faq"><span className="dot" />{t.nav.faq}</a>
      </div>
      <div className="nav-cta">
        <LangPicker lang={lang} onLang={onLang} t={t} />
        <button className="theme-tog" onClick={onTheme} aria-label={theme === "dark" ? t.nav.themeLight : t.nav.themeDark} title={theme === "dark" ? t.nav.themeLight : t.nav.themeDark}>
          {theme === "dark" ? <Ic.sun /> : <Ic.moon />}
        </button>
        <a className="btn btn-ghost" href="https://panel.wsguardian.com/">
          {t.nav.panelLogin} <Ic.external />
        </a>
        <a className="btn btn-primary" href="#pricing">
          <Ic.rocket /> {t.nav.tryFree}
        </a>
      </div>
    </div>
  </nav>
);

/* ============ Hero ============ */
const Hero = ({ t }) => (
  <section className="hero" id="hero">
    <div className="shell hero-grid">
      <div>
        <div className="eyebrow">
          <span className="pulse" />
          {t.hero.eyebrow}
        </div>
        <h1>
          {t.hero.h1a}<br />
          {t.hero.h1b} <em>{t.hero.h1em}</em> {t.hero.h1c}
        </h1>
        <p className="lead">{t.hero.lead}</p>
        <div className="hero-ctas">
          <a className="btn btn-primary btn-lg" href="#pricing">
            <Ic.plus /> {t.hero.cta1}
          </a>
          <a className="btn btn-lg" href="https://www.shopier.com/wsguardian/46204743" target="_blank" rel="noreferrer">
            <Ic.premium /> {t.hero.cta2}
          </a>
        </div>
        <div className="hero-meta">
          <div className="item"><Ic.check /> {t.hero.m1}</div>
          <div className="item"><Ic.spotify /> {t.hero.m2}</div>
          <div className="item"><Ic.key /> {t.hero.m3}</div>
        </div>
      </div>
      <div className="player-stage">
        <Player t={t} />
        <div className="float-chip fc-1">
          <Ic.bolt />
          <span><b>!play fein</b> · {t.hero.chip1}</span>
        </div>
        <div className="float-chip fc-2">
          <Ic.shield />
          <span>{t.hero.chip2} <b>{t.hero.chipActive}</b></span>
        </div>
      </div>
    </div>
  </section>
);

/* ============ Player widget ============ */
const Player = (props) => {
  const [tab, setTab] = useState("Lyrics");
  const [playing, setPlaying] = useState(true);
  return (
    <div className="player">
      <div className="player-head">
        <span className="tag"><span className="live" /> {(props.t && props.t.hero.now) || "Şimdi Çalıyor · #genel"}</span>
        <span className="plan">PRO</span>
      </div>
      <div className="player-body">
        <div className="cover"><div className="vinyl" /></div>
        <div className="track-meta">
          <div className="now">via Spotify · 320 kbps</div>
          <div className="title">FE!N</div>
          <div className="artist">Travis Scott ft. Playboi Carti</div>
          <div className="scrubber">
            <div className="scrubber-bar"><div className="fill" /></div>
            <div className="scrubber-times"><span>1:42</span><span>4:12</span></div>
          </div>
        </div>
      </div>
      <div className="player-controls">
        <div className="group">
          <button className="ctrl"><Ic.shuffle /></button>
          <button className="ctrl"><Ic.prev /></button>
          <button className="ctrl play" onClick={() => setPlaying(!playing)}>
            {playing ? <Ic.pause /> : <Ic.play />}
          </button>
          <button className="ctrl"><Ic.next /></button>
          <button className="ctrl"><Ic.repeat /></button>
        </div>
        <div className="player-tabs">
          {["Play", "Lyrics", "Queue", "Loop"].map(t => (
            <span key={t} className={"tab" + (tab === t ? " on" : "")} onClick={() => setTab(t)}>{t}</span>
          ))}
        </div>
      </div>
      {tab === "Lyrics" && (
        <div className="lyrics-inset">
          <div>♪  yeah, you know that I'm lit</div>
          <div className="active">→  fein, fein, fein, fein, fein</div>
          <div className="next">♪  devil in a new dress (yeah)</div>
        </div>
      )}
      {tab === "Queue" && (
        <div className="lyrics-inset">
          <div className="active">→  1. FE!N — Travis Scott  ·  4:12</div>
          <div>♪  2. Sky — Playboi Carti  ·  3:36</div>
          <div className="next">♪  3. Type Shit — Future, Metro  ·  3:48</div>
        </div>
      )}
    </div>
  );
};

/* ============ Logo / capability strip ============ */
const Strip = ({ t }) => {
  const items = [
    { i: <Ic.spotify />, t: t.strip.spotify },
    { i: <Ic.youtube />, t: t.strip.youtube },
    { i: <Ic.music />, t: t.strip.lyrics },
    { i: <Ic.list />, t: t.strip.playlist },
    { i: <Ic.heart />, t: t.strip.fav },
    { i: <Ic.shield />, t: t.strip.nuke },
    { i: <Ic.tune />, t: t.strip.automod },
    { i: <Ic.panel />, t: t.strip.panel },
    { i: <Ic.key />, t: t.strip.license },
    { i: <Ic.globe />, t: t.strip.langs },
  ];
  const all = [...items, ...items];
  return (
    <div className="strip">
      <div className="strip-track">
        {all.map((it, i) => (
          <span key={i} className="strip-item">{it.i} {it.t}</span>
        ))}
      </div>
    </div>
  );
};

/* ============ Features (numbered editorial) ============ */
const Features = ({ t }) => {
  const f = t.feat;
  const rows = [
    { num: "01", title: f.r1t, badge: "FREE+PRO", desc: f.r1d },
    { num: "02", title: f.r2t, badge: "PRO", desc: f.r2d },
    { num: "03", title: f.r3t, badge: "PRO", desc: f.r3d },
    { num: "04", title: f.r4t, badge: "PRO", desc: f.r4d },
    { num: "05", title: f.r5t, badge: "PANEL", desc: f.r5d },
    { num: "06", title: f.r6t, badge: "FREE+PRO", desc: f.r6d },
  ];
  return (
    <section className="section" id="features">
      <div className="shell">
        <div className="section-head">
          <div className="section-label">{f.label}</div>
          <h2 className="section-title">
            {f.titleA}<br />
            <em>{f.titleB}</em>
          </h2>
          <p className="section-sub">{f.sub}</p>
        </div>
        <div className="features-list">
          {rows.map(r => (
            <div className="feature-row" key={r.num}>
              <div className="num">{r.num}</div>
              <div>
                <h3>{r.title}<span className="badge">{r.badge}</span></h3>
              </div>
              <p>{r.desc}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
};

/* ============ Modules grid ============ */
const Modules = ({ t }) => {
  const m = t.mods;
  return (
  <section className="section" id="modules" style={{ paddingTop: 0 }}>
    <div className="shell">
      <div className="section-head">
        <div className="section-label">{m.label}</div>
        <h2 className="section-title">
          {m.titleA}<br />
          <em>{m.titleB}</em>
        </h2>
      </div>
      <div className="modules">
        <div className="module wide">
          <span className="badge-mini pro">PRO</span>
          <div>
            <div className="ic-wrap"><Ic.music /></div>
            <h4>{m.m1t}</h4>
            <p>{m.m1d}</p>
          </div>
          <div className="mod-visual-music" aria-hidden>
            {Array.from({ length: 24 }).map((_, i) => (
              <span key={i} style={{ animationDelay: `${i * 0.06}s`, height: `${30 + Math.sin(i) * 20}%` }} />
            ))}
          </div>
        </div>

        <div className="module">
          <span className="badge-mini pro">PRO</span>
          <div className="ic-wrap"><Ic.spark /></div>
          <h4>{m.m2t}</h4>
          <p>{m.m2d}</p>
          <div className="mod-visual-lyrics">
            <div>♪ yeah you know</div>
            <div className="hl">→ fein, fein, fein</div>
          </div>
        </div>

        <div className="module">
          <span className="badge-mini pro">PRO</span>
          <div className="ic-wrap"><Ic.heart /></div>
          <h4>{m.m3t}</h4>
          <p>{m.m3d}</p>
          <div className="mod-visual-fav">
            <div className="row"><Ic.heart /> gece — fein</div>
            <div className="row"><Ic.heart /> sabah — sky</div>
          </div>
        </div>

        <div className="module">
          <span className="badge-mini pro">PRO</span>
          <div className="ic-wrap"><Ic.list /></div>
          <h4>{m.m4t}</h4>
          <p>{m.m4d}</p>
          <div className="mod-visual-playlist">
            {Array.from({ length: 6 }).map((_, i) => <div key={i} className="tile" />)}
          </div>
        </div>

        <div className="module">
          <span className="badge-mini free">FREE</span>
          <div className="ic-wrap"><Ic.shield /></div>
          <h4>{m.m5t}</h4>
          <p>{m.m5d}</p>
        </div>

        <div className="module wide">
          <span className="badge-mini pro">PANEL</span>
          <div>
            <div className="ic-wrap"><Ic.key /></div>
            <h4>{m.m6t}</h4>
            <p>{m.m6d}</p>
          </div>
          <div style={{ display: "flex", gap: 8, marginTop: 16, flexWrap: "wrap" }}>
            {["OAuth2", "License", "Plan", "TR/EN/ES/PT"].map(x => (
              <span key={x} className="tab" style={{ background: "rgba(255,255,255,0.04)" }}>{x}</span>
            ))}
          </div>
        </div>
      </div>
    </div>
  </section>
  );
};

/* ============ Pricing ============ */
const Pricing = ({ t }) => {
  const p = t.price;
  return (
  <section className="section" id="pricing">
    <div className="shell">
      <div className="section-head">
        <div className="section-label">{p.label}</div>
        <h2 className="section-title">
          {p.titleA}<br />
          <em>{p.titleB}</em>
        </h2>
        <p className="section-sub">{p.sub}</p>
      </div>
      <div className="pricing">
        <div className="plan">
          <div className="plan-head">
            <span className="plan-name">Free</span>
          </div>
          <div className="plan-price">
            <span className="amount">₺0</span>
            <span className="period">{p.forever}</span>
          </div>
          <p className="plan-tagline">{p.freeTag}</p>
          <ul className="plan-features">
            <li><span className="check"><Ic.check /></span>{p.f1}</li>
            <li><span className="check"><Ic.check /></span>{p.f2}</li>
            <li><span className="check"><Ic.check /></span>{p.f3}</li>
            <li><span className="check"><Ic.check /></span>{p.f4}</li>
            <li className="off"><span className="check"><Ic.x /></span>{p.f5}</li>
            <li className="off"><span className="check"><Ic.x /></span>{p.f6}</li>
          </ul>
          <a className="btn plan-cta btn-lg" href="#cta"><Ic.plus /> {t.hero.cta1}</a>
        </div>

        <div className="plan pro">
          <div className="plan-head">
            <span className="plan-name">Pro</span>
            <span className="plan-flag">{p.recommended}</span>
          </div>
          <div className="plan-price">
            <span className="amount">₺799</span>
            <span className="period">{p.monthly}</span>
          </div>
          <p className="plan-tagline">{p.proTag}</p>
          <ul className="plan-features">
            <li><span className="check"><Ic.check /></span>{p.p1}</li>
            <li><span className="check"><Ic.check /></span>{p.p2}</li>
            <li><span className="check"><Ic.check /></span>{p.p3}</li>
            <li><span className="check"><Ic.check /></span>{p.p4}</li>
            <li><span className="check"><Ic.check /></span>{p.p5}</li>
            <li><span className="check"><Ic.check /></span>{p.p6}</li>
            <li><span className="check"><Ic.check /></span>{p.p7}</li>
          </ul>
          <a className="btn btn-primary plan-cta btn-lg" href="https://www.shopier.com/wsguardian/46204743" target="_blank" rel="noreferrer">
            <Ic.premium /> {t.hero.cta2}
          </a>
        </div>
      </div>
    </div>
  </section>
  );
};

/* ============ Panel preview ============ */
const Panel = ({ t }) => {
  const pn = t.panel;
  const [filters, setFilters] = useState({ ad: true, kufur: true, spam: true, caps: false, repeat: true, nuke: true });
  const tog = (k) => setFilters(f => ({ ...f, [k]: !f[k] }));
  return (
    <section className="section" id="panel">
      <div className="shell">
        <div className="section-head">
          <div className="section-label">{pn.label}</div>
          <h2 className="section-title">
            {pn.titleA}<br />
            <em>{pn.titleB}</em>
          </h2>
          <p className="section-sub">{pn.sub}</p>
        </div>
        <div className="panel-preview">
          <div className="panel-bar">
            <div className="panel-dots"><span /><span /><span /></div>
            <div className="panel-url">
              <Ic.lock /> panel.wsguardian.com / dashboard
            </div>
          </div>
          <div className="panel-body">
            <aside className="panel-side">
              <div className="item on"><Ic.panel /> {pn.overview}</div>
              <div className="item"><Ic.premium /> {pn.plan}</div>
              <div className="item"><Ic.tune /> {pn.settings}</div>
              <div className="item"><Ic.music /> {pn.music}</div>
              <div className="item"><Ic.chart /> {pn.stats}</div>
              <div className="div" />
              <div className="item"><Ic.term /> {pn.customCmds}</div>
              <div className="item"><Ic.list /> {pn.cmdGuide}</div>
            </aside>
            <div className="panel-content">
              <div className="panel-h">
                <h4>{pn.overview}</h4>
                <span className="save"><span className="saved" /> {pn.synced}</span>
              </div>
              <div className="stat-row">
                <div className="stat">
                  <div className="label">{pn.labelPlan}</div>
                  <div className="value" style={{ color: "var(--a1)" }}>PRO</div>
                </div>
                <div className="stat">
                  <div className="label">{pn.labelLicense}</div>
                  <div className="value">{pn.licenseActive}</div>
                </div>
                <div className="stat">
                  <div className="label">{pn.labelToday}</div>
                  <div className="value">∞ <small>/ ∞</small></div>
                </div>
                <div className="stat pro">
                  <div className="label">{pn.labelRenew}</div>
                  <div className="value">28 <small>{pn.days}</small></div>
                </div>
              </div>
              <div className="panel-grid-2">
                <div className="toggle-card">
                  <h5>{pn.protectionTitle}</h5>
                  {[["ad",pn.ad],["kufur",pn.swear],["spam",pn.spam],["caps",pn.caps],["repeat",pn.repeat],["nuke",pn.nuke]].map(([k, l]) => (
                    <div className="toggle-row" key={k} onClick={() => tog(k)} style={{ cursor: "pointer" }}>
                      <span>{l}</span>
                      <span className={"toggle" + (filters[k] ? " on" : "")} />
                    </div>
                  ))}
                </div>
                <div className="toggle-card">
                  <h5>{pn.musicConfig}</h5>
                  <div className="toggle-row"><span>{pn.autoplay}</span><span className="toggle on" /></div>
                  <div className="toggle-row"><span>{pn.twentyfour}</span><span className="toggle" /></div>
                  <div className="toggle-row"><span>{pn.dj}</span><span className="toggle on" /></div>
                  <div className="toggle-row"><span>{pn.botLang}</span><span style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" }}>Türkçe ▾</span></div>
                  <h5 style={{ marginTop: 8 }}>{pn.licenseField}</h5>
                  <div style={{ display: "flex", gap: 8 }}>
                    <div style={{ flex: 1, height: 32, borderRadius: 8, background: "rgba(0,0,0,0.3)", border: "1px solid var(--line)", display: "flex", alignItems: "center", padding: "0 12px", fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--ink-3)" }}>
                      WSG-PRO-XXXX-XXXX-XXXX
                    </div>
                    <button className="btn" style={{ height: 32, padding: "0 12px", fontSize: 12 }}><Ic.key /> {pn.licenseActive}</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div className="cmd-strip">
          <div className="cmd">
            <div className="l">!play</div>
            <div className="c"><span className="p">!play</span> <span className="a">travis scott fein</span></div>
          </div>
          <div className="cmd">
            <div className="l">!lyrics</div>
            <div className="c"><span className="p">!lyrics</span></div>
          </div>
          <div className="cmd">
            <div className="l">!playlist</div>
            <div className="c"><span className="p">!playlist iceaktar</span> <span className="a">chill spotify.link</span></div>
          </div>
          <div className="cmd">
            <div className="l">!fav</div>
            <div className="c"><span className="p">!fav ekle</span> <span className="a">gece</span></div>
          </div>
        </div>
      </div>
    </section>
  );
};

/* ============ FAQ ============ */
const FAQ = ({ t }) => {
  const [open, setOpen] = useState(0);
  const f = t.faq;
  const items = [
    { q: f.q1, a: f.a1 },
    { q: f.q2, a: f.a2 },
    { q: f.q3, a: f.a3 },
    { q: f.q4, a: f.a4 },
    { q: f.q5, a: f.a5 },
    { q: f.q6, a: f.a6 },
  ];
  return (
    <section className="section" id="faq">
      <div className="shell">
        <div className="section-head">
          <div className="section-label">{f.label}</div>
          <h2 className="section-title">{f.titleA} <em>{f.titleB}</em></h2>
        </div>
        <div className="faq">
          {items.map((it, i) => (
            <div key={i} className={"faq-item" + (open === i ? " open" : "")} onClick={() => setOpen(open === i ? -1 : i)}>
              <div className="q-num">{String(i + 1).padStart(2, "0")}</div>
              <div>
                <h4>{it.q}</h4>
                <div className="faq-answer">{it.a}</div>
              </div>
              <div className="toggle-ic"><Ic.plus /></div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
};

/* ============ Final CTA ============ */
const CTA = ({ t }) => (
  <section className="section" id="cta" style={{ paddingBottom: 32 }}>
    <div className="shell">
      <div className="cta-card">
        <div className="section-label" style={{ justifyContent: "center", display: "inline-flex" }}>{t.cta.label}</div>
        <h2>
          {t.cta.h1}<br />
          {t.cta.h2} <em>{t.cta.h2em}</em><br />
          {t.cta.h3}
        </h2>
        <p>{t.cta.p}</p>
        <div className="cta-actions">
          <a className="btn btn-primary btn-lg" href="https://discord.com/oauth2/authorize?client_id=1225528616197296158&permissions=4503602847939670&scope=bot%20applications.commands" target="_blank" rel="noreferrer"><Ic.plus /> {t.cta.c1}</a>
          <a className="btn btn-lg" href="https://www.shopier.com/wsguardian/46204743" target="_blank" rel="noreferrer">
            <Ic.premium /> {t.cta.c2}
          </a>
        </div>
      </div>
    </div>
  </section>
);

/* ============ Footer ============ */
const Footer = ({ t }) => (
  <footer className="footer">
    <div className="shell">
      <div className="footer-grid">
        <div>
          <Brand small />
          <p style={{ marginTop: 14 }}>{t.foot.tag}</p>
        </div>
        <div>
          <h6>{t.foot.hProduct}</h6>
          <a href="#features">{t.nav.features}</a>
          <a href="#modules">{t.nav.modules}</a>
          <a href="#pricing">{t.nav.pricing}</a>
          <a href="#faq">{t.nav.faq}</a>
        </div>
        <div>
          <h6>{t.foot.hPanel}</h6>
          <a href="https://panel.wsguardian.com/">{t.foot.panelLogin}</a>
          <a href="https://www.shopier.com/wsguardian/46204743" target="_blank" rel="noreferrer">{t.foot.shopier}</a>
          <a href="#panel">{t.foot.license}</a>
        </div>
        <div>
          <h6>{t.foot.hLegal}</h6>
          <a href="https://panel.wsguardian.com/privacy" target="_blank" rel="noreferrer">{t.foot.privacy}</a>
          <a href="https://panel.wsguardian.com/terms" target="_blank" rel="noreferrer">{t.foot.terms}</a>
        </div>
      </div>
      <div className="footer-bottom">
        <span>{t.foot.copy}</span>
        <span className="links">
          <a href="https://panel.wsguardian.com/privacy" target="_blank" rel="noreferrer">{t.foot.short_privacy}</a>
          <a href="https://panel.wsguardian.com/terms" target="_blank" rel="noreferrer">{t.foot.short_terms}</a>
        </span>
      </div>
    </div>
  </footer>
);

/* ============ Tweaks ============ */
const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "accent": "violet",
  "hero": "split",
  "density": "default"
}/*EDITMODE-END*/;

const App = () => {
  const [tweaks, setTweak] = window.useTweaks
    ? window.useTweaks(TWEAK_DEFAULTS)
    : [TWEAK_DEFAULTS, () => {}];

  const [theme, setTheme] = useState(() => {
    try { return localStorage.getItem("wsg-theme") || "light"; } catch { return "light"; }
  });
  const toggleTheme = () => {
    const next = theme === "dark" ? "light" : "dark";
    setTheme(next);
    try { localStorage.setItem("wsg-theme", next); } catch {}
  };

  const [lang, setLang] = useState(() => {
    try { return localStorage.getItem("wsg-lang") || "tr"; } catch { return "tr"; }
  });
  const onLang = (code) => {
    setLang(code);
    try { localStorage.setItem("wsg-lang", code); } catch {}
    document.documentElement.lang = code;
  };

  useEffect(() => {
    document.documentElement.dataset.accent = tweaks.accent;
    document.documentElement.dataset.hero = tweaks.hero;
    document.documentElement.dataset.density = tweaks.density;
    document.documentElement.dataset.theme = theme;
  }, [tweaks, theme]);

  const TP = window.TweaksPanel;
  const TS = window.TweakSection;
  const TR = window.TweakRadio;

  const t = (window.WSG_T && window.WSG_T[lang]) || (window.WSG_T && window.WSG_T.tr) || {};

  return (
    <>
      <Nav theme={theme} onTheme={toggleTheme} lang={lang} onLang={onLang} t={t} />
      <Hero t={t} />
      <Strip t={t} />
      <Features t={t} />
      <Modules t={t} />
      <Pricing t={t} />
      <Panel t={t} />
      <FAQ t={t} />
      <CTA t={t} />
      <Footer t={t} />
      {TP && (
        <TP title="Tweaks">
          <TS title="Vurgu rengi">
            <TR value={tweaks.accent} onChange={v => setTweak("accent", v)}
              options={[
                { value: "violet", label: "Violet" },
                { value: "lime", label: "Lime" },
                { value: "amber", label: "Amber" },
                { value: "cyan", label: "Cyan" },
              ]} />
          </TS>
          <TS title="Hero düzeni">
            <TR value={tweaks.hero} onChange={v => setTweak("hero", v)}
              options={[
                { value: "split", label: "Split + Player" },
                { value: "minimal", label: "Minimal" },
                { value: "mono", label: "Mono başlık" },
              ]} />
          </TS>
          <TS title="Yoğunluk">
            <TR value={tweaks.density} onChange={v => setTweak("density", v)}
              options={[
                { value: "cozy", label: "Cozy" },
                { value: "default", label: "Default" },
                { value: "airy", label: "Airy" },
              ]} />
          </TS>
        </TP>
      )}
    </>
  );
};

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
