// OXIDE v3 — ABI-inspired fullpage layout
// Single-file React app. Loaded after copy.js + tweaks-panel.jsx

const { useState, useEffect, useRef, useMemo, useCallback } = React;

// ============== ICONS ==============
const Icon = {
  pc: (p) => <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" {...p}><rect x="2.5" y="4" width="19" height="13" rx="1.5"/><path d="M8.5 21h7M12 17v4"/></svg>,
  steam: (p) => <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="12" cy="12" r="9"/><circle cx="15.5" cy="9.5" r="2.6"/><circle cx="9" cy="14.5" r="1.6"/><path d="M3.4 14l5.2 1.5"/></svg>,
  epic: (p) => <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M5 3h14a2 2 0 0 1 2 2v12l-9 5-9-5V5a2 2 0 0 1 2-2zm3 5v8h2v-3h2v3h2V8h-2v3h-2V8H8zm9 0h-2v8h2V8z"/></svg>,
  apple: (p) => <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M16.5 11.4c0-2.5 2-3.7 2.1-3.8-1.2-1.7-3-1.9-3.6-2-1.6-.2-3 .9-3.8.9s-2-.9-3.3-.9c-1.7 0-3.3 1-4.2 2.5C2 11 3.2 15.7 5 18.3c.9 1.3 1.9 2.7 3.3 2.6 1.3-.1 1.8-.9 3.4-.9s2 .9 3.4.8c1.4 0 2.3-1.3 3.2-2.6.6-.9 1.1-1.9 1.5-3-1.6-.7-2.3-2.4-2.3-3.8zM14 4.6c.7-.9 1.2-2.1 1.1-3.3-1 0-2.3.7-3 1.5-.7.8-1.3 2-1.1 3.2 1.1.1 2.2-.6 3-1.4z"/></svg>,
  google: (p) => <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M3.6 2.6c-.4.4-.6 1-.6 1.7v15.4c0 .7.2 1.3.6 1.7l8.5-8.4-8.5-8.4zM13.5 13.4l2.7 2.7-9.7 5.5c-.3.2-.6.2-1 .2l8-8.4zM17.7 9l3.5 2c.7.4.7 1.6 0 2l-3.5 2-3-3 3-3zM5.5 1.7c.3 0 .6 0 1 .2l9.7 5.5-2.7 2.7-8-8.4z"/></svg>,
  bs: (p) => <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6zm-2 14h20v1.2H2V20zm5.5-9.6h2v4.8h-2v-4.8zm3.5 0h2v4.8h-2v-4.8zm3.5 0h2v4.8h-2v-4.8z"/></svg>,
  arrow: (p) => <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M1 7h12M8 2l5 5-5 5"/></svg>,
  arrowL: (p) => <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M13 7H1M6 2L1 7l5 5"/></svg>,
  triR: (p) => <svg width="9" height="10" viewBox="0 0 9 10" fill="currentColor" {...p}><path d="M0 0v10l9-5z"/></svg>,
  scrollDown: (p) => <svg width="14" height="20" viewBox="0 0 14 20" fill="none" stroke="currentColor" strokeWidth="1.4" {...p}><path d="M7 1v15M2 11l5 5 5-5"/></svg>,
  yt: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M23.5 6.5a3 3 0 00-2.1-2.1C19.6 4 12 4 12 4s-7.6 0-9.4.4A3 3 0 00.5 6.5C.1 8.3.1 12 .1 12s0 3.7.4 5.5a3 3 0 002.1 2.1c1.8.4 9.4.4 9.4.4s7.6 0 9.4-.4a3 3 0 002.1-2.1c.4-1.8.4-5.5.4-5.5s0-3.7-.4-5.5zM9.6 15.6V8.4l6.3 3.6-6.3 3.6z"/></svg>,
  x: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>,
  discord: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M19.6 4.5C18 3.7 16.3 3.2 14.6 3l-.2.4a13 13 0 00-4.9 0L9.3 3a16 16 0 00-5 1.5C1.4 9 .6 13.4 1 17.7c2 1.4 3.8 2.3 5.7 2.8.5-.6.9-1.3 1.2-2-.7-.3-1.3-.6-2-1l.5-.4a12 12 0 0011.2 0l.5.4a13 13 0 01-2 1c.4.7.8 1.4 1.3 2 1.9-.5 3.8-1.4 5.7-2.8.4-5-.9-9.3-3.5-13.2zM8.5 15.2c-1.2 0-2.1-1-2.1-2.3 0-1.2 1-2.2 2.1-2.2 1.2 0 2.2 1 2.2 2.2 0 1.2-1 2.3-2.2 2.3zm7 0c-1.1 0-2.1-1-2.1-2.3 0-1.2 1-2.2 2.1-2.2 1.2 0 2.2 1 2.2 2.2-.1 1.2-1 2.3-2.2 2.3z"/></svg>,
  tt: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M19.6 6.7c-1.4-.9-2.3-2.4-2.3-4.1V2H14v13c0 1.7-1.4 3-3 3s-3-1.4-3-3 1.3-3 3-3c.4 0 .7 0 1 .2v-3.4a6 6 0 00-1-.1c-3.4 0-6.2 2.8-6.2 6.3 0 3.5 2.8 6.3 6.3 6.3 3.5 0 6.2-2.8 6.2-6.3v-7c1.5 1 3.2 1.7 5 1.7V6.4c-1 0-2-.4-2.7-.9z"/></svg>,
  telegram: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M9.78 18.65l.28-4.23 7.68-6.92c.34-.31-.07-.46-.52-.19L7.74 13.3 3.64 12c-.88-.25-.89-.86.2-1.3l15.97-6.16c.73-.33 1.43.18 1.15 1.3l-2.72 12.81c-.19.91-.74 1.13-1.5.71L12.6 16.3l-1.99 1.93c-.23.23-.42.42-.83.42z"/></svg>,
  vk: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M22.5 7.4c.2-.5 0-.9-.7-.9h-2.4c-.6 0-.8.3-1 .6 0 0-1.2 2.9-2.9 4.8-.6.6-.8.7-1.1.7-.2 0-.4-.2-.4-.7v-4.5c0-.6-.2-.9-.7-.9h-3.7c-.4 0-.6.3-.6.5 0 .6.8.7.9 2.3v3.5c0 .8-.1.9-.4.9-.8 0-2.7-2.9-3.9-6.3-.2-.6-.5-.9-1.1-.9H1.9c-.7 0-.8.3-.8.6 0 .6.8 3.7 3.7 7.7 1.9 2.7 4.7 4.2 7.1 4.2 1.5 0 1.7-.3 1.7-.9v-2c0-.6.1-.7.6-.7.3 0 .9.2 2.2 1.4 1.5 1.5 1.7 2.2 2.6 2.2h2.4c.7 0 1-.3.8-1-.2-.7-1-1.6-2-2.7-.6-.7-1.4-1.4-1.7-1.8-.4-.5-.3-.7 0-1.2 0 0 3-4.2 3.3-5.6z"/></svg>,
  reddit: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M22 12c0-1.1-.9-2-2-2-.5 0-1 .2-1.4.6-1.4-.9-3.1-1.5-5-1.6l.9-4 2.8.6c0 .8.7 1.4 1.5 1.4s1.5-.7 1.5-1.5S19.6 4 18.8 4c-.6 0-1.1.3-1.4.8L14.3 4c-.2 0-.4 0-.5.4l-1 4.6c-1.9 0-3.6.6-5 1.6-.4-.4-.9-.6-1.4-.6C5.3 10 4.4 11 4.4 12c0 .8.5 1.5 1.1 1.8 0 .2-.1.5-.1.7 0 3.3 3.7 6 8.3 6s8.3-2.7 8.3-6c0-.2 0-.5-.1-.7.6-.3 1.1-1 1.1-1.8zM8.4 13.5c0-.8.7-1.5 1.5-1.5s1.5.7 1.5 1.5S10.7 15 9.9 15s-1.5-.7-1.5-1.5zm9.6 4c-1.2 1.2-3.4 1.3-4 1.3s-2.8-.1-4-1.3c-.2-.2-.2-.5 0-.7s.5-.2.7 0c.8.8 2.4 1 3.3 1s2.5-.3 3.3-1c.2-.2.5-.2.7 0s.2.5 0 .7zm-.1-2.4c-.8 0-1.5-.7-1.5-1.5s.7-1.5 1.5-1.5 1.5.7 1.5 1.5-.7 1.5-1.5 1.5z"/></svg>,
  twitch: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M4 2 2 6.5V20h6v3h3l3-3h4l5-5V2H4zm17 11-3 3h-5l-3 3v-3H6V4h15v9z"/><path d="M16 7h2v6h-2zm-5 0h2v6h-2z"/></svg>,
  instagram: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" {...p}><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" stroke="none"/></svg>,
  cart: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="9" cy="20" r="1.5"/><circle cx="18" cy="20" r="1.5"/><path d="M2 3h3l3 13h12l2-9H6"/></svg>,
  globe: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18"/></svg>,
  user: (p) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><circle cx="12" cy="8" r="4"/><path d="M3 21a9 9 0 0 1 18 0"/></svg>,
};

