// Contact section + Footer + Scroll-following Knight

function ContactSection({ dark, accent, font }) {
  const fg = dark ? '#f0eef9' : '#0c0a14';
  const muted = dark ? 'rgba(240,238,249,0.6)' : 'rgba(20,18,30,0.6)';
  const links = window.PORTFOLIO_LINKS;

  return (
    <section id="contact" style={{
      position: 'relative', padding: '120px 60px 80px', zIndex: 2,
    }}>
      <div style={{
        position: 'relative', padding: '80px 60px',
        background: dark ? 'rgba(255,255,255,0.04)' : 'rgba(255,255,255,0.6)',
        border: `1px solid ${dark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.05)'}`,
        borderRadius: 32, backdropFilter: 'blur(28px)',
        overflow: 'hidden', textAlign: 'center',
      }}>
        <div style={{
          position: 'absolute', inset: 0,
          background: `
            radial-gradient(50% 60% at 30% 0%, ${accent}30, transparent 70%),
            radial-gradient(50% 60% at 70% 100%, #b48aff30, transparent 70%)
          `,
          filter: 'blur(20px)', pointerEvents: 'none',
        }} />
        <div style={{ position: 'relative' }}>
          <div style={{
            fontSize: 11, letterSpacing: '0.16em', textTransform: 'uppercase',
            color: accent, fontWeight: 600,
          }}>Let's build</div>
          <h2 style={{
            fontFamily: font.display, fontSize: 'clamp(40px, 6vw, 76px)',
            fontWeight: 700, letterSpacing: '-0.04em', lineHeight: 1,
            margin: '14px auto 0', maxWidth: 800, color: fg,
          }}>
            Have something interesting<br/>
            <span style={{
              background: `linear-gradient(135deg, ${accent} 0%, #b48aff 50%, #63b3ed 100%)`,
              WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent',
              fontStyle: 'italic', fontFamily: font.italic || font.display,
            }}>to make?</span>
          </h2>
          <p style={{ fontSize: 17, color: muted, margin: '20px auto 0', maxWidth: 480, lineHeight: 1.5 }}>
            Open to AI/ML roles, freelance, and collaborations. The cleaner the
            problem, the louder I'll be about it.
          </p>

          <div style={{ display: 'flex', gap: 12, justifyContent: 'center', marginTop: 36, flexWrap: 'wrap' }}>
            <a href={`mailto:${links.email}`} style={{
              padding: '14px 24px', fontSize: 14, fontWeight: 600,
              background: fg, color: dark ? '#0c0a14' : '#f0eef9',
              border: 'none', borderRadius: 999, cursor: 'pointer',
              textDecoration: 'none', display: 'inline-flex', alignItems: 'center', gap: 8,
            }}>
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 7l9 6 9-6"/></svg>
              {links.email}
            </a>
          </div>

          <div style={{
            display: 'flex', gap: 24, justifyContent: 'center', marginTop: 24,
            fontSize: 13, color: muted,
          }}>
            <a href={links.github} target="_blank" rel="noreferrer" style={{ color: 'inherit', textDecoration: 'none', display: 'inline-flex', alignItems: 'center', gap: 6 }}>
              <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"/></svg>
              GitHub
            </a>
            <a href={links.linkedin} target="_blank" rel="noreferrer" style={{ color: 'inherit', textDecoration: 'none', display: 'inline-flex', alignItems: 'center', gap: 6 }}>
              <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M19 0h-14c-2.76 0-5 2.24-5 5v14c0 2.76 2.24 5 5 5h14c2.76 0 5-2.24 5-5v-14c0-2.76-2.24-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.27c-.97 0-1.75-.79-1.75-1.76s.78-1.76 1.75-1.76 1.75.79 1.75 1.76-.78 1.76-1.75 1.76zm13.5 12.27h-3v-5.6c0-1.34-.03-3.07-1.87-3.07-1.87 0-2.16 1.46-2.16 2.97v5.7h-3v-11h2.88v1.5h.04c.4-.76 1.38-1.56 2.84-1.56 3.04 0 3.6 2 3.6 4.6v6.46z"/></svg>
              LinkedIn
            </a>
          </div>
        </div>
      </div>
    </section>
  );
}

function Footer({ dark, accent, font }) {
  const muted = dark ? 'rgba(240,238,249,0.45)' : 'rgba(20,18,30,0.45)';
  return (
    <footer style={{
      position: 'relative', padding: '40px 60px 60px',
      borderTop: `1px solid ${dark ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.05)'}`,
      display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      flexWrap: 'wrap', gap: 16, zIndex: 2,
      fontSize: 12, color: muted,
    }}>
      <div>© 2025 Sliuveru Vashishta. Built with care, caffeine and a 100 wpm keyboard.</div>
      <div style={{ display: 'flex', gap: 6, alignItems: 'center' }}>
        <span style={{ width: 6, height: 6, borderRadius: 3, background: '#4ade80', boxShadow: '0 0 6px #4ade80' }} />
        Currently available
      </div>
    </footer>
  );
}

// Scroll-following knight — smooth eased path, subtle glow companion
function ScrollKnight({ dark, accent }) {
  const targetRef = useRef({ y: 0, x: 0, rot: 0 });
  const currentRef = useRef({ y: 0, x: 0, rot: 0 });
  const elRef = useRef(null);
  const rafRef = useRef(null);

  useEffect(() => {
    const easeInOut = (t) => t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;

    const computeTarget = () => {
      const docH = Math.max(1, document.documentElement.scrollHeight - window.innerHeight);
      const t = Math.min(1, Math.max(0, window.scrollY / docH));
      const eased = easeInOut(t);
      // Vertical: drift from 12vh to 78vh on an eased curve
      const y = 12 + eased * 66;
      // Horizontal: gentle sine sway (smaller amplitude than before)
      const sway = Math.sin(t * Math.PI * 2.2) * 28;
      // Rotation: tiny tilt that mirrors the sway
      const rot = Math.sin(t * Math.PI * 2.2) * 6;
      targetRef.current = { y, x: sway, rot };
    };

    const tick = () => {
      const cur = currentRef.current;
      const tgt = targetRef.current;
      // Critical-damped lerp — frame-rate friendly smoothing
      const k = 0.08;
      cur.y += (tgt.y - cur.y) * k;
      cur.x += (tgt.x - cur.x) * k;
      cur.rot += (tgt.rot - cur.rot) * k;
      if (elRef.current) {
        elRef.current.style.top = `${cur.y}vh`;
        elRef.current.style.transform =
          `translate3d(${cur.x}px, -50%, 0) rotate(${cur.rot}deg)`;
      }
      rafRef.current = requestAnimationFrame(tick);
    };

    computeTarget();
    rafRef.current = requestAnimationFrame(tick);
    window.addEventListener('scroll', computeTarget, { passive: true });
    window.addEventListener('resize', computeTarget);
    return () => {
      cancelAnimationFrame(rafRef.current);
      window.removeEventListener('scroll', computeTarget);
      window.removeEventListener('resize', computeTarget);
    };
  }, []);

  return (
    <div ref={elRef} style={{
      position: 'fixed',
      top: '12vh', right: '5vw',
      transform: 'translate3d(0,-50%,0)',
      pointerEvents: 'none',
      zIndex: 1,
      willChange: 'transform, top',
    }}>
      <div style={{ opacity: dark ? 0.14 : 0.18, color: dark ? '#f0eef9' : '#0c0a14' }}>
        <window.KnightPiece size={96} color="currentColor" glow={false} />
      </div>
    </div>
  );
}

window.ContactSection = ContactSection;
window.Footer = Footer;
window.ScrollKnight = ScrollKnight;
