﻿"use client";
import { useEffect, useRef, useState } from "react";
import Link from "next/link";
import { motion, AnimatePresence } from "framer-motion";
import { ArrowUpRight, Check, ChevronDown, Maximize2, RefreshCw, X, Mail, MessageSquare, Server } from "lucide-react";
import { contactConfig } from "@/lib/contact";

const intents = [...contactConfig.services] as string[];

export default function ContactClient() {
  const [step, setStep] = useState(0);
  const [intent, setIntent] = useState<string | null>(null);
  const [form, setForm] = useState({ name:"", email:"", company:"", subject:"", message:"", budget:"", timeline:"" });
  const [honeypot, setHoneypot] = useState("");
  const [errors, setErrors] = useState<Record<string,string>>({});
  const [loading, setLoading] = useState(false);
  const [success, setSuccess] = useState(false);
  const [errorMsg, setErrorMsg] = useState<string | null>(null);
  const [zyFull, setZyFull] = useState(false);
  const [zyKey, setZyKey] = useState(0);
  const [faq, setFaq] = useState<number | null>(0);
  const [bgStep, setBgStep] = useState(0);
  const btnRef = useRef<HTMLButtonElement>(null);

  useEffect(() => { setBgStep(step); }, [step]);
  useEffect(() => { if (zyFull) document.body.style.overflow="hidden"; else document.body.style.overflow=""; return ()=>{document.body.style.overflow="";}; }, [zyFull]);

  // magnetic send
  useEffect(() => {
    if (window.matchMedia("(pointer: coarse)").matches) return;
    const el = btnRef.current; if (!el) return;
    const onMove = (e: MouseEvent) => {
      const r = el.getBoundingClientRect();
      const x = e.clientX - (r.left + r.width/2);
      const y = e.clientY - (r.top + r.height/2);
      const dist = Math.hypot(x,y);
      if (dist < 180) { el.style.transform = `translate(${x*0.12}px, ${y*0.12}px)`; } else { el.style.transform = ""; }
    };
    const onLeave = () => { el.style.transform = ""; };
    window.addEventListener("mousemove", onMove);
    window.addEventListener("mouseleave", onLeave);
    return () => { window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseleave", onLeave); };
  }, [step, success]);

  const validateStep = () => {
    const e: Record<string,string> = {};
    if (step===0 && !intent) e.intent = "Select an option";
    if (step===1) {
      if (!form.name.trim() || form.name.trim().length<2) e.name = "Please enter your name";
      if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(form.email)) e.email = "Please enter a valid email address.";
      if (!form.subject.trim()) e.subject = "Add a subject";
      if (!form.message.trim() || form.message.trim().length<10) e.message = "Message at least 10 chars";
      if (form.message.length>2000) e.message = "Max 2000 chars";
    }
    setErrors(e);
    return Object.keys(e).length===0;
  };

  const next = () => { if (validateStep()) setStep(s=> Math.min(3, s+1)); };
  const prev = () => setStep(s=> Math.max(0, s-1));

  const submit = async () => {
    if (!validateStep()) return;
    setLoading(true); setErrorMsg(null);
    try {
      const res = await fetch("/api/contact", { method:"POST", headers:{ "Content-Type":"application/json" }, body: JSON.stringify({ ...form, intent, honeypot }) });
      const data = await res.json();
      if (!res.ok) throw new Error(data.error || "Failed");
      setSuccess(true);
    } catch (err:any) {
      setErrorMsg(err.message || "The message couldn't be sent. Please try again or use the direct email option.");
    } finally { setLoading(false); }
  };

  return (
    <div className="bg-[#07080c] overflow-hidden">
      {/* HERO */}
      <section className={`relative min-h-[92vh] flex flex-col justify-center overflow-hidden transition-colors duration-700 ${bgStep===0 ? "bg-[#07080c]" : bgStep===1 ? "bg-[#080c10]" : bgStep===2 ? "bg-[#070c14]" : "bg-[#07080c]"}`}>
        <div className="absolute inset-0">
          <div className="absolute inset-0 grid-pattern opacity-[0.22] [mask-image:radial-gradient(70%_50%_at_50%_0%,black,transparent)]" />
          <div className={`absolute inset-0 transition-opacity duration-700 ${bgStep===3 ? "opacity-100" : "opacity-60"} bg-[radial-gradient(800px_500px_at_50%_-10%,rgba(59,130,246,0.14),transparent_70%)]`} />
          <div className="absolute inset-0 opacity-[0.03]" style={{ backgroundImage: `url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")` }} />
          <div className="absolute top-[18%] left-[6%] hidden sm:block text-[10px] tracking-[0.2em] text-white/10">PING ravneet â€¢ ONLINE</div>
          <div className="absolute bottom-[18%] right-[8%] hidden sm:block text-[10px] tracking-[0.2em] text-white/10">ravneet@contact:~$ availability</div>
        </div>
        <div className="relative max-w-[1100px] mx-auto px-6 sm:px-8 pt-24 pb-10 text-center w-full">
          <p className="text-[11px] tracking-[0.2em] font-semibold text-white/30 uppercase">Contact / Let&apos;s Talk</p>
          <motion.h1 initial={{ opacity:0, y:16 }} animate={{ opacity:1, y:0 }} transition={{ duration:0.6, ease:[0.16,1,0.3,1] }} className="mt-3 text-[40px] sm:text-[68px] lg:text-[78px] font-[800] tracking-[-0.05em] leading-[0.85] text-white">HAVE AN IDEA?<br /><span className="bg-gradient-to-r from-blue-400 to-cyan-300 bg-clip-text text-transparent">LET&apos;S MAKE IT REAL.</span></motion.h1>
          <p className="mt-4 max-w-[600px] mx-auto text-[14px] leading-relaxed text-white/50">Whether it&apos;s a project, collaboration, question or simply an idea worth discussing, send me a message.</p>
          <div className="mt-6 flex flex-wrap justify-center gap-3">
            <span className="inline-flex items-center gap-2 rounded-full border border-emerald-500/20 bg-emerald-500/10 px-3 py-1.5 text-[11px] tracking-widest font-semibold text-emerald-300"><span className="w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse" /> {contactConfig.availability}</span>
            <span className="hidden sm:inline-flex rounded-full border border-white/10 bg-white/5 px-3 py-1.5 text-[11px] tracking-widest text-white/40">{contactConfig.location} â€¢ {contactConfig.timezone}</span>
          </div>
          <a href="#start" className="mt-6 inline-flex px-5 py-2.5 rounded-full bg-white text-black font-semibold text-sm">Start a conversation â†“</a>
        </div>
        <div className="absolute bottom-6 left-1/2 -translate-x-1/2 flex flex-col items-center gap-2 text-white/30"><span className="text-[10px] tracking-[0.2em]">START A CONVERSATION</span><span className="w-px h-8 bg-gradient-to-b from-white/30 to-transparent animate-pulse" /></div>
      </section>

      {/* CONTACT INFO */}
      <section className="max-w-[1100px] mx-auto px-6 sm:px-8 py-6 grid sm:grid-cols-3 gap-3">
        <a href={`mailto:${contactConfig.email}`} className="rounded-2xl border border-white/10 bg-white/[0.04] p-5 hover:bg-white hover:text-black group flex justify-between items-center">
          <span><p className="text-xs tracking-widest opacity-50">EMAIL</p><p className="font-semibold text-sm mt-1 break-all">{contactConfig.email}</p><p className="text-xs opacity-50">Best for: Projects / Business</p></span><ArrowUpRight size={16} className="opacity-40 group-hover:translate-x-0.5 group-hover:-translate-y-0.5" />
        </a>
        <Link href="/zyphron" className="rounded-2xl border border-blue-500/20 bg-blue-500/10 p-5 flex justify-between items-center hover:bg-blue-500/15">
          <span><p className="text-xs tracking-widest text-blue-300">ZYPHRON</p><p className="font-semibold text-white text-sm mt-1">Cloud / Hosting</p><p className="text-xs text-white/50">Ask about Zyphron</p></span><Server size={16} className="text-blue-300" />
        </Link>
        <div className="rounded-2xl border border-white/10 bg-white/[0.03] p-5">
          <p className="text-xs tracking-widest text-white/30">LOCATION</p><p className="font-semibold text-white text-sm mt-1">{contactConfig.location}</p><p className="text-xs text-white/40">{contactConfig.timezone} â€¢ {contactConfig.responseTime}</p>
        </div>
      </section>

      {/* METHOD CARDS */}
      <section className="max-w-[1100px] mx-auto px-6 sm:px-8 pb-6 grid sm:grid-cols-4 gap-3">
        {[
          { name:"Email", best:"Projects / Business", href:`mailto:${contactConfig.email}`, label:"Send Email â†’" },
          { name:"LinkedIn", best:"Professional", href: contactConfig.socials.linkedin, label:"Connect â†’" },
          { name:"GitHub", best:"Code / Projects", href: contactConfig.socials.github, label:"View GitHub â†’" },
          { name:"Zyphron", best:"Cloud / Hosting", href: contactConfig.socials.zyphron, label:"Visit â†’" },
        ].map(m=>(
          <a key={m.name} href={m.href} target={m.href.startsWith("http") ? "_blank" : undefined} rel={m.href.startsWith("http") ? "noopener noreferrer" : undefined} className="group rounded-2xl border border-white/10 bg-white/[0.04] p-4 hover:bg-white hover:text-black flex justify-between items-center">
            <span><p className="font-semibold text-sm">{m.name}</p><p className="text-xs opacity-50">Best for: {m.best}</p></span><ArrowUpRight size={14} className="opacity-40 group-hover:translate-x-0.5" />
          </a>
        ))}
      </section>

      {/* PROJECT BRIEF vs QUICK */}
      <section id="start" className="max-w-[1100px] mx-auto px-6 sm:px-8 py-4 grid lg:grid-cols-2 gap-4">
        <div className="rounded-[20px] border border-white/10 bg-white/[0.04] p-6">
          <h3 className="font-bold text-white">HAVE A PROJECT IN MIND?</h3>
          <p className="text-sm text-white/50 mt-1">Detailed brief â€” 4 steps, no reload.</p>
          <button onClick={()=>document.getElementById("form")?.scrollIntoView({ behavior:"smooth" })} className="mt-3 px-5 py-2 rounded-full bg-white text-black font-semibold text-sm">START A PROJECT BRIEF â†’</button>
        </div>
        <div className="rounded-[20px] border border-white/10 bg-white/[0.03] p-6">
          <h3 className="font-bold text-white">JUST WANT TO SAY HI?</h3>
          <div className="mt-3 flex flex-wrap gap-2">
            <a href={`mailto:${contactConfig.email}`} className="px-4 py-2 rounded-full bg-white text-black font-semibold text-sm">Email Me â†’</a>
            <a href={contactConfig.socials.linkedin} className="px-4 py-2 rounded-full border border-white/15 text-white font-semibold text-sm">Connect on LinkedIn â†’</a>
            <a href={contactConfig.socials.discord} className="px-4 py-2 rounded-full border border-white/15 text-white font-semibold text-sm">Message on Discord â†’</a>
          </div>
        </div>
      </section>

      {/* FORM */}
      <section id="form" className="max-w-[900px] mx-auto px-6 sm:px-8 py-8">
        <div className="rounded-[24px] border border-white/10 bg-white/[0.04] overflow-hidden">
          {/* step indicator */}
          <div className="flex items-center justify-between px-6 py-4 border-b border-white/10 bg-white/[0.02]">
            <div className="flex gap-1.5">
              {[0,1,2,3].map(s=>(
                <span key={s} className={`w-8 h-1.5 rounded-full transition ${s < step ? "bg-white" : s===step ? "bg-blue-500" : "bg-white/10"}`} />
              ))}
            </div>
            <span className="text-xs tracking-widest text-white/30">0{step+1} / 04</span>
          </div>

          <div className="p-6 sm:p-8 min-h-[380px]">
            <AnimatePresence mode="wait">
              {/* success */}
              {success ? (
                <motion.div key="success" initial={{ opacity:0, scale:0.98 }} animate={{ opacity:1, scale:1 }} className="text-center py-10">
                  <div className="w-14 h-14 mx-auto rounded-full bg-emerald-500 text-white grid place-items-center"><Check size={22} /></div>
                  <h2 className="mt-4 text-2xl font-bold text-white">MESSAGE SENT.</h2>
                  <p className="text-sm text-white/60 mt-2">Thanks for reaching out. Your message has been received.<br />I&apos;ll get back to you as soon as possible.</p>
                  <div className="mt-6 flex flex-wrap justify-center gap-3">
                    <Link href="/" className="px-5 py-2 rounded-full bg-white text-black font-semibold text-sm">Back Home â†’</Link>
                    <Link href="/work" className="px-5 py-2 rounded-full border border-white/15 text-white font-semibold text-sm">Explore My Work â†’</Link>
                  </div>
                </motion.div>
              ) : errorMsg ? (
                <motion.div key="error" initial={{ opacity:0 }} animate={{ opacity:1 }} className="text-center py-10">
                  <h2 className="text-xl font-bold text-white">SOMETHING WENT WRONG.</h2>
                  <p className="text-sm text-white/60 mt-2">{errorMsg}</p>
                  <div className="mt-6 flex flex-wrap justify-center gap-3">
                    <button onClick={()=>setErrorMsg(null)} className="px-5 py-2 rounded-full bg-white text-black font-semibold text-sm">Try Again</button>
                    <a href={`mailto:${contactConfig.email}`} className="px-5 py-2 rounded-full border border-white/15 text-white font-semibold text-sm">Use Email</a>
                  </div>
                </motion.div>
              ) : step===0 ? (
                <motion.div key="step0" initial={{ opacity:0, x:12 }} animate={{ opacity:1, x:0 }} exit={{ opacity:0, x:-12 }} transition={{ duration:0.25 }}>
                  <h2 className="text-[22px] font-bold text-white">WHAT CAN I HELP WITH?</h2>
                  <p className="text-sm text-white/50">Select one â€” cards animate âœ“</p>
                  <div className="mt-6 grid sm:grid-cols-3 gap-3">
                    {intents.map(o=>(
                      <button key={o} onClick={()=>setIntent(o)} className={`text-left rounded-2xl border p-4 font-medium text-sm transition ${intent===o ? "bg-white text-black border-white" : "bg-white/5 border-white/10 text-white/70 hover:bg-white/10 hover:text-white"}`}>
                        <span className="flex justify-between items-center">{o} {intent===o && <span className="text-xs bg-emerald-500 text-white px-2 py-0.5 rounded-full">âœ“ Selected</span>}</span>
                      </button>
                    ))}
                  </div>
                  {errors.intent && <p className="text-xs text-red-400 mt-3">{errors.intent}</p>}
                  <div className="mt-6 flex justify-end"><button onClick={next} className="px-6 py-2.5 rounded-full bg-white text-black font-semibold text-sm">Next â†’</button></div>
                </motion.div>
              ) : step===1 ? (
                <motion.div key="step1" initial={{ opacity:0, x:12 }} animate={{ opacity:1, x:0 }} exit={{ opacity:0, x:-12 }} transition={{ duration:0.25 }} className="space-y-4">
                  <h2 className="text-[22px] font-bold text-white">TELL ME ABOUT IT</h2>
                  {/* honeypot hidden */}
                  <input value={honeypot} onChange={e=>setHoneypot(e.target.value)} tabIndex={-1} autoComplete="off" aria-hidden className="hidden" />
                  <div className="grid sm:grid-cols-2 gap-4">
                    <div>
                      <label className="text-xs tracking-widest text-white/40">Name *</label>
                      <input value={form.name} onChange={e=>setForm({...form, name:e.target.value})} autoComplete="name" placeholder="Ravneet" className={`mt-1 w-full rounded-xl bg-black/40 border px-3 py-2.5 text-sm text-white placeholder:text-white/30 outline-none ${errors.name ? "border-red-400/50" : "border-white/10 focus:border-white/20"}`} />
                      {errors.name && <p className="text-xs text-red-400 mt-1">{errors.name}</p>}
                    </div>
                    <div>
                      <label className="text-xs tracking-widest text-white/40">Email *</label>
                      <input value={form.email} onChange={e=>setForm({...form, email:e.target.value})} autoComplete="email" type="email" placeholder="you@example.com" className={`mt-1 w-full rounded-xl bg-black/40 border px-3 py-2.5 text-sm text-white placeholder:text-white/30 outline-none ${errors.email ? "border-red-400/50" : "border-white/10 focus:border-white/20"}`} />
                      {errors.email && <p className="text-xs text-red-400 mt-1">{errors.email}</p>}
                    </div>
                  </div>
                  <div>
                    <label className="text-xs tracking-widest text-white/40">Company / Organization</label>
                    <input value={form.company} onChange={e=>setForm({...form, company:e.target.value})} placeholder="Optional" className="mt-1 w-full rounded-xl bg-black/40 border border-white/10 px-3 py-2.5 text-sm text-white placeholder:text-white/30 outline-none focus:border-white/20" />
                  </div>
                  <div>
                    <label className="text-xs tracking-widest text-white/40">Project / Subject *</label>
                    <input value={form.subject} onChange={e=>setForm({...form, subject:e.target.value})} placeholder="Website â€” Zyphron idea" className={`mt-1 w-full rounded-xl bg-black/40 border px-3 py-2.5 text-sm text-white placeholder:text-white/30 outline-none ${errors.subject ? "border-red-400/50" : "border-white/10 focus:border-white/20"}`} />
                    {errors.subject && <p className="text-xs text-red-400 mt-1">{errors.subject}</p>}
                  </div>
                  <div>
                    <label className="text-xs tracking-widest text-white/40 flex justify-between"><span>Message *</span><span className="font-mono text-white/30">{form.message.length} / 2000</span></label>
                    <textarea value={form.message} onChange={e=>setForm({...form, message:e.target.value})} rows={5} placeholder="Tell me about your idea..." maxLength={2000} className={`mt-1 w-full rounded-xl bg-black/40 border px-3 py-2.5 text-sm text-white placeholder:text-white/30 outline-none ${errors.message ? "border-red-400/50" : "border-white/10 focus:border-white/20"}`} />
                    {errors.message && <p className="text-xs text-red-400 mt-1">{errors.message}</p>}
                  </div>
                  <div className="flex justify-between pt-2"><button onClick={prev} className="px-4 py-2 rounded-full border border-white/15 text-white text-sm">â† Back</button><button onClick={next} className="px-6 py-2.5 rounded-full bg-white text-black font-semibold text-sm">Next â†’</button></div>
                </motion.div>
              ) : step===2 ? (
                <motion.div key="step2" initial={{ opacity:0, x:12 }} animate={{ opacity:1, x:0 }} exit={{ opacity:0, x:-12 }} transition={{ duration:0.25 }} className="space-y-4">
                  <h2 className="text-[22px] font-bold text-white">PROJECT DETAILS</h2>
                  <p className="text-xs text-white/40">Optional â€” make tiers editable via lib/contact.ts</p>
                  <div>
                    <p className="text-xs tracking-widest text-white/40">Budget</p>
                    <div className="mt-2 flex flex-wrap gap-2">
                      {contactConfig.budgets.map(b=>(
                        <button key={b} onClick={()=>setForm({...form, budget:b})} className={`px-3.5 py-1.5 rounded-full text-xs font-semibold border ${form.budget===b ? "bg-white text-black border-white" : "bg-white/5 border-white/10 text-white/60 hover:text-white"}`}>{b}</button>
                      ))}
                    </div>
                  </div>
                  <div>
                    <p className="text-xs tracking-widest text-white/40">Timeline</p>
                    <div className="mt-2 flex flex-wrap gap-2">
                      {contactConfig.timelines.map(t=>(
                        <button key={t} onClick={()=>setForm({...form, timeline:t})} className={`px-3.5 py-1.5 rounded-full text-xs font-semibold border ${form.timeline===t ? "bg-white text-black border-white" : "bg-white/5 border-white/10 text-white/60 hover:text-white"}`}>{t}</button>
                      ))}
                    </div>
                  </div>
                  <div className="flex justify-between pt-2"><button onClick={prev} className="px-4 py-2 rounded-full border border-white/15 text-white text-sm">â† Back</button><button onClick={next} className="px-6 py-2.5 rounded-full bg-white text-black font-semibold text-sm">Review â†’</button></div>
                </motion.div>
              ) : (
                <motion.div key="step3" initial={{ opacity:0, x:12 }} animate={{ opacity:1, x:0 }} exit={{ opacity:0, x:-12 }} transition={{ duration:0.25 }}>
                  <h2 className="text-[22px] font-bold text-white">YOUR MESSAGE</h2>
                  <div className="mt-4 rounded-2xl border border-white/10 bg-black/20 p-5 space-y-2 text-sm">
                    <p><span className="text-white/40">Name:</span> <span className="text-white font-medium">{form.name || "â€”"}</span></p>
                    <p><span className="text-white/40">Email:</span> <span className="text-white">{form.email || "â€”"}</span></p>
                    <p><span className="text-white/40">Project:</span> <span className="text-white">{intent || form.subject || "â€”"}</span></p>
                    <p><span className="text-white/40">Budget:</span> <span className="text-white">{form.budget || "â€”"}</span> <span className="text-white/40">â€¢ Timeline:</span> <span className="text-white">{form.timeline || "â€”"}</span></p>
                    <p className="pt-2 border-t border-white/10 whitespace-pre-wrap text-white/70">{form.message || "â€”"}</p>
                  </div>
                  <div className="mt-6 flex justify-between items-center">
                    <button onClick={prev} className="px-4 py-2 rounded-full border border-white/15 text-white text-sm">â† Edit</button>
                    <button ref={btnRef} onClick={submit} disabled={loading} className="px-8 py-3 rounded-full bg-white text-black font-bold text-sm inline-flex items-center gap-2 hover:bg-white/90 disabled:opacity-50 transition-transform will-change-transform">
                      {loading ? "Sendingâ€¦" : "SEND MESSAGE â†’"}
                    </button>
                  </div>
                </motion.div>
              )}
            </AnimatePresence>
          </div>
        </div>
      </section>

      {/* WHAT HAPPENS NEXT */}
      <section className="max-w-[1100px] mx-auto px-6 sm:px-8 py-8">
        <h2 className="text-[11px] tracking-[0.2em] text-white/30 uppercase text-center">What happens next?</h2>
        <div className="mt-4 grid sm:grid-cols-3 gap-4">
          {[
            { n:"01", t:"MESSAGE", d:"Tell me what you're working on." },
            { n:"02", t:"DISCUSS", d:"We figure out whether it's a good fit." },
            { n:"03", t:"BUILD", d:"Turn the idea into something real." },
          ].map(s=>(
            <div key={s.n} className="rounded-2xl border border-white/10 bg-white/[0.04] p-6 text-center">
              <p className="text-xs tracking-widest text-blue-300">{s.n}</p><p className="font-bold text-white mt-1">{s.t}</p><p className="text-sm text-white/50 mt-1">{s.d}</p>
            </div>
          ))}
        </div>
      </section>

      {/* FAQ split */}
      <section className="max-w-[1100px] mx-auto px-6 sm:px-8 py-8 grid lg:grid-cols-2 gap-6">
        <div>
          <h2 className="text-xl font-bold text-white">BEFORE YOU MESSAGE</h2>
          <div className="mt-4 divide-y divide-white/10 border border-white/10 rounded-2xl overflow-hidden">
            {[
              { q:"What kind of projects do you work on?", a:"Websites, applications, hosting, infrastructure, automation and products. If it's at the intersection of tech and business, I'm interested." },
              { q:"Are you available for collaborations?", a:"Yes for selected projects â€” use the form and tell me what you have in mind." },
              { q:"Do you work on hosting/infrastructure?", a:"Yes â€” Zyphron Cloud is my main infra product. Mention ZYPHRON in the form for fastest routing." },
              { q:"Can I contact you about Zyphron?", a:"Absolutely â€” or visit zyphron.cloud directly." },
              { q:"What's the best way to reach you?", a:"Form for full context, email for quick notes: hello@ravneetbrar.in" },
            ].map((f,i)=>(
              <div key={f.q}>
                <button onClick={()=>setFaq(faq===i?null:i)} className="w-full flex justify-between items-center px-4 py-3 text-left bg-white/[0.03] hover:bg-white/[0.06]">
                  <span className="text-sm text-white">{f.q}</span><ChevronDown size={14} className={`text-white/40 shrink-0 transition ${faq===i ? "rotate-180" : ""}`} />
                </button>
                <AnimatePresence>
                  {faq===i && <motion.div initial={{ height:0, opacity:0 }} animate={{ height:"auto", opacity:1 }} exit={{ height:0, opacity:0 }} className="overflow-hidden bg-black/20"><p className="px-4 py-3 text-sm text-white/60">{f.a}</p></motion.div>}
                </AnimatePresence>
              </div>
            ))}
          </div>
        </div>
        <div className="rounded-[20px] border border-white/10 bg-gradient-to-br from-white/[0.06] to-transparent p-6 flex flex-col justify-center">
          <h3 className="text-xl font-bold text-white">READY TO TALK?</h3>
          <p className="text-sm text-white/50 mt-1">Pick a project type and start â€” takes ~60 seconds.</p>
          <button onClick={()=>document.getElementById("form")?.scrollIntoView({ behavior:"smooth" })} className="mt-4 w-fit px-5 py-2.5 rounded-full bg-white text-black font-semibold text-sm">Start a Conversation â†’</button>
          <p className="text-xs text-white/30 mt-3">{contactConfig.responseTime}</p>
        </div>
      </section>

      {/* ZYPHRON */}
      <section className="max-w-[1100px] mx-auto px-6 sm:px-8 py-6">
        <div className="rounded-[20px] border border-blue-500/20 bg-blue-500/10 p-6 flex flex-col sm:flex-row justify-between gap-4 items-start sm:items-center">
          <div><h3 className="font-bold text-white">ASK ABOUT ZYPHRON</h3><p className="text-sm text-white/60">Looking for hosting, infrastructure or Zyphron info?</p></div>
          <div className="flex gap-2"><a href="https://zyphron.cloud" target="_blank" rel="noopener noreferrer" className="px-4 py-2 rounded-full bg-white text-black font-semibold text-sm">Visit Zyphron Cloud â†—</a><a href="https://zyphron.cloud/" target="_blank" rel="noopener noreferrer" className="px-4 py-2 rounded-full border border-white/15 text-white font-semibold text-sm">Zyphron Support â†—</a></div>
        </div>
        <div className="mt-4 rounded-[18px] border border-white/10 bg-[#0e1118] overflow-hidden">
          <div className="flex items-center justify-between px-4 py-3 border-b border-white/10">
            <div className="flex gap-1.5"><span className="w-3 h-3 rounded-full bg-red-500/80" /><span className="w-3 h-3 rounded-full bg-yellow-500/80" /><span className="w-3 h-3 rounded-full bg-green-500/80" /></div>
            <span className="text-xs text-white/50 flex items-center gap-2"><span className="w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse" /> zyphron.cloud</span>
            <div className="flex gap-1"><button onClick={()=>setZyKey(k=>k+1)} className="w-7 h-7 rounded-full bg-white/10 grid place-items-center text-white/60"><RefreshCw size={12} /></button><button onClick={()=>setZyFull(true)} className="w-7 h-7 rounded-full bg-white text-black grid place-items-center"><Maximize2 size={12} /></button></div>
          </div>
          <div className="h-[300px] bg-white"><iframe key={zyKey} src="https://zyphron.cloud/" title="Live Zyphron Cloud" className="w-full h-full border-0" loading="lazy" sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox" /></div>
          <div className="px-4 py-2 flex justify-between text-xs text-white/30 border-t border-white/10"><span>â— LIVE</span><a href="https://zyphron.cloud" target="_blank" rel="noopener noreferrer" className="text-blue-400">OPEN ZYPHRON CLOUD â†—</a></div>
        </div>
        {zyFull && <div className="fixed inset-0 z-40 bg-black/80 backdrop-blur flex flex-col"><div className="flex justify-between items-center px-4 py-3 bg-[#0e1118] border-b border-white/10"><span className="text-xs text-white/60">zyphron.cloud</span><button onClick={()=>setZyFull(false)} className="w-8 h-8 rounded-full bg-white/10 grid place-items-center text-white"><X size={16} /></button></div><div className="flex-1 bg-white"><iframe src="https://zyphron.cloud/" title="Zyphron fullscreen" className="w-full h-full border-0" /></div></div>}
      </section>

      {/* TERMINAL + social */}
      <section className="max-w-[1100px] mx-auto px-6 sm:px-8 py-6 grid lg:grid-cols-2 gap-6">
        <div className="rounded-[18px] border border-white/10 bg-[#0a0d12] overflow-hidden">
          <div className="flex items-center justify-between px-4 py-3 bg-white/[0.04] border-b border-white/10"><span className="font-mono text-xs text-white/40">ravneet@contact:~$</span><span className="text-xs text-emerald-400">â— ONLINE</span></div>
          <div className="p-5 font-mono text-xs leading-relaxed text-white/60">
            <div>$ ping ravneet<br />PING...<br /><span className="text-emerald-400">â— ONLINE</span></div>
            <div className="mt-2">$ availability<br />CHECKING...<br /><span className="text-white">â— SEE CONTACT FORM</span></div>
            <div className="mt-2">$ next<br /><span className="text-blue-400">START CONVERSATION</span></div>
          </div>
        </div>
        <div className="rounded-[18px] border border-white/10 bg-white/[0.03] p-6">
          <p className="text-xs tracking-widest text-white/30 uppercase">Connect</p>
          <div className="mt-3 grid grid-cols-2 gap-2 text-sm">
            <a href={`mailto:${contactConfig.email}`} className="group flex justify-between items-center rounded-xl bg-white text-black px-4 py-3 font-medium"><span className="flex items-center gap-2"><Mail size={14} /> Email</span><ArrowUpRight size={14} className="opacity-40 group-hover:translate-x-0.5" /></a>
            <a href={contactConfig.socials.github} className="group flex justify-between items-center rounded-xl border border-white/10 bg-white/[0.04] px-4 py-3 text-white hover:bg-white hover:text-black"><span>GitHub</span><ArrowUpRight size={14} /></a>
            <a href={contactConfig.socials.x} className="group flex justify-between items-center rounded-xl border border-white/10 bg-white/[0.04] px-4 py-3 text-white hover:bg-white hover:text-black"><span>X</span><ArrowUpRight size={14} /></a>
            <a href={contactConfig.socials.discord} className="group flex justify-between items-center rounded-xl border border-white/10 bg-white/[0.04] px-4 py-3 text-white hover:bg-white hover:text-black"><span>Discord</span><ArrowUpRight size={14} /></a>
          </div>
          <p className="text-xs text-white/20 mt-3">Only public accounts shown â€¢ No private info exposed</p>
        </div>
      </section>

      {/* FINAL CTA */}
      <section className="py-16 sm:py-20 text-center border-t border-white/10 bg-gradient-to-b from-white/[0.04] to-transparent">
        <p className="text-[11px] tracking-[0.2em] text-white/30 uppercase">One message can start something big.</p>
        <h2 className="mt-2 text-[40px] sm:text-[64px] font-[800] tracking-[-0.05em] text-white leading-none">LET&apos;S BUILD.</h2>
        <p className="text-white/50 mt-3">Have an idea? Tell me about it.</p>
        <div className="mt-6 flex flex-wrap justify-center gap-3">
          <button onClick={()=>document.getElementById("form")?.scrollIntoView({ behavior:"smooth" })} className="px-6 py-3 rounded-full bg-white text-black font-semibold">Start a Conversation â†’</button>
          <Link href="/work" className="px-6 py-3 rounded-full border border-white/15 text-white font-semibold">View My Work â†’</Link>
          <a href="https://zyphron.cloud" target="_blank" rel="noopener noreferrer" className="px-6 py-3 rounded-full bg-[#2563eb] text-white font-semibold">Visit Zyphron Cloud â†—</a>
        </div>
      </section>
    </div>
  );
}