function fmt(n) { return n.toLocaleString("ru-RU").replace(/,/g, " "); }

// Live stats poller — polls the public API every 5s, with graceful fallback.
const STATS_API = "https://api.oxidesurvival.com/public/stats";
const STATS_FALLBACK = { totalOnline: 39241, totalServers: 1660, nextWipe: "2026-06-12T13:00:00" };

function useLiveStats() {
  const [stats, setStats] = useState(STATS_FALLBACK);
  useEffect(() => {
    let alive = true;
    const load = async () => {
      try {
        const r = await fetch(STATS_API, { cache: "no-store" });
        if (!r.ok) { console.warn("[OXIDE stats] HTTP", r.status); return; }
        const d = await r.json();
        if (!alive || !d) return;
        setStats((prev) => ({
          totalOnline: typeof d.totalOnline === "number" ? d.totalOnline : prev.totalOnline,
          totalServers: typeof d.totalServers === "number" ? d.totalServers : prev.totalServers,
          nextWipe: d.nextWipe || prev.nextWipe,
        }));
      } catch (e) { console.warn("[OXIDE stats] fetch failed:", e && e.message); }
    };
    load();
    const id = setInterval(load, 5000);
    return () => { alive = false; clearInterval(id); };
  }, []);
  return stats;
}

