/* ═══════════════ Closink · SHARED (atoms, nav, footer, legal shell) ═══════════════ */
const { useState, useEffect, useRef, useCallback } = React;
const HOME = 'index.html';

/* ----- icon factory (lucide-style, inline SVG) ----- */
const Ic = ({ d, s = 22, c = 'currentColor', sw = 1.7, fill = 'none', style }) => (
  <svg viewBox="0 0 24 24" width={s} height={s} fill={fill} stroke={fill === 'none' ? c : 'none'}
    strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round" style={style}>{d}</svg>
);
const IconShield   = (p) => <Ic {...p} d={<path d="M12 3l7.5 2.7v5.3c0 4.6-3.2 7.9-7.5 8.7-4.3-.8-7.5-4.1-7.5-8.7V5.7z"/>} />;
const IconShieldOk = (p) => <Ic {...p} d={<><path d="M12 3l7.5 2.7v5.3c0 4.6-3.2 7.9-7.5 8.7-4.3-.8-7.5-4.1-7.5-8.7V5.7z"/><path d="M8.6 12.1l2.2 2.2 4.6-4.8"/></>} />;
const ShieldFill   = ({ s = 22, c = '#fff' }) => <svg viewBox="0 0 24 24" width={s} height={s}><path d="M12 2.5l8 2.9v5.6c0 4.9-3.4 8.4-8 9.2-4.6-.8-8-4.3-8-9.2V5.4z" fill={c}/></svg>;
const IconLock     = (p) => <Ic {...p} d={<><rect x="4.5" y="11" width="15" height="9.5" rx="2.2"/><path d="M8 11V8a4 4 0 018 0v3"/></>} />;
const IconMapPin   = (p) => <Ic {...p} d={<><path d="M12 21c4.5-4.2 7-7.4 7-11a7 7 0 10-14 0c0 3.6 2.5 6.8 7 11z"/><circle cx="12" cy="10" r="2.6"/></>} />;
const IconHeart    = (p) => <Ic {...p} d={<path d="M12 20s-7-4.4-9.2-9C1.3 8 3 4.7 6.2 4.7c2 0 3.2 1.2 3.8 2.3.6-1.1 1.8-2.3 3.8-2.3 3.2 0 4.9 3.3 3.4 6.3C19 15.6 12 20 12 20z"/>} />;
const HeartFill    = ({ s = 22, c = '#EF4444' }) => <svg viewBox="0 0 24 24" width={s} height={s}><path d="M12 20.5S3.6 15.5 2.2 9.7C1.3 6 3.4 3.5 6.3 3.5c2 0 3.5 1.1 4.4 2.6.9-1.5 2.4-2.6 4.4-2.6 2.9 0 5 2.5 4.1 6.2C20.4 15.5 12 20.5 12 20.5z" fill={c}/></svg>;
const IconBell     = (p) => <Ic {...p} d={<><path d="M6 9a6 6 0 0112 0c0 5 2 6 2 6H4s2-1 2-6z"/><path d="M10.5 20a2 2 0 003 0"/></>} />;
const IconCheck    = (p) => <Ic {...p} d={<path d="M5 12.5l4.2 4.3L19 6.5"/>} />;
const IconArrowR   = (p) => <Ic {...p} d={<><path d="M4 12h15"/><path d="M13 6l6 6-6 6"/></>} />;
const IconArrowL   = (p) => <Ic {...p} d={<><path d="M20 12H5"/><path d="M11 6l-6 6 6 6"/></>} />;
const IconEye      = (p) => <Ic {...p} d={<><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z"/><circle cx="12" cy="12" r="3"/></>} />;
const IconEyeOff   = (p) => <Ic {...p} d={<><path d="M3 3l18 18"/><path d="M10.6 5.2A9.7 9.7 0 0112 5c6.5 0 10 7 10 7a16 16 0 01-3.3 4M6.2 6.3A16 16 0 002 12s3.5 7 10 7a9.6 9.6 0 004-.85"/></>} />;
const IconUsers    = (p) => <Ic {...p} d={<><circle cx="9" cy="8" r="3.2"/><path d="M3 20c0-3.3 2.7-5.5 6-5.5s6 2.2 6 5.5"/><path d="M16 4.2a3.2 3.2 0 010 6.1M21 20c0-2.7-1.6-4.6-3.8-5.2"/></>} />;
const IconSpark    = (p) => <Ic {...p} d={<path d="M12 3l1.8 5.4L19 10l-5.2 1.6L12 17l-1.8-5.4L5 10l5.2-1.6z"/>} />;
const IconStar     = ({ s = 16, c = '#E6B450' }) => <svg viewBox="0 0 24 24" width={s} height={s}><path d="M12 2.5l2.9 6 6.6.6-5 4.4 1.5 6.5L12 17.6 6 20l1.5-6.5-5-4.4 6.6-.6z" fill={c}/></svg>;
const IconFinger   = (p) => <Ic {...p} d={<><path d="M12 11v3a4 4 0 01-4 4"/><path d="M8 11a4 4 0 018 0v2a7 7 0 01-1 3.6"/><path d="M5 13v-2a7 7 0 0114 0v2"/></>} />;
const IconGlobe    = (p) => <Ic {...p} d={<><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.6 2.6 2.6 15.4 0 18M12 3c-2.6 2.6-2.6 15.4 0 18"/></>} />;
const IconMail     = (p) => <Ic {...p} d={<><rect x="3" y="5" width="18" height="14" rx="2.4"/><path d="M4 7l8 6 8-6"/></>} />;
const IconPhone    = (p) => <Ic {...p} d={<path d="M5 4h3.5l1.5 4.5-2 1.5a12 12 0 005.5 5.5l1.5-2 4.5 1.5V19a2 2 0 01-2 2A16 16 0 014 6a2 2 0 011-2z"/>} />;
const IconClock    = (p) => <Ic {...p} d={<><circle cx="12" cy="12" r="9"/><path d="M12 7.5V12l3 2"/></>} />;
const IconDoc      = (p) => <Ic {...p} d={<><path d="M6 3h7l5 5v13a1 1 0 01-1 1H6a1 1 0 01-1-1V4a1 1 0 011-1z"/><path d="M13 3v5h5M8.5 13h7M8.5 16.5h7"/></>} />;
const IconKey      = (p) => <Ic {...p} d={<><circle cx="8" cy="14" r="3.5"/><path d="M10.5 11.5L20 2M16 6l2.5 2.5M13.5 8.5L16 11"/></>} />;
const IconServer   = (p) => <Ic {...p} d={<><rect x="3.5" y="4" width="17" height="7" rx="2"/><rect x="3.5" y="13" width="17" height="7" rx="2"/><path d="M7 7.5h.01M7 16.5h.01"/></>} />;
const IconLayers   = (p) => <Ic {...p} d={<><path d="M12 3l9 5-9 5-9-5z"/><path d="M3 13l9 5 9-5"/></>} />;
const IconCookie   = (p) => <Ic {...p} d={<><path d="M12 3a9 9 0 109 9 3.2 3.2 0 01-3.4-3.4A3.2 3.2 0 0114 5.4 3 3 0 0112 3z"/><path d="M9 10h.01M14 14h.01M9.5 15.5h.01M16 9h.01"/></>} />;
const IconScale    = (p) => <Ic {...p} d={<><path d="M12 4v16M7 20h10M12 6l-6 2 2.4 4.5a3 3 0 01-4.8 0L6 8M18 8l2.4 4.5a3 3 0 01-4.8 0L18 8l-6-2"/></>} />;
const IconShare    = (p) => <Ic {...p} d={<><circle cx="6" cy="12" r="2.4"/><circle cx="17" cy="6" r="2.4"/><circle cx="17" cy="18" r="2.4"/><path d="M8.2 11l6.6-3.6M8.2 13l6.6 3.6"/></>} />;
const IconFlag     = (p) => <Ic {...p} d={<><path d="M5 21V4M5 5h11l-1.5 3L16 11H5"/></>} />;
const IconMinimize = (p) => <Ic {...p} d={<><path d="M4 8V5a1 1 0 011-1h3M20 8V5a1 1 0 00-1-1h-3M4 16v3a1 1 0 001 1h3M20 16v3a1 1 0 01-1 1h-3"/></>} />;

/* ----- shared atoms ----- */
const Eyebrow = ({ children, color = '#3678F9', dot = true }) => (
  <span className="inline-flex items-center gap-2 mono text-[12px] font-semibold tracking-[0.22em] uppercase whitespace-nowrap" style={{ color }}>
    {dot && <span className="w-1.5 h-1.5 rounded-full" style={{ background: color, boxShadow: `0 0 10px ${color}` }}></span>}
    {children}
  </span>
);
const Glass = ({ children, className = '', style }) => (
  <div className={`glass glass-edge rounded-3xl ${className}`} style={style}>{children}</div>
);
const PillBadge = ({ icon, children, tone = 'cyan' }) => {
  const map = {
    cyan:  ['rgba(56,189,248,.14)', 'rgba(56,189,248,.36)', '#0369A1'],
    green: ['rgba(34,197,94,.14)', 'rgba(34,197,94,.38)', '#15803D'],
    gold:  ['rgba(230,180,80,.16)', 'rgba(230,180,80,.46)', '#B45309'],
    red:   ['rgba(239,68,68,.12)', 'rgba(239,68,68,.4)', '#DC2626'],
    blue:  ['rgba(54,120,249,.12)', 'rgba(54,120,249,.34)', '#1D4ED8'],
  }[tone];
  return (
    <span className="inline-flex items-center gap-2 rounded-full px-3.5 py-1.5 text-[13px] font-semibold whitespace-nowrap"
      style={{ background: map[0], border: `1px solid ${map[1]}`, color: map[2] }}>
      {icon}{children}
    </span>
  );
};

/* ----- aurora / mesh background blobs ----- */
const Aurora = ({ variant = 'blue' }) => {
  const sets = {
    blue: [['#1D4ED8', '8%', '6%', 560], ['#38BDF8', '78%', '14%', 460], ['#7C5CFC', '52%', '70%', 520]],
    cyan: [['#38BDF8', '70%', '4%', 520], ['#1D4ED8', '6%', '40%', 560]],
    gold: [['#E6B450', '50%', '0%', 540], ['#1D4ED8', '14%', '60%', 460]],
    rose: [['#E11D48', '60%', '8%', 520], ['#7C5CFC', '10%', '64%', 460]],
  }[variant];
  return (
    <div className="absolute inset-0 overflow-hidden pointer-events-none" aria-hidden="true">
      {sets.map(([c, l, t, sz], i) => (
        <div key={i} className="absolute rounded-full" style={{
          left: l, top: t, width: sz, height: sz,
          background: `radial-gradient(circle, ${c}26 0%, ${c}0d 40%, transparent 70%)`,
          filter: 'blur(24px)', opacity: 0.9, animation: `auroraShift ${16 + i * 4}s ease-in-out infinite`,
        }}></div>
      ))}
    </div>
  );
};

/* ----- hooks ----- */
function useInView() {
  const ref = useRef(null);
  const [seen, setSeen] = useState(false);
  useEffect(() => {
    const el = ref.current; if (!el) return;
    const vh = window.innerHeight || 800;
    const inView = () => { const r = el.getBoundingClientRect(); return r.top < vh * 0.94 && r.bottom > 0; };
    if (inView()) { setSeen(true); return; }
    if (typeof IntersectionObserver === 'undefined') { setSeen(true); return; }
    const ob = new IntersectionObserver((es) => { if (es.some((e) => e.isIntersecting)) { setSeen(true); ob.disconnect(); } }, { threshold: 0.08, rootMargin: '0px 0px -6% 0px' });
    ob.observe(el);
    return () => ob.disconnect();
  }, []);
  return [ref, seen];
}
const Reveal = ({ children, delay = 0, className = '', as: Tag = 'div', style }) => {
  const dc = delay ? ` d${delay}` : '';
  return <Tag className={`reveal${dc} ${className}`} style={style}>{children}</Tag>;
};

/* ----- brand logo lockup ----- */
const Logo = ({ s = 30 }) => (
  <div className="flex items-center gap-2.5 select-none">
    <span className="relative flex items-center justify-center rounded-xl" style={{ width: s + 8, height: s + 8, background: 'linear-gradient(150deg,#60A5FA,#3678F9 60%,#1D4ED8)', boxShadow: '0 6px 18px rgba(54,120,249,.4)' }}>
      <svg viewBox="0 0 1024 1024" width={s * 0.66} height={s * 0.66}>
        <path d="M625.27 785.47 A296 296 0 1 1 804.75 555.75" fill="none" stroke="#fff" strokeWidth="116" strokeLinecap="round" />
        <circle cx="462" cy="448" r="60" fill="#fff" />
        <circle cx="582" cy="540" r="46" fill="#fff" />
        <circle cx="745" cy="694" r="70" fill="#fff" />
      </svg>
    </span>
    <span className="font-extrabold tracking-tight text-white" style={{ fontSize: s * 0.78 }}>Closink</span>
  </div>
);

/* ----- store badges ----- */
const AppleBadge = () => (
  <a href={HOME + '#indir'} className="group inline-flex items-center gap-3 rounded-2xl px-5 h-[58px] bg-white text-[#0F172A] ring-soft transition-transform duration-200 hover:-translate-y-0.5">
    <svg viewBox="0 0 384 512" width="24" height="24" fill="#0F172A"><path d="M318.7 268c-.5-58 47.4-85.9 49.5-87.2-27-39.5-69-44.9-83.9-45.5-35.7-3.6-69.7 21-87.8 21-18 0-46-20.5-75.7-20-39 .6-74.9 22.6-94.9 57.5-40.5 70.2-10.4 174 29 231 19.2 27.8 42.1 59 72.1 57.9 28.9-1.1 39.8-18.7 74.8-18.7s44.9 18.7 75.6 18.1c31.2-.5 51-28.3 70.1-56.2 22.1-32.1 31.2-63.2 31.7-64.8-.7-.3-60.8-23.3-61.3-92.1zM260.6 96.7c16-19.4 26.8-46.3 23.8-73.1-23 1-50.9 15.3-67.4 34.6-14.8 17.1-27.8 44.5-24.3 70.8 25.7 2 51.9-13 67.9-32.3z"/></svg>
    <span className="flex flex-col leading-none text-left whitespace-nowrap">
      <span className="text-[10px] font-medium opacity-60 mono">İNDİR</span>
      <span className="text-[17px] font-extrabold -mt-0.5 tracking-tight">App Store</span>
    </span>
  </a>
);
const GoogleBadge = () => (
  <a href={HOME + '#indir'} className="group inline-flex items-center gap-3 rounded-2xl px-5 h-[58px] bg-white text-[#0F172A] ring-soft transition-transform duration-200 hover:-translate-y-0.5">
    <svg viewBox="0 0 512 512" width="22" height="22"><path d="M48 60c-4 4-7 11-7 20v352c0 9 3 16 7 20l201-216z" fill="#34A853"/><path d="M325 254L78 53c-8-4-16-3-22 1l201 216z" fill="#EA4335"/><path d="M325 254L56 458c6 4 14 5 22 1l247-142z" fill="#FBBC04"/><path d="M325 254l78 45c20 12 20 30 0 42l-78 45-49-91z" fill="#4285F4"/></svg>
    <span className="flex flex-col leading-none text-left whitespace-nowrap">
      <span className="text-[10px] font-medium opacity-60 mono">İNDİR</span>
      <span className="text-[17px] font-extrabold -mt-0.5 tracking-tight">Google Play</span>
    </span>
  </a>
);

/* ════ NAVBAR (sub-page) ════ */
const Navbar = ({ active }) => {
  const [solid, setSolid] = useState(false);
  useEffect(() => {
    const on = () => setSolid(window.scrollY > 40);
    on(); window.addEventListener('scroll', on, { passive: true });
    return () => window.removeEventListener('scroll', on);
  }, []);
  const links = [['Özellikler', HOME + '#ozellikler'], ['Sinematik', HOME + '#sinematik'], ['SOS', HOME + '#sos'], ['Mahremiyet', HOME + '#mahremiyet'], ['Planlar', HOME + '#planlar']];
  return (
    <header className="fixed top-0 left-0 right-0 z-[70] flex flex-col items-center px-4 pt-3.5 gap-2">
      <nav className={`glass glass-edge w-full max-w-6xl rounded-2xl flex items-center gap-3 px-4 sm:px-5 transition-all duration-300 ${solid ? 'py-2' : 'py-2.5'}`}
        style={{ border: '1px solid rgba(15,23,42,.07)', boxShadow: solid ? '0 12px 34px rgba(15,23,42,.12)' : '0 6px 20px rgba(15,23,42,.05)' }}>
        <a href={HOME + '#top'} className="shrink-0"><Logo s={26} /></a>
        <a href={HOME} className="hidden md:inline-flex items-center gap-1.5 ml-1 px-2.5 py-1.5 rounded-lg text-[13px] font-semibold text-slate-400 hover:text-white hover:bg-white/5 transition-colors whitespace-nowrap">
          <IconArrowL s={15} c="currentColor" />Ana sayfa
        </a>
        <div className="hidden lg:flex items-center gap-0.5 ml-1">
          {links.map(([t, h]) => (
            <a key={h} href={h} className="px-3 py-2 rounded-lg text-[14px] font-semibold text-slate-300 hover:text-white hover:bg-white/5 transition-colors">{t}</a>
          ))}
        </div>
        <div className="flex-1"></div>
        <a href={HOME + '#indir'} className="hidden sm:inline-flex items-center gap-2 rounded-xl px-4 h-10 text-[14px] font-bold text-white whitespace-nowrap transition-transform hover:-translate-y-0.5"
          style={{ background: 'linear-gradient(100deg,#1D4ED8,#3678F9)', color: '#fff', boxShadow: '0 8px 22px rgba(54,120,249,.42)' }}>
          Ücretsiz İndir<IconArrowR s={16} c="#fff" />
        </a>
        <a href={HOME + '#indir'} className="sm:hidden inline-flex items-center justify-center rounded-xl w-10 h-10" style={{ background: 'linear-gradient(100deg,#1D4ED8,#3678F9)' }}><IconArrowR s={18} c="#fff" /></a>
      </nav>
    </header>
  );
};

/* small back link for use inside hero */
const BackHome = () => (
  <a href={HOME} className="inline-flex items-center gap-1.5 text-[13.5px] font-semibold text-slate-400 hover:text-white transition-colors mono whitespace-nowrap">
    <IconArrowL s={15} c="currentColor" />ANA SAYFA
  </a>
);

/* ════ FOOTER ════ */
const Footer = () => (
  <footer className="relative pt-16 pb-10 border-t" style={{ borderColor: 'rgba(15,23,42,.08)', background: 'linear-gradient(#FFFFFF,#F8FAFC)' }}>
    <div className="max-w-6xl mx-auto px-5">
      <div className="grid sm:grid-cols-2 lg:grid-cols-[1.4fr_1fr_1fr_1fr] gap-10">
        <div>
          <a href={HOME}><Logo s={28} /></a>
          <p className="mt-4 text-slate-400 text-[14px] leading-relaxed max-w-xs">Ailenin huzuru, avucunda. Türkiye'de tasarlanan, mahremiyet-öncelikli aile güvenliği uygulaması.</p>
          <div className="mt-5 flex gap-2.5">
            {['IG', 'X', 'in', 'TT'].map(s => (
              <a key={s} href="#" className="flex items-center justify-center rounded-xl text-slate-300 hover:text-white hover:bg-white/10 transition-colors" style={{ width: 38, height: 38, background: '#F1F5F9', border: '1px solid #E2E8F0', fontSize: 12, fontWeight: 700 }}>{s}</a>
            ))}
          </div>
        </div>
        {[
          ['Ürün', [['Özellikler', HOME + '#ozellikler'], ['Sinematik Rapor', HOME + '#sinematik'], ['SOS', HOME + '#sos'], ['Planlar', HOME + '#planlar']]],
          ['Şirket', [['Hakkımızda', 'hakkimizda.html'], ['Manifesto', 'manifesto.html'], ['İletişim', 'iletisim.html']]],
          ['Yasal', [['Gizlilik (KVKK)', 'gizlilik.html'], ['Kullanım Şartları', 'kullanim-sartlari.html'], ['Çerezler', 'cerezler.html'], ['Güvenlik', 'guvenlik.html']]],
        ].map(([h, items]) => (
          <div key={h}>
            <div className="mono text-[11px] tracking-[0.16em] uppercase text-slate-500 font-semibold">{h}</div>
            <ul className="mt-4 space-y-2.5">
              {items.map(([it, href]) => <li key={it}><a href={href} className="text-slate-400 hover:text-white text-[14px] transition-colors">{it}</a></li>)}
            </ul>
          </div>
        ))}
      </div>
      <div className="mt-12 pt-6 border-t flex flex-col sm:flex-row items-center justify-between gap-4" style={{ borderColor: 'rgba(15,23,42,.08)' }}>
        <span className="text-slate-500 text-[13px]">© 2026 Closink · closink.com · Tüm hakları saklıdır.</span>
        <span className="flex items-center gap-2 text-slate-500 text-[13px]"><IconLock s={14} c="#7DD3FC" />Konum verini asla satmayız.</span>
      </div>
    </div>
  </footer>
);

/* ════ PAGE SHELL — grain + nav + page bg + footer ════ */
const Shell = ({ children }) => (
  <div className="relative" style={{ background: 'var(--page-bg)' }}>
    <Navbar />
    <main>{children}</main>
    <Footer />
  </div>
);

Object.assign(window, {
  React, ReactDOM, useState, useEffect, useRef, useCallback, HOME,
  Ic, IconShield, IconShieldOk, ShieldFill, IconLock, IconMapPin, IconHeart, HeartFill, IconBell,
  IconCheck, IconArrowR, IconArrowL, IconEye, IconEyeOff, IconUsers, IconSpark, IconStar, IconFinger,
  IconGlobe, IconMail, IconPhone, IconClock, IconDoc, IconKey, IconServer, IconLayers, IconCookie,
  IconScale, IconShare, IconFlag, IconMinimize,
  Eyebrow, Glass, PillBadge, Aurora, useInView, Reveal, Logo, AppleBadge, GoogleBadge,
  Navbar, BackHome, Footer, Shell,
});