function OnlineWidget({ t, online }) {
  // Light drift between 5s polls so the number feels alive
  const [display, setDisplay] = useState(online);
  useEffect(() => { setDisplay(online); }, [online]);
  useEffect(() => {
    const id = setInterval(() => {
      setDisplay((v) => {
        const delta = Math.floor(Math.random() * 21) - 10; // -10..+10
        const drifted = v + delta;
        // never wander more than ~40 from the real value
        if (Math.abs(drifted - online) > 40) return online + (Math.random() < 0.5 ? -1 : 1) * Math.floor(Math.random() * 20);
        return drifted;
      });
    }, 1600);
    return () => clearInterval(id);
  }, [online]);
  return (
    <div className="online-widget" title="Online players">
      <span className="dot"/>
      <span className="num">{display.toLocaleString("ru-RU").replace(/,/g, " ")}</span>
      <span className="lbl">{t.online_lbl}</span>
    </div>
  );
}

function nextWipeDate(now = new Date()) {
  // Fallback only — anchor 15 May 2026 (Friday), every 4 weeks.
  const base = new Date(Date.UTC(2026, 4, 15));
  const ms28 = 28 * 24 * 60 * 60 * 1000;
  let d = new Date(base);
  while (d.getTime() <= now.getTime()) d = new Date(d.getTime() + ms28);
  return d;
}
function fmtWipe(d, lang) {
  // Use the visitor's own system locale → native date format for their region.
  try {
    const loc = (navigator.languages && navigator.languages[0]) || navigator.language;
    return new Intl.DateTimeFormat(loc || undefined, {
      day: "2-digit", month: "2-digit", year: "numeric"
    }).format(d);
  } catch (e) {
    const dd = String(d.getUTCDate()).padStart(2, "0");
    const mm = String(d.getUTCMonth() + 1).padStart(2, "0");
    return `${dd}.${mm}.${d.getUTCFullYear()}`;
  }
}

function WipeWidget({ t, lang, nextWipe }) {
  const parsed = nextWipe ? new Date(nextWipe) : null;
  const date = parsed && !isNaN(parsed.getTime()) ? parsed : nextWipeDate();
  return (
    <div className="wipe-widget" title="Global wipe date">
      <span className="wipe-flag"/>
      <span className="num">{fmtWipe(date, lang)}</span>
      <span className="lbl">{(t.hero_stat_wipe || "WIPE").toUpperCase()}</span>
    </div>
  );
}

function ServersWidget({ t, servers }) {
  return (
    <div className="servers-widget" title="Active servers">
      <span className="srv-ico"/>
      <span className="num">{servers.toLocaleString("ru-RU").replace(/,/g, " ")}</span>
      <span className="lbl">{t.servers_lbl}</span>
    </div>
  );
}

// ============== TOP NAV ==============
function TopNav({ lang, setLang, t, activePage, onJump, stats }) {
  const items = [
    { key: "about", label: t.nav_about, plus: true, page: 1 },
    { key: "shop", label: t.nav_shop_menu, plus: true, page: 2, accent: true },
    { key: "creators", label: t.nav_creator, plus: true, page: 3 },
    { key: "devices", label: t.nav_devices, plus: true, page: 4 },
    { key: "support", label: t.nav_support, plus: true, href: "https://support.playoxide.com/", activeOnPage: 5 },
    { key: "fankit", label: t.nav_fankit, plus: true, href: "https://art.playoxide.com/", shimmer: true },
  ];
  return (
    <nav className="nav">
      <a className="nav-logo" href="#" onClick={(e) => { e.preventDefault(); onJump(0); }}>
        <img className="brand" src="media/oxide-brand.png" alt="OXIDE Survival Island"/>
      </a>
      <div className="nav-menu">
        {items.map((it, i) => (
          it.href
            ? <a key={it.key} className={`nav-item ${it.accent ? "nav-shop" : ""} ${it.shimmer ? "nav-shimmer" : ""} ${it.activeOnPage !== undefined && activePage === it.activeOnPage ? "active" : ""}`} href={it.href} target="_blank" rel="noopener noreferrer">
                {it.label}{it.plus ? <span className="plus">+</span> : null}
              </a>
            : <a key={it.key} className={`nav-item ${activePage === it.page ? "active" : ""}`}
                 href="#" onClick={(e) => { e.preventDefault(); onJump(it.page); }}>
                {it.label}{it.plus ? <span className="plus">+</span> : null}
              </a>
        ))}
      </div>
      <div className="nav-right">
        <OnlineWidget t={t} online={stats.totalOnline}/>
        <ServersWidget t={t} servers={stats.totalServers}/>
        <WipeWidget t={t} lang={lang} nextWipe={stats.nextWipe}/>
      </div>
    </nav>
  );
}

// ============== RIGHT RAIL ==============
function RightRail({ activePage, total, onJump }) {
  return (
    <div className="rail">
      {Array.from({ length: total }).map((_, i) => (
        <div key={i}
          className={`rail-tick ${i === activePage ? "active" : ""}`}
          onClick={() => onJump(i)}>
          <span className="num">{String(i + 1).padStart(2, "0")}</span>
        </div>
      ))}
    </div>
  );
}

// ============== HERO (page 1) ==============
function HeroPage({ t, lang }) {
  return (
    <section className="page hero-wrap" data-screen-label="01 Hero">
      <div className="page-bg">
        <img src="media/hero-bg.jpg" alt="" decoding="async" fetchpriority="high" style={{width:"100%",height:"100%",objectFit:"cover"}}/>
      </div>
      <div className="page-noise"/>

      <div className="page-content hero-layout">
        <div className="hero-center">
          <h1 className="hero-headline" data-text={t.hero_headline}>{t.hero_headline}</h1>
          {t.hero_sub && <div className="hero-sub">{t.hero_sub}</div>}
          <div className="hero-tagline-avail">{t.hero_tagline}</div>
        </div>

        <div className="hero-promo">
          <img src="media/promo-protocol-shadow.jpg" alt=""/>
          <div className="pad">
            <div className="ev">{t.hero_promo_eye}</div>
            <div className="tt">{t.hero_promo_title}</div>
          </div>
        </div>

        <div className="hero-bottom">
          <div className="hero-stores">
            <a className="store-btn" href="https://apps.apple.com/us/app/oxide-survival-island-online/id1579424683" target="_blank" rel="noopener noreferrer"><span className="icon icon-img"><img src="media/icon-appstore.png" alt="App Store"/></span>
              <span className="text"><span className="small">{t.dl_on}</span><span className="big">App Store</span></span>
            </a>
            <a className="store-btn" href="https://play.google.com/store/apps/details?id=com.catsbit.oxidesurvivalisland&" target="_blank" rel="noopener noreferrer"><span className="icon icon-img"><img src="media/icon-googleplay.png" alt="Google Play"/></span>
              <span className="text"><span className="small">{t.dl_get}</span><span className="big">Google Play</span></span>
            </a>
            <a className="store-btn bs" href="https://oxi.de/pc" target="_blank" rel="noopener noreferrer">
              <span className="icon"><Icon.pc width="30" height="30"/></span>
              <span className="text"><span className="small">{t.dl_on}</span><span className="big">PC/MAC</span></span>
            </a>
          </div>
        </div>
        <div className="scroll-hint hero-scroll-hint">
          <span>{t.scroll}</span>
          <Icon.scrollDown/>
        </div>
      </div>
    </section>
  );
}

// ============== FEATURE SLIDER (page 2) ==============
function FeaturesPage({ t, lang }) {
  const slides = useMemo(() => [
    { bg: "media/pillar-01-craft.jpg",  ttl: t.f01.title, sub: t.f01.sub, body: t.f01.body },
    { bg: "media/pillar-02-bases.png",  ttl: t.f02.title, sub: t.f02.sub, body: t.f02.body },
    { bg: "media/pillar-03-pvp.jpg",    ttl: t.f03.title, sub: t.f03.sub, body: t.f03.body },
    { bg: "media/pillar-04-clans.png",  ttl: t.f04.title, sub: t.f04.sub, body: t.f04.body },
    { bg: "media/media-gameplay.png",   ttl: t.f05.title, sub: t.f05.sub, body: t.f05.body },
    { bg: "media/feat-06-wipes.png",    ttl: t.f06.title, sub: t.f06.sub, body: t.f06.body },
  ], [t]);

  const DURATION = 10000; // 10s per slide
  const [i, setI] = useState(0);
  const [progress, setProgress] = useState(0); // 0..1 for current slide
  const [inView, setInView] = useState(false);
  const sectionRef = useRef(null);
  const max = slides.length;

  // Observe visibility — only tick when section is the active page
  useEffect(() => {
    const el = sectionRef.current;
    if (!el) return;
    const io = new IntersectionObserver(
      (entries) => entries.forEach((e) => setInView(e.intersectionRatio >= 0.5)),
      { threshold: [0, 0.5, 1] }
    );
    io.observe(el);
    return () => io.disconnect();
  }, []);

  // Drive progress with rAF; advance when full
  useEffect(() => {
    if (!inView) return;
    let raf, start = performance.now() - progress * DURATION;
    const tick = (now) => {
      const p = Math.min(1, (now - start) / DURATION);
      setProgress(p);
      if (p >= 1) {
        setI((v) => (v + 1) % max);
        setProgress(0);
        start = performance.now();
      }
      raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
    // eslint-disable-next-line
  }, [inView, i, max]);

  const goTo = (idx) => { setI(idx); setProgress(0); };
  const prev = () => { setI((v) => (v - 1 + max) % max); setProgress(0); };
  const next = () => { setI((v) => (v + 1) % max); setProgress(0); };
  const cur = slides[i];

  return (
    <section className="page" data-screen-label="02 Features" ref={sectionRef}>
      <div className="page-bg feat-bg">
        {slides.map((s, idx) => (
          <img
            key={s.bg}
            src={s.bg}
            alt=""
            className="feat-bg-layer"
            style={{ opacity: idx === i ? 1 : 0 }}
            decoding="async"
            loading="eager"
          />
        ))}
      </div>
      <div className="page-noise"/>

      <div className="feat-stage">
        <div className="feat-content">
          <div className="feat-text">
            <div className="feat-title-wrap">
              <div>
                <div className="feat-title">{cur.ttl}<span className="red-tri"/></div>
                <div className="feat-sub">{cur.sub}</div>
              </div>
            </div>
            <div className="feat-divider"/>
            <p className="feat-desc">{cur.body}</p>
          </div>
        </div>

        <button className="feat-prev" onClick={prev}>
          <Icon.arrowL/><span>{t.feat_prev}</span>
        </button>
        <button className="feat-next" onClick={next}>
          <span>{t.feat_next}</span><Icon.arrow/>
        </button>

        <div className="feat-scrub">
          <div className="feat-bars">
            {slides.map((s, idx) => {
              const fill = idx < i ? 1 : idx === i ? progress : 0;
              return (
                <div key={idx} className={`fb ${idx === i ? "active" : ""}`} onClick={() => goTo(idx)}>
                  <div className="fb-num">{String(idx + 1).padStart(2, "0")}</div>
                  <div className="fb-track"><div className="fb-fill" style={{ width: `${fill * 100}%` }}/></div>
                </div>
              );
            })}
          </div>
        </div>

      </div>
    </section>
  );
}

// ============== SNEAK PEEK (page 3) ==============
function PeekPage({ t, lang }) {
  const [tab, setTab] = useState(0);
  const tabs = t.peek_tabs;
  const cur = tabs[tab];

  return (
    <section className="page" data-screen-label="03 Sneak Peek">
      <div className="page-bg" style={{ background: "#0a0a0c" }}>
        <img src="media/media-concept.png" alt="" style={{ opacity: .25, filter: "brightness(0.5) blur(4px)" }}/>
      </div>
      <div className="page-noise"/>

      <div className="peek-wrap">
        <div className="section-head">
          <div>
            <div className="section-title">
              {t.peek_title}<span className="red-tri"/>
            </div>
            <div className="section-title-sub">{t.peek_subtitle}</div>
          </div>
        </div>
        <div className="section-divider"/>

        <div className="peek-stage">
          <div className="peek-big peek-big-xl">
            {tabs.map((tt, idx) => (
              <img
                key={idx}
                src={tt.img}
                alt=""
                className="peek-bg-layer"
                style={{ opacity: idx === tab ? 1 : 0 }}
                decoding="async"
                loading="eager"
              />
            ))}
            <div className="corner tl"/><div className="corner tr"/>
            <div className="corner bl"/><div className="corner br"/>
            <div className="peek-stage-cap">
              <div className="peek-stage-eye">{String(tab + 1).padStart(2, "0")} / {String(tabs.length).padStart(2, "0")}  ·  {cur.tabLbl}</div>
              <div className="peek-stage-ttl">{cur.modeTitle}</div>
              <div className="peek-stage-sub">{cur.caption}</div>
            </div>
          </div>

          <div className="peek-cards">
            {tabs.map((tt, i) => (
              <button key={i} className={`peek-card ${tab === i ? "active" : ""}`} onClick={() => setTab(i)}>
                <div className="peek-card-img">
                  <img src={tt.tabImg} alt=""/>
                </div>
                <div className="peek-card-txt">
                  <div className="peek-card-num">{String(i + 1).padStart(2, "0")}</div>
                  <div className="peek-card-ttl">{tt.tabHead || tt.tabLbl}</div>
                  <div className="peek-card-sub">{tt.tabSub}</div>
                </div>
              </button>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

// ============== NEWS + COMMUNITY (page 4) ==============
function NewsPage({ t, lang }) {
  const [active, setActive] = useState(0);
  const items = t.news_items;
  const cur = items[active];

  return (
    <section className="page" data-screen-label="04 News">
      <div className="page-bg" style={{ background: "linear-gradient(180deg, #1c1410, #0c0a0a)" }}>
        <img src="media/media-stream.png" alt="" style={{ opacity: .25, filter: "blur(2px) brightness(0.5)" }}/>
      </div>
      <div className="page-noise"/>

      <div className="news-wrap">
        {/* NEWS BLOCK */}
        <div className="section-head">
          <div>
            <div className="section-title">{t.news_title}<span className="red-tri"/></div>
            <div className="section-title-sub">{t.news_subtitle}</div>
          </div>
        </div>
        <div className="section-divider"/>

        <div className="news-grid">
          {/* LIST (left) */}
          <div className="news-list">
            <div className="news-list-head">{t.news_update_head}</div>
            {items.map((r, i) => (
              <button
                key={i}
                className={`news-row ${active === i ? "active" : ""}`}
                onClick={() => setActive(i)}
                type="button"
              >
                <span className={`badge ${r.tag.toLowerCase()}`}>{(t.news_tags && t.news_tags[r.tag]) || r.tag}</span>
                <span className="ttl">{r.title}</span>
                <span className="date">{r.date}</span>
              </button>
            ))}
          </div>

          {/* PREVIEW (right) */}
          <div className="news-preview">
            <div className="news-preview-img">
              {items.map((r, idx) => (
                <img
                  key={idx}
                  src={r.img}
                  alt=""
                  className="news-bg-layer"
                  style={{ opacity: idx === active ? 1 : 0 }}
                  decoding="async"
                  loading="eager"
                />
              ))}
              <div className="corner tl"/><div className="corner tr"/>
              <div className="corner bl"/><div className="corner br"/>
              <div className="news-preview-cap">
                {cur.headlinePre}<span className="accent">{cur.headlineAcc}</span>{cur.headlinePost}
              </div>
            </div>
            <div className="news-preview-foot">
              <div className="news-preview-meta">
                <span className={`badge ${cur.tag.toLowerCase()}`}>{(t.news_tags && t.news_tags[cur.tag]) || cur.tag}</span>
                <span className="date">{cur.date}</span>
              </div>
              <div className="news-preview-body">{cur.body}</div>
            </div>
          </div>
        </div>

        {/* COMMUNITY BLOCK */}
        <div className="creator-block">
          <div className="section-head">
            <div>
              <div className="section-title">{t.community_title}<span className="red-tri"/></div>
              <div className="section-title-sub">{t.community_subtitle}</div>
            </div>
          </div>
          <div className="section-divider"/>

          <div className="community-banner">
            <img src="media/community-banner.jpg" alt="OXIDE community"/>
            <div className="community-banner-grid"/>
            <div className="community-banner-scan"/>
            <div className="community-banner-meta">
              <span className="cb-tag">{t.cb_tag}</span>
              <span className="cb-id">{t.cb_id}</span>
            </div>
          </div>

          <div className="community-grid">
            {t.community_socials.map((s, i) => (
              <a key={i} className={`community-card community-${s.kind}`} href={s.href} target="_blank" rel="noopener noreferrer">
                <div className="community-icon">
                  {s.kind === "discord" && <Icon.discord/>}
                  {s.kind === "yt" && <Icon.yt/>}
                  {s.kind === "tt" && <Icon.tt/>}
                  {s.kind === "twitch" && <Icon.twitch/>}
                  {s.kind === "telegram" && <Icon.telegram/>}
                  {s.kind === "instagram" && <Icon.instagram/>}
                </div>
                <div className="community-txt">
                  <div className="community-name">{s.name}</div>
                  <div className="community-sub">{s.sub}</div>
                </div>
                <div className="community-arrow">→</div>
              </a>
            ))}
          </div>

          {/* CREATOR PROGRAM CALLOUT */}
          <a className="creator-program" href="https://creators.playoxide.com/" target="_blank" rel="noopener noreferrer">
            <div className="creator-program-bg">
              <img src="media/media-stream.png" alt=""/>
            </div>
            <div className="creator-program-content">
              <div className="creator-program-eye">{t.creator_program_eyebrow}<span className="red-tri"/></div>
              <div className="creator-program-title">{t.creator_program_title}</div>
              <div className="creator-program-body">{t.creator_program_body}</div>
            </div>
            <div className="creator-program-cta">
              {t.creator_program_cta}<span className="arrow">→</span>
            </div>
          </a>
        </div>
      </div>
    </section>
  );
}

// ============== SHOP (new) ==============
function ShopPage({ t, lang }) {
  return (
    <section className="page" data-screen-label="03 Shop">
      <div className="page-bg" style={{ background: "linear-gradient(180deg,#1b0d2c 0%,#0a0a0c 100%)" }}>
        <img src="media/shop-hero.png" alt="" style={{ objectPosition: "left center" }}/>
      </div>
      <div className="page-noise"/>
      <div className="shop-wrap">
        <div className="shop-content">
          <div className="section-title">{t.shop_title}<span className="red-tri"/></div>
          <div className="section-title-sub">{t.shop_subtitle}</div>
          <div className="ac-divider"/>
          <p className="ac-body" style={{ maxWidth: 560 }}>{t.shop_body}</p>
          <ul className="shop-list">
            {t.shop_bullets.map((b, i) => <li key={i}><span className="bullet-dot"/>{b}</li>)}
          </ul>
          <a className="ac-cta shop-cta" href="https://shop.playoxide.com/" target="_blank" rel="noopener noreferrer">🛒 {t.shop_cta}</a>
        </div>
      </div>
    </section>
  );
}

// ============== COMMUNITY (new dedicated page) ==============
function CommunityPage({ t, lang }) {
  return (
    <section className="page community-page" data-screen-label="04 Community">
      <div className="page-bg" style={{ background: "linear-gradient(180deg, #1c1410, #0c0a0a)" }}/>
      <div className="page-noise"/>
      <div className="news-wrap community-tight">
        <div className="section-head">
          <div>
            <div className="section-title">{t.community_title}<span className="red-tri"/></div>
            <div className="section-title-sub">{t.community_subtitle}</div>
          </div>
        </div>

        <div className="community-banner">
          <img src="media/community-banner.jpg" alt=""/>
          <div className="community-banner-grid"/>
          <div className="community-banner-scan"/>
          <div className="community-banner-meta">
            <span className="cb-tag">{t.cb_tag}</span>
            <span className="cb-id">{t.cb_id}</span>
          </div>
        </div>

        <div className="community-grid community-grid-compact">
          {t.community_socials.map((s, i) => (
            <a key={i} className={`community-card community-${s.kind}`} href={s.href} target="_blank" rel="noopener noreferrer">
              <div className="community-icon">
                {s.kind === "discord" && <Icon.discord/>}
                {s.kind === "yt" && <Icon.yt/>}
                {s.kind === "tt" && <Icon.tt/>}
                {s.kind === "twitch" && <Icon.twitch/>}
                {s.kind === "telegram" && <Icon.telegram/>}
                {s.kind === "instagram" && <Icon.instagram/>}
              </div>
              <div className="community-txt">
                <div className="community-name">{s.name}</div>
                <div className="community-sub">{s.sub}</div>
              </div>
              <div className="community-arrow">→</div>
            </a>
          ))}
        </div>

        <a className="creator-program creator-program-prominent" href="https://creators.playoxide.com/" target="_blank" rel="noopener noreferrer">
          <div className="creator-program-content">
            <div className="creator-program-eye">{t.creator_program_eyebrow}<span className="red-tri"/></div>
            <div className="creator-program-title">{t.creator_program_title}</div>
          </div>
          <div className="creator-program-cta creator-program-cta-big">
            {t.creator_program_cta}<span className="arrow">→</span>
          </div>
        </a>
      </div>
    </section>
  );
}

// ============== INCLUSIVE PLATFORMS (campfire) ==============
function PlatformsPage({ t, lang }) {
  return (
    <section className="page" data-screen-label="05 Platforms">
      <div className="page-bg">
        <img src="media/campfire-bg.jpg" alt="" style={{width:"100%",height:"100%",objectFit:"cover"}}/>
      </div>
      <div className="page-noise"/>
      <div className="ac-wrap platforms-wrap">
        <div className="ac-content platforms-content">
          <div className="ac-title">{t.platforms_title}<span className="red-tri"/></div>
          <div className="section-title-sub">{t.platforms_subtitle}</div>
          <div className="ac-divider"/>
          <p className="ac-body" style={{maxWidth:560}}>{t.platforms_body}</p>
          <div className="platforms-badge">
            <span className="pb-dot"/>
            <span className="pb-text">{t.platforms_tested}</span>
          </div>
          <ul className="shop-list" style={{marginTop:14}}>
            {t.platforms_bullets.map((b,i) => <li key={i}><span className="bullet-dot"/>{b}</li>)}
          </ul>
          <div className="hero-stores platforms-stores">
            <a className="store-btn" href="https://apps.apple.com/us/app/oxide-survival-island-online/id1579424683" target="_blank" rel="noopener noreferrer">
              <span className="icon icon-img"><img src="media/icon-appstore.png" alt="App Store"/></span>
              <span className="text"><span className="small">{t.dl_on}</span><span className="big">App Store</span></span>
            </a>
            <a className="store-btn" href="https://play.google.com/store/apps/details?id=com.catsbit.oxidesurvivalisland&" target="_blank" rel="noopener noreferrer">
              <span className="icon icon-img"><img src="media/icon-googleplay.png" alt="Google Play"/></span>
              <span className="text"><span className="small">{t.dl_get}</span><span className="big">Google Play</span></span>
            </a>
          </div>
        </div>
      </div>
    </section>
  );
}

// ============== ANTI-CHEAT + FOOTER (page 5) ==============
function AntiCheatPage({ t, lang }) {
  return (
    <section className="page" data-screen-label="05 Anti-cheat">
      <div className="page-bg fair-bg">
        <img src="media/fairplay-bg.jpg" alt=""/>
      </div>
      <div className="page-noise"/>

      <div className="ac-wrap">
        <div className="ac-content">
          <div className="ac-title">{t.ac_title}<span className="red-tri"/></div>
          <div className="ac-divider"/>

          <div className="ac-block">
            <h4>{t.ac_b1.title}</h4>
            <p>{t.ac_b1.body}</p>
          </div>

          <a className="ac-cta" href="https://support.playoxide.com/hc/en/oxide/articles/report-a-cheater-37" target="_blank" rel="noopener noreferrer">📝 {t.ac_cta}</a>
        </div>
      </div>

      <footer className="footer">
        <div className="f-brand">
          <div className="f-logo">
            <img className="brand" src="media/oxide-brand.png" alt="OXIDE Survival Island"/>
          </div>
        </div>
        <div className="copyright">
          <a href="https://hyperhug.com/privacy" target="_blank" rel="noopener noreferrer">{t.priv}</a>
          <span className="sep">·</span>
          <a href="https://hyperhug.com/terms" target="_blank" rel="noopener noreferrer">{t.terms}</a>
        </div>
        <div className="f-community">
          <span className="lbl">{t.join}</span>
          <a href="https://oxi.de/ds" target="_blank" rel="noopener noreferrer"><Icon.discord/></a>
          <a href="https://oxi.de/yt" target="_blank" rel="noopener noreferrer"><Icon.yt/></a>
          <a href="https://oxi.de/tt" target="_blank" rel="noopener noreferrer"><Icon.tt/></a>
          <a href="https://oxi.de/tw" target="_blank" rel="noopener noreferrer"><Icon.twitch/></a>
          <a href="https://oxi.de/tg" target="_blank" rel="noopener noreferrer"><Icon.telegram/></a>
          <a href="https://oxi.de/ig" target="_blank" rel="noopener noreferrer"><Icon.instagram/></a>
        </div>
      </footer>
    </section>
  );
}

// ============== COOKIE BANNER ==============
function Cookie({ t, onClose }) {
  return (
    <div className="cookie">
      <div className="ck-text">
        <b>{t.ck_title}</b><br/>
        {t.ck_body}
      </div>
      <div className="ck-btns">
        <button className="ck-btn ghost" onClick={onClose}>{t.ck_custom}</button>
        <button className="ck-btn ghost" onClick={onClose}>{t.ck_reject}</button>
        <button className="ck-btn" onClick={onClose}>{t.ck_accept}</button>
      </div>
    </div>
  );
}

// ============== APP ==============
function App() {
  const [lang, setLang] = useState(() => {
    // RU only for users from RU/KZ/UZ/BY/TM — detected via browser timezone.
    if (typeof Intl !== "undefined") {
      try {
        const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || "";
        const ruZones = [
          "Europe/Moscow","Europe/Kaliningrad","Europe/Samara","Europe/Simferopol","Europe/Volgograd","Europe/Saratov","Europe/Astrakhan","Europe/Kirov","Europe/Ulyanovsk",
          "Asia/Yekaterinburg","Asia/Omsk","Asia/Novosibirsk","Asia/Novokuznetsk","Asia/Krasnoyarsk","Asia/Irkutsk","Asia/Yakutsk","Asia/Vladivostok","Asia/Khandyga","Asia/Sakhalin","Asia/Ust-Nera","Asia/Magadan","Asia/Srednekolymsk","Asia/Kamchatka","Asia/Anadyr","Asia/Chita","Asia/Tomsk","Asia/Barnaul",
          "Asia/Almaty","Asia/Aqtau","Asia/Aqtobe","Asia/Atyrau","Asia/Oral","Asia/Qostanay","Asia/Qyzylorda",
          "Asia/Tashkent","Asia/Samarkand",
          "Europe/Minsk",
          "Asia/Ashgabat"
        ];
        if (ruZones.indexOf(tz) !== -1) return "ru";
      } catch (e) {}
    }
    return "en";
  });
  const [activePage, setActivePage] = useState(0);
  const [cookieOpen, setCookieOpen] = useState(true);
  const stageRef = useRef(null);
  const TOTAL = 6;
  const t = window.OXIDE_COPY_V3[lang];
  const stats = useLiveStats();

  // active page tracking via scroll
  useEffect(() => {
    const stage = stageRef.current;
    if (!stage) return;
    const onScroll = () => {
      const h = window.innerHeight;
      const idx = Math.round(stage.scrollTop / h);
      setActivePage(Math.min(TOTAL - 1, Math.max(0, idx)));
    };
    stage.addEventListener("scroll", onScroll, { passive: true });
    return () => stage.removeEventListener("scroll", onScroll);
  }, []);

  const jump = useCallback((i) => {
    const stage = stageRef.current;
    if (!stage) return;
    stage.scrollTo({ top: i * window.innerHeight, behavior: "smooth" });
  }, []);

  // keyboard nav
  useEffect(() => {
    const onKey = (e) => {
      if (e.key === "ArrowDown" || e.key === "PageDown") {
        e.preventDefault(); jump(Math.min(TOTAL - 1, activePage + 1));
      } else if (e.key === "ArrowUp" || e.key === "PageUp") {
        e.preventDefault(); jump(Math.max(0, activePage - 1));
      }
    };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, [activePage, jump]);

  return (
    <>
      <TopNav lang={lang} setLang={setLang} t={t} activePage={activePage} onJump={jump} stats={stats}/>
      <RightRail activePage={activePage} total={TOTAL} onJump={jump}/>
      <div className="stage" ref={stageRef}>
        <HeroPage t={t} lang={lang}/>
        <FeaturesPage t={t} lang={lang}/>
        <ShopPage t={t} lang={lang}/>
        <CommunityPage t={t} lang={lang}/>
        <PlatformsPage t={t} lang={lang}/>
        <AntiCheatPage t={t} lang={lang}/>
      </div>
      {cookieOpen && <Cookie t={t} onClose={() => setCookieOpen(false)}/>}
    </>
  );
}

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